Sophie

Sophie

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

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/pdc1.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/pdc1.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> *  libzvbi VPS/PDC example 1</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *  Copyright (C) 2009 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: pdc1.c,v 1.2 2009/03/23 01:30:42 mschimek Exp $ */</span></div><div class="line"></div><div class="line"><span class="comment">/* This example shows how to receive Program IDs transmitted in VPS</span></div><div class="line"><span class="comment">   and Teletext packets using the libzvbi VBI decoder. Example pdc2.c</span></div><div class="line"><span class="comment">   demonstrates how video recorders respond to Program IDs.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">   If you prefer to decode the VPS and Teletext packets directly see</span></div><div class="line"><span class="comment">   test/decode.c for an example.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">   gcc -o pdc1 pdc1.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"></div><div class="line"><span class="comment">/* Attention! This function returns a static string. */</span></div><div class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *</div><div class="line">pil_str                         (<a class="code" href="group__ProgramID.html#ga870eeecedc6aed609b9f53d4dbe0f6c7">vbi_pil</a>                pil)</div><div class="line">{</div><div class="line">        <span class="keyword">static</span> <span class="keywordtype">char</span> buffer[32];</div><div class="line"></div><div class="line">        <span class="keywordflow">switch</span> (pil) {</div><div class="line">        <span class="keywordflow">case</span> <a name="a2"></a><a class="code" href="group__ProgramID.html#gga05589fbab0657f08285ebdfe93f5ec9eae7cbef095ebb79470785785bebdb2f8d">VBI_PIL_TIMER_CONTROL</a>:     <span class="keywordflow">return</span> <span class="stringliteral">&quot;TC&quot;</span>;</div><div class="line">        <span class="keywordflow">case</span> <a name="a3"></a><a class="code" href="group__ProgramID.html#gga05589fbab0657f08285ebdfe93f5ec9eaad30c6505f26ef2b6e26626afdff02dd">VBI_PIL_INHIBIT_TERMINATE</a>: <span class="keywordflow">return</span> <span class="stringliteral">&quot;RI/T&quot;</span>;</div><div class="line">        <span class="keywordflow">case</span> <a name="a4"></a><a class="code" href="group__ProgramID.html#gga05589fbab0657f08285ebdfe93f5ec9ea835908e1f719f7761589ac1f3b968cb4">VBI_PIL_INTERRUPTION</a>:      <span class="keywordflow">return</span> <span class="stringliteral">&quot;INT&quot;</span>;</div><div class="line">        <span class="keywordflow">case</span> <a name="a5"></a><a class="code" href="group__ProgramID.html#gga05589fbab0657f08285ebdfe93f5ec9ea4084b4cb78ad4667f7645101adebb3e1">VBI_PIL_CONTINUE</a>:          <span class="keywordflow">return</span> <span class="stringliteral">&quot;CONT&quot;</span>;</div><div class="line">        <span class="keywordflow">case</span> <a name="a6"></a><a class="code" href="group__ProgramID.html#gga05589fbab0657f08285ebdfe93f5ec9eac9b7c435e58a2f76a87f1acb221630f9">VBI_PIL_NSPV</a>:              <span class="keywordflow">return</span> <span class="stringliteral">&quot;NSPV/END&quot;</span>;</div><div class="line"></div><div class="line">        <span class="keywordflow">default</span>:</div><div class="line">                snprintf (buffer, <span class="keyword">sizeof</span> (buffer),</div><div class="line">                          <span class="stringliteral">&quot;%02u%02uT%02u%02u&quot;</span>,</div><div class="line">                          <a name="a7"></a><a class="code" href="group__ProgramID.html#gaae3974c3e680d42322edaad37b35ebcc">VBI_PIL_MONTH</a> (pil),</div><div class="line">                          <a name="a8"></a><a class="code" href="group__ProgramID.html#ga138a4f95542c36527f6df6ee08094f2f">VBI_PIL_DAY</a> (pil),</div><div class="line">                          <a name="a9"></a><a class="code" href="group__ProgramID.html#ga78d71b2b88dd3729e5364f6061000ebf">VBI_PIL_HOUR</a> (pil),</div><div class="line">                          <a name="a10"></a><a class="code" href="group__ProgramID.html#gaacada356d88add876dc7484892231e73">VBI_PIL_MINUTE</a> (pil));</div><div class="line">                <span class="keywordflow">return</span> buffer;</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"><a name="_a11"></a><a class="code" href="structevent__handler.html">event_handler</a>                   (<a name="_a12"></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> <a name="_a13"></a><a class="code" href="structvbi__program__id.html">vbi_program_id</a> *pid;</div><div class="line"></div><div class="line">        user_data = user_data; <span class="comment">/* unused, no warning please */</span></div><div class="line"></div><div class="line">        pid = ev-&gt;<a name="a14"></a>ev.<a name="a15"></a>prog_id;</div><div class="line"></div><div class="line">        printf (<span class="stringliteral">&quot;Received PIL %s/%02X on LC %u.\n&quot;</span>,</div><div class="line">                pil_str (pid-&gt;<a name="a16"></a><a class="code" href="structvbi__program__id.html#a30c0862c008de112f4222e1208038d58">pil</a>), pid-&gt;<a name="a17"></a><a class="code" href="structvbi__program__id.html#a069f84e950d47f19a589cbe4a3603068">pty</a>, pid-&gt;<a name="a18"></a><a class="code" href="structvbi__program__id.html#a90794327986da193ddb76d518331589d">channel</a>);</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"></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="keywordflow">for</span> (;;) {</div><div class="line">                <a name="_a19"></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_lines;</div><div class="line">                <span class="keywordtype">int</span> r;</div><div class="line"></div><div class="line">                r = <a name="a20"></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;<a name="a21"></a>size / <span class="keyword">sizeof</span> (<a name="_a22"></a><a class="code" href="structvbi__sliced.html">vbi_sliced</a>);</div><div class="line"></div><div class="line">                <a name="a23"></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;<a name="a24"></a>data,</div><div class="line">                            n_lines,</div><div class="line">                            sliced_buffer-&gt;<a name="a25"></a>timestamp);</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="keywordtype">char</span> *errstr;</div><div class="line">        vbi_bool success;</div><div class="line">        <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> services;</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"></div><div class="line">        cap = <a name="a26"></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="a27"></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="a28"></a><a class="code" href="group__Event.html#gacd13f9d8a2d47a4393541b7411fe426a">vbi_event_handler_add</a> (dec,</div><div class="line">                                         VBI_EVENT_PROG_ID,</div><div class="line">                                         <a class="code" href="structevent__handler.html">event_handler</a>,</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="a29"></a><a class="code" href="group__Service.html#gab3f52f0b71746c9081c053a33cad7bce">vbi_decoder_delete</a> (dec);</div><div class="line"></div><div class="line">        <a name="a30"></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>