mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1219178 - [3.1] Clamp seeking offsets to estimated frame boundaries. r=jya
This commit is contained in:
parent
c6f7725f07
commit
2261f8026c
@ -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;
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user