2010-06-15 17:43:20 -04:00
|
|
|
// Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the LICENSE file in the root of the source
|
|
|
|
// tree. An additional intellectual property rights grant can be found
|
|
|
|
// in the file PATENTS. All contributing project authors may
|
|
|
|
// be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
|
|
|
#ifndef MKVPARSER_HPP
|
|
|
|
#define MKVPARSER_HPP
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
namespace mkvparser
|
|
|
|
{
|
|
|
|
|
|
|
|
const int E_FILE_FORMAT_INVALID = -2;
|
|
|
|
const int E_BUFFER_NOT_FULL = -3;
|
|
|
|
|
|
|
|
class IMkvReader
|
|
|
|
{
|
|
|
|
public:
|
2010-09-03 16:01:36 -04:00
|
|
|
virtual int Read(long long pos, long len, unsigned char* buf) = 0;
|
2010-06-15 17:47:45 -04:00
|
|
|
virtual int Length(long long* total, long long* available) = 0;
|
2010-06-15 17:43:20 -04:00
|
|
|
protected:
|
|
|
|
virtual ~IMkvReader();
|
|
|
|
};
|
|
|
|
|
|
|
|
long long GetUIntLength(IMkvReader*, long long, long&);
|
|
|
|
long long ReadUInt(IMkvReader*, long long, long&);
|
|
|
|
long long SyncReadUInt(IMkvReader*, long long pos, long long stop, long&);
|
|
|
|
long long UnserializeUInt(IMkvReader*, long long pos, long long size);
|
|
|
|
float Unserialize4Float(IMkvReader*, long long);
|
|
|
|
double Unserialize8Double(IMkvReader*, long long);
|
|
|
|
short Unserialize2SInt(IMkvReader*, long long);
|
|
|
|
signed char Unserialize1SInt(IMkvReader*, long long);
|
|
|
|
bool Match(IMkvReader*, long long&, unsigned long, long long&);
|
|
|
|
bool Match(IMkvReader*, long long&, unsigned long, char*&);
|
|
|
|
bool Match(IMkvReader*, long long&, unsigned long,unsigned char*&, size_t&);
|
|
|
|
bool Match(IMkvReader*, long long&, unsigned long, double&);
|
|
|
|
bool Match(IMkvReader*, long long&, unsigned long, short&);
|
|
|
|
|
2010-07-19 13:56:30 -04:00
|
|
|
void GetVersion(int& major, int& minor, int& build, int& revision);
|
2010-06-15 17:43:20 -04:00
|
|
|
|
|
|
|
struct EBMLHeader
|
|
|
|
{
|
|
|
|
EBMLHeader();
|
2010-06-15 17:47:45 -04:00
|
|
|
~EBMLHeader();
|
2010-06-15 17:43:20 -04:00
|
|
|
long long m_version;
|
|
|
|
long long m_readVersion;
|
|
|
|
long long m_maxIdLength;
|
|
|
|
long long m_maxSizeLength;
|
|
|
|
char* m_docType;
|
|
|
|
long long m_docTypeVersion;
|
|
|
|
long long m_docTypeReadVersion;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
long long Parse(IMkvReader*, long long&);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Segment;
|
|
|
|
class Track;
|
|
|
|
class Cluster;
|
|
|
|
|
|
|
|
class Block
|
|
|
|
{
|
|
|
|
Block(const Block&);
|
|
|
|
Block& operator=(const Block&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
const long long m_start;
|
|
|
|
const long long m_size;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
Block(long long start, long long size, IMkvReader*);
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-09-23 10:48:27 -04:00
|
|
|
long long GetTrackNumber() const;
|
2010-06-15 17:43:20 -04:00
|
|
|
long long GetTimeCode(Cluster*) const; //absolute, but not scaled
|
2010-09-03 16:01:36 -04:00
|
|
|
long long GetTime(Cluster*) const; //absolute, and scaled (ns units)
|
2010-06-15 17:43:20 -04:00
|
|
|
bool IsKey() const;
|
|
|
|
void SetKey(bool);
|
|
|
|
|
|
|
|
long GetSize() const;
|
|
|
|
long Read(IMkvReader*, unsigned char*) const;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
private:
|
|
|
|
long long m_track; //Track::Number()
|
|
|
|
short m_timecode; //relative to cluster
|
|
|
|
unsigned char m_flags;
|
|
|
|
long long m_frameOff;
|
2010-06-15 17:47:45 -04:00
|
|
|
long m_frameSize;
|
2010-06-15 17:43:20 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BlockEntry
|
|
|
|
{
|
|
|
|
BlockEntry(const BlockEntry&);
|
|
|
|
BlockEntry& operator=(const BlockEntry&);
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
public:
|
|
|
|
virtual ~BlockEntry();
|
|
|
|
virtual bool EOS() const = 0;
|
|
|
|
virtual Cluster* GetCluster() const = 0;
|
|
|
|
virtual size_t GetIndex() const = 0;
|
|
|
|
virtual const Block* GetBlock() const = 0;
|
|
|
|
virtual bool IsBFrame() const = 0;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
protected:
|
|
|
|
BlockEntry();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SimpleBlock : public BlockEntry
|
|
|
|
{
|
|
|
|
SimpleBlock(const SimpleBlock&);
|
|
|
|
SimpleBlock& operator=(const SimpleBlock&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
SimpleBlock(Cluster*, size_t, long long start, long long size);
|
|
|
|
|
|
|
|
bool EOS() const;
|
2010-06-15 17:47:45 -04:00
|
|
|
Cluster* GetCluster() const;
|
2010-06-15 17:43:20 -04:00
|
|
|
size_t GetIndex() const;
|
|
|
|
const Block* GetBlock() const;
|
|
|
|
bool IsBFrame() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Cluster* const m_pCluster;
|
|
|
|
const size_t m_index;
|
|
|
|
Block m_block;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BlockGroup : public BlockEntry
|
|
|
|
{
|
|
|
|
BlockGroup(const BlockGroup&);
|
|
|
|
BlockGroup& operator=(const BlockGroup&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
BlockGroup(Cluster*, size_t, long long, long long);
|
|
|
|
~BlockGroup();
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
bool EOS() const;
|
2010-06-15 17:47:45 -04:00
|
|
|
Cluster* GetCluster() const;
|
2010-06-15 17:43:20 -04:00
|
|
|
size_t GetIndex() const;
|
|
|
|
const Block* GetBlock() const;
|
|
|
|
bool IsBFrame() const;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
short GetPrevTimeCode() const; //relative to block's time
|
|
|
|
short GetNextTimeCode() const; //as above
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
protected:
|
|
|
|
Cluster* const m_pCluster;
|
|
|
|
const size_t m_index;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
private:
|
|
|
|
BlockGroup(Cluster*, size_t, unsigned long);
|
|
|
|
void ParseBlock(long long start, long long size);
|
|
|
|
|
|
|
|
short m_prevTimeCode;
|
|
|
|
short m_nextTimeCode;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
|
|
|
//TODO: the Matroska spec says you can have multiple blocks within the
|
2010-06-15 17:43:20 -04:00
|
|
|
//same block group, with blocks ranked by priority (the flag bits).
|
|
|
|
//For now we just cache a single block.
|
|
|
|
#if 0
|
|
|
|
typedef std::deque<Block*> blocks_t;
|
|
|
|
blocks_t m_blocks; //In practice should contain only a single element.
|
|
|
|
#else
|
|
|
|
Block* m_pBlock;
|
|
|
|
#endif
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Track
|
|
|
|
{
|
|
|
|
Track(const Track&);
|
|
|
|
Track& operator=(const Track&);
|
|
|
|
|
2010-06-15 17:47:45 -04:00
|
|
|
public:
|
2010-06-15 17:43:20 -04:00
|
|
|
Segment* const m_pSegment;
|
|
|
|
virtual ~Track();
|
2010-06-15 17:47:45 -04:00
|
|
|
|
|
|
|
long long GetType() const;
|
2010-09-23 10:48:27 -04:00
|
|
|
long long GetNumber() const;
|
2010-06-15 17:43:20 -04:00
|
|
|
const char* GetNameAsUTF8() const;
|
|
|
|
const char* GetCodecNameAsUTF8() const;
|
|
|
|
const char* GetCodecId() const;
|
|
|
|
const unsigned char* GetCodecPrivate(size_t&) const;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
const BlockEntry* GetEOS() const;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
|
|
|
struct Settings
|
2010-06-15 17:43:20 -04:00
|
|
|
{
|
|
|
|
long long start;
|
|
|
|
long long size;
|
|
|
|
};
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
struct Info
|
|
|
|
{
|
|
|
|
long long type;
|
|
|
|
long long number;
|
|
|
|
long long uid;
|
|
|
|
char* nameAsUTF8;
|
|
|
|
char* codecId;
|
|
|
|
unsigned char* codecPrivate;
|
|
|
|
size_t codecPrivateSize;
|
|
|
|
char* codecNameAsUTF8;
|
|
|
|
Settings settings;
|
|
|
|
Info();
|
|
|
|
void Clear();
|
|
|
|
};
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
long GetFirst(const BlockEntry*&) const;
|
|
|
|
long GetNext(const BlockEntry* pCurr, const BlockEntry*& pNext) const;
|
|
|
|
virtual bool VetEntry(const BlockEntry*) const = 0;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
protected:
|
2010-06-15 17:47:45 -04:00
|
|
|
Track(Segment*, const Info&);
|
2010-06-15 17:43:20 -04:00
|
|
|
const Info m_info;
|
|
|
|
|
|
|
|
class EOSBlock : public BlockEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EOSBlock();
|
|
|
|
|
2010-06-15 17:47:45 -04:00
|
|
|
bool EOS() const;
|
2010-06-15 17:43:20 -04:00
|
|
|
Cluster* GetCluster() const;
|
|
|
|
size_t GetIndex() const;
|
|
|
|
const Block* GetBlock() const;
|
|
|
|
bool IsBFrame() const;
|
|
|
|
};
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
EOSBlock m_eos;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class VideoTrack : public Track
|
|
|
|
{
|
|
|
|
VideoTrack(const VideoTrack&);
|
|
|
|
VideoTrack& operator=(const VideoTrack&);
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
public:
|
2010-06-15 17:47:45 -04:00
|
|
|
VideoTrack(Segment*, const Info&);
|
2010-06-15 17:43:20 -04:00
|
|
|
long long GetWidth() const;
|
|
|
|
long long GetHeight() const;
|
|
|
|
double GetFrameRate() const;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
bool VetEntry(const BlockEntry*) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
long long m_width;
|
|
|
|
long long m_height;
|
|
|
|
double m_rate;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class AudioTrack : public Track
|
|
|
|
{
|
|
|
|
AudioTrack(const AudioTrack&);
|
|
|
|
AudioTrack& operator=(const AudioTrack&);
|
|
|
|
|
|
|
|
public:
|
2010-06-15 17:47:45 -04:00
|
|
|
AudioTrack(Segment*, const Info&);
|
2010-06-15 17:43:20 -04:00
|
|
|
double GetSamplingRate() const;
|
|
|
|
long long GetChannels() const;
|
2010-06-15 17:47:45 -04:00
|
|
|
long long GetBitDepth() const;
|
2010-06-15 17:43:20 -04:00
|
|
|
bool VetEntry(const BlockEntry*) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
double m_rate;
|
|
|
|
long long m_channels;
|
|
|
|
long long m_bitDepth;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Tracks
|
|
|
|
{
|
|
|
|
Tracks(const Tracks&);
|
|
|
|
Tracks& operator=(const Tracks&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Segment* const m_pSegment;
|
|
|
|
const long long m_start;
|
|
|
|
const long long m_size;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
Tracks(Segment*, long long start, long long size);
|
|
|
|
virtual ~Tracks();
|
|
|
|
|
|
|
|
Track* GetTrackByNumber(unsigned long tn) const;
|
|
|
|
Track* GetTrackByIndex(unsigned long idx) const;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
private:
|
2010-06-15 17:47:45 -04:00
|
|
|
Track** m_trackEntries;
|
2010-06-15 17:43:20 -04:00
|
|
|
Track** m_trackEntriesEnd;
|
|
|
|
|
|
|
|
void ParseTrackEntry(long long, long long, Track*&);
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
public:
|
|
|
|
unsigned long GetTracksCount() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SegmentInfo
|
|
|
|
{
|
|
|
|
SegmentInfo(const SegmentInfo&);
|
|
|
|
SegmentInfo& operator=(const SegmentInfo&);
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
public:
|
|
|
|
Segment* const m_pSegment;
|
|
|
|
const long long m_start;
|
|
|
|
const long long m_size;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
SegmentInfo(Segment*, long long start, long long size);
|
|
|
|
~SegmentInfo();
|
|
|
|
long long GetTimeCodeScale() const;
|
|
|
|
long long GetDuration() const; //scaled
|
|
|
|
const char* GetMuxingAppAsUTF8() const;
|
|
|
|
const char* GetWritingAppAsUTF8() const;
|
|
|
|
const char* GetTitleAsUTF8() const;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
private:
|
|
|
|
long long m_timecodeScale;
|
|
|
|
double m_duration;
|
|
|
|
char* m_pMuxingAppAsUTF8;
|
|
|
|
char* m_pWritingAppAsUTF8;
|
|
|
|
char* m_pTitleAsUTF8;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-09-21 16:37:19 -04:00
|
|
|
class CuePoint
|
|
|
|
{
|
|
|
|
public:
|
2010-09-23 10:48:27 -04:00
|
|
|
CuePoint();
|
|
|
|
~CuePoint();
|
|
|
|
|
2010-09-21 16:37:19 -04:00
|
|
|
void Parse(IMkvReader*, long long start, long long size);
|
|
|
|
|
2010-09-23 13:04:39 -04:00
|
|
|
long long GetTimeCode() const; //absolute but unscaled
|
2010-09-21 16:37:19 -04:00
|
|
|
long long GetTime(Segment*) const; //absolute and scaled (ns units)
|
|
|
|
|
|
|
|
struct TrackPosition
|
|
|
|
{
|
|
|
|
long long m_track;
|
|
|
|
long long m_pos; //of cluster
|
|
|
|
long long m_block;
|
|
|
|
//codec_state //defaults to 0
|
|
|
|
//reference = clusters containing req'd referenced blocks
|
|
|
|
// reftime = timecode of the referenced block
|
|
|
|
|
2010-09-23 10:48:27 -04:00
|
|
|
void Parse(IMkvReader*, long long, long long);
|
2010-09-21 16:37:19 -04:00
|
|
|
};
|
|
|
|
|
2010-09-23 13:04:39 -04:00
|
|
|
const TrackPosition* Find(const Track*) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
long long m_timecode;
|
2010-09-23 10:48:27 -04:00
|
|
|
TrackPosition* m_track_positions;
|
|
|
|
size_t m_track_positions_count;
|
2010-09-21 16:37:19 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Cues
|
|
|
|
{
|
|
|
|
Cues(const Cues&);
|
|
|
|
Cues& operator=(const Cues&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Segment* const m_pSegment;
|
|
|
|
const long long m_start;
|
|
|
|
const long long m_size;
|
|
|
|
|
|
|
|
Cues(Segment*, long long start, long long size);
|
2010-09-23 10:48:27 -04:00
|
|
|
~Cues();
|
2010-09-21 16:37:19 -04:00
|
|
|
|
|
|
|
bool Find( //lower bound of time_ns
|
|
|
|
long long time_ns,
|
|
|
|
const Track*,
|
|
|
|
const CuePoint*&,
|
|
|
|
const CuePoint::TrackPosition*&) const;
|
|
|
|
|
|
|
|
bool FindNext( //upper_bound of time_ns
|
|
|
|
long long time_ns,
|
|
|
|
const Track*,
|
|
|
|
const CuePoint*&,
|
|
|
|
const CuePoint::TrackPosition*&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CuePoint* m_cue_points;
|
2010-09-23 10:48:27 -04:00
|
|
|
size_t m_cue_points_count;
|
2010-09-21 16:37:19 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
class Cluster
|
|
|
|
{
|
|
|
|
Cluster(const Cluster&);
|
|
|
|
Cluster& operator=(const Cluster&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Segment* const m_pSegment;
|
|
|
|
const size_t m_index;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
|
|
|
public:
|
2010-06-15 17:43:20 -04:00
|
|
|
static Cluster* Parse(Segment*, size_t, long long off);
|
|
|
|
|
|
|
|
Cluster(); //EndOfStream
|
|
|
|
~Cluster();
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
bool EOS() const;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-09-03 16:01:36 -04:00
|
|
|
long long GetTimeCode(); //absolute, but not scaled
|
|
|
|
long long GetTime(); //absolute, and scaled (nanosecond units)
|
|
|
|
long long GetFirstTime(); //time (ns) of first (earliest) block
|
2010-06-15 17:43:20 -04:00
|
|
|
|
|
|
|
const BlockEntry* GetFirst();
|
|
|
|
const BlockEntry* GetLast();
|
2010-06-15 17:47:45 -04:00
|
|
|
const BlockEntry* GetNext(const BlockEntry*) const;
|
2010-06-15 17:43:20 -04:00
|
|
|
const BlockEntry* GetEntry(const Track*);
|
2010-09-23 10:48:27 -04:00
|
|
|
const BlockEntry* GetEntry(
|
|
|
|
const CuePoint&,
|
|
|
|
const CuePoint::TrackPosition&);
|
2010-09-16 15:54:40 -04:00
|
|
|
const BlockEntry* GetMaxKey(const VideoTrack*);
|
|
|
|
|
2010-06-15 17:47:45 -04:00
|
|
|
protected:
|
2010-06-15 17:43:20 -04:00
|
|
|
Cluster(Segment*, size_t, long long off);
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-09-23 10:48:27 -04:00
|
|
|
public:
|
|
|
|
long long m_pos;
|
2010-06-15 17:47:45 -04:00
|
|
|
long long m_size;
|
2010-09-23 10:48:27 -04:00
|
|
|
|
|
|
|
private:
|
2010-06-15 17:43:20 -04:00
|
|
|
long long m_timecode;
|
|
|
|
BlockEntry** m_pEntries;
|
|
|
|
size_t m_entriesCount;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
void Load();
|
|
|
|
void LoadBlockEntries();
|
|
|
|
void ParseBlockGroup(long long, long long, size_t);
|
|
|
|
void ParseSimpleBlock(long long, long long, size_t);
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Segment
|
|
|
|
{
|
|
|
|
Segment(const Segment&);
|
|
|
|
Segment& operator=(const Segment&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Segment(IMkvReader*, long long pos, long long size);
|
|
|
|
|
|
|
|
public:
|
|
|
|
IMkvReader* const m_pReader;
|
|
|
|
const long long m_start; //posn of segment payload
|
|
|
|
const long long m_size; //size of segment payload
|
|
|
|
Cluster m_eos; //TODO: make private?
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
static long long CreateInstance(IMkvReader*, long long, Segment*&);
|
|
|
|
~Segment();
|
|
|
|
|
|
|
|
//for big-bang loading (source filter)
|
|
|
|
long Load();
|
|
|
|
|
2010-06-15 17:47:45 -04:00
|
|
|
//for incremental loading (splitter)
|
2010-06-15 17:43:20 -04:00
|
|
|
long long Unparsed() const;
|
|
|
|
long long ParseHeaders();
|
|
|
|
long ParseCluster(Cluster*&, long long& newpos) const;
|
|
|
|
bool AddCluster(Cluster*, long long);
|
|
|
|
|
2010-06-15 17:47:45 -04:00
|
|
|
Tracks* GetTracks() const;
|
2010-09-23 12:02:55 -04:00
|
|
|
const SegmentInfo* GetInfo() const;
|
2010-06-15 17:43:20 -04:00
|
|
|
long long GetDuration() const;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
//NOTE: this turned out to be too inefficient.
|
|
|
|
//long long Load(long long time_nanoseconds);
|
|
|
|
|
|
|
|
Cluster* GetFirst();
|
|
|
|
Cluster* GetLast();
|
|
|
|
unsigned long GetCount() const;
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
Cluster* GetNext(const Cluster*);
|
|
|
|
Cluster* GetCluster(long long time_nanoseconds);
|
2010-06-15 17:47:45 -04:00
|
|
|
|
2010-09-16 15:54:40 -04:00
|
|
|
void GetCluster(
|
2010-09-21 11:40:21 -04:00
|
|
|
long long time_nanoseconds,
|
2010-09-16 15:54:40 -04:00
|
|
|
Track*,
|
|
|
|
Cluster*&,
|
|
|
|
const BlockEntry*&);
|
|
|
|
|
2010-09-21 16:37:19 -04:00
|
|
|
const Cues* GetCues() const;
|
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
private:
|
2010-06-15 17:47:45 -04:00
|
|
|
long long m_pos; //absolute file posn; what has been consumed so far
|
2010-06-15 17:43:20 -04:00
|
|
|
SegmentInfo* m_pInfo;
|
2010-06-15 17:47:45 -04:00
|
|
|
Tracks* m_pTracks;
|
2010-09-21 16:37:19 -04:00
|
|
|
Cues* m_pCues;
|
2010-06-15 17:43:20 -04:00
|
|
|
Cluster** m_clusters;
|
2010-09-21 16:37:19 -04:00
|
|
|
size_t m_clusterCount; //number of entries
|
|
|
|
size_t m_clusterSize; //array size
|
2010-06-15 17:43:20 -04:00
|
|
|
|
2010-09-22 12:47:24 -04:00
|
|
|
void AppendCluster(Cluster*);
|
|
|
|
|
|
|
|
//void ParseSeekHead(long long pos, long long size, size_t*);
|
|
|
|
//void ParseSeekEntry(long long pos, long long size, size_t*);
|
|
|
|
//void ParseSecondarySeekHead(long long off, size_t*);
|
2010-09-21 16:37:19 -04:00
|
|
|
void ParseCues(long long off);
|
|
|
|
|
|
|
|
bool SearchCues(
|
|
|
|
long long time_ns,
|
|
|
|
Track*,
|
|
|
|
Cluster*&,
|
|
|
|
const BlockEntry*&);
|
|
|
|
|
2010-06-15 17:43:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} //end namespace mkvparser
|
|
|
|
|
|
|
|
#endif //MKVPARSER_HPP
|