1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2407e84cdSMauro Carvalho Chehab.. c:namespace:: V4L
354f38fcaSMauro Carvalho Chehab
454f38fcaSMauro Carvalho Chehab.. _rw:
554f38fcaSMauro Carvalho Chehab
654f38fcaSMauro Carvalho Chehab**********
754f38fcaSMauro Carvalho ChehabRead/Write
854f38fcaSMauro Carvalho Chehab**********
954f38fcaSMauro Carvalho Chehab
10407e84cdSMauro Carvalho ChehabInput and output devices support the :c:func:`read()` and
11407e84cdSMauro Carvalho Chehab:c:func:`write()` function, respectively, when the
1254f38fcaSMauro Carvalho Chehab``V4L2_CAP_READWRITE`` flag in the ``capabilities`` field of struct
1354f38fcaSMauro Carvalho Chehab:c:type:`v4l2_capability` returned by the
1454f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_QUERYCAP` ioctl is set.
1554f38fcaSMauro Carvalho Chehab
1654f38fcaSMauro Carvalho ChehabDrivers may need the CPU to copy the data, but they may also support DMA
1754f38fcaSMauro Carvalho Chehabto or from user memory, so this I/O method is not necessarily less
1854f38fcaSMauro Carvalho Chehabefficient than other methods merely exchanging buffer pointers. It is
1954f38fcaSMauro Carvalho Chehabconsidered inferior though because no meta-information like frame
2054f38fcaSMauro Carvalho Chehabcounters or timestamps are passed. This information is necessary to
2154f38fcaSMauro Carvalho Chehabrecognize frame dropping and to synchronize with other data streams.
2254f38fcaSMauro Carvalho ChehabHowever this is also the simplest I/O method, requiring little or no
2354f38fcaSMauro Carvalho Chehabsetup to exchange data. It permits command line stunts like this (the
2454f38fcaSMauro Carvalho Chehabvidctrl tool is fictitious):
2554f38fcaSMauro Carvalho Chehab
2654f38fcaSMauro Carvalho Chehab.. code-block:: none
2754f38fcaSMauro Carvalho Chehab
2854f38fcaSMauro Carvalho Chehab    $ vidctrl /dev/video --input=0 --format=YUYV --size=352x288
2954f38fcaSMauro Carvalho Chehab    $ dd if=/dev/video of=myimage.422 bs=202752 count=1
3054f38fcaSMauro Carvalho Chehab
31407e84cdSMauro Carvalho ChehabTo read from the device applications use the :c:func:`read()`
32407e84cdSMauro Carvalho Chehabfunction, to write the :c:func:`write()` function. Drivers
3354f38fcaSMauro Carvalho Chehabmust implement one I/O method if they exchange data with applications,
3454f38fcaSMauro Carvalho Chehabbut it need not be this. [#f1]_ When reading or writing is supported, the
35407e84cdSMauro Carvalho Chehabdriver must also support the :c:func:`select()` and
36407e84cdSMauro Carvalho Chehab:c:func:`poll()` function. [#f2]_
3754f38fcaSMauro Carvalho Chehab
3854f38fcaSMauro Carvalho Chehab.. [#f1]
3954f38fcaSMauro Carvalho Chehab   It would be desirable if applications could depend on drivers
4054f38fcaSMauro Carvalho Chehab   supporting all I/O interfaces, but as much as the complex memory
4154f38fcaSMauro Carvalho Chehab   mapping I/O can be inadequate for some devices we have no reason to
4254f38fcaSMauro Carvalho Chehab   require this interface, which is most useful for simple applications
4354f38fcaSMauro Carvalho Chehab   capturing still images.
4454f38fcaSMauro Carvalho Chehab
4554f38fcaSMauro Carvalho Chehab.. [#f2]
46407e84cdSMauro Carvalho Chehab   At the driver level :c:func:`select()` and :c:func:`poll()` are
47407e84cdSMauro Carvalho Chehab   the same, and :c:func:`select()` is too important to be optional.
48