live
MatroskaFileParser.hh
Go to the documentation of this file.
1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "liveMedia"
17// Copyright (c) 1996-2023 Live Networks, Inc. All rights reserved.
18// A parser for a Matroska file.
19// C++ header
20
21#ifndef _MATROSKA_FILE_PARSER_HH
22
23#ifndef _STREAM_PARSER_HH
24#include "StreamParser.hh"
25#endif
26#ifndef _MATROSKA_FILE_HH
27#include "MatroskaFile.hh"
28#endif
29#ifndef _EBML_NUMBER_HH
30#include "EBMLNumber.hh"
31#endif
32
33// An enum representing the current state of the parser:
44};
45
47public:
49 FramedSource::onCloseFunc* onEndFunc, void* onEndClientData,
50 MatroskaDemux* ourDemux = NULL);
52
53 void seekToTime(double& seekNPT);
54 void pause();
55
56 // StreamParser 'client continue' function:
57 static void continueParsing(void* clientData, unsigned char* ptr, unsigned size, struct timeval presentationTime);
59
60private:
61 // Parsing functions:
63 // returns True iff we have finished parsing to the end of all 'Track' headers (on initialization)
64
69
71 void parseBlock();
74
75 void getCommonFrameBytes(MatroskaTrack* track, u_int8_t* to, unsigned numBytesToGet, unsigned numBytesToSkip);
76
79 Boolean parseEBMLVal_unsigned64(EBMLDataSize& size, u_int64_t& result);
80 Boolean parseEBMLVal_unsigned(EBMLDataSize& size, unsigned& result);
83 // Note: "result" is dynamically allocated; the caller must delete[] it later
84 Boolean parseEBMLVal_binary(EBMLDataSize& size, u_int8_t*& result);
85 // Note: "result" is dynamically allocated; the caller must delete[] it later
86 void skipHeader(EBMLDataSize const& size);
87 void skipRemainingHeaderBytes(Boolean isContinuation);
88
90
91 void seekToFilePosition(u_int64_t offsetInFile);
93 void resetStateAfterSeeking(); // common code, called by both of the above
94
96 // called after a seek or pause to ensure that presentation times continue to be
97 // aligned with 'wall clock' time
98
99private: // redefined virtual functions
101
102private:
103 // General state for parsing:
111
112 // For skipping over (possibly large) headers:
114
115 // For parsing 'Seek ID's:
117
118 // Parameters of the most recently-parsed 'Cluster':
120
121 // Parameters of the most recently-parsed 'Block':
122 unsigned fBlockSize;
127
128 // Parameters of the most recently-parsed frame within a 'Block':
131 unsigned fCurOffsetWithinFrame, fSavedCurOffsetWithinFrame; // used if track->haveSubframes()
132
133 // Parameters of the (sub)frame that's currently being delivered:
134 u_int8_t* fCurFrameTo;
137};
138
139#endif
unsigned char Boolean
Definition: Boolean.hh:25
MatroskaParseState
@ DELIVERING_FRAME_WITHIN_BLOCK
@ PARSING_TRACK
@ LOOKING_FOR_BLOCK
@ PARSING_CUES
@ LOOKING_FOR_TRACKS
@ LOOKING_FOR_CLUSTER
@ PARSING_BLOCK
@ PARSING_START_OF_FILE
@ DELIVERING_FRAME_BYTES
#define NULL
void() onCloseFunc(void *clientData)
Definition: FramedSource.hh:40
Boolean parseEBMLIdAndSize(EBMLId &id, EBMLDataSize &size)
FramedSource * fInputSource
void skipHeader(EBMLDataSize const &size)
MatroskaParseState fCurrentParseState
virtual ~MatroskaFileParser()
Boolean parseEBMLVal_binary(EBMLDataSize &size, u_int8_t *&result)
Boolean parseEBMLVal_float(EBMLDataSize &size, float &result)
unsigned * fFrameSizesWithinBlock
Boolean parseEBMLVal_string(EBMLDataSize &size, char *&result)
Boolean parseStartOfFile()
Boolean parseTrack()
void getCommonFrameBytes(MatroskaTrack *track, u_int8_t *to, unsigned numBytesToGet, unsigned numBytesToSkip)
virtual void restoreSavedParserState()
void seekToTime(double &seekNPT)
void skipRemainingHeaderBytes(Boolean isContinuation)
FramedSource::onCloseFunc * fOnEndFunc
MatroskaDemux * fOurDemux
Boolean deliverFrameWithinBlock()
MatroskaFileParser(MatroskaFile &ourFile, FramedSource *inputSource, FramedSource::onCloseFunc *onEndFunc, void *onEndClientData, MatroskaDemux *ourDemux=NULL)
void seekToFilePosition(u_int64_t offsetInFile)
Boolean parseEBMLVal_unsigned(EBMLDataSize &size, unsigned &result)
static void continueParsing(void *clientData, unsigned char *ptr, unsigned size, struct timeval presentationTime)
Boolean parseEBMLNumber(EBMLNumber &num)
void resetPresentationTimes()
void resetStateAfterSeeking()
Boolean parseEBMLVal_unsigned64(EBMLDataSize &size, u_int64_t &result)