diff options
-rw-r--r-- | media/filters/video_renderer_base.cc | 19 | ||||
-rw-r--r-- | media/filters/video_renderer_base_unittest.cc | 2 |
2 files changed, 15 insertions, 6 deletions
diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc index 6161852..9f832b4 100644 --- a/media/filters/video_renderer_base.cc +++ b/media/filters/video_renderer_base.cc @@ -27,10 +27,13 @@ static const size_t kMaxFrames = 3; // A higher value will be a slower frame rate, which looks worse but allows the // audio renderer to catch up faster. A lower value will be a smoother frame // rate, but results in the video being out of sync for longer. -// -// TODO(scherkus): what if the native frame rate is 15 or 10 fps? static const int64 kMaxSleepMilliseconds = 60; +// The number of milliseconds to idle when we do not have anything to do. +// Nothing special about the value, other than we're being more OS-friendly +// than sleeping for 1 millisecond. +static const int kIdleMilliseconds = 10; + VideoRendererBase::VideoRendererBase() : width_(0), height_(0), @@ -193,10 +196,9 @@ void VideoRendererBase::ThreadMain() { return; } - // Sleep for 10 milliseconds while paused. Nothing special about the value, - // other than we're being more OS-friendly than sleeping for 1 millisecond. + // Sleep while paused or seeking. if (state == kPaused || state == kSeeking || playback_rate == 0) { - PlatformThread::Sleep(10); + PlatformThread::Sleep(kIdleMilliseconds); continue; } @@ -211,6 +213,13 @@ void VideoRendererBase::ThreadMain() { continue; } + // Idle if the next frame is too far ahead. + base::TimeDelta diff = current_frame_->GetTimestamp() - host()->GetTime(); + if (diff.InMilliseconds() > kIdleMilliseconds) { + PlatformThread::Sleep(kIdleMilliseconds); + continue; + } + // Otherwise we're playing, so advance the frame and keep reading from the // decoder. |frames_| might be empty if we seeked to the very end of the // media where no frames were available. diff --git a/media/filters/video_renderer_base_unittest.cc b/media/filters/video_renderer_base_unittest.cc index be5afe1..14f7259 100644 --- a/media/filters/video_renderer_base_unittest.cc +++ b/media/filters/video_renderer_base_unittest.cc @@ -27,7 +27,7 @@ class MockVideoRendererBase : public VideoRendererBase { virtual ~MockVideoRendererBase() {} // VideoRendererBase implementation. - MOCK_METHOD1(OnInitialize, bool (VideoDecoder* decoder)); + MOCK_METHOD1(OnInitialize, bool(VideoDecoder* decoder)); MOCK_METHOD0(OnStop, void()); MOCK_METHOD0(OnFrameAvailable, void()); |