Sophie

Sophie

distrib > Mandriva > current > x86_64 > by-pkgid > d76e9d0335eb50de9ef01195761a76f9 > files > 25

lib64kate-devel-0.3.7-1mdv2010.1.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"/>
<title>libkate: encoding.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&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;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>encoding.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">  */</span>

<span class="preprocessor">#include &lt;stdio.h&gt;</span>
<span class="preprocessor">#include &lt;string.h&gt;</span>
<span class="preprocessor">#include &lt;ogg/ogg.h&gt;</span>
<span class="preprocessor">#include &quot;common.h&quot;</span>

<span class="comment">/* All the libkate API is available from the main kate header file: */</span>

<span class="preprocessor">#include &lt;<a class="code" href="oggkate_8h.html">kate/oggkate.h</a>&gt;</span>

<span class="comment">/*</span>
<span class="comment">  We want to control when Ogg pages are output, as Kate is a discontinuous</span>
<span class="comment">  codec, so we don&apos;t know when the next event will happen, hence the need</span>
<span class="comment">  to create a page for every event.</span>
<span class="comment">  */</span>

<span class="keyword">static</span> <span class="keywordtype">void</span> flush_page(ogg_stream_state *os)
{
  ogg_page og;
  <span class="keywordflow">while</span> (1) {
    <span class="keywordtype">int</span> ret=ogg_stream_flush(os,&amp;og);
    <span class="keywordflow">if</span> (ret==0) <span class="keywordflow">break</span>;
    fwrite(og.header,1,og.header_len,stdout);
    fwrite(og.body,1,og.body_len,stdout);
  }
}

<span class="keywordtype">int</span> main()
{
  <span class="comment">/* We need an Ogg stream to write to */</span>

  ogg_stream_state os;
  ogg_packet op;

  <span class="comment">/*</span>
<span class="comment">    First, a kate_info structure needs to be created and setup for the stream to create.</span>
<span class="comment">    A kate_comment structure also has to be created.</span>
<span class="comment">    Information from both of these will get encoded into the stream headers.</span>
<span class="comment">    Last, we also need a kate_state structure, which will be initialized later.</span>
<span class="comment">    */</span>

  <a name="_a0"></a><a class="code" href="structkate__info.html">kate_info</a> ki;
  <a name="_a1"></a><a class="code" href="structkate__comment.html">kate_comment</a> kc;
  <a name="_a2"></a><a class="code" href="structkate__state.html">kate_state</a> k;

  <a name="a3"></a><a class="code" href="group__info.html#gab9031b2c167954bc7d754b30774f0241">kate_info_init</a>(&amp;ki);
  <a name="a4"></a><a class="code" href="group__comments.html#ga4f717746ed53e557e57bb1e2b40dbd84">kate_comment_init</a>(&amp;kc);

  <span class="comment">/*</span>
<span class="comment">    The most important part of the kate_info structure on encoding is the granule</span>
<span class="comment">    encoding information, which describes how granules and time are mapped.</span>
<span class="comment">    Here, we map one granule to one millisecond.</span>
<span class="comment">   */</span>

  ki.<a name="a5"></a><a class="code" href="structkate__info.html#a1bf457732577344fa6d0f035d30d1e13">granule_shift</a>=32;
  ki.<a name="a6"></a><a class="code" href="structkate__info.html#a7eb196702d96e5676b27838cadfd6acf">gps_numerator</a>=1000;
  ki.<a name="a7"></a><a class="code" href="structkate__info.html#a00c2253966d5a22cc3e56f4f98dd4995">gps_denominator</a>=1;

  <span class="comment">/* With that done, we can initialize libkate for encoding, and initialize libogg as well: */</span>

  <a name="a8"></a><a class="code" href="group__encoding.html#ga0a7588d43b22fd5ef6e0a88ed7245210">kate_encode_init</a>(&amp;k,&amp;ki);
  ogg_stream_init(&amp;os,0x12345678);

  <span class="comment">/* for the benefit of windows, which mangles data otherwise */</span>
  set_binary_file(stdout);

  <span class="comment">/*</span>
<span class="comment">    Before you can create events, headers need to be sent. Here, we&apos;ll just send</span>
<span class="comment">    the headers directly, but you will usually want to add regions, styles, etc to</span>
<span class="comment">    the headers before doing so:</span>
<span class="comment">    */</span>

  <span class="keywordflow">while</span> (<a name="a9"></a><a class="code" href="oggkate_8h.html#ac9f5a00fc71e781a8c18bccb12c3f9f7">kate_ogg_encode_headers</a>(&amp;k,&amp;kc,&amp;op)==0) {
    ogg_stream_packetin(&amp;os,&amp;op);
    ogg_packet_clear(&amp;op);
  }
  flush_page(&amp;os);

  <span class="comment">/*</span>
<span class="comment">    Events can now be created, and we&apos;ll just create and send a single one here,</span>
<span class="comment">    starting at time 10 seconds, and stopping at time 15 seconds.</span>
<span class="comment">    */</span>

<span class="preprocessor">#define text &quot;Hello, world!&quot;</span>
<span class="preprocessor"></span>  <a name="a10"></a><a class="code" href="oggkate_8h.html#aa66db5293b6c4afa2fbbf536d0d1e4dd">kate_ogg_encode_text</a>(&amp;k,10.0,15.0,text,strlen(text)+1,&amp;op);
  ogg_stream_packetin(&amp;os,&amp;op);
  ogg_packet_clear(&amp;op);
  flush_page(&amp;os);

  <span class="comment">/*</span>
<span class="comment">    When we&apos;re done, we can tell libkate so an &quot;end of stream&quot; packet will be generated,</span>
<span class="comment">    and clear the resources we&apos;ve been using:</span>
<span class="comment">    */</span>

  <a name="a11"></a><a class="code" href="oggkate_8h.html#a28a9b117b4051ed02c761f279d5c34ee">kate_ogg_encode_finish</a>(&amp;k,-1,&amp;op);
  ogg_stream_packetin(&amp;os,&amp;op);
  ogg_packet_clear(&amp;op);
  flush_page(&amp;os);
  ogg_stream_clear(&amp;os);
  <a name="a12"></a><a class="code" href="kate_8h.html#a8617b44c49f19262a9e03c0dcb45d971">kate_clear</a>(&amp;k);
  <a name="a13"></a><a class="code" href="group__info.html#gaa8ba295f7925e8926ed46510c28be60d">kate_info_clear</a>(&amp;ki);
  <a name="a14"></a><a class="code" href="group__comments.html#ga92e532be93459a5b1d6835b64c1129da">kate_comment_clear</a>(&amp;kc);

  <span class="comment">/*</span>
<span class="comment">    That&apos;s it, we now have created a full kate stream. You may now want to decode it,</span>
<span class="comment">    or multiplex it with a Theora video, etc.</span>
<span class="comment">    */</span>

  <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&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>