Bug 1219178 - [3.1] Clamp seeking offsets to estimated frame boundaries. r=jya

This commit is contained in:
Eugen Sawin 2015-11-17 16:37:38 +01:00
parent c6f7725f07
commit 2261f8026c
2 changed files with 26 additions and 7 deletions

View File

@ -199,22 +199,22 @@ MP3TrackDemuxer::FastSeek(const TimeUnit& aTime) {
const auto& vbr = mParser.VBRInfo();
if (!aTime.ToMicroseconds()) {
// Quick seek to the beginning of the stream.
mOffset = mFirstFrameOffset;
mFrameIndex = 0;
} else if (vbr.IsTOCPresent()) {
// Use TOC for more precise seeking.
const float durationFrac = static_cast<float>(aTime.ToMicroseconds()) /
Duration().ToMicroseconds();
mOffset = vbr.Offset(durationFrac);
mFrameIndex = FrameIndexFromOffset(vbr.Offset(durationFrac));
} else if (AverageFrameLength() > 0) {
mOffset = mFirstFrameOffset + FrameIndexFromTime(aTime) *
AverageFrameLength();
mFrameIndex = FrameIndexFromTime(aTime);
}
mOffset = OffsetFromFrameIndex(mFrameIndex);
if (mOffset > mFirstFrameOffset && StreamLength() > 0) {
mOffset = std::min(StreamLength() - 1, mOffset);
}
mFrameIndex = FrameIndexFromOffset(mOffset);
mParser.EndFrameSession();
MP3LOG("FastSeek End TOC=%d avgFrameLen=%f mNumParsedFrames=%" PRIu64
@ -523,6 +523,22 @@ MP3TrackDemuxer::GetNextFrame(const MediaByteRange& aRange) {
return frame.forget();
}
int64_t
MP3TrackDemuxer::OffsetFromFrameIndex(int64_t aFrameIndex) const {
int64_t offset = 0;
const auto& vbr = mParser.VBRInfo();
if (vbr.NumBytes() && vbr.NumAudioFrames()) {
offset = mFirstFrameOffset + aFrameIndex * vbr.NumBytes().value() /
vbr.NumAudioFrames().value();
} else if (AverageFrameLength() > 0) {
offset = mFirstFrameOffset + aFrameIndex * AverageFrameLength();
}
MP3LOGV("OffsetFromFrameIndex(%" PRId64 ") -> %" PRId64, aFrameIndex, offset);
return std::max<int64_t>(mFirstFrameOffset, offset);
}
int64_t
MP3TrackDemuxer::FrameIndexFromOffset(int64_t aOffset) const {
int64_t frameIndex = 0;

View File

@ -411,10 +411,13 @@ private:
// Updates post-read meta data.
void UpdateState(const MediaByteRange& aRange);
// Returns the frame index for the given offset.
// Returns the estimated offset for the given frame index.
int64_t OffsetFromFrameIndex(int64_t aFrameIndex) const;
// Returns the estimated frame index for the given offset.
int64_t FrameIndexFromOffset(int64_t aOffset) const;
// Returns the frame index for the given time.
// Returns the estimated frame index for the given time.
int64_t FrameIndexFromTime(const media::TimeUnit& aTime) const;
// Reads aSize bytes into aBuffer from the source starting at aOffset.