Compare commits

..

11 Commits

Author SHA1 Message Date
matthewjheaney
093b78faf2 set version to 1.0.0.5
Change-Id: I3643a0019110b1ff7359a8d414bf0cd2ba9b5d54
2010-10-29 14:31:47 -04:00
matthewjheaney
ed90de0d52 check lacing bits
Change-Id: Iaa3a65429b7f3211868a86bbb83ce8018350554a
2010-10-29 14:04:43 -04:00
matthewjheaney
a01e568293 removed IsBFrame selector
Change-Id: Iae51165c318997a9131e9af5c667cfac1f37e773
2010-10-28 17:28:59 -04:00
matthewjheaney
d7ce23a019 handle empty clusters when seeking
Change-Id: I9bb39ff95e308639402e1c7f9aec59c81350d091
2010-10-28 14:45:27 -04:00
matthewjheaney
acf7ddb273 handle empty clusters
Change-Id: I57b085367e1b900acb0ddd6ee419e317f261718a
2010-10-27 16:47:14 -04:00
matthewjheaney
fc12207e15 handle case when no duration
Change-Id: I694f6ce6ae9ecc6fc3b90b954dd7041e82fb9ac0
2010-10-22 13:46:39 -04:00
matthewjheaney
c2f6bea0d8 changed version to 1.0.0.4
Change-Id: I8580a5de258d74b6a83505046d014ad9c6abfc23
2010-10-14 19:34:37 -04:00
matthewjheaney
16934eb76f separate cue-based searches
Change-Id: I5d98be1c9c5bc33b4ef216f48de22220f38c0f36
2010-10-13 13:44:13 -04:00
matthewjheaney
9c15c0f40b Segment::GetCluster returns CuePoint too
Change-Id: Id1b865a9efdcee6b6ef68d4fb323da50f1942f2a
2010-10-12 15:29:28 -04:00
matthewjheaney
43f77d54bd defend against badly-formatted cue points
Change-Id: I72bab89f0828b2c5275a4c4b3ac22ee61a173ddf
2010-10-11 19:09:27 -04:00
matthewjheaney
aec650fed7 made Cues member variables mutable
Change-Id: I405b845f37c9deaffd67e50752fb9b2aa7124484
2010-10-11 12:59:17 -04:00
2 changed files with 358 additions and 280 deletions

View File

