<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>ZVBI Library: examples/rawout.c</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.9 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div class="contents"> <h1>examples/rawout.c</h1>Raw VBI output example.<p> <div class="fragment"><pre class="fragment"><span class="comment">/*</span> <span class="comment"> * libzvbi raw VBI output example</span> <span class="comment"> *</span> <span class="comment"> * Copyright (C) 2006 Michael H. Schimek</span> <span class="comment"> *</span> <span class="comment"> * Redistribution and use in source and binary forms, with or without</span> <span class="comment"> * modification, are permitted provided that the following conditions</span> <span class="comment"> * are met:</span> <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span> <span class="comment"> * notice, this list of conditions and the following disclaimer.</span> <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span> <span class="comment"> * notice, this list of conditions and the following disclaimer in</span> <span class="comment"> * the documentation and/or other materials provided with the</span> <span class="comment"> * distribution.</span> <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span> <span class="comment"> * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span> <span class="comment"> * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span> <span class="comment"> * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span> <span class="comment"> * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span> <span class="comment"> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span> <span class="comment"> * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span> <span class="comment"> * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span> <span class="comment"> * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span> <span class="comment"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span> <span class="comment"> * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span> <span class="comment"> */</span> <span class="comment">/* $Id: rawout.c,v 1.8 2008/02/19 00:52:04 mschimek Exp $ */</span> <span class="comment">/* This example shows how to convert VBI data in a DVB PES stream</span> <span class="comment"> to raw VBI data.</span> <span class="comment"></span> <span class="comment"> gcc -o rawout rawout.c `pkg-config zvbi-0.2 --cflags --libs`</span> <span class="comment"></span> <span class="comment"> ./rawout <pes | mplayer - -rawvideo on:w=720:h=34:format=0x32595559 */</span> <span class="preprocessor">#undef NDEBUG</span> <span class="preprocessor"></span><span class="preprocessor">#include <assert.h></span> <span class="preprocessor">#include <stdio.h></span> <span class="preprocessor">#include <stdlib.h></span> <span class="preprocessor">#include <string.h></span> <span class="preprocessor">#include <unistd.h></span> <span class="preprocessor">#include <libzvbi.h></span> <span class="keyword">static</span> <a class="code" href="group__DVBDemux.html#g3d8ea8fb42aa99b702185ada0e3465d0" title="DVB VBI demultiplexer.">vbi_dvb_demux</a> * dvb; <span class="keyword">static</span> uint8_t pes_buffer[2048]; <span class="keyword">static</span> vbi_sampling_par sp; <span class="keyword">static</span> uint8_t * image; <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> image_size; <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pixel_mask; <span class="keyword">static</span> int64_t last_pts; <span class="keyword">static</span> <a name="_a0"></a><a class="code" href="structvbi__raw__decoder.html" title="Raw vbi decoder context.">vbi_raw_decoder</a> rd; <span class="keyword">static</span> <span class="keywordtype">void</span> raw_test (<span class="keyword">const</span> <a name="_a1"></a><a class="code" href="structvbi__sliced.html" title="This structure holds one scan line of sliced vbi data.">vbi_sliced</a> * expect_sliced, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> expect_n_lines) { <a class="code" href="structvbi__sliced.html" title="This structure holds one scan line of sliced vbi data.">vbi_sliced</a> sliced[50]; <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n_lines; <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i; n_lines = <a name="a2"></a><a class="code" href="group__Rawdec.html#g590834a98acc13c74c08b72de4fbfe80">vbi_raw_decode</a> (&rd, image, sliced); assert (n_lines == expect_n_lines); <span class="keywordflow">for</span> (i = 0; i < n_lines; ++i) { <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> payload; assert (sliced[i].<span class="keywordtype">id</span> == expect_sliced[i].<span class="keywordtype">id</span>); assert (sliced[i].line == expect_sliced[i].line); payload = (<a name="a3"></a><a class="code" href="group__Sliced.html#g366932921d0f6f58cb2e58c6ec130998">vbi_sliced_payload_bits</a> (sliced[i].<span class="keywordtype">id</span>) + 7) / 8; assert (0 == memcmp (sliced[i].data, expect_sliced[i].data, payload)); } } <span class="keyword">static</span> vbi_bool convert (<a class="code" href="group__DVBDemux.html#g3d8ea8fb42aa99b702185ada0e3465d0" title="DVB VBI demultiplexer.">vbi_dvb_demux</a> * dx, <span class="keywordtype">void</span> * user_data, <span class="keyword">const</span> <a class="code" href="structvbi__sliced.html" title="This structure holds one scan line of sliced vbi data.">vbi_sliced</a> * sliced, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n_lines, int64_t pts) { vbi_bool success; ssize_t actual; dx = dx; <span class="comment">/* unused */</span> user_data = user_data; pts &= ((int64_t) 1 << 33) - 1; <span class="comment">/* Handle PTS wrap-around. */</span> <span class="keywordflow">if</span> (0 == last_pts) { last_pts = pts; } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pts < last_pts) { last_pts -= (int64_t) 1 << 33; } <span class="keywordflow">while</span> (pts - last_pts > 90000 / 25 * 3 / 2) { <span class="comment">/* No data for this frame. */</span> success = <a name="a4"></a><a class="code" href="group__Rawenc.html#g885133bce06ae9f142bda5b9648e4d90">vbi_raw_video_image</a> (image, image_size, &sp, 0, 0, 0, pixel_mask, FALSE, NULL, <span class="comment">/* n_lines */</span> 0); assert (success); raw_test (NULL, 0); actual = write (STDOUT_FILENO, image, image_size); assert (actual == (ssize_t) image_size); last_pts += 90000 / 25; } success = <a class="code" href="group__Rawenc.html#g885133bce06ae9f142bda5b9648e4d90">vbi_raw_video_image</a> (image, image_size, &sp, <span class="comment">/* blank_level: default */</span> 0, <span class="comment">/* black_level: default */</span> 0, <span class="comment">/* white_level: default */</span> 0, pixel_mask, <span class="comment">/* swap_fields */</span> FALSE, sliced, n_lines); assert (success); raw_test (sliced, n_lines); actual = write (STDOUT_FILENO, image, image_size); assert (actual == (ssize_t) image_size); last_pts = pts; <span class="keywordflow">return</span> TRUE; <span class="comment">/* success */</span> } <span class="keyword">static</span> <span class="keywordtype">void</span> mainloop (<span class="keywordtype">void</span>) { <span class="keywordflow">while</span> (1 == fread (pes_buffer, <span class="keyword">sizeof</span> (pes_buffer), 1, stdin)) { vbi_bool success; success = <a name="a5"></a><a class="code" href="group__DVBDemux.html#g8f9c94782bb25d042180d98fd2b00f67" title="Feeds DVB VBI demux with data.">vbi_dvb_demux_feed</a> (dvb, pes_buffer, <span class="keyword">sizeof</span> (pes_buffer)); assert (success); } fprintf (stderr, <span class="stringliteral">"End of stream.\n"</span>); } <span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) { <span class="keywordflow">if</span> (isatty (STDIN_FILENO)) { fprintf (stderr, <span class="stringliteral">"No DVB PES on standard input.\n"</span>); exit (EXIT_FAILURE); } <span class="keywordflow">if</span> (isatty (STDOUT_FILENO)) { fprintf (stderr, <span class="stringliteral">"Output is binary image data. Pipe to "</span> <span class="stringliteral">"another tool or redirect to a file.\n"</span>); exit (EXIT_FAILURE); } <span class="comment">/* Helps debugging. */</span> <a name="a6"></a><a class="code" href="group__Basic.html#g594dbe49c85f00a11c3586a131203b61">vbi_set_log_fn</a> ((<a name="a7"></a><a class="code" href="group__Basic.html#gg14be5ab1155e94b01c79a4ed044e64ac6b8552ba1cf85168196a872f9fb11c3a">VBI_LOG_NOTICE</a> | <a name="a8"></a><a class="code" href="group__Basic.html#gg14be5ab1155e94b01c79a4ed044e64ac36d1d236c051fc0db20ccdec56a19596">VBI_LOG_WARNING</a> | <a name="a9"></a><a class="code" href="group__Basic.html#gg14be5ab1155e94b01c79a4ed044e64ac07b09f3b08a81ce12ac0a515978b56e2">VBI_LOG_ERROR</a>), <a name="a10"></a><a class="code" href="group__Basic.html#g892c64da1c60919512f0c4db6641a708">vbi_log_on_stderr</a>, <span class="comment">/* user_data */</span> NULL); dvb = <a name="a11"></a><a class="code" href="group__DVBDemux.html#g1e996d59787ce58b8682d27e8eca7edc" title="Allocates DVB VBI demux.">vbi_dvb_pes_demux_new</a> (convert, <span class="comment">/* user_data */</span> NULL); assert (NULL != dvb); memset (&sp, 0, <span class="keyword">sizeof</span> (sp)); <span class="preprocessor">#if 1</span> <span class="preprocessor"></span> <span class="comment">/* ITU BT.601 YUYV. */</span> sp.scanning = 625; <span class="comment">/* PAL/SECAM */</span> sp.sampling_format = VBI_PIXFMT_YUYV; sp.sampling_rate = 13.5e6; sp.bytes_per_line = 720 * 2; <span class="comment">/* 2 bpp */</span> sp.offset = 9.5e-6 * 13.5e6; sp.start[0] = 6; sp.count[0] = 17; sp.start[1] = 319; sp.count[1] = 17; sp.interlaced = TRUE; sp.synchronous = TRUE; <span class="comment">/* Other bytes are left unmodified. */</span> pixel_mask = 0x000000FF; <span class="comment">/* 0xAAVVUUYY */</span> <span class="preprocessor">#else</span> <span class="preprocessor"></span> <span class="comment">/* PAL square pixels BGRA32. */</span> sp.scanning = 625; <span class="comment">/* PAL/SECAM */</span> sp.sampling_format = VBI_PIXFMT_BGRA32_LE; sp.sampling_rate = 14.75e6; sp.bytes_per_line = 768 * 4; <span class="comment">/* 4 bpp */</span> sp.offset = 10.2e-6 * 14.75e6; sp.start[0] = 6; sp.count[0] = 17; sp.start[1] = 319; sp.count[1] = 17; sp.interlaced = TRUE; sp.synchronous = TRUE; pixel_mask = 0x0000FF00; <span class="comment">/* 0xAABBGGRR */</span> <span class="preprocessor">#endif</span> <span class="preprocessor"></span> image_size = (sp.count[0] + sp.count[1]) * sp.bytes_per_line; image = malloc (image_size); assert (NULL != image); <span class="keywordflow">if</span> (VBI_PIXFMT_YUYV == sp.sampling_format) { <span class="comment">/* Reset Cb/Cr bytes. */</span> memset (image, 0x80, image_size); } <span class="keywordflow">else</span> { memset (image, 0x00, image_size); } <span class="comment">/* To verify the generated raw VBI data we feed it back</span> <span class="comment"> into a decoder and compare the sliced VBI data. */</span> <a name="a12"></a><a class="code" href="group__Rawdec.html#g5bbc43c12196c9be0065ecc566906adb">vbi_raw_decoder_init</a> (&rd); rd.<a name="a13"></a><a class="code" href="structvbi__raw__decoder.html#7ff6b942e66eae2ca7a3b6bbfbbc550f">scanning</a> = sp.scanning; rd.<a name="a14"></a><a class="code" href="structvbi__raw__decoder.html#042431c6c0abab3eeecce4f9a014bd1d">sampling_format</a> = sp.sampling_format; rd.<a name="a15"></a><a class="code" href="structvbi__raw__decoder.html#72596d7bf3dd5f3fedf8ce51f25f6377">sampling_rate</a> = sp.sampling_rate; rd.<a name="a16"></a><a class="code" href="structvbi__raw__decoder.html#0610feb3dba297670cadb678d8370e80">bytes_per_line</a> = sp.bytes_per_line; rd.<a name="a17"></a><a class="code" href="structvbi__raw__decoder.html#ec686bff8271a5304417cdb2e84dd198">offset</a> = sp.offset; rd.<a name="a18"></a><a class="code" href="structvbi__raw__decoder.html#b8a8df50593ebc6ab7d9f52f0cc8275d">start</a>[0] = sp.start[0]; rd.<a class="code" href="structvbi__raw__decoder.html#b8a8df50593ebc6ab7d9f52f0cc8275d">start</a>[1] = sp.start[1]; rd.<a name="a19"></a><a class="code" href="structvbi__raw__decoder.html#b77ddf5224b63d84d66c36daded1ab90">count</a>[0] = sp.count[0]; rd.<a class="code" href="structvbi__raw__decoder.html#b77ddf5224b63d84d66c36daded1ab90">count</a>[1] = sp.count[1]; rd.<a name="a20"></a><a class="code" href="structvbi__raw__decoder.html#b21be06e2fb0141314311d820c51b35f">interlaced</a> = sp.interlaced; rd.<a name="a21"></a><a class="code" href="structvbi__raw__decoder.html#dbeef46d32445684cdf52c4cfbe8f3ac">synchronous</a> = sp.synchronous; <span class="comment">/* Strict 0 because the function would consider the</span> <span class="comment"> square pixel timing too tight to reliably decode</span> <span class="comment"> Teletext. */</span> <a name="a22"></a><a class="code" href="group__Rawdec.html#g18c46d4a4885261c45e32e8eb509d1b9">vbi_raw_decoder_add_services</a> (&rd, (VBI_SLICED_TELETEXT_B | VBI_SLICED_VPS | VBI_SLICED_CAPTION_625), <span class="comment">/* strict */</span> 0); mainloop (); <a name="a23"></a><a class="code" href="group__DVBDemux.html#g501c9d925a5d5946417f5c251c4ec8b8" title="Deletes DVB VBI demux.">vbi_dvb_demux_delete</a> (dvb); exit (EXIT_SUCCESS); <span class="keywordflow">return</span> 0; } </pre></div> </div> <hr size="1"><address style="text-align: right;"><small>Generated on Wed May 27 04:47:58 2009 for ZVBI Library by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address> </body> </html>