Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media...

41
Samsung Open Source Group © SAMSUNG Electronics Co. 1 Media Resource Sharing Through The Media Controller API Korea Linux Forum, October 26 th 2015 Shuah Khan Samsung Open Source Group [email protected]

Transcript of Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media...

Page 1: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.1

Media Resource Sharing Through The Media Controller API

Korea Linux Forum, October 26th 2015

Shuah KhanSamsung Open Source [email protected]

Page 2: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.2

Abstract

Media devices have hardware resources that are shared across several functions. However, media drivers have no knowledge of which resources are shared. For example, accessing DVB and ALSA at the same time, or the DVB and V4L analog video at the same time results in video and audio stream errors.

At the root of this problem is a lack of a common locking mechanism that can provide access control. As a result, it is necessary to create a locking construct at the master device level for all drivers that share a device to facilitate resource sharing. A common managed media device created at the parent USB device level can function as this locking construct.

In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition, she will show how media-ctl/mc_nextgen_test tool can be used to generate media graphs for a media device.

Page 3: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.3

Agenda ...

● Media Devices● Media vs. Multi-function Devices● Shared Media Functions Nicely - Challenges● Exclusive Access Use-cases● About Win-TV HVR 950Q● Media Controller API● Managed Media Controller API● HVR 950Q Drivers with Managed Media Device● HVR 950Q Device Media Graphs● HVR 950Q Drivers Sharing Resources

Page 4: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.4

Media Devices ...

Hauppauge Win TV HVR 950QHybrid USB TV Stick

Kworld UB435-Q V3

Hauppauge 80e PCTV HD Mini Stick

Page 5: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.5

Media vs. Multi-function Devices ...● A group of independent

devices.

● Each device implements a function.

● Sharing is not limited to attach point.

● A single device.

● MFD framework helps identify functions as discrete platform devices.

● Sharing is limited to attach point – sub-devices attached to a shared bus.

Page 6: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.6

Media vs. Multi-function Devices ...

● Functions can be shared.

● Media drivers have to coordinate sharing.

● Fine grain locking.

● Leverage non-media drivers. e.g: snd-usb-audio for audio function.

● Each function is independent.

● Drivers don't need to coordinate sharing.

● Fine grain locking.

Page 7: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.7

Sharing Media Functions Nicely - Challenges ...● Drivers are unaware of shared resources.● Drivers don't have a way to ensure exclusive access to

shared resource/function.– e.g: Starting Digital application disrupts Video streaming.

● Drivers can access/change modes while resource is in use by another.

● Existing fine grain locks don't ensure exclusive access.● Existing locks are local to function drivers. No global

locks that span all drivers.

Page 8: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.8

Exclusive Access Use-cases ...

● Starting Digital application ...

– should not disrupt active Video and Audio streams.● Starting Video application ...

– should not disrupt active Digital and Audio streams.● Starting Audio application …

– should not disrupt Video and Digital streams.● Querying current configuration (read only access)

should work.

Page 9: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.9

About Win-TV HVR 950Q ...

Hardware:– USB bus – attach point

– Tuner on I2C bus

– Audio Processor

– Decoder

– Video

– Digital

– No Radio

– IR receiver (No transmitter)

Page 10: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.10

About Win-TV HVR 950Q ...

Drivers:

– au0828 usb driver– au0828 dvb extension– au0828 analog (v4l2) extension– i2c Hauppauge eeprom decoder driver– Xceive xc5000 silicon tuner driver– snd-usb-audio

Page 11: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.11

About Win-TV HVR 950Q ...

Device/Driver view:

USB Devicestruct usb_device

USB Device Parentstruct device

Au0828 USB driverstruct au0828_dev

Snd-usb-audio

Au0828 DVB

Au0828 Video

Shared USB Interface

Au8522 Decoder

Xc5000 tuner

Page 12: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.12

Shared Resource Exclusive Locking ...

Page 13: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.13

Media Controller API ...

● Relational media graph framework● Media functions/resources represented as

nodes on a graph● Media Device serves as the root node● Allows creating links between nodes● Allows active/inactive links between nodes● Allows start/stop pipelines between nodes

Page 14: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.14

