live
OggFileParser.hh
Go to the documentation of this file.
1 /**********
2 This library is free software; you can redistribute it and/or modify it under
3 the terms of the GNU Lesser General Public License as published by the
4 Free Software Foundation; either version 3 of the License, or (at your
5 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6 
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10 more details.
11 
12 You should have received a copy of the GNU Lesser General Public License
13 along with this library; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 **********/
16 // "liveMedia"
17 // Copyright (c) 1996-2022 Live Networks, Inc. All rights reserved.
18 // A parser for an Ogg file
19 // C++ header
20 
21 #ifndef _OGG_FILE_PARSER_HH
22 
23 #ifndef _STREAM_PARSER_HH
24 #include "StreamParser.hh"
25 #endif
26 #ifndef _OGG_FILE_HH
27 #include "OggFile.hh"
28 #endif
29 
30 // An enum representing the current state of the parser:
35 };
36 
37 // A structure that counts the sizes of 'packets' given by each page's "segment_table":
39 public:
40  PacketSizeTable(unsigned number_page_segments);
42 
43  unsigned numCompletedPackets; // will be <= "number_page_segments"
44  unsigned* size; // an array of sizes of each of the packets
45  unsigned totSizes;
47  Boolean lastPacketIsIncomplete; // iff the last segment's 'lacing' was 255
48 };
49 
50 class OggFileParser: public StreamParser {
51 public:
52  OggFileParser(OggFile& ourFile, FramedSource* inputSource,
53  FramedSource::onCloseFunc* onEndFunc, void* onEndClientData,
54  OggDemux* ourDemux = NULL);
55  virtual ~OggFileParser();
56 
57  // StreamParser 'client continue' function:
58  static void continueParsing(void* clientData, unsigned char* ptr, unsigned size, struct timeval presentationTime);
60 
61 private:
63 
64  // Parsing functions:
65  Boolean parse(); // returns True iff we have finished parsing all BOS pages (on initialization)
66 
68  u_int8_t parseInitialPage(); // returns the 'header_type_flag' byte
72  void parseStartOfPage(u_int8_t& header_type_flag, u_int32_t& bitstream_serial_number);
73 
74  Boolean validateHeader(OggTrack* track, u_int8_t const* p, unsigned headerSize);
75 
76 private:
77  // General state for parsing:
84 
88  u_int8_t* fSavedPacket; // used to temporarily save a copy of a 'packet' from a page
89 };
90 
91 #endif
unsigned char Boolean
Definition: Boolean.hh:25
OggParseState
@ PARSING_START_OF_FILE
@ PARSING_AND_DELIVERING_PAGES
@ DELIVERING_PACKET_WITHIN_PAGE
#define NULL
void() onCloseFunc(void *clientData)
Definition: FramedSource.hh:40
FramedSource * fInputSource
OggFileParser(OggFile &ourFile, FramedSource *inputSource, FramedSource::onCloseFunc *onEndFunc, void *onEndClientData, OggDemux *ourDemux=NULL)
OggParseState fCurrentParseState
virtual ~OggFileParser()
void * fOnEndClientData
Boolean deliverPacketWithinPage()
OggDemux * fOurDemux
unsigned fNumUnfulfilledTracks
PacketSizeTable * fPacketSizeTable
Boolean needHeaders()
static void continueParsing(void *clientData, unsigned char *ptr, unsigned size, struct timeval presentationTime)
FramedSource::onCloseFunc * fOnEndFunc
u_int8_t parseInitialPage()
void parseAndDeliverPages()
Boolean parseAndDeliverPage()
void parseStartOfPage(u_int8_t &header_type_flag, u_int32_t &bitstream_serial_number)
Boolean parseStartOfFile()
OggFile & fOurFile
Boolean validateHeader(OggTrack *track, u_int8_t const *p, unsigned headerSize)
Boolean parse()
void continueParsing()
u_int8_t * fSavedPacket
u_int32_t fCurrentTrackNumber
unsigned * size
unsigned nextPacketNumToDeliver
unsigned numCompletedPackets
Boolean lastPacketIsIncomplete
PacketSizeTable(unsigned number_page_segments)