5.Media Controller devices¶
5.1.Media Controller¶
The media controller userspace API is documented inthe Media Controller uAPI book. This document focuson the kernel-side implementation of the media framework.
5.1.1.Abstract media device model¶
Discovering a device internal topology, and configuring it at runtime, is oneof the goals of the media framework. To achieve this, hardware devices aremodelled as an oriented graph of building blocks called entities connectedthrough pads.
An entity is a basic media hardware building block. It can correspond toa large variety of logical blocks such as physical hardware devices(CMOS sensor for instance), logical hardware devices (a building blockin a System-on-Chip image processing pipeline), DMA channels or physicalconnectors.
A pad is a connection endpoint through which an entity can interact withother entities. Data (not restricted to video) produced by an entityflows from the entity’s output to one or more entity inputs. Pads shouldnot be confused with physical pins at chip boundaries.
A link is a point-to-point oriented connection between two pads, eitheron the same entity or on different entities. Data flows from a sourcepad to a sink pad.
5.1.2.Media device¶
A media device is represented by astructmedia_deviceinstance, defined ininclude/media/media-device.h.Allocation of the structure is handled by the media device driver, usually byembedding themedia_device instance in a larger driver-specificstructure.
Drivers initialise media device instances by callingmedia_device_init(). After initialising a media device instance, it isregistered by calling__media_device_register() via the macromedia_device_register() and unregistered by callingmedia_device_unregister(). An initialised media device must beeventually cleaned up by callingmedia_device_cleanup().
Note that it is not allowed to unregister a media device instance that was notpreviously registered, or clean up a media device instance that was notpreviously initialised.
5.1.3.Entities¶
Entities are represented by astructmedia_entityinstance, defined ininclude/media/media-entity.h. The structure is usuallyembedded into a higher-level structure, such asv4l2_subdev orvideo_deviceinstances, although drivers can allocate entities directly.
Drivers initialize entity pads by callingmedia_entity_pads_init().
Drivers register entities with a media device by callingmedia_device_register_entity()and unregistered by callingmedia_device_unregister_entity().
5.1.4.Interfaces¶
Interfaces are represented by astructmedia_interface instance, defined ininclude/media/media-entity.h. Currently, only one type of interface isdefined: a device node. Such interfaces are represented by astructmedia_intf_devnode.
Drivers initialize and create device node interfaces by callingmedia_devnode_create()and remove them by calling:media_devnode_remove().
5.1.5.Pads¶
Pads are represented by astructmedia_pad instance,defined ininclude/media/media-entity.h. Each entity stores its pads ina pads array managed by the entity driver. Drivers usually embed the array ina driver-specific structure.
Pads are identified by their entity and their 0-based index in the padsarray.
Both information are stored in thestructmedia_pad,making thestructmedia_pad pointer the canonical wayto store and pass link references.
Pads have flags that describe the pad capabilities and state.
MEDIA_PAD_FL_SINK indicates that the pad supports sinking data.MEDIA_PAD_FL_SOURCE indicates that the pad supports sourcing data.
Note
One and only one ofMEDIA_PAD_FL_SINK orMEDIA_PAD_FL_SOURCE mustbe set for each pad.
5.1.6.Links¶
Links are represented by astructmedia_link instance,defined ininclude/media/media-entity.h. There are two types of links:
1. pad to pad links:
Associate two entities via their PADs. Each entity has a list that pointsto all links originating at or targeting any of its pads.A given link is thus stored twice, once in the source entity and once inthe target entity.
Drivers create pad to pad links by calling:media_create_pad_link() and remove withmedia_entity_remove_links().
2. interface to entity links:
Associate one interface to a Link.
Drivers create interface to entity links by calling:media_create_intf_link() and remove withmedia_remove_intf_links().
Note
Links can only be created after having both ends already created.
Links have flags that describe the link capabilities and state. Thevalid values are described atmedia_create_pad_link() andmedia_create_intf_link().
5.1.7.Graph traversal¶
The media framework provides APIs to traverse media graphs, locating connectedentities and links.
To iterate over all entities belonging to a media device, drivers can usethe media_device_for_each_entity macro, defined ininclude/media/media-device.h.
structmedia_entity*entity;media_device_for_each_entity(entity,mdev){// entity will point to each entity in turn...}
Helper functions can be used to find a link between two given pads, or a padconnected to another pad through an enabled link(media_entity_find_link(),media_pad_remote_pad_first(),media_entity_remote_source_pad_unique() andmedia_pad_remote_pad_unique()).
5.1.8.Use count and power handling¶
Due to the wide differences between drivers regarding power managementneeds, the media controller does not implement power management. However,thestructmedia_entity includes ause_countfield that media driverscan use to track the number of users of every entity for power managementneeds.
Themedia_entity.use_count field is owned bymedia drivers and must not betouched by entity drivers. Access to the field must be protected by themedia_device.graph_mutex lock.
5.1.9.Links setup¶
Link properties can be modified at runtime by callingmedia_entity_setup_link().
5.1.10.Pipelines and media streams¶
A media stream is a stream of pixels or metadata originating from one or moresource devices (such as a sensors) and flowing through media entity padstowards the final sinks. The stream can be modified on the route by thedevices (e.g. scaling or pixel format conversions), or it can be split intomultiple branches, or multiple branches can be merged.
A media pipeline is a set of media streams which are interdependent. Thisinterdependency can be caused by the hardware (e.g. configuration of a secondstream cannot be changed if the first stream has been enabled) or by the driverdue to the software design. Most commonly a media pipeline consists of a singlestream which does not branch.
When starting streaming, drivers must notify all entities in the pipeline toprevent link states from being modified during streaming by callingmedia_pipeline_start().
The function will mark all the pads which are part of the pipeline as streaming.
Thestructmedia_pipeline instance pointed to by the pipe argument will bestored in every pad in the pipeline. Drivers should embed thestructmedia_pipeline in higher-level pipeline structures and can then access thepipeline through thestructmedia_pad pipe field.
Calls tomedia_pipeline_start() can be nested.The pipeline pointer must be identical for all nested calls to the function.
media_pipeline_start() may return an error. In that case,it will clean up any of the changes it did by itself.
When stopping the stream, drivers must notify the entities withmedia_pipeline_stop().
If multiple calls tomedia_pipeline_start() have beenmade the same number ofmedia_pipeline_stop() callsare required to stop streaming.Themedia_entity.pipe field is reset toNULL on the lastnested stop call.
Link configuration will fail with-EBUSY by default if either end of thelink is a streaming entity. Links that can be modified while streaming mustbe marked with theMEDIA_LNK_FL_DYNAMIC flag.
If other operations need to be disallowed on streaming entities (such aschanging entities configuration parameters) drivers can explicitly check themedia_entity stream_count field to find out if an entity is streaming. Thisoperation must be done with the media_device graph_mutex held.
5.1.11.Link validation¶
Link validation is performed bymedia_pipeline_start()for any entity which has sink pads in the pipeline. Themedia_entity.link_validate() callback is used for thatpurpose. Inlink_validate() callback, entity driver should checkthat the properties of the source pad of the connected entity and its ownsink pad match. It is up to the type of the entity (and in the end, theproperties of the hardware) what matching actually means.
Subsystems should facilitate link validation by providing subsystem specifichelper functions to provide easy access for commonly needed information, andin the end provide a way to use driver-specific callbacks.
5.1.12.Pipeline traversal¶
Once a pipeline has been constructed withmedia_pipeline_start(),drivers can iterate over entities or pads in the pipeline with the:c:macro:´media_pipeline_for_each_entity` and:c:macro:´media_pipeline_for_each_pad` macros. Iterating over pads isstraightforward:
media_pipeline_pad_iteriter;structmedia_pad*pad;media_pipeline_for_each_pad(pipe,&iter,pad){/* 'pad' will point to each pad in turn */...}
To iterate over entities, the iterator needs to be initialized and cleaned upas an additional steps:
media_pipeline_entity_iteriter;structmedia_entity*entity;intret;ret=media_pipeline_entity_iter_init(pipe,&iter);if(ret)...;media_pipeline_for_each_entity(pipe,&iter,entity){/* 'entity' will point to each entity in turn */...}media_pipeline_entity_iter_cleanup(&iter);
5.1.13.Media Controller Device Allocator API¶
When the media device belongs to more than one driver, the shared mediadevice is allocated with the sharedstructdevice as the key for look ups.
The shared media device should stay in registered state until the lastdriver unregisters it. In addition, the media device should be released whenall the references are released. Each driver gets a reference to the mediadevice during probe, when it allocates the media device. If media device isalready allocated, the allocate API bumps up the refcount and returns theexisting media device. The driver puts the reference back in its disconnectroutine when it callsmedia_device_delete().
The media device is unregistered and cleaned up from the kref put handler toensure that the media device stays in registered state until the last driverunregisters the media device.
Driver Usage
Drivers should use the appropriate media-core routines to manage the sharedmedia device life-time handling the two states:1. allocate -> register -> delete2. get reference to already registered device -> delete
callmedia_device_delete() routine to make sure the shared mediadevice delete is handled correctly.
driver probe:Callmedia_device_usb_allocate() to allocate or get a referenceCallmedia_device_register(), if media devnode isn’t registered
driver disconnect:Callmedia_device_delete() to free the media_device. Freeing ishandled by the kref put handler.
5.1.14.API Definitions¶
- structmedia_entity_notify¶
Media Entity Notify
Definition:
struct media_entity_notify { struct list_head list; void *notify_data; void (*notify)(struct media_entity *entity, void *notify_data);};Members
listList head
notify_dataInput data to invoke the callback
notifyCallback function pointer
Description
Drivers may register a callback to take action when new entities getregistered with the media device. This handler is intended for creatinglinks between existing entities and should not create entities and registerthem.
- structmedia_device_ops¶
Media device operations
Definition:
struct media_device_ops { int (*link_notify)(struct media_link *link, u32 flags, unsigned int notification); struct media_request *(*req_alloc)(struct media_device *mdev); void (*req_free)(struct media_request *req); int (*req_validate)(struct media_request *req); void (*req_queue)(struct media_request *req);};Members
link_notifyLink state change notification callback. This callback iscalled with the graph_mutex held.
req_allocAllocate a request. Set this if you need to allocate a
structlargerthenstructmedia_request.req_alloc andreq_free musteither both be set or both be NULL.req_freeFree a request. Set this ifreq_alloc was set as well, leaveto NULL otherwise.
req_validateValidate a request, but do not queue yet. The req_queue_mutexlock is held when this op is called.
req_queueQueue a validated request, cannot fail. If something goeswrong when queueing this request then it should be markedas such internally in the driver and any related buffersmust eventually return to vb2 with state VB2_BUF_STATE_ERROR.The req_queue_mutex lock is held when this op is called.It is important that vb2 buffer objects are queued last afterall other object types are queued: queueing a buffer kickstartsthe request processing, so all other objects related to therequest (and thus the buffer) must be available to the driver.And once a buffer is queued, then the driver can completeor delete objects from the request before req_queue exits.
- structmedia_device¶
Media device
Definition:
struct media_device { struct device *dev; struct media_devnode *devnode; char model[32]; char driver_name[32]; char serial[40]; char bus_info[32]; u32 hw_revision; u64 topology_version; u32 id; struct ida entity_internal_idx; int entity_internal_idx_max; struct list_head entities; struct list_head interfaces; struct list_head pads; struct list_head links; struct list_head entity_notify; struct mutex graph_mutex; struct media_graph pm_count_walk; void *source_priv; int (*enable_source)(struct media_entity *entity, struct media_pipeline *pipe); void (*disable_source)(struct media_entity *entity); const struct media_device_ops *ops; struct mutex req_queue_mutex; atomic_t request_id;};Members
devParent device
devnodeMedia device node
modelDevice model name
driver_nameOptional device driver name. If not set, calls to
MEDIA_IOC_DEVICE_INFOwill returndev->driver->name.This is needed for USB drivers for example, as otherwisethey’ll all appear as if the driver name was “usb”.serialDevice serial number (optional)
bus_infoUnique and stable device location identifier
hw_revisionHardware device revision
topology_versionMonotonic counter for storing the version of the graphtopology. Should be incremented each time the topology changes.
idUnique ID used on the last registered graph object
entity_internal_idxUnique internal entity ID used by the graph traversalalgorithms
entity_internal_idx_maxAllocated internal entity indices
entitiesList of registered entities
interfacesList of registered interfaces
padsList of registered pads
linksList of registered links
entity_notifyList of registered entity_notify callbacks
graph_mutexProtects access to
structmedia_devicedatapm_count_walkGraph walk for power state walk. Access serialised usinggraph_mutex.
source_privDriver Private data for enable/disable source handlers
enable_sourceEnable Source Handler function pointer
disable_sourceDisable Source Handler function pointer
opsOperation handler callbacks
req_queue_mutexSerialise the MEDIA_REQUEST_IOC_QUEUE ioctl w.r.t.other operations that stop or start streaming.
request_idUsed to generate unique request IDs
Description
This structure represents an abstract high-level media device. It allows easyaccess to entities and provides basic media device-level support. Thestructure can be allocated directly or embedded in a larger structure.
The parentdev is a physical device. It must be set before registering themedia device.
model is a descriptive model name exported through sysfs. It doesn’t have tobe unique.
enable_source is a handler to find source entity for thesink entity and activate the link between them if sourceentity is free. Drivers should call this handler beforeaccessing the source.
disable_source is a handler to find source entity for thesink entity and deactivate the link between them. Driversshould call this handler to release the source.
Use-case: find tuner entity connected to the decoderentity and check if it is available, and activate thelink between them fromenable_source and deactivatefromdisable_source.
Note
Bridge driver is expected to implement and set thehandler whenmedia_device is registered or whenbridge driver finds the media_device during probe.Bridge driver sets source_priv with informationnecessary to runenable_source anddisable_source handlers.Callers should hold graph_mutex to access and callenable_sourceanddisable_source handlers.
- voidmedia_device_init(structmedia_device*mdev)¶
Initializes a media device element
Parameters
structmedia_device*mdevpointer to struct
media_device
Description
This function initializes the media device prior to its registration.The media device initialization and registration is split in two functionsto avoid race conditions and make the media device available to user-spacebefore the media graph has been completed.
So drivers need to first initialize the media device, register any entitywithin the media device, create pad to pad links and then finally registerthe media device by callingmedia_device_register() as a final step.
The caller is responsible for initializing the media device beforeregistration. The following fields must be set:
dev must point to the parent device
model must be filled with the device model name
The bus_info field is set bymedia_device_init() for PCI and platform devicesif the field begins with ‘0’.
- voidmedia_device_cleanup(structmedia_device*mdev)¶
Cleanups a media device element
Parameters
structmedia_device*mdevpointer to struct
media_device
Description
This function that will destroy the graph_mutex that isinitialized inmedia_device_init().
- int__media_device_register(structmedia_device*mdev,structmodule*owner)¶
Registers a media device element
Parameters
structmedia_device*mdevpointer to struct
media_devicestructmodule*ownershould be filled with
THIS_MODULE
Description
Users, should, instead, call themedia_device_register() macro.
The caller is responsible for initializing themedia_device structurebefore registration. The following fields ofmedia_device must be set:
media_device.modelmust be filled with the device model name as aNUL-terminated UTF-8 string. The device/model revision must not bestored in this field.
The following fields are optional:
media_device.serialis a unique serial number stored as aNUL-terminated ASCII string. The field is big enough to store a GUIDin text form. If the hardware doesn’t provide a unique serial numberthis field must be left empty.
media_device.bus_inforepresents the location of the device in thesystem as a NUL-terminated ASCII string. For PCI/PCIe devicesmedia_device.bus_infomust be set to “PCI:” (or “PCIe:”) followed bythe value ofpci_name(). For USB devices,theusb_make_path()functionmust be used. This field is used by applications to distinguish betweenotherwise identical devices that don’t provide a serial number.
media_device.hw_revisionis the hardware device revision in adriver-specific format. When possible the revision should be formattedwith theKERNEL_VERSION()macro.
Note
Upon successful registration a character device named media[0-9]+ is created. The device major and minor numbers are dynamic. The model name is exported as a sysfs attribute.
Unregistering a media device that hasn’t been registered isNOT safe.
Return
returns zero on success or a negative error code.
- media_device_register¶
media_device_register(mdev)
Registers a media device element
Parameters
mdevpointer to struct
media_device
Description
This macro calls__media_device_register() passingTHIS_MODULE asthe__media_device_register() second argument (owner).
- voidmedia_device_unregister(structmedia_device*mdev)¶
Unregisters a media device element
Parameters
structmedia_device*mdevpointer to struct
media_device
Description
It is safe to call this function on an unregistered (but initialised)media device.
- intmedia_device_register_entity(structmedia_device*mdev,structmedia_entity*entity)¶
registers a media entity inside a previously registered media device.
Parameters
structmedia_device*mdevpointer to struct
media_devicestructmedia_entity*entitypointer to struct
media_entityto be registered
Description
Entities are identified by a unique positive integer ID. The mediacontroller framework will such ID automatically. IDs are not guaranteedto be contiguous, and the ID number can change on newer Kernel versions.So, neither the driver nor userspace should hardcode ID numbers to referto the entities, but, instead, use the framework to find the ID, whenneeded.
The media_entity name, type and flags fields should be initialized beforecallingmedia_device_register_entity(). Entities embedded in higher-levelstandard structures can have some of those fields set by the higher-levelframework.
If the device has pads,media_entity_pads_init() should be called beforethis function. Otherwise, themedia_entity.pad andmedia_entity.num_padsshould be zeroed before calling this function.
Entities have flags that describe the entity capabilities and state:
MEDIA_ENT_FL_DEFAULTindicates the default entity for a given type.This can be used to report the default audio and video devices or thedefault camera sensor.
Note
Drivers should set the entity function before calling this function.Please notice that the valuesMEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN andMEDIA_ENT_F_UNKNOWN should not be used by the drivers.
- voidmedia_device_unregister_entity(structmedia_entity*entity)¶
unregisters a media entity.
Parameters
structmedia_entity*entitypointer to struct
media_entityto be unregistered
Description
All links associated with the entity and all PADs are automaticallyunregistered from the media_device when this function is called.
Unregistering an entity will not change the IDs of the other entities andthe previoully used ID will never be reused for a newly registered entities.
When a media device is unregistered, all its entities are unregisteredautomatically. No manual entities unregistration is then required.
Note
The media_entity instance itself must be freed explicitly bythe driver if required.
- voidmedia_device_register_entity_notify(structmedia_device*mdev,structmedia_entity_notify*nptr)¶
Registers a media entity_notify callback
Parameters
structmedia_device*mdevThe media device
structmedia_entity_notify*nptrThe media_entity_notify
Description
Note
When a new entity is registered, all the registeredmedia_entity_notify callbacks are invoked.
- voidmedia_device_unregister_entity_notify(structmedia_device*mdev,structmedia_entity_notify*nptr)¶
Unregister a media entity notify callback
Parameters
structmedia_device*mdevThe media device
structmedia_entity_notify*nptrThe media_entity_notify
- voidmedia_device_pci_init(structmedia_device*mdev,structpci_dev*pci_dev,constchar*name)¶
create and initialize a struct
media_devicefrom a PCI device.
Parameters
structmedia_device*mdevpointer to struct
media_devicestructpci_dev*pci_devpointer to
structpci_devconstchar*namemedia device name. If
NULL, the routine will use the defaultname for the pci device, given bypci_name()macro.
- void__media_device_usb_init(structmedia_device*mdev,structusb_device*udev,constchar*board_name,constchar*driver_name)¶
create and initialize a struct
media_devicefrom a PCI device.
Parameters
structmedia_device*mdevpointer to struct
media_devicestructusb_device*udevpointer to
structusb_deviceconstchar*board_namemedia device name. If
NULL, the routine will use the usbproduct name, if available.constchar*driver_namename of the driver. if
NULL, the routine will use the namegiven byudev->dev->driver->name, with is usually the wrongthing to do.
Description
Note
It is better to callmedia_device_usb_init() instead, assuch macro fills driver_name withKBUILD_MODNAME.
- media_device_usb_init¶
media_device_usb_init(mdev,udev,name)
create and initialize a struct
media_devicefrom a PCI device.
Parameters
mdevpointer to struct
media_deviceudevpointer to
structusb_devicenamemedia device name. If
NULL, the routine will use the usbproduct name, if available.
Description
This macro callsmedia_device_usb_init() passing themedia_device_usb_init()driver_name parameter filled withKBUILD_MODNAME.
Parameters
char*bus_infoVariable where to write the bus info (char array)
size_tbus_info_sizeLength of the bus_info
structdevice*devRelated
structdevice
Description
Sets bus information based ondev. This is currently done for PCI andplatform devices. dev is required to be non-NULL for this to happen.
This function is not meant to be called from drivers.
- structmedia_file_operations¶
Media device file operations
Definition:
struct media_file_operations { struct module *owner; ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); __poll_t (*poll) (struct file *, struct poll_table_struct *); long (*ioctl) (struct file *, unsigned int, unsigned long); long (*compat_ioctl) (struct file *, unsigned int, unsigned long); int (*open) (struct file *); int (*release) (struct file *);};Members
ownershould be filled with
THIS_MODULEreadpointer to the function that implements read() syscall
writepointer to the function that implements write() syscall
pollpointer to the function that implements poll() syscall
ioctlpointer to the function that implements ioctl() syscall
compat_ioctlpointer to the function that will handle 32 bits userspacecalls to the ioctl() syscall on a Kernel compiled with 64 bits.
openpointer to the function that implements open() syscall
releasepointer to the function that will release the resources allocatedby theopen function.
- structmedia_devnode¶
Media device node
Definition:
struct media_devnode { struct media_device *media_dev; const struct media_file_operations *fops; struct device dev; struct cdev cdev; struct device *parent; int minor; unsigned long flags; void (*release)(struct media_devnode *devnode);};Members
media_devpointer to struct
media_devicefopspointer to struct
media_file_operationswith media device opsdevpointer to struct
devicecontaining the media controller devicecdevstructcdevpointer character deviceparentparent device
minordevice node minor number
flagsflags, combination of the
MEDIA_FLAG_*constantsreleaserelease callback called at the end of
media_devnode_release()routine at media-device.c.
Description
This structure represents a media-related device node.
Theparent is a physical device. It must be set by core or device driversbefore registering the node.
- intmedia_devnode_register(structmedia_device*mdev,structmedia_devnode*devnode,structmodule*owner)¶
register a media device node
Parameters
structmedia_device*mdevstructmedia_devicewe want to register a device nodestructmedia_devnode*devnodemedia device node structure we want to register
structmodule*ownershould be filled with
THIS_MODULE
Description
The registration code assigns minor numbers and registers the new device nodewith the kernel. An error is returned if no free minor number can be found,or if the registration of the device node fails.
Zero is returned on success.
Note that if the media_devnode_register call fails, therelease() callback ofthe media_devnode structure isnot called, so the caller is responsible forfreeing any data.
- voidmedia_devnode_unregister_prepare(structmedia_devnode*devnode)¶
clear the media device node register bit
Parameters
structmedia_devnode*devnodethe device node to prepare for unregister
Description
This clears the passed device register bit. Future open calls will be metwith errors. Should be called beforemedia_devnode_unregister() to avoidraces with unregister and device file open calls.
This function can safely be called if the device node has never beenregistered or has already been unregistered.
- voidmedia_devnode_unregister(structmedia_devnode*devnode)¶
unregister a media device node
Parameters
structmedia_devnode*devnodethe device node to unregister
Description
This unregisters the passed device. Future open calls will be met witherrors.
Should be called aftermedia_devnode_unregister_prepare()
- structmedia_devnode*media_devnode_data(structfile*filp)¶
returns a pointer to the
media_devnode
Parameters
structfile*filppointer to struct
file
- intmedia_devnode_is_registered(structmedia_devnode*devnode)¶
returns true if
media_devnodeis registered; false otherwise.
Parameters
structmedia_devnode*devnodepointer to struct
media_devnode.
Note
If mdev is NULL, it also returns false.
- enummedia_gobj_type¶
type of a graph object
Constants
MEDIA_GRAPH_ENTITYIdentify a media entity
MEDIA_GRAPH_PADIdentify a media pad
MEDIA_GRAPH_LINKIdentify a media link
MEDIA_GRAPH_INTF_DEVNODEIdentify a media Kernel API interface viaa device node
- structmedia_gobj¶
Define a graph object.
Definition:
struct media_gobj { struct media_device *mdev; u32 id; struct list_head list;};Members
mdevPointer to the struct
media_devicethat owns the objectidNon-zero object ID identifier. The ID should be uniqueinside a media_device, as it is composed by
MEDIA_BITS_PER_TYPEto store the type plusMEDIA_BITS_PER_IDto store the IDlistList entry stored in one of the per-type mdev object lists
Description
All objects on the media graph should have thisstructembedded
- structmedia_entity_enum¶
An enumeration of media entities.
Definition:
struct media_entity_enum { unsigned long *bmap; int idx_max;};Members
bmapBit map in which each bit represents one entity at
structmedia_entity->internal_idx.idx_maxNumber of bits in bmap
- structmedia_graph¶
Media graph traversal state
Definition:
struct media_graph { struct { struct media_entity *entity; struct list_head *link; } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; struct media_entity_enum ent_enum; int top;};Members
stackGraph traversal stack; the stack contains informationon the path the media entities to be walked and thelinks through which they were reached.
stack.entitypointer to
structmedia_entityat the graph.stack.linkpointer to
structlist_head.ent_enumVisited entities
topThe top of the stack
- structmedia_pipeline¶
Media pipeline related information
Definition:
struct media_pipeline { bool allocated; struct media_device *mdev; struct list_head pads; int start_count;};Members
allocatedMedia pipeline allocated and freed by the framework
mdevThe media device the pipeline is part of
padsList of media_pipeline_pad
start_countMedia pipeline start - stop count
- structmedia_pipeline_pad¶
A pad part of a media pipeline
Definition:
struct media_pipeline_pad { struct list_head list; struct media_pipeline *pipe; struct media_pad *pad;};Members
listEntry in the media_pad pads list
pipeThe media_pipeline that the pad is part of
padThe media pad
Description
This structure associate a pad with a media pipeline. Instances ofmedia_pipeline_pad are created bymedia_pipeline_start() when it builds thepipeline, and stored in themedia_pad.pads list.media_pipeline_stop()removes the entries from the list and deletes them.
- structmedia_pipeline_pad_iter¶
Iterator for media_pipeline_for_each_pad
Definition:
struct media_pipeline_pad_iter { struct list_head *cursor;};Members
cursorThe current element
- structmedia_pipeline_entity_iter¶
Iterator for media_pipeline_for_each_entity
Definition:
struct media_pipeline_entity_iter { struct media_entity_enum ent_enum; struct list_head *cursor;};Members
ent_enumThe entity enumeration tracker
cursorThe current element
- structmedia_link¶
A link object part of a media graph.
Definition:
struct media_link { struct media_gobj graph_obj; struct list_head list; union { struct media_gobj *gobj0; struct media_pad *source; struct media_interface *intf; }; union { struct media_gobj *gobj1; struct media_pad *sink; struct media_entity *entity; }; struct media_link *reverse; unsigned long flags; bool is_backlink;};Members
graph_objEmbedded structure containing the media object common data
listLinked list associated with an entity or an interface thatowns the link.
{unnamed_union}anonymous
gobj0Part of a union. Used to get the pointer for the firstgraph_object of the link.
sourcePart of a union. Used only if the first object (gobj0) isa pad. In that case, it represents the source pad.
intfPart of a union. Used only if the first object (gobj0) isan interface.
{unnamed_union}anonymous
gobj1Part of a union. Used to get the pointer for the secondgraph_object of the link.
sinkPart of a union. Used only if the second object (gobj1) isa pad. In that case, it represents the sink pad.
entityPart of a union. Used only if the second object (gobj1) isan entity.
reversePointer to the link for the reverse direction of a pad to padlink.
flagsLink flags, as defined in uapi/media.h (MEDIA_LNK_FL_*)
is_backlinkIndicate if the link is a backlink.
- enummedia_pad_signal_type¶
type of the signal inside a media pad
Constants
PAD_SIGNAL_DEFAULTDefault signal. Use this when all inputs or all outputs areuniquely identified by the pad number.
PAD_SIGNAL_ANALOGThe pad contains an analog signal. It can be Radio Frequency,Intermediate Frequency, a baseband signal or sub-carriers.Tuner inputs, IF-PLL demodulators, composite and s-video signalsshould use it.
PAD_SIGNAL_DVContains a digital video signal, with can be a bitstream of samplestaken from an analog TV video source. On such case, it usuallycontains the VBI data on it.
PAD_SIGNAL_AUDIOContains an Intermediate Frequency analog signal from an audiosub-carrier or an audio bitstream. IF signals are provided by tunersand consumed by audio AM/FM decoders. Bitstream audio is provided byan audio decoder.
- structmedia_pad¶
A media pad graph object.
Definition:
struct media_pad { struct media_gobj graph_obj; struct media_entity *entity; u16 index; u16 num_links; enum media_pad_signal_type sig_type; unsigned long flags; struct media_pipeline *pipe;};Members
graph_objEmbedded structure containing the media object common data
entityEntity this pad belongs to
indexPad index in the entity pads array, numbered from 0 to n
num_linksNumber of links connected to this pad
sig_typeType of the signal inside a media pad
flagsPad flags, as defined ininclude/uapi/linux/media.h(seek for
MEDIA_PAD_FL_*)pipePipeline this pad belongs to. Use
media_entity_pipeline()toaccess this field.
- structmedia_entity_operations¶
Media entity operations
Definition:
struct media_entity_operations { int (*get_fwnode_pad)(struct media_entity *entity, struct fwnode_endpoint *endpoint); int (*link_setup)(struct media_entity *entity, const struct media_pad *local, const struct media_pad *remote, u32 flags); int (*link_validate)(struct media_link *link); bool (*has_pad_interdep)(struct media_entity *entity, unsigned int pad0, unsigned int pad1);};Members
get_fwnode_padReturn the pad number based on a fwnode endpoint ora negative value on error. This operation can be usedto map a fwnode to a media pad number. Optional.
link_setupNotify the entity of link changes. The operation canreturn an error, in which case link setup will becancelled. Optional.
link_validateReturn whether a link is valid from the entity point ofview. The
media_pipeline_start()functionvalidates all links by calling this operation. Optional.has_pad_interdepReturn whether two pads of the entity areinterdependent. If two pads are interdependent they arepart of the same pipeline and enabling one of the padsmeans that the other pad will become “locked” anddoesn’t allow configuration changes. pad0 and pad1 areguaranteed to not both be sinks or sources. Never callthe .
has_pad_interdep()operation directly, always usemedia_entity_has_pad_interdep().Optional: If the operation isn’t implemented all padswill be considered as interdependent.
Description
Note
Those these callbacks are called with structmedia_device.graph_mutexmutex held.
- enummedia_entity_type¶
Media entity type
Constants
MEDIA_ENTITY_TYPE_BASEThe entity isn’t embedded in another subsystem structure.
MEDIA_ENTITY_TYPE_VIDEO_DEVICEThe entity is embedded in a
structvideo_deviceinstance.MEDIA_ENTITY_TYPE_V4L2_SUBDEVThe entity is embedded in a
structv4l2_subdevinstance.
Description
Media entity objects are often not instantiated directly, but the mediaentity structure is inherited by (through embedding) other subsystem-specificstructures. The media entity type identifies the type of the subclassstructure that implements a media entity instance.
This allows runtime type identification of media entities and safe casting tothe correct object type. For instance, a media entity structure instanceembedded in a v4l2_subdev structure instance will have the typeMEDIA_ENTITY_TYPE_V4L2_SUBDEV and can safely be cast to av4l2_subdevstructure using thecontainer_of() macro.
- structmedia_entity¶
A media entity graph object.
Definition:
struct media_entity { struct media_gobj graph_obj; const char *name; enum media_entity_type obj_type; u32 function; unsigned long flags; u16 num_pads; u16 num_links; u16 num_backlinks; int internal_idx; struct media_pad *pads; struct list_head links; const struct media_entity_operations *ops; int use_count; union { struct { u32 major; u32 minor; } dev; } info;};Members
graph_objEmbedded structure containing the media object common data.
nameEntity name.
obj_typeType of the object that implements the media_entity.
functionEntity main function, as defined ininclude/uapi/linux/media.h(seek for
MEDIA_ENT_F_*)flagsEntity flags, as defined ininclude/uapi/linux/media.h(seek for
MEDIA_ENT_FL_*)num_padsNumber of sink and source pads.
num_linksTotal number of links, forward and back, enabled and disabled.
num_backlinksNumber of backlinks
internal_idxAn unique internal entity specific number. The numbers arere-used if entities are unregistered or registered again.
padsPads array with the size defined bynum_pads.
linksList of data links.
opsEntity operations.
use_countUse count for the entity.
infoUnion with devnode information. Kept just for backwardcompatibility.
info.devContains device major and minor info.
info.dev.majordevice node major, if the device is a devnode.
info.dev.minordevice node minor, if the device is a devnode.
Description
Note
Theuse_count reference count must never be negative, but is a signedinteger on purpose: a simpleWARN_ON(<0) check can be used to detectreference count bugs that would make it negative.
- media_entity_for_each_pad¶
media_entity_for_each_pad(entity,iter)
Iterate on all pads in an entity
Parameters
entityThe entity the pads belong to
iterThe iterator pad
Description
Iterate on all pads in a media entity.
- structmedia_interface¶
A media interface graph object.
Definition:
struct media_interface { struct media_gobj graph_obj; struct list_head links; u32 type; u32 flags;};Members
graph_objembedded graph object
linksList of links pointing to graph entities
typeType of the interface as defined ininclude/uapi/linux/media.h(seek for
MEDIA_INTF_T_*)flagsInterface flags as defined ininclude/uapi/linux/media.h(seek for
MEDIA_INTF_FL_*)
Description
Note
Currently, no flags formedia_interface is defined.
- structmedia_intf_devnode¶
A media interface via a device node.
Definition:
struct media_intf_devnode { struct media_interface intf; u32 major; u32 minor;};Members
intfembedded interface object
majorMajor number of a device node
minorMinor number of a device node
- u32media_entity_id(structmedia_entity*entity)¶
return the media entity graph object id
Parameters
structmedia_entity*entitypointer to
media_entity
- enummedia_gobj_typemedia_type(structmedia_gobj*gobj)¶
return the media object type
Parameters
structmedia_gobj*gobjPointer to the struct
media_gobjgraph object
- u32media_id(structmedia_gobj*gobj)¶
return the media object ID
Parameters
structmedia_gobj*gobjPointer to the struct
media_gobjgraph object
- u32media_gobj_gen_id(enummedia_gobj_typetype,u64local_id)¶
encapsulates type and ID on at the object ID
Parameters
enummedia_gobj_typetypeobject type as define at enum
media_gobj_type.u64local_idnext ID, from struct
media_device.id.
- boolis_media_entity_v4l2_video_device(structmedia_entity*entity)¶
Check if the entity is a video_device
Parameters
structmedia_entity*entitypointer to entity
Return
true if the entity is an instance of a video_device object and cansafely be cast to astructvideo_device using thecontainer_of() macro, orfalse otherwise.
- boolis_media_entity_v4l2_subdev(structmedia_entity*entity)¶
Check if the entity is a v4l2_subdev
Parameters
structmedia_entity*entitypointer to entity
Return
true if the entity is an instance of av4l2_subdev object and cansafely be cast to a structv4l2_subdev using thecontainer_of() macro, orfalse otherwise.
- intmedia_entity_enum_init(structmedia_entity_enum*ent_enum,structmedia_device*mdev)¶
Initialise an entity enumeration
Parameters
structmedia_entity_enum*ent_enumEntity enumeration to be initialised
structmedia_device*mdevThe related media device
Return
zero on success or a negative error code.
- voidmedia_entity_enum_cleanup(structmedia_entity_enum*ent_enum)¶
Release resources of an entity enumeration
Parameters
structmedia_entity_enum*ent_enumEntity enumeration to be released
- voidmedia_entity_enum_zero(structmedia_entity_enum*ent_enum)¶
Clear the entire enum
Parameters
structmedia_entity_enum*ent_enumEntity enumeration to be cleared
- voidmedia_entity_enum_set(structmedia_entity_enum*ent_enum,structmedia_entity*entity)¶
Mark a single entity in the enum
Parameters
structmedia_entity_enum*ent_enumEntity enumeration
structmedia_entity*entityEntity to be marked
- voidmedia_entity_enum_clear(structmedia_entity_enum*ent_enum,structmedia_entity*entity)¶
Unmark a single entity in the enum
Parameters
structmedia_entity_enum*ent_enumEntity enumeration
structmedia_entity*entityEntity to be unmarked
- boolmedia_entity_enum_test(structmedia_entity_enum*ent_enum,structmedia_entity*entity)¶
Test whether the entity is marked
Parameters
structmedia_entity_enum*ent_enumEntity enumeration
structmedia_entity*entityEntity to be tested
Description
Returnstrue if the entity was marked.
- boolmedia_entity_enum_test_and_set(structmedia_entity_enum*ent_enum,structmedia_entity*entity)¶
Test whether the entity is marked, and mark it
Parameters
structmedia_entity_enum*ent_enumEntity enumeration
structmedia_entity*entityEntity to be tested
Description
Returnstrue if the entity was marked, and mark it before doing so.
- boolmedia_entity_enum_empty(structmedia_entity_enum*ent_enum)¶
Test whether the entire
enumisempty
Parameters
structmedia_entity_enum*ent_enumEntity enumeration
Return
true if the entity was empty.
- boolmedia_entity_enum_intersects(structmedia_entity_enum*ent_enum1,structmedia_entity_enum*ent_enum2)¶
Test whether two enums intersect
Parameters
structmedia_entity_enum*ent_enum1First entity enumeration
structmedia_entity_enum*ent_enum2Second entity enumeration
Return
true if entity enumerationsent_enum1 andent_enum2 intersect,otherwisefalse.
- gobj_to_entity¶
gobj_to_entity(gobj)
returns the struct
media_entitypointer from thegobj contained on it.
Parameters
gobjPointer to the struct
media_gobjgraph object
- gobj_to_pad¶
gobj_to_pad(gobj)
returns the struct
media_padpointer from thegobj contained on it.
Parameters
gobjPointer to the struct
media_gobjgraph object
- gobj_to_link¶
gobj_to_link(gobj)
returns the struct
media_linkpointer from thegobj contained on it.
Parameters
gobjPointer to the struct
media_gobjgraph object
- gobj_to_intf¶
gobj_to_intf(gobj)
returns the struct
media_interfacepointer from thegobj contained on it.
Parameters
gobjPointer to the struct
media_gobjgraph object
- intf_to_devnode¶
intf_to_devnode(intf)
returns the
structmedia_intf_devnodepointer from theintf contained on it.
Parameters
intfPointer to struct
media_intf_devnode
- voidmedia_gobj_create(structmedia_device*mdev,enummedia_gobj_typetype,structmedia_gobj*gobj)¶
Initialize a graph object
Parameters
structmedia_device*mdevPointer to the
media_devicethat contains the objectenummedia_gobj_typetypeType of the object
structmedia_gobj*gobjPointer to the struct
media_gobjgraph object
Description
This routine initializes the embedded structmedia_gobj inside amedia graph object. It is called automatically ifmedia_*_createfunction calls are used. However, if the object (entity, link, pad,interface) is embedded on some other object, this function should becalled before registering the object at the media controller.
- voidmedia_gobj_destroy(structmedia_gobj*gobj)¶
Stop using a graph object on a media device
Parameters
structmedia_gobj*gobjPointer to the struct
media_gobjgraph object
Description
This should be called by all routines likemedia_device_unregister()that remove/destroy media graph objects.
- intmedia_entity_pads_init(structmedia_entity*entity,u16num_pads,structmedia_pad*pads)¶
Initialize the entity pads
Parameters
structmedia_entity*entityentity where the pads belong
u16num_padstotal number of sink and source pads
structmedia_pad*padsArray ofnum_pads pads.
Description
The pads array is managed by the entity driver and passed tomedia_entity_pads_init() where its pointer will be stored in themedia_entity structure.
If no pads are needed, drivers could either directly fillmedia_entity->num_pads with 0 andmedia_entity->pads withNULL or callthis function that will do the same.
As the number of pads is known in advance, the pads array is not allocateddynamically but is managed by the entity driver. Most drivers will embed thepads array in a driver-specific structure, avoiding dynamic allocation.
Drivers must set the direction of every pad in the pads array before callingmedia_entity_pads_init(). The function will initialize the other pads fields.
- voidmedia_entity_cleanup(structmedia_entity*entity)¶
free resources associated with an entity
Parameters
structmedia_entity*entityentity where the pads belong
Description
This function must be called during the cleanup phase after unregisteringthe entity (currently, it does nothing).
Callingmedia_entity_cleanup() on a media_entity whose memory has beenzeroed but that has not been initialized withmedia_entity_pad_init() isvalid and is a no-op.
- intmedia_get_pad_index(structmedia_entity*entity,u32pad_type,enummedia_pad_signal_typesig_type)¶
retrieves a pad index from an entity
Parameters
structmedia_entity*entityentity where the pads belong
u32pad_typethe type of the pad, one of MEDIA_PAD_FL_* pad types
enummedia_pad_signal_typesig_typetype of signal of the pad to be search
Description
This helper function finds the first pad index inside an entity thatsatisfies bothis_sink andsig_type conditions.
On success, return the pad number. If the pad was not found or the mediaentity is a NULL pointer, return -EINVAL.
- intmedia_create_pad_link(structmedia_entity*source,u16source_pad,structmedia_entity*sink,u16sink_pad,u32flags)¶
creates a link between two entities.
Parameters
structmedia_entity*sourcepointer to
media_entityof the source pad.u16source_padnumber of the source pad in the pads array
structmedia_entity*sinkpointer to
media_entityof the sink pad.u16sink_padnumber of the sink pad in the pads array.
u32flagsLink flags, as defined ininclude/uapi/linux/media.h( seek for
MEDIA_LNK_FL_*)
Description
Valid values for flags:
MEDIA_LNK_FL_ENABLEDIndicates that the link is enabled and can be used to transfer media data.When two or more links target a sink pad, only one of them can beenabled at a time.
MEDIA_LNK_FL_IMMUTABLEIndicates that the link enabled state can’t be modified at runtime. If
MEDIA_LNK_FL_IMMUTABLEis set, thenMEDIA_LNK_FL_ENABLEDmust also beset, since an immutable link is always enabled.
Note
Before calling this function,media_entity_pads_init() andmedia_device_register_entity() should be called previously for both ends.
- intmedia_create_pad_links(conststructmedia_device*mdev,constu32source_function,structmedia_entity*source,constu16source_pad,constu32sink_function,structmedia_entity*sink,constu16sink_pad,u32flags,constboolallow_both_undefined)¶
creates a link between two entities.
Parameters
conststructmedia_device*mdevPointer to the media_device that contains the object
constu32source_functionFunction of the source entities. Used only ifsource isNULL.
structmedia_entity*sourcepointer to
media_entityof the source pad. If NULL, it will useall entities that matches thesink_function.constu16source_padnumber of the source pad in the pads array
constu32sink_functionFunction of the sink entities. Used only ifsink is NULL.
structmedia_entity*sinkpointer to
media_entityof the sink pad. If NULL, it will useall entities that matches thesink_function.constu16sink_padnumber of the sink pad in the pads array.
u32flagsLink flags, as defined in include/uapi/linux/media.h.
constboolallow_both_undefinedif
true, then bothsource andsink can be NULL.In such case, it will create a crossbar between all entities thatmatchessource_function to all entities that matchessink_function.Iffalse, it will return 0 and won’t create any link if bothsourceandsink are NULL.
Description
Valid values for flags:
- A
MEDIA_LNK_FL_ENABLEDflag indicates that the link is enabled and can be used to transfer media data. If multiple links are created and thisflag is passed as an argument, only the first created link will havethis flag.
- A
MEDIA_LNK_FL_IMMUTABLEflag indicates that the link enabled state can’t be modified at runtime. If
MEDIA_LNK_FL_IMMUTABLEis set, thenMEDIA_LNK_FL_ENABLEDmust also be set since an immutable link isalways enabled.
It is common for some devices to have multiple source and/or sink entitiesof the same type that should be linked. Whilemedia_create_pad_link()creates link by link, this function is meant to allow 1:n, n:1 and evencross-bar (n:n) links.
Note
Before calling this function,media_entity_pads_init() andmedia_device_register_entity() should be called previously for theentities to be linked.
- voidmedia_entity_remove_links(structmedia_entity*entity)¶
remove all links associated with an entity
Parameters
structmedia_entity*entitypointer to
media_entity
Description
Note
This is called automatically when an entity is unregistered viamedia_device_register_entity().
- int__media_entity_setup_link(structmedia_link*link,u32flags)¶
Configure a media link without locking
Parameters
structmedia_link*linkThe link being configured
u32flagsLink configuration flags
Description
The bulk of link setup is handled by the two entities connected through thelink. This function notifies both entities of the link configuration change.
If the link is immutable or if the current and new configuration areidentical, return immediately.
The user is expected to hold link->source->parent->mutex. If not,media_entity_setup_link() should be used instead.
- intmedia_entity_setup_link(structmedia_link*link,u32flags)¶
changes the link flags properties in runtime
Parameters
structmedia_link*linkpointer to
media_linku32flagsthe requested new link flags
Description
The only configurable property is theMEDIA_LNK_FL_ENABLED link flagto enable/disable a link. Links marked with theMEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled.
When a link is enabled or disabled, the media framework calls thelink_setup operation for the two entities at the source and sink of thelink, in that order. If the second link_setup call fails, anotherlink_setup call is made on the first entity to restore the original linkflags.
Media device drivers can be notified of link setup operations by setting themedia_device.link_notify pointer to a callback function. If provided, thenotification callback will be called before enabling and after disablinglinks.
Entity drivers must implement the link_setup operation if any of their linksis non-immutable. The operation must either configure the hardware or storethe configuration information to be applied later.
Link configuration must not have any side effect on other links. If anenabled link at a sink pad prevents another link at the same pad frombeing enabled, the link_setup operation must return-EBUSY and can’timplicitly disable the first enabled link.
Note
The valid values of the flags for the link is the same as describedonmedia_create_pad_link(), for pad to pad links or the same as describedonmedia_create_intf_link(), for interface to entity links.
- structmedia_link*media_entity_find_link(structmedia_pad*source,structmedia_pad*sink)¶
Find a link between two pads
Parameters
structmedia_pad*sourceSource pad
structmedia_pad*sinkSink pad
Return
returns a pointer to the link between the two entities. If nosuch link exists, returnNULL.
- structmedia_pad*media_pad_remote_pad_first(conststructmedia_pad*pad)¶
Find the first pad at the remote end of a link
Parameters
conststructmedia_pad*padPad at the local end of the link
Description
Search for a remote pad connected to the given pad by iterating over alllinks originating or terminating at that pad until an enabled link is found.
Return
returns a pointer to the pad at the remote end of the first foundenabled link, orNULL if no enabled link has been found.
- structmedia_pad*media_pad_remote_pad_unique(conststructmedia_pad*pad)¶
Find a remote pad connected to a pad
Parameters
conststructmedia_pad*padThe pad
Description
Search for and return a remote pad connected topad through an enabledlink. If multiple (or no) remote pads are found, an error is returned.
The uniqueness constraint makes this helper function suitable for entitiesthat support a single active source at a time on a given pad.
-ENOTUNIQ - Multiple links are enabled
-ENOLINK - No connected pad found
Return
A pointer to the remote pad, or one of the following error pointersif an error occurs:
- structmedia_pad*media_entity_remote_pad_unique(conststructmedia_entity*entity,unsignedinttype)¶
Find a remote pad connected to an entity
Parameters
conststructmedia_entity*entityThe entity
unsignedinttypeThe type of pad to find (MEDIA_PAD_FL_SINK or MEDIA_PAD_FL_SOURCE)
Description
Search for and return a remote pad oftype connected toentity through anenabled link. If multiple (or no) remote pads match these criteria, an erroris returned.
The uniqueness constraint makes this helper function suitable for entitiesthat support a single active source or sink at a time.
-ENOTUNIQ - Multiple links are enabled
-ENOLINK - No connected pad found
Return
A pointer to the remote pad, or one of the following error pointersif an error occurs:
- structmedia_pad*media_entity_remote_source_pad_unique(conststructmedia_entity*entity)¶
Find a remote source pad connected to an entity
Parameters
conststructmedia_entity*entityThe entity
Description
Search for and return a remote source pad connected toentity through anenabled link. If multiple (or no) remote pads match these criteria, an erroris returned.
The uniqueness constraint makes this helper function suitable for entitiesthat support a single active source at a time.
-ENOTUNIQ - Multiple links are enabled
-ENOLINK - No connected pad found
Return
A pointer to the remote pad, or one of the following error pointersif an error occurs:
Parameters
conststructmedia_pad*padThe pad
Return
True if the pad is part of a pipeline started with themedia_pipeline_start() function, false otherwise.
- boolmedia_entity_is_streaming(conststructmedia_entity*entity)¶
Test if an entity is part of a streaming pipeline
Parameters
conststructmedia_entity*entityThe entity
Return
True if the entity is part of a pipeline started with themedia_pipeline_start() function, false otherwise.
- structmedia_pipeline*media_entity_pipeline(structmedia_entity*entity)¶
Get the media pipeline an entity is part of
Parameters
structmedia_entity*entityThe entity
Description
DEPRECATED: usemedia_pad_pipeline() instead.
This function returns the media pipeline that an entity has been associatedwith when constructing the pipeline withmedia_pipeline_start(). The pointerremains valid untilmedia_pipeline_stop() is called.
In general, entities can be part of multiple pipelines, when carryingmultiple streams (either on different pads, or on the same pad usingmultiplexed streams). This function is to be used only for entities thatdo not support multiple pipelines.
Return
The media_pipeline the entity is part of, or NULL if the entity isnot part of any pipeline.
- structmedia_pipeline*media_pad_pipeline(structmedia_pad*pad)¶
Get the media pipeline a pad is part of
Parameters
structmedia_pad*padThe pad
Description
This function returns the media pipeline that a pad has been associatedwith when constructing the pipeline withmedia_pipeline_start(). The pointerremains valid untilmedia_pipeline_stop() is called.
Return
The media_pipeline the pad is part of, or NULL if the pad isnot part of any pipeline.
- intmedia_entity_get_fwnode_pad(structmedia_entity*entity,conststructfwnode_handle*fwnode,unsignedlongdirection_flags)¶
Get pad number from fwnode
Parameters
structmedia_entity*entityThe entity
conststructfwnode_handle*fwnodePointer to the fwnode_handle which should be used to find the pad
unsignedlongdirection_flagsExpected direction of the pad, as defined ininclude/uapi/linux/media.h(seek for
MEDIA_PAD_FL_*)
Description
This function can be used to resolve the media pad number froma fwnode. This is useful for devices which use more complexmappings of media pads.
If the entity does not implement theget_fwnode_pad() operationthen this function searches the entity for the first pad thatmatches thedirection_flags.
Return
returns the pad number on success or a negative error code.
- intmedia_graph_walk_init(structmedia_graph*graph,structmedia_device*mdev)¶
Allocate resources used by graph walk.
Parameters
structmedia_graph*graphMedia graph structure that will be used to walk the graph
structmedia_device*mdevPointer to the
media_devicethat contains the object
Description
This function is deprecated, usemedia_pipeline_for_each_pad() instead.
The caller is required to hold the media_device graph_mutex during the graphwalk until the graph state is released.
Returns zero on success or a negative error code otherwise.
- voidmedia_graph_walk_cleanup(structmedia_graph*graph)¶
Release resources used by graph walk.
Parameters
structmedia_graph*graphMedia graph structure that will be used to walk the graph
Description
This function is deprecated, usemedia_pipeline_for_each_pad() instead.
- voidmedia_graph_walk_start(structmedia_graph*graph,structmedia_entity*entity)¶
Start walking the media graph at a given entity
Parameters
structmedia_graph*graphMedia graph structure that will be used to walk the graph
structmedia_entity*entityStarting entity
Description
This function is deprecated, usemedia_pipeline_for_each_pad() instead.
Before using this function,media_graph_walk_init() must beused to allocate resources used for walking the graph. Thisfunction initializes the graph traversal structure to walk theentities graph starting at the given entity. The traversalstructure must not be modified by the caller during graphtraversal. After the graph walk, the resources must be releasedusingmedia_graph_walk_cleanup().
- structmedia_entity*media_graph_walk_next(structmedia_graph*graph)¶
Get the next entity in the graph
Parameters
structmedia_graph*graphMedia graph structure
Description
This function is deprecated, usemedia_pipeline_for_each_pad() instead.
Perform a depth-first traversal of the given media entities graph.
The graph structure must have been previously initialized with a call tomedia_graph_walk_start().
Return
returns the next entity in the graph orNULL if the whole graphhave been traversed.
- intmedia_pipeline_start(structmedia_pad*origin,structmedia_pipeline*pipe)¶
Mark a pipeline as streaming
Parameters
structmedia_pad*originStarting pad
structmedia_pipeline*pipeMedia pipeline to be assigned to all pads in the pipeline.
Description
Mark all pads connected to padorigin through enabled links, eitherdirectly or indirectly, as streaming. The given pipeline object is assignedto every pad in the pipeline and stored in the media_pad pipe field.
Calls to this function can be nested, in which case the same number ofmedia_pipeline_stop() calls will be required to stop streaming. Thepipeline pointer must be identical for all nested calls tomedia_pipeline_start().
- int__media_pipeline_start(structmedia_pad*origin,structmedia_pipeline*pipe)¶
Mark a pipeline as streaming
Parameters
structmedia_pad*originStarting pad
structmedia_pipeline*pipeMedia pipeline to be assigned to all pads in the pipeline.
Description
..note:: This is the non-locking version ofmedia_pipeline_start()
Parameters
structmedia_pad*padStarting pad
Description
Mark all pads connected to a given pad through enabled links, eitherdirectly or indirectly, as not streaming. The media_pad pipe field isreset toNULL.
If multiple calls tomedia_pipeline_start() have been made, the samenumber of calls to this function are required to mark the pipeline as notstreaming.
Parameters
structmedia_pad*padStarting pad
Description
Note
This is the non-locking version ofmedia_pipeline_stop()
- media_pipeline_for_each_pad¶
media_pipeline_for_each_pad(pipe,iter,pad)
Iterate on all pads in a media pipeline
Parameters
pipeThe pipeline
iterThe iterator (
structmedia_pipeline_pad_iter)padThe iterator pad
Description
Iterate on all pads in a media pipeline. This is only valid after thepipeline has been built withmedia_pipeline_start() and before it getsdestroyed withmedia_pipeline_stop().
- intmedia_pipeline_entity_iter_init(structmedia_pipeline*pipe,structmedia_pipeline_entity_iter*iter)¶
Initialize a pipeline entity iterator
Parameters
structmedia_pipeline*pipeThe pipeline
structmedia_pipeline_entity_iter*iterThe iterator
Description
This function must be called to initialize the iterator before using it in amedia_pipeline_for_each_entity() loop. The iterator must be destroyed by acall to media_pipeline_entity_iter_cleanup after the loop (including in codepaths that break from the loop).
The same iterator can be used in multiple consecutive loops without beingdestroyed and reinitialized.
Return
0 on success or a negative error code otherwise.
- voidmedia_pipeline_entity_iter_cleanup(structmedia_pipeline_entity_iter*iter)¶
Destroy a pipeline entity iterator
Parameters
structmedia_pipeline_entity_iter*iterThe iterator
Description
This function must be called to destroy iterators initialized withmedia_pipeline_entity_iter_init().
- media_pipeline_for_each_entity¶
media_pipeline_for_each_entity(pipe,iter,entity)
Iterate on all entities in a media pipeline
Parameters
pipeThe pipeline
iterThe iterator (
structmedia_pipeline_entity_iter)entityThe iterator entity
Description
Iterate on all entities in a media pipeline. This is only valid after thepipeline has been built withmedia_pipeline_start() and before it getsdestroyed withmedia_pipeline_stop(). The iterator must be initialized withmedia_pipeline_entity_iter_init() before iteration, and destroyed withmedia_pipeline_entity_iter_cleanup() after (including in code paths thatbreak from the loop).
Parameters
structmedia_pad*padStarting pad
Description
media_pipeline_alloc_start() is similar tomedia_pipeline_start() but insteadof working on a given pipeline the function will use an existing pipeline ifthe pad is already part of a pipeline, or allocate a new pipeline.
Calls tomedia_pipeline_alloc_start() must be matched withmedia_pipeline_stop().
- structmedia_intf_devnode*media_devnode_create(structmedia_device*mdev,u32type,u32flags,u32major,u32minor)¶
creates and initializes a device node interface
Parameters
structmedia_device*mdevpointer to struct
media_deviceu32typetype of the interface, as given byinclude/uapi/linux/media.h( seek for
MEDIA_INTF_T_*) macros.u32flagsInterface flags, as defined ininclude/uapi/linux/media.h( seek for
MEDIA_INTF_FL_*)u32majorDevice node major number.
u32minorDevice node minor number.
Return
if succeeded, returns a pointer to the newly allocatedmedia_intf_devnode pointer.
Description
Note
Currently, no flags formedia_interface is defined.
- voidmedia_devnode_remove(structmedia_intf_devnode*devnode)¶
removes a device node interface
Parameters
structmedia_intf_devnode*devnodepointer to
media_intf_devnodeto be freed.
Description
When a device node interface is removed, all links to it are automaticallyremoved.
- structmedia_link*media_create_intf_link(structmedia_entity*entity,structmedia_interface*intf,u32flags)¶
creates a link between an entity and an interface
Parameters
structmedia_entity*entitypointer to
media_entitystructmedia_interface*intfpointer to
media_interfaceu32flagsLink flags, as defined ininclude/uapi/linux/media.h( seek for
MEDIA_LNK_FL_*)
Description
Valid values for flags:
MEDIA_LNK_FL_ENABLEDIndicates that the interface is connected to the entity hardware.That’s the default value for interfaces. An interface may be disabled ifthe hardware is busy due to the usage of some other interface that it iscurrently controlling the hardware.
A typical example is an hybrid TV device that handle only one type ofstream on a given time. So, when the digital TV is streaming,the V4L2 interfaces won’t be enabled, as such device is not able toalso stream analog TV or radio.
Note
Before calling this function,media_devnode_create() should be called forthe interface andmedia_device_register_entity() should be called for theinterface that will be part of the link.
- void__media_remove_intf_link(structmedia_link*link)¶
remove a single interface link
Parameters
structmedia_link*linkpointer to
media_link.
Description
Note
This is an unlocked version ofmedia_remove_intf_link()
- voidmedia_remove_intf_link(structmedia_link*link)¶
remove a single interface link
Parameters
structmedia_link*linkpointer to
media_link.
Description
Note
Prefer to use this one, instead of__media_remove_intf_link()
- void__media_remove_intf_links(structmedia_interface*intf)¶
remove all links associated with an interface
Parameters
structmedia_interface*intfpointer to
media_interface
Description
Note
This is an unlocked version ofmedia_remove_intf_links().
- voidmedia_remove_intf_links(structmedia_interface*intf)¶
remove all links associated with an interface
Parameters
structmedia_interface*intfpointer to
media_interface
Description
Note
This is called automatically when an entity is unregistered via
media_device_register_entity()and bymedia_devnode_remove().Prefer to use this one, instead of
__media_remove_intf_links().
- media_entity_call¶
media_entity_call(entity,operation,args...)
Calls a
structmedia_entity_operationsoperation on an entity
Parameters
entityentity where theoperation will be called
operationtype of the operation. Should be the name of a member ofstruct
media_entity_operations.args...variable arguments
Description
This helper function will check ifoperation is notNULL. On such case,it will issue a call tooperation(entity,args).
- structmedia_link*media_create_ancillary_link(structmedia_entity*primary,structmedia_entity*ancillary)¶
create an ancillary link between two instances of
media_entity
Parameters
structmedia_entity*primarypointer to the primary
media_entitystructmedia_entity*ancillarypointer to the ancillary
media_entity
Description
Create an ancillary link between two entities, indicating that theyrepresent two connected pieces of hardware that form a single logical unit.A typical example is a camera lens controller being linked to the sensor thatit is supporting.
The function sets both MEDIA_LNK_FL_ENABLED and MEDIA_LNK_FL_IMMUTABLE forthe new link.
- structmedia_link*__media_entity_next_link(structmedia_entity*entity,structmedia_link*link,unsignedlonglink_type)¶
Iterate through a
media_entity’s links
Parameters
structmedia_entity*entitypointer to the
media_entitystructmedia_link*linkpointer to a
media_linkto hold the iterated valuesunsignedlonglink_typeone of the MEDIA_LNK_FL_LINK_TYPE flags
Description
Return the next link against an entity matching a specific link type. Thisallows iteration through an entity’s links whilst guaranteeing all of thereturned links are of the given type.
- for_each_media_entity_data_link¶
for_each_media_entity_data_link(entity,link)
Iterate through an entity’s data links
Parameters
entitypointer to the
media_entitylinkpointer to a
media_linkto hold the iterated values
Description
Iterate over amedia_entity’s data links
- enummedia_request_state¶
media request state
Constants
MEDIA_REQUEST_STATE_IDLEIdle
MEDIA_REQUEST_STATE_VALIDATINGValidating the request, no state changesallowed
MEDIA_REQUEST_STATE_QUEUEDQueued
MEDIA_REQUEST_STATE_COMPLETECompleted, the request is done
MEDIA_REQUEST_STATE_CLEANINGCleaning, the request is being re-inited
MEDIA_REQUEST_STATE_UPDATINGThe request is being updated, i.e.request objects are being added,modified or removed
NR_OF_MEDIA_REQUEST_STATEThe number of media request states, usedinternally for sanity check purposes
- structmedia_request¶
Media device request
Definition:
struct media_request { struct media_device *mdev; struct kref kref; char debug_str[TASK_COMM_LEN + 11]; enum media_request_state state; unsigned int updating_count; unsigned int access_count; struct list_head objects; unsigned int num_incomplete_objects; wait_queue_head_t poll_wait; spinlock_t lock;};Members
mdevMedia device this request belongs to
krefReference count
debug_strPrefix for debug messages (process name:fd)
stateThe state of the request
updating_countcount the number of request updates that are in progress
access_countcount the number of request accesses that are in progress
objectsList ofstruct media_request_object request objects
num_incomplete_objectsThe number of incomplete objects in the request
poll_waitWait queue for poll
lockSerializes access to this struct
- intmedia_request_lock_for_access(structmedia_request*req)¶
Lock the request to access its objects
Parameters
structmedia_request*reqThe media request
Description
Use before accessing a completed request. A reference to the request mustbe held during the access. This usually takes place automatically througha file handle. Usemedia_request_unlock_for_access when done.
- voidmedia_request_unlock_for_access(structmedia_request*req)¶
Unlock a request previously locked for access
Parameters
structmedia_request*reqThe media request
Description
Unlock a request that has previously been locked usingmedia_request_lock_for_access.
- intmedia_request_lock_for_update(structmedia_request*req)¶
Lock the request for updating its objects
Parameters
structmedia_request*reqThe media request
Description
Use before updating a request, i.e. adding, modifying or removing a requestobject in it. A reference to the request must be held during the update. Thisusually takes place automatically through a file handle. Usemedia_request_unlock_for_update when done.
- voidmedia_request_unlock_for_update(structmedia_request*req)¶
Unlock a request previously locked for update
Parameters
structmedia_request*reqThe media request
Description
Unlock a request that has previously been locked usingmedia_request_lock_for_update.
- voidmedia_request_get(structmedia_request*req)¶
Get the media request
Parameters
structmedia_request*reqThe media request
Description
Get the media request.
- voidmedia_request_put(structmedia_request*req)¶
Put the media request
Parameters
structmedia_request*reqThe media request
Description
Put the media request. The media request will be releasedwhen the refcount reaches 0.
- structmedia_request*media_request_get_by_fd(structmedia_device*mdev,intrequest_fd)¶
Get a media request by fd
Parameters
structmedia_device*mdevMedia device this request belongs to
intrequest_fdThe file descriptor of the request
Description
Get the request represented byrequest_fd that is ownedby the media device.
Return a -EBADR error pointer if requests are not supportedby this driver. Return -EINVAL if the request was not found.Return the pointer to the request if found: the caller willhave to callmedia_request_put when it finished using therequest.
- intmedia_request_alloc(structmedia_device*mdev,int*alloc_fd)¶
Allocate the media request
Parameters
structmedia_device*mdevMedia device this request belongs to
int*alloc_fdStore the request’s file descriptor in this int
Description
Allocated the media request and put the fd inalloc_fd.
- structmedia_request_object_ops¶
Media request object operations
Definition:
struct media_request_object_ops { int (*prepare)(struct media_request_object *object); void (*unprepare)(struct media_request_object *object); void (*queue)(struct media_request_object *object); void (*unbind)(struct media_request_object *object); void (*release)(struct media_request_object *object);};Members
prepareValidate and prepare the request object, optional.
unprepareUnprepare the request object, optional.
queueQueue the request object, optional.
unbindUnbind the request object, optional.
releaseRelease the request object, required.
- structmedia_request_object¶
An opaque object that belongs to a media request
Definition:
struct media_request_object { const struct media_request_object_ops *ops; void *priv; struct media_request *req; struct list_head list; struct kref kref; bool completed;};Members
opsobject’s operations
privobject’s priv pointer
reqthe request this object belongs to (can be NULL)
listList entry of the object forstruct media_request
krefReference count of the object, acquire before releasing req->lock
completedIf true, then this object was completed.
Description
An object related to the request. Thisstructis always embedded inanotherstructthat contains the actual data for this request object.
- voidmedia_request_object_get(structmedia_request_object*obj)¶
Get a media request object
Parameters
structmedia_request_object*objThe object
Description
Get a media request object.
- voidmedia_request_object_put(structmedia_request_object*obj)¶
Put a media request object
Parameters
structmedia_request_object*objThe object
Description
Put a media request object. Once all references are gone, theobject’s memory is released.
- structmedia_request_object*media_request_object_find(structmedia_request*req,conststructmedia_request_object_ops*ops,void*priv)¶
Find an object in a request
Parameters
structmedia_request*reqThe media request
conststructmedia_request_object_ops*opsFind an object with this ops value
void*privFind an object with this priv value
Description
Bothops andpriv must be non-NULL.
Returns the object pointer or NULL if not found. The caller mustcallmedia_request_object_put() once it finished using the object.
Since this function needs to walk the list of objects it takesthereq->lock spin lock to make this safe.
- voidmedia_request_object_init(structmedia_request_object*obj)¶
Initialise a media request object
Parameters
structmedia_request_object*objThe object
Description
Initialise a media request object. The object will be released using therelease callback of the ops once it has no references (this functioninitialises references to one).
- intmedia_request_object_bind(structmedia_request*req,conststructmedia_request_object_ops*ops,void*priv,boolis_buffer,structmedia_request_object*obj)¶
Bind a media request object to a request
Parameters
structmedia_request*reqThe media request
conststructmedia_request_object_ops*opsThe object ops for this object
void*privA driver-specific priv pointer associated with this object
boolis_bufferSet to true if the object a buffer object.
structmedia_request_object*objThe object
Description
Bind this object to the request and set the ops and priv values ofthe object so it can be found later withmedia_request_object_find().
Every bound object must be unbound or completed by the kernel at somepoint in time, otherwise the request will never complete. When therequest is released all completed objects will be unbound by therequest core code.
Buffer objects will be added to the end of the request’s objectlist, non-buffer objects will be added to the front of the list.This ensures that all buffer objects are at the end of the listand that all non-buffer objects that they depend on are processedfirst.
- voidmedia_request_object_unbind(structmedia_request_object*obj)¶
Unbind a media request object
Parameters
structmedia_request_object*objThe object
Description
Unbind the media request object from the request.
- voidmedia_request_object_complete(structmedia_request_object*obj)¶
Mark the media request object as complete
Parameters
structmedia_request_object*objThe object
Description
Mark the media request object as complete. Only bound objects canbe completed.
- structmedia_device*media_device_usb_allocate(structusb_device*udev,constchar*module_name,structmodule*owner)¶
Allocate and return struct
mediadevice
Parameters
structusb_device*udevstruct
usb_devicepointerconstchar*module_nameshould be filled with
KBUILD_MODNAMEstructmodule*ownerstructmodulepointerTHIS_MODULEfor the driver.THIS_MODULEis null for a built-in driver.It is safe even whenTHIS_MODULEis null.
Description
This interface should be called to allocate a Media Device when multipledrivers share usb_device and the media device. This interface allocatesmedia_device structure and callsmedia_device_usb_init() to initializeit.
- voidmedia_device_delete(structmedia_device*mdev,constchar*module_name,structmodule*owner)¶
Release media device. Calls
kref_put().
Parameters
structmedia_device*mdevstruct
media_devicepointerconstchar*module_nameshould be filled with
KBUILD_MODNAMEstructmodule*ownerstructmodulepointerTHIS_MODULEfor the driver.THIS_MODULEis null for a built-in driver.It is safe even whenTHIS_MODULEis null.
Description
This interface should be called to put Media Device Instance kref.