Managed Media Controller API ...

Media Device as a device resource● media_device_get_devres()● media_device_find_devres()

Page 15: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.15

Managed Media Controller API ...

Allows au0828 and snd-usb-audio share media device● Media Device is a managed device resource at

the parent USB device.● Media Device is the root node for the shared

media graph.● Media Device gets created by either au0828 or

snd-usb-audio – first one to run probe wins.

Page 16: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.16

HVR 950Q drivers with Managed Media Device ...

Device/Driver view:

USB Devicestruct usb_device

USB Device Parentstruct device

Au0828 USB driverstruct au0828_dev

Snd-usb-audio

Au0828 DVB

Au0828 Video

Shared USB Interface

Managed MediaDevice on

USB Device Parentstruct device

Shared Media Device

Au8522 Decoder

Xc5000 tuner

Page 17: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.17

Media Controller Entity Notify API ...

● media_device_register_entity_notify()● media_device_unregister_entity_notify()● Enables drivers to register callbacks to take

action as entities get added by other drivers.

Page 18: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.18

Shared Media Graph Creation ...

● Drivers (au0828, and snd-usb-audio) add entities for their functions.

● Bridge driver (au0828) creates links between entities via entity_notify API.

Page 19: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.19

HVR 950Q Media Graph ...

Page 20: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.20

Media Controller Enable/Disable Source handlers ...

● Media Device - enable/disable source handlers.● Enable source grants access to shared

resource or returns -EBUSY.● Disable source marks shared resource free.● Bridge drivers (e.g au0828) implement and

register enable/disable source handlers to manage access to shared resources.

Page 21: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.21

Audio owns tuner ...

Page 22: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.22

Audio releases tuner ...

Page 23: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.23

Video owns tuner ...

Page 24: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.24

Video releases tuner ...

Page 25: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.25

Digital owns tuner ...

Page 26: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.26

Digital releases tuner ...

Page 27: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.27

Audio owns tuner – Digital start/stop ...

Page 28: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.28

Audio owns tuner – Video start/stop ...

Page 29: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.29

Video owns tuner – Audio start/stop ...

Page 30: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.30

Video owns tuner – Digital start/stop ...

Page 31: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.31

Digital owns tuner – Audio start/stop ...

Page 32: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.32

Digital owns tuner – Video start/stop ...

Page 33: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.33

tvtime owns tuner ...

Page 34: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.34

tvtime releases tuner ...

Page 35: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.35

After v4l2-ctl –all run ...

Page 36: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.36

mc_nextgen_test tool ...

Usage: mc_nextgen_test [OPTION...]

A testing tool for the MC next geneneration API

-d, --device=DEVICE media controller device (default: /dev/media0

-D, --dot show in Graphviz format

-e, --entities show entities

-i, --interfaces show pads

-I, --intf-links show interface links

-l, --data-links show data links

-?, --help Give this help list

--usage Give a short usage message

-V, --version Print program version

Page 37: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.37

Links to patches ...

● Update ALSA, and au0828 drivers to use Managed Media Controller API – patch series links:– https://www.mail-archive.com/[email protected]

.org/msg92752.html● Mixer and Control Interface support

– https://www.mail-archive.com/[email protected]/msg93084.html

● mc_nextgen_test tool patch to add ALSA entity support– https://www.mail-archive.com/[email protected]

.org/msg93086.html

Page 38: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.38

Links to media graphs ...

● Media graphs generated using mc_nextgen_test tool at various points during testing at– https://drive.google.com/open?id=0B0NIL0BQg-

AlLWE3SzAxazBJWm8

Page 39: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.39

Questions ?

Page 40: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.40

Thank You!

Page 41: Media Resource Sharing Through The Media …...In this talk, Shuah will discuss the Managed Media Controller API and how ALSA and au0828 use it to share media resources. In addition,

Samsung Open Source Group © SAMSUNG Electronics Co.41

About Kworld ATSC TV Stick ...

● Hardware:– USB bus – attach point

– Tuner on I2C bus

– Digital TV

– Audio

● Drivers:

– em28xx usb driver– em28xx dvb extension– dvb frontend adapter: demux, dvr, net– tda18212