func-read.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <refentry id="func-read">
  2. <refmeta>
  3. <refentrytitle>V4L2 read()</refentrytitle>
  4. &manvol;
  5. </refmeta>
  6. <refnamediv>
  7. <refname>v4l2-read</refname>
  8. <refpurpose>Read from a V4L2 device</refpurpose>
  9. </refnamediv>
  10. <refsynopsisdiv>
  11. <funcsynopsis>
  12. <funcsynopsisinfo>#include &lt;unistd.h&gt;</funcsynopsisinfo>
  13. <funcprototype>
  14. <funcdef>ssize_t <function>read</function></funcdef>
  15. <paramdef>int <parameter>fd</parameter></paramdef>
  16. <paramdef>void *<parameter>buf</parameter></paramdef>
  17. <paramdef>size_t <parameter>count</parameter></paramdef>
  18. </funcprototype>
  19. </funcsynopsis>
  20. </refsynopsisdiv>
  21. <refsect1>
  22. <title>Arguments</title>
  23. <variablelist>
  24. <varlistentry>
  25. <term><parameter>fd</parameter></term>
  26. <listitem>
  27. <para>&fd;</para>
  28. </listitem>
  29. </varlistentry>
  30. <varlistentry>
  31. <term><parameter>buf</parameter></term>
  32. <listitem>
  33. <para></para>
  34. </listitem>
  35. </varlistentry>
  36. <varlistentry>
  37. <term><parameter>count</parameter></term>
  38. <listitem>
  39. <para></para>
  40. </listitem>
  41. </varlistentry>
  42. </variablelist>
  43. </refsect1>
  44. <refsect1>
  45. <title>Description</title>
  46. <para><function>read()</function> attempts to read up to
  47. <parameter>count</parameter> bytes from file descriptor
  48. <parameter>fd</parameter> into the buffer starting at
  49. <parameter>buf</parameter>. The layout of the data in the buffer is
  50. discussed in the respective device interface section, see ##. If <parameter>count</parameter> is zero,
  51. <function>read()</function> returns zero and has no other results. If
  52. <parameter>count</parameter> is greater than
  53. <constant>SSIZE_MAX</constant>, the result is unspecified. Regardless
  54. of the <parameter>count</parameter> value each
  55. <function>read()</function> call will provide at most one frame (two
  56. fields) worth of data.</para>
  57. <para>By default <function>read()</function> blocks until data
  58. becomes available. When the <constant>O_NONBLOCK</constant> flag was
  59. given to the &func-open; function it
  60. returns immediately with an &EAGAIN; when no data is available. The
  61. &func-select; or &func-poll; functions
  62. can always be used to suspend execution until data becomes available. All
  63. drivers supporting the <function>read()</function> function must also
  64. support <function>select()</function> and
  65. <function>poll()</function>.</para>
  66. <para>Drivers can implement read functionality in different
  67. ways, using a single or multiple buffers and discarding the oldest or
  68. newest frames once the internal buffers are filled.</para>
  69. <para><function>read()</function> never returns a "snapshot" of a
  70. buffer being filled. Using a single buffer the driver will stop
  71. capturing when the application starts reading the buffer until the
  72. read is finished. Thus only the period of the vertical blanking
  73. interval is available for reading, or the capture rate must fall below
  74. the nominal frame rate of the video standard.</para>
  75. <para>The behavior of
  76. <function>read()</function> when called during the active picture
  77. period or the vertical blanking separating the top and bottom field
  78. depends on the discarding policy. A driver discarding the oldest
  79. frames keeps capturing into an internal buffer, continuously
  80. overwriting the previously, not read frame, and returns the frame
  81. being received at the time of the <function>read()</function> call as
  82. soon as it is complete.</para>
  83. <para>A driver discarding the newest frames stops capturing until
  84. the next <function>read()</function> call. The frame being received at
  85. <function>read()</function> time is discarded, returning the following
  86. frame instead. Again this implies a reduction of the capture rate to
  87. one half or less of the nominal frame rate. An example of this model
  88. is the video read mode of the bttv driver, initiating a DMA to user
  89. memory when <function>read()</function> is called and returning when
  90. the DMA finished.</para>
  91. <para>In the multiple buffer model drivers maintain a ring of
  92. internal buffers, automatically advancing to the next free buffer.
  93. This allows continuous capturing when the application can empty the
  94. buffers fast enough. Again, the behavior when the driver runs out of
  95. free buffers depends on the discarding policy.</para>
  96. <para>Applications can get and set the number of buffers used
  97. internally by the driver with the &VIDIOC-G-PARM; and &VIDIOC-S-PARM;
  98. ioctls. They are optional, however. The discarding policy is not
  99. reported and cannot be changed. For minimum requirements see <xref
  100. linkend="devices" />.</para>
  101. </refsect1>
  102. <refsect1>
  103. <title>Return Value</title>
  104. <para>On success, the number of bytes read is returned. It is not
  105. an error if this number is smaller than the number of bytes requested,
  106. or the amount of data required for one frame. This may happen for
  107. example because <function>read()</function> was interrupted by a
  108. signal. On error, -1 is returned, and the <varname>errno</varname>
  109. variable is set appropriately. In this case the next read will start
  110. at the beginning of a new frame. Possible error codes are:</para>
  111. <variablelist>
  112. <varlistentry>
  113. <term><errorcode>EAGAIN</errorcode></term>
  114. <listitem>
  115. <para>Non-blocking I/O has been selected using
  116. O_NONBLOCK and no data was immediately available for reading.</para>
  117. </listitem>
  118. </varlistentry>
  119. <varlistentry>
  120. <term><errorcode>EBADF</errorcode></term>
  121. <listitem>
  122. <para><parameter>fd</parameter> is not a valid file
  123. descriptor or is not open for reading, or the process already has the
  124. maximum number of files open.</para>
  125. </listitem>
  126. </varlistentry>
  127. <varlistentry>
  128. <term><errorcode>EBUSY</errorcode></term>
  129. <listitem>
  130. <para>The driver does not support multiple read streams and the
  131. device is already in use.</para>
  132. </listitem>
  133. </varlistentry>
  134. <varlistentry>
  135. <term><errorcode>EFAULT</errorcode></term>
  136. <listitem>
  137. <para><parameter>buf</parameter> references an inaccessible
  138. memory area.</para>
  139. </listitem>
  140. </varlistentry>
  141. <varlistentry>
  142. <term><errorcode>EINTR</errorcode></term>
  143. <listitem>
  144. <para>The call was interrupted by a signal before any
  145. data was read.</para>
  146. </listitem>
  147. </varlistentry>
  148. <varlistentry>
  149. <term><errorcode>EIO</errorcode></term>
  150. <listitem>
  151. <para>I/O error. This indicates some hardware problem or a
  152. failure to communicate with a remote device (USB camera etc.).</para>
  153. </listitem>
  154. </varlistentry>
  155. <varlistentry>
  156. <term><errorcode>EINVAL</errorcode></term>
  157. <listitem>
  158. <para>The <function>read()</function> function is not
  159. supported by this driver, not on this device, or generally not on this
  160. type of device.</para>
  161. </listitem>
  162. </varlistentry>
  163. </variablelist>
  164. </refsect1>
  165. </refentry>