Media Controller devices
Media Controller #
The media controller userspace API is documented in the Media Controller uAPI book. This document focus on the kernel-side implementation of the media framework.
Abstract media device model #
Discovering a device internal topology, and configuring it at runtime, is one of the goals of the media framework. To achieve this, hardware devices are modelled as an oriented graph of building blocks called entities connected through pads.
An entity is a basic media hardware building block. It can correspond to a large variety of logical blocks such as physical hardware devices (CMOS sensor for instance), logical hardware devices (a building block in a System-on-Chip image processing pipeline), DMA channels or physical connectors.
A pad is a connection endpoint through which an entity can interact with other entities. Data (not restricted to video) produced by an entity flows from the entity's output to one or more entity inputs. Pads should not be confused with physical pins at chip boundaries.
A link is a point-to-point oriented connection between two pads, either on the same entity or on different entities. Data flows from a source pad to a sink pad.
Media device #
A media device is represented by a struct media_device instance, defined in include/media/media-device.h. Allocation of the structure is handled by the media device driver, usually by embedding the media_device instance in a larger driver-specific structure.
Drivers initialise media device instances by calling media_device_init(). After initialising a media device instance, it is registered by calling __media_device_register() via the macro media_device_register() and unregistered by calling media_device_unregister(). An initialised media device must be eventually cleaned up by calling media_device_cleanup().
Note that it is not allowed to unregister a media device instance that was not previously registered, or clean up a media device instance that was not previously initialised.
Entities #
Entities are represented by a struct media_entity instance, defined in include/media/media-entity.h. The structure is usually embedded into a higher-level structure, such as v4l2_subdev or video_device instances, although drivers can allocate entities directly.
Drivers initialize entity pads by calling media_entity_pads_init().
Drivers register entities with a media device by calling media_device_register_entity() and unregistered by calling media_device_unregister_entity().
Interfaces #
Interfaces are represented by a struct media_interface instance, defined in include/media/media-entity.h. Currently, only one type of interface is defined: a device node. Such interfaces are represented by a struct media_intf_devnode.
Drivers initialize and create device node interfaces by calling media_devnode_create() and remove them by calling: media_devnode_remove().
Pads #
Pads are represented by a struct media_pad instance, defined in include/media/media-entity.h. Each entity stores its pads in a pads array managed by the entity driver. Drivers usually embed the array in a driver-specific structure.
Pads are identified by their entity and their 0-based index in the pads array.
Both information are stored in the struct media_pad, making the struct media_pad pointer the canonical way to 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.
Links #
Links are represented by a struct media_link instance, defined in include/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 points to all links originating at or targeting any of its pads. A given link is thus stored twice, once in the source entity and once in the target entity.
Drivers create pad to pad links by calling: media_create_pad_link() and remove with media_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 with media_remove_intf_links().
Links have flags that describe the link capabilities and state. The valid values are described at media_create_pad_link() and media_create_intf_link().
Graph traversal #
The media framework provides APIs to traverse media graphs, locating connected entities and links.
To iterate over all entities belonging to a media device, drivers can use the media_device_for_each_entity macro, defined in include/media/media-device.h.
struct media_entity *entity;
Helper functions can be used to find a link between two given pads, or a pad connected to another pad through an enabled link (media_entity_find_link(), media_pad_remote_pad_first(), media_entity_remote_source_pad_unique() and media_pad_remote_pad_unique()).
Use count and power handling #
Due to the wide differences between drivers regarding power management needs, the media controller does not implement power management. However, the struct media_entity includes a use_count field that media drivers can use to track the number of users of every entity for power management needs.
The media_entity<media_entity>.use_count field is owned by media drivers and must not be touched by entity drivers. Access to the field must be protected by the media_device.graph_mutex lock.
Links setup #
Link properties can be modified at runtime by calling media_entity_setup_link().
Pipelines and media streams #
A media stream is a stream of pixels or metadata originating from one or more source devices (such as a sensors) and flowing through media entity pads towards the final sinks. The stream can be modified on the route by the devices (e.g. scaling or pixel format conversions), or it can be split into multiple branches, or multiple branches can be merged.
A media pipeline is a set of media streams which are interdependent. This interdependency can be caused by the hardware (e.g. configuration of a second stream cannot be changed if the first stream has been enabled) or by the driver due to the software design. Most commonly a media pipeline consists of a single stream which does not branch.
When starting streaming, drivers must notify all entities in the pipeline to prevent link states from being modified during streaming by calling media_pipeline_start().
The function will mark all the pads which are part of the pipeline as streaming.
The struct media_pipeline instance pointed to by the pipe argument will be stored in every pad in the pipeline. Drivers should embed the struct media_pipeline in higher-level pipeline structures and can then access the pipeline through the struct media_pad pipe field.
Calls to media_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 with media_pipeline_stop().
If multiple calls to media_pipeline_start() have been made the same number of media_pipeline_stop() calls are required to stop streaming. The media_entity.pipe field is reset to NULL on the last nested stop call.
Link configuration will fail with -EBUSY by default if either end of the link is a streaming entity. Links that can be modified while streaming must be marked with the MEDIA_LNK_FL_DYNAMIC flag.
If other operations need to be disallowed on streaming entities (such as changing entities configuration parameters) drivers can explicitly check the media_entity stream_count field to find out if an entity is streaming. This operation must be done with the media_device graph_mutex held.
Link validation #
Link validation is performed by media_pipeline_start() for any entity which has sink pads in the pipeline. The media_entity.link_validate() callback is used for that purpose. In link_validate() callback, entity driver should check that the properties of the source pad of the connected entity and its own sink pad match. It is up to the type of the entity (and in the end, the properties of the hardware) what matching actually means.
Subsystems should facilitate link validation by providing subsystem specific helper functions to provide easy access for commonly needed information, and in the end provide a way to use driver-specific callbacks.
Pipeline traversal #
Once a pipeline has been constructed with media_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 is straightforward:
media_pipeline_pad_iter iter;
struct media_pad *pad;
To iterate over entities, the iterator needs to be initialized and cleaned up as an additional steps:
media_pipeline_entity_iter iter;
struct media_entity *entity;
int ret;
ret = ;
if
...;
;
Media Controller Device Allocator API #
When the media device belongs to more than one driver, the shared media device is allocated with the shared struct device as the key for look ups.
The shared media device should stay in registered state until the last driver unregisters it. In addition, the media device should be released when all the references are released. Each driver gets a reference to the media device during probe, when it allocates the media device. If media device is already allocated, the allocate API bumps up the refcount and returns the existing media device. The driver puts the reference back in its disconnect routine when it calls media_device_delete().
The media device is unregistered and cleaned up from the kref put handler to ensure that the media device stays in registered state until the last driver unregisters the media device.
Driver Usage
Drivers should use the appropriate media-core routines to manage the shared media device life-time handling the two states: 1. allocate -> register -> delete 2. get reference to already registered device -> delete
call media_device_delete() routine to make sure the shared media device delete is handled correctly.
driver probe: Call media_device_usb_allocate() to allocate or get a reference Call media_device_register(), if media devnode isn't registered
driver disconnect: Call media_device_delete() to free the media_device. Freeing is handled by the kref put handler.
API Definitions #
struct media_entity_notify #
Media Entity Notify
Definition
;
Members
list: List headnotify_data: Input data to invoke the callbacknotify: Callback function pointer
Description
Drivers may register a callback to take action when new entities get registered with the media device. This handler is intended for creating links between existing entities and should not create entities and register them.
struct media_device_ops #
Media device operations
Definition
;
Members
link_notify: Link state change notification callback. This callback is called with the graph_mutex held.req_alloc: Allocate a request. Set this if you need to allocate a struct larger then struct media_request. req_alloc and req_free must either both be set or both be NULL.req_free: Free a request. Set this if req_alloc was set as well, leave to NULL otherwise.req_validate: Validate a request, but do not queue yet. The req_queue_mutex lock is held when this op is called.req_queue: Queue a validated request, cannot fail. If something goes wrong when queueing this request then it should be marked as such internally in the driver and any related buffers must 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 after all other object types are queued: queueing a buffer kickstarts the request processing, so all other objects related to the request (and thus the buffer) must be available to the driver. And once a buffer is queued, then the driver can complete or delete objects from the request before req_queue exits.
struct media_device #
Media device
Definition
;
Members
dev: Parent devicedevnode: Media device nodemodel: Device model namedriver_name: Optional device driver name. If not set, calls toMEDIA_IOC_DEVICE_INFOwill returndev->driver->name. This is needed for USB drivers for example, as otherwise they'll all appear as if the driver name was "usb".serial: Device serial number (optional)bus_info: Unique and stable device location identifierhw_revision: Hardware device revisiontopology_version: Monotonic counter for storing the version of the graph topology. Should be incremented each time the topology changes.id: Unique ID used on the last registered graph objectentity_internal_idx: Unique internal entity ID used by the graph traversal algorithmsentity_internal_idx_max: Allocated internal entity indicesentities: List of registered entitiesinterfaces: List of registered interfacespads: List of registered padslinks: List of registered linksentity_notify: List of registered entity_notify callbacksgraph_mutex: Protects access to struct media_device datapm_count_walk: Graph walk for power state walk. Access serialised using graph_mutex.source_priv: Driver Private data for enable/disable source handlersenable_source: Enable Source Handler function pointerdisable_source: Disable Source Handler function pointerops: Operation handler callbacksreq_queue_mutex: Serialise the MEDIA_REQUEST_IOC_QUEUE ioctl w.r.t. other operations that stop or start streaming.num_requests: number of associated requestsnum_request_objects: number of associated request objectsmedia_dir: DebugFS media directoryrequest_id: Used to generate unique request IDs
Description
This structure represents an abstract high-level media device. It allows easy access to entities and provides basic media device-level support. The structure can be allocated directly or embedded in a larger structure.
The parent dev is a physical device. It must be set before registering the media device.
model is a descriptive model name exported through sysfs. It doesn't have to be unique.
enable_source is a handler to find source entity for the sink entity and activate the link between them if source entity is free. Drivers should call this handler before accessing the source.
disable_source is a handler to find source entity for the sink entity and deactivate the link between them. Drivers should call this handler to release the source.
Use-case: find tuner entity connected to the decoder entity and check if it is available, and activate the link between them from enable_source and deactivate from disable_source.
media_device_init() #
void Initializes a media device element
Parameters
struct media_device *mdev: pointer to structmedia_device
Description
This function initializes the media device prior to its registration. The media device initialization and registration is split in two functions to avoid race conditions and make the media device available to user-space before the media graph has been completed.
So drivers need to first initialize the media device, register any entity
within the media device, create pad to pad links and then finally register
the media device by calling media_device_register() as a final step.
The caller is responsible for initializing the media device before registration. 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 by media_device_init() for PCI and platform devices
if the field begins with '\0'.
media_device_cleanup() #
void Cleanups a media device element
Parameters
struct media_device *mdev: pointer to structmedia_device
Description
This function that will destroy the graph_mutex that is
initialized in media_device_init().
__media_device_register() #
int Registers a media device element
Parameters
struct media_device *mdev: pointer to structmedia_devicestruct module *owner: should be filled withTHIS_MODULE
Description
Users, should, instead, call the media_device_register() macro.
The caller is responsible for initializing the media_device structure
before registration. The following fields of media_device must be set:
media_device.modelmust be filled with the device model name as a NUL-terminated UTF-8 string. The device/model revision must not be stored in this field.
The following fields are optional:
-
media_device.serialis a unique serial number stored as a NUL-terminated ASCII string. The field is big enough to store a GUID in text form. If the hardware doesn't provide a unique serial number this field must be left empty. -
media_device.bus_inforepresents the location of the device in the system as a NUL-terminated ASCII string. For PCI/PCIe devicesmedia_device.bus_infomust be set to "PCI:" (or "PCIe:") followed by the value ofpci_name(). For USB devices,theusb_make_path()function must be used. This field is used by applications to distinguish between otherwise identical devices that don't provide a serial number. -
media_device.hw_revisionis the hardware device revision in a driver-specific format. When possible the revision should be formatted with theKERNEL_VERSION()macro.
Return
returns zero on success or a negative error code.
media_device_register() #
Registers a media device element
Parameters
mdev: pointer to structmedia_device
Description
This macro calls __media_device_register() passing THIS_MODULE as
the __media_device_register() second argument (owner).
media_device_unregister() #
void Unregisters a media device element
Parameters
struct media_device *mdev: pointer to structmedia_device
Description
It is safe to call this function on an unregistered (but initialised) media device.
media_device_register_entity() #
int registers a media entity inside a previously registered media device.
Parameters
struct media_device *mdev: pointer to structmedia_devicestruct media_entity *entity: pointer to structmedia_entityto be registered
Description
Entities are identified by a unique positive integer ID. The media controller framework will such ID automatically. IDs are not guaranteed to be contiguous, and the ID number can change on newer Kernel versions. So, neither the driver nor userspace should hardcode ID numbers to refer to the entities, but, instead, use the framework to find the ID, when needed.
The media_entity name, type and flags fields should be initialized before
calling media_device_register_entity(). Entities embedded in higher-level
standard structures can have some of those fields set by the higher-level
framework.
If the device has pads, media_entity_pads_init() should be called before
this function. Otherwise, the media_entity.pad and media_entity.num_pads
should be zeroed before calling this function.
Entities have flags that describe the entity capabilities and state:
MEDIA_ENT_FL_DEFAULT: indicates the default entity for a given type. This can be used to report the default audio and video devices or the default camera sensor.
media_device_unregister_entity() #
void unregisters a media entity.
Parameters
struct media_entity *entity: pointer to structmedia_entityto be unregistered
Description
All links associated with the entity and all PADs are automatically unregistered from the media_device when this function is called.
Unregistering an entity will not change the IDs of the other entities and the previoully used ID will never be reused for a newly registered entities.
When a media device is unregistered, all its entities are unregistered automatically. No manual entities unregistration is then required.
media_device_register_entity_notify() #
void Registers a media entity_notify callback
Parameters
struct media_device *mdev: The media devicestruct media_entity_notify *nptr: The media_entity_notify
Description
media_device_unregister_entity_notify() #
void Unregister a media entity notify callback
Parameters
struct media_device *mdev: The media devicestruct media_entity_notify *nptr: The media_entity_notify
media_device_pci_init() #
void create and initialize a struct media_device from a PCI device.
Parameters
struct media_device *mdev: pointer to structmedia_devicestruct pci_dev *pci_dev: pointer to struct pci_devconst char *name: media device name. IfNULL, the routine will use the default name for the pci device, given bypci_name()macro.
__media_device_usb_init() #
void create and initialize a struct media_device from a PCI device.
Parameters
struct media_device *mdev: pointer to structmedia_devicestruct usb_device *udev: pointer to struct usb_deviceconst char *board_name: media device name. IfNULL, the routine will use the usb product name, if available.const char *driver_name: name of the driver. ifNULL, the routine will use the name given byudev->dev->driver->name, with is usually the wrong thing to do.
Description
media_device_usb_init() #
create and initialize a struct media_device from a PCI device.
Parameters
mdev: pointer to structmedia_deviceudev: pointer to struct usb_devicename: media device name. IfNULL, the routine will use the usb product name, if available.
Description
This macro calls media_device_usb_init() passing the
media_device_usb_init() driver_name parameter filled with
KBUILD_MODNAME.
media_set_bus_info() #
void Set bus_info field
Parameters
char *bus_info: Variable where to write the bus info (char array)size_t bus_info_size: Length of the bus_infostruct device *dev: Related struct device
Description
Sets bus information based on dev. This is currently done for PCI and
platform devices. dev is required to be non-NULL for this to happen.
This function is not meant to be called from drivers.
struct media_file_operations #
Media device file operations
Definition
;
Members
owner: should be filled withTHIS_MODULEread: pointer to the function that implementsread()syscallwrite: pointer to the function that implementswrite()syscallpoll: pointer to the function that implementspoll()syscallioctl: pointer to the function that implementsioctl()syscallcompat_ioctl: pointer to the function that will handle 32 bits userspace calls to theioctl()syscall on a Kernel compiled with 64 bits.open: pointer to the function that implementsopen()syscallrelease: pointer to the function that will release the resources allocated by the open function.
struct media_devnode #
Media device node
Definition
;
Members
media_dev: pointer to structmedia_devicefops: pointer to structmedia_file_operationswith media device opsdev: pointer to structdevicecontaining the media controller devicecdev: struct cdev pointer character deviceparent: parent deviceminor: device node minor numberflags: flags, combination of theMEDIA_FLAG_*constantsrelease: release callback called at the end ofmedia_devnode_release()routine at media-device.c.
Description
This structure represents a media-related device node.
The parent is a physical device. It must be set by core or device drivers before registering the node.
media_devnode_register() #
int register a media device node
Parameters
struct media_device *mdev: struct media_device we want to register a device nodestruct media_devnode *devnode: media device node structure we want to registerstruct module *owner: should be filled withTHIS_MODULE
Description
The registration code assigns minor numbers and registers the new device node with 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, the release() callback of
the media_devnode structure is not called, so the caller is responsible for
freeing any data.
media_devnode_unregister_prepare() #
void clear the media device node register bit
Parameters
struct media_devnode *devnode: the device node to prepare for unregister
Description
This clears the passed device register bit. Future open calls will be met
with errors. Should be called before media_devnode_unregister() to avoid
races with unregister and device file open calls.
This function can safely be called if the device node has never been registered or has already been unregistered.
media_devnode_unregister() #
void unregister a media device node
Parameters
struct media_devnode *devnode: the device node to unregister
Description
This unregisters the passed device. Future open calls will be met with errors.
Should be called after media_devnode_unregister_prepare()
media_devnode_data() #
struct media_devnode * returns a pointer to the media_devnode
Parameters
struct file *filp: pointer to structfile
media_devnode_is_registered() #
int returns true if media_devnode is registered; false otherwise.
Parameters
struct media_devnode *devnode: pointer to structmedia_devnode.
Note
If mdev is NULL, it also returns false.
enum media_gobj_type #
type of a graph object
Constants
MEDIA_GRAPH_ENTITY: Identify a media entityMEDIA_GRAPH_PAD: Identify a media padMEDIA_GRAPH_LINK: Identify a media linkMEDIA_GRAPH_INTF_DEVNODE: Identify a media Kernel API interface via a device node
struct media_gobj #
Define a graph object.
Definition
;
Members
mdev: Pointer to the structmedia_devicethat owns the objectid: Non-zero object ID identifier. The ID should be unique inside a media_device, as it is composed byMEDIA_BITS_PER_TYPEto store the type plusMEDIA_BITS_PER_IDto store the IDlist: List entry stored in one of the per-type mdev object lists
Description
All objects on the media graph should have this struct embedded
struct media_entity_enum #
An enumeration of media entities.
Definition
;
Members
bmap: Bit map in which each bit represents one entity at struct media_entity->internal_idx.idx_max: Number of bits in bmap
struct media_graph #
Media graph traversal state
Definition
;
Members
stack: Graph traversal stack; the stack contains information on the path the media entities to be walked and the links through which they were reached.stack.entity: pointer tostruct media_entityat the graph.stack.link: pointer tostruct list_head.ent_enum: Visited entitiestop: The top of the stack
struct media_pipeline #
Media pipeline related information
Definition
;
Members
allocated: Media pipeline allocated and freed by the frameworkmdev: The media device the pipeline is part ofpads: List of media_pipeline_padstart_count: Media pipeline start - stop count
struct media_pipeline_pad #
A pad part of a media pipeline
Definition
;
Members
list: Entry in the media_pad pads listpipe: The media_pipeline that the pad is part ofpad: The media pad
Description
This structure associate a pad with a media pipeline. Instances of
media_pipeline_pad are created by media_pipeline_start() when it builds the
pipeline, and stored in the media_pad.pads list. media_pipeline_stop()
removes the entries from the list and deletes them.
struct media_pipeline_pad_iter #
Iterator for media_pipeline_for_each_pad
Definition
;
Members
cursor: The current element
struct media_pipeline_entity_iter #
Iterator for media_pipeline_for_each_entity
Definition
;
Members
ent_enum: The entity enumeration trackercursor: The current element
struct media_link #
A link object part of a media graph.
Definition
;
Members
graph_obj: Embedded structure containing the media object common datalist: Linked list associated with an entity or an interface that owns the link.{unnamed_union}: anonymousgobj0: Part of a union. Used to get the pointer for the first graph_object of the link.source: Part of a union. Used only if the first object (gobj0) is a pad. In that case, it represents the source pad.intf: Part of a union. Used only if the first object (gobj0) is an interface.{unnamed_union}: anonymousgobj1: Part of a union. Used to get the pointer for the second graph_object of the link.sink: Part of a union. Used only if the second object (gobj1) is a pad. In that case, it represents the sink pad.entity: Part of a union. Used only if the second object (gobj1) is an entity.reverse: Pointer to the link for the reverse direction of a pad to pad link.flags: Link flags, as defined in uapi/media.h (MEDIA_LNK_FL_*)is_backlink: Indicate if the link is a backlink.
enum media_pad_signal_type #
type of the signal inside a media pad
Constants
PAD_SIGNAL_DEFAULT: Default signal. Use this when all inputs or all outputs are uniquely identified by the pad number.PAD_SIGNAL_ANALOG: The 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 signals should use it.PAD_SIGNAL_DV: Contains a digital video signal, with can be a bitstream of samples taken from an analog TV video source. On such case, it usually contains the VBI data on it.PAD_SIGNAL_AUDIO: Contains an Intermediate Frequency analog signal from an audio sub-carrier or an audio bitstream. IF signals are provided by tuners and consumed by audio AM/FM decoders. Bitstream audio is provided by an audio decoder.
struct media_pad #
A media pad graph object.
Definition
;
Members
graph_obj: Embedded structure containing the media object common dataentity: Entity this pad belongs toindex: Pad index in the entity pads array, numbered from 0 to nnum_links: Number of links connected to this padsig_type: Type of the signal inside a media padflags: Pad flags, as defined in include/uapi/linux/media.h (seek forMEDIA_PAD_FL_*)pipe: Pipeline this pad belongs to. Usemedia_entity_pipeline()to access this field.
struct media_entity_operations #
Media entity operations
Definition
;
Members
get_fwnode_pad: Return the pad number based on a fwnode endpoint or a negative value on error. This operation can be used to map a fwnode to a media pad number. Optional.link_setup: Notify the entity of link changes. The operation can return an error, in which case link setup will be cancelled. Optional.link_validate: Return whether a link is valid from the entity point of view. Themedia_pipeline_start()function validates all links by calling this operation. Optional.has_pad_interdep: Return whether two pads of the entity are interdependent. If two pads are interdependent they are part of the same pipeline and enabling one of the pads means that the other pad will become "locked" and doesn't allow configuration changes. pad0 and pad1 are guaranteed to not both be sinks or sources. Never call the .has_pad_interdep()operation directly, always usemedia_entity_has_pad_interdep(). Optional: If the operation isn't implemented all pads will be considered as interdependent.
Description
enum media_entity_type #
Media entity type
Constants
MEDIA_ENTITY_TYPE_BASE: The entity isn't embedded in another subsystem structure.MEDIA_ENTITY_TYPE_VIDEO_DEVICE: The entity is embedded in a struct video_device instance.MEDIA_ENTITY_TYPE_V4L2_SUBDEV: The entity is embedded in a struct v4l2_subdev instance.
Description
Media entity objects are often not instantiated directly, but the media entity structure is inherited by (through embedding) other subsystem-specific structures. The media entity type identifies the type of the subclass structure that implements a media entity instance.
This allows runtime type identification of media entities and safe casting to
the correct object type. For instance, a media entity structure instance
embedded in a v4l2_subdev structure instance will have the type
MEDIA_ENTITY_TYPE_V4L2_SUBDEV and can safely be cast to a v4l2_subdev
structure using the container_of() macro.
struct media_entity #
A media entity graph object.
Definition
;
Members
graph_obj: Embedded structure containing the media object common data.name: Entity name.obj_type: Type of the object that implements the media_entity.function: Entity main function, as defined in include/uapi/linux/media.h (seek forMEDIA_ENT_F_*)flags: Entity flags, as defined in include/uapi/linux/media.h (seek forMEDIA_ENT_FL_*)num_pads: Number of sink and source pads.num_links: Total number of links, forward and back, enabled and disabled.num_backlinks: Number of backlinksinternal_idx: An unique internal entity specific number. The numbers are re-used if entities are unregistered or registered again.pads: Pads array with the size defined by num_pads.links: List of data links.ops: Entity operations.use_count: Use count for the entity.info: Union with devnode information. Kept just for backward compatibility.info.dev: Contains device major and minor info.info.dev.major: device node major, if the device is a devnode.info.dev.minor: device node minor, if the device is a devnode.
Description
media_entity_for_each_pad() #
Iterate on all pads in an entity
Parameters
entity: The entity the pads belong toiter: The iterator pad
Description
Iterate on all pads in a media entity.
struct media_interface #
A media interface graph object.
Definition
;
Members
graph_obj: embedded graph objectlinks: List of links pointing to graph entitiestype: Type of the interface as defined in include/uapi/linux/media.h (seek forMEDIA_INTF_T_*)flags: Interface flags as defined in include/uapi/linux/media.h (seek forMEDIA_INTF_FL_*)
Description
struct media_intf_devnode #
A media interface via a device node.
Definition
;
Members
intf: embedded interface objectmajor: Major number of a device nodeminor: Minor number of a device node
media_entity_id() #
u32 return the media entity graph object id
Parameters
struct media_entity *entity: pointer tomedia_entity
media_type() #
enum media_gobj_type return the media object type
Parameters
struct media_gobj *gobj: Pointer to the structmedia_gobjgraph object
media_id() #
u32 return the media object ID
Parameters
struct media_gobj *gobj: Pointer to the structmedia_gobjgraph object
media_gobj_gen_id() #
u32 encapsulates type and ID on at the object ID
Parameters
enum media_gobj_type type: object type as define at enummedia_gobj_type.u64 local_id: next ID, from structmedia_device.id.
is_media_entity_v4l2_video_device() #
bool Check if the entity is a video_device
Parameters
struct media_entity *entity: pointer to entity
Return
true if the entity is an instance of a video_device object and can
safely be cast to a struct video_device using the container_of() macro, or
false otherwise.
is_media_entity_v4l2_subdev() #
bool Check if the entity is a v4l2_subdev
Parameters
struct media_entity *entity: pointer to entity
Return
true if the entity is an instance of a v4l2_subdev object and can
safely be cast to a struct v4l2_subdev using the container_of() macro, or
false otherwise.
media_entity_enum_init() #
int Initialise an entity enumeration
Parameters
struct media_entity_enum *ent_enum: Entity enumeration to be initialisedstruct media_device *mdev: The related media device
Return
zero on success or a negative error code.
media_entity_enum_cleanup() #
void Release resources of an entity enumeration
Parameters
struct media_entity_enum *ent_enum: Entity enumeration to be released
media_entity_enum_zero() #
void Clear the entire enum
Parameters
struct media_entity_enum *ent_enum: Entity enumeration to be cleared
media_entity_enum_set() #
void Mark a single entity in the enum
Parameters
struct media_entity_enum *ent_enum: Entity enumerationstruct media_entity *entity: Entity to be marked
media_entity_enum_clear() #
void Unmark a single entity in the enum
Parameters
struct media_entity_enum *ent_enum: Entity enumerationstruct media_entity *entity: Entity to be unmarked
media_entity_enum_test() #
bool Test whether the entity is marked
Parameters
struct media_entity_enum *ent_enum: Entity enumerationstruct media_entity *entity: Entity to be tested
Description
Returns true if the entity was marked.
media_entity_enum_test_and_set() #
bool Test whether the entity is marked, and mark it
Parameters
struct media_entity_enum *ent_enum: Entity enumerationstruct media_entity *entity: Entity to be tested
Description
Returns true if the entity was marked, and mark it before doing so.
media_entity_enum_empty() #
bool Test whether the entire enum is empty
Parameters
struct media_entity_enum *ent_enum: Entity enumeration
Return
true if the entity was empty.
media_entity_enum_intersects() #
bool Test whether two enums intersect
Parameters
struct media_entity_enum *ent_enum1: First entity enumerationstruct media_entity_enum *ent_enum2: Second entity enumeration
Return
true if entity enumerations ent_enum1 and ent_enum2 intersect,
otherwise false.
gobj_to_entity() #
returns the struct media_entity pointer from the gobj contained on it.
Parameters
gobj: Pointer to the structmedia_gobjgraph object
gobj_to_pad() #
returns the struct media_pad pointer from the gobj contained on it.
Parameters
gobj: Pointer to the structmedia_gobjgraph object
gobj_to_link() #
returns the struct media_link pointer from the gobj contained on it.
Parameters
gobj: Pointer to the structmedia_gobjgraph object
gobj_to_intf() #
returns the struct media_interface pointer from the gobj contained on it.
Parameters
gobj: Pointer to the structmedia_gobjgraph object
intf_to_devnode() #
returns the struct media_intf_devnode pointer from the intf contained on it.
Parameters
intf: Pointer to structmedia_intf_devnode
media_gobj_create() #
void Initialize a graph object
Parameters
struct media_device *mdev: Pointer to themedia_devicethat contains the objectenum media_gobj_type type: Type of the objectstruct media_gobj *gobj: Pointer to the structmedia_gobjgraph object
Description
This routine initializes the embedded struct media_gobj inside a
media graph object. It is called automatically if media_*_create
function calls are used. However, if the object (entity, link, pad,
interface) is embedded on some other object, this function should be
called before registering the object at the media controller.
media_gobj_destroy() #
void Stop using a graph object on a media device
Parameters
struct media_gobj *gobj: Pointer to the structmedia_gobjgraph object
Description
This should be called by all routines like media_device_unregister()
that remove/destroy media graph objects.
media_entity_pads_init() #
int Initialize the entity pads
Parameters
struct media_entity *entity: entity where the pads belongu16 num_pads: total number of sink and source padsstruct media_pad *pads: Array of num_pads pads.
Description
The pads array is managed by the entity driver and passed to
media_entity_pads_init() where its pointer will be stored in the
media_entity structure.
If no pads are needed, drivers could either directly fill
media_entity->num_pads with 0 and media_entity->pads with NULL or call
this function that will do the same.
As the number of pads is known in advance, the pads array is not allocated dynamically but is managed by the entity driver. Most drivers will embed the pads array in a driver-specific structure, avoiding dynamic allocation.
Drivers must set the direction of every pad in the pads array before calling
media_entity_pads_init(). The function will initialize the other pads fields.
media_entity_cleanup() #
void free resources associated with an entity
Parameters
struct media_entity *entity: entity where the pads belong
Description
This function must be called during the cleanup phase after unregistering the entity (currently, it does nothing).
Calling media_entity_cleanup() on a media_entity whose memory has been
zeroed but that has not been initialized with media_entity_pad_init() is
valid and is a no-op.
media_get_pad_index() #
int retrieves a pad index from an entity
Parameters
struct media_entity *entity: entity where the pads belongu32 pad_type: the type of the pad, one of MEDIA_PAD_FL_* pad typesenum media_pad_signal_type sig_type: type of signal of the pad to be search
Description
This helper function finds the first pad index inside an entity that satisfies both is_sink and sig_type conditions.
On success, return the pad number. If the pad was not found or the media entity is a NULL pointer, return -EINVAL.
media_create_pad_link() #
int creates a link between two entities.
Parameters
struct media_entity *source: pointer tomedia_entityof the source pad.u16 source_pad: number of the source pad in the pads arraystruct media_entity *sink: pointer tomedia_entityof the sink pad.u16 sink_pad: number of the sink pad in the pads array.u32 flags: Link flags, as defined in include/uapi/linux/media.h ( seek forMEDIA_LNK_FL_*)
Description
Valid values for flags:
-
MEDIA_LNK_FL_ENABLED: Indicates 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 be enabled at a time. -
MEDIA_LNK_FL_IMMUTABLE: Indicates that the link enabled state can't be modified at runtime. IfMEDIA_LNK_FL_IMMUTABLEis set, thenMEDIA_LNK_FL_ENABLEDmust also be set, since an immutable link is always enabled.
media_create_pad_links() #
int creates a link between two entities.
Parameters
const struct media_device *mdev: Pointer to the media_device that contains the objectconst u32 source_function: Function of the source entities. Used only if source is NULL.struct media_entity *source: pointer tomedia_entityof the source pad. If NULL, it will use all entities that matches the sink_function.const u16 source_pad: number of the source pad in the pads arrayconst u32 sink_function: Function of the sink entities. Used only if sink is NULL.struct media_entity *sink: pointer tomedia_entityof the sink pad. If NULL, it will use all entities that matches the sink_function.const u16 sink_pad: number of the sink pad in the pads array.u32 flags: Link flags, as defined in include/uapi/linux/media.h.const bool allow_both_undefined: iftrue, then both source and sink can be NULL. In such case, it will create a crossbar between all entities that matches source_function to all entities that matches sink_function. Iffalse, it will return 0 and won't create any link if both source and sink are NULL.
Description
Valid values for flags:
-
A
MEDIA_LNK_FL_ENABLEDflag indicates that the link is enabled and can beused to transfer media data. If multiple links are created and this flag is passed as an argument, only the first created link will have this flag.
-
A
MEDIA_LNK_FL_IMMUTABLEflag indicates that the link enabled state can'tbe modified at runtime. If
MEDIA_LNK_FL_IMMUTABLEis set, thenMEDIA_LNK_FL_ENABLEDmust also be set since an immutable link is always enabled.
It is common for some devices to have multiple source and/or sink entities
of the same type that should be linked. While media_create_pad_link()
creates link by link, this function is meant to allow 1:n, n:1 and even
cross-bar (n:n) links.
media_entity_remove_links() #
void remove all links associated with an entity
Parameters
struct media_entity *entity: pointer tomedia_entity
Description
__media_entity_setup_link() #
int Configure a media link without locking
Parameters
struct media_link *link: The link being configuredu32 flags: Link configuration flags
Description
The bulk of link setup is handled by the two entities connected through the link. This function notifies both entities of the link configuration change.
If the link is immutable or if the current and new configuration are identical, return immediately.
The user is expected to hold link->source->parent->mutex. If not,
media_entity_setup_link() should be used instead.
media_entity_setup_link() #
int changes the link flags properties in runtime
Parameters
struct media_link *link: pointer tomedia_linku32 flags: the requested new link flags
Description
The only configurable property is the MEDIA_LNK_FL_ENABLED link flag
to enable/disable a link. Links marked with the
MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled.
When a link is enabled or disabled, the media framework calls the link_setup operation for the two entities at the source and sink of the link, in that order. If the second link_setup call fails, another link_setup call is made on the first entity to restore the original link flags.
Media device drivers can be notified of link setup operations by setting the
media_device.link_notify pointer to a callback function. If provided, the
notification callback will be called before enabling and after disabling
links.
Entity drivers must implement the link_setup operation if any of their links is non-immutable. The operation must either configure the hardware or store the configuration information to be applied later.
Link configuration must not have any side effect on other links. If an
enabled link at a sink pad prevents another link at the same pad from
being enabled, the link_setup operation must return -EBUSY and can't
implicitly disable the first enabled link.
media_entity_find_link() #
struct media_link * Find a link between two pads
Parameters
struct media_pad *source: Source padstruct media_pad *sink: Sink pad
Return
returns a pointer to the link between the two entities. If no
such link exists, return NULL.
media_pad_remote_pad_first() #
struct media_pad * Find the first pad at the remote end of a link
Parameters
const struct media_pad *pad: Pad at the local end of the link
Description
Search for a remote pad connected to the given pad by iterating over all links 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 found
enabled link, or NULL if no enabled link has been found.
media_pad_remote_pad_unique() #
struct media_pad * Find a remote pad connected to a pad
Parameters
const struct media_pad *pad: The pad
Description
Search for and return a remote pad connected to pad through an enabled link. If multiple (or no) remote pads are found, an error is returned.
The uniqueness constraint makes this helper function suitable for entities that 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 pointers if an error occurs:
media_entity_remote_pad_unique() #
struct media_pad * Find a remote pad connected to an entity
Parameters
const struct media_entity *entity: The entityunsigned int type: The type of pad to find (MEDIA_PAD_FL_SINK or MEDIA_PAD_FL_SOURCE)
Description
Search for and return a remote pad of type connected to entity through an enabled link. If multiple (or no) remote pads match these criteria, an error is returned.
The uniqueness constraint makes this helper function suitable for entities that 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 pointers if an error occurs:
media_entity_remote_source_pad_unique() #
struct media_pad * Find a remote source pad connected to an entity
Parameters
const struct media_entity *entity: The entity
Description
Search for and return a remote source pad connected to entity through an enabled link. If multiple (or no) remote pads match these criteria, an error is returned.
The uniqueness constraint makes this helper function suitable for entities that 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 pointers if an error occurs:
media_pad_is_streaming() #
bool Test if a pad is part of a streaming pipeline
Parameters
const struct media_pad *pad: The pad
Return
True if the pad is part of a pipeline started with the
media_pipeline_start() function, false otherwise.
media_entity_is_streaming() #
bool Test if an entity is part of a streaming pipeline
Parameters
const struct media_entity *entity: The entity
Return
True if the entity is part of a pipeline started with the
media_pipeline_start() function, false otherwise.
media_entity_pipeline() #
struct media_pipeline * Get the media pipeline an entity is part of
Parameters
struct media_entity *entity: The entity
Description
DEPRECATED: use media_pad_pipeline() instead.
This function returns the media pipeline that an entity has been associated
with when constructing the pipeline with media_pipeline_start(). The pointer
remains valid until media_pipeline_stop() is called.
In general, entities can be part of multiple pipelines, when carrying multiple streams (either on different pads, or on the same pad using multiplexed streams). This function is to be used only for entities that do not support multiple pipelines.
Return
The media_pipeline the entity is part of, or NULL if the entity is not part of any pipeline.
media_pad_pipeline() #
struct media_pipeline * Get the media pipeline a pad is part of
Parameters
struct media_pad *pad: The pad
Description
This function returns the media pipeline that a pad has been associated
with when constructing the pipeline with media_pipeline_start(). The pointer
remains valid until media_pipeline_stop() is called.
Return
The media_pipeline the pad is part of, or NULL if the pad is not part of any pipeline.
media_entity_get_fwnode_pad() #
int Get pad number from fwnode
Parameters
struct media_entity *entity: The entityconst struct fwnode_handle *fwnode: Pointer to the fwnode_handle which should be used to find the padunsigned long direction_flags: Expected direction of the pad, as defined in include/uapi/linux/media.h (seek forMEDIA_PAD_FL_*)
Description
This function can be used to resolve the media pad number from a fwnode. This is useful for devices which use more complex mappings of media pads.
If the entity does not implement the get_fwnode_pad() operation
then this function searches the entity for the first pad that
matches the direction_flags.
Return
returns the pad number on success or a negative error code.
media_graph_walk_init() #
int Allocate resources used by graph walk.
Parameters
struct media_graph *graph: Media graph structure that will be used to walk the graphstruct media_device *mdev: Pointer to themedia_devicethat contains the object
Description
This function is deprecated, use media_pipeline_for_each_pad() instead.
The caller is required to hold the media_device graph_mutex during the graph walk until the graph state is released.
Returns zero on success or a negative error code otherwise.
media_graph_walk_cleanup() #
void Release resources used by graph walk.
Parameters
struct media_graph *graph: Media graph structure that will be used to walk the graph
Description
This function is deprecated, use media_pipeline_for_each_pad() instead.
media_graph_walk_start() #
void Start walking the media graph at a given entity
Parameters
struct media_graph *graph: Media graph structure that will be used to walk the graphstruct media_entity *entity: Starting entity
Description
This function is deprecated, use media_pipeline_for_each_pad() instead.
Before using this function, media_graph_walk_init() must be
used to allocate resources used for walking the graph. This
function initializes the graph traversal structure to walk the
entities graph starting at the given entity. The traversal
structure must not be modified by the caller during graph
traversal. After the graph walk, the resources must be released
using media_graph_walk_cleanup().
media_graph_walk_next() #
struct media_entity * Get the next entity in the graph
Parameters
struct media_graph *graph: Media graph structure
Description
This function is deprecated, use media_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 to
media_graph_walk_start().
Return
returns the next entity in the graph or NULL if the whole graph
have been traversed.
media_pipeline_start() #
int Mark a pipeline as streaming
Parameters
struct media_pad *origin: Starting padstruct media_pipeline *pipe: Media pipeline to be assigned to all pads in the pipeline.
Description
Mark all pads connected to pad origin through enabled links, either directly or indirectly, as streaming. The given pipeline object is assigned to 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 of
media_pipeline_stop() calls will be required to stop streaming. The
pipeline pointer must be identical for all nested calls to
media_pipeline_start().
__media_pipeline_start() #
int Mark a pipeline as streaming
Parameters
struct media_pad *origin: Starting padstruct media_pipeline *pipe: Media pipeline to be assigned to all pads in the pipeline.
Description
..note:: This is the non-locking version of media_pipeline_start()
media_pipeline_stop() #
void Mark a pipeline as not streaming
Parameters
struct media_pad *pad: Starting pad
Description
Mark all pads connected to a given pad through enabled links, either
directly or indirectly, as not streaming. The media_pad pipe field is
reset to NULL.
If multiple calls to media_pipeline_start() have been made, the same
number of calls to this function are required to mark the pipeline as not
streaming.
__media_pipeline_stop() #
void Mark a pipeline as not streaming
Parameters
struct media_pad *pad: Starting pad
Description
media_pipeline_for_each_pad() #
Iterate on all pads in a media pipeline
Parameters
pipe: The pipelineiter: The iterator (struct media_pipeline_pad_iter)pad: The iterator pad
Description
Iterate on all pads in a media pipeline. This is only valid after the
pipeline has been built with media_pipeline_start() and before it gets
destroyed with media_pipeline_stop().
media_pipeline_entity_iter_init() #
int Initialize a pipeline entity iterator
Parameters
struct media_pipeline *pipe: The pipelinestruct media_pipeline_entity_iter *iter: The iterator
Description
This function must be called to initialize the iterator before using it in a
media_pipeline_for_each_entity() loop. The iterator must be destroyed by a
call to media_pipeline_entity_iter_cleanup after the loop (including in code
paths that break from the loop).
The same iterator can be used in multiple consecutive loops without being destroyed and reinitialized.
Return
0 on success or a negative error code otherwise.
media_pipeline_entity_iter_cleanup() #
void Destroy a pipeline entity iterator
Parameters
struct media_pipeline_entity_iter *iter: The iterator
Description
This function must be called to destroy iterators initialized with
media_pipeline_entity_iter_init().
media_pipeline_for_each_entity() #
Iterate on all entities in a media pipeline
Parameters
pipe: The pipelineiter: The iterator (struct media_pipeline_entity_iter)entity: The iterator entity
Description
Iterate on all entities in a media pipeline. This is only valid after the
pipeline has been built with media_pipeline_start() and before it gets
destroyed with media_pipeline_stop(). The iterator must be initialized with
media_pipeline_entity_iter_init() before iteration, and destroyed with
media_pipeline_entity_iter_cleanup() after (including in code paths that
break from the loop).
media_pipeline_alloc_start() #
int Mark a pipeline as streaming
Parameters
struct media_pad *pad: Starting pad
Description
media_pipeline_alloc_start() is similar to media_pipeline_start() but instead
of working on a given pipeline the function will use an existing pipeline if
the pad is already part of a pipeline, or allocate a new pipeline.
Calls to media_pipeline_alloc_start() must be matched with
media_pipeline_stop().
media_devnode_create() #
struct media_intf_devnode * creates and initializes a device node interface
Parameters
struct media_device *mdev: pointer to structmedia_deviceu32 type: type of the interface, as given by include/uapi/linux/media.h ( seek forMEDIA_INTF_T_*) macros.u32 flags: Interface flags, as defined in include/uapi/linux/media.h ( seek forMEDIA_INTF_FL_*)u32 major: Device node major number.u32 minor: Device node minor number.
Return
if succeeded, returns a pointer to the newly allocated
media_intf_devnode pointer.
Description
media_devnode_remove() #
void removes a device node interface
Parameters
struct media_intf_devnode *devnode: pointer tomedia_intf_devnodeto be freed.
Description
When a device node interface is removed, all links to it are automatically removed.
media_create_intf_link() #
struct media_link * creates a link between an entity and an interface
Parameters
struct media_entity *entity: pointer tomedia_entitystruct media_interface *intf: pointer tomedia_interfaceu32 flags: Link flags, as defined in include/uapi/linux/media.h ( seek forMEDIA_LNK_FL_*)
Description
Valid values for flags:
-
MEDIA_LNK_FL_ENABLED: Indicates that the interface is connected to the entity hardware. That's the default value for interfaces. An interface may be disabled if the hardware is busy due to the usage of some other interface that it is currently controlling the hardware.A typical example is an hybrid TV device that handle only one type of stream on a given time. So, when the digital TV is streaming, the V4L2 interfaces won't be enabled, as such device is not able to also stream analog TV or radio.
__media_remove_intf_link() #
void remove a single interface link
Parameters
struct media_link *link: pointer tomedia_link.
Description
media_remove_intf_link() #
void remove a single interface link
Parameters
struct media_link *link: pointer tomedia_link.
Description
__media_remove_intf_links() #
void remove all links associated with an interface
Parameters
struct media_interface *intf: pointer tomedia_interface
Description
media_remove_intf_links() #
void remove all links associated with an interface
Parameters
struct media_interface *intf: pointer tomedia_interface
Description
media_entity_call() #
Calls a struct media_entity_operations operation on an entity
Parameters
entity: entity where the operation will be calledoperation: type of the operation. Should be the name of a member of structmedia_entity_operations.args...: variable arguments
Description
This helper function will check if operation is not NULL. On such case,
it will issue a call to operation(entity, args).
media_create_ancillary_link() #
struct media_link * create an ancillary link between two instances of media_entity
Parameters
struct media_entity *primary: pointer to the primarymedia_entitystruct media_entity *ancillary: pointer to the ancillarymedia_entity
Description
Create an ancillary link between two entities, indicating that they represent two connected pieces of hardware that form a single logical unit. A typical example is a camera lens controller being linked to the sensor that it is supporting.
The function sets both MEDIA_LNK_FL_ENABLED and MEDIA_LNK_FL_IMMUTABLE for the new link.
__media_entity_next_link() #
struct media_link * Iterate through a media_entity's links
Parameters
struct media_entity *entity: pointer to themedia_entitystruct media_link *link: pointer to amedia_linkto hold the iterated valuesunsigned long link_type: one of the MEDIA_LNK_FL_LINK_TYPE flags
Description
Return the next link against an entity matching a specific link type. This allows iteration through an entity's links whilst guaranteeing all of the returned links are of the given type.
for_each_media_entity_data_link() #
Iterate through an entity's data links
Parameters
entity: pointer to themedia_entitylink: pointer to amedia_linkto hold the iterated values
Description
Iterate over a media_entity's data links
enum media_request_state #
media request state
Constants
MEDIA_REQUEST_STATE_IDLE: IdleMEDIA_REQUEST_STATE_VALIDATING: Validating the request, no state changes allowedMEDIA_REQUEST_STATE_QUEUED: QueuedMEDIA_REQUEST_STATE_COMPLETE: Completed, the request is doneMEDIA_REQUEST_STATE_CLEANING: Cleaning, the request is being re-initedMEDIA_REQUEST_STATE_UPDATING: The request is being updated, i.e. request objects are being added, modified or removedNR_OF_MEDIA_REQUEST_STATE: The number of media request states, used internally for sanity check purposes
struct media_request #
Media device request
Definition
;
Members
mdev: Media device this request belongs tokref: Reference countdebug_str: Prefix for debug messages (process name:fd)state: The state of the requestupdating_count: count the number of request updates that are in progressaccess_count: count the number of request accesses that are in progressobjects: List of struct media_request_object request objectsnum_incomplete_objects: The number of incomplete objects in the requestmanual_completion: if true, then the request won't be marked as completed when num_incomplete_objects reaches 0. Callmedia_request_manual_complete()to complete the request after num_incomplete_objects == 0.poll_wait: Wait queue for polllock: Serializes access to this struct
media_request_lock_for_access() #
int Lock the request to access its objects
Parameters
struct media_request *req: The media request
Description
Use before accessing a completed request. A reference to the request must be held during the access. This usually takes place automatically through a file handle. Use media_request_unlock_for_access when done.
media_request_unlock_for_access() #
void Unlock a request previously locked for access
Parameters
struct media_request *req: The media request
Description
Unlock a request that has previously been locked using media_request_lock_for_access.
media_request_lock_for_update() #
int Lock the request for updating its objects
Parameters
struct media_request *req: The media request
Description
Use before updating a request, i.e. adding, modifying or removing a request object in it. A reference to the request must be held during the update. This usually takes place automatically through a file handle. Use media_request_unlock_for_update when done.
media_request_unlock_for_update() #
void Unlock a request previously locked for update
Parameters
struct media_request *req: The media request
Description
Unlock a request that has previously been locked using media_request_lock_for_update.
media_request_get() #
void Get the media request
Parameters
struct media_request *req: The media request
Description
Get the media request.
media_request_put() #
void Put the media request
Parameters
struct media_request *req: The media request
Description
Put the media request. The media request will be released when the refcount reaches 0.
media_request_get_by_fd() #
struct media_request * Get a media request by fd
Parameters
struct media_device *mdev: Media device this request belongs toint request_fd: The file descriptor of the request
Description
Get the request represented by request_fd that is owned by the media device.
Return a -EBADR error pointer if requests are not supported by this driver. Return -EINVAL if the request was not found. Return the pointer to the request if found: the caller will have to call media_request_put when it finished using the request.
media_request_alloc() #
int Allocate the media request
Parameters
struct media_device *mdev: Media device this request belongs toint *alloc_fd: Store the request's file descriptor in this int
Description
Allocated the media request and put the fd in alloc_fd.
media_request_mark_manual_completion() #
void Enable manual completion
Parameters
struct media_request *req: The request
Description
Mark that the request has to be manually completed by calling
media_request_manual_complete().
This function shall be called in the req_queue callback.
media_request_manual_complete() #
void Mark the request as completed
Parameters
struct media_request *req: The request
Description
This function completes a request that was marked for manual completion by an
earlier call to media_request_mark_manual_completion(). The request's
manual_completion field is reset to false.
All objects contained in the request must have been completed previously. It is an error to call this function otherwise. If such an error occurred, the function will WARN and the object completion will be delayed until num_incomplete_objects is 0.
struct media_request_object_ops #
Media request object operations
Definition
;
Members
prepare: Validate and prepare the request object, optional.unprepare: Unprepare the request object, optional.queue: Queue the request object, optional.unbind: Unbind the request object, optional.release: Release the request object, required.
struct media_request_object #
An opaque object that belongs to a media request
Definition
;
Members
mdev: Media device this object belongs toops: object's operationspriv: object's priv pointerreq: the request this object belongs to (can be NULL)list: List entry of the object for struct media_requestkref: Reference count of the object, acquire before releasing req->lockcompleted: If true, then this object was completed.
Description
An object related to the request. This struct is always embedded in another struct that contains the actual data for this request object.
media_request_object_get() #
void Get a media request object
Parameters
struct media_request_object *obj: The object
Description
Get a media request object.
media_request_object_put() #
void Put a media request object
Parameters
struct media_request_object *obj: The object
Description
Put a media request object. Once all references are gone, the object's memory is released.
media_request_object_find() #
struct media_request_object * Find an object in a request
Parameters
struct media_request *req: The media requestconst struct media_request_object_ops *ops: Find an object with this ops valuevoid *priv: Find an object with this priv value
Description
Both ops and priv must be non-NULL.
Returns the object pointer or NULL if not found. The caller must
call media_request_object_put() once it finished using the object.
Since this function needs to walk the list of objects it takes the req->lock spin lock to make this safe.
media_request_object_init() #
void Initialise a media request object
Parameters
struct media_request_object *obj: The object
Description
Initialise a media request object. The object will be released using the release callback of the ops once it has no references (this function initialises references to one).
media_request_object_bind() #
int Bind a media request object to a request
Parameters
struct media_request *req: The media requestconst struct media_request_object_ops *ops: The object ops for this objectvoid *priv: A driver-specific priv pointer associated with this objectbool is_buffer: Set to true if the object is a buffer object.struct media_request_object *obj: The object
Description
Bind this object to the request and set the ops and priv values of
the object so it can be found later with media_request_object_find().
Every bound object must be unbound or completed by the kernel at some point in time, otherwise the request will never complete. When the request is released all completed objects will be unbound by the request core code.
Buffer objects will be added to the end of the request's object list, non-buffer objects will be added to the front of the list. This ensures that all buffer objects are at the end of the list and that all non-buffer objects that they depend on are processed first.
media_request_object_unbind() #
void Unbind a media request object
Parameters
struct media_request_object *obj: The object
Description
Unbind the media request object from the request.
media_request_object_complete() #
void Mark the media request object as complete
Parameters
struct media_request_object *obj: The object
Description
Mark the media request object as complete. Only bound objects can be completed.
media_device_usb_allocate() #
struct media_device * Allocate and return struct media device
Parameters
struct usb_device *udev: structusb_devicepointerconst char *module_name: should be filled withKBUILD_MODNAMEstruct module *owner: struct module pointerTHIS_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 multiple
drivers share usb_device and the media device. This interface allocates
media_device structure and calls media_device_usb_init() to initialize
it.
media_device_delete() #
void Release media device. Calls kref_put().
Parameters
struct media_device *mdev: structmedia_devicepointerconst char *module_name: should be filled withKBUILD_MODNAMEstruct module *owner: struct module pointerTHIS_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.