Bug 1128380: Make AmpleVideoFrames calculation dynamic. r=cpearce

This commit is contained in:
Jean-Yves Avenard 2015-03-05 16:53:47 +11:00
parent d77c2f7f49
commit bd7cb8851d
7 changed files with 37 additions and 14 deletions

View File

@ -262,6 +262,10 @@ public:
// the newer async model.
virtual bool IsAsync() const { return false; }
// Returns true if this decoder reader uses hardware accelerated video
// decoding.
virtual bool VideoIsHardwareAccelerated() const { return false; }
protected:
virtual ~MediaDecoderReader();

View File

@ -220,7 +220,6 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
mVolume(1.0),
mPlaybackRate(1.0),
mPreservesPitch(true),
mAmpleVideoFrames(MIN_VIDEO_QUEUE_SIZE),
mLowAudioThresholdUsecs(detail::LOW_AUDIO_USECS),
mAmpleAudioThresholdUsecs(detail::AMPLE_AUDIO_USECS),
mQuickBufferingLowDataThresholdUsecs(detail::QUICK_BUFFERING_LOW_DATA_USECS),
@ -581,7 +580,7 @@ bool MediaDecoderStateMachine::HaveEnoughDecodedVideo()
{
AssertCurrentThreadInMonitor();
if (static_cast<uint32_t>(VideoQueue().GetSize()) < mAmpleVideoFrames * mPlaybackRate) {
if (static_cast<uint32_t>(VideoQueue().GetSize()) < GetAmpleVideoFrames() * mPlaybackRate) {
return false;
}
@ -2239,13 +2238,10 @@ nsresult MediaDecoderStateMachine::DecodeMetadata()
mInfo = info;
if (HasVideo()) {
mAmpleVideoFrames = (mReader->IsAsync() && mInfo.mVideo.mIsHardwareAccelerated)
? std::max<uint32_t>(sVideoQueueHWAccelSize, MIN_VIDEO_QUEUE_SIZE)
: std::max<uint32_t>(sVideoQueueDefaultSize, MIN_VIDEO_QUEUE_SIZE);
DECODER_LOG("Video decode isAsync=%d HWAccel=%d videoQueueSize=%d",
mReader->IsAsync(),
mInfo.mVideo.mIsHardwareAccelerated,
mAmpleVideoFrames);
mReader->VideoIsHardwareAccelerated(),
GetAmpleVideoFrames());
}
mDecoder->StartProgressUpdates();
@ -3672,6 +3668,14 @@ void MediaDecoderStateMachine::OnAudioSinkError()
DecodeError();
}
uint32_t MediaDecoderStateMachine::GetAmpleVideoFrames() const
{
AssertCurrentThreadInMonitor();
return (mReader->IsAsync() && mReader->VideoIsHardwareAccelerated())
? std::max<uint32_t>(sVideoQueueHWAccelSize, MIN_VIDEO_QUEUE_SIZE)
: std::max<uint32_t>(sVideoQueueDefaultSize, MIN_VIDEO_QUEUE_SIZE);
}
} // namespace mozilla
// avoid redefined macro in unified build

View File

@ -904,10 +904,11 @@ protected:
uint32_t mBufferingWait;
int64_t mLowDataThresholdUsecs;
// If we've got more than mAmpleVideoFrames decoded video frames waiting in
// If we've got more than this number of decoded video frames waiting in
// the video queue, we will not decode any more video frames until some have
// been consumed by the play state machine thread.
uint32_t mAmpleVideoFrames;
// Must hold monitor.
uint32_t GetAmpleVideoFrames() const;
// Low audio threshold. If we've decoded less than this much audio we
// consider our audio decode "behind", and we may skip video decoding
@ -946,7 +947,11 @@ protected:
MOZ_ASSERT(result <= mAmpleAudioThresholdUsecs, "Prerolling will never finish");
return result;
}
uint32_t VideoPrerollFrames() const { return mScheduler->IsRealTime() ? 0 : mAmpleVideoFrames / 2; }
uint32_t VideoPrerollFrames() const
{
return mScheduler->IsRealTime() ? 0 : GetAmpleVideoFrames() / 2;
}
bool DonePrerollingAudio()
{

View File

@ -46,7 +46,6 @@ private:
mDisplay = nsIntSize(aWidth, aHeight);
mStereoMode = StereoMode::MONO;
mHasVideo = aHasVideo;
mIsHardwareAccelerated = false;
// TODO: TrackInfo should be initialized by its specific codec decoder.
// This following call should be removed once we have that implemented.
@ -76,8 +75,6 @@ public:
bool mHasVideo;
TrackInfo mTrackInfo;
bool mIsHardwareAccelerated;
};
class AudioInfo {

View File

@ -497,7 +497,6 @@ MP4Reader::ReadMetadata(MediaInfo* aInfo,
NS_ENSURE_TRUE(mVideo.mDecoder != nullptr, NS_ERROR_FAILURE);
nsresult rv = mVideo.mDecoder->Init();
NS_ENSURE_SUCCESS(rv, rv);
mInfo.mVideo.mIsHardwareAccelerated = mVideo.mDecoder->IsHardwareAccelerated();
// Collect telemetry from h264 AVCC SPS.
if (!mFoundSPSForTelemetry) {
@ -1100,4 +1099,10 @@ MP4Reader::SetSharedDecoderManager(SharedDecoderManager* aManager)
#endif
}
bool
MP4Reader::VideoIsHardwareAccelerated() const
{
return mVideo.mDecoder && mVideo.mDecoder->IsHardwareAccelerated();
}
} // namespace mozilla

View File

@ -82,6 +82,8 @@ public:
virtual bool IsAsync() const MOZ_OVERRIDE { return true; }
virtual bool VideoIsHardwareAccelerated() const MOZ_OVERRIDE;
private:
bool InitDemuxer();

View File

@ -142,10 +142,16 @@ public:
#endif
virtual bool IsAsync() const MOZ_OVERRIDE {
ReentrantMonitorAutoEnter decoderMon(mDecoder->GetReentrantMonitor());
return (!GetAudioReader() || GetAudioReader()->IsAsync()) &&
(!GetVideoReader() || GetVideoReader()->IsAsync());
}
virtual bool VideoIsHardwareAccelerated() const MOZ_OVERRIDE {
ReentrantMonitorAutoEnter decoderMon(mDecoder->GetReentrantMonitor());
return GetVideoReader() && GetVideoReader()->VideoIsHardwareAccelerated();
}
// Returns true if aReader is a currently active audio or video
bool IsActiveReader(MediaDecoderReader* aReader);