rw.rst 1.9 KB

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