restructured Segment::LoadCluster

Change-Id: Iaf792807445f3866f4ace4cc5663eb6396ac34be
This commit is contained in:
matthewjheaney 2010-10-06 12:13:33 -04:00
parent 885d2e1ef8
commit d2688d316d

View File

@ -1023,6 +1023,8 @@ long long Segment::ParseHeaders()
return E_FILE_FORMAT_INVALID; return E_FILE_FORMAT_INVALID;
//TODO: require Cues too? //TODO: require Cues too?
//No, don't require it, but use its presence or abscense
//to determine whether seeking is allowed.
return 0; //success return 0; //success
} }
@ -1235,14 +1237,26 @@ long Segment::LoadCluster()
if ((pos + size) > stop) if ((pos + size) > stop)
return E_FILE_FORMAT_INVALID; return E_FILE_FORMAT_INVALID;
const bool bCluster = (id == 0x0F43B675); //Cluster ID if (id == 0x0C53BB6B) //Cues ID
if (bCluster)
{ {
const long idx = m_clusterCount; if (m_pCues == NULL)
const long long off = idpos - m_start; {
m_pCues = new Cues(this, pos, size);
assert(m_pCues); //TODO
}
bool bParse = true; m_pos = pos + size; //consume payload
continue;
}
if (id != 0x0F43B675) //Cluster ID
{
m_pos = pos + size; //consume payload
continue;
}
const long idx = m_clusterCount;
const long long idoff = idpos - m_start;
if (m_clusterPreloadCount > 0) if (m_clusterPreloadCount > 0)
{ {
@ -1252,25 +1266,24 @@ long Segment::LoadCluster()
assert(pCluster); assert(pCluster);
assert(pCluster->m_index < 0); assert(pCluster->m_index < 0);
const long long pos_ = pCluster->m_pos; const long long off_ = pCluster->m_pos;
assert(pos_); assert(off_);
const long long pos = pos_ * ((pos_ >= 0) ? 1 : -1); const long long off = off_ * ((off_ >= 0) ? 1 : -1);
assert(off <= pos); assert(idoff <= off);
if (off == pos) //match if (idoff == off) //cluster has been preloaded already
{ {
pCluster->m_index = idx; pCluster->m_index = idx;
++m_clusterCount; ++m_clusterCount;
--m_clusterPreloadCount; --m_clusterPreloadCount;
bParse = false; m_pos = pos + size; //consume payload
break;
} }
} }
if (bParse) Cluster* const pCluster = Cluster::Parse(this, idx, idoff);
{
Cluster* const pCluster = Cluster::Parse(this, idx, off);
assert(pCluster); assert(pCluster);
assert(pCluster->m_index == idx); assert(pCluster->m_index == idx);
@ -1278,21 +1291,8 @@ long Segment::LoadCluster()
assert(m_clusters); assert(m_clusters);
assert(idx < m_clusterSize); assert(idx < m_clusterSize);
assert(m_clusters[idx] == pCluster); assert(m_clusters[idx] == pCluster);
}
}
#if 0 //TODO
else if (id == 0x0C53BB6B) //Cues ID
{
assert(m_pCues == NULL);
m_pCues = new Cues(this, pos, size);
assert(m_pCues); //TODO
}
#endif
m_pos = pos + size; //consume payload m_pos = pos + size; //consume payload
if (bCluster)
break; break;
} }
@ -1301,7 +1301,6 @@ long Segment::LoadCluster()
} }
void Segment::AppendCluster(Cluster* pCluster) void Segment::AppendCluster(Cluster* pCluster)
{ {
assert(pCluster); assert(pCluster);