Bug 1194624: [MSE] P3. Determine when canplaythrough can be fired. r=jwwang

We assume that if we have 30s of data buffered ahead of the current position or up to the element's duration that we can play ahead without interruption.
This commit is contained in:
Jean-Yves Avenard 2015-12-02 15:09:47 +11:00
Родитель 8e5e1f7311
Коммит d77e4129ea
3 изменённых файлов: 29 добавлений и 1 удалений

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

@ -577,7 +577,7 @@ private:
// Returns true if we can play the entire media through without stopping
// to buffer, given the current download and playback rates.
bool CanPlayThrough();
virtual bool CanPlayThrough();
void SetAudioChannel(dom::AudioChannel aChannel) { mAudioChannel = aChannel; }
dom::AudioChannel GetAudioChannel() { return mAudioChannel; }

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

@ -16,6 +16,7 @@
#include "MediaFormatReader.h"
#include "MediaSourceDemuxer.h"
#include "SourceBufferList.h"
#include <algorithm>
extern mozilla::LogModule* GetMediaSourceLog();
@ -265,6 +266,32 @@ MediaSourceDecoder::NextFrameBufferedStatus()
: MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
}
bool
MediaSourceDecoder::CanPlayThrough()
{
MOZ_ASSERT(NS_IsMainThread());
if (IsNaN(mMediaSource->Duration())) {
// Don't have any data yet.
return false;
}
TimeUnit duration = TimeUnit::FromSeconds(mMediaSource->Duration());
TimeUnit currentPosition = TimeUnit::FromMicroseconds(CurrentPosition());
if (duration.IsInfinite()) {
// We can't make an informed decision and just assume that it's a live stream
return true;
} else if (duration <= currentPosition) {
return true;
}
// If we have data up to the mediasource's duration or 30s ahead, we can
// assume that we can play without interruption.
TimeUnit timeAhead =
std::min(duration, currentPosition + TimeUnit::FromSeconds(30));
TimeInterval interval(currentPosition,
timeAhead,
MediaSourceDemuxer::EOS_FUZZ);
return GetBuffered().Contains(interval);
}
#undef MSE_DEBUG
#undef MSE_DEBUGV

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

@ -78,6 +78,7 @@ public:
void AddSizeOfResources(ResourceSizes* aSizes) override;
MediaDecoderOwner::NextFrameStatus NextFrameBufferedStatus() override;
bool CanPlayThrough() override;
private:
void DoSetMediaSourceDuration(double aDuration);