00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _MATROSKA_FILE_PARSER_HH
00022
00023 #ifndef _STREAM_PARSER_HH
00024 #include "StreamParser.hh"
00025 #endif
00026 #ifndef _MATROSKA_FILE_HH
00027 #include "MatroskaFile.hh"
00028 #endif
00029 #ifndef _EBML_NUMBER_HH
00030 #include "EBMLNumber.hh"
00031 #endif
00032
00033
00034 enum MatroskaParseState {
00035 PARSING_START_OF_FILE,
00036 LOOKING_FOR_TRACKS,
00037 PARSING_TRACK,
00038 PARSING_CUES,
00039 LOOKING_FOR_CLUSTER,
00040 LOOKING_FOR_BLOCK,
00041 PARSING_BLOCK,
00042 DELIVERING_FRAME_WITHIN_BLOCK,
00043 DELIVERING_FRAME_BYTES
00044 };
00045
00046 class MatroskaFileParser: public StreamParser {
00047 public:
00048 MatroskaFileParser(MatroskaFile& ourFile, FramedSource* inputSource,
00049 FramedSource::onCloseFunc* onEndFunc, void* onEndClientData,
00050 MatroskaDemux* ourDemux = NULL);
00051 virtual ~MatroskaFileParser();
00052
00053 void seekToTime(double& seekNPT);
00054
00055
00056 static void continueParsing(void* clientData, unsigned char* ptr, unsigned size, struct timeval presentationTime);
00057 void continueParsing();
00058
00059 private:
00060
00061 Boolean parse();
00062
00063
00064 Boolean parseStartOfFile();
00065 void lookForNextTrack();
00066 Boolean parseTrack();
00067 Boolean parseCues();
00068
00069 void lookForNextBlock();
00070 void parseBlock();
00071 Boolean deliverFrameWithinBlock();
00072 void deliverFrameBytes();
00073
00074 void getCommonFrameBytes(MatroskaTrack* track, u_int8_t* to, unsigned numBytesToGet, unsigned numBytesToSkip);
00075
00076 Boolean parseEBMLNumber(EBMLNumber& num);
00077 Boolean parseEBMLIdAndSize(EBMLId& id, EBMLDataSize& size);
00078 Boolean parseEBMLVal_unsigned64(EBMLDataSize& size, u_int64_t& result);
00079 Boolean parseEBMLVal_unsigned(EBMLDataSize& size, unsigned& result);
00080 Boolean parseEBMLVal_float(EBMLDataSize& size, float& result);
00081 Boolean parseEBMLVal_string(EBMLDataSize& size, char*& result);
00082
00083 Boolean parseEBMLVal_binary(EBMLDataSize& size, u_int8_t*& result);
00084
00085 void skipHeader(EBMLDataSize const& size);
00086
00087 void setParseState();
00088
00089 void seekToFilePosition(u_int64_t offsetInFile);
00090 void seekToEndOfFile();
00091 void resetStateAfterSeeking();
00092
00093 private:
00094 virtual void restoreSavedParserState();
00095
00096 private:
00097
00098 MatroskaFile& fOurFile;
00099 FramedSource* fInputSource;
00100 FramedSource::onCloseFunc* fOnEndFunc;
00101 void* fOnEndClientData;
00102 MatroskaDemux* fOurDemux;
00103 MatroskaParseState fCurrentParseState;
00104 u_int64_t fCurOffsetInFile, fSavedCurOffsetInFile, fLimitOffsetInFile;
00105
00106
00107 EBMLId fLastSeekId;
00108
00109
00110 unsigned fClusterTimecode;
00111
00112
00113 unsigned fBlockSize;
00114 unsigned fBlockTrackNumber;
00115 short fBlockTimecode;
00116 unsigned fNumFramesInBlock;
00117 unsigned* fFrameSizesWithinBlock;
00118
00119
00120 double fPresentationTimeOffset;
00121 unsigned fNextFrameNumberToDeliver;
00122 unsigned fCurOffsetWithinFrame, fSavedCurOffsetWithinFrame;
00123
00124
00125 u_int8_t* fCurFrameTo;
00126 unsigned fCurFrameNumBytesToGet;
00127 unsigned fCurFrameNumBytesToSkip;
00128 };
00129
00130 #endif