dev-subdev.rst 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _subdev:
  4. ********************
  5. Sub-device Interface
  6. ********************
  7. The complex nature of V4L2 devices, where hardware is often made of
  8. several integrated circuits that need to interact with each other in a
  9. controlled way, leads to complex V4L2 drivers. The drivers usually
  10. reflect the hardware model in software, and model the different hardware
  11. components as software blocks called sub-devices.
  12. V4L2 sub-devices are usually kernel-only objects. If the V4L2 driver
  13. implements the media device API, they will automatically inherit from
  14. media entities. Applications will be able to enumerate the sub-devices
  15. and discover the hardware topology using the media entities, pads and
  16. links enumeration API.
  17. In addition to make sub-devices discoverable, drivers can also choose to
  18. make them directly configurable by applications. When both the
  19. sub-device driver and the V4L2 device driver support this, sub-devices
  20. will feature a character device node on which ioctls can be called to
  21. - query, read and write sub-devices controls
  22. - subscribe and unsubscribe to events and retrieve them
  23. - negotiate image formats on individual pads
  24. - inspect and modify internal data routing between pads of the same entity
  25. Sub-device character device nodes, conventionally named
  26. ``/dev/v4l-subdev*``, use major number 81.
  27. Drivers may opt to limit the sub-device character devices to only expose
  28. operations that do not modify the device state. In such a case the sub-devices
  29. are referred to as ``read-only`` in the rest of this documentation, and the
  30. related restrictions are documented in individual ioctls.
  31. Controls
  32. ========
  33. Most V4L2 controls are implemented by sub-device hardware. Drivers
  34. usually merge all controls and expose them through video device nodes.
  35. Applications can control all sub-devices through a single interface.
  36. Complex devices sometimes implement the same control in different pieces
  37. of hardware. This situation is common in embedded platforms, where both
  38. sensors and image processing hardware implement identical functions,
  39. such as contrast adjustment, white balance or faulty pixels correction.
  40. As the V4L2 controls API doesn't support several identical controls in a
  41. single device, all but one of the identical controls are hidden.
  42. Applications can access those hidden controls through the sub-device
  43. node with the V4L2 control API described in :ref:`control`. The ioctls
  44. behave identically as when issued on V4L2 device nodes, with the
  45. exception that they deal only with controls implemented in the
  46. sub-device.
  47. Depending on the driver, those controls might also be exposed through
  48. one (or several) V4L2 device nodes.
  49. Events
  50. ======
  51. V4L2 sub-devices can notify applications of events as described in
  52. :ref:`event`. The API behaves identically as when used on V4L2 device
  53. nodes, with the exception that it only deals with events generated by
  54. the sub-device. Depending on the driver, those events might also be
  55. reported on one (or several) V4L2 device nodes.
  56. .. _pad-level-formats:
  57. Pad-level Formats
  58. =================
  59. .. warning::
  60. Pad-level formats are only applicable to very complex devices that
  61. need to expose low-level format configuration to user space. Generic
  62. V4L2 applications do *not* need to use the API described in this
  63. section.
  64. .. note::
  65. For the purpose of this section, the term *format* means the
  66. combination of media bus data format, frame width and frame height.
  67. Image formats are typically negotiated on video capture and output
  68. devices using the format and
  69. :ref:`selection <VIDIOC_SUBDEV_G_SELECTION>` ioctls. The driver is
  70. responsible for configuring every block in the video pipeline according
  71. to the requested format at the pipeline input and/or output.
  72. For complex devices, such as often found in embedded systems, identical
  73. image sizes at the output of a pipeline can be achieved using different
  74. hardware configurations. One such example is shown on
  75. :ref:`pipeline-scaling`, where image scaling can be performed on both
  76. the video sensor and the host image processing hardware.
  77. .. _pipeline-scaling:
  78. .. kernel-figure:: pipeline.dot
  79. :alt: pipeline.dot
  80. :align: center
  81. Image Format Negotiation on Pipelines
  82. High quality and high speed pipeline configuration
  83. The sensor scaler is usually of less quality than the host scaler, but
  84. scaling on the sensor is required to achieve higher frame rates.
  85. Depending on the use case (quality vs. speed), the pipeline must be
  86. configured differently. Applications need to configure the formats at
  87. every point in the pipeline explicitly.
  88. Drivers that implement the :ref:`media API <media-controller-intro>`
  89. can expose pad-level image format configuration to applications. When
  90. they do, applications can use the
  91. :ref:`VIDIOC_SUBDEV_G_FMT <VIDIOC_SUBDEV_G_FMT>` and
  92. :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctls. to
  93. negotiate formats on a per-pad basis.
  94. Applications are responsible for configuring coherent parameters on the
  95. whole pipeline and making sure that connected pads have compatible
  96. formats. The pipeline is checked for formats mismatch at
  97. :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` time, and an ``EPIPE`` error
  98. code is then returned if the configuration is invalid.
  99. Pad-level image format configuration support can be tested by calling
  100. the :ref:`VIDIOC_SUBDEV_G_FMT` ioctl on pad
  101. 0. If the driver returns an ``EINVAL`` error code pad-level format
  102. configuration is not supported by the sub-device.
  103. Format Negotiation
  104. ------------------
  105. Acceptable formats on pads can (and usually do) depend on a number of
  106. external parameters, such as formats on other pads, active links, or
  107. even controls. Finding a combination of formats on all pads in a video
  108. pipeline, acceptable to both application and driver, can't rely on
  109. formats enumeration only. A format negotiation mechanism is required.
  110. Central to the format negotiation mechanism are the get/set format
  111. operations. When called with the ``which`` argument set to
  112. :ref:`V4L2_SUBDEV_FORMAT_TRY <VIDIOC_SUBDEV_G_FMT>`, the
  113. :ref:`VIDIOC_SUBDEV_G_FMT <VIDIOC_SUBDEV_G_FMT>` and
  114. :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctls operate on
  115. a set of formats parameters that are not connected to the hardware
  116. configuration. Modifying those 'try' formats leaves the device state
  117. untouched (this applies to both the software state stored in the driver
  118. and the hardware state stored in the device itself).
  119. While not kept as part of the device state, try formats are stored in
  120. the sub-device file handles. A
  121. :ref:`VIDIOC_SUBDEV_G_FMT <VIDIOC_SUBDEV_G_FMT>` call will return
  122. the last try format set *on the same sub-device file handle*. Several
  123. applications querying the same sub-device at the same time will thus not
  124. interact with each other.
  125. To find out whether a particular format is supported by the device,
  126. applications use the
  127. :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctl. Drivers
  128. verify and, if needed, change the requested ``format`` based on device
  129. requirements and return the possibly modified value. Applications can
  130. then choose to try a different format or accept the returned value and
  131. continue.
  132. Formats returned by the driver during a negotiation iteration are
  133. guaranteed to be supported by the device. In particular, drivers
  134. guarantee that a returned format will not be further changed if passed
  135. to an :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` call as-is
  136. (as long as external parameters, such as formats on other pads or links'
  137. configuration are not changed).
  138. Drivers automatically propagate formats inside sub-devices. When a try
  139. or active format is set on a pad, corresponding formats on other pads of
  140. the same sub-device can be modified by the driver. Drivers are free to
  141. modify formats as required by the device. However, they should comply
  142. with the following rules when possible:
  143. - Formats should be propagated from sink pads to source pads. Modifying
  144. a format on a source pad should not modify the format on any sink
  145. pad.
  146. - Sub-devices that scale frames using variable scaling factors should
  147. reset the scale factors to default values when sink pads formats are
  148. modified. If the 1:1 scaling ratio is supported, this means that
  149. source pads formats should be reset to the sink pads formats.
  150. Formats are not propagated across links, as that would involve
  151. propagating them from one sub-device file handle to another.
  152. Applications must then take care to configure both ends of every link
  153. explicitly with compatible formats. Identical formats on the two ends of
  154. a link are guaranteed to be compatible. Drivers are free to accept
  155. different formats matching device requirements as being compatible.
  156. :ref:`sample-pipeline-config` shows a sample configuration sequence
  157. for the pipeline described in :ref:`pipeline-scaling` (table columns
  158. list entity names and pad numbers).
  159. .. raw:: latex
  160. \begingroup
  161. \scriptsize
  162. \setlength{\tabcolsep}{2pt}
  163. .. tabularcolumns:: |p{2.0cm}|p{2.1cm}|p{2.1cm}|p{2.1cm}|p{2.1cm}|p{2.1cm}|p{2.1cm}|
  164. .. _sample-pipeline-config:
  165. .. flat-table:: Sample Pipeline Configuration
  166. :header-rows: 1
  167. :stub-columns: 0
  168. :widths: 5 5 5 5 5 5 5
  169. * -
  170. - Sensor/0
  171. format
  172. - Frontend/0
  173. format
  174. - Frontend/1
  175. format
  176. - Scaler/0
  177. format
  178. - Scaler/0
  179. compose selection rectangle
  180. - Scaler/1
  181. format
  182. * - Initial state
  183. - 2048x1536
  184. SGRBG8_1X8
  185. - (default)
  186. - (default)
  187. - (default)
  188. - (default)
  189. - (default)
  190. * - Configure frontend sink format
  191. - 2048x1536
  192. SGRBG8_1X8
  193. - *2048x1536*
  194. *SGRBG8_1X8*
  195. - *2046x1534*
  196. *SGRBG8_1X8*
  197. - (default)
  198. - (default)
  199. - (default)
  200. * - Configure scaler sink format
  201. - 2048x1536
  202. SGRBG8_1X8
  203. - 2048x1536
  204. SGRBG8_1X8
  205. - 2046x1534
  206. SGRBG8_1X8
  207. - *2046x1534*
  208. *SGRBG8_1X8*
  209. - *0,0/2046x1534*
  210. - *2046x1534*
  211. *SGRBG8_1X8*
  212. * - Configure scaler sink compose selection
  213. - 2048x1536
  214. SGRBG8_1X8
  215. - 2048x1536
  216. SGRBG8_1X8
  217. - 2046x1534
  218. SGRBG8_1X8
  219. - 2046x1534
  220. SGRBG8_1X8
  221. - *0,0/1280x960*
  222. - *1280x960*
  223. *SGRBG8_1X8*
  224. .. raw:: latex
  225. \endgroup
  226. 1. Initial state. The sensor source pad format is set to its native 3MP
  227. size and V4L2_MBUS_FMT_SGRBG8_1X8 media bus code. Formats on the
  228. host frontend and scaler sink and source pads have the default
  229. values, as well as the compose rectangle on the scaler's sink pad.
  230. 2. The application configures the frontend sink pad format's size to
  231. 2048x1536 and its media bus code to V4L2_MBUS_FMT_SGRBG_1X8. The
  232. driver propagates the format to the frontend source pad.
  233. 3. The application configures the scaler sink pad format's size to
  234. 2046x1534 and the media bus code to V4L2_MBUS_FMT_SGRBG_1X8 to
  235. match the frontend source size and media bus code. The media bus code
  236. on the sink pad is set to V4L2_MBUS_FMT_SGRBG_1X8. The driver
  237. propagates the size to the compose selection rectangle on the
  238. scaler's sink pad, and the format to the scaler source pad.
  239. 4. The application configures the size of the compose selection
  240. rectangle of the scaler's sink pad 1280x960. The driver propagates
  241. the size to the scaler's source pad format.
  242. When satisfied with the try results, applications can set the active
  243. formats by setting the ``which`` argument to
  244. ``V4L2_SUBDEV_FORMAT_ACTIVE``. Active formats are changed exactly as try
  245. formats by drivers. To avoid modifying the hardware state during format
  246. negotiation, applications should negotiate try formats first and then
  247. modify the active settings using the try formats returned during the
  248. last negotiation iteration. This guarantees that the active format will
  249. be applied as-is by the driver without being modified.
  250. .. _v4l2-subdev-selections:
  251. Selections: cropping, scaling and composition
  252. ---------------------------------------------
  253. Many sub-devices support cropping frames on their input or output pads
  254. (or possible even on both). Cropping is used to select the area of
  255. interest in an image, typically on an image sensor or a video decoder.
  256. It can also be used as part of digital zoom implementations to select
  257. the area of the image that will be scaled up.
  258. Crop settings are defined by a crop rectangle and represented in a
  259. struct :c:type:`v4l2_rect` by the coordinates of the top
  260. left corner and the rectangle size. Both the coordinates and sizes are
  261. expressed in pixels.
  262. As for pad formats, drivers store try and active rectangles for the
  263. selection targets :ref:`v4l2-selections-common`.
  264. On sink pads, cropping is applied relative to the current pad format.
  265. The pad format represents the image size as received by the sub-device
  266. from the previous block in the pipeline, and the crop rectangle
  267. represents the sub-image that will be transmitted further inside the
  268. sub-device for processing.
  269. The scaling operation changes the size of the image by scaling it to new
  270. dimensions. The scaling ratio isn't specified explicitly, but is implied
  271. from the original and scaled image sizes. Both sizes are represented by
  272. struct :c:type:`v4l2_rect`.
  273. Scaling support is optional. When supported by a subdev, the crop
  274. rectangle on the subdev's sink pad is scaled to the size configured
  275. using the
  276. :ref:`VIDIOC_SUBDEV_S_SELECTION <VIDIOC_SUBDEV_G_SELECTION>` IOCTL
  277. using ``V4L2_SEL_TGT_COMPOSE`` selection target on the same pad. If the
  278. subdev supports scaling but not composing, the top and left values are
  279. not used and must always be set to zero.
  280. On source pads, cropping is similar to sink pads, with the exception
  281. that the source size from which the cropping is performed, is the
  282. COMPOSE rectangle on the sink pad. In both sink and source pads, the
  283. crop rectangle must be entirely contained inside the source image size
  284. for the crop operation.
  285. The drivers should always use the closest possible rectangle the user
  286. requests on all selection targets, unless specifically told otherwise.
  287. ``V4L2_SEL_FLAG_GE`` and ``V4L2_SEL_FLAG_LE`` flags may be used to round
  288. the image size either up or down. :ref:`v4l2-selection-flags`
  289. Types of selection targets
  290. --------------------------
  291. Actual targets
  292. ^^^^^^^^^^^^^^
  293. Actual targets (without a postfix) reflect the actual hardware
  294. configuration at any point of time. There is a BOUNDS target
  295. corresponding to every actual target.
  296. BOUNDS targets
  297. ^^^^^^^^^^^^^^
  298. BOUNDS targets is the smallest rectangle that contains all valid actual
  299. rectangles. It may not be possible to set the actual rectangle as large
  300. as the BOUNDS rectangle, however. This may be because e.g. a sensor's
  301. pixel array is not rectangular but cross-shaped or round. The maximum
  302. size may also be smaller than the BOUNDS rectangle.
  303. .. _format-propagation:
  304. Order of configuration and format propagation
  305. ---------------------------------------------
  306. Inside subdevs, the order of image processing steps will always be from
  307. the sink pad towards the source pad. This is also reflected in the order
  308. in which the configuration must be performed by the user: the changes
  309. made will be propagated to any subsequent stages. If this behaviour is
  310. not desired, the user must set ``V4L2_SEL_FLAG_KEEP_CONFIG`` flag. This
  311. flag causes no propagation of the changes are allowed in any
  312. circumstances. This may also cause the accessed rectangle to be adjusted
  313. by the driver, depending on the properties of the underlying hardware.
  314. The coordinates to a step always refer to the actual size of the
  315. previous step. The exception to this rule is the sink compose
  316. rectangle, which refers to the sink compose bounds rectangle --- if it
  317. is supported by the hardware.
  318. 1. Sink pad format. The user configures the sink pad format. This format
  319. defines the parameters of the image the entity receives through the
  320. pad for further processing.
  321. 2. Sink pad actual crop selection. The sink pad crop defines the crop
  322. performed to the sink pad format.
  323. 3. Sink pad actual compose selection. The size of the sink pad compose
  324. rectangle defines the scaling ratio compared to the size of the sink
  325. pad crop rectangle. The location of the compose rectangle specifies
  326. the location of the actual sink compose rectangle in the sink compose
  327. bounds rectangle.
  328. 4. Source pad actual crop selection. Crop on the source pad defines crop
  329. performed to the image in the sink compose bounds rectangle.
  330. 5. Source pad format. The source pad format defines the output pixel
  331. format of the subdev, as well as the other parameters with the
  332. exception of the image width and height. Width and height are defined
  333. by the size of the source pad actual crop selection.
  334. Accessing any of the above rectangles not supported by the subdev will
  335. return ``EINVAL``. Any rectangle referring to a previous unsupported
  336. rectangle coordinates will instead refer to the previous supported
  337. rectangle. For example, if sink crop is not supported, the compose
  338. selection will refer to the sink pad format dimensions instead.
  339. .. _subdev-image-processing-crop:
  340. .. kernel-figure:: subdev-image-processing-crop.svg
  341. :alt: subdev-image-processing-crop.svg
  342. :align: center
  343. Image processing in subdevs: simple crop example
  344. In the above example, the subdev supports cropping on its sink pad. To
  345. configure it, the user sets the media bus format on the subdev's sink
  346. pad. Now the actual crop rectangle can be set on the sink pad --- the
  347. location and size of this rectangle reflect the location and size of a
  348. rectangle to be cropped from the sink format. The size of the sink crop
  349. rectangle will also be the size of the format of the subdev's source
  350. pad.
  351. .. _subdev-image-processing-scaling-multi-source:
  352. .. kernel-figure:: subdev-image-processing-scaling-multi-source.svg
  353. :alt: subdev-image-processing-scaling-multi-source.svg
  354. :align: center
  355. Image processing in subdevs: scaling with multiple sources
  356. In this example, the subdev is capable of first cropping, then scaling
  357. and finally cropping for two source pads individually from the resulting
  358. scaled image. The location of the scaled image in the cropped image is
  359. ignored in sink compose target. Both of the locations of the source crop
  360. rectangles refer to the sink scaling rectangle, independently cropping
  361. an area at location specified by the source crop rectangle from it.
  362. .. _subdev-image-processing-full:
  363. .. kernel-figure:: subdev-image-processing-full.svg
  364. :alt: subdev-image-processing-full.svg
  365. :align: center
  366. Image processing in subdevs: scaling and composition with multiple sinks and sources
  367. The subdev driver supports two sink pads and two source pads. The images
  368. from both of the sink pads are individually cropped, then scaled and
  369. further composed on the composition bounds rectangle. From that, two
  370. independent streams are cropped and sent out of the subdev from the
  371. source pads.
  372. .. toctree::
  373. :maxdepth: 1
  374. subdev-formats
  375. .. _subdev-routing:
  376. Streams, multiplexed media pads and internal routing
  377. ====================================================
  378. Simple V4L2 sub-devices do not support multiple, unrelated video streams,
  379. and only a single stream can pass through a media link and a media pad.
  380. Thus each pad contains a format and selection configuration for that
  381. single stream. A subdev can do stream processing and split a stream into
  382. two or compose two streams into one, but the inputs and outputs for the
  383. subdev are still a single stream per pad.
  384. Some hardware, e.g. MIPI CSI-2, support multiplexed streams, that is, multiple
  385. data streams are transmitted on the same bus, which is represented by a media
  386. link connecting a transmitter source pad with a sink pad on the receiver. For
  387. example, a camera sensor can produce two distinct streams, a pixel stream and a
  388. metadata stream, which are transmitted on the multiplexed data bus, represented
  389. by a media link which connects the single sensor's source pad with the receiver
  390. sink pad. The stream-aware receiver will de-multiplex the streams received on
  391. the its sink pad and allows to route them individually to one of its source
  392. pads.
  393. Subdevice drivers that support multiplexed streams are compatible with
  394. non-multiplexed subdev drivers. However, if the driver at the sink end of a link
  395. does not support streams, then only stream 0 of source end may be captured.
  396. There may be additional limitations specific to the sink device.
  397. Understanding streams
  398. ---------------------
  399. A stream is a stream of content (e.g. pixel data or metadata) flowing through
  400. the media pipeline from a source (e.g. a sensor) towards the final sink (e.g. a
  401. receiver and demultiplexer in a SoC). Each media link carries all the enabled
  402. streams from one end of the link to the other, and sub-devices have routing
  403. tables which describe how the incoming streams from sink pads are routed to the
  404. source pads.
  405. A stream ID is a media pad-local identifier for a stream. Streams IDs of
  406. the same stream must be equal on both ends of a link. In other words,
  407. a particular stream ID must exist on both sides of a media
  408. link, but another stream ID can be used for the same stream at the other side
  409. of the sub-device.
  410. A stream at a specific point in the media pipeline is identified by the
  411. sub-device and a (pad, stream) pair. For sub-devices that do not support
  412. multiplexed streams the 'stream' field is always 0.
  413. Interaction between routes, streams, formats and selections
  414. -----------------------------------------------------------
  415. The addition of streams to the V4L2 sub-device interface moves the sub-device
  416. formats and selections from pads to (pad, stream) pairs. Besides the
  417. usual pad, also the stream ID needs to be provided for setting formats and
  418. selections. The order of configuring formats and selections along a stream is
  419. the same as without streams (see :ref:`format-propagation`).
  420. Instead of the sub-device wide merging of streams from all sink pads
  421. towards all source pads, data flows for each route are separate from each
  422. other. Any number of routes from streams on sink pads towards streams on
  423. source pads is allowed, to the extent supported by drivers. For every
  424. stream on a source pad, however, only a single route is allowed.
  425. Any configurations of a stream within a pad, such as format or selections,
  426. are independent of similar configurations on other streams. This is
  427. subject to change in the future.
  428. Device types and routing setup
  429. ------------------------------
  430. Different kinds of sub-devices have differing behaviour for route activation,
  431. depending on the hardware. In all cases, however, only routes that have the
  432. ``V4L2_SUBDEV_ROUTE_FL_ACTIVE`` flag set are active.
  433. Devices generating the streams may allow enabling and disabling some of the
  434. routes or have a fixed routing configuration. If the routes can be disabled, not
  435. declaring the routes (or declaring them without ``V4L2_SUBDEV_ROUTE_FL_ACTIVE``
  436. flag set) in ``VIDIOC_SUBDEV_S_ROUTING`` will disable the routes.
  437. ``VIDIOC_SUBDEV_S_ROUTING`` will still return such routes back to the user in
  438. the routes array, with the ``V4L2_SUBDEV_ROUTE_FL_ACTIVE`` flag unset.
  439. Devices transporting the streams almost always have more configurability with
  440. respect to routing. Typically any route between the sub-device's sink and source
  441. pads is possible, and multiple routes (usually up to certain limited number) may
  442. be active simultaneously. For such devices, no routes are created by the driver
  443. and user-created routes are fully replaced when ``VIDIOC_SUBDEV_S_ROUTING`` is
  444. called on the sub-device. Such newly created routes have the device's default
  445. configuration for format and selection rectangles.
  446. Configuring streams
  447. -------------------
  448. The configuration of the streams is done individually for each sub-device and
  449. the validity of the streams between sub-devices is validated when the pipeline
  450. is started.
  451. There are three steps in configuring the streams:
  452. 1. Set up links. Connect the pads between sub-devices using the
  453. :ref:`Media Controller API <media_controller>`
  454. 2. Streams. Streams are declared and their routing is configured by setting the
  455. routing table for the sub-device using :ref:`VIDIOC_SUBDEV_S_ROUTING
  456. <VIDIOC_SUBDEV_G_ROUTING>` ioctl. Note that setting the routing table will
  457. reset formats and selections in the sub-device to default values.
  458. 3. Configure formats and selections. Formats and selections of each stream are
  459. configured separately as documented for plain sub-devices in
  460. :ref:`format-propagation`. The stream ID is set to the same stream ID
  461. associated with either sink or source pads of routes configured using the
  462. :ref:`VIDIOC_SUBDEV_S_ROUTING <VIDIOC_SUBDEV_G_ROUTING>` ioctl.
  463. Multiplexed streams setup example
  464. ---------------------------------
  465. A simple example of a multiplexed stream setup might be as follows:
  466. - Two identical sensors (Sensor A and Sensor B). Each sensor has a single source
  467. pad (pad 0) which carries a pixel data stream.
  468. - Multiplexer bridge (Bridge). The bridge has two sink pads, connected to the
  469. sensors (pads 0, 1), and one source pad (pad 2), which outputs two streams.
  470. - Receiver in the SoC (Receiver). The receiver has a single sink pad (pad 0),
  471. connected to the bridge, and two source pads (pads 1-2), going to the DMA
  472. engine. The receiver demultiplexes the incoming streams to the source pads.
  473. - DMA Engines in the SoC (DMA Engine), one for each stream. Each DMA engine is
  474. connected to a single source pad in the receiver.
  475. The sensors, the bridge and the receiver are modeled as V4L2 sub-devices,
  476. exposed to userspace via /dev/v4l-subdevX device nodes. The DMA engines are
  477. modeled as V4L2 devices, exposed to userspace via /dev/videoX nodes.
  478. To configure this pipeline, the userspace must take the following steps:
  479. 1. Set up media links between entities: connect the sensors to the bridge,
  480. bridge to the receiver, and the receiver to the DMA engines. This step does
  481. not differ from normal non-multiplexed media controller setup.
  482. 2. Configure routing
  483. .. flat-table:: Bridge routing table
  484. :header-rows: 1
  485. * - Sink Pad/Stream
  486. - Source Pad/Stream
  487. - Routing Flags
  488. - Comments
  489. * - 0/0
  490. - 2/0
  491. - V4L2_SUBDEV_ROUTE_FL_ACTIVE
  492. - Pixel data stream from Sensor A
  493. * - 1/0
  494. - 2/1
  495. - V4L2_SUBDEV_ROUTE_FL_ACTIVE
  496. - Pixel data stream from Sensor B
  497. .. flat-table:: Receiver routing table
  498. :header-rows: 1
  499. * - Sink Pad/Stream
  500. - Source Pad/Stream
  501. - Routing Flags
  502. - Comments
  503. * - 0/0
  504. - 1/0
  505. - V4L2_SUBDEV_ROUTE_FL_ACTIVE
  506. - Pixel data stream from Sensor A
  507. * - 0/1
  508. - 2/0
  509. - V4L2_SUBDEV_ROUTE_FL_ACTIVE
  510. - Pixel data stream from Sensor B
  511. 3. Configure formats and selections
  512. After configuring routing, the next step is configuring the formats and
  513. selections for the streams. This is similar to performing this step without
  514. streams, with just one exception: the ``stream`` field needs to be assigned
  515. to the value of the stream ID.
  516. A common way to accomplish this is to start from the sensors and propagate
  517. the configurations along the stream towards the receiver, using
  518. :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctls to configure each
  519. stream endpoint in each sub-device.