blob: 722170cb7f4085add1d67e953ef95f6f5601b609 [file] [log] [blame]
Mauro Carvalho Chehabd26a5d42016-07-17 07:20:06 -03001==========
2Media core
3==========
4
5Video2Linux devices
6-------------------
7
8.. kernel-doc:: include/media/tuner.h
9
10.. kernel-doc:: include/media/tuner-types.h
11
12.. kernel-doc:: include/media/tveeprom.h
13
14.. kernel-doc:: include/media/v4l2-async.h
15
16.. kernel-doc:: include/media/v4l2-ctrls.h
17
18.. kernel-doc:: include/media/v4l2-dv-timings.h
19
20.. kernel-doc:: include/media/v4l2-event.h
21
22.. kernel-doc:: include/media/v4l2-flash-led-class.h
23
24.. kernel-doc:: include/media/v4l2-mc.h
25
26.. kernel-doc:: include/media/v4l2-mediabus.h
27
28.. kernel-doc:: include/media/v4l2-mem2mem.h
29
30.. kernel-doc:: include/media/v4l2-of.h
31
32.. kernel-doc:: include/media/v4l2-rect.h
33
34.. kernel-doc:: include/media/v4l2-subdev.h
35
36.. kernel-doc:: include/media/videobuf2-core.h
37
38.. kernel-doc:: include/media/videobuf2-v4l2.h
39
40.. kernel-doc:: include/media/videobuf2-memops.h
41
42
43Digital TV (DVB) devices
44------------------------
45
46Digital TV Common functions
47---------------------------
48
49.. kernel-doc:: drivers/media/dvb-core/dvb_math.h
50
51.. kernel-doc:: drivers/media/dvb-core/dvb_ringbuffer.h
52
53.. kernel-doc:: drivers/media/dvb-core/dvbdev.h
54
55
56Digital TV Frontend kABI
57------------------------
58
59Digital TV Frontend
60~~~~~~~~~~~~~~~~~~~
61
62The Digital TV Frontend kABI defines a driver-internal interface for
63registering low-level, hardware specific driver to a hardware independent
64frontend layer. It is only of interest for Digital TV device driver writers.
65The header file for this API is named dvb_frontend.h and located in
66drivers/media/dvb-core.
67
68Before using the Digital TV frontend core, the bridge driver should attach
69the frontend demod, tuner and SEC devices and call dvb_register_frontend(),
70in order to register the new frontend at the subsystem. At device
71detach/removal, the bridge driver should call dvb_unregister_frontend() to
72remove the frontend from the core and then dvb_frontend_detach() to free the
73memory allocated by the frontend drivers.
74
75The drivers should also call dvb_frontend_suspend() as part of their
76handler for the &device_driver.suspend(), and dvb_frontend_resume() as
77part of their handler for &device_driver.resume().
78
79few other optional functions are provided to handle some special cases.
80
81.. kernel-doc:: drivers/media/dvb-core/dvb_frontend.h
82
83
84Digital TV Demux kABI
85---------------------
86
87Digital TV Demux
88~~~~~~~~~~~~~~~~
89
90The Kernel Digital TV Demux kABI defines a driver-internal interface for
91registering low-level, hardware specific driver to a hardware independent
92demux layer. It is only of interest for Digital TV device driver writers.
93The header file for this kABI is named demux.h and located in
94drivers/media/dvb-core.
95
96The demux kABI should be implemented for each demux in the system. It is
97used to select the TS source of a demux and to manage the demux resources.
98When the demux client allocates a resource via the demux kABI, it receives
99a pointer to the kABI of that resource.
100
101Each demux receives its TS input from a DVB front-end or from memory, as
102set via this demux kABI. In a system with more than one front-end, the kABI
103can be used to select one of the DVB front-ends as a TS source for a demux,
104unless this is fixed in the HW platform.
105
106The demux kABI only controls front-ends regarding to their connections with
107demuxes; the kABI used to set the other front-end parameters, such as
108tuning, are devined via the Digital TV Frontend kABI.
109
110The functions that implement the abstract interface demux should be defined
111static or module private and registered to the Demux core for external
112access. It is not necessary to implement every function in the struct
113&dmx_demux. For example, a demux interface might support Section filtering,
114but not PES filtering. The kABI client is expected to check the value of any
115function pointer before calling the function: the value of NULL means
116that the function is not available.
117
118Whenever the functions of the demux API modify shared data, the
119possibilities of lost update and race condition problems should be
120addressed, e.g. by protecting parts of code with mutexes.
121
122Note that functions called from a bottom half context must not sleep.
123Even a simple memory allocation without using %GFP_ATOMIC can result in a
124kernel thread being put to sleep if swapping is needed. For example, the
125Linux Kernel calls the functions of a network device interface from a
126bottom half context. Thus, if a demux kABI function is called from network
127device code, the function must not sleep.
128
129
130
131Demux Callback API
132------------------
133
134Demux Callback
135~~~~~~~~~~~~~~
136
137This kernel-space API comprises the callback functions that deliver filtered
138data to the demux client. Unlike the other DVB kABIs, these functions are
139provided by the client and called from the demux code.
140
141The function pointers of this abstract interface are not packed into a
142structure as in the other demux APIs, because the callback functions are
143registered and used independent of each other. As an example, it is possible
144for the API client to provide several callback functions for receiving TS
145packets and no callbacks for PES packets or sections.
146
147The functions that implement the callback API need not be re-entrant: when
148a demux driver calls one of these functions, the driver is not allowed to
149call the function again before the original call returns. If a callback is
150triggered by a hardware interrupt, it is recommended to use the Linux
151bottom half mechanism or start a tasklet instead of making the callback
152function call directly from a hardware interrupt.
153
154This mechanism is implemented by dmx_ts_cb() and dmx_section_cb()
155callbacks.
156
157
158.. kernel-doc:: drivers/media/dvb-core/demux.h
159
160
161Digital TV Conditional Access kABI
162----------------------------------
163
164.. kernel-doc:: drivers/media/dvb-core/dvb_ca_en50221.h
165
166
167Remote Controller devices
168-------------------------
169
170.. kernel-doc:: include/media/rc-core.h
171
172.. kernel-doc:: include/media/lirc_dev.h
173
174
175Media Controller devices
176------------------------
177
178Media Controller
179~~~~~~~~~~~~~~~~
180
181
182The media controller userspace API is documented in DocBook format in
183Documentation/DocBook/media/v4l/media-controller.xml. This document focus
184on the kernel-side implementation of the media framework.
185
186* Abstract media device model:
187
188Discovering a device internal topology, and configuring it at runtime, is one
189of the goals of the media framework. To achieve this, hardware devices are
190modelled as an oriented graph of building blocks called entities connected
191through pads.
192
193An entity is a basic media hardware building block. It can correspond to
194a large variety of logical blocks such as physical hardware devices
195(CMOS sensor for instance), logical hardware devices (a building block
196in a System-on-Chip image processing pipeline), DMA channels or physical
197connectors.
198
199A pad is a connection endpoint through which an entity can interact with
200other entities. Data (not restricted to video) produced by an entity
201flows from the entity's output to one or more entity inputs. Pads should
202not be confused with physical pins at chip boundaries.
203
204A link is a point-to-point oriented connection between two pads, either
205on the same entity or on different entities. Data flows from a source
206pad to a sink pad.
207
208
209* Media device:
210
211A media device is represented by a struct &media_device instance, defined in
212include/media/media-device.h. Allocation of the structure is handled by the
213media device driver, usually by embedding the &media_device instance in a
214larger driver-specific structure.
215
216Drivers register media device instances by calling
217__media_device_register() via the macro media_device_register()
218and unregistered by calling
219media_device_unregister().
220
221* Entities, pads and links:
222
223- Entities
224
225Entities are represented by a struct &media_entity instance, defined in
226include/media/media-entity.h. The structure is usually embedded into a
227higher-level structure, such as a v4l2_subdev or video_device instance,
228although drivers can allocate entities directly.
229
230Drivers initialize entity pads by calling
231media_entity_pads_init().
232
233Drivers register entities with a media device by calling
234media_device_register_entity()
235and unregistred by calling
236media_device_unregister_entity().
237
238- Interfaces
239
240Interfaces are represented by a struct &media_interface instance, defined in
241include/media/media-entity.h. Currently, only one type of interface is
242defined: a device node. Such interfaces are represented by a struct
243&media_intf_devnode.
244
245Drivers initialize and create device node interfaces by calling
246media_devnode_create()
247and remove them by calling:
248media_devnode_remove().
249
250- Pads
251
252Pads are represented by a struct &media_pad instance, defined in
253include/media/media-entity.h. Each entity stores its pads in a pads array
254managed by the entity driver. Drivers usually embed the array in a
255driver-specific structure.
256
257Pads are identified by their entity and their 0-based index in the pads
258array.
259Both information are stored in the &media_pad structure, making the
260&media_pad pointer the canonical way to store and pass link references.
261
262Pads have flags that describe the pad capabilities and state.
263
264%MEDIA_PAD_FL_SINK indicates that the pad supports sinking data.
265%MEDIA_PAD_FL_SOURCE indicates that the pad supports sourcing data.
266
267NOTE: One and only one of %MEDIA_PAD_FL_SINK and %MEDIA_PAD_FL_SOURCE must
268be set for each pad.
269
270- Links
271
272Links are represented by a struct &media_link instance, defined in
273include/media/media-entity.h. There are two types of links:
274
2751. pad to pad links:
276
277Associate two entities via their PADs. Each entity has a list that points
278to all links originating at or targeting any of its pads.
279A given link is thus stored twice, once in the source entity and once in
280the target entity.
281
282Drivers create pad to pad links by calling:
283media_create_pad_link() and remove with media_entity_remove_links().
284
2852. interface to entity links:
286
287Associate one interface to a Link.
288
289Drivers create interface to entity links by calling:
290media_create_intf_link() and remove with media_remove_intf_links().
291
292NOTE:
293
294Links can only be created after having both ends already created.
295
296Links have flags that describe the link capabilities and state. The
297valid values are described at media_create_pad_link() and
298media_create_intf_link().
299
300Graph traversal:
301
302The media framework provides APIs to iterate over entities in a graph.
303
304To iterate over all entities belonging to a media device, drivers can use
305the media_device_for_each_entity macro, defined in
306include/media/media-device.h.
307
308struct media_entity *entity;
309
310media_device_for_each_entity(entity, mdev) {
311// entity will point to each entity in turn
312...
313}
314
315Drivers might also need to iterate over all entities in a graph that can be
316reached only through enabled links starting at a given entity. The media
317framework provides a depth-first graph traversal API for that purpose.
318
319Note that graphs with cycles (whether directed or undirected) are *NOT*
320supported by the graph traversal API. To prevent infinite loops, the graph
321traversal code limits the maximum depth to MEDIA_ENTITY_ENUM_MAX_DEPTH,
322currently defined as 16.
323
324Drivers initiate a graph traversal by calling
325media_entity_graph_walk_start()
326
327The graph structure, provided by the caller, is initialized to start graph
328traversal at the given entity.
329
330Drivers can then retrieve the next entity by calling
331media_entity_graph_walk_next()
332
333When the graph traversal is complete the function will return NULL.
334
335Graph traversal can be interrupted at any moment. No cleanup function call
336is required and the graph structure can be freed normally.
337
338Helper functions can be used to find a link between two given pads, or a pad
339connected to another pad through an enabled link
340media_entity_find_link() and media_entity_remote_pad()
341
342Use count and power handling:
343
344Due to the wide differences between drivers regarding power management
345needs, the media controller does not implement power management. However,
346the &media_entity structure includes a use_count field that media drivers
347can use to track the number of users of every entity for power management
348needs.
349
350The &media_entity.@use_count field is owned by media drivers and must not be
351touched by entity drivers. Access to the field must be protected by the
352&media_device.@graph_mutex lock.
353
354Links setup:
355
356Link properties can be modified at runtime by calling
357media_entity_setup_link()
358
359Pipelines and media streams:
360
361When starting streaming, drivers must notify all entities in the pipeline to
362prevent link states from being modified during streaming by calling
363media_entity_pipeline_start().
364
365The function will mark all entities connected to the given entity through
366enabled links, either directly or indirectly, as streaming.
367
368The &media_pipeline instance pointed to by the pipe argument will be stored
369in every entity in the pipeline. Drivers should embed the &media_pipeline
370structure in higher-level pipeline structures and can then access the
371pipeline through the &media_entity pipe field.
372
373Calls to media_entity_pipeline_start() can be nested. The pipeline pointer
374must be identical for all nested calls to the function.
375
376media_entity_pipeline_start() may return an error. In that case, it will
377clean up any of the changes it did by itself.
378
379When stopping the stream, drivers must notify the entities with
380media_entity_pipeline_stop().
381
382If multiple calls to media_entity_pipeline_start() have been made the same
383number of media_entity_pipeline_stop() calls are required to stop streaming.
384The &media_entity pipe field is reset to NULL on the last nested stop call.
385
386Link configuration will fail with -%EBUSY by default if either end of the
387link is a streaming entity. Links that can be modified while streaming must
388be marked with the %MEDIA_LNK_FL_DYNAMIC flag.
389
390If other operations need to be disallowed on streaming entities (such as
391changing entities configuration parameters) drivers can explicitly check the
392media_entity stream_count field to find out if an entity is streaming. This
393operation must be done with the media_device graph_mutex held.
394
395Link validation:
396
397Link validation is performed by media_entity_pipeline_start() for any
398entity which has sink pads in the pipeline. The
399&media_entity.@link_validate() callback is used for that purpose. In
400@link_validate() callback, entity driver should check that the properties of
401the source pad of the connected entity and its own sink pad match. It is up
402to the type of the entity (and in the end, the properties of the hardware)
403what matching actually means.
404
405Subsystems should facilitate link validation by providing subsystem specific
406helper functions to provide easy access for commonly needed information, and
407in the end provide a way to use driver-specific callbacks.
408
409.. kernel-doc:: include/media/media-device.h
410
411.. kernel-doc:: include/media/media-devnode.h
412
413.. kernel-doc:: include/media/media-entity.h
414