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,65 +1237,63 @@ 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;
bool bParse = true;
if (m_clusterPreloadCount > 0)
{ {
assert(idx < m_clusterSize); m_pCues = new Cues(this, pos, size);
assert(m_pCues); //TODO
Cluster* const pCluster = m_clusters[idx];
assert(pCluster);
assert(pCluster->m_index < 0);
const long long pos_ = pCluster->m_pos;
assert(pos_);
const long long pos = pos_ * ((pos_ >= 0) ? 1 : -1);
assert(off <= pos);
if (off == pos) //match
{
pCluster->m_index = idx;
++m_clusterCount;
--m_clusterPreloadCount;
bParse = false;
}
} }
if (bParse) m_pos = pos + size; //consume payload
{ continue;
Cluster* const pCluster = Cluster::Parse(this, idx, off); }
assert(pCluster);
assert(pCluster->m_index == idx);
AppendCluster(pCluster); if (id != 0x0F43B675) //Cluster ID
assert(m_clusters); {
assert(idx < m_clusterSize); m_pos = pos + size; //consume payload
assert(m_clusters[idx] == pCluster); continue;
}
const long idx = m_clusterCount;
const long long idoff = idpos - m_start;
if (m_clusterPreloadCount > 0)
{
assert(idx < m_clusterSize);
Cluster* const pCluster = m_clusters[idx];
assert(pCluster);
assert(pCluster->m_index < 0);
const long long off_ = pCluster->m_pos;
assert(off_);
const long long off = off_ * ((off_ >= 0) ? 1 : -1);
assert(idoff <= off);
if (idoff == off) //cluster has been preloaded already
{
pCluster->m_index = idx;
++m_clusterCount;
--m_clusterPreloadCount;
m_pos = pos + size; //consume payload
break;
} }
} }
#if 0 //TODO
else if (id == 0x0C53BB6B) //Cues ID
{
assert(m_pCues == NULL);
m_pCues = new Cues(this, pos, size); Cluster* const pCluster = Cluster::Parse(this, idx, idoff);
assert(m_pCues); //TODO assert(pCluster);
} assert(pCluster->m_index == idx);
#endif
AppendCluster(pCluster);
assert(m_clusters);
assert(idx < m_clusterSize);
assert(m_clusters[idx] == pCluster);
m_pos = pos + size; //consume payload m_pos = pos + size; //consume payload
break;
if (bCluster)
break;
} }
assert(m_pos <= stop); assert(m_pos <= stop);
@ -1301,7 +1301,6 @@ long Segment::LoadCluster()
} }
void Segment::AppendCluster(Cluster* pCluster) void Segment::AppendCluster(Cluster* pCluster)
{ {
assert(pCluster); assert(pCluster);