Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members

oggcc.h

00001 
00008 // #include "oggpy_wrappers.h"
00009 
00010 #ifndef OGGCC_H
00011 #define OGGCC_H
00012 
00013 #include <ogg/ogg.h>
00014 #include <string>
00015 
00016 
00018 namespace ogg {
00019 
00021     class packet {
00025         protected:
00026             void clear ( )              { ogg_packet_clear(&this->data); }
00027 
00028         private:
00029             ogg_packet data;
00030 
00031         public:
00032             ogg_packet *get_data( )     { return &this->data; }
00033 
00034             packet ( )                  { /* memset(&data, 0, sizeof(this->data)); // may be redundant anyway */ }
00035             virtual ~packet ( )         { }
00036 
00037             ogg_int64_t packetno( )     { return this->get_data()->packetno; }
00038             ogg_int64_t granulepos( )   { return this->get_data()->granulepos; } // may want to expose only page granulepos, or this may be useful for encode only.
00039     };
00040 
00041 
00043     class userpacket : public packet {
00044         private:
00045             std::string bytes;
00046 
00047         public:
00048             virtual ~userpacket ()    { }
00049 
00051             // libogg framing sets the packetno for us.
00052             userpacket(std::string bytes, ogg_int64_t granulepos, bool bos = false, bool eos = false)
00053             {
00054                 this->bytes = bytes;
00055                 (const char*)(this->get_data()->packet) = bytes.c_str();
00056                 this->get_data()->granulepos = granulepos;
00057                 this->get_data()->bytes      = bytes.size();
00058                 this->get_data()->b_o_s      = bos;
00059                 this->get_data()->e_o_s      = eos;
00060             }
00061     };
00062 
00063 
00065     class oggpack_base {
00066         private:
00067             oggpack_buffer data;
00068 
00069         public:
00070             oggpack_buffer *get_data()          { return &this->data; }
00071             unsigned char *get_buffer ( )       { return oggpack_get_buffer ( this->get_data() ); }
00072 
00073             void readinit ( unsigned char *buf, int bytes )  { oggpack_readinit ( this->get_data(), buf, bytes );  }
00074 
00080             void readinit ( packet *p )    {
00081                 ogg_packet *op;
00082                 op = p->get_data();
00083                 this->readinit(op->packet, op->bytes);
00084 
00085                 /* LIBOGG2:
00086                  * opb = malloc(oggpack_buffersize()):
00087                  * // oggpack_buffersize() is implemented as
00088                  * // sizeof(oggpack_buffer), but we don't
00089                  * // get that size in our main code.
00090                  * oggpack_readinit(op->packet);
00091                  */
00092             }
00093             
00094             void writeinit ( )                  { oggpack_writeinit ( this->get_data() );  }
00095 
00097             ogg::packet packetout(ogg_int64_t granulepos, bool bos=false, bool eos=false) { 
00098                 oggpack_buffer *opb = this->get_data();
00099                 return ogg::userpacket(std::string((const char*)opb->buffer,
00100                                                    oggpack_bytes(opb)), granulepos, bos, eos);
00101             }
00102     };
00103 
00104 
00106     class oggpack : public oggpack_base {
00107         public:
00108             long bits   ( )             { return oggpack_bits   ( this->get_data() );  }
00109             long bytes  ( )             { return oggpack_bytes  ( this->get_data() );  }
00110             long look   ( int bits )    { return oggpack_look   ( this->get_data(), bits );  }
00111             long look1  ( )             { return oggpack_look1  ( this->get_data() ); }
00112             long read   ( int bits )    { return oggpack_read   ( this->get_data(), bits );  }
00113             long read1  ( )             { return oggpack_read1  ( this->get_data() ); }
00114 
00115             void adv ( int bits )       { oggpack_adv   ( this->get_data(), bits );  }
00116             void adv1 ( )               { oggpack_adv1  ( this->get_data() );  }
00117             void reset ( )              { oggpack_reset ( this->get_data() );  }
00118 
00119             void write (unsigned long value, int bits )     { oggpack_write ( this->get_data(), value, bits ); }
00120 
00121             void writealign (  )                            { oggpack_writealign ( this->get_data() ); }
00122             void writeclear (  )                            { oggpack_writeclear ( this->get_data() ); }
00123             void writecopy  ( void *source, long bits )     { oggpack_writecopy ( this->get_data(), source, bits );  }
00124             void writetrunc ( long bits )                   { oggpack_writetrunc ( this->get_data(), bits );  }
00125     };
00126 
00127     
00129     class oggpackB : public oggpack_base {
00130         public:
00131             long bits   ( )             { return oggpackB_bits   ( this->get_data() );  }
00132             long bytes  ( )             { return oggpackB_bytes  ( this->get_data() );  }
00133             long look   ( int bits )    { return oggpackB_look   ( this->get_data(), bits );  }
00134             long look1  ( )             { return oggpackB_look1  ( this->get_data() ); }
00135             long read   ( int bits )    { return oggpackB_read   ( this->get_data(), bits );  }
00136             long read1  ( )             { return oggpackB_read1  ( this->get_data() ); }
00137 
00138             void adv ( int bits )       { oggpackB_adv   ( this->get_data(), bits );  }
00139             void adv1 ( )               { oggpackB_adv1  ( this->get_data() );  }
00140             void reset ( )              { oggpackB_reset ( this->get_data() );  }
00141 
00142             void write (unsigned long value, int bits )     { oggpackB_write ( this->get_data(), value, bits ); }
00143 
00144             void writealign (  )                            { oggpackB_writealign ( this->get_data() ); }
00145             void writeclear (  )                            { oggpackB_writeclear ( this->get_data() ); }
00146             void writecopy  ( void *source, long bits )     { oggpackB_writecopy ( this->get_data(), source, bits );  }
00147             void writetrunc ( long bits )                   { oggpackB_writetrunc ( this->get_data(), bits );  }
00148     };
00149 
00150     
00152     class page {
00153         private:
00154 
00155         public:
00156             ogg_page data;  // soon to be privatized, take that social security!
00157             ogg_page *get_data()        { return &this->data; }
00158 
00160             bool bos ( )                { return (ogg_page_bos(this->get_data())); }
00161             bool continued ( )          { return (ogg_page_continued(this->get_data())); }
00163             bool eos ( )                { return ogg_page_eos(this->get_data()); }
00165             int packets ( )             { return ogg_page_packets(this->get_data()); }
00166             int serialno ( )            { return ogg_page_serialno(this->get_data()); }
00167             int version ( )             { return ogg_page_version(this->get_data()); }
00168             long pageno ( )             { return ogg_page_pageno(this->get_data()); }
00169             ogg_int64_t granulepos ( )  { return ogg_page_granulepos(this->get_data()); }
00171             void checksum_set ( )       { ogg_page_checksum_set(this->get_data()); }
00172 
00174             std::string header ( )      { return std::string((char*)this->data.header, (size_t)this->data.header_len); }
00175             std::string body ( )        { return std::string((char*)this->data.body, (size_t)this->data.body_len); }
00176     };
00177 
00178     
00180     class sync {
00181         protected:
00182             int   clear     ( )               { return ogg_sync_clear (&this->data); }
00183             int   destroy   ( )               { return ogg_sync_destroy (&this->data); }
00184             int   init      ( )               { return ogg_sync_init (&this->data); }
00185             int   pageout   ( ogg_page *og )  { return ogg_sync_pageout (&this->data, og); }
00186 
00192             long  pageseek  ( ogg_page *og )  { return ogg_sync_pageseek (&this->data, og); }
00193 
00194         public:
00195             ogg_sync_state data;
00196 
00197             sync ()   { this->init();  }
00198             ~sync ()  { this->clear(); }
00199 
00201             char *buffer    ( long size )     { return ogg_sync_buffer (&this->data, size); }
00202             int   wrote     ( long bytes )    { return ogg_sync_wrote (&this->data, bytes); }
00203 
00204             int   pageout   ( page *og )      { return this->pageout(&og->data);  }
00205             long  pageseek  ( page *og )      { return this->pageseek(&og->data); }
00206 
00208             int   reset     ( )               { return ogg_sync_reset (&this->data); }
00209     };
00210 
00211     
00213     class stream {
00214         public:
00215             ogg_stream_state data;
00216 
00217         protected:
00219             int init ( int serialno )             { return ogg_stream_init(&this->data, serialno); }
00221             int clear ( )                         { return ogg_stream_clear(&this->data); }
00223             int destroy ( )                       { return ogg_stream_destroy(&this->data); }
00224 
00225             int flush ( ogg_page *og )            { return ogg_stream_flush(&this->data, og); }
00226 
00227             int packetin ( ogg_packet *op )       { return ogg_stream_packetin(&this->data, op); }
00228             int packetout ( ogg_packet *op )      { return ogg_stream_packetout(&this->data, op); }
00229             int packetpeek ( ogg_packet *op )     { return ogg_stream_packetpeek(&this->data, op); }
00230 
00231             int pagein  ( ogg_page *og )          { return ogg_stream_pagein(&this->data, og); }
00232             int pageout ( ogg_page *og )          { return ogg_stream_pageout(&this->data, og); }
00233 
00234         public:
00235             stream(int serialno)                  { this->init(serialno); }
00236             ~stream()                             { this->clear(); }
00237 
00238             int eos ( )                           { return ogg_stream_eos(&this->data); }
00239 
00241             int flush ( page *og )                { return this->flush(&og->data); }
00242 
00243             // decode.  copies page in?
00244             int pagein  ( page *og )              { return this->pagein(&og->data); }
00246             int packetout   ( packet *op )        { return this->packetout(op->get_data()); }
00254             int packetpeek  ( packet *op )        { return this->packetpeek(op->get_data()); }
00255 
00256             // encode. copies submitted packet. always returns zero.
00257             int packetin ( packet *op )           { return this->packetin(op->get_data()); }
00258             int pageout ( page *og )              { return this->pageout(&og->data); }
00259 
00261             int reset   ( )                       { return ogg_stream_reset(&this->data); }
00262             int reset_serialno ( int serialno )   { return ogg_stream_reset_serialno(&this->data, serialno); }
00263     };
00264 };
00265 
00266 #endif

Generated on Wed Apr 7 03:10:32 2004 for oggpy/oggcc by doxygen 1.3.5