mkvparser: Cues, change asserts to error checks.

Change-Id: I116845b792aa5bb9a35341097cbd393300539f79
This commit is contained in:
Tom Finegan
2015-08-26 11:42:55 -07:00
parent 7f77201dca
commit 1c5bd949d0

View File

@@ -1812,8 +1812,8 @@ bool Cues::Init() const {
if (m_cue_points) if (m_cue_points)
return true; return true;
assert(m_count == 0); if (m_count != 0 || m_preload_count != 0)
assert(m_preload_count == 0); return false;
IMkvReader* const pReader = m_pSegment->m_pReader; IMkvReader* const pReader = m_pSegment->m_pReader;
@@ -1855,7 +1855,8 @@ bool Cues::Init() const {
} }
bool Cues::PreloadCuePoint(long& cue_points_size, long long pos) const { bool Cues::PreloadCuePoint(long& cue_points_size, long long pos) const {
assert(m_count == 0); if (m_count != 0)
return false;
if (m_preload_count >= cue_points_size) { if (m_preload_count >= cue_points_size) {
const long n = (cue_points_size <= 0) ? 2048 : 2 * cue_points_size; const long n = (cue_points_size <= 0) ? 2048 : 2 * cue_points_size;
@@ -1887,9 +1888,6 @@ bool Cues::PreloadCuePoint(long& cue_points_size, long long pos) const {
} }
bool Cues::LoadCuePoint() const { bool Cues::LoadCuePoint() const {
// odbgstream os;
// os << "Cues::LoadCuePoint" << endl;
const long long stop = m_start + m_size; const long long stop = m_start + m_size;
if (m_pos >= stop) if (m_pos >= stop)
@@ -1950,19 +1948,12 @@ bool Cues::LoadCuePoint() const {
return true; // yes, we loaded a cue point return true; // yes, we loaded a cue point
} }
// return (m_pos < stop);
return false; // no, we did not load a cue point return false; // no, we did not load a cue point
} }
bool Cues::Find(long long time_ns, const Track* pTrack, const CuePoint*& pCP, bool Cues::Find(long long time_ns, const Track* pTrack, const CuePoint*& pCP,
const CuePoint::TrackPosition*& pTP) const { const CuePoint::TrackPosition*& pTP) const {
assert(time_ns >= 0); if (time_ns < 0 || pTrack == NULL || m_cue_points == NULL || m_count == 0)
assert(pTrack);
if (m_cue_points == NULL)
return false;
if (m_count == 0)
return false; return false;
CuePoint** const ii = m_cue_points; CuePoint** const ii = m_cue_points;
@@ -1972,7 +1963,8 @@ bool Cues::Find(long long time_ns, const Track* pTrack, const CuePoint*& pCP,
CuePoint** j = jj; CuePoint** j = jj;
pCP = *i; pCP = *i;
assert(pCP); if (pCP == NULL)
return false;
if (time_ns <= pCP->GetTime(m_pSegment)) { if (time_ns <= pCP->GetTime(m_pSegment)) {
pTP = pCP->Find(pTrack); pTP = pCP->Find(pTrack);
@@ -1986,10 +1978,12 @@ bool Cues::Find(long long time_ns, const Track* pTrack, const CuePoint*& pCP,
//[j, jj) > time_ns //[j, jj) > time_ns
CuePoint** const k = i + (j - i) / 2; CuePoint** const k = i + (j - i) / 2;
assert(k < jj); if (k >= jj)
return false;
CuePoint* const pCP = *k; CuePoint* const pCP = *k;
assert(pCP); if (pCP == NULL)
return false;
const long long t = pCP->GetTime(m_pSegment); const long long t = pCP->GetTime(m_pSegment);
@@ -1998,16 +1992,17 @@ bool Cues::Find(long long time_ns, const Track* pTrack, const CuePoint*& pCP,
else else
j = k; j = k;
assert(i <= j); if (i > j)
return false;
} }
assert(i == j); if (i != j || i > jj || i <= ii)
assert(i <= jj); return false;
assert(i > ii);
pCP = *--i; pCP = *--i;
assert(pCP);
assert(pCP->GetTime(m_pSegment) <= time_ns); if (pCP == NULL || pCP->GetTime(m_pSegment) > time_ns)
return false;
// TODO: here and elsewhere, it's probably not correct to search // TODO: here and elsewhere, it's probably not correct to search
// for the cue point with this time, and then search for a matching // for the cue point with this time, and then search for a matching
@@ -2022,55 +2017,50 @@ bool Cues::Find(long long time_ns, const Track* pTrack, const CuePoint*& pCP,
} }
const CuePoint* Cues::GetFirst() const { const CuePoint* Cues::GetFirst() const {
if (m_cue_points == NULL) if (m_cue_points == NULL || m_count == 0)
return NULL;
if (m_count == 0)
return NULL; return NULL;
CuePoint* const* const pp = m_cue_points; CuePoint* const* const pp = m_cue_points;
assert(pp); if (pp == NULL)
return NULL;
CuePoint* const pCP = pp[0]; CuePoint* const pCP = pp[0];
assert(pCP); if (pCP == NULL || pCP->GetTimeCode() < 0)
assert(pCP->GetTimeCode() >= 0); return NULL;
return pCP; return pCP;
} }
const CuePoint* Cues::GetLast() const { const CuePoint* Cues::GetLast() const {
if (m_cue_points == NULL) if (m_cue_points == NULL || m_count <= 0)
return NULL;
if (m_count <= 0)
return NULL; return NULL;
const long index = m_count - 1; const long index = m_count - 1;
CuePoint* const* const pp = m_cue_points; CuePoint* const* const pp = m_cue_points;
assert(pp); if (pp == NULL)
return NULL;
CuePoint* const pCP = pp[index]; CuePoint* const pCP = pp[index];
assert(pCP); if (pCP == NULL || pCP->GetTimeCode() < 0)
assert(pCP->GetTimeCode() >= 0); return NULL;
return pCP; return pCP;
} }
const CuePoint* Cues::GetNext(const CuePoint* pCurr) const { const CuePoint* Cues::GetNext(const CuePoint* pCurr) const {
if (pCurr == NULL) if (pCurr == NULL || pCurr->GetTimeCode() < 0 ||
m_cue_points == NULL || m_count < 1) {
return NULL; return NULL;
}
assert(pCurr->GetTimeCode() >= 0);
assert(m_cue_points);
assert(m_count >= 1);
long index = pCurr->m_index; long index = pCurr->m_index;
assert(index < m_count); if (index >= m_count)
return NULL;
CuePoint* const* const pp = m_cue_points; CuePoint* const* const pp = m_cue_points;
assert(pp); if (pp == NULL || pp[index] != pCurr)
assert(pp[index] == pCurr); return NULL;
++index; ++index;
@@ -2078,18 +2068,16 @@ const CuePoint* Cues::GetNext(const CuePoint* pCurr) const {
return NULL; return NULL;
CuePoint* const pNext = pp[index]; CuePoint* const pNext = pp[index];
assert(pNext);
assert(pNext->GetTimeCode() >= 0); if (pNext == NULL || pNext->GetTimeCode() < 0)
return NULL;
return pNext; return pNext;
} }
const BlockEntry* Cues::GetBlock(const CuePoint* pCP, const BlockEntry* Cues::GetBlock(const CuePoint* pCP,
const CuePoint::TrackPosition* pTP) const { const CuePoint::TrackPosition* pTP) const {
if (pCP == NULL) if (pCP == NULL || pTP == NULL)
return NULL;
if (pTP == NULL)
return NULL; return NULL;
return m_pSegment->GetBlock(*pCP, *pTP); return m_pSegment->GetBlock(*pCP, *pTP);