Bug 1500713: P3 - Prevent duration in GetBuffered from being overestimated. r=kinetik

Depends on D19097

Differential Revision: https://phabricator.services.mozilla.com/D22048

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chun-Min Chang 2019-03-09 01:09:37 +00:00
Родитель 10ff475ede
Коммит fe833872ac
2 изменённых файлов: 22 добавлений и 6 удалений

Просмотреть файл

@ -297,16 +297,17 @@ int64_t MP3TrackDemuxer::GetResourceOffset() const { return mOffset; }
TimeIntervals MP3TrackDemuxer::GetBuffered() {
AutoPinned<MediaResource> stream(mSource.GetResource());
TimeIntervals buffered;
TimeIntervals duration;
duration += TimeInterval(TimeUnit(), Duration());
if (Duration() > TimeUnit() && stream->IsDataCachedToEndOfResource(0)) {
// Special case completely cached files. This also handles local files.
buffered += TimeInterval(TimeUnit(), Duration());
MP3LOGV("buffered = [[%" PRId64 ", %" PRId64 "]]",
TimeUnit().ToMicroseconds(), Duration().ToMicroseconds());
return buffered;
return duration;
}
TimeIntervals buffered;
MediaByteRangeSet ranges;
nsresult rv = stream->GetCachedRanges(ranges);
NS_ENSURE_SUCCESS(rv, buffered);
@ -322,7 +323,11 @@ TimeIntervals MP3TrackDemuxer::GetBuffered() {
buffered += TimeInterval(start, end);
}
return buffered;
// If the number of frames presented in header is valid, the duration
// calculated from it should be the maximal duration.
return ValidNumAudioFrames().isSome() && buffered.GetEnd() > duration.GetEnd()
? duration
: buffered;
}
int64_t MP3TrackDemuxer::StreamLength() const { return mSource.GetLength(); }
@ -333,8 +338,8 @@ TimeUnit MP3TrackDemuxer::Duration() const {
}
int64_t numFrames = 0;
const auto numAudioFrames = mParser.VBRInfo().NumAudioFrames();
if (mParser.VBRInfo().IsValid() && numAudioFrames.valueOr(0) + 1 > 1) {
const auto numAudioFrames = ValidNumAudioFrames();
if (numAudioFrames.isSome()) {
// VBR headers don't include the VBR header frame.
numFrames = numAudioFrames.value() + 1;
return Duration(numFrames);
@ -728,6 +733,13 @@ double MP3TrackDemuxer::AverageFrameLength() const {
return 0.0;
}
Maybe<uint32_t> MP3TrackDemuxer::ValidNumAudioFrames() const {
return mParser.VBRInfo().IsValid() &&
mParser.VBRInfo().NumAudioFrames().valueOr(0) + 1 > 1
? mParser.VBRInfo().NumAudioFrames()
: Maybe<uint32_t>();
}
} // namespace mozilla
#undef MP3LOG

Просмотреть файл

@ -122,6 +122,10 @@ class MP3TrackDemuxer : public MediaTrackDemuxer,
// Returns the average frame length derived from the previously parsed frames.
double AverageFrameLength() const;
// Returns the number of frames reported by the header if it's valid. Nothing
// otherwise.
Maybe<uint32_t> ValidNumAudioFrames() const;
// The (hopefully) MPEG resource.
MediaResourceIndex mSource;