handled no seekhead of clusters

Change-Id: I901381c774772103e9f0324c8618f2e4b783deec
This commit is contained in:
Hwasoo Lee
2010-06-11 14:30:34 -04:00
parent d537a9471d
commit 5e785450d6
2 changed files with 41 additions and 26 deletions

View File

@@ -1160,6 +1160,9 @@ long Segment::Load()
m_clusterCount = 0; m_clusterCount = 0;
long long* fileposition_of_clusters = NULL;
long long size_of_cluster_pos = 0;
while (index < stop) while (index < stop)
{ {
long len = 0; long len = 0;
@@ -1197,12 +1200,31 @@ long Segment::Load()
index += len; //consume length of size of element index += len; //consume length of size of element
if (id == 0x0F43B675) // Cluster ID if (id == 0x0F43B675) // Cluster ID
break;
if (id == 0x014D9B74) // SeekHead ID
{ {
ParseSeekHead(index, size, NULL); assert(fileposition_of_clusters);
break; if (m_clusterCount > size_of_cluster_pos)
{
size_of_cluster_pos *= 2;
long long* const temp = new long long[size_of_cluster_pos];
memset(temp, 0, size_of_cluster_pos);
memcpy(temp, fileposition_of_clusters, size_of_cluster_pos);
delete [] fileposition_of_clusters;
fileposition_of_clusters = temp;
}
fileposition_of_clusters[m_clusterCount] = idpos;
++m_clusterCount;
}
else if (id == 0x0549A966) //Segment Info ID
{
assert(m_pInfo == NULL);
m_pInfo = new SegmentInfo(this, index, size);
assert(m_pInfo);
assert(m_clusterCount == 0);
const long long duration = m_pInfo->GetDuration();
size_of_cluster_pos = duration / 1000000000 + 1;
fileposition_of_clusters = new long long[size_of_cluster_pos];
memset(fileposition_of_clusters, 0, size_of_cluster_pos);
} }
index += size; index += size;
} }
@@ -1210,6 +1232,15 @@ long Segment::Load()
if (m_clusterCount == 0) if (m_clusterCount == 0)
return -1L; return -1L;
m_clusters = new Cluster*[m_clusterCount];
for (int i = 0; i < m_clusterCount; ++i)
{
m_clusters[i] = Cluster::Parse(this, i, fileposition_of_clusters[i]);
}
delete [] fileposition_of_clusters;
while (m_pos < stop) while (m_pos < stop)
{ {
long long pos = m_pos; long long pos = m_pos;
@@ -1256,21 +1287,7 @@ long Segment::Load()
if (id == 0x0F43B675) //Cluster ID if (id == 0x0F43B675) //Cluster ID
break; break;
if (id == 0x014D9B74) //SeekHead ID if (id == 0x0654AE6B) //Tracks ID
{
m_clusters = new Cluster*[m_clusterCount];
size_t index = 0;
ParseSeekHead(pos, size, &index);
assert(index == m_clusterCount);
}
else if (id == 0x0549A966) //Segment Info ID
{
assert(m_pInfo == NULL);
m_pInfo = new SegmentInfo(this, pos, size);
assert(m_pInfo); //TODO
}
else if (id == 0x0654AE6B) //Tracks ID
{ {
assert(m_pTracks == NULL); assert(m_pTracks == NULL);
m_pTracks = new Tracks(this, pos, size); m_pTracks = new Tracks(this, pos, size);
@@ -1375,7 +1392,6 @@ void Segment::ParseSecondarySeekHead(long long off, size_t* pIndex)
ParseSeekHead(pos, size, pIndex); ParseSeekHead(pos, size, pIndex);
} }
void Segment::ParseSeekEntry(long long start, long long size_, size_t* pIndex) void Segment::ParseSeekEntry(long long start, long long size_, size_t* pIndex)
{ {
long long pos = start; long long pos = start;
@@ -2444,8 +2460,7 @@ void Cluster::Load()
IMkvReader* const pReader = m_pSegment->m_pReader; IMkvReader* const pReader = m_pSegment->m_pReader;
const long long off = -m_start; //relative to segment long long pos = -m_start;
long long pos = m_pSegment->m_start + off; //absolute
long len; long len;

View File

@@ -207,7 +207,7 @@ int main(int argc, char* argv[])
printf("\t\tCluster Time Code\t: %lld\n", timeCode); printf("\t\tCluster Time Code\t: %lld\n", timeCode);
const long long time_ns = pCluster->GetTime(); const long long time_ns = pCluster->GetTime();
printf("\t\tCluster Time (ns)\t\t: %lld\n", time_ns); printf("\t\tCluster Time (ns)\t: %lld\n", time_ns);
const BlockEntry* pBlockEntry = pCluster->GetFirst(); const BlockEntry* pBlockEntry = pCluster->GetFirst();