| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/threading/simple_thread.h" | 10 #include "base/threading/simple_thread.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // TODO(scherkus): even though some filters are initialized on separate | 87 // TODO(scherkus): even though some filters are initialized on separate |
| 88 // threads these test aren't flaky... why? It's because filters' Initialize() | 88 // threads these test aren't flaky... why? It's because filters' Initialize() |
| 89 // is executed on |message_loop_| and the mock filters instantly call | 89 // is executed on |message_loop_| and the mock filters instantly call |
| 90 // InitializationComplete(), which keeps the pipeline humming along. If | 90 // InitializationComplete(), which keeps the pipeline humming along. If |
| 91 // either filters don't call InitializationComplete() immediately or filter | 91 // either filters don't call InitializationComplete() immediately or filter |
| 92 // initialization is moved to a separate thread this test will become flaky. | 92 // initialization is moved to a separate thread this test will become flaky. |
| 93 class PipelineTest : public ::testing::Test { | 93 class PipelineTest : public ::testing::Test { |
| 94 public: | 94 public: |
| 95 PipelineTest() | 95 PipelineTest() |
| 96 : pipeline_(new Pipeline(message_loop_.message_loop_proxy(), | 96 : pipeline_(new Pipeline(message_loop_.message_loop_proxy(), |
| 97 new MediaLog())) { | 97 new MediaLog())), |
| 98 audio_disabled_(false) { |
| 98 mocks_.reset(new MockFilterCollection()); | 99 mocks_.reset(new MockFilterCollection()); |
| 99 | 100 |
| 100 // InitializeDemuxer() adds overriding expectations for expected non-NULL | 101 // InitializeDemuxer() adds overriding expectations for expected non-NULL |
| 101 // streams. | 102 // streams. |
| 102 DemuxerStream* null_pointer = NULL; | 103 DemuxerStream* null_pointer = NULL; |
| 103 EXPECT_CALL(*mocks_->demuxer(), GetStream(_)) | 104 EXPECT_CALL(*mocks_->demuxer(), GetStream(_)) |
| 104 .WillRepeatedly(Return(null_pointer)); | 105 .WillRepeatedly(Return(null_pointer)); |
| 105 | 106 |
| 106 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) | 107 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) |
| 107 .WillRepeatedly(Return(base::TimeDelta())); | 108 .WillRepeatedly(Return(base::TimeDelta())); |
| 108 } | 109 } |
| 109 | 110 |
| 110 virtual ~PipelineTest() { | 111 virtual ~PipelineTest() { |
| 111 // Shutdown sequence. | 112 // Shutdown sequence. |
| 112 if (pipeline_->IsRunning()) { | 113 if (pipeline_->IsRunning()) { |
| 113 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 114 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 114 .WillOnce(RunClosure()); | 115 .WillOnce(RunClosure()); |
| 115 | 116 |
| 116 // TODO(scherkus): Don't pause+flush on shutdown, | 117 // TODO(scherkus): Don't pause+flush on shutdown, |
| 117 // see http://crbug.com/110228 | 118 // see http://crbug.com/110228 |
| 118 if (audio_stream_) { | 119 if (audio_stream_ && !audio_disabled_) { |
| 119 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 120 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 120 .WillOnce(RunClosure()); | 121 .WillOnce(RunClosure()); |
| 121 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 122 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 122 .WillOnce(RunClosure()); | 123 .WillOnce(RunClosure()); |
| 123 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | 124 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) |
| 124 .WillOnce(RunClosure()); | 125 .WillOnce(RunClosure()); |
| 125 } | 126 } |
| 126 | 127 |
| 127 if (video_stream_) { | 128 if (video_stream_) { |
| 128 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) | 129 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 197 } |
| 197 | 198 |
| 198 // Sets up expectations to allow the audio renderer to initialize. | 199 // Sets up expectations to allow the audio renderer to initialize. |
| 199 void InitializeAudioRenderer(bool disable_after_init_cb = false) { | 200 void InitializeAudioRenderer(bool disable_after_init_cb = false) { |
| 200 if (disable_after_init_cb) { | 201 if (disable_after_init_cb) { |
| 201 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | 202 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( |
| 202 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), | 203 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), |
| 203 _, _, _, _, _, _)) | 204 _, _, _, _, _, _)) |
| 204 .WillOnce(DoAll(RunPipelineStatusCB(), | 205 .WillOnce(DoAll(RunPipelineStatusCB(), |
| 205 WithArg<5>(RunClosure()))); // |disabled_cb|. | 206 WithArg<5>(RunClosure()))); // |disabled_cb|. |
| 207 audio_disabled_ = true; |
| 206 } else { | 208 } else { |
| 207 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | 209 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( |
| 208 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), | 210 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), |
| 209 _, _, _, _, _, _)) | 211 _, _, _, _, _, _)) |
| 210 .WillOnce(DoAll(SaveArg<3>(&audio_time_cb_), | 212 .WillOnce(DoAll(SaveArg<3>(&audio_time_cb_), |
| 211 RunPipelineStatusCB())); | 213 RunPipelineStatusCB())); |
| 212 } | 214 } |
| 213 } | 215 } |
| 214 | 216 |
| 215 // Sets up expectations on the callback and initializes the pipeline. Called | 217 // Sets up expectations on the callback and initializes the pipeline. Called |
| 216 // after tests have set expectations any filters they wish to use. | 218 // after tests have set expectations any filters they wish to use. |
| 217 void InitializePipeline(PipelineStatus start_status) { | 219 void InitializePipeline(PipelineStatus start_status) { |
| 218 EXPECT_CALL(callbacks_, OnStart(start_status)); | 220 EXPECT_CALL(callbacks_, OnStart(start_status)); |
| 219 | 221 |
| 220 if (start_status == PIPELINE_OK) { | 222 if (start_status == PIPELINE_OK) { |
| 221 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); | 223 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); |
| 222 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 224 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |
| 223 | 225 |
| 224 if (audio_stream_) { | 226 if (audio_stream_ && !audio_disabled_) { |
| 225 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | 227 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); |
| 226 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | 228 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); |
| 227 | 229 |
| 228 // Startup sequence. | 230 // Startup sequence. |
| 229 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) | 231 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) |
| 230 .WillOnce(RunPipelineStatusCB()); | 232 .WillOnce(RunPipelineStatusCB()); |
| 231 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 233 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 232 .WillOnce(RunClosure()); | 234 .WillOnce(RunClosure()); |
| 233 } | 235 } |
| 234 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); | 236 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 pipeline_->Seek(seek_time, | 301 pipeline_->Seek(seek_time, |
| 300 base::Bind(&CallbackHelper::OnSeek, | 302 base::Bind(&CallbackHelper::OnSeek, |
| 301 base::Unretained(&callbacks_))); | 303 base::Unretained(&callbacks_))); |
| 302 | 304 |
| 303 // We expect the time to be updated only after the seek has completed. | 305 // We expect the time to be updated only after the seek has completed. |
| 304 EXPECT_NE(seek_time, pipeline_->GetMediaTime()); | 306 EXPECT_NE(seek_time, pipeline_->GetMediaTime()); |
| 305 message_loop_.RunAllPending(); | 307 message_loop_.RunAllPending(); |
| 306 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); | 308 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); |
| 307 } | 309 } |
| 308 | 310 |
| 311 void DisableAudio() { |
| 312 pipeline_->OnAudioDisabled(); |
| 313 audio_disabled_ = true; |
| 314 } |
| 315 |
| 309 // Fixture members. | 316 // Fixture members. |
| 310 StrictMock<CallbackHelper> callbacks_; | 317 StrictMock<CallbackHelper> callbacks_; |
| 311 MessageLoop message_loop_; | 318 MessageLoop message_loop_; |
| 312 scoped_refptr<Pipeline> pipeline_; | 319 scoped_refptr<Pipeline> pipeline_; |
| 313 scoped_ptr<media::MockFilterCollection> mocks_; | 320 scoped_ptr<media::MockFilterCollection> mocks_; |
| 314 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; | 321 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; |
| 315 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; | 322 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; |
| 323 bool audio_disabled_; |
| 316 AudioRenderer::TimeCB audio_time_cb_; | 324 AudioRenderer::TimeCB audio_time_cb_; |
| 317 VideoDecoderConfig video_decoder_config_; | 325 VideoDecoderConfig video_decoder_config_; |
| 318 | 326 |
| 319 private: | 327 private: |
| 320 DISALLOW_COPY_AND_ASSIGN(PipelineTest); | 328 DISALLOW_COPY_AND_ASSIGN(PipelineTest); |
| 321 }; | 329 }; |
| 322 | 330 |
| 323 // Test that playback controls methods no-op when the pipeline hasn't been | 331 // Test that playback controls methods no-op when the pipeline hasn't been |
| 324 // started. | 332 // started. |
| 325 TEST_F(PipelineTest, NotStarted) { | 333 TEST_F(PipelineTest, NotStarted) { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 InitializeDemuxer(&streams); | 582 InitializeDemuxer(&streams); |
| 575 InitializeAudioDecoder(audio_stream()); | 583 InitializeAudioDecoder(audio_stream()); |
| 576 InitializeAudioRenderer(); | 584 InitializeAudioRenderer(); |
| 577 InitializeVideoRenderer(video_stream()); | 585 InitializeVideoRenderer(video_stream()); |
| 578 | 586 |
| 579 InitializePipeline(PIPELINE_OK); | 587 InitializePipeline(PIPELINE_OK); |
| 580 EXPECT_TRUE(pipeline_->HasAudio()); | 588 EXPECT_TRUE(pipeline_->HasAudio()); |
| 581 EXPECT_TRUE(pipeline_->HasVideo()); | 589 EXPECT_TRUE(pipeline_->HasVideo()); |
| 582 | 590 |
| 583 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); | 591 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); |
| 584 pipeline_->OnAudioDisabled(); | 592 DisableAudio(); |
| 585 | 593 |
| 586 // Verify that ended event is fired when video ends. | 594 // Verify that ended event is fired when video ends. |
| 587 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 595 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 588 pipeline_->OnVideoRendererEnded(); | 596 pipeline_->OnVideoRendererEnded(); |
| 589 } | 597 } |
| 590 | 598 |
| 591 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { | 599 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { |
| 592 CreateAudioStream(); | 600 CreateAudioStream(); |
| 593 CreateVideoStream(); | 601 CreateVideoStream(); |
| 594 MockDemuxerStreamVector streams; | 602 MockDemuxerStreamVector streams; |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); | 1327 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); |
| 1320 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); | 1328 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); |
| 1321 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); | 1329 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); |
| 1322 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); | 1330 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); |
| 1323 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1331 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
| 1324 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); | 1332 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); |
| 1325 INSTANTIATE_TEARDOWN_TEST(Error, Starting); | 1333 INSTANTIATE_TEARDOWN_TEST(Error, Starting); |
| 1326 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1334 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
| 1327 | 1335 |
| 1328 } // namespace media | 1336 } // namespace media |
| OLD | NEW |