filter out empty clusters

Change-Id: Iad4da9d55c1cfc332042d0017bd5d77e9ad511b6
This commit is contained in:
matthewjheaney 2010-11-18 19:28:50 -05:00
parent cb5414a42a
commit be2f81abca
2 changed files with 112 additions and 24 deletions

View File

@ -1074,10 +1074,15 @@ long Segment::ParseCluster(long long& off, long long& new_pos) const
if (id == 0x0F43B675) //Cluster ID
{
off = idpos - m_start; // >= 0 means we found a cluster
const long long off_ = idpos - m_start;
if (Cluster::HasBlockEntries(this, off_))
{
off = off_; // >= 0 means we found a cluster
break;
}
}
}
assert(pos <= stop);
@ -1162,7 +1167,6 @@ bool Segment::AddCluster(long long off, long long pos)
{
Cluster* const pCluster = Cluster::Parse(this, m_clusterCount, off);
assert(pCluster);
assert(pCluster->m_index == m_clusterCount);
AppendCluster(pCluster);
assert(m_clusters);
@ -1171,7 +1175,6 @@ bool Segment::AddCluster(long long off, long long pos)
}
m_pos = pos; //m_pos >= stop is now we know we have all clusters
return (pos >= stop);
}
@ -1271,21 +1274,27 @@ long Segment::LoadCluster()
--m_clusterPreloadCount;
m_pos = pos + size; //consume payload
break;
assert(m_pos <= stop);
return 0;
}
}
m_pos = pos + size; //consume payload
assert(m_pos <= stop);
if (Cluster::HasBlockEntries(this, idoff))
{
Cluster* const pCluster = Cluster::Parse(this, idx, idoff);
assert(pCluster);
assert(pCluster->m_index == idx);
AppendCluster(pCluster);
assert(m_clusters);
assert(idx < m_clusterSize);
assert(m_clusters[idx] == pCluster);
m_pos = pos + size; //consume payload
break;
return 0;
}
}
assert(m_pos <= stop);
@ -1510,15 +1519,17 @@ long Segment::Load()
const long idx = m_clusterCount;
const long long off = idpos - m_start;
if (Cluster::HasBlockEntries(this, off))
{
Cluster* const pCluster = Cluster::Parse(this, idx, off);
assert(pCluster);
assert(pCluster->m_index == idx);
AppendCluster(pCluster);
assert(m_clusters);
assert(m_clusterSize > idx);
assert(m_clusters[idx] == pCluster);
}
}
else if (id == 0x0C53BB6B) //Cues ID
{
assert(m_pCues == NULL);
@ -2154,8 +2165,11 @@ const BlockEntry* Segment::GetBlock(
}
assert(i == j);
assert(Cluster::HasBlockEntries(this, tp.m_pos));
Cluster* const pCluster = Cluster::Parse(this, -1, tp.m_pos);
assert(pCluster);
const ptrdiff_t idx = i - m_clusters;
PreloadCluster(pCluster, idx);
@ -2530,9 +2544,14 @@ const Cluster* Segment::GetNext(const Cluster* pCurr)
if (id == 0x0F43B675) //Cluster ID
{
off_next = idpos - m_start;
const long long off_next_ = idpos - m_start;
if (Cluster::HasBlockEntries(this, off_next_))
{
off_next = off_next_;
break;
}
}
pos += size; //consume payload
}
@ -2576,6 +2595,8 @@ const Cluster* Segment::GetNext(const Cluster* pCurr)
assert(i == j);
Cluster* const pNext = Cluster::Parse(this, -1, off_next);
assert(pNext);
const ptrdiff_t idx_next = i - m_clusters; //insertion position
PreloadCluster(pNext, idx_next);
@ -3776,6 +3797,9 @@ Cluster* Cluster::Parse(
assert(off >= 0);
assert(off < pSegment->m_size);
//if (!HasBlockEntries(pSegment, off))
// return NULL;
Cluster* const pCluster = new Cluster(pSegment, idx, -off);
assert(pCluster);
@ -3836,6 +3860,68 @@ bool Cluster::EOS() const
}
bool Cluster::HasBlockEntries(
const Segment* pSegment,
long long off) //relative to start of segment payload
{
assert(pSegment);
assert(off >= 0); //relative to segment
IMkvReader* const pReader = pSegment->m_pReader;
long long pos = pSegment->m_start + off; //absolute
long long size;
{
long len;
const long long id = ReadUInt(pReader, pos, len);
id;
assert(id >= 0);
assert(id == 0x0F43B675); //Cluster ID
pos += len; //consume id
size = ReadUInt(pReader, pos, len);
assert(size > 0);
pos += len; //consume size
//pos now points to start of payload
}
const long long stop = pos + size;
while (pos < stop)
{
long len;
const long long id = ReadUInt(pReader, pos, len);
assert(id >= 0); //TODO
assert((pos + len) <= stop);
pos += len; //consume id
const long long size = ReadUInt(pReader, pos, len);
assert(size >= 0); //TODO
assert((pos + len) <= stop);
pos += len; //consume size
if (id == 0x20) //BlockGroup ID
return true;
if (id == 0x23) //SimpleBlock ID
return true;
pos += size; //consume payload
assert(pos <= stop);
}
return false;
}
void Cluster::LoadBlockEntries() const
{
if (m_entries)

View File

@ -479,6 +479,8 @@ public:
const CuePoint::TrackPosition&) const;
const BlockEntry* GetMaxKey(const VideoTrack*) const;
static bool HasBlockEntries(const Segment*, long long);
protected:
Cluster(Segment*, long, long long off);