| Index: media/filters/video_renderer_base.cc
|
| diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc
|
| index 8451201fae668bd916c1c86bb853bf48e6c9883b..a381a345c6aac6cee2bfe9affbec661f4431b02d 100644
|
| --- a/media/filters/video_renderer_base.cc
|
| +++ b/media/filters/video_renderer_base.cc
|
| @@ -2,24 +2,23 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "media/filters/video_renderer_base.h"
|
| +
|
| #include "base/bind.h"
|
| #include "base/callback.h"
|
| #include "base/callback_helpers.h"
|
| #include "base/threading/platform_thread.h"
|
| #include "media/base/buffers.h"
|
| -#include "media/base/filter_host.h"
|
| #include "media/base/limits.h"
|
| #include "media/base/pipeline.h"
|
| #include "media/base/video_frame.h"
|
| -#include "media/filters/video_renderer_base.h"
|
|
|
| namespace media {
|
|
|
| VideoRendererBase::VideoRendererBase(const base::Closure& paint_cb,
|
| const SetOpaqueCB& set_opaque_cb,
|
| bool drop_frames)
|
| - : host_(NULL),
|
| - frame_available_(&lock_),
|
| + : frame_available_(&lock_),
|
| state_(kUninitialized),
|
| thread_(base::kNullThreadHandle),
|
| pending_read_(false),
|
| @@ -32,12 +31,6 @@ VideoRendererBase::VideoRendererBase(const base::Closure& paint_cb,
|
| DCHECK(!paint_cb_.is_null());
|
| }
|
|
|
| -void VideoRendererBase::SetHost(FilterHost* host) {
|
| - DCHECK(host);
|
| - DCHECK(!host_);
|
| - host_ = host;
|
| -}
|
| -
|
| void VideoRendererBase::Play(const base::Closure& callback) {
|
| base::AutoLock auto_lock(lock_);
|
| DCHECK_EQ(kPrerolled, state_);
|
| @@ -114,22 +107,36 @@ void VideoRendererBase::Seek(base::TimeDelta time, const PipelineStatusCB& cb) {
|
| }
|
|
|
| void VideoRendererBase::Initialize(const scoped_refptr<VideoDecoder>& decoder,
|
| - const PipelineStatusCB& status_cb,
|
| + const PipelineStatusCB& init_cb,
|
| const StatisticsCB& statistics_cb,
|
| - const TimeCB& time_cb) {
|
| + const TimeCB& time_cb,
|
| + const NaturalSizeChangedCB& size_changed_cb,
|
| + const base::Closure& ended_cb,
|
| + const PipelineStatusCB& error_cb,
|
| + const TimeDeltaCB& get_time_cb,
|
| + const TimeDeltaCB& get_duration_cb) {
|
| base::AutoLock auto_lock(lock_);
|
| DCHECK(decoder);
|
| - DCHECK(!status_cb.is_null());
|
| + DCHECK(!init_cb.is_null());
|
| DCHECK(!statistics_cb.is_null());
|
| DCHECK(!time_cb.is_null());
|
| + DCHECK(!size_changed_cb.is_null());
|
| + DCHECK(!ended_cb.is_null());
|
| + DCHECK(!get_time_cb.is_null());
|
| + DCHECK(!get_duration_cb.is_null());
|
| DCHECK_EQ(kUninitialized, state_);
|
| decoder_ = decoder;
|
|
|
| statistics_cb_ = statistics_cb;
|
| time_cb_ = time_cb;
|
| + size_changed_cb_ = size_changed_cb;
|
| + ended_cb_ = ended_cb;
|
| + error_cb_ = error_cb;
|
| + get_time_cb_ = get_time_cb;
|
| + get_duration_cb_ = get_duration_cb;
|
|
|
| // Notify the pipeline of the video dimensions.
|
| - host_->SetNaturalVideoSize(decoder_->natural_size());
|
| + size_changed_cb_.Run(decoder_->natural_size());
|
|
|
| // We're all good! Consider ourselves flushed. (ThreadMain() should never
|
| // see us in the kUninitialized state).
|
| @@ -144,7 +151,7 @@ void VideoRendererBase::Initialize(const scoped_refptr<VideoDecoder>& decoder,
|
| if (!base::PlatformThread::Create(0, this, &thread_)) {
|
| NOTREACHED() << "Video thread creation failed";
|
| state_ = kError;
|
| - status_cb.Run(PIPELINE_ERROR_INITIALIZATION_FAILED);
|
| + init_cb.Run(PIPELINE_ERROR_INITIALIZATION_FAILED);
|
| return;
|
| }
|
|
|
| @@ -153,7 +160,7 @@ void VideoRendererBase::Initialize(const scoped_refptr<VideoDecoder>& decoder,
|
| // TODO(scherkus): find out if this is necessary, but it seems to help.
|
| ::SetThreadPriority(thread_, THREAD_PRIORITY_ABOVE_NORMAL);
|
| #endif // defined(OS_WIN)
|
| - status_cb.Run(PIPELINE_OK);
|
| + init_cb.Run(PIPELINE_OK);
|
| }
|
|
|
| bool VideoRendererBase::HasEnded() {
|
| @@ -208,7 +215,7 @@ void VideoRendererBase::ThreadMain() {
|
| // This can happen if our preroll only contains end of stream frames.
|
| if (ready_frames_.front()->IsEndOfStream()) {
|
| state_ = kEnded;
|
| - host_->NotifyEnded();
|
| + ended_cb_.Run();
|
| ready_frames_.clear();
|
|
|
| // No need to sleep here as we idle when |state_ != kPlaying|.
|
| @@ -247,7 +254,7 @@ void VideoRendererBase::ThreadMain() {
|
| // |current_frame_|.
|
| if (ready_frames_.front()->IsEndOfStream()) {
|
| state_ = kEnded;
|
| - host_->NotifyEnded();
|
| + ended_cb_.Run();
|
| ready_frames_.clear();
|
|
|
| // No need to sleep here as we idle when |state_ != kPlaying|.
|
| @@ -265,7 +272,7 @@ void VideoRendererBase::ThreadMain() {
|
| break;
|
|
|
| base::TimeDelta remaining_time =
|
| - ready_frames_.front()->GetTimestamp() - host_->GetTime();
|
| + ready_frames_.front()->GetTimestamp() - get_time_cb_.Run();
|
|
|
| // Still a chance we can render the frame!
|
| if (remaining_time.InMicroseconds() > 0)
|
| @@ -384,7 +391,7 @@ void VideoRendererBase::FrameReady(VideoDecoder::DecoderStatus status,
|
| return;
|
| }
|
|
|
| - host_->SetError(error);
|
| + error_cb_.Run(error);
|
| return;
|
| }
|
|
|
| @@ -424,10 +431,11 @@ void VideoRendererBase::FrameReady(VideoDecoder::DecoderStatus status,
|
| // frame rate. Another way for this to happen is for the container to state a
|
| // smaller duration than the largest packet timestamp.
|
| if (!frame->IsEndOfStream()) {
|
| - if (frame->GetTimestamp() > host_->GetDuration())
|
| - frame->SetTimestamp(host_->GetDuration());
|
| - if ((frame->GetTimestamp() + frame->GetDuration()) > host_->GetDuration())
|
| - frame->SetDuration(host_->GetDuration() - frame->GetTimestamp());
|
| + base::TimeDelta duration = get_duration_cb_.Run();
|
| + if (frame->GetTimestamp() > duration)
|
| + frame->SetTimestamp(duration);
|
| + if ((frame->GetTimestamp() + frame->GetDuration()) > duration)
|
| + frame->SetDuration(duration - frame->GetTimestamp());
|
| }
|
|
|
| // This one's a keeper! Place it in the ready queue.
|
| @@ -516,7 +524,7 @@ base::TimeDelta VideoRendererBase::CalculateSleepDuration(
|
| const scoped_refptr<VideoFrame>& next_frame,
|
| float playback_rate) {
|
| // Determine the current and next presentation timestamps.
|
| - base::TimeDelta now = host_->GetTime();
|
| + base::TimeDelta now = get_time_cb_.Run();
|
| base::TimeDelta this_pts = current_frame_->GetTimestamp();
|
| base::TimeDelta next_pts;
|
| if (!next_frame->IsEndOfStream()) {
|
|
|