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-2026 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 const& size, u_int64_t& result);
82 Boolean parseEBMLVal_unsigned(EBMLDataSize const& size, unsigned& result);
83 Boolean parseEBMLVal_float(EBMLDataSize const& size, float& result);
84 Boolean parseEBMLVal_string(EBMLDataSize const& size, char*& result);
85 // Note: "result" is dynamically allocated; the caller must delete[] it later
86 Boolean parseEBMLVal_binary(EBMLDataSize const& size, u_int8_t*& result);
87 // Note: "result" is dynamically allocated; the caller must delete[] it later
88 Boolean parseEBMLVal_binary_constrainSize(EBMLDataSize const& size, u_int32_t& length, u_int8_t*& result);
89 // A version of "parseEBMLVal_binary()" where the result size is constrained to fit
90 // into a "u_int32_t".
91 // Note: "result" is dynamically allocated; the caller must delete[] it later
92 void skipHeader(EBMLDataSize const& size);
93 void skipRemainingHeaderBytes(Boolean isContinuation);
94
96
97 void seekToFilePosition(u_int64_t offsetInFile);
99 void resetStateAfterSeeking(); // common code, called by both of the above
100
102 // called after a seek or pause to ensure that presentation times continue to be
103 // aligned with 'wall clock' time
104
105private: // redefined virtual functions
107
108private:
109 // General state for parsing:
117
118 // For skipping over (possibly large) headers:
120
121 // For parsing 'Seek ID's:
123
124 // Parameters of the most recently-parsed 'Cluster':
126
127 // Parameters of the most recently-parsed 'Block':
128 unsigned fBlockSize;
133
134 // Parameters of the most recently-parsed frame within a 'Block':
137 unsigned fCurOffsetWithinFrame, fSavedCurOffsetWithinFrame; // used if track->haveSubframes()
138
139 // Parameters of the (sub)frame that's currently being delivered:
140 u_int8_t* fCurFrameTo;
143};
144
145#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)
Boolean parseEBMLVal_binary_constrainSize(EBMLDataSize const &size, u_int32_t &length, u_int8_t *&result)
FramedSource * fInputSource
void skipHeader(EBMLDataSize const &size)
MatroskaParseState fCurrentParseState
virtual ~MatroskaFileParser()
unsigned * fFrameSizesWithinBlock
Boolean parseStartOfFile()
Boolean parseTrack()
void getCommonFrameBytes(MatroskaTrack *track, u_int8_t *to, unsigned numBytesToGet, unsigned numBytesToSkip)
virtual void restoreSavedParserState()
void seekToTime(double &seekNPT)
Boolean parseEBMLVal_unsigned64(EBMLDataSize const &size, u_int64_t &result)
void skipRemainingHeaderBytes(Boolean isContinuation)
FramedSource::onCloseFunc * fOnEndFunc
MatroskaDemux * fOurDemux
Boolean deliverFrameWithinBlock()
Boolean parseEBMLVal_float(EBMLDataSize const &size, float &result)
MatroskaFileParser(MatroskaFile &ourFile, FramedSource *inputSource, FramedSource::onCloseFunc *onEndFunc, void *onEndClientData, MatroskaDemux *ourDemux=NULL)
void seekToFilePosition(u_int64_t offsetInFile)
Boolean parseEBMLVal_string(EBMLDataSize const &size, char *&result)
Boolean parseEBMLVal_binary(EBMLDataSize const &size, u_int8_t *&result)
Boolean parseEBMLVal_unsigned(EBMLDataSize const &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()