Sophie

Sophie

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

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/network.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/network.c</div>  </div>
</div><!--header-->
<div class="contents">
<p>Network identification example.</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> *  libzvbi network identification example</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *  Copyright (C) 2006 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: network.c,v 1.7 2009/03/23 01:30:22 mschimek Exp $ */</span></div><div class="line"></div><div class="line"><span class="comment">/* This example shows how to identify a network from data transmitted</span></div><div class="line"><span class="comment">   in XDS packets, Teletext packet 8/30 format 1 and 2, and VPS packets.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">   gcc -o network network.c `pkg-config zvbi-0.2 --cflags --libs` */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#undef NDEBUG</span></div><div class="line"><span class="preprocessor">#include &lt;assert.h&gt;</span></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;locale.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;errno.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="keyword">static</span> <a name="_a0"></a><a class="code" href="structvbi__capture.html">vbi_capture</a> *            cap;</div><div class="line"><span class="keyword">static</span> <a name="_a1"></a><a class="code" href="structvbi__decoder.html">vbi_decoder</a> *            dec;</div><div class="line"><span class="keyword">static</span> vbi_bool                 quit;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>             services;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">handler                         (<a name="_a2"></a><a class="code" href="structvbi__event.html">vbi_event</a> *            ev,</div><div class="line">                                 <span class="keywordtype">void</span> *                 user_data)</div><div class="line">{</div><div class="line">        <span class="keyword">const</span> <span class="keywordtype">char</span> *event_name;</div><div class="line">        <span class="keyword">const</span> <span class="keywordtype">char</span> *network_name;</div><div class="line">        <span class="keyword">const</span> <span class="keywordtype">char</span> *call_sign;</div><div class="line">        <span class="keywordtype">char</span> *locale_network_name;</div><div class="line"></div><div class="line">        user_data = user_data; <span class="comment">/* unused */</span></div><div class="line"></div><div class="line">        <span class="comment">/* VBI_EVENT_NETWORK_ID is always sent when the decoder</span></div><div class="line"><span class="comment">           receives a CNI. VBI_EVENT_NETWORK only if it can</span></div><div class="line"><span class="comment">           determine a network name. */</span></div><div class="line"></div><div class="line">        <span class="keywordflow">switch</span> (ev-&gt;<a name="a3"></a>type) {</div><div class="line">        <span class="keywordflow">case</span> VBI_EVENT_NETWORK:</div><div class="line">                event_name = <span class="stringliteral">&quot;VBI_EVENT_NETWORK&quot;</span>;</div><div class="line">                quit = TRUE;</div><div class="line">                <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">        <span class="keywordflow">case</span> VBI_EVENT_NETWORK_ID:</div><div class="line">                event_name = <span class="stringliteral">&quot;VBI_EVENT_NETWORK_ID&quot;</span>;</div><div class="line">                <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">        <span class="keywordflow">default</span>:</div><div class="line">                assert (0);</div><div class="line">        }</div><div class="line"></div><div class="line">        network_name = <span class="stringliteral">&quot;unknown&quot;</span>;</div><div class="line">        <span class="keywordflow">if</span> (0 != ev-&gt;<a name="a4"></a>ev.<a name="a5"></a>network.<a name="a6"></a><a class="code" href="structvbi__network.html#af9d608a153277b382fe51f7100d02724">name</a>[0])</div><div class="line">                network_name = (<span class="keyword">const</span> <span class="keywordtype">char</span> *) ev-&gt;ev.network.<a class="code" href="structvbi__network.html#af9d608a153277b382fe51f7100d02724">name</a>;</div><div class="line"></div><div class="line">        <span class="comment">/* The network name is an ISO-8859-1 string (the API is</span></div><div class="line"><span class="comment">           quite old...) so we convert it to locale encoding,</span></div><div class="line"><span class="comment">           nowadays usually UTF-8. */</span></div><div class="line">        locale_network_name = <a name="a7"></a><a class="code" href="group__Conv.html#gab360448d13ec1cd3c4a7a4babb07243f">vbi_strndup_iconv</a> (<a name="a8"></a><a class="code" href="group__Conv.html#ga69e68f14e65c01622db558df3e6a11f6">vbi_locale_codeset</a> (),</div><div class="line">                                                 <span class="stringliteral">&quot;ISO-8859-1&quot;</span>,</div><div class="line">                                                 network_name,</div><div class="line">                                                 strlen (network_name),</div><div class="line">                                                 <span class="comment">/* repl_char */</span> <span class="charliteral">&#39;?&#39;</span>);</div><div class="line"></div><div class="line">        <span class="comment">/* ASCII. */</span></div><div class="line">        call_sign = <span class="stringliteral">&quot;unknown&quot;</span>;</div><div class="line">        <span class="keywordflow">if</span> (0 != ev-&gt;ev.network.<a name="a9"></a><a class="code" href="structvbi__network.html#af0c2eebb0061a42a4c19835d4daca487">call</a>[0])</div><div class="line">                call_sign = (<span class="keyword">const</span> <span class="keywordtype">char</span> *) ev-&gt;ev.network.<a class="code" href="structvbi__network.html#af0c2eebb0061a42a4c19835d4daca487">call</a>;</div><div class="line"></div><div class="line">        printf (<span class="stringliteral">&quot;%s: receiving: \&quot;%s\&quot; call sign: \&quot;%s\&quot; &quot;</span></div><div class="line">                <span class="stringliteral">&quot;CNI VPS: 0x%x 8/30/1: 0x%x 8/30/2: 0x%x\n&quot;</span>,</div><div class="line">                event_name,</div><div class="line">                (NULL == locale_network_name) ?</div><div class="line">                <span class="stringliteral">&quot;iconv-error&quot;</span> : locale_network_name,</div><div class="line">                call_sign,</div><div class="line">                ev-&gt;ev.network.<a name="a10"></a><a class="code" href="structvbi__network.html#a072907768d911e73c4d96e5be9414954">cni_vps</a>,</div><div class="line">                ev-&gt;ev.network.<a name="a11"></a><a class="code" href="structvbi__network.html#ae994f3cec515287f42aaedb7eab6b93c">cni_8301</a>,</div><div class="line">                ev-&gt;ev.network.<a name="a12"></a><a class="code" href="structvbi__network.html#a1ce63ca7c685b7563da4115a71a2afed">cni_8302</a>);</div><div class="line"></div><div class="line">        free (locale_network_name);</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">        <span class="keyword">struct </span>timeval timeout;</div><div class="line">        <a name="_a13"></a><a class="code" href="structvbi__capture__buffer.html">vbi_capture_buffer</a> *sliced_buffer;</div><div class="line">        <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n_frames;</div><div class="line"></div><div class="line">        <span class="comment">/* Don&#39;t wait more than two seconds for the driver</span></div><div class="line"><span class="comment">           to return data. */</span></div><div class="line">        timeout.tv_sec = 2;</div><div class="line">        timeout.tv_usec = 0;</div><div class="line"></div><div class="line">        <span class="comment">/* Should receive a CNI within two seconds,</span></div><div class="line"><span class="comment">           call sign within ten seconds(?). */</span></div><div class="line">        <span class="keywordflow">if</span> (services &amp; VBI_SLICED_CAPTION_525)</div><div class="line">                n_frames = 11 * 30;</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">                n_frames = 3 * 25;</div><div class="line"></div><div class="line">        <span class="keywordflow">for</span> (; n_frames &gt; 0; --n_frames) {</div><div class="line">                <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n_lines;</div><div class="line">                <span class="keywordtype">int</span> r;</div><div class="line"></div><div class="line">                r = <a name="a14"></a><a class="code" href="group__Device.html#ga58dcf2387b685b7c1c09a729f07893c8">vbi_capture_pull</a> (cap,</div><div class="line">                                      <span class="comment">/* raw_buffer */</span> NULL,</div><div class="line">                                      &amp;sliced_buffer,</div><div class="line">                                      &amp;timeout);</div><div class="line">                <span class="keywordflow">switch</span> (r) {</div><div class="line">                <span class="keywordflow">case</span> -1:</div><div class="line">                        fprintf (stderr, <span class="stringliteral">&quot;VBI read error %d (%s)\n&quot;</span>,</div><div class="line">                                 errno, strerror (errno));</div><div class="line">                        <span class="comment">/* Could be ignored, esp. EIO with some drivers. */</span></div><div class="line">                        exit (EXIT_FAILURE);</div><div class="line"></div><div class="line">                <span class="keywordflow">case</span> 0: </div><div class="line">                        fprintf (stderr, <span class="stringliteral">&quot;VBI read timeout\n&quot;</span>);</div><div class="line">                        exit (EXIT_FAILURE);</div><div class="line"></div><div class="line">                <span class="keywordflow">case</span> 1: <span class="comment">/* success */</span></div><div class="line">                        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">                <span class="keywordflow">default</span>:</div><div class="line">                        assert (0);</div><div class="line">                }</div><div class="line"></div><div class="line">                n_lines = sliced_buffer-&gt;size / <span class="keyword">sizeof</span> (<a name="_a15"></a><a class="code" href="structvbi__sliced.html">vbi_sliced</a>);</div><div class="line"></div><div class="line">                <a name="a16"></a><a class="code" href="group__Service.html#ga2e2201e3b2bab9b7fb1bb66ade716772">vbi_decode</a> (dec,</div><div class="line">                            (<a class="code" href="structvbi__sliced.html">vbi_sliced</a> *) sliced_buffer-&gt;data,</div><div class="line">                            n_lines,</div><div class="line">                            sliced_buffer-&gt;timestamp);</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span> (quit)</div><div class="line">                        <span class="keywordflow">return</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        printf (<span class="stringliteral">&quot;No network ID received or network unknown.\n&quot;</span>);</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="keywordtype">char</span> *errstr;</div><div class="line">        vbi_bool success;</div><div class="line"></div><div class="line">        setlocale (LC_ALL, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line">        services = (VBI_SLICED_TELETEXT_B |</div><div class="line">                    VBI_SLICED_VPS |</div><div class="line">                    VBI_SLICED_CAPTION_525);</div><div class="line"></div><div class="line">        cap = <a name="a17"></a><a class="code" href="group__Device.html#ga85ba4554b337ecb053168bb88f713e5f">vbi_capture_v4l2_new</a> (<span class="stringliteral">&quot;/dev/vbi&quot;</span>,</div><div class="line">                                    <span class="comment">/* buffers */</span> 5,</div><div class="line">                                    &amp;services,</div><div class="line">                                    <span class="comment">/* strict */</span> 0,</div><div class="line">                                    &amp;errstr,</div><div class="line">                                    <span class="comment">/* verbose */</span> FALSE);</div><div class="line">        <span class="keywordflow">if</span> (NULL == cap) {</div><div class="line">                fprintf (stderr,</div><div class="line">                         <span class="stringliteral">&quot;Cannot capture VBI data with V4L2 interface:\n&quot;</span></div><div class="line">                         <span class="stringliteral">&quot;%s\n&quot;</span>,</div><div class="line">                         errstr);</div><div class="line"></div><div class="line">                free (errstr);</div><div class="line"></div><div class="line">                exit (EXIT_FAILURE);</div><div class="line">        }</div><div class="line"></div><div class="line">        dec = <a name="a18"></a><a class="code" href="group__Service.html#ga3c09b7fa196326f51409a91e2857ba5e">vbi_decoder_new</a> ();</div><div class="line">        assert (NULL != dec);</div><div class="line"></div><div class="line">        success = <a name="a19"></a><a class="code" href="group__Event.html#gacd13f9d8a2d47a4393541b7411fe426a">vbi_event_handler_add</a> (dec,</div><div class="line">                                         (VBI_EVENT_NETWORK |</div><div class="line">                                          VBI_EVENT_NETWORK_ID),</div><div class="line">                                         handler,</div><div class="line">                                         <span class="comment">/* user_data */</span> NULL);</div><div class="line">        assert (success);</div><div class="line"></div><div class="line">        mainloop ();</div><div class="line"></div><div class="line">        <a name="a20"></a><a class="code" href="group__Service.html#gab3f52f0b71746c9081c053a33cad7bce">vbi_decoder_delete</a> (dec);</div><div class="line"></div><div class="line">        <a name="a21"></a><a class="code" href="group__Device.html#gaec518b62f39b83c80b06cc0a4affbee6">vbi_capture_delete</a> (cap);</div><div class="line"></div><div class="line">        exit (EXIT_SUCCESS);</div><div class="line">}</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>