| Index: media/filters/video_renderer_impl_unittest.cc
|
| diff --git a/media/filters/video_renderer_impl_unittest.cc b/media/filters/video_renderer_impl_unittest.cc
|
| index e51391cda4781912b825ecb3983df0f1fc24e26a..6e0c95a09b965277127ce0f4735d75a1b1b75650 100644
|
| --- a/media/filters/video_renderer_impl_unittest.cc
|
| +++ b/media/filters/video_renderer_impl_unittest.cc
|
| @@ -32,6 +32,7 @@ using ::testing::Invoke;
|
| using ::testing::NiceMock;
|
| using ::testing::NotNull;
|
| using ::testing::Return;
|
| +using ::testing::SaveArg;
|
| using ::testing::StrictMock;
|
|
|
| namespace media {
|
| @@ -67,9 +68,9 @@ class VideoRendererImplTest : public ::testing::Test {
|
| demuxer_stream_.set_video_decoder_config(TestVideoConfig::Normal());
|
|
|
| // We expect these to be called but we don't care how/when.
|
| - EXPECT_CALL(demuxer_stream_, Read(_))
|
| - .WillRepeatedly(RunCallback<0>(DemuxerStream::kOk,
|
| - DecoderBuffer::CreateEOSBuffer()));
|
| + EXPECT_CALL(demuxer_stream_, Read(_)).WillRepeatedly(
|
| + RunCallback<0>(DemuxerStream::kOk,
|
| + scoped_refptr<DecoderBuffer>(new DecoderBuffer(0))));
|
| EXPECT_CALL(*decoder_, Stop())
|
| .WillRepeatedly(Invoke(this, &VideoRendererImplTest::StopRequested));
|
| EXPECT_CALL(statistics_cb_object_, OnStatistics(_))
|
| @@ -90,16 +91,13 @@ class VideoRendererImplTest : public ::testing::Test {
|
| void InitializeWithLowDelay(bool low_delay) {
|
| // Monitor decodes from the decoder.
|
| EXPECT_CALL(*decoder_, Decode(_, _))
|
| - .WillRepeatedly(Invoke(this, &VideoRendererImplTest::FrameRequested));
|
| + .WillRepeatedly(Invoke(this, &VideoRendererImplTest::DecodeRequested));
|
|
|
| EXPECT_CALL(*decoder_, Reset(_))
|
| .WillRepeatedly(Invoke(this, &VideoRendererImplTest::FlushRequested));
|
|
|
| InSequence s;
|
|
|
| - EXPECT_CALL(*decoder_, Initialize(_, _, _))
|
| - .WillOnce(RunCallback<2>(PIPELINE_OK));
|
| -
|
| // Set playback rate before anything else happens.
|
| renderer_->SetPlaybackRate(1.0f);
|
|
|
| @@ -110,11 +108,15 @@ class VideoRendererImplTest : public ::testing::Test {
|
| void InitializeRenderer(PipelineStatus expected, bool low_delay) {
|
| SCOPED_TRACE(base::StringPrintf("InitializeRenderer(%d)", expected));
|
| WaitableMessageLoopEvent event;
|
| - CallInitialize(event.GetPipelineStatusCB(), low_delay);
|
| + CallInitialize(event.GetPipelineStatusCB(), low_delay, expected);
|
| event.RunAndWaitForStatus(expected);
|
| }
|
|
|
| - void CallInitialize(const PipelineStatusCB& status_cb, bool low_delay) {
|
| + void CallInitialize(const PipelineStatusCB& status_cb,
|
| + bool low_delay,
|
| + PipelineStatus decoder_status) {
|
| + EXPECT_CALL(*decoder_, Initialize(_, _, _, _)).WillOnce(
|
| + DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(decoder_status)));
|
| renderer_->Initialize(
|
| &demuxer_stream_,
|
| low_delay,
|
| @@ -219,7 +221,7 @@ class VideoRendererImplTest : public ::testing::Test {
|
| }
|
|
|
| bool IsReadPending() {
|
| - return !read_cb_.is_null();
|
| + return !decode_cb_.is_null();
|
| }
|
|
|
| void WaitForError(PipelineStatus expected) {
|
| @@ -234,31 +236,31 @@ class VideoRendererImplTest : public ::testing::Test {
|
|
|
| void WaitForPendingRead() {
|
| SCOPED_TRACE("WaitForPendingRead()");
|
| - if (!read_cb_.is_null())
|
| + if (!decode_cb_.is_null())
|
| return;
|
|
|
| - DCHECK(wait_for_pending_read_cb_.is_null());
|
| + DCHECK(wait_for_pending_decode_cb_.is_null());
|
|
|
| WaitableMessageLoopEvent event;
|
| - wait_for_pending_read_cb_ = event.GetClosure();
|
| + wait_for_pending_decode_cb_ = event.GetClosure();
|
| event.RunAndWait();
|
|
|
| - DCHECK(!read_cb_.is_null());
|
| - DCHECK(wait_for_pending_read_cb_.is_null());
|
| + DCHECK(!decode_cb_.is_null());
|
| + DCHECK(wait_for_pending_decode_cb_.is_null());
|
| }
|
|
|
| void SatisfyPendingRead() {
|
| - CHECK(!read_cb_.is_null());
|
| + CHECK(!decode_cb_.is_null());
|
| CHECK(!decode_results_.empty());
|
|
|
| - base::Closure closure = base::Bind(
|
| - read_cb_, decode_results_.front().first,
|
| - decode_results_.front().second);
|
| -
|
| - read_cb_.Reset();
|
| + // Post tasks for OutputCB and DecodeCB.
|
| + scoped_refptr<VideoFrame> frame = decode_results_.front().second;
|
| + if (frame)
|
| + message_loop_.PostTask(FROM_HERE, base::Bind(output_cb_, frame));
|
| + message_loop_.PostTask(
|
| + FROM_HERE, base::Bind(base::ResetAndReturn(&decode_cb_),
|
| + decode_results_.front().first));
|
| decode_results_.pop_front();
|
| -
|
| - message_loop_.PostTask(FROM_HERE, closure);
|
| }
|
|
|
| void AdvanceTimeInMs(int time_ms) {
|
| @@ -292,15 +294,15 @@ class VideoRendererImplTest : public ::testing::Test {
|
| return base::TimeDelta::FromMilliseconds(kVideoDurationInMs);
|
| }
|
|
|
| - void FrameRequested(const scoped_refptr<DecoderBuffer>& buffer,
|
| - const VideoDecoder::DecodeCB& read_cb) {
|
| + void DecodeRequested(const scoped_refptr<DecoderBuffer>& buffer,
|
| + const VideoDecoder::DecodeCB& decode_cb) {
|
| DCHECK_EQ(&message_loop_, base::MessageLoop::current());
|
| - CHECK(read_cb_.is_null());
|
| - read_cb_ = read_cb;
|
| + CHECK(decode_cb_.is_null());
|
| + decode_cb_ = decode_cb;
|
|
|
| // Wake up WaitForPendingRead() if needed.
|
| - if (!wait_for_pending_read_cb_.is_null())
|
| - base::ResetAndReturn(&wait_for_pending_read_cb_).Run();
|
| + if (!wait_for_pending_decode_cb_.is_null())
|
| + base::ResetAndReturn(&wait_for_pending_decode_cb_).Run();
|
|
|
| if (decode_results_.empty())
|
| return;
|
| @@ -311,7 +313,7 @@ class VideoRendererImplTest : public ::testing::Test {
|
| void FlushRequested(const base::Closure& callback) {
|
| DCHECK_EQ(&message_loop_, base::MessageLoop::current());
|
| decode_results_.clear();
|
| - if (!read_cb_.is_null()) {
|
| + if (!decode_cb_.is_null()) {
|
| QueueFrames("abort");
|
| SatisfyPendingRead();
|
| }
|
| @@ -322,7 +324,7 @@ class VideoRendererImplTest : public ::testing::Test {
|
| void StopRequested() {
|
| DCHECK_EQ(&message_loop_, base::MessageLoop::current());
|
| decode_results_.clear();
|
| - if (!read_cb_.is_null()) {
|
| + if (!decode_cb_.is_null()) {
|
| QueueFrames("abort");
|
| SatisfyPendingRead();
|
| }
|
| @@ -335,14 +337,15 @@ class VideoRendererImplTest : public ::testing::Test {
|
| base::TimeDelta time_;
|
|
|
| // Used for satisfying reads.
|
| - VideoDecoder::DecodeCB read_cb_;
|
| + VideoDecoder::OutputCB output_cb_;
|
| + VideoDecoder::DecodeCB decode_cb_;
|
| base::TimeDelta next_frame_timestamp_;
|
|
|
| WaitableMessageLoopEvent error_event_;
|
| WaitableMessageLoopEvent ended_event_;
|
|
|
| - // Run during FrameRequested() to unblock WaitForPendingRead().
|
| - base::Closure wait_for_pending_read_cb_;
|
| + // Run during DecodeRequested() to unblock WaitForPendingRead().
|
| + base::Closure wait_for_pending_decode_cb_;
|
|
|
| std::deque<std::pair<
|
| VideoDecoder::Status, scoped_refptr<VideoFrame> > > decode_results_;
|
| @@ -378,9 +381,7 @@ static void ExpectNotCalled(PipelineStatus) {
|
| }
|
|
|
| TEST_F(VideoRendererImplTest, StopWhileInitializing) {
|
| - EXPECT_CALL(*decoder_, Initialize(_, _, _))
|
| - .WillOnce(RunCallback<2>(PIPELINE_OK));
|
| - CallInitialize(base::Bind(&ExpectNotCalled), false);
|
| + CallInitialize(base::Bind(&ExpectNotCalled), false, PIPELINE_OK);
|
| Stop();
|
|
|
| // ~VideoRendererImpl() will CHECK() if we left anything initialized.
|
| @@ -625,11 +626,7 @@ TEST_F(VideoRendererImplTest, AbortPendingRead_Preroll) {
|
|
|
| TEST_F(VideoRendererImplTest, VideoDecoder_InitFailure) {
|
| InSequence s;
|
| -
|
| - EXPECT_CALL(*decoder_, Initialize(_, _, _))
|
| - .WillOnce(RunCallback<2>(DECODER_ERROR_NOT_SUPPORTED));
|
| InitializeRenderer(DECODER_ERROR_NOT_SUPPORTED, false);
|
| -
|
| Stop();
|
| }
|
|
|
|
|