group__force__feed.html 3.79 KB
Newer Older
zen's avatar
zen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>liboggz: Writing by force feeding OGGZ</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.4 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="globals.html">Globals</a></div>
<h1>Writing by force feeding OGGZ</h1><ul>
<li>* - * - This process is illustrated in the following diagram:</li></ul>
<p>
<div align="center">
<img src="forcefeed.png" alt="forcefeed.png">
</div>
<p>
The following example code generates a stream of ten packets, each containing a single byte ('A', 'B', ... , 'J'):<p>
<div class="fragment"><pre>
<span class="preprocessor">#include &lt;stdlib.h&gt;</span> <span class="comment">/* exit */</span>
<span class="preprocessor">#include &lt;<a class="code" href="oggz_8h.html">oggz/oggz.h</a>&gt;</span>

<span class="keyword">static</span> <span class="keywordtype">long</span> serialno;
<span class="keyword">static</span> ogg_int64_t granulepos = 0;
<span class="keyword">static</span> ogg_int64_t packetno = 0;

<span class="keywordtype">int</span>
main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> * argv[])
{
  <span class="keywordtype">char</span> * progname, * filename = NULL;
  <a class="code" href="oggz_8h.html#a0">OGGZ</a> * oggz;
  ogg_packet op;
  <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[1];
  <span class="keywordtype">long</span> n;

  progname = argv[0];
  <span class="keywordflow">if</span> (argc &gt; 1) filename = argv[1];

  <span class="keywordflow">if</span> (filename) {
    oggz = <a class="code" href="oggz_8h.html#a5">oggz_open</a> (filename, OGGZ_WRITE);
  } <span class="keywordflow">else</span> {
    oggz = <a class="code" href="oggz_8h.html#a6">oggz_open_stdio</a> (stdout, OGGZ_WRITE);
  }

  <span class="keywordflow">if</span> (oggz == NULL) {
    fprintf (stderr, <span class="stringliteral">"%s: Error creating oggz\n"</span>, progname);
    exit (1);
  }

  serialno = <a class="code" href="oggz_8h.html#a25">oggz_serialno_new</a> (oggz);

  <span class="keywordflow">for</span> (packetno = 0; packetno &lt; 10; packetno++) {

    <span class="comment">/* Create a packet */</span>

    buf[0] = <span class="charliteral">'A'</span> + (<span class="keywordtype">int</span>)packetno;

    op.packet = buf;
    op.bytes = 1;
    op.granulepos = granulepos;
    op.packetno = packetno;
    
    <span class="keywordflow">if</span> (packetno == 0) op.b_o_s = 1;
    <span class="keywordflow">else</span> op.b_o_s = 0;
    
    <span class="keywordflow">if</span> (packetno == 9) op.e_o_s = 1;
    <span class="keywordflow">else</span> op.e_o_s = 0;
    
    <span class="comment">/* Feed it to the Oggz packet queue */</span>

    <a class="code" href="group__write__api.html#a2">oggz_write_feed</a> (oggz, &amp;op, serialno, OGGZ_FLUSH_AFTER, NULL);
    
    granulepos += 100;
    packetno++;

    <span class="comment">/* Write bytes from packetized bitstream to the output file */</span>

    <span class="keywordflow">while</span> ((n = <a class="code" href="group__write__api.html#a4">oggz_write</a> (oggz, 32)) &gt; 0);
  }

  <a class="code" href="oggz_8h.html#a8">oggz_close</a> (oggz);

  exit (0);
}
</pre></div> 
<p>
<table border=0 cellpadding=0 cellspacing=0>
<tr><td></td></tr>
</table>
87
<hr size="1"><address style="align: right;"><small>Generated on Wed Jan 21 15:05:41 2004 for liboggz by
zen's avatar
zen committed
88
89
90
91
92
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 > 
</a>1.3.4 </small></address>
</body>
</html>