1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2*4882a593Smuzhiyun.. c:namespace:: V4L 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun.. _rw: 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun********** 7*4882a593SmuzhiyunRead/Write 8*4882a593Smuzhiyun********** 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunInput and output devices support the :c:func:`read()` and 11*4882a593Smuzhiyun:c:func:`write()` function, respectively, when the 12*4882a593Smuzhiyun``V4L2_CAP_READWRITE`` flag in the ``capabilities`` field of struct 13*4882a593Smuzhiyun:c:type:`v4l2_capability` returned by the 14*4882a593Smuzhiyun:ref:`VIDIOC_QUERYCAP` ioctl is set. 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunDrivers may need the CPU to copy the data, but they may also support DMA 17*4882a593Smuzhiyunto or from user memory, so this I/O method is not necessarily less 18*4882a593Smuzhiyunefficient than other methods merely exchanging buffer pointers. It is 19*4882a593Smuzhiyunconsidered inferior though because no meta-information like frame 20*4882a593Smuzhiyuncounters or timestamps are passed. This information is necessary to 21*4882a593Smuzhiyunrecognize frame dropping and to synchronize with other data streams. 22*4882a593SmuzhiyunHowever this is also the simplest I/O method, requiring little or no 23*4882a593Smuzhiyunsetup to exchange data. It permits command line stunts like this (the 24*4882a593Smuzhiyunvidctrl tool is fictitious): 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun.. code-block:: none 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun $ vidctrl /dev/video --input=0 --format=YUYV --size=352x288 29*4882a593Smuzhiyun $ dd if=/dev/video of=myimage.422 bs=202752 count=1 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunTo read from the device applications use the :c:func:`read()` 32*4882a593Smuzhiyunfunction, to write the :c:func:`write()` function. Drivers 33*4882a593Smuzhiyunmust implement one I/O method if they exchange data with applications, 34*4882a593Smuzhiyunbut it need not be this. [#f1]_ When reading or writing is supported, the 35*4882a593Smuzhiyundriver must also support the :c:func:`select()` and 36*4882a593Smuzhiyun:c:func:`poll()` function. [#f2]_ 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun.. [#f1] 39*4882a593Smuzhiyun It would be desirable if applications could depend on drivers 40*4882a593Smuzhiyun supporting all I/O interfaces, but as much as the complex memory 41*4882a593Smuzhiyun mapping I/O can be inadequate for some devices we have no reason to 42*4882a593Smuzhiyun require this interface, which is most useful for simple applications 43*4882a593Smuzhiyun capturing still images. 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun.. [#f2] 46*4882a593Smuzhiyun At the driver level :c:func:`select()` and :c:func:`poll()` are 47*4882a593Smuzhiyun the same, and :c:func:`select()` is too important to be optional. 48