162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci.. c:namespace:: V4L
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci.. _rw:
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci**********
762306a36Sopenharmony_ciRead/Write
862306a36Sopenharmony_ci**********
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciInput and output devices support the :c:func:`read()` and
1162306a36Sopenharmony_ci:c:func:`write()` function, respectively, when the
1262306a36Sopenharmony_ci``V4L2_CAP_READWRITE`` flag in the ``capabilities`` field of struct
1362306a36Sopenharmony_ci:c:type:`v4l2_capability` returned by the
1462306a36Sopenharmony_ci:ref:`VIDIOC_QUERYCAP` ioctl is set.
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ciDrivers may need the CPU to copy the data, but they may also support DMA
1762306a36Sopenharmony_cito or from user memory, so this I/O method is not necessarily less
1862306a36Sopenharmony_ciefficient than other methods merely exchanging buffer pointers. It is
1962306a36Sopenharmony_ciconsidered inferior though because no meta-information like frame
2062306a36Sopenharmony_cicounters or timestamps are passed. This information is necessary to
2162306a36Sopenharmony_cirecognize frame dropping and to synchronize with other data streams.
2262306a36Sopenharmony_ciHowever this is also the simplest I/O method, requiring little or no
2362306a36Sopenharmony_cisetup to exchange data. It permits command line stunts like this (the
2462306a36Sopenharmony_cividctrl tool is fictitious):
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci.. code-block:: none
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci    $ vidctrl /dev/video --input=0 --format=YUYV --size=352x288
2962306a36Sopenharmony_ci    $ dd if=/dev/video of=myimage.422 bs=202752 count=1
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciTo read from the device applications use the :c:func:`read()`
3262306a36Sopenharmony_cifunction, to write the :c:func:`write()` function. Drivers
3362306a36Sopenharmony_cimust implement one I/O method if they exchange data with applications,
3462306a36Sopenharmony_cibut it need not be this. [#f1]_ When reading or writing is supported, the
3562306a36Sopenharmony_cidriver must also support the :c:func:`select()` and
3662306a36Sopenharmony_ci:c:func:`poll()` function. [#f2]_
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci.. [#f1]
3962306a36Sopenharmony_ci   It would be desirable if applications could depend on drivers
4062306a36Sopenharmony_ci   supporting all I/O interfaces, but as much as the complex memory
4162306a36Sopenharmony_ci   mapping I/O can be inadequate for some devices we have no reason to
4262306a36Sopenharmony_ci   require this interface, which is most useful for simple applications
4362306a36Sopenharmony_ci   capturing still images.
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci.. [#f2]
4662306a36Sopenharmony_ci   At the driver level :c:func:`select()` and :c:func:`poll()` are
4762306a36Sopenharmony_ci   the same, and :c:func:`select()` is too important to be optional.
48