examples/sfexamples/oggvorbiscodec/src/libvorbis/doc/vorbisfile/chainingexample.html

00001 <html>
00002 
00003 <head>
00004 <title>vorbisfile - Example Code</title>
00005 <link rel=stylesheet href="style.css" type="text/css">
00006 </head>
00007 
00008 <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
00009 <table border=0 width=100%>
00010 <tr>
00011 <td><p class=tiny>Vorbisfile documentation</p></td>
00012 <td align=right><p class=tiny>vorbisfile version 1.68 - 20030307</p></td>
00013 </tr>
00014 </table>
00015 
00016 <h1>Chaining Example Code</h1>
00017 
00018 <p>
00019 The following is a run-through of the chaining example program supplied
00020 with vorbisfile - <a href="chaining_example_c.html">chaining_example.c</a>.  
00021 This program demonstrates how to work with a chained bitstream.
00022 
00023 <p>
00024 First, relevant headers, including vorbis-specific "codec.h" and "vorbisfile.h" have to be included.
00025 
00026 <br><br>
00027 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00028 <tr bgcolor=#cccccc>
00029         <td>
00030 <pre><b>
00031 #include "vorbis/codec.h"
00032 #include "vorbis/vorbisfile.h"
00033 #include "../lib/misc.h"
00034 </b></pre>
00035         </td>
00036 </tr>
00037 </table>
00038 
00039 <p>Inside main(), we declare our primary OggVorbis_File structure.  We also declare a other helpful variables to track our progress within the file.
00040 <br><br>
00041 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00042 <tr bgcolor=#cccccc>
00043         <td>
00044 <pre><b>
00045 int main(){
00046   OggVorbis_File ov;
00047   int i;
00048 </b></pre>
00049         </td>
00050 </tr>
00051 </table>
00052 
00053 <p><a href="ov_open.html">ov_open()</a> must be
00054 called to initialize the <a href="OggVorbis_File.html">OggVorbis_File</a> structure with default values.  
00055 <a href="ov_open.html">ov_open()</a> also checks to ensure that we're reading Vorbis format and not something else.
00056 
00057 <br><br>
00058 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00059 <tr bgcolor=#cccccc>
00060         <td>
00061 <pre><b>
00062   if(ov_open(stdin,&amp;ov,NULL,-1)&gt;0){
00063     printf("Could not open input as an OggVorbis file.\n\n");
00064     exit(1);
00065   }
00066 
00067 </b></pre>
00068         </td>
00069 </tr>
00070 </table>
00071 
00072 <p>
00073 First we check to make sure the stream is seekable using <a href="ov_seekable.html">ov_seekable</a>.
00074 
00075 <p>Then we're going to find the number of logical bitstreams in the physical bitstream using <a href="ov_streams.html">ov_streams</a>.
00076 
00077 <p>We use <a href="ov_time_total.html">ov_time_total</a> to determine the total length of the physical bitstream.  We specify that we want the entire bitstream by using the argument <tt>-1</tt>.
00078 
00079 <br><br>
00080 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00081 <tr bgcolor=#cccccc>
00082         <td>
00083 <pre><b>
00084   if(ov_seekable(&amp;ov)){
00085     printf("Input bitstream contained %ld logical bitstream section(s).\n",
00086            ov_streams(&amp;ov));
00087     printf("Total bitstream playing time: %ld seconds\n\n",
00088            (long)ov_time_total(&amp;ov,-1));
00089 
00090   }else{
00091     printf("Standard input was not seekable.\n"
00092            "First logical bitstream information:\n\n");
00093   }
00094   
00095 </b></pre>
00096         </td>
00097 </tr>
00098 </table>
00099 
00100 <p>Now we're going to iterate through each logical bitstream and print information about that bitstream.
00101 
00102 <p>We use <a href="ov_info.html">ov_info</a> to pull out the <a href="vorbis_info.html">vorbis_info</a> struct for each logical bitstream.  This struct contains bitstream-specific info.
00103 
00104 <p><a href="ov_serialnumber.html">ov_serialnumber</a> retrieves the unique serial number for the logical bistream.  <a href="ov_raw_total.html">ov_raw_total</a> gives the total compressed bytes for the logical bitstream, and <a href="ov_time_total.html">ov_time_total</a> gives the total time in the logical bitstream.
00105 
00106 <br><br>
00107 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00108 <tr bgcolor=#cccccc>
00109         <td>
00110 <pre><b>
00111   for(i=0;i&lt;ov_streams(&amp;ov);i++){
00112     vorbis_info *vi=ov_info(&amp;ov,i);
00113     printf("\tlogical bitstream section %d information:\n",i+1);
00114     printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
00115            vi-&gt;rate,vi-&gt;channels,ov_bitrate(&amp;ov,i)/1000,
00116            ov_serialnumber(&amp;ov,i));
00117     printf("\t\tcompressed length: %ld bytes ",(long)(ov_raw_total(&amp;ov,i)));
00118     printf(" play time: %lds\n",(long)ov_time_total(&amp;ov,i));
00119   } 
00120 </b></pre>
00121         </td>
00122 </tr>
00123 </table>
00124 <p>
00125 When we're done with the entire physical bitstream, we need to call <a href="ov_clear.html">ov_clear()</a> to release the bitstream.
00126 
00127 <br><br>
00128 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00129 <tr bgcolor=#cccccc>
00130         <td>
00131 <pre><b>
00132   ov_clear(&amp;ov);
00133   return 0;
00134 }
00135 </b></pre>
00136         </td>
00137 </tr>
00138 </table>
00139 
00140 <p>
00141 The full source for chaining_example.c can be found with the vorbis
00142 distribution in <a href="chaining_example_c.html">chaining_example.c</a>.
00143 
00144 <br><br>
00145 <hr noshade>
00146 <table border=0 width=100%>
00147 <tr valign=top>
00148 <td><p class=tiny>copyright &copy; 2004 Xiph.org</p></td>
00149 <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a><br><a href="mailto:team@vorbis.org">team@vorbis.org</a></p></td>
00150 </tr><tr>
00151 <td><p class=tiny>Vorbisfile documentation</p></td>
00152 <td align=right><p class=tiny>vorbisfile version 1.68 - 20030307</p></td>
00153 </tr>
00154 </table>
00155 
00156 </body>
00157 
00158 </html>

Generated by  doxygen 1.6.2