18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 28c2ecf20Sopenharmony_ci.. c:namespace:: V4L 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci.. _rw: 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci********** 78c2ecf20Sopenharmony_ciRead/Write 88c2ecf20Sopenharmony_ci********** 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciInput and output devices support the :c:func:`read()` and 118c2ecf20Sopenharmony_ci:c:func:`write()` function, respectively, when the 128c2ecf20Sopenharmony_ci``V4L2_CAP_READWRITE`` flag in the ``capabilities`` field of struct 138c2ecf20Sopenharmony_ci:c:type:`v4l2_capability` returned by the 148c2ecf20Sopenharmony_ci:ref:`VIDIOC_QUERYCAP` ioctl is set. 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ciDrivers may need the CPU to copy the data, but they may also support DMA 178c2ecf20Sopenharmony_cito or from user memory, so this I/O method is not necessarily less 188c2ecf20Sopenharmony_ciefficient than other methods merely exchanging buffer pointers. It is 198c2ecf20Sopenharmony_ciconsidered inferior though because no meta-information like frame 208c2ecf20Sopenharmony_cicounters or timestamps are passed. This information is necessary to 218c2ecf20Sopenharmony_cirecognize frame dropping and to synchronize with other data streams. 228c2ecf20Sopenharmony_ciHowever this is also the simplest I/O method, requiring little or no 238c2ecf20Sopenharmony_cisetup to exchange data. It permits command line stunts like this (the 248c2ecf20Sopenharmony_cividctrl tool is fictitious): 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci.. code-block:: none 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci $ vidctrl /dev/video --input=0 --format=YUYV --size=352x288 298c2ecf20Sopenharmony_ci $ dd if=/dev/video of=myimage.422 bs=202752 count=1 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciTo read from the device applications use the :c:func:`read()` 328c2ecf20Sopenharmony_cifunction, to write the :c:func:`write()` function. Drivers 338c2ecf20Sopenharmony_cimust implement one I/O method if they exchange data with applications, 348c2ecf20Sopenharmony_cibut it need not be this. [#f1]_ When reading or writing is supported, the 358c2ecf20Sopenharmony_cidriver must also support the :c:func:`select()` and 368c2ecf20Sopenharmony_ci:c:func:`poll()` function. [#f2]_ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci.. [#f1] 398c2ecf20Sopenharmony_ci It would be desirable if applications could depend on drivers 408c2ecf20Sopenharmony_ci supporting all I/O interfaces, but as much as the complex memory 418c2ecf20Sopenharmony_ci mapping I/O can be inadequate for some devices we have no reason to 428c2ecf20Sopenharmony_ci require this interface, which is most useful for simple applications 438c2ecf20Sopenharmony_ci capturing still images. 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci.. [#f2] 468c2ecf20Sopenharmony_ci At the driver level :c:func:`select()` and :c:func:`poll()` are 478c2ecf20Sopenharmony_ci the same, and :c:func:`select()` is too important to be optional. 48