handle case when no duration

Change-Id: I694f6ce6ae9ecc6fc3b90b954dd7041e82fb9ac0
This commit is contained in:
matthewjheaney 2010-10-22 13:46:39 -04:00
parent c2f6bea0d8
commit fc12207e15
2 changed files with 69 additions and 4 deletions

View File

@ -2033,6 +2033,50 @@ bool Cues::FindNext(
#endif
const CuePoint* Cues::GetFirst() const
{
LoadCuePoint(); //init cues
const size_t count = m_count + m_preload_count;
if (count == 0) //weird
return NULL;
CuePoint* const* const pp = m_cue_points;
assert(pp);
CuePoint* const pCP = pp[0];
assert(pCP);
assert(pCP->GetTimeCode() >= 0);
return pCP;
}
const CuePoint* Cues::GetLast() const
{
LoadCuePoint(); //init cues
const size_t count = m_count + m_preload_count;
if (count == 0) //weird
return NULL;
const size_t index = count - 1;
CuePoint* const* const pp = m_cue_points;
assert(pp);
CuePoint* const pCP = pp[index];
assert(pCP);
pCP->Load(m_pSegment->m_pReader);
assert(pCP->GetTimeCode() >= 0);
return pCP;
}
const CuePoint* Cues::GetNext(const CuePoint* pCurr) const
{
if (pCurr == NULL)
@ -2827,7 +2871,7 @@ SegmentInfo::SegmentInfo(Segment* pSegment, long long start, long long size_) :
const long long stop = start + size_;
m_timecodeScale = 1000000;
m_duration = 0;
m_duration = -1;
while (pos < stop)
{
@ -2843,8 +2887,9 @@ SegmentInfo::SegmentInfo(Segment* pSegment, long long start, long long size_) :
else if (Match(pReader, pos, 0x1741, m_pWritingAppAsUTF8)) //[57][41]
assert(m_pWritingAppAsUTF8);
else if (Match(pReader, pos, 0x3BA9, m_pTitleAsUTF8)) //[7B][A9]
else if (Match(pReader, pos, 0x3BA9, m_pTitleAsUTF8)) //[7B][A9]
assert(m_pTitleAsUTF8);
else
{
long len;
@ -2898,7 +2943,9 @@ long long SegmentInfo::GetTimeCodeScale() const
long long SegmentInfo::GetDuration() const
{
assert(m_duration >= 0);
if (m_duration < 0)
return -1;
assert(m_timecodeScale >= 1);
const double dd = double(m_duration) * double(m_timecodeScale);
@ -3899,6 +3946,19 @@ long long Cluster::GetFirstTime()
}
long long Cluster::GetLastTime()
{
const BlockEntry* const pEntry = GetLast();
if (pEntry == NULL) //empty cluster
return GetTime();
const Block* const pBlock = pEntry->GetBlock();
assert(pBlock);
return pBlock->GetTime(this);
}
void Cluster::ParseBlockGroup(long long start, long long size, size_t index)
{

View File

@ -403,6 +403,9 @@ public:
const CuePoint::TrackPosition*&) const;
#endif
const CuePoint* GetFirst() const;
const CuePoint* GetLast() const;
const CuePoint* GetNext(const CuePoint*) const;
const BlockEntry* GetBlock(
@ -429,7 +432,6 @@ class Cluster
public:
Segment* const m_pSegment;
long m_index;
public:
static Cluster* Parse(Segment*, long, long long off);
@ -442,6 +444,7 @@ public:
long long GetTimeCode(); //absolute, but not scaled
long long GetTime(); //absolute, and scaled (nanosecond units)
long long GetFirstTime(); //time (ns) of first (earliest) block
long long GetLastTime(); //time (ns) of last (latest) block
const BlockEntry* GetFirst();
const BlockEntry* GetLast();
@ -456,6 +459,8 @@ protected:
Cluster(Segment*, long, long long off);
public:
//TODO: these should all be private, with public selector functions
long m_index;
long long m_pos;
long long m_size;