Compare commits

..

3 Commits

Author SHA1 Message Date
matthewjheaney
6c9f4d11a1 set version to 1.0.0.6
Change-Id: I259171d7bce7f670cb937707a9864aa0b9eb0d22
2010-11-05 15:21:28 -04:00
matthewjheaney
95c134ad53 ensure const correctness
Change-Id: Ia401d66519d1d663e9630ad1e70f18adec0f0bb5
2010-11-04 19:15:16 -04:00
matthewjheaney
7adec5248a added lacing support
Change-Id: I79ce0b6820f62846b05edbc8a0cb381aa2bc32a6
2010-11-02 11:44:31 -04:00
2 changed files with 356 additions and 116 deletions

View File

@@ -25,7 +25,7 @@ void mkvparser::GetVersion(int& major, int& minor, int& build, int& revision)
major = 1; major = 1;
minor = 0; minor = 0;
build = 0; build = 0;
revision = 5; revision = 6;
} }
@@ -707,6 +707,7 @@ long long EBMLHeader::Parse(
if ((total - pos) < len) if ((total - pos) < len)
return E_FILE_FORMAT_INVALID; return E_FILE_FORMAT_INVALID;
if ((available - pos) < len) if ((available - pos) < len)
return pos + len; //try again later return pos + len; //try again later
@@ -769,7 +770,6 @@ long long EBMLHeader::Parse(
} }
assert(pos == end); assert(pos == end);
return 0; return 0;
} }
@@ -1029,17 +1029,15 @@ long long Segment::ParseHeaders()
} }
#if 0 long Segment::ParseCluster(long long& off, long long& new_pos) const
long Segment::ParseCluster(Cluster*& pCluster, long long& pos_) const
{ {
pCluster = NULL; off = -1;
pos_ = -1; new_pos = -1;
const long long stop = m_start + m_size; const long long stop = m_start + m_size;
assert(m_pos <= stop); assert(m_pos <= stop);
long long pos = m_pos; long long pos = m_pos;
long long off = -1;
while (pos < stop) while (pos < stop)
{ {
@@ -1089,8 +1087,8 @@ long Segment::ParseCluster(Cluster*& pCluster, long long& pos_) const
if (off < 0) //we did not found any more clusters if (off < 0) //we did not found any more clusters
{ {
pos_ = stop; //pos_ >= 0 here means EOF (cluster is NULL) new_pos = stop; //pos >= 0 here means EOF (cluster is NULL)
return 0; //TODO: confirm this return value return 0; //TODO: confirm this return value
} }
//We found a cluster. Now read something, to ensure that it is //We found a cluster. Now read something, to ensure that it is
@@ -1122,7 +1120,7 @@ long Segment::ParseCluster(Cluster*& pCluster, long long& pos_) const
const int result = m_pReader->Read(pos - 1, 1, &b); const int result = m_pReader->Read(pos - 1, 1, &b);
assert(result == 0); assert(result == 0);
pos_ = stop; new_pos = stop;
} }
else else
{ {
@@ -1145,33 +1143,26 @@ long Segment::ParseCluster(Cluster*& pCluster, long long& pos_) const
if (size < 0) //error if (size < 0) //error
return static_cast<long>(size); return static_cast<long>(size);
pos_ = idpos; new_pos = idpos;
} }
//We found a cluster, and it has been completely loaded into the
//network cache. (We can guarantee this because we actually read
//the EBML tag that follows the cluster, or, if we reached EOF,
//because we actually read the last byte of the cluster).
Segment* const this_ = const_cast<Segment*>(this);
pCluster = Cluster::Parse(this_, m_clusterCount, off);
assert(pCluster);
assert(pCluster->m_index == m_clusterCount);
return 0; return 0;
} }
bool Segment::AddCluster(Cluster* pCluster, long long pos) bool Segment::AddCluster(long long off, long long pos)
{ {
assert(pos >= m_start); assert(pos >= m_start);
const long long stop = m_start + m_size; const long long stop = m_start + m_size;
assert(pos <= stop); assert(pos <= stop);
if (pCluster) if (off >= 0)
{ {
Cluster* const pCluster = Cluster::Parse(this, m_clusterCount, off);
assert(pCluster);
assert(pCluster->m_index == m_clusterCount);
AppendCluster(pCluster); AppendCluster(pCluster);
assert(m_clusters); assert(m_clusters);
assert(m_clusterSize > pCluster->m_index); assert(m_clusterSize > pCluster->m_index);
@@ -1182,7 +1173,6 @@ bool Segment::AddCluster(Cluster* pCluster, long long pos)
return (pos >= stop); return (pos >= stop);
} }
#endif
long Segment::LoadCluster() long Segment::LoadCluster()
@@ -2408,7 +2398,7 @@ long long Segment::Unparsed() const
} }
Cluster* Segment::GetFirst() const Cluster* Segment::GetFirst() const
{ {
if ((m_clusters == NULL) || (m_clusterCount <= 0)) if ((m_clusters == NULL) || (m_clusterCount <= 0))
return &m_eos; return &m_eos;
@@ -2420,7 +2410,7 @@ Cluster* Segment::GetFirst()
} }
Cluster* Segment::GetLast() const Cluster* Segment::GetLast() const
{ {
if ((m_clusters == NULL) || (m_clusterCount <= 0)) if ((m_clusters == NULL) || (m_clusterCount <= 0))
return &m_eos; return &m_eos;
@@ -2440,7 +2430,7 @@ unsigned long Segment::GetCount() const
} }
Cluster* Segment::GetNext(const Cluster* pCurr) const Cluster* Segment::GetNext(const Cluster* pCurr)
{ {
assert(pCurr); assert(pCurr);
assert(pCurr != &m_eos); assert(pCurr != &m_eos);
@@ -2596,7 +2586,7 @@ Cluster* Segment::GetNext(const Cluster* pCurr)
} }
Cluster* Segment::FindCluster(long long time_ns) const Cluster* Segment::FindCluster(long long time_ns) const
{ {
if ((m_clusters == NULL) || (m_clusterCount <= 0)) if ((m_clusters == NULL) || (m_clusterCount <= 0))
return &m_eos; return &m_eos;
@@ -2656,7 +2646,7 @@ Cluster* Segment::FindCluster(long long time_ns)
const BlockEntry* Segment::Seek( const BlockEntry* Segment::Seek(
long long time_ns, long long time_ns,
const Track* pTrack) const Track* pTrack) const
{ {
assert(pTrack); assert(pTrack);
@@ -3068,7 +3058,7 @@ bool Track::GetLacing() const
long Track::GetFirst(const BlockEntry*& pBlockEntry) const long Track::GetFirst(const BlockEntry*& pBlockEntry) const
{ {
Cluster* pCluster = m_pSegment->GetFirst(); const Cluster* pCluster = m_pSegment->GetFirst();
//If Segment::GetFirst returns NULL, then this must be a network //If Segment::GetFirst returns NULL, then this must be a network
//download, and we haven't loaded any clusters yet. In this case, //download, and we haven't loaded any clusters yet. In this case,
@@ -3129,7 +3119,7 @@ long Track::GetNext(
const Block* const pCurrBlock = pCurrEntry->GetBlock(); const Block* const pCurrBlock = pCurrEntry->GetBlock();
assert(pCurrBlock->GetTrackNumber() == m_info.number); assert(pCurrBlock->GetTrackNumber() == m_info.number);
Cluster* pCluster = pCurrEntry->GetCluster(); const Cluster* pCluster = pCurrEntry->GetCluster();
assert(pCluster); assert(pCluster);
assert(!pCluster->EOS()); assert(!pCluster->EOS());
@@ -3633,7 +3623,7 @@ Tracks::~Tracks()
} }
Track* Tracks::GetTrackByNumber(unsigned long tn_) const const Track* Tracks::GetTrackByNumber(unsigned long tn_) const
{ {
const long long tn = tn_; const long long tn = tn_;
@@ -3655,7 +3645,7 @@ Track* Tracks::GetTrackByNumber(unsigned long tn_) const
} }
Track* Tracks::GetTrackByIndex(unsigned long idx) const const Track* Tracks::GetTrackByIndex(unsigned long idx) const
{ {
const ptrdiff_t count = m_trackEntriesEnd - m_trackEntries; const ptrdiff_t count = m_trackEntriesEnd - m_trackEntries;
@@ -3666,7 +3656,7 @@ Track* Tracks::GetTrackByIndex(unsigned long idx) const
} }
void Cluster::Load() void Cluster::Load() const
{ {
assert(m_pSegment); assert(m_pSegment);
assert(m_pos); assert(m_pos);
@@ -3808,7 +3798,7 @@ bool Cluster::EOS() const
} }
void Cluster::LoadBlockEntries() void Cluster::LoadBlockEntries() const
{ {
if (m_entries) if (m_entries)
return; return;
@@ -3936,14 +3926,14 @@ void Cluster::LoadBlockEntries()
long long Cluster::GetTimeCode() long long Cluster::GetTimeCode() const
{ {
Load(); Load();
return m_timecode; return m_timecode;
} }
long long Cluster::GetTime() long long Cluster::GetTime() const
{ {
const long long tc = GetTimeCode(); const long long tc = GetTimeCode();
assert(tc >= 0); assert(tc >= 0);
@@ -3960,7 +3950,7 @@ long long Cluster::GetTime()
} }
long long Cluster::GetFirstTime() long long Cluster::GetFirstTime() const
{ {
const BlockEntry* const pEntry = GetFirst(); const BlockEntry* const pEntry = GetFirst();
@@ -3974,7 +3964,7 @@ long long Cluster::GetFirstTime()
} }
long long Cluster::GetLastTime() long long Cluster::GetLastTime() const
{ {
const BlockEntry* const pEntry = GetLast(); const BlockEntry* const pEntry = GetLast();
@@ -3988,40 +3978,40 @@ long long Cluster::GetLastTime()
} }
void Cluster::ParseBlockGroup(long long start, long long size, size_t index) void Cluster::ParseBlockGroup(long long st, long long sz, size_t idx) const
{ {
assert(m_entries); assert(m_entries);
assert(m_entriesCount); assert(m_entriesCount);
assert(index < m_entriesCount); assert(idx < m_entriesCount);
BlockGroup* const pGroup = Cluster* const this_ = const_cast<Cluster*>(this);
new (std::nothrow) BlockGroup(this, index, start, size);
assert(pGroup); //TODO
m_entries[index] = pGroup; BlockGroup* const e = new (std::nothrow) BlockGroup(this_, idx, st, sz);
assert(e); //TODO
m_entries[idx] = e;
} }
void Cluster::ParseSimpleBlock(long long start, long long size, size_t index) void Cluster::ParseSimpleBlock(long long st, long long sz, size_t idx) const
{ {
assert(m_entries); assert(m_entries);
assert(m_entriesCount); assert(m_entriesCount);
assert(index < m_entriesCount); assert(idx < m_entriesCount);
SimpleBlock* const pSimpleBlock = Cluster* const this_ = const_cast<Cluster*>(this);
new (std::nothrow) SimpleBlock(this, index, start, size);
assert(pSimpleBlock); //TODO
m_entries[index] = pSimpleBlock; SimpleBlock* const e = new (std::nothrow) SimpleBlock(this_, idx, st, sz);
assert(e); //TODO
m_entries[idx] = e;
} }
const BlockEntry* Cluster::GetFirst() const BlockEntry* Cluster::GetFirst() const
{ {
LoadBlockEntries(); LoadBlockEntries();
//assert(m_entries);
//assert(m_entriesCount >= 1);
if ((m_entries == NULL) || (m_entriesCount == 0)) if ((m_entries == NULL) || (m_entriesCount == 0))
return NULL; return NULL;
@@ -4033,11 +4023,9 @@ const BlockEntry* Cluster::GetFirst()
} }
const BlockEntry* Cluster::GetLast() const BlockEntry* Cluster::GetLast() const
{ {
LoadBlockEntries(); LoadBlockEntries();
//assert(m_entries);
//assert(m_entriesCount >= 1);
if ((m_entries == NULL) || (m_entriesCount == 0)) if ((m_entries == NULL) || (m_entriesCount == 0))
return NULL; return NULL;
@@ -4070,7 +4058,7 @@ const BlockEntry* Cluster::GetNext(const BlockEntry* pEntry) const
} }
const BlockEntry* Cluster::GetEntry(const Track* pTrack) const BlockEntry* Cluster::GetEntry(const Track* pTrack) const
{ {
assert(pTrack); assert(pTrack);
@@ -4110,7 +4098,7 @@ const BlockEntry* Cluster::GetEntry(const Track* pTrack)
const BlockEntry* const BlockEntry*
Cluster::GetEntry( Cluster::GetEntry(
const CuePoint& cp, const CuePoint& cp,
const CuePoint::TrackPosition& tp) const CuePoint::TrackPosition& tp) const
{ {
assert(m_pSegment); assert(m_pSegment);
@@ -4200,7 +4188,7 @@ Cluster::GetEntry(
} }
const BlockEntry* Cluster::GetMaxKey(const VideoTrack* pTrack) const BlockEntry* Cluster::GetMaxKey(const VideoTrack* pTrack) const
{ {
assert(pTrack); assert(pTrack);
@@ -4208,7 +4196,6 @@ const BlockEntry* Cluster::GetMaxKey(const VideoTrack* pTrack)
return pTrack->GetEOS(); return pTrack->GetEOS();
LoadBlockEntries(); LoadBlockEntries();
//assert(m_entries);
BlockEntry** i = m_entries + m_entriesCount; BlockEntry** i = m_entries + m_entriesCount;
BlockEntry** const j = m_entries; BlockEntry** const j = m_entries;
@@ -4262,7 +4249,7 @@ bool SimpleBlock::EOS() const
} }
Cluster* SimpleBlock::GetCluster() const const Cluster* SimpleBlock::GetCluster() const
{ {
return m_pCluster; return m_pCluster;
} }
@@ -4389,7 +4376,7 @@ bool BlockGroup::EOS() const
} }
Cluster* BlockGroup::GetCluster() const const Cluster* BlockGroup::GetCluster() const
{ {
return m_pCluster; return m_pCluster;
} }
@@ -4425,7 +4412,6 @@ short BlockGroup::GetNextTimeCode() const
//} //}
Block::Block(long long start, long long size_, IMkvReader* pReader) : Block::Block(long long start, long long size_, IMkvReader* pReader) :
m_start(start), m_start(start),
m_size(size_) m_size(size_)
@@ -4447,30 +4433,238 @@ Block::Block(long long start, long long size_, IMkvReader* pReader) :
pos += 2; pos += 2;
assert((stop - pos) >= 1); assert((stop - pos) >= 1);
const long hr = pReader->Read(pos, 1, &m_flags); long status = pReader->Read(pos, 1, &m_flags);
assert(hr == 0L); assert(status == 0);
const int invisible = int(m_flags & 0x08); const int invisible = int(m_flags & 0x08) >> 3;
invisible; invisible;
assert(!invisible); assert(!invisible); //TODO
const int lacing = int(m_flags & 0x06); const int lacing = int(m_flags & 0x06) >> 1;
lacing;
assert(!lacing);
++pos; ++pos; //consume flags byte
assert(pos <= stop); assert(pos <= stop);
m_frameOff = pos; if (lacing == 0) //no lacing
{
m_frame_count = 1;
m_frames = new Frame[m_frame_count];
const long long frame_size = stop - pos; Frame& f = m_frames[0];
assert(frame_size <= LONG_MAX); f.pos = pos;
m_frameSize = static_cast<long>(frame_size); const long long frame_size = stop - pos;
assert(frame_size <= LONG_MAX);
f.len = static_cast<long>(frame_size);
return;
}
assert(pos < stop);
unsigned char count;
status = pReader->Read(pos, 1, &count);
assert(status == 0);
++pos; //consume frame count
assert(pos <= stop);
m_frame_count = ++count;
m_frames = new Frame[m_frame_count];
if (lacing == 1) //Xiph
{
Frame* pf = m_frames;
Frame* const pf_end = pf + m_frame_count;
long size = 0;
while (count > 1)
{
long frame_size = 0;
for (;;)
{
unsigned char val;
status = pReader->Read(pos, 1, &val);
assert(status == 0);
++pos; //consume xiph size byte
frame_size += val;
if (val < 255)
break;
}
Frame& f = *pf++;
assert(pf < pf_end);
f.len = frame_size;
size += frame_size; //contribution of this frame
--count;
}
assert(pf < pf_end);
assert(pos < stop);
{
Frame& f = *pf++;
assert(pf == pf_end);
const long long total_size = stop - pos;
assert(total_size > size);
const long long frame_size = total_size - size;
assert(frame_size <= LONG_MAX);
f.len = static_cast<long>(frame_size);
}
pf = m_frames;
while (pf != pf_end)
{
Frame& f = *pf++;
assert((pos + f.len) <= stop);
f.pos = pos;
pos += f.len;
}
assert(pos == stop);
}
else if (lacing == 2) //fixed-size lacing
{
const long long total_size = stop - pos;
assert((total_size % m_frame_count) == 0);
const long long frame_size = total_size / m_frame_count;
assert(frame_size <= LONG_MAX);
Frame* pf = m_frames;
Frame* const pf_end = pf + m_frame_count;
while (pf != pf_end)
{
assert((pos + frame_size) <= stop);
Frame& f = *pf++;
f.pos = pos;
f.len = static_cast<long>(frame_size);
pos += frame_size;
}
assert(pos == stop);
}
else
{
assert(lacing == 3); //EBML lacing
assert(pos < stop);
long size = 0;
long long frame_size = ReadUInt(pReader, pos, len);
assert(frame_size > 0);
assert(frame_size <= LONG_MAX);
assert((pos + len) <= stop);
pos += len; //consume length of size of first frame
assert((pos + frame_size) <= stop);
Frame* pf = m_frames;
Frame* const pf_end = pf + m_frame_count;
{
Frame& curr = *pf;
curr.len = static_cast<long>(frame_size);
size += curr.len; //contribution of this frame
}
--count;
while (count > 1)
{
assert(pos < stop);
assert(pf < pf_end);
const Frame& prev = *pf++;
assert(pf < pf_end);
assert(prev.len == frame_size);
Frame& curr = *pf;
const long long delta_size_ = ReadUInt(pReader, pos, len);
assert(delta_size_ >= 0);
assert((pos + len) <= stop);
pos += len; //consume length of (delta) size
assert(pos <= stop);
const int exp = 7*len - 1;
const long long bias = (1LL << exp) - 1LL;
const long long delta_size = delta_size_ - bias;
frame_size += delta_size;
assert(frame_size > 0);
assert(frame_size <= LONG_MAX);
curr.len = static_cast<long>(frame_size);
size += curr.len; //contribution of this frame
--count;
}
{
assert(pos < stop);
assert(pf < pf_end);
const Frame& prev = *pf++;
assert(pf < pf_end);
assert(prev.len == frame_size);
Frame& curr = *pf++;
assert(pf == pf_end);
const long long total_size = stop - pos;
assert(total_size > 0);
assert(total_size > size);
frame_size = total_size - size;
assert(frame_size > 0);
assert(frame_size <= LONG_MAX);
curr.len = static_cast<long>(frame_size);
}
pf = m_frames;
while (pf != pf_end)
{
Frame& f = *pf++;
assert((pos + f.len) <= stop);
f.pos = pos;
pos += f.len;
}
assert(pos == stop);
}
} }
long long Block::GetTimeCode(Cluster* pCluster) const Block::~Block()
{
delete[] m_frames;
}
long long Block::GetTimeCode(const Cluster* pCluster) const
{ {
assert(pCluster); assert(pCluster);
@@ -4484,7 +4678,7 @@ long long Block::GetTimeCode(Cluster* pCluster) const
} }
long long Block::GetTime(Cluster* pCluster) const long long Block::GetTime(const Cluster* pCluster) const
{ {
assert(pCluster); assert(pCluster);
@@ -4524,6 +4718,7 @@ void Block::SetKey(bool bKey)
} }
#if 0
long long Block::GetOffset() const long long Block::GetOffset() const
{ {
return m_frameOff; return m_frameOff;
@@ -4535,10 +4730,8 @@ long Block::GetSize() const
return m_frameSize; return m_frameSize;
} }
long Block::Read(IMkvReader* pReader, unsigned char* buf) const long Block::Read(IMkvReader* pReader, unsigned char* buf) const
{ {
assert(pReader); assert(pReader);
assert(buf); assert(buf);
@@ -4546,6 +4739,35 @@ long Block::Read(IMkvReader* pReader, unsigned char* buf) const
return hr; return hr;
} }
#else
int Block::GetFrameCount() const
{
return m_frame_count;
}
const Block::Frame& Block::GetFrame(int idx) const
{
assert(idx >= 0);
assert(idx < m_frame_count);
const Frame& f = m_frames[idx];
assert(f.pos > 0);
assert(f.len > 0);
return f;
}
long Block::Frame::Read(IMkvReader* pReader, unsigned char* buf) const
{
assert(pReader);
assert(buf);
const long status = pReader->Read(pos, len, buf);
return status;
}
#endif
} //end namespace mkvparser } //end namespace mkvparser

View File

@@ -73,23 +73,44 @@ public:
const long long m_size; const long long m_size;
Block(long long start, long long size, IMkvReader*); Block(long long start, long long size, IMkvReader*);
~Block();
long long GetTrackNumber() const; long long GetTrackNumber() const;
long long GetTimeCode(Cluster*) const; //absolute, but not scaled long long GetTimeCode(const Cluster*) const; //absolute, but not scaled
long long GetTime(Cluster*) const; //absolute, and scaled (ns units) long long GetTime(const Cluster*) const; //absolute, and scaled (ns)
bool IsKey() const; bool IsKey() const;
void SetKey(bool); void SetKey(bool);
int GetFrameCount() const; //to index frames: [0, count)
struct Frame
{
long long pos; //absolute offset
long len;
long Read(IMkvReader*, unsigned char*) const;
};
#if 0
long long GetOffset() const; long long GetOffset() const;
long GetSize() const; long GetSize() const;
long Read(IMkvReader*, unsigned char*) const; long Read(IMkvReader*, unsigned char*) const;
#else
const Frame& GetFrame(int frame_index) const;
#endif
private: private:
long long m_track; //Track::Number() long long m_track; //Track::Number()
short m_timecode; //relative to cluster short m_timecode; //relative to cluster
unsigned char m_flags; unsigned char m_flags;
#if 0
long long m_frameOff; long long m_frameOff;
long m_frameSize; long m_frameSize;
#else
Frame* m_frames;
int m_frame_count;
#endif
}; };
@@ -102,7 +123,7 @@ class BlockEntry
public: public:
virtual ~BlockEntry(); virtual ~BlockEntry();
virtual bool EOS() const = 0; virtual bool EOS() const = 0;
virtual Cluster* GetCluster() const = 0; virtual const Cluster* GetCluster() const = 0;
virtual size_t GetIndex() const = 0; virtual size_t GetIndex() const = 0;
virtual const Block* GetBlock() const = 0; virtual const Block* GetBlock() const = 0;
//virtual bool IsBFrame() const = 0; //virtual bool IsBFrame() const = 0;
@@ -122,7 +143,7 @@ public:
SimpleBlock(Cluster*, size_t, long long start, long long size); SimpleBlock(Cluster*, size_t, long long start, long long size);
bool EOS() const; bool EOS() const;
Cluster* GetCluster() const; const Cluster* GetCluster() const;
size_t GetIndex() const; size_t GetIndex() const;
const Block* GetBlock() const; const Block* GetBlock() const;
//bool IsBFrame() const; //bool IsBFrame() const;
@@ -145,7 +166,7 @@ public:
~BlockGroup(); ~BlockGroup();
bool EOS() const; bool EOS() const;
Cluster* GetCluster() const; const Cluster* GetCluster() const;
size_t GetIndex() const; size_t GetIndex() const;
const Block* GetBlock() const; const Block* GetBlock() const;
//bool IsBFrame() const; //bool IsBFrame() const;
@@ -297,8 +318,8 @@ public:
Tracks(Segment*, long long start, long long size); Tracks(Segment*, long long start, long long size);
virtual ~Tracks(); virtual ~Tracks();
Track* GetTrackByNumber(unsigned long tn) const; const Track* GetTrackByNumber(unsigned long tn) const;
Track* GetTrackByIndex(unsigned long idx) const; const Track* GetTrackByIndex(unsigned long idx) const;
private: private:
Track** m_trackEntries; Track** m_trackEntries;
@@ -408,7 +429,6 @@ public:
const CuePoint* GetFirst() const; const CuePoint* GetFirst() const;
const CuePoint* GetLast() const; const CuePoint* GetLast() const;
const CuePoint* GetNext(const CuePoint*) const; const CuePoint* GetNext(const CuePoint*) const;
const BlockEntry* GetBlock( const BlockEntry* GetBlock(
@@ -444,19 +464,19 @@ public:
bool EOS() const; bool EOS() const;
long long GetTimeCode(); //absolute, but not scaled long long GetTimeCode() const; //absolute, but not scaled
long long GetTime(); //absolute, and scaled (nanosecond units) long long GetTime() const; //absolute, and scaled (nanosecond units)
long long GetFirstTime(); //time (ns) of first (earliest) block long long GetFirstTime() const; //time (ns) of first (earliest) block
long long GetLastTime(); //time (ns) of last (latest) block long long GetLastTime() const; //time (ns) of last (latest) block
const BlockEntry* GetFirst(); const BlockEntry* GetFirst() const;
const BlockEntry* GetLast(); const BlockEntry* GetLast() const;
const BlockEntry* GetNext(const BlockEntry*) const; const BlockEntry* GetNext(const BlockEntry*) const;
const BlockEntry* GetEntry(const Track*); const BlockEntry* GetEntry(const Track*) const;
const BlockEntry* GetEntry( const BlockEntry* GetEntry(
const CuePoint&, const CuePoint&,
const CuePoint::TrackPosition&); const CuePoint::TrackPosition&) const;
const BlockEntry* GetMaxKey(const VideoTrack*); const BlockEntry* GetMaxKey(const VideoTrack*) const;
protected: protected:
Cluster(Segment*, long, long long off); Cluster(Segment*, long, long long off);
@@ -464,18 +484,18 @@ protected:
public: public:
//TODO: these should all be private, with public selector functions //TODO: these should all be private, with public selector functions
long m_index; long m_index;
long long m_pos; mutable long long m_pos;
long long m_size; mutable long long m_size;
private: private:
long long m_timecode; mutable long long m_timecode;
BlockEntry** m_entries; mutable BlockEntry** m_entries;
size_t m_entriesCount; mutable size_t m_entriesCount;
void Load(); void Load() const;
void LoadBlockEntries(); void LoadBlockEntries() const;
void ParseBlockGroup(long long, long long, size_t); void ParseBlockGroup(long long, long long, size_t) const;
void ParseSimpleBlock(long long, long long, size_t); void ParseSimpleBlock(long long, long long, size_t) const;
}; };
@@ -506,12 +526,10 @@ public:
long long ParseHeaders(); //stops when first cluster is found long long ParseHeaders(); //stops when first cluster is found
long LoadCluster(); //loads one cluster long LoadCluster(); //loads one cluster
#if 0
//This pair parses one cluster, but only changes the state of the //This pair parses one cluster, but only changes the state of the
//segment object when the cluster is actually added to the index. //segment object when the cluster is actually added to the index.
long ParseCluster(Cluster*&, long long& newpos) const; long ParseCluster(long long& cluster_pos, long long& new_pos) const;
bool AddCluster(Cluster*, long long); bool AddCluster(long long cluster_pos, long long new_pos);
#endif
Tracks* GetTracks() const; Tracks* GetTracks() const;
const SegmentInfo* GetInfo() const; const SegmentInfo* GetInfo() const;
@@ -520,12 +538,12 @@ public:
long long GetDuration() const; long long GetDuration() const;
unsigned long GetCount() const; unsigned long GetCount() const;
Cluster* GetFirst(); const Cluster* GetFirst() const;
Cluster* GetLast(); const Cluster* GetLast() const;
Cluster* GetNext(const Cluster*); const Cluster* GetNext(const Cluster*);
Cluster* FindCluster(long long time_nanoseconds); const Cluster* FindCluster(long long time_nanoseconds) const;
const BlockEntry* Seek(long long time_nanoseconds, const Track*); const BlockEntry* Seek(long long time_nanoseconds, const Track*) const;
private: private: