<!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"/> <title>libkate: decoding.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.6.1 --> <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="files.html"><span>Files</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div class="contents"> <h1>decoding.c</h1><div class="fragment"><pre class="fragment"><span class="comment">/*</span> <span class="comment"> This shows the steps necessary to encode a Kate stream.</span> <span class="comment"> For clarity, error checking is omitted.</span> <span class="comment"> For simplicity, the input is assumed to be a single Kate stream.</span> <span class="comment"> Usually, Kate streams will be multiplexed with other streams (either</span> <span class="comment"> other Kate streams, or audio, or video). In these cases, the Ogg</span> <span class="comment"> part will have to be more complex, but the Kate specific code will</span> <span class="comment"> be the same.</span> <span class="comment"> */</span> <span class="preprocessor">#include <stdio.h></span> <span class="preprocessor">#include <string.h></span> <span class="preprocessor">#include "common.h"</span> <span class="comment">/* All the libkate API is available from the main kate header file: */</span> <span class="preprocessor">#include <<a class="code" href="oggkate_8h.html">kate/oggkate.h</a>></span> <span class="keywordtype">int</span> main() { ogg_sync_state oy; ogg_stream_state os; <span class="keywordtype">int</span> init=0; ogg_packet op; <a name="_a0"></a><a class="code" href="structkate__state.html">kate_state</a> k; <a name="_a1"></a><a class="code" href="structkate__info.html">kate_info</a> ki; <a name="_a2"></a><a class="code" href="structkate__comment.html">kate_comment</a> kc; <span class="keyword">const</span> <a name="_a3"></a><a class="code" href="structkate__event.html">kate_event</a> *ev; <span class="comment">/* for the benefit of windows, which mangles data otherwise */</span> set_binary_file(stdin); <span class="comment">/* we initialize ogg and kate info/comment structures */</span> ogg_sync_init(&oy); <a name="a4"></a><a class="code" href="group__info.html#gab9031b2c167954bc7d754b30774f0241">kate_info_init</a>(&ki); <a name="a5"></a><a class="code" href="group__comments.html#ga4f717746ed53e557e57bb1e2b40dbd84">kate_comment_init</a>(&kc); <span class="comment">/*</span> <span class="comment"> First, read the headers, which must appear first in a Kate stream. When</span> <span class="comment"> kate_decode_header returns a positive number, all headers have been seen</span> <span class="comment"> and we're ready to decode data.</span> <span class="comment"> */</span> <span class="keywordflow">do</span> { get_packet(&oy,&os,&init,&op); } <span class="keywordflow">while</span> (<a name="a6"></a><a class="code" href="oggkate_8h.html#ad9a723eff7f66cadae79719d09aebd4d">kate_ogg_decode_headerin</a>(&ki,&kc,&op)==0); <span class="comment">/*</span> <span class="comment"> We now have all the information we need from the headers, so we can</span> <span class="comment"> initialize kate for decoding</span> <span class="comment"> */</span> <a name="a7"></a><a class="code" href="group__decoding.html#gaecc12ec59e4b3256f50b5c135d4fe90f">kate_decode_init</a>(&k,&ki); <span class="comment">/*</span> <span class="comment"> We can now read data, until kate_decode_packetin returns a positive</span> <span class="comment"> number, signaling the end of the stream</span> <span class="comment"> */</span> <span class="keywordflow">while</span> (1) { <span class="keywordflow">if</span> (get_packet(&oy,&os,&init,&op)) <span class="keywordflow">break</span>; <span class="keywordflow">if</span> (<a name="a8"></a><a class="code" href="oggkate_8h.html#a66a5a414cf4ad9b094b27a78c00e83a7">kate_ogg_decode_packetin</a>(&k,&op)>0) <span class="keywordflow">break</span>; <span class="comment">/* we may have an event (eg, text) */</span> <span class="keywordflow">if</span> (<a name="a9"></a><a class="code" href="group__decoding.html#gacdc7b2786e9fb2c8c685ebe3f483852c">kate_decode_eventout</a>(&k,&ev)==0) { printf(<span class="stringliteral">"Kate stream has text: %s\n"</span>,ev-><a name="a10"></a><a class="code" href="structkate__event.html#ae10745a5078521816cc07a09654fbfd4">text</a>); } } <span class="comment">/* That's it, we can now cleanup */</span> ogg_stream_clear(&os); ogg_sync_clear(&oy); <a name="a11"></a><a class="code" href="kate_8h.html#a8617b44c49f19262a9e03c0dcb45d971">kate_clear</a>(&k); <a name="a12"></a><a class="code" href="group__info.html#gaa8ba295f7925e8926ed46510c28be60d">kate_info_clear</a>(&ki); <a name="a13"></a><a class="code" href="group__comments.html#ga92e532be93459a5b1d6835b64c1129da">kate_comment_clear</a>(&kc); <span class="keywordflow">return</span> 0; } </pre></div> </div> <hr size="1"/><address style="text-align: right;"><small>Generated on Wed Dec 23 04:05:07 2009 for libkate by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address> </body> </html>