Bug 1000608 - Implement cue-less seeking on WebM Reader - r=kinetik

This commit is contained in:
cajbir 2014-04-23 19:47:00 +12:00
parent af943fb408
commit ff8b2f2881
3 changed files with 28 additions and 1 deletions

View File

@ -219,6 +219,22 @@ bool WebMBufferedState::CalculateBufferedForRange(int64_t aStartOffset, int64_t
return true;
}
bool WebMBufferedState::GetOffsetForTime(uint64_t aTime, int64_t* aOffset)
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
WebMTimeDataOffset result(0,0);
for (uint32_t i = 0; i < mTimeMapping.Length(); ++i) {
WebMTimeDataOffset o = mTimeMapping[i];
if (o.mTimecode < aTime && o.mTimecode > result.mTimecode) {
result = o;
}
}
*aOffset = result.mOffset;
return true;
}
void WebMBufferedState::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
{
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");

View File

@ -194,6 +194,7 @@ public:
void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
bool CalculateBufferedForRange(int64_t aStartOffset, int64_t aEndOffset,
uint64_t* aStartTime, uint64_t* aEndTime);
bool GetOffsetForTime(uint64_t aTime, int64_t* aOffset);
private:
// Private destructor, to discourage deletion outside of Release():

View File

@ -1004,7 +1004,17 @@ nsresult WebMReader::Seek(int64_t aTarget, int64_t aStartTime, int64_t aEndTime,
}
int r = nestegg_track_seek(mContext, trackToSeek, target);
if (r != 0) {
return NS_ERROR_FAILURE;
// Try seeking directly based on cluster information in memory.
int64_t offset = 0;
bool rv = mBufferedState->GetOffsetForTime((aTarget - aStartTime)/NS_PER_USEC, &offset);
if (!rv) {
return NS_ERROR_FAILURE;
}
r = nestegg_offset_seek(mContext, offset);
if (r != 0) {
return NS_ERROR_FAILURE;
}
}
return NS_OK;
}