summaryrefslogtreecommitdiffstats
path: root/Documentation/linux_tv/media/v4l/rw.rst
blob: c123d3a1bfbb9454dee4b194ae09a5e63d843fdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
.. -*- coding: utf-8; mode: rst -*-

.. _rw:

**********
Read/Write
**********

Input and output devices support the :c:func:`read()` and
:c:func:`write()` function, respectively, when the
``V4L2_CAP_READWRITE`` flag in the ``capabilities`` field of struct
:ref:`v4l2_capability <v4l2-capability>` returned by the
:ref:`VIDIOC_QUERYCAP <vidioc-querycap>` ioctl is set.

Drivers may need the CPU to copy the data, but they may also support DMA
to or from user memory, so this I/O method is not necessarily less
efficient than other methods merely exchanging buffer pointers. It is
considered inferior though because no meta-information like frame
counters or timestamps are passed. This information is necessary to
recognize frame dropping and to synchronize with other data streams.
However this is also the simplest I/O method, requiring little or no
setup to exchange data. It permits command line stunts like this (the
vidctrl tool is fictitious):



::

    > vidctrl /dev/video --input=0 --format=YUYV --size=352x288
    > dd if=/dev/video of=myimage.422 bs=202752 count=1
To read from the device applications use the :ref:`read() <func-read>`
function, to write the :ref:`write() <func-write>` function. Drivers
must implement one I/O method if they exchange data with applications,
but it need not be this. [1]_ When reading or writing is supported, the
driver must also support the :ref:`select() <func-select>` and
:ref:`poll() <func-poll>` function. [2]_

.. [1]
   It would be desirable if applications could depend on drivers
   supporting all I/O interfaces, but as much as the complex memory
   mapping I/O can be inadequate for some devices we have no reason to
   require this interface, which is most useful for simple applications
   capturing still images.

.. [2]
   At the driver level :c:func:`select()` and :c:func:`poll()` are
   the same, and :c:func:`select()` is too important to be optional.


.. ------------------------------------------------------------------------------
.. This file was automatically converted from DocBook-XML with the dbxml
.. library (https://github.com/return42/sphkerneldoc). The origin XML comes
.. from the linux kernel, refer to:
..
.. * https://github.com/torvalds/linux/tree/master/Documentation/DocBook
.. ------------------------------------------------------------------------------
OpenPOWER on IntegriCloud