OggPageHeader.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 <libilliCore/iLE_Math.h>
00034 #include <libilliCore/StringHelper.h>
00035 //#include "OggSegmentTable.h"
00036 //#include "OggInt64.h"
00037 //#include "OggMath.h"
00038 
00039 
00040 using namespace std;
00041 
00042 #define OGG_CAPTURE_PATTERN "Oggs"
00043 class LIBOOOGG_API OggPageHeader                        //Do not derive - or needs virtual destructor.
00044 {
00045 public:
00046         OggPageHeader(void);
00047         ~OggPageHeader(void);
00048         OggPageHeader* clone();
00049         //0-3                   CapPattern                                              "Oggs"
00050         //4                             Struct Ver
00051         //5                             Head Flags
00052         //6-13                  Granule Pos
00053         //14-17                 Stream Serial No
00054         //18-21                 Page Seq No
00055         //22-25                 CheckSum
00056         //26                    Num Segments
00057         //27...                 SegmentTable
00058 
00059         static const int MAX_NUM_SEGMENTS = 255;
00060         static const int MAX_SEGMENT_SIZE = 255;
00061         static const int SEGMENT_WIDTH = 1;
00062 
00063         static const unsigned char OGG_CAPTURE_PATTERN_SIZE = 4;
00064         static const unsigned char OGG_BASE_HEADER_SIZE = 27;
00065         static const LOOG_INT64 UNKNOWN_GRANULE_POS = -1;
00066         enum ePageState {
00067                 INVALID,
00068                 BLANK,
00069                 BASE_HEAD_SET,
00070                 FULL_HEAD_SET,
00071                 COMPLETE
00072         };
00073 
00074         enum eHeadFlags {
00075                 NO_FLAGS = 0,
00076                 CONTINUATION = 1,
00077                 BOS = 2,
00078                 EOS = 4
00079         };
00080 
00081         
00082         enum eFieldOffsets {
00083                 CAPTURE_PATTURN = 0,
00084                 STRUCTURE_VERSION = 4,
00085                 HEADER_FLAGS = 5,
00086                 GRANULE_POS = 6,
00087                 SERIAL_NO = 14,
00088                 SEQUENCE_NO = 18,
00089                 OGG_CHECKSUM = 22,
00090                 NUM_SEGMENTS = 26,
00091                 SEGMENT_TABLE = 27
00092         };
00093         
00094 
00095         bool rawData(unsigned char* outData, unsigned long inBuffSize);
00096         
00097         //State variables
00098         ePageState pageState();
00099         void setPageState(ePageState inPageState);
00100 
00101         //Access header flags
00102         bool isContinuation();
00103         bool isBOS();
00104         bool isEOS();   
00105 
00106         //Size variables        
00107         unsigned long pageSize();
00108         unsigned long headerSize();
00109         unsigned long dataSize();
00110         unsigned long calculateDataSize();
00111         
00112         //Bulk Mutators
00113         bool setBaseHeader(const unsigned char* inBaseHeader);
00114         
00115         //Accesors
00116         unsigned char StructureVersion();
00117         unsigned char HeaderFlags();
00118         LOOG_INT64 GranulePos();
00119         unsigned long StreamSerialNo();
00120         unsigned long PageSequenceNo();
00121         unsigned long CRCChecksum();
00122         unsigned char NumPageSegments();
00123         unsigned char* SegmentTable();
00124 
00125         //Mutators
00126         void setStructureVersion(unsigned char inVal);
00127         void setHeaderFlags(unsigned char inVal);
00128         void setGranulePos(LOOG_INT64 inPtr);
00129         void setGranulePos(const unsigned char* inPtr);
00130         void setStreamSerialNo(unsigned long inVal);
00131         void setStreamSerialNo(const unsigned char* inPtr);
00132         void setPageSequenceNo(unsigned long inVal);
00133         void setPageSequenceNo(const unsigned char* inPtr);
00134         void setCRCChecksum(unsigned long inVal);
00135         void setCRCChecksum(const unsigned char* inPtr);
00136         void setNumPageSegments(unsigned char inVal);
00137         void setSegmentTable(unsigned char* inPtr);
00138         void setSegmentTable(const unsigned char* inPtr, unsigned char inNumSegs);
00139 
00140         void setHeaderSize(unsigned long inVal);
00141         void setDataSize(unsigned long inVal);
00142 
00143 
00144         //unsigned long headerCheckSum();
00145         string toString();
00146 protected:
00147         //Size fields
00148         unsigned long mPageSize;
00149         unsigned long mHeaderSize;
00150         unsigned long mDataSize;
00151 
00152         //Header fields
00153         unsigned char mStructureVersion;
00154         unsigned char mHeaderFlags;
00155         LOOG_INT64 mGranulePos;
00156         unsigned long mStreamSerialNo;
00157         unsigned long mPageSequenceNo;
00158         unsigned long mCRCChecksum;
00159         unsigned char mNumPageSegments;
00160 
00161         //Segment table
00162         unsigned char* mSegmentTable;
00163         
00164         //Page state
00165         ePageState mPageState;
00166 private:
00167         OggPageHeader& operator=(const OggPageHeader& other);  /* Don't assign me */
00168         OggPageHeader(const OggPageHeader& other); /* Don't copy me */
00169 };

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