@@ -10,6 +10,7 @@
#include <cassert>
#include <cstring>
#include <new>
#include <climits>
//#include <windows.h>
//#include "odbgstream.hpp"
//using std::endl;
@@ -24,7 +25,7 @@ void mkvparser::GetVersion(int& major, int& minor, int& build, int& revision)
major = 1;
minor = 0;
build = 0;
revision = 3;
revision = 5;
}
@@ -1740,7 +1741,7 @@ Cues::~Cues()
}
void Cues::Init()
void Cues::Init() const
{
if (m_cue_points)
return;
@@ -1780,14 +1781,12 @@ void Cues::Init()
pos += size; //consume payload
assert(pos <= stop);
}
LoadCuePoint();
}
void Cues::PreloadCuePoint(
size_t& cue_points_size,
long long pos)
long long pos) const
{
assert(m_count == 0);
@@ -1832,42 +1831,12 @@ void Cues::PreloadCuePoint(
cue_points_size = n;
}
CuePoint* const pCP = new CuePoint(pos);
CuePoint* const pCP = new CuePoint(m_preload_count, pos);
m_cue_points[m_preload_count++] = pCP;
}
#if 0
const CuePoint* Cues::GetFirst() const
{
if (m_count < 1)
return NULL;
CuePoint* const pCP = m_cue_points[0];
assert(pCP);
assert(pCP->GetTimeCode() >= 0);
return pCP;
}
const CuePoint* Cues::GetLast() const
{
if (m_count < 1)
return NULL;
const size_t idx = m_count - 1;
CuePoint* const pCP = m_cue_points[idx];
assert(pCP);
assert(pCP->GetTimeCode() >= 0);
return pCP;
}
#endif
bool Cues::LoadCuePoint()
bool Cues::LoadCuePoint() const
{
//odbgstream os;
//os << "Cues::LoadCuePoint" << endl;
@@ -1912,8 +1881,9 @@ bool Cues::LoadCuePoint()
CuePoint* const pCP = m_cue_points[m_count];
assert(pCP);
assert((pCP->GetTimeCode() >= 0) || (-pCP->GetTimeCode() == idpos));
pCP->Load(pReader, idpos);
pCP->Load(pReader);
++m_count;
--m_preload_count;
@@ -1936,7 +1906,7 @@ bool Cues::Find(
assert(time_ns >= 0);
assert(pTrack);
const_cast<Cues*>(this)->LoadCuePoint();
LoadCuePoint();
assert(m_cue_points);
assert(m_count > 0);
@@ -1971,7 +1941,7 @@ bool Cues::Find(
CuePoint* const pCP = *k;
assert(pCP);
pCP->Load(pReader, 0);
pCP->Load(pReader);
const long long t = pCP->GetTime(m_pSegment);
@@ -2064,93 +2034,151 @@ bool Cues::FindNext(
#endif
#if 0
const CuePoint* Cues::LoadCuePoint(
long long time_ns,
const Track* pTrack,
const CuePoint::TrackPosition*& pTP) const
const CuePoint* Cues::GetFirst() const
{
assert(time_ns >= 0);
assert(pTrack);
LoadCuePoint(); //init cues
//odbgstream os;
//os << "Cues::LoadCuePoint: time[sec]="
// << (double(time_ns) / 1000000000)
// << " count=" << m_count
// << " preload_count=" << m_preload_count
// << endl;
const size_t count = m_count + m_preload_count;
if (m_count > 0)
{
const CuePoint* pCP = GetLast();
assert(pCP);
if (count == 0) //weird
return NULL;
const long long ns = pCP->GetTime(m_pSegment);
CuePoint* const* const pp = m_cue_points;
assert(pp);
if ((ns >= time_ns) || (m_preload_count == 0))
{
const bool bFound = Find(time_ns, pTrack, pCP, pTP);
assert(bFound); //TODO
assert(pCP);
assert(pTP);
CuePoint* const pCP = pp[0];
assert(pCP);
assert(pCP->GetTimeCode() >= 0);
return pCP;
}
}
return pCP;
}
assert(m_preload_count > 0);
const CuePoint* Cues::GetLast() const
{
LoadCuePoint(); //init cues
const size_t count = m_count + m_preload_count;
if (count == 0) //weird
return NULL;
const size_t index = count - 1;
CuePoint* const* const pp = m_cue_points;
assert(pp);
CuePoint* const pCP = pp[index];
assert(pCP);
pCP->Load(m_pSegment->m_pReader);
assert(pCP->GetTimeCode() >= 0);
return pCP;
}
const CuePoint* Cues::GetNext(const CuePoint* pCurr) const
{
if (pCurr == NULL)
return NULL;
assert(pCurr->GetTimeCode() >= 0);
assert(m_cue_points);
assert(m_count >= 1);
IMkvReader* const pReader = m_pSegment->m_pReader;
const size_t count = m_count + m_preload_count;
CuePoint** const ii = m_cue_points + m_count;
CuePoint** i = ii;
size_t index = pCurr->m_index;
assert(index < count);
CuePoint** const jj = ii + m_preload_count;
CuePoint** j = jj;
CuePoint* const* const pp = m_cue_points;
assert(pp);
assert(pp[index] == pCurr);
++index;
if (index >= count)
return NULL;
CuePoint* const pNext = pp[index];
assert(pNext);
pNext->Load(m_pSegment->m_pReader);
return pNext;
}
const BlockEntry* Cues::GetBlock(
const CuePoint* pCP,
const CuePoint::TrackPosition* pTP) const
{
if (pCP == NULL)
return NULL;
if (pTP == NULL)
return NULL;
return m_pSegment->GetBlock(*pCP, *pTP);
}
const BlockEntry* Segment::GetBlock(
const CuePoint& cp,
const CuePoint::TrackPosition& tp)
{
Cluster** const ii = m_clusters;
Cluster** i = ii;
const long count = m_clusterCount + m_clusterPreloadCount;
Cluster** const jj = ii + count;
Cluster** j = jj;
while (i < j)
{
//INVARIANT:
//[ii, i) <= time_ns
//[i, j) ?
//[j, jj) > time_ns
//[ii, i) < pTP->m_pos
//[i, j) ?
//[j, jj) > pTP->m_pos
CuePoint** const k = i + (j - i) / 2;
Cluster** const k = i + (j - i) / 2;
assert(k < jj);
CuePoint* const pCP = *k;
assert(pCP);
Cluster* const pCluster = *k;
assert(pCluster);
pCP->Load(pReader, 0);
const long long pos_ = pCluster->m_pos;
assert(pos_);
const long long t = pCP->GetTime(m_pSegment);
const long long pos = pos_ * ((pos_ < 0) ? -1 : 1);
if (t <= time_ns)
if (pos < tp.m_pos)
i = k + 1;
else
else if (pos > tp.m_pos)
j = k;
assert(i <= j);
else
return pCluster->GetEntry(cp, tp);
}
assert(i == j);
assert(i <= jj);
assert(i > m_cue_points);
const CuePoint* const pCP = *--i;
assert(pCP);
assert(pCP->GetTime(m_pSegment) <= time_ns);
Cluster* const pCluster = Cluster::Parse(this, -1, tp.m_pos);
const ptrdiff_t idx = i - m_clusters;
pTP = pCP->Find(pTrack);
assert(pTP); //TODO
PreloadCluster(pCluster, idx);
assert(m_clusters);
assert(m_clusterPreloadCount > 0);
assert(m_clusters[idx] == pCluster);
return pCP;
return pCluster->GetEntry(cp, tp);
}
#endif
CuePoint::CuePoint(long long pos) :
CuePoint::CuePoint(size_t idx, long long pos) :
m_index(idx),
m_timecode(-1 * pos),
m_track_positions(NULL),
m_track_positions_count(0)
@@ -2165,7 +2193,7 @@ CuePoint::~CuePoint()
}
void CuePoint::Load(IMkvReader* pReader, long long idpos)
void CuePoint::Load(IMkvReader* pReader)
{
//odbgstream os;
//os << "CuePoint::Load(begin): timecode=" << m_timecode << endl;
@@ -2176,8 +2204,7 @@ void CuePoint::Load(IMkvReader* pReader, long long idpos)
assert(m_track_positions == NULL);
assert(m_track_positions_count == 0);
long long pos_ = -1 * m_timecode;
assert((idpos <= 0) || (idpos == pos_));
long long pos_ = -m_timecode;
long long stop;
@@ -2321,8 +2348,8 @@ void CuePoint::TrackPosition::Parse(
assert(pos <= stop);
}
assert(m_track > 0);
assert(m_pos >= 0);
assert(m_track > 0);
assert(m_block > 0);
}
@@ -2569,7 +2596,7 @@ Cluster* Segment::GetNext(const Cluster* pCurr)
}
Cluster* Segment::GetCluster(long long time_ns)
Cluster* Segment::FindCluster(long long time_ns)
{
if ((m_clusters == NULL) || (m_clusterCount <= 0))
return &m_eos;
@@ -2627,39 +2654,26 @@ Cluster* Segment::GetCluster(long long time_ns)
}
void Segment::GetCluster(
const BlockEntry* Segment::Seek(
long long time_ns,
Track* pTrack,
Cluster*& pCluster,
const BlockEntry*& pBlockEntry)
const Track* pTrack)
{
assert(pTrack);
if (SearchCues(time_ns, pTrack, pCluster, pBlockEntry))
return;
if ((m_clusters == NULL) || (m_clusterCount <= 0))
{
pCluster = &m_eos;
pBlockEntry = pTrack->GetEOS();
return;
}
return pTrack->GetEOS();
Cluster** const i = m_clusters;
assert(i);
{
pCluster = *i;
Cluster* const pCluster = *i;
assert(pCluster);
assert(pCluster->m_index == 0);
assert(pCluster->m_index == 0); //m_clusterCount > 0
assert(pCluster->m_pSegment == this);
if (time_ns <= pCluster->GetTime())
{
pBlockEntry = pCluster->GetEntry(pTrack);
return;
}
return pCluster->GetEntry(pTrack);
}
Cluster** const j = i + m_clusterCount;
@@ -2703,12 +2717,21 @@ void Segment::GetCluster(
assert(lo > i);
assert(lo <= j);
pCluster = *--lo;
assert(pCluster);
assert(pCluster->GetTime() <= time_ns);
while (lo > i)
{
Cluster* const pCluster = *--lo;
assert(pCluster);
assert(pCluster->GetTime() <= time_ns);
pBlockEntry = pCluster->GetEntry(pTrack);
return;
const BlockEntry* const pBE = pCluster->GetEntry(pTrack);
if ((pBE != 0) && !pBE->EOS())
return pBE;
//landed on empty cluster (no entries)
}
return pTrack->GetEOS(); //weird
}
assert(pTrack->GetType() == 1); //video
@@ -2743,31 +2766,30 @@ void Segment::GetCluster(
assert(lo > i);
assert(lo <= j);
pCluster = *--lo;
Cluster* pCluster = *--lo;
assert(pCluster);
assert(pCluster->GetTime() <= time_ns);
{
pBlockEntry = pCluster->GetEntry(pTrack);
assert(pBlockEntry);
const BlockEntry* const pBlockEntry = pCluster->GetEntry(pTrack);
if (!pBlockEntry->EOS()) //found a keyframe
if ((pBlockEntry != 0) && !pBlockEntry->EOS()) //found a keyframe
{
const Block* const pBlock = pBlockEntry->GetBlock();
assert(pBlock);
//TODO: this isn't necessarily the keyframe we want,
//NOTE: this isn't necessarily the keyframe we want,
//since there might another keyframe on this same
//cluster with a greater timecode that but that is
//still less than the requested time. For now we
//cluster with a greater timecode, that is still
//less than the requested time. For now we
//simply return the first keyframe we find.
if (pBlock->GetTime(pCluster) <= time_ns)
return;
return pBlockEntry;
}
}
const VideoTrack* const pVideo = static_cast<VideoTrack*>(pTrack);
const VideoTrack* const pVideo = static_cast<const VideoTrack*>(pTrack);
while (lo != i)
{
@@ -2775,26 +2797,27 @@ void Segment::GetCluster(
assert(pCluster);
assert(pCluster->GetTime() <= time_ns);
pBlockEntry = pCluster->GetMaxKey(pVideo);
assert(pBlockEntry);
const BlockEntry* const pBlockEntry = pCluster->GetMaxKey(pVideo);
if (!pBlockEntry->EOS())
return;
if ((pBlockEntry != 0) && !pBlockEntry->EOS())
return pBlockEntry;
}
//weird: we're on the first cluster, but no keyframe found
//should never happen but we must return something anyway
pCluster = &m_eos;
pBlockEntry = pTrack->GetEOS();
return pTrack->GetEOS();
}
#if 0
bool Segment::SearchCues(
long long time_ns,
Track* pTrack,
Cluster*& pCluster,
const BlockEntry*& pBlockEntry)
const BlockEntry*& pBlockEntry,
const CuePoint*& pCP,
const CuePoint::TrackPosition*& pTP)
{
if (pTrack->GetType() != 1) //not video
return false; //TODO: for now, just handle video stream
@@ -2802,9 +2825,6 @@ bool Segment::SearchCues(
if (m_pCues == NULL)
return false;
const CuePoint* pCP;
const CuePoint::TrackPosition* pTP;
if (!m_pCues->Find(time_ns, pTrack, pCP, pTP))
return false; //weird
@@ -2816,60 +2836,9 @@ bool Segment::SearchCues(
//so we now need to search for the cluster having
//the indicated position.
Cluster** const ii = m_clusters;
Cluster** i = ii;
const long count = m_clusterCount + m_clusterPreloadCount;
Cluster** const jj = ii + count;
Cluster** j = jj;
while (i < j)
{
//INVARIANT:
//[ii, i) < pTP->m_pos
//[i, j) ?
//[j, jj) > pTP->m_pos
Cluster** const k = i + (j - i) / 2;
assert(k < jj);
pCluster = *k;
assert(pCluster);
const long long pos_ = pCluster->m_pos;
assert(pos_);
const long long pos = pos_ * ((pos_ < 0) ? -1 : 1);
if (pos < pTP->m_pos)
i = k + 1;
else if (pos > pTP->m_pos)
j = k;
else
{
pBlockEntry = pCluster->GetEntry(*pCP, *pTP);
assert(pBlockEntry);
return true;
}
}
assert(i == j);
pCluster = Cluster::Parse(this, -1, pTP->m_pos);
const ptrdiff_t idx = i - m_clusters;
PreloadCluster(pCluster, idx);
assert(m_clusters);
assert(m_clusterPreloadCount > 0);
assert(m_clusters[idx] == pCluster);
pBlockEntry = pCluster->GetEntry(*pCP, *pTP);
assert(pBlockEntry);
return true;
return GetCluster(pCP, pTP, pCluster, pBlockEntry);
}
#endif
Tracks* Segment::GetTracks() const
@@ -2884,7 +2853,7 @@ const SegmentInfo* Segment::GetInfo() const
}
Cues* Segment::GetCues() const
const Cues* Segment::GetCues() const
{
return m_pCues;
}
@@ -2911,7 +2880,7 @@ SegmentInfo::SegmentInfo(Segment* pSegment, long long start, long long size_) :
const long long stop = start + size_;
m_timecodeScale = 1000000;
m_duration = 0;
m_duration = -1;
while (pos < stop)
{
@@ -2927,8 +2896,9 @@ SegmentInfo::SegmentInfo(Segment* pSegment, long long start, long long size_) :
else if (Match(pReader, pos, 0x1741, m_pWritingAppAsUTF8)) //[57][41]
assert(m_pWritingAppAsUTF8);
else if (Match(pReader, pos, 0x3BA9, m_pTitleAsUTF8)) //[7B][A9]
else if (Match(pReader, pos, 0x3BA9, m_pTitleAsUTF8)) //[7B][A9]
assert(m_pTitleAsUTF8);
else
{
long len;
@@ -2982,7 +2952,9 @@ long long SegmentInfo::GetTimeCodeScale() const
long long SegmentInfo::GetDuration() const
{
assert(m_duration >= 0);
if (m_duration < 0)
return -1;
assert(m_timecodeScale >= 1);
const double dd = double(m_duration) * double(m_timecodeScale);
@@ -3028,6 +3000,7 @@ Track::Info::Info():
codecPrivate(NULL),
codecPrivateSize(0),
codecNameAsUTF8(NULL)
//lacing(false)
{
}
@@ -3087,6 +3060,12 @@ const unsigned char* Track::GetCodecPrivate(size_t& size) const
}
bool Track::GetLacing() const
{
return m_info.lacing;
}
long Track::GetFirst(const BlockEntry*& pBlockEntry) const
{
Cluster* pCluster = m_pSegment->GetFirst();
@@ -3490,7 +3469,13 @@ Tracks::Tracks(Segment* pSegment, long long start, long long size_) :
//pos now desinates start of element
if (id == 0x2E) //TrackEntry ID
ParseTrackEntry(pos, size1, *m_trackEntriesEnd++);
{
Track*& pTrack = *m_trackEntriesEnd;
ParseTrackEntry(pos, size1, pTrack);
if (pTrack)
++m_trackEntriesEnd;
}
pos += size1; //consume payload
assert(pos <= stop);
@@ -3525,6 +3510,8 @@ void Tracks::ParseTrackEntry(
Track::Settings audioSettings;
audioSettings.start = -1;
long long lacing = 1; //default is true
while (pos < stop)
{
#ifdef _DEBUG
@@ -3543,6 +3530,8 @@ void Tracks::ParseTrackEntry(
assert(i.nameAsUTF8);
else if (Match(pReader, pos, 0x06, i.codecId))
;
else if (Match(pReader, pos, 0x1C, lacing))
assert(lacing <= 1);
else if (Match(pReader,
pos,
0x23A2,
@@ -3589,6 +3578,8 @@ void Tracks::ParseTrackEntry(
//and that it is unique among all tracks.
assert(i.number > 0);
i.lacing = (lacing > 0) ? true : false;
//TODO: vet settings, to ensure that video settings (0x60)
//were specified when type = 1, and that audio settings (0x61)
//were specified when type = 2.
@@ -3983,6 +3974,19 @@ long long Cluster::GetFirstTime()
}
long long Cluster::GetLastTime()
{
const BlockEntry* const pEntry = GetLast();
if (pEntry == NULL) //empty cluster
return GetTime();
const Block* const pBlock = pEntry->GetBlock();
assert(pBlock);
return pBlock->GetTime(this);
}
void Cluster::ParseBlockGroup(long long start, long long size, size_t index)
{
@@ -4015,11 +4019,12 @@ void Cluster::ParseSimpleBlock(long long start, long long size, size_t index)
const BlockEntry* Cluster::GetFirst()
{
//TODO: handle empty cluster
LoadBlockEntries();
assert(m_entries);
assert(m_entriesCount >= 1);
//assert(m_entries);
//assert(m_entriesCount >= 1);
if ((m_entries == NULL) || (m_entriesCount == 0))
return NULL;
const BlockEntry* const pFirst = m_entries[0];
assert(pFirst);
@@ -4030,11 +4035,12 @@ const BlockEntry* Cluster::GetFirst()
const BlockEntry* Cluster::GetLast()
{
//TODO: handle empty cluster
LoadBlockEntries();
assert(m_entries);
assert(m_entriesCount >= 1);
//assert(m_entries);
//assert(m_entriesCount >= 1);
if ((m_entries == NULL) || (m_entriesCount == 0))
return NULL;
const size_t idx = m_entriesCount - 1;
@@ -4073,6 +4079,9 @@ const BlockEntry* Cluster::GetEntry(const Track* pTrack)
LoadBlockEntries();
if ((m_entries == NULL) || (m_entriesCount == 0))
return NULL;
BlockEntry** i = m_entries;
assert(i);
@@ -4104,23 +4113,90 @@ Cluster::GetEntry(
const CuePoint::TrackPosition& tp)
{
assert(m_pSegment);
assert(tp.m_block > 0);
LoadBlockEntries();
assert(m_entries); //TODO: handle empty cluster
assert(m_entriesCount > 0);
assert(tp.m_block <= (long long)m_entriesCount); //blocks are 1-based
const size_t block = static_cast<size_t>(tp.m_block);
const size_t index = block - 1;
if (m_entries == NULL)
return NULL;
const BlockEntry* const pEntry = m_entries[index];
assert(pEntry);
assert(!pEntry->EOS());
assert(pEntry->GetBlock()->GetTrackNumber() == tp.m_track);
assert(pEntry->GetBlock()->GetTimeCode(this) == cp.GetTimeCode());
const long long count = m_entriesCount;
return pEntry;
if (count <= 0)
return NULL;
const long long tc = cp.GetTimeCode();
if ((tp.m_block > 0) && (tp.m_block <= count))
{
const size_t block = static_cast<size_t>(tp.m_block);
const size_t index = block - 1;
const BlockEntry* const pEntry = m_entries[index];
assert(pEntry);
assert(!pEntry->EOS());
const Block* const pBlock = pEntry->GetBlock();
assert(pBlock);
if ((pBlock->GetTrackNumber() == tp.m_track) &&
(pBlock->GetTimeCode(this) == tc))
{
return pEntry;
}
}
const BlockEntry* const* i = m_entries;
const BlockEntry* const* const j = i + count;
while (i != j)
{
#ifdef _DEBUG
const ptrdiff_t idx = i - m_entries;
idx;
#endif
const BlockEntry* const pEntry = *i++;
assert(pEntry);
assert(!pEntry->EOS());
const Block* const pBlock = pEntry->GetBlock();
assert(pBlock);
if (pBlock->GetTrackNumber() != tp.m_track)
continue;
const long long tc_ = pBlock->GetTimeCode(this);
if (tc_ < tc)
continue;
if (tc_ > tc)
return NULL;
const Tracks* const pTracks = m_pSegment->GetTracks();
assert(pTracks);
const long tn = static_cast<long>(tp.m_track);
const Track* const pTrack = pTracks->GetTrackByNumber(tn);
if (pTrack == NULL)
return NULL;
const long long type = pTrack->GetType();
if (type == 2) //audio
return pEntry;
if (type != 1) //not video
return NULL;
if (!pBlock->IsKey())
return NULL;
return pEntry;
}
return NULL;
}
@@ -4132,7 +4208,7 @@ const BlockEntry* Cluster::GetMaxKey(const VideoTrack* pTrack)
return pTrack->GetEOS();
LoadBlockEntries();
assert(m_entries);
//assert(m_entries);
BlockEntry** i = m_entries + m_entriesCount;
BlockEntry** const j = m_entries;
@@ -4204,10 +4280,10 @@ const Block* SimpleBlock::GetBlock() const
}
bool SimpleBlock::IsBFrame() const
{
return false;
}
//bool SimpleBlock::IsBFrame() const
//{
// return false;
//}
BlockGroup::BlockGroup(
@@ -4343,10 +4419,10 @@ short BlockGroup::GetNextTimeCode() const
}
bool BlockGroup::IsBFrame() const
{
return (m_nextTimeCode > 0);
}
//bool BlockGroup::IsBFrame() const
//{
// return (m_nextTimeCode > 0);
//}
@@ -4374,14 +4450,21 @@ Block::Block(long long start, long long size_, IMkvReader* pReader) :
const long hr = pReader->Read(pos, 1, &m_flags);
assert(hr == 0L);
const int invisible = int(m_flags & 0x08);
invisible;
assert(!invisible);
const int lacing = int(m_flags & 0x06);
lacing;
assert(!lacing);
++pos;
assert(pos <= stop);
m_frameOff = pos;
const long long frame_size = stop - pos;
assert(frame_size <= 2147483647L);
assert(frame_size <= LONG_MAX);
m_frameSize = static_cast<long>(frame_size);
}

View File

@@ -105,7 +105,7 @@ public:
virtual Cluster* GetCluster() const = 0;
virtual size_t GetIndex() const = 0;
virtual const Block* GetBlock() const = 0;
virtual bool IsBFrame() const = 0;
//virtual bool IsBFrame() const = 0;
protected:
BlockEntry();
@@ -125,7 +125,7 @@ public:
Cluster* GetCluster() const;
size_t GetIndex() const;
const Block* GetBlock() const;
bool IsBFrame() const;
//bool IsBFrame() const;
protected:
Cluster* const m_pCluster;
@@ -148,7 +148,7 @@ public:
Cluster* GetCluster() const;
size_t GetIndex() const;
const Block* GetBlock() const;
bool IsBFrame() const;
//bool IsBFrame() const;
short GetPrevTimeCode() const; //relative to block's time
short GetNextTimeCode() const; //as above
@@ -192,6 +192,7 @@ public:
const char* GetCodecNameAsUTF8() const;
const char* GetCodecId() const;
const unsigned char* GetCodecPrivate(size_t&) const;
bool GetLacing() const;
const BlockEntry* GetEOS() const;
@@ -211,7 +212,9 @@ public:
unsigned char* codecPrivate;
size_t codecPrivateSize;
char* codecNameAsUTF8;
bool lacing;
Settings settings;
Info();
void Clear();
};
@@ -334,18 +337,19 @@ private:
char* m_pTitleAsUTF8;
};
class Cues;
class CuePoint
{
friend class Cues;
CuePoint(size_t, long long);
~CuePoint();
CuePoint(const CuePoint&);
CuePoint& operator=(const CuePoint&);
public:
explicit CuePoint(long long);
~CuePoint();
//void Parse(IMkvReader*, long long start, long long size);
void Load(IMkvReader*, long long);
void Load(IMkvReader*);
long long GetTimeCode() const; //absolute but unscaled
long long GetTime(Segment*) const; //absolute and scaled (ns units)
@@ -365,7 +369,7 @@ public:
const TrackPosition* Find(const Track*) const;
private:
//long long m_pos;
const size_t m_index;
long long m_timecode;
TrackPosition* m_track_positions;
size_t m_track_positions_count;
@@ -375,6 +379,11 @@ private:
class Cues
{
friend class Segment;
Cues(Segment*, long long start, long long size);
~Cues();
Cues(const Cues&);
Cues& operator=(const Cues&);
@@ -383,9 +392,6 @@ public:
const long long m_start;
const long long m_size;
Cues(Segment*, long long start, long long size);
~Cues();
bool Find( //lower bound of time_ns
long long time_ns,
const Track*,
@@ -400,29 +406,24 @@ public:
const CuePoint::TrackPosition*&) const;
#endif
#if 0
const CuePoint* GetFirst() const;
const CuePoint* GetLast() const;
#endif
bool LoadCuePoint();
const CuePoint* GetNext(const CuePoint*) const;
#if 0
const CuePoint* LoadCuePoint(
long long time_ns,
const Track*,
const CuePoint::TrackPosition*&) const;
#endif
const BlockEntry* GetBlock(
const CuePoint*,
const CuePoint::TrackPosition*) const;
private:
void Init();
void PreloadCuePoint(size_t&, long long);
void Init() const;
bool LoadCuePoint() const;
void PreloadCuePoint(size_t&, long long) const;
CuePoint** m_cue_points;
//size_t m_cue_points_size;
size_t m_count;
size_t m_preload_count;
long long m_pos;
mutable CuePoint** m_cue_points;
mutable size_t m_count;
mutable size_t m_preload_count;
mutable long long m_pos;
};
@@ -434,7 +435,6 @@ class Cluster
public:
Segment* const m_pSegment;
long m_index;
public:
static Cluster* Parse(Segment*, long, long long off);
@@ -447,6 +447,7 @@ public:
long long GetTimeCode(); //absolute, but not scaled
long long GetTime(); //absolute, and scaled (nanosecond units)
long long GetFirstTime(); //time (ns) of first (earliest) block
long long GetLastTime(); //time (ns) of last (latest) block
const BlockEntry* GetFirst();
const BlockEntry* GetLast();
@@ -461,6 +462,8 @@ protected:
Cluster(Segment*, long, long long off);
public:
//TODO: these should all be private, with public selector functions
long m_index;
long long m_pos;
long long m_size;
@@ -479,6 +482,8 @@ private:
class Segment
{
friend class Cues;
Segment(const Segment&);
Segment& operator=(const Segment&);
@@ -510,25 +515,17 @@ public:
Tracks* GetTracks() const;
const SegmentInfo* GetInfo() const;
const Cues* GetCues() const;
long long GetDuration() const;
//NOTE: this turned out to be too inefficient.
//long long Load(long long time_nanoseconds);
unsigned long GetCount() const;
Cluster* GetFirst();
Cluster* GetLast();
unsigned long GetCount() const;
Cluster* GetNext(const Cluster*);
Cluster* GetCluster(long long time_nanoseconds);
void GetCluster(
long long time_nanoseconds,
Track*,
Cluster*&,
const BlockEntry*&);
Cues* GetCues() const;
Cluster* FindCluster(long long time_nanoseconds);
const BlockEntry* Seek(long long time_nanoseconds, const Track*);
private:
@@ -548,11 +545,9 @@ private:
void ParseSeekEntry(long long pos, long long size);
void ParseCues(long long);
bool SearchCues(
long long time_ns,
Track*,
Cluster*&,
const BlockEntry*&);
const BlockEntry* GetBlock(
const CuePoint&,
const CuePoint::TrackPosition&);
};