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-2024 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 void stopAnyDeliveryForTrack(unsigned trackNumber);
57
58 // StreamParser 'client continue' function:
59 static void continueParsing(void* clientData, unsigned char* ptr, unsigned size, struct timeval presentationTime);
61
62private:
63 // Parsing functions:
65 // returns True iff we have finished parsing to the end of all 'Track' headers (on initialization)
66
71
73 void parseBlock();
76
77 void getCommonFrameBytes(MatroskaTrack* track, u_int8_t* to, unsigned numBytesToGet, unsigned numBytesToSkip);
78
81 Boolean parseEBMLVal_unsigned64(EBMLDataSize& size, u_int64_t& result);
82 Boolean parseEBMLVal_unsigned(EBMLDataSize& size, unsigned& result);
85 // Note: "result" is dynamically allocated; the caller must delete[] it later
86 Boolean parseEBMLVal_binary(EBMLDataSize& size, u_int8_t*& result);
87 // Note: "result" is dynamically allocated; the caller must delete[] it later
88 void skipHeader(EBMLDataSize const& size);
89 void skipRemainingHeaderBytes(Boolean isContinuation);
90
92
93 void seekToFilePosition(u_int64_t offsetInFile);
95 void resetStateAfterSeeking(); // common code, called by both of the above
96
98 // called after a seek or pause to ensure that presentation times continue to be
99 // aligned with 'wall clock' time
100
101private: // redefined virtual functions
103
104private:
105 // General state for parsing:
113
114 // For skipping over (possibly large) headers:
116
117 // For parsing 'Seek ID's:
119
120 // Parameters of the most recently-parsed 'Cluster':
122
123 // Parameters of the most recently-parsed 'Block':
124 unsigned fBlockSize;
129
130 // Parameters of the most recently-parsed frame within a 'Block':
133 unsigned fCurOffsetWithinFrame, fSavedCurOffsetWithinFrame; // used if track->haveSubframes()
134
135 // Parameters of the (sub)frame that's currently being delivered:
136 u_int8_t* fCurFrameTo;
139};
140
141#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 stopAnyDeliveryForTrack(unsigned trackNumber)
void resetStateAfterSeeking()
Boolean parseEBMLVal_unsigned64(EBMLDataSize &size, u_int64_t &result)