Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-release > by-pkgid > 2a781e5f78e233aedaa1e51ed196dcc3 > files > 30

lib64zvbi-devel-0.2.35-5.mga6.x86_64.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>ZVBI Library: examples/wss.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">ZVBI Library
   &#160;<span id="projectnumber">0.2.35</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">examples/wss.c</div>  </div>
</div><!--header-->
<div class="contents">
<p>WSS capture example.</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> *  libzvbi WSS capture example</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *  Copyright (C) 2005 Michael H. Schimek</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *  Redistribution and use in source and binary forms, with or without</span></div><div class="line"><span class="comment"> *  modification, are permitted provided that the following conditions</span></div><div class="line"><span class="comment"> *  are met:</span></div><div class="line"><span class="comment"> *  1. Redistributions of source code must retain the above copyright</span></div><div class="line"><span class="comment"> *     notice, this list of conditions and the following disclaimer.</span></div><div class="line"><span class="comment"> *  2. Redistributions in binary form must reproduce the above copyright</span></div><div class="line"><span class="comment"> *     notice, this list of conditions and the following disclaimer in</span></div><div class="line"><span class="comment"> *     the documentation and/or other materials provided with the</span></div><div class="line"><span class="comment"> *     distribution.</span></div><div class="line"><span class="comment"> *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span></div><div class="line"><span class="comment"> *  &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span></div><div class="line"><span class="comment"> *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span></div><div class="line"><span class="comment"> *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span></div><div class="line"><span class="comment"> *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span></div><div class="line"><span class="comment"> *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span></div><div class="line"><span class="comment"> *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span></div><div class="line"><span class="comment"> *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span></div><div class="line"><span class="comment"> *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span></div><div class="line"><span class="comment"> *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span></div><div class="line"><span class="comment"> *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="comment">/* $Id: wss.c,v 1.11 2008/02/19 00:52:04 mschimek Exp $ */</span></div><div class="line"></div><div class="line"><span class="comment">/* This example shows how to extract Wide Screen Signalling data</span></div><div class="line"><span class="comment">   (EN 300 294) from video images. The signal is transmitted on the</span></div><div class="line"><span class="comment">   first half of PAL/SECAM scan line 23, which ITU-R BT.601 defines</span></div><div class="line"><span class="comment">   as the first line of a 576 line picture.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">   The author is not aware of any drivers which can capture a scan</span></div><div class="line"><span class="comment">   line as raw VBI and video data at the same time, and sliced VBI</span></div><div class="line"><span class="comment">   capturing is not supported yet by libzvbi. Note some drivers like</span></div><div class="line"><span class="comment">   the Linux saa7134 driver cannot capture line 23 at all.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">   gcc -o wss wss.c `pkg-config zvbi-0.2 --cflags --libs` */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef HAVE_CONFIG_H</span></div><div class="line"><span class="preprocessor">#  include &quot;config.h&quot;</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;assert.h&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef ENABLE_V4L2</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;fcntl.h&gt;</span>              <span class="comment">/* low-level i/o */</span></div><div class="line"><span class="preprocessor">#include &lt;unistd.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;errno.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;sys/stat.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;sys/types.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;sys/time.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;sys/mman.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;sys/ioctl.h&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;libzvbi.h&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;asm/types.h&gt;</span>          <span class="comment">/* for videodev2.h */</span></div><div class="line"><span class="preprocessor">#include &quot;videodev2k.h&quot;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define CLEAR(x) memset (&amp;(x), 0, sizeof (x))</span></div><div class="line"></div><div class="line"><span class="keyword">struct </span>buffer {</div><div class="line">        <span class="keywordtype">void</span> *                  start;</div><div class="line">        <span class="keywordtype">size_t</span>                  length;</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *     dev_name = <span class="stringliteral">&quot;/dev/video&quot;</span>;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span>              fd;</div><div class="line"><span class="keyword">static</span> <span class="keyword">struct </span>buffer *  buffers;</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>     n_buffers;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span>              quit;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <a name="_a0"></a><a class="code" href="structvbi__raw__decoder.html">vbi_raw_decoder</a>  rd;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">errno_exit                      (<span class="keyword">const</span> <span class="keywordtype">char</span> *           s)</div><div class="line">{</div><div class="line">        fprintf (stderr, <span class="stringliteral">&quot;%s error %d, %s\n&quot;</span>,</div><div class="line">                 s, errno, strerror (errno));</div><div class="line"></div><div class="line">        exit (EXIT_FAILURE);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">xioctl                          (<span class="keywordtype">int</span>                    fd,</div><div class="line">                                 <span class="keywordtype">int</span>                    request,</div><div class="line">                                 <span class="keywordtype">void</span> *                 p)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> r;</div><div class="line"></div><div class="line">        <span class="keywordflow">do</span> r = ioctl (fd, request, p);</div><div class="line">        <span class="keywordflow">while</span> (-1 == r &amp;&amp; EINTR == errno);</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> r;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">decode_wss_625                  (uint8_t *              buf)</div><div class="line">{</div><div class="line">        <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *formats [] = {</div><div class="line">                <span class="stringliteral">&quot;Full format 4:3, 576 lines&quot;</span>,</div><div class="line">                <span class="stringliteral">&quot;Letterbox 14:9 centre, 504 lines&quot;</span>,</div><div class="line">                <span class="stringliteral">&quot;Letterbox 14:9 top, 504 lines&quot;</span>,</div><div class="line">                <span class="stringliteral">&quot;Letterbox 16:9 centre, 430 lines&quot;</span>,</div><div class="line">                <span class="stringliteral">&quot;Letterbox 16:9 top, 430 lines&quot;</span>,</div><div class="line">                <span class="stringliteral">&quot;Letterbox &gt; 16:9 centre&quot;</span>,</div><div class="line">                <span class="stringliteral">&quot;Full format 14:9 centre, 576 lines&quot;</span>,</div><div class="line">                <span class="stringliteral">&quot;Anamorphic 16:9, 576 lines&quot;</span></div><div class="line">        };</div><div class="line">        <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *subtitles [] = {</div><div class="line">                <span class="stringliteral">&quot;none&quot;</span>,</div><div class="line">                <span class="stringliteral">&quot;in active image area&quot;</span>,</div><div class="line">                <span class="stringliteral">&quot;out of active image area&quot;</span>,</div><div class="line">                <span class="stringliteral">&quot;&lt;invalid&gt;&quot;</span></div><div class="line">        };</div><div class="line">        <span class="keywordtype">int</span> g1;</div><div class="line">        <span class="keywordtype">int</span> parity;</div><div class="line"></div><div class="line">        g1 = buf[0] &amp; 15;</div><div class="line"></div><div class="line">        parity = g1;</div><div class="line">        parity ^= parity &gt;&gt; 2;</div><div class="line">        parity ^= parity &gt;&gt; 1;</div><div class="line">        g1 &amp;= 7;</div><div class="line"></div><div class="line">        printf (<span class="stringliteral">&quot;WSS PAL: &quot;</span>);</div><div class="line">        <span class="keywordflow">if</span> (!(parity &amp; 1))</div><div class="line">                printf (<span class="stringliteral">&quot;&lt;parity error&gt; &quot;</span>);</div><div class="line">        printf (<span class="stringliteral">&quot;%s; %s mode; %s colour coding; %s helper; &quot;</span></div><div class="line">                <span class="stringliteral">&quot;reserved b7=%d; %s Teletext subtitles; &quot;</span></div><div class="line">                <span class="stringliteral">&quot;open subtitles: %s; %s surround sound; &quot;</span></div><div class="line">                <span class="stringliteral">&quot;copyright %s; copying %s\n&quot;</span>,</div><div class="line">                formats[g1],</div><div class="line">                (buf[0] &amp; 0x10) ? <span class="stringliteral">&quot;film&quot;</span> : <span class="stringliteral">&quot;camera&quot;</span>,</div><div class="line">                (buf[0] &amp; 0x20) ? <span class="stringliteral">&quot;MA/CP&quot;</span> : <span class="stringliteral">&quot;standard&quot;</span>,</div><div class="line">                (buf[0] &amp; 0x40) ? <span class="stringliteral">&quot;modulated&quot;</span> : <span class="stringliteral">&quot;no&quot;</span>,</div><div class="line">                !!(buf[0] &amp; 0x80),</div><div class="line">                (buf[1] &amp; 0x01) ? <span class="stringliteral">&quot;have&quot;</span> : <span class="stringliteral">&quot;no&quot;</span>,</div><div class="line">                subtitles[(buf[1] &gt;&gt; 1) &amp; 3],</div><div class="line">                (buf[1] &amp; 0x08) ? <span class="stringliteral">&quot;have&quot;</span> : <span class="stringliteral">&quot;no&quot;</span>,</div><div class="line">                (buf[1] &amp; 0x10) ? <span class="stringliteral">&quot;asserted&quot;</span> : <span class="stringliteral">&quot;unknown&quot;</span>,</div><div class="line">                (buf[1] &amp; 0x20) ? <span class="stringliteral">&quot;restricted&quot;</span> : <span class="stringliteral">&quot;not restricted&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">process_image                   (<span class="keyword">const</span> <span class="keywordtype">void</span> *           p)</div><div class="line">{</div><div class="line">        <a name="_a1"></a><a class="code" href="structvbi__sliced.html">vbi_sliced</a> sliced[1];</div><div class="line">        <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n_lines;</div><div class="line"></div><div class="line">        n_lines = <a name="a2"></a><a class="code" href="group__Rawdec.html#ga590834a98acc13c74c08b72de4fbfe80">vbi_raw_decode</a> (&amp;rd, (uint8_t *) p, sliced);</div><div class="line">        <span class="keywordflow">if</span> (0 <span class="comment">/* test */</span>) {</div><div class="line">                <span class="comment">/* Error ignored. */</span></div><div class="line">                write (STDOUT_FILENO, p, rd.<a name="a3"></a><a class="code" href="structvbi__raw__decoder.html#a0610feb3dba297670cadb678d8370e80">bytes_per_line</a>);</div><div class="line">        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (n_lines &gt; 0) {</div><div class="line">                assert (VBI_SLICED_WSS_625 == sliced[0].<span class="keywordtype">id</span>);</div><div class="line">                assert (1 == n_lines);</div><div class="line">                decode_wss_625 (sliced[0].data);</div><div class="line">        } <span class="keywordflow">else</span> {</div><div class="line">                fputc (<span class="charliteral">&#39;.&#39;</span>, stdout);</div><div class="line">                fflush (stdout);</div><div class="line">        }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">init_decoder                    (<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">        <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> services;</div><div class="line"></div><div class="line">        <a name="a4"></a><a class="code" href="group__Rawdec.html#ga5bbc43c12196c9be0065ecc566906adb">vbi_raw_decoder_init</a> (&amp;rd);</div><div class="line"></div><div class="line">        rd.<a name="a5"></a><a class="code" href="structvbi__raw__decoder.html#a7ff6b942e66eae2ca7a3b6bbfbbc550f">scanning</a> = 625;</div><div class="line">        rd.<a name="a6"></a><a class="code" href="structvbi__raw__decoder.html#a042431c6c0abab3eeecce4f9a014bd1d">sampling_format</a> = VBI_PIXFMT_YUYV;</div><div class="line"></div><div class="line">        <span class="comment">/* Should be calculated from VIDIOC_CROPCAP information.</span></div><div class="line"><span class="comment">           Common sampling rates are 14.75 MHz to get 768 PAL/SECAM</span></div><div class="line"><span class="comment">           square pixels per line, and 13.5 MHz according to ITU-R Rec.</span></div><div class="line"><span class="comment">           BT.601 with 720 pixels/line. Note BT.601 overscans the line:</span></div><div class="line"><span class="comment">           13.5e6 / 720 &gt; 14.75e6 / 768. Don&#39;t be fooled by a driver</span></div><div class="line"><span class="comment">           scaling 768 square pixels to 720. */</span></div><div class="line">        rd.<a name="a7"></a><a class="code" href="structvbi__raw__decoder.html#a72596d7bf3dd5f3fedf8ce51f25f6377">sampling_rate</a> = 768 * 14.75e6 / 768;</div><div class="line"></div><div class="line">        rd.<a class="code" href="structvbi__raw__decoder.html#a0610feb3dba297670cadb678d8370e80">bytes_per_line</a> = 768 * 2;</div><div class="line"></div><div class="line">        <span class="comment">/* Should be calculated from VIDIOC_CROPCAP information. */</span></div><div class="line">        rd.<a name="a8"></a><a class="code" href="structvbi__raw__decoder.html#aec686bff8271a5304417cdb2e84dd198">offset</a> = 0;</div><div class="line"></div><div class="line">        rd.<a name="a9"></a><a class="code" href="structvbi__raw__decoder.html#ab8a8df50593ebc6ab7d9f52f0cc8275d">start</a>[0] = 23;</div><div class="line">        rd.<a name="a10"></a><a class="code" href="structvbi__raw__decoder.html#ab77ddf5224b63d84d66c36daded1ab90">count</a>[0] = 1;</div><div class="line"></div><div class="line">        rd.<a class="code" href="structvbi__raw__decoder.html#ab8a8df50593ebc6ab7d9f52f0cc8275d">start</a>[1] = 0;</div><div class="line">        rd.<a class="code" href="structvbi__raw__decoder.html#ab77ddf5224b63d84d66c36daded1ab90">count</a>[1] = 0;</div><div class="line"></div><div class="line">        rd.<a name="a11"></a><a class="code" href="structvbi__raw__decoder.html#ab21be06e2fb0141314311d820c51b35f">interlaced</a> = FALSE; <span class="comment">/* just one line */</span></div><div class="line">        rd.<a name="a12"></a><a class="code" href="structvbi__raw__decoder.html#adbeef46d32445684cdf52c4cfbe8f3ac">synchronous</a> = TRUE;</div><div class="line"></div><div class="line">        services = <a name="a13"></a><a class="code" href="group__Rawdec.html#ga18c46d4a4885261c45e32e8eb509d1b9">vbi_raw_decoder_add_services</a> (&amp;rd,</div><div class="line">                                                 VBI_SLICED_WSS_625,</div><div class="line">                                                 <span class="comment">/* strict */</span> 2);</div><div class="line">        <span class="keywordflow">if</span> (0 == services) {</div><div class="line">                fprintf (stderr, <span class="stringliteral">&quot;Cannot decode WSS\n&quot;</span>);</div><div class="line">                exit (EXIT_FAILURE);</div><div class="line">        }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">mainloop                        (<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">        quit = 0;</div><div class="line"></div><div class="line">        <span class="keywordflow">while</span> (!quit) {</div><div class="line">                <span class="keyword">struct </span>v4l2_buffer buf;</div><div class="line"></div><div class="line">                <span class="keywordflow">for</span> (;;) {</div><div class="line">                        fd_set fds;</div><div class="line">                        <span class="keyword">struct </span>timeval tv;</div><div class="line">                        <span class="keywordtype">int</span> r;</div><div class="line"></div><div class="line">                        FD_ZERO (&amp;fds);</div><div class="line">                        FD_SET (fd, &amp;fds);</div><div class="line"></div><div class="line">                        tv.tv_sec = 2;</div><div class="line">                        tv.tv_usec = 0;</div><div class="line"></div><div class="line">                        r = select (fd + 1, &amp;fds, NULL, NULL, &amp;tv);</div><div class="line"></div><div class="line">                        <span class="keywordflow">if</span> (-1 == r) {</div><div class="line">                                <span class="keywordflow">if</span> (EINTR == errno) {</div><div class="line">                                        <span class="comment">/* XXX should subtract the elapsed</span></div><div class="line"><span class="comment">                                           time from timeout here. */</span></div><div class="line">                                        <span class="keywordflow">continue</span>;</div><div class="line">                                }</div><div class="line"></div><div class="line">                                errno_exit (<span class="stringliteral">&quot;select&quot;</span>);</div><div class="line">                        }</div><div class="line"></div><div class="line">                        <span class="keywordflow">if</span> (0 == r) {</div><div class="line">                                fprintf (stderr, <span class="stringliteral">&quot;select timeout\n&quot;</span>);</div><div class="line">                                exit (EXIT_FAILURE);</div><div class="line">                        }</div><div class="line"></div><div class="line">                        <span class="keywordflow">break</span>;</div><div class="line">                }</div><div class="line"></div><div class="line">                CLEAR (buf);</div><div class="line"></div><div class="line">                buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;</div><div class="line">                buf.memory      = V4L2_MEMORY_MMAP;</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span> (-1 == xioctl (fd, VIDIOC_DQBUF, &amp;buf)) {</div><div class="line">                        <span class="keywordflow">if</span> (EAGAIN == errno)</div><div class="line">                                <span class="keywordflow">continue</span>;</div><div class="line"></div><div class="line">                        errno_exit (<span class="stringliteral">&quot;VIDIOC_DQBUF&quot;</span>);</div><div class="line">                }</div><div class="line"></div><div class="line">                assert (buf.index &lt; n_buffers);</div><div class="line"></div><div class="line">                process_image (buffers[buf.index].start);</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span> (-1 == xioctl (fd, VIDIOC_QBUF, &amp;buf))</div><div class="line">                        errno_exit (<span class="stringliteral">&quot;VIDIOC_QBUF&quot;</span>);</div><div class="line">        }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">start_capturing                 (<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">        <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;</div><div class="line">        <span class="keyword">enum</span> v4l2_buf_type type;</div><div class="line"></div><div class="line">        <span class="keywordflow">for</span> (i = 0; i &lt; n_buffers; ++i) {</div><div class="line">                <span class="keyword">struct </span>v4l2_buffer buf;</div><div class="line"></div><div class="line">                CLEAR (buf);</div><div class="line"></div><div class="line">                buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;</div><div class="line">                buf.memory      = V4L2_MEMORY_MMAP;</div><div class="line">                buf.index       = i;</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span> (-1 == xioctl (fd, VIDIOC_QBUF, &amp;buf))</div><div class="line">                        errno_exit (<span class="stringliteral">&quot;VIDIOC_QBUF&quot;</span>);</div><div class="line">        }</div><div class="line"></div><div class="line">        type = V4L2_BUF_TYPE_VIDEO_CAPTURE;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (-1 == xioctl (fd, VIDIOC_STREAMON, &amp;type))</div><div class="line">                errno_exit (<span class="stringliteral">&quot;VIDIOC_STREAMON&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">init_device                     (<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">        <span class="keyword">struct </span>v4l2_capability cap;</div><div class="line">        v4l2_std_id std_id;</div><div class="line">        <span class="keyword">struct </span>v4l2_format fmt;</div><div class="line">        <span class="keyword">struct </span>v4l2_requestbuffers req;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (-1 == xioctl (fd, VIDIOC_QUERYCAP, &amp;cap)) {</div><div class="line">                <span class="keywordflow">if</span> (EINVAL == errno) {</div><div class="line">                        fprintf (stderr, <span class="stringliteral">&quot;%s is no V4L2 device\n&quot;</span>,</div><div class="line">                                 dev_name);</div><div class="line">                        exit (EXIT_FAILURE);</div><div class="line">                } <span class="keywordflow">else</span> {</div><div class="line">                        errno_exit (<span class="stringliteral">&quot;VIDIOC_QUERYCAP&quot;</span>);</div><div class="line">                }</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (!(cap.capabilities &amp; V4L2_CAP_VIDEO_CAPTURE)) {</div><div class="line">                fprintf (stderr, <span class="stringliteral">&quot;%s is no video capture device\n&quot;</span>,</div><div class="line">                         dev_name);</div><div class="line">                exit (EXIT_FAILURE);</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (!(cap.capabilities &amp; V4L2_CAP_STREAMING)) {</div><div class="line">                fprintf (stderr, <span class="stringliteral">&quot;%s does not support streaming I/O\n&quot;</span>,</div><div class="line">                         dev_name);</div><div class="line">                exit (EXIT_FAILURE);</div><div class="line">        }</div><div class="line"></div><div class="line">        std_id = V4L2_STD_PAL;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (-1 == xioctl (fd, VIDIOC_S_STD, &amp;std_id))</div><div class="line">                errno_exit (<span class="stringliteral">&quot;VIDIOC_S_STD&quot;</span>);</div><div class="line"></div><div class="line">        CLEAR (fmt);</div><div class="line"></div><div class="line">        <span class="comment">/* We need the top field without vertical scaling,</span></div><div class="line"><span class="comment">           width must be at least 320 pixels. */</span></div><div class="line"></div><div class="line">        fmt.type                = V4L2_BUF_TYPE_VIDEO_CAPTURE;</div><div class="line">        fmt.fmt.pix.width       = 768; </div><div class="line">        fmt.fmt.pix.height      = 576;</div><div class="line">        fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;</div><div class="line">        fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (-1 == xioctl (fd, VIDIOC_S_FMT, &amp;fmt))</div><div class="line">                errno_exit (<span class="stringliteral">&quot;VIDIOC_S_FMT&quot;</span>);</div><div class="line"></div><div class="line">        <span class="comment">/* XXX the driver may adjust width and height, some</span></div><div class="line"><span class="comment">           even change the pixelformat, that should be checked here. */</span></div><div class="line"></div><div class="line">        CLEAR (req);</div><div class="line"></div><div class="line">        req.count               = 4;</div><div class="line">        req.type                = V4L2_BUF_TYPE_VIDEO_CAPTURE;</div><div class="line">        req.memory              = V4L2_MEMORY_MMAP;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (-1 == xioctl (fd, VIDIOC_REQBUFS, &amp;req)) {</div><div class="line">                <span class="keywordflow">if</span> (EINVAL == errno) {</div><div class="line">                        fprintf (stderr, <span class="stringliteral">&quot;%s does not support &quot;</span></div><div class="line">                                 <span class="stringliteral">&quot;memory mapping\n&quot;</span>, dev_name);</div><div class="line">                        exit (EXIT_FAILURE);</div><div class="line">                } <span class="keywordflow">else</span> {</div><div class="line">                        errno_exit (<span class="stringliteral">&quot;VIDIOC_REQBUFS&quot;</span>);</div><div class="line">                }</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (req.count &lt; 2) {</div><div class="line">                fprintf (stderr, <span class="stringliteral">&quot;Insufficient buffer memory on %s\n&quot;</span>,</div><div class="line">                         dev_name);</div><div class="line">                exit (EXIT_FAILURE);</div><div class="line">        }</div><div class="line"></div><div class="line">        buffers = calloc (req.count, sizeof (*buffers));</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (!buffers) {</div><div class="line">                fprintf (stderr, <span class="stringliteral">&quot;Out of memory\n&quot;</span>);</div><div class="line">                exit (EXIT_FAILURE);</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordflow">for</span> (n_buffers = 0; n_buffers &lt; req.count; ++n_buffers) {</div><div class="line">                <span class="keyword">struct </span>v4l2_buffer buf;</div><div class="line"></div><div class="line">                CLEAR (buf);</div><div class="line"></div><div class="line">                buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;</div><div class="line">                buf.memory      = V4L2_MEMORY_MMAP;</div><div class="line">                buf.index       = n_buffers;</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span> (-1 == xioctl (fd, VIDIOC_QUERYBUF, &amp;buf))</div><div class="line">                        errno_exit (<span class="stringliteral">&quot;VIDIOC_QUERYBUF&quot;</span>);</div><div class="line"></div><div class="line">                buffers[n_buffers].length = buf.length;</div><div class="line">                buffers[n_buffers].start =</div><div class="line">                        mmap (NULL <span class="comment">/* start anywhere */</span>,</div><div class="line">                              buf.length,</div><div class="line">                              PROT_READ | PROT_WRITE <span class="comment">/* required */</span>,</div><div class="line">                              MAP_SHARED <span class="comment">/* recommended */</span>,</div><div class="line">                              fd, buf.m.offset);</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span> (MAP_FAILED == buffers[n_buffers].start)</div><div class="line">                        errno_exit (<span class="stringliteral">&quot;mmap&quot;</span>);</div><div class="line">        }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">open_device                     (<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">        <span class="keyword">struct </span>stat st; </div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (-1 == stat (dev_name, &amp;st)) {</div><div class="line">                fprintf (stderr, <span class="stringliteral">&quot;Cannot identify &#39;%s&#39;: %d, %s\n&quot;</span>,</div><div class="line">                         dev_name, errno, strerror (errno));</div><div class="line">                exit (EXIT_FAILURE);</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (!S_ISCHR (st.st_mode)) {</div><div class="line">                fprintf (stderr, <span class="stringliteral">&quot;%s is no device\n&quot;</span>, dev_name);</div><div class="line">                exit (EXIT_FAILURE);</div><div class="line">        }</div><div class="line"></div><div class="line">        fd = open (dev_name, O_RDWR | O_NONBLOCK, 0);</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (-1 == fd) {</div><div class="line">                fprintf (stderr, <span class="stringliteral">&quot;Cannot open &#39;%s&#39;: %d, %s\n&quot;</span>,</div><div class="line">                         dev_name, errno, strerror (errno));</div><div class="line">                exit (EXIT_FAILURE);</div><div class="line">        }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span></div><div class="line">main                            (<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">        <span class="comment">/* Helps debugging. */</span></div><div class="line">        <a name="a14"></a><a class="code" href="group__Basic.html#ga594dbe49c85f00a11c3586a131203b61">vbi_set_log_fn</a> (<span class="comment">/* mask: log everything */</span> -1,</div><div class="line">                        <a name="a15"></a><a class="code" href="group__Basic.html#ga892c64da1c60919512f0c4db6641a708">vbi_log_on_stderr</a>,</div><div class="line">                        <span class="comment">/* user_data */</span> NULL);</div><div class="line"></div><div class="line">        open_device ();</div><div class="line"></div><div class="line">        init_device ();</div><div class="line"></div><div class="line">        init_decoder ();</div><div class="line"></div><div class="line">        start_capturing ();</div><div class="line"></div><div class="line">        mainloop ();</div><div class="line"></div><div class="line">        exit (EXIT_SUCCESS);</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="preprocessor">#else </span><span class="comment">/* !ENABLE_V4L2 */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span></div><div class="line">main                            (<span class="keywordtype">int</span>                    argc,</div><div class="line">                                 <span class="keywordtype">char</span> **                argv)</div><div class="line">{</div><div class="line">        fprintf (stderr, <span class="stringliteral">&quot;Sorry, V4L2 only. Patches welcome.\n&quot;</span>);</div><div class="line"></div><div class="line">        exit (EXIT_FAILURE);</div><div class="line">        </div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="preprocessor">#endif </span><span class="comment">/* !ENABLE_V4L2 */</span><span class="preprocessor"></span></div></div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>