OggDataBuffer.h

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2003, 2004 Zentaro Kavanagh
00003 //
00004 //Redistribution and use in source and binary forms, with or without
00005 //modification, are permitted provided that the following conditions
00006 //are met:
00007 //
00008 //- Redistributions of source code must retain the above copyright
00009 //  notice, this list of conditions and the following disclaimer.
00010 //
00011 //- Redistributions in binary form must reproduce the above copyright
00012 //  notice, this list of conditions and the following disclaimer in the
00013 //  documentation and/or other materials provided with the distribution.
00014 //
00015 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00016 //  may be used to endorse or promote products derived from this software 
00017 //  without specific prior written permission.
00018 //
00019 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00022 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00023 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00024 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00025 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 //===========================================================================
00031 
00032 #pragma once
00033 //#include <sstream>
00034 #include <libOOOgg/CircularBuffer.h>
00035 #include <libOOOgg/OggPage.h>
00036 #include <libOOOgg/OggTypeDefs.h>
00037 #include <libOOOgg/IOggCallback.h>
00038 #include <libOOOgg/IFIFOBuffer.h>
00039 
00040 //Only needed for debugging
00041 //#include <fstream>
00042 //
00043 using namespace std;
00044 
00045 class LIBOOOGG_API OggDataBuffer {
00046 public:
00047         //Public Constants and enums
00048         enum eState {
00049                 EOS,
00050                 AWAITING_BASE_HEADER = 32,
00051                 AWAITING_SEG_TABLE,
00052                 AWAITING_DATA,
00053                 LOST_PAGE_SYNC
00054         };
00055 
00056         enum eFeedResult {
00057                 FEED_OK,
00058                 FEED_NULL_POINTER = 64,
00059                 FEED_BUFFER_WRITE_ERROR
00060         };
00061 
00062         enum eDispatchResult {
00063                 DISPATCH_OK,
00064                 DISPATCH_NO_CALLBACK = 256,
00065                 DISPATCH_FALSE
00066         };
00067 
00068         enum eProcessResult {
00069                 PROCESS_OK,
00070                 PROCESS_UNKNOWN_INTERNAL_ERROR = 512,
00071                 PROCESS_STREAM_READ_ERROR,
00072                 PROCESS_DISPATCH_FALSE,
00073                 PROCESS_DISPATCH_FAILED,
00074                 PROCESS_FAILED_TO_SET_HEADER,
00075                 PROCESS_LOST_SYNC = 4096
00076 
00077         };
00078 
00079         static const int MAX_OGG_PAGE_SIZE =    OggPageHeader::OGG_BASE_HEADER_SIZE +                                                                                   //Header
00080                                                                                         (OggPageHeader::MAX_NUM_SEGMENTS * OggPageHeader::MAX_SEGMENT_SIZE) +           //Page Data
00081                                                                                         (OggPageHeader::SEGMENT_WIDTH * OggPageHeader::MAX_NUM_SEGMENTS);                       //Segment table
00082 
00083         //Debug only
00084         //OggDataBuffer::OggDataBuffer(bool x);
00085         void debugWrite(string inString);
00086         //
00087 
00088         //Constructors
00089         OggDataBuffer(void);
00090         virtual ~OggDataBuffer(void);
00091 
00093         bool registerStaticCallback(fPageCallback inPageCallback, void* inUserData);
00094 
00096         bool registerVirtualCallback(IOggCallback* inPageCallback);
00097         
00099         eFeedResult feed(const unsigned char* inData, unsigned long inNumBytes);
00100         void clearData();
00101         
00103         unsigned long numBytesAvail();
00104 
00106         eState state();
00107 
00108 protected:
00109         //FIFO Buffer
00110         IFIFOBuffer* mBuffer;
00111         
00112         //Buffer State
00113         unsigned long mNumBytesNeeded;
00114         eState mState;  
00115         OggPage* pendingPage;
00116         LOOG_INT64 mPrevGranPos;
00117 
00118         //Callback pointers
00119         IOggCallback* mVirtualCallback;
00120         fPageCallback mStaticCallback;
00121         void* mStaticCallbackUserData;
00122 
00123         //Internal processing
00124         eProcessResult processBuffer();
00125         eProcessResult processBaseHeader();
00126         eProcessResult processSegTable();
00127         eProcessResult processDataSegment();
00128 
00129         //Internal dispatch
00130         virtual eDispatchResult dispatch(OggPage* inOggPage);
00131 
00132         //DEBUG
00133         //fstream debugLog;
00134         //
00135 private:
00136         OggDataBuffer& operator=(const OggDataBuffer& other);  /* Don't assign me */
00137         OggDataBuffer(const OggDataBuffer& other); /* Don't copy me */
00138 };

Generated on Tue Feb 15 14:54:21 2005 for oggdsf by  doxygen 1.3.9