<!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.14"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>libkate: encoding.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">libkate  <span id="projectnumber">0.4.1</span> </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.14 --> <script type="text/javascript" src="menudata.js"></script> <script type="text/javascript" src="menu.js"></script> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ $(function() { initMenu('',false,false,'search.php','Search'); }); /* @license-end */</script> <div id="main-nav"></div> </div><!-- top --> <div class="header"> <div class="headertitle"> <div class="title">encoding.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"> This shows the steps necessary to encode a Kate stream.</span></div><div class="line"><span class="comment"> For clarity, error checking is omitted.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <stdio.h></span></div><div class="line"><span class="preprocessor">#include <string.h></span></div><div class="line"><span class="preprocessor">#include <ogg/ogg.h></span></div><div class="line"><span class="preprocessor">#include "common.h"</span></div><div class="line"></div><div class="line"><span class="comment">/* All the libkate API is available from the main kate header file: */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <<a class="code" href="oggkate_8h.html">kate/oggkate.h</a>></span></div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> We want to control when Ogg pages are output, as Kate is a discontinuous</span></div><div class="line"><span class="comment"> codec, so we don't know when the next event will happen, hence the need</span></div><div class="line"><span class="comment"> to create a page for every event.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> flush_page(ogg_stream_state *os)</div><div class="line">{</div><div class="line"> ogg_page og;</div><div class="line"> <span class="keywordflow">while</span> (1) {</div><div class="line"> <span class="keywordtype">int</span> ret=ogg_stream_flush(os,&og);</div><div class="line"> <span class="keywordflow">if</span> (ret==0) <span class="keywordflow">break</span>;</div><div class="line"> fwrite(og.header,1,og.header_len,stdout);</div><div class="line"> fwrite(og.body,1,og.body_len,stdout);</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main()</div><div class="line">{</div><div class="line"> <span class="comment">/* We need an Ogg stream to write to */</span></div><div class="line"></div><div class="line"> ogg_stream_state os;</div><div class="line"> ogg_packet op;</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> First, a kate_info structure needs to be created and setup for the stream to create.</span></div><div class="line"><span class="comment"> A kate_comment structure also has to be created.</span></div><div class="line"><span class="comment"> Information from both of these will get encoded into the stream headers.</span></div><div class="line"><span class="comment"> Last, we also need a kate_state structure, which will be initialized later.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"> <a name="_a0"></a><a class="code" href="structkate__info.html">kate_info</a> ki;</div><div class="line"> <a name="_a1"></a><a class="code" href="structkate__comment.html">kate_comment</a> kc;</div><div class="line"> <a name="_a2"></a><a class="code" href="structkate__state.html">kate_state</a> k;</div><div class="line"></div><div class="line"> <a name="a3"></a><a class="code" href="group__info.html#gab9031b2c167954bc7d754b30774f0241">kate_info_init</a>(&ki);</div><div class="line"> <a name="a4"></a><a class="code" href="group__comments.html#ga4f717746ed53e557e57bb1e2b40dbd84">kate_comment_init</a>(&kc);</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> The most important part of the kate_info structure on encoding is the granule</span></div><div class="line"><span class="comment"> encoding information, which describes how granules and time are mapped.</span></div><div class="line"><span class="comment"> Here, we map one granule to one millisecond.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"> ki.<a name="a5"></a><a class="code" href="structkate__info.html#a1bf457732577344fa6d0f035d30d1e13">granule_shift</a>=32;</div><div class="line"> ki.<a name="a6"></a><a class="code" href="structkate__info.html#a7eb196702d96e5676b27838cadfd6acf">gps_numerator</a>=1000;</div><div class="line"> ki.<a name="a7"></a><a class="code" href="structkate__info.html#a00c2253966d5a22cc3e56f4f98dd4995">gps_denominator</a>=1;</div><div class="line"></div><div class="line"> <span class="comment">/* With that done, we can initialize libkate for encoding, and initialize libogg as well: */</span></div><div class="line"></div><div class="line"> <a name="a8"></a><a class="code" href="group__encoding.html#ga0a7588d43b22fd5ef6e0a88ed7245210">kate_encode_init</a>(&k,&ki);</div><div class="line"> ogg_stream_init(&os,0x12345678);</div><div class="line"></div><div class="line"> <span class="comment">/* for the benefit of windows, which mangles data otherwise */</span></div><div class="line"> set_binary_file(stdout);</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> Before you can create events, headers need to be sent. Here, we'll just send</span></div><div class="line"><span class="comment"> the headers directly, but you will usually want to add regions, styles, etc to</span></div><div class="line"><span class="comment"> the headers before doing so:</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"> <span class="keywordflow">while</span> (<a name="a9"></a><a class="code" href="oggkate_8h.html#ac9f5a00fc71e781a8c18bccb12c3f9f7">kate_ogg_encode_headers</a>(&k,&kc,&op)==0) {</div><div class="line"> ogg_stream_packetin(&os,&op);</div><div class="line"> ogg_packet_clear(&op);</div><div class="line"> }</div><div class="line"> flush_page(&os);</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> Events can now be created, and we'll just create and send a single one here,</span></div><div class="line"><span class="comment"> starting at time 10 seconds, and stopping at time 15 seconds.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define text "Hello, world!"</span></div><div class="line"> <a name="a10"></a><a class="code" href="oggkate_8h.html#aa66db5293b6c4afa2fbbf536d0d1e4dd">kate_ogg_encode_text</a>(&k,10.0,15.0,text,strlen(text)+1,&op);</div><div class="line"> ogg_stream_packetin(&os,&op);</div><div class="line"> ogg_packet_clear(&op);</div><div class="line"> flush_page(&os);</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> When we're done, we can tell libkate so an "end of stream" packet will be generated,</span></div><div class="line"><span class="comment"> and clear the resources we've been using:</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"> <a name="a11"></a><a class="code" href="oggkate_8h.html#a28a9b117b4051ed02c761f279d5c34ee">kate_ogg_encode_finish</a>(&k,-1,&op);</div><div class="line"> ogg_stream_packetin(&os,&op);</div><div class="line"> ogg_packet_clear(&op);</div><div class="line"> flush_page(&os);</div><div class="line"> ogg_stream_clear(&os);</div><div class="line"> <a name="a12"></a><a class="code" href="kate_8h.html#a8617b44c49f19262a9e03c0dcb45d971">kate_clear</a>(&k);</div><div class="line"> <a name="a13"></a><a class="code" href="group__info.html#gaa8ba295f7925e8926ed46510c28be60d">kate_info_clear</a>(&ki);</div><div class="line"> <a name="a14"></a><a class="code" href="group__comments.html#ga92e532be93459a5b1d6835b64c1129da">kate_comment_clear</a>(&kc);</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> That's it, we now have created a full kate stream. You may now want to decode it,</span></div><div class="line"><span class="comment"> or multiplex it with a Theora video, etc.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div></div><!-- fragment --> </div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.14 </small></address> </body> </html>