| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/waitable_event.h" | 7 #include "base/waitable_event.h" |
| 8 #include "media/base/pipeline_impl.h" | 8 #include "media/base/pipeline_impl.h" |
| 9 #include "media/base/media_format.h" | 9 #include "media/base/media_format.h" |
| 10 #include "media/base/filters.h" | 10 #include "media/base/filters.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 &CallbackHelper::OnStop)); | 61 &CallbackHelper::OnStop)); |
| 62 message_loop_.RunAllPending(); | 62 message_loop_.RunAllPending(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 protected: | 65 protected: |
| 66 // Sets up expectations to allow the data source to initialize. | 66 // Sets up expectations to allow the data source to initialize. |
| 67 void InitializeDataSource() { | 67 void InitializeDataSource() { |
| 68 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) | 68 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
| 69 .WillOnce(Invoke(&RunFilterCallback)); | 69 .WillOnce(Invoke(&RunFilterCallback)); |
| 70 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); | 70 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); |
| 71 EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull())) |
| 72 .WillOnce(Invoke(&RunFilterCallback)); |
| 71 EXPECT_CALL(*mocks_->data_source(), Stop()); | 73 EXPECT_CALL(*mocks_->data_source(), Stop()); |
| 72 } | 74 } |
| 73 | 75 |
| 74 // Sets up expectations to allow the demuxer to initialize. | 76 // Sets up expectations to allow the demuxer to initialize. |
| 75 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 77 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
| 76 void InitializeDemuxer(MockDemuxerStreamVector* streams) { | 78 void InitializeDemuxer(MockDemuxerStreamVector* streams) { |
| 77 EXPECT_CALL(*mocks_->demuxer(), | 79 EXPECT_CALL(*mocks_->demuxer(), |
| 78 Initialize(mocks_->data_source(), NotNull())) | 80 Initialize(mocks_->data_source(), NotNull())) |
| 79 .WillOnce(Invoke(&RunFilterCallback)); | 81 .WillOnce(Invoke(&RunFilterCallback)); |
| 80 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) | 82 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) |
| 81 .WillRepeatedly(Return(streams->size())); | 83 .WillRepeatedly(Return(streams->size())); |
| 82 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 84 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |
| 85 EXPECT_CALL(*mocks_->demuxer(), Seek(base::TimeDelta(), NotNull())) |
| 86 .WillOnce(Invoke(&RunFilterCallback)); |
| 83 EXPECT_CALL(*mocks_->demuxer(), Stop()); | 87 EXPECT_CALL(*mocks_->demuxer(), Stop()); |
| 84 | 88 |
| 85 // Configure the demuxer to return the streams. | 89 // Configure the demuxer to return the streams. |
| 86 for (size_t i = 0; i < streams->size(); ++i) { | 90 for (size_t i = 0; i < streams->size(); ++i) { |
| 87 scoped_refptr<DemuxerStream> stream = (*streams)[i]; | 91 scoped_refptr<DemuxerStream> stream = (*streams)[i]; |
| 88 EXPECT_CALL(*mocks_->demuxer(), GetStream(i)) | 92 EXPECT_CALL(*mocks_->demuxer(), GetStream(i)) |
| 89 .WillRepeatedly(Return(stream)); | 93 .WillRepeatedly(Return(stream)); |
| 90 } | 94 } |
| 91 } | 95 } |
| 92 | 96 |
| 93 // Sets up expectations to allow the video decoder to initialize. | 97 // Sets up expectations to allow the video decoder to initialize. |
| 94 void InitializeVideoDecoder(MockDemuxerStream* stream) { | 98 void InitializeVideoDecoder(MockDemuxerStream* stream) { |
| 95 EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream, NotNull())) | 99 EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream, NotNull())) |
| 96 .WillOnce(Invoke(&RunFilterCallback)); | 100 .WillOnce(Invoke(&RunFilterCallback)); |
| 97 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); | 101 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); |
| 102 EXPECT_CALL(*mocks_->video_decoder(), Seek(base::TimeDelta(), NotNull())) |
| 103 .WillOnce(Invoke(&RunFilterCallback)); |
| 98 EXPECT_CALL(*mocks_->video_decoder(), Stop()); | 104 EXPECT_CALL(*mocks_->video_decoder(), Stop()); |
| 99 } | 105 } |
| 100 | 106 |
| 101 // Sets up expectations to allow the audio decoder to initialize. | 107 // Sets up expectations to allow the audio decoder to initialize. |
| 102 void InitializeAudioDecoder(MockDemuxerStream* stream) { | 108 void InitializeAudioDecoder(MockDemuxerStream* stream) { |
| 103 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, NotNull())) | 109 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, NotNull())) |
| 104 .WillOnce(Invoke(&RunFilterCallback)); | 110 .WillOnce(Invoke(&RunFilterCallback)); |
| 105 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); | 111 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); |
| 112 EXPECT_CALL(*mocks_->audio_decoder(), Seek(base::TimeDelta(), NotNull())) |
| 113 .WillOnce(Invoke(&RunFilterCallback)); |
| 106 EXPECT_CALL(*mocks_->audio_decoder(), Stop()); | 114 EXPECT_CALL(*mocks_->audio_decoder(), Stop()); |
| 107 } | 115 } |
| 108 | 116 |
| 109 // Sets up expectations to allow the video renderer to initialize. | 117 // Sets up expectations to allow the video renderer to initialize. |
| 110 void InitializeVideoRenderer() { | 118 void InitializeVideoRenderer() { |
| 111 EXPECT_CALL(*mocks_->video_renderer(), | 119 EXPECT_CALL(*mocks_->video_renderer(), |
| 112 Initialize(mocks_->video_decoder(), NotNull())) | 120 Initialize(mocks_->video_decoder(), NotNull())) |
| 113 .WillOnce(Invoke(&RunFilterCallback)); | 121 .WillOnce(Invoke(&RunFilterCallback)); |
| 114 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | 122 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); |
| 123 EXPECT_CALL(*mocks_->video_renderer(), Seek(base::TimeDelta(), NotNull())) |
| 124 .WillOnce(Invoke(&RunFilterCallback)); |
| 115 EXPECT_CALL(*mocks_->video_renderer(), Stop()); | 125 EXPECT_CALL(*mocks_->video_renderer(), Stop()); |
| 116 } | 126 } |
| 117 | 127 |
| 118 // Sets up expectations to allow the audio renderer to initialize. | 128 // Sets up expectations to allow the audio renderer to initialize. |
| 119 void InitializeAudioRenderer() { | 129 void InitializeAudioRenderer() { |
| 120 EXPECT_CALL(*mocks_->audio_renderer(), | 130 EXPECT_CALL(*mocks_->audio_renderer(), |
| 121 Initialize(mocks_->audio_decoder(), NotNull())) | 131 Initialize(mocks_->audio_decoder(), NotNull())) |
| 122 .WillOnce(Invoke(&RunFilterCallback)); | 132 .WillOnce(Invoke(&RunFilterCallback)); |
| 123 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | 133 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); |
| 124 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | 134 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); |
| 135 EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), NotNull())) |
| 136 .WillOnce(Invoke(&RunFilterCallback)); |
| 125 EXPECT_CALL(*mocks_->audio_renderer(), Stop()); | 137 EXPECT_CALL(*mocks_->audio_renderer(), Stop()); |
| 126 } | 138 } |
| 127 | 139 |
| 128 // Sets up expectations on the callback and initializes the pipeline. Called | 140 // Sets up expectations on the callback and initializes the pipeline. Called |
| 129 // after tests have set expectations any filters they wish to use. | 141 // after tests have set expectations any filters they wish to use. |
| 130 void InitializePipeline() { | 142 void InitializePipeline() { |
| 131 // Expect an initialization callback. | 143 // Expect an initialization callback. |
| 132 EXPECT_CALL(callbacks_, OnStart()); | 144 EXPECT_CALL(callbacks_, OnStart()); |
| 133 pipeline_->Start(mocks_, "", | 145 pipeline_->Start(mocks_, "", |
| 134 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 146 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 .WillOnce(Invoke(&RunFilterCallback)); | 361 .WillOnce(Invoke(&RunFilterCallback)); |
| 350 | 362 |
| 351 // We expect a successful seek callback. | 363 // We expect a successful seek callback. |
| 352 EXPECT_CALL(callbacks_, OnSeek()); | 364 EXPECT_CALL(callbacks_, OnSeek()); |
| 353 | 365 |
| 354 // Initialize then seek! | 366 // Initialize then seek! |
| 355 InitializePipeline(); | 367 InitializePipeline(); |
| 356 pipeline_->Seek(expected, | 368 pipeline_->Seek(expected, |
| 357 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 369 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
| 358 &CallbackHelper::OnSeek)); | 370 &CallbackHelper::OnSeek)); |
| 371 |
| 372 // We expect the time to be updated only after the seek has completed. |
| 373 EXPECT_TRUE(expected != pipeline_->GetCurrentTime()); |
| 359 message_loop_.RunAllPending(); | 374 message_loop_.RunAllPending(); |
| 375 EXPECT_TRUE(expected == pipeline_->GetCurrentTime()); |
| 360 } | 376 } |
| 361 | 377 |
| 362 TEST_F(PipelineImplTest, SetVolume) { | 378 TEST_F(PipelineImplTest, SetVolume) { |
| 363 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = | 379 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = |
| 364 new StrictMock<MockDemuxerStream>("audio/x-foo"); | 380 new StrictMock<MockDemuxerStream>("audio/x-foo"); |
| 365 MockDemuxerStreamVector streams; | 381 MockDemuxerStreamVector streams; |
| 366 streams.push_back(audio_stream); | 382 streams.push_back(audio_stream); |
| 367 | 383 |
| 368 InitializeDataSource(); | 384 InitializeDataSource(); |
| 369 InitializeDemuxer(&streams); | 385 InitializeDemuxer(&streams); |
| 370 InitializeAudioDecoder(audio_stream); | 386 InitializeAudioDecoder(audio_stream); |
| 371 InitializeAudioRenderer(); | 387 InitializeAudioRenderer(); |
| 372 | 388 |
| 373 // The audio renderer should receive a call to SetVolume(). | 389 // The audio renderer should receive a call to SetVolume(). |
| 374 float expected = 0.5f; | 390 float expected = 0.5f; |
| 375 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); | 391 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); |
| 376 | 392 |
| 377 // Initialize then set volume! | 393 // Initialize then set volume! |
| 378 InitializePipeline(); | 394 InitializePipeline(); |
| 379 pipeline_->SetVolume(expected); | 395 pipeline_->SetVolume(expected); |
| 380 } | 396 } |
| 381 | 397 |
| 382 } // namespace media | 398 } // namespace media |
| OLD | NEW |