| 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/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
| 11 #include "base/threading/simple_thread.h" | 11 #include "base/threading/simple_thread.h" |
| 12 #include "base/time/clock.h" | 12 #include "base/time/clock.h" |
| 13 #include "media/base/clock.h" | 13 #include "media/base/clock.h" |
| 14 #include "media/base/fake_text_track_stream.h" |
| 14 #include "media/base/gmock_callback_support.h" | 15 #include "media/base/gmock_callback_support.h" |
| 15 #include "media/base/media_log.h" | 16 #include "media/base/media_log.h" |
| 16 #include "media/base/mock_filters.h" | 17 #include "media/base/mock_filters.h" |
| 17 #include "media/base/pipeline.h" | 18 #include "media/base/pipeline.h" |
| 18 #include "media/base/test_helpers.h" | 19 #include "media/base/test_helpers.h" |
| 20 #include "media/base/text_renderer.h" |
| 21 #include "media/base/text_track_config.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/gfx/size.h" | 23 #include "ui/gfx/size.h" |
| 21 | 24 |
| 22 using ::testing::_; | 25 using ::testing::_; |
| 23 using ::testing::DeleteArg; | 26 using ::testing::DeleteArg; |
| 24 using ::testing::DoAll; | 27 using ::testing::DoAll; |
| 25 // TODO(scherkus): Remove InSequence after refactoring Pipeline. | 28 // TODO(scherkus): Remove InSequence after refactoring Pipeline. |
| 26 using ::testing::InSequence; | 29 using ::testing::InSequence; |
| 27 using ::testing::Invoke; | 30 using ::testing::Invoke; |
| 28 using ::testing::InvokeWithoutArgs; | 31 using ::testing::InvokeWithoutArgs; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 filter_collection_->SetDemuxer(demuxer_.get()); | 89 filter_collection_->SetDemuxer(demuxer_.get()); |
| 87 | 90 |
| 88 video_renderer_ = new MockVideoRenderer(); | 91 video_renderer_ = new MockVideoRenderer(); |
| 89 scoped_ptr<VideoRenderer> video_renderer(video_renderer_); | 92 scoped_ptr<VideoRenderer> video_renderer(video_renderer_); |
| 90 filter_collection_->SetVideoRenderer(video_renderer.Pass()); | 93 filter_collection_->SetVideoRenderer(video_renderer.Pass()); |
| 91 | 94 |
| 92 audio_renderer_ = new MockAudioRenderer(); | 95 audio_renderer_ = new MockAudioRenderer(); |
| 93 scoped_ptr<AudioRenderer> audio_renderer(audio_renderer_); | 96 scoped_ptr<AudioRenderer> audio_renderer(audio_renderer_); |
| 94 filter_collection_->SetAudioRenderer(audio_renderer.Pass()); | 97 filter_collection_->SetAudioRenderer(audio_renderer.Pass()); |
| 95 | 98 |
| 99 text_renderer_ = new TextRenderer( |
| 100 message_loop_.message_loop_proxy(), |
| 101 base::Bind(&PipelineTest::OnAddTextTrack, |
| 102 base::Unretained(this))); |
| 103 scoped_ptr<TextRenderer> text_renderer(text_renderer_); |
| 104 filter_collection_->SetTextRenderer(text_renderer.Pass()); |
| 105 |
| 96 // InitializeDemuxer() adds overriding expectations for expected non-NULL | 106 // InitializeDemuxer() adds overriding expectations for expected non-NULL |
| 97 // streams. | 107 // streams. |
| 98 DemuxerStream* null_pointer = NULL; | 108 DemuxerStream* null_pointer = NULL; |
| 99 EXPECT_CALL(*demuxer_, GetStream(_)) | 109 EXPECT_CALL(*demuxer_, GetStream(_)) |
| 100 .WillRepeatedly(Return(null_pointer)); | 110 .WillRepeatedly(Return(null_pointer)); |
| 101 | 111 |
| 102 EXPECT_CALL(*demuxer_, GetStartTime()) | 112 EXPECT_CALL(*demuxer_, GetStartTime()) |
| 103 .WillRepeatedly(Return(base::TimeDelta())); | 113 .WillRepeatedly(Return(base::TimeDelta())); |
| 104 } | 114 } |
| 105 | 115 |
| 106 virtual ~PipelineTest() { | 116 virtual ~PipelineTest() { |
| 107 if (!pipeline_ || !pipeline_->IsRunning()) | 117 if (!pipeline_ || !pipeline_->IsRunning()) |
| 108 return; | 118 return; |
| 109 | 119 |
| 110 ExpectStop(); | 120 ExpectStop(); |
| 111 | 121 |
| 122 // The mock demuxer doesn't stop the fake text track stream, |
| 123 // so just stop it manually. |
| 124 if (text_stream_) { |
| 125 text_stream_->Stop(); |
| 126 message_loop_.RunUntilIdle(); |
| 127 } |
| 128 |
| 112 // Expect a stop callback if we were started. | 129 // Expect a stop callback if we were started. |
| 113 EXPECT_CALL(callbacks_, OnStop()); | 130 EXPECT_CALL(callbacks_, OnStop()); |
| 114 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, | 131 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, |
| 115 base::Unretained(&callbacks_))); | 132 base::Unretained(&callbacks_))); |
| 116 message_loop_.RunUntilIdle(); | 133 message_loop_.RunUntilIdle(); |
| 117 } | 134 } |
| 118 | 135 |
| 119 protected: | 136 protected: |
| 120 // Sets up expectations to allow the demuxer to initialize. | 137 // Sets up expectations to allow the demuxer to initialize. |
| 121 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 138 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
| 122 void InitializeDemuxer(MockDemuxerStreamVector* streams, | 139 void InitializeDemuxer(MockDemuxerStreamVector* streams, |
| 123 const base::TimeDelta& duration) { | 140 const base::TimeDelta& duration) { |
| 124 EXPECT_CALL(callbacks_, OnDurationChange()); | 141 EXPECT_CALL(callbacks_, OnDurationChange()); |
| 125 EXPECT_CALL(*demuxer_, Initialize(_, _)) | 142 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) |
| 126 .WillOnce(DoAll(SetDemuxerProperties(duration), | 143 .WillOnce(DoAll(SetDemuxerProperties(duration), |
| 127 RunCallback<1>(PIPELINE_OK))); | 144 RunCallback<1>(PIPELINE_OK))); |
| 128 | 145 |
| 129 // Configure the demuxer to return the streams. | 146 // Configure the demuxer to return the streams. |
| 130 for (size_t i = 0; i < streams->size(); ++i) { | 147 for (size_t i = 0; i < streams->size(); ++i) { |
| 131 DemuxerStream* stream = (*streams)[i]; | 148 DemuxerStream* stream = (*streams)[i]; |
| 132 EXPECT_CALL(*demuxer_, GetStream(stream->type())) | 149 EXPECT_CALL(*demuxer_, GetStream(stream->type())) |
| 133 .WillRepeatedly(Return(stream)); | 150 .WillRepeatedly(Return(stream)); |
| 134 } | 151 } |
| 135 } | 152 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 166 EXPECT_CALL(*audio_renderer_, Initialize(stream, _, _, _, _, _, _, _)) | 183 EXPECT_CALL(*audio_renderer_, Initialize(stream, _, _, _, _, _, _, _)) |
| 167 .WillOnce(DoAll(RunCallback<1>(PIPELINE_OK), | 184 .WillOnce(DoAll(RunCallback<1>(PIPELINE_OK), |
| 168 WithArg<6>(RunClosure<0>()))); // |disabled_cb|. | 185 WithArg<6>(RunClosure<0>()))); // |disabled_cb|. |
| 169 } else { | 186 } else { |
| 170 EXPECT_CALL(*audio_renderer_, Initialize(stream, _, _, _, _, _, _, _)) | 187 EXPECT_CALL(*audio_renderer_, Initialize(stream, _, _, _, _, _, _, _)) |
| 171 .WillOnce(DoAll(SaveArg<4>(&audio_time_cb_), | 188 .WillOnce(DoAll(SaveArg<4>(&audio_time_cb_), |
| 172 RunCallback<1>(PIPELINE_OK))); | 189 RunCallback<1>(PIPELINE_OK))); |
| 173 } | 190 } |
| 174 } | 191 } |
| 175 | 192 |
| 193 void AddTextStream() { |
| 194 EXPECT_CALL(*this, OnAddTextTrack(_,_)) |
| 195 .WillOnce(Invoke(this, &PipelineTest::DoOnAddTextTrack)); |
| 196 static_cast<DemuxerHost*>(pipeline_.get())->AddTextStream(text_stream(), |
| 197 TextTrackConfig(kTextSubtitles, "", "")); |
| 198 } |
| 199 |
| 176 // Sets up expectations on the callback and initializes the pipeline. Called | 200 // Sets up expectations on the callback and initializes the pipeline. Called |
| 177 // after tests have set expectations any filters they wish to use. | 201 // after tests have set expectations any filters they wish to use. |
| 178 void InitializePipeline(PipelineStatus start_status) { | 202 void InitializePipeline(PipelineStatus start_status) { |
| 179 EXPECT_CALL(callbacks_, OnStart(start_status)); | 203 EXPECT_CALL(callbacks_, OnStart(start_status)); |
| 180 | 204 |
| 181 if (start_status == PIPELINE_OK) { | 205 if (start_status == PIPELINE_OK) { |
| 182 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); | 206 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); |
| 183 | 207 |
| 184 if (audio_stream_) { | 208 if (audio_stream_) { |
| 185 EXPECT_CALL(*audio_renderer_, SetPlaybackRate(0.0f)); | 209 EXPECT_CALL(*audio_renderer_, SetPlaybackRate(0.0f)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 208 | 232 |
| 209 void CreateAudioStream() { | 233 void CreateAudioStream() { |
| 210 audio_stream_ = CreateStream(DemuxerStream::AUDIO); | 234 audio_stream_ = CreateStream(DemuxerStream::AUDIO); |
| 211 } | 235 } |
| 212 | 236 |
| 213 void CreateVideoStream() { | 237 void CreateVideoStream() { |
| 214 video_stream_ = CreateStream(DemuxerStream::VIDEO); | 238 video_stream_ = CreateStream(DemuxerStream::VIDEO); |
| 215 video_stream_->set_video_decoder_config(video_decoder_config_); | 239 video_stream_->set_video_decoder_config(video_decoder_config_); |
| 216 } | 240 } |
| 217 | 241 |
| 242 void CreateTextStream() { |
| 243 scoped_ptr<FakeTextTrackStream> text_stream(new FakeTextTrackStream); |
| 244 text_stream_ = text_stream.Pass(); |
| 245 } |
| 246 |
| 218 MockDemuxerStream* audio_stream() { | 247 MockDemuxerStream* audio_stream() { |
| 219 return audio_stream_.get(); | 248 return audio_stream_.get(); |
| 220 } | 249 } |
| 221 | 250 |
| 222 MockDemuxerStream* video_stream() { | 251 MockDemuxerStream* video_stream() { |
| 223 return video_stream_.get(); | 252 return video_stream_.get(); |
| 224 } | 253 } |
| 225 | 254 |
| 255 FakeTextTrackStream* text_stream() { |
| 256 return text_stream_.get(); |
| 257 } |
| 258 |
| 226 void ExpectSeek(const base::TimeDelta& seek_time) { | 259 void ExpectSeek(const base::TimeDelta& seek_time) { |
| 227 // Every filter should receive a call to Seek(). | 260 // Every filter should receive a call to Seek(). |
| 228 EXPECT_CALL(*demuxer_, Seek(seek_time, _)) | 261 EXPECT_CALL(*demuxer_, Seek(seek_time, _)) |
| 229 .WillOnce(RunCallback<1>(PIPELINE_OK)); | 262 .WillOnce(RunCallback<1>(PIPELINE_OK)); |
| 230 | 263 |
| 231 if (audio_stream_) { | 264 if (audio_stream_) { |
| 232 EXPECT_CALL(*audio_renderer_, Pause(_)) | 265 EXPECT_CALL(*audio_renderer_, Pause(_)) |
| 233 .WillOnce(RunClosure<0>()); | 266 .WillOnce(RunClosure<0>()); |
| 234 EXPECT_CALL(*audio_renderer_, Flush(_)) | 267 EXPECT_CALL(*audio_renderer_, Flush(_)) |
| 235 .WillOnce(RunClosure<0>()); | 268 .WillOnce(RunClosure<0>()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 if (demuxer_) | 307 if (demuxer_) |
| 275 EXPECT_CALL(*demuxer_, Stop(_)).WillOnce(RunClosure<0>()); | 308 EXPECT_CALL(*demuxer_, Stop(_)).WillOnce(RunClosure<0>()); |
| 276 | 309 |
| 277 if (audio_stream_) | 310 if (audio_stream_) |
| 278 EXPECT_CALL(*audio_renderer_, Stop(_)).WillOnce(RunClosure<0>()); | 311 EXPECT_CALL(*audio_renderer_, Stop(_)).WillOnce(RunClosure<0>()); |
| 279 | 312 |
| 280 if (video_stream_) | 313 if (video_stream_) |
| 281 EXPECT_CALL(*video_renderer_, Stop(_)).WillOnce(RunClosure<0>()); | 314 EXPECT_CALL(*video_renderer_, Stop(_)).WillOnce(RunClosure<0>()); |
| 282 } | 315 } |
| 283 | 316 |
| 317 MOCK_METHOD2(OnAddTextTrack, void(const TextTrackConfig&, |
| 318 const AddTextTrackDoneCB&)); |
| 319 |
| 320 void DoOnAddTextTrack(const TextTrackConfig& config, |
| 321 const AddTextTrackDoneCB& done_cb) { |
| 322 scoped_ptr<TextTrack> text_track(new MockTextTrack); |
| 323 done_cb.Run(text_track.Pass()); |
| 324 } |
| 325 |
| 284 // Fixture members. | 326 // Fixture members. |
| 285 StrictMock<CallbackHelper> callbacks_; | 327 StrictMock<CallbackHelper> callbacks_; |
| 286 base::SimpleTestTickClock test_tick_clock_; | 328 base::SimpleTestTickClock test_tick_clock_; |
| 287 base::MessageLoop message_loop_; | 329 base::MessageLoop message_loop_; |
| 288 scoped_ptr<Pipeline> pipeline_; | 330 scoped_ptr<Pipeline> pipeline_; |
| 289 | 331 |
| 290 scoped_ptr<FilterCollection> filter_collection_; | 332 scoped_ptr<FilterCollection> filter_collection_; |
| 291 scoped_ptr<MockDemuxer> demuxer_; | 333 scoped_ptr<MockDemuxer> demuxer_; |
| 292 MockVideoRenderer* video_renderer_; | 334 MockVideoRenderer* video_renderer_; |
| 293 MockAudioRenderer* audio_renderer_; | 335 MockAudioRenderer* audio_renderer_; |
| 336 StrictMock<CallbackHelper> text_renderer_callbacks_; |
| 337 TextRenderer* text_renderer_; |
| 294 scoped_ptr<StrictMock<MockDemuxerStream> > audio_stream_; | 338 scoped_ptr<StrictMock<MockDemuxerStream> > audio_stream_; |
| 295 scoped_ptr<StrictMock<MockDemuxerStream> > video_stream_; | 339 scoped_ptr<StrictMock<MockDemuxerStream> > video_stream_; |
| 340 scoped_ptr<FakeTextTrackStream> text_stream_; |
| 296 AudioRenderer::TimeCB audio_time_cb_; | 341 AudioRenderer::TimeCB audio_time_cb_; |
| 297 VideoDecoderConfig video_decoder_config_; | 342 VideoDecoderConfig video_decoder_config_; |
| 298 | 343 |
| 299 private: | 344 private: |
| 300 DISALLOW_COPY_AND_ASSIGN(PipelineTest); | 345 DISALLOW_COPY_AND_ASSIGN(PipelineTest); |
| 301 }; | 346 }; |
| 302 | 347 |
| 303 // Test that playback controls methods no-op when the pipeline hasn't been | 348 // Test that playback controls methods no-op when the pipeline hasn't been |
| 304 // started. | 349 // started. |
| 305 TEST_F(PipelineTest, NotStarted) { | 350 TEST_F(PipelineTest, NotStarted) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 331 | 376 |
| 332 // Should always get set to zero. | 377 // Should always get set to zero. |
| 333 gfx::Size size(1, 1); | 378 gfx::Size size(1, 1); |
| 334 pipeline_->GetNaturalVideoSize(&size); | 379 pipeline_->GetNaturalVideoSize(&size); |
| 335 EXPECT_EQ(0, size.width()); | 380 EXPECT_EQ(0, size.width()); |
| 336 EXPECT_EQ(0, size.height()); | 381 EXPECT_EQ(0, size.height()); |
| 337 } | 382 } |
| 338 | 383 |
| 339 TEST_F(PipelineTest, NeverInitializes) { | 384 TEST_F(PipelineTest, NeverInitializes) { |
| 340 // Don't execute the callback passed into Initialize(). | 385 // Don't execute the callback passed into Initialize(). |
| 341 EXPECT_CALL(*demuxer_, Initialize(_, _)); | 386 EXPECT_CALL(*demuxer_, Initialize(_, _, _)); |
| 342 | 387 |
| 343 // This test hangs during initialization by never calling | 388 // This test hangs during initialization by never calling |
| 344 // InitializationComplete(). StrictMock<> will ensure that the callback is | 389 // InitializationComplete(). StrictMock<> will ensure that the callback is |
| 345 // never executed. | 390 // never executed. |
| 346 pipeline_->Start( | 391 pipeline_->Start( |
| 347 filter_collection_.Pass(), | 392 filter_collection_.Pass(), |
| 348 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 393 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
| 349 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 394 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |
| 350 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)), | 395 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)), |
| 351 base::Bind(&CallbackHelper::OnBufferingState, | 396 base::Bind(&CallbackHelper::OnBufferingState, |
| 352 base::Unretained(&callbacks_)), | 397 base::Unretained(&callbacks_)), |
| 353 base::Bind(&CallbackHelper::OnDurationChange, | 398 base::Bind(&CallbackHelper::OnDurationChange, |
| 354 base::Unretained(&callbacks_))); | 399 base::Unretained(&callbacks_))); |
| 355 message_loop_.RunUntilIdle(); | 400 message_loop_.RunUntilIdle(); |
| 356 | 401 |
| 357 | 402 |
| 358 // Because our callback will get executed when the test tears down, we'll | 403 // Because our callback will get executed when the test tears down, we'll |
| 359 // verify that nothing has been called, then set our expectation for the call | 404 // verify that nothing has been called, then set our expectation for the call |
| 360 // made during tear down. | 405 // made during tear down. |
| 361 Mock::VerifyAndClear(&callbacks_); | 406 Mock::VerifyAndClear(&callbacks_); |
| 362 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK)); | 407 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK)); |
| 363 } | 408 } |
| 364 | 409 |
| 365 TEST_F(PipelineTest, URLNotFound) { | 410 TEST_F(PipelineTest, URLNotFound) { |
| 366 EXPECT_CALL(*demuxer_, Initialize(_, _)) | 411 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) |
| 367 .WillOnce(RunCallback<1>(PIPELINE_ERROR_URL_NOT_FOUND)); | 412 .WillOnce(RunCallback<1>(PIPELINE_ERROR_URL_NOT_FOUND)); |
| 368 EXPECT_CALL(*demuxer_, Stop(_)) | 413 EXPECT_CALL(*demuxer_, Stop(_)) |
| 369 .WillOnce(RunClosure<0>()); | 414 .WillOnce(RunClosure<0>()); |
| 370 | 415 |
| 371 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); | 416 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); |
| 372 } | 417 } |
| 373 | 418 |
| 374 TEST_F(PipelineTest, NoStreams) { | 419 TEST_F(PipelineTest, NoStreams) { |
| 375 EXPECT_CALL(*demuxer_, Initialize(_, _)) | 420 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) |
| 376 .WillOnce(RunCallback<1>(PIPELINE_OK)); | 421 .WillOnce(RunCallback<1>(PIPELINE_OK)); |
| 377 EXPECT_CALL(*demuxer_, Stop(_)) | 422 EXPECT_CALL(*demuxer_, Stop(_)) |
| 378 .WillOnce(RunClosure<0>()); | 423 .WillOnce(RunClosure<0>()); |
| 379 | 424 |
| 380 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); | 425 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); |
| 381 } | 426 } |
| 382 | 427 |
| 383 TEST_F(PipelineTest, AudioStream) { | 428 TEST_F(PipelineTest, AudioStream) { |
| 384 CreateAudioStream(); | 429 CreateAudioStream(); |
| 385 MockDemuxerStreamVector streams; | 430 MockDemuxerStreamVector streams; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 415 | 460 |
| 416 InitializeDemuxer(&streams); | 461 InitializeDemuxer(&streams); |
| 417 InitializeAudioRenderer(audio_stream(), false); | 462 InitializeAudioRenderer(audio_stream(), false); |
| 418 InitializeVideoRenderer(video_stream()); | 463 InitializeVideoRenderer(video_stream()); |
| 419 | 464 |
| 420 InitializePipeline(PIPELINE_OK); | 465 InitializePipeline(PIPELINE_OK); |
| 421 EXPECT_TRUE(pipeline_->HasAudio()); | 466 EXPECT_TRUE(pipeline_->HasAudio()); |
| 422 EXPECT_TRUE(pipeline_->HasVideo()); | 467 EXPECT_TRUE(pipeline_->HasVideo()); |
| 423 } | 468 } |
| 424 | 469 |
| 470 TEST_F(PipelineTest, VideoTextStream) { |
| 471 CreateVideoStream(); |
| 472 CreateTextStream(); |
| 473 MockDemuxerStreamVector streams; |
| 474 streams.push_back(video_stream()); |
| 475 |
| 476 InitializeDemuxer(&streams); |
| 477 InitializeVideoRenderer(video_stream()); |
| 478 |
| 479 InitializePipeline(PIPELINE_OK); |
| 480 EXPECT_FALSE(pipeline_->HasAudio()); |
| 481 EXPECT_TRUE(pipeline_->HasVideo()); |
| 482 |
| 483 AddTextStream(); |
| 484 message_loop_.RunUntilIdle(); |
| 485 } |
| 486 |
| 487 TEST_F(PipelineTest, VideoAudioTextStream) { |
| 488 CreateVideoStream(); |
| 489 CreateAudioStream(); |
| 490 CreateTextStream(); |
| 491 MockDemuxerStreamVector streams; |
| 492 streams.push_back(video_stream()); |
| 493 streams.push_back(audio_stream()); |
| 494 |
| 495 InitializeDemuxer(&streams); |
| 496 InitializeVideoRenderer(video_stream()); |
| 497 InitializeAudioRenderer(audio_stream(), false); |
| 498 |
| 499 InitializePipeline(PIPELINE_OK); |
| 500 EXPECT_TRUE(pipeline_->HasAudio()); |
| 501 EXPECT_TRUE(pipeline_->HasVideo()); |
| 502 |
| 503 AddTextStream(); |
| 504 message_loop_.RunUntilIdle(); |
| 505 } |
| 506 |
| 425 TEST_F(PipelineTest, Seek) { | 507 TEST_F(PipelineTest, Seek) { |
| 426 CreateAudioStream(); | 508 CreateAudioStream(); |
| 427 CreateVideoStream(); | 509 CreateVideoStream(); |
| 510 CreateTextStream(); |
| 428 MockDemuxerStreamVector streams; | 511 MockDemuxerStreamVector streams; |
| 429 streams.push_back(audio_stream()); | 512 streams.push_back(audio_stream()); |
| 430 streams.push_back(video_stream()); | 513 streams.push_back(video_stream()); |
| 431 | 514 |
| 432 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); | 515 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); |
| 433 InitializeAudioRenderer(audio_stream(), false); | 516 InitializeAudioRenderer(audio_stream(), false); |
| 434 InitializeVideoRenderer(video_stream()); | 517 InitializeVideoRenderer(video_stream()); |
| 435 | 518 |
| 436 // Initialize then seek! | 519 // Initialize then seek! |
| 437 InitializePipeline(PIPELINE_OK); | 520 InitializePipeline(PIPELINE_OK); |
| 438 | 521 |
| 522 AddTextStream(); |
| 523 message_loop_.RunUntilIdle(); |
| 524 |
| 439 // Every filter should receive a call to Seek(). | 525 // Every filter should receive a call to Seek(). |
| 440 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); | 526 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); |
| 441 ExpectSeek(expected); | 527 ExpectSeek(expected); |
| 442 DoSeek(expected); | 528 DoSeek(expected); |
| 443 } | 529 } |
| 444 | 530 |
| 445 TEST_F(PipelineTest, SetVolume) { | 531 TEST_F(PipelineTest, SetVolume) { |
| 446 CreateAudioStream(); | 532 CreateAudioStream(); |
| 447 MockDemuxerStreamVector streams; | 533 MockDemuxerStreamVector streams; |
| 448 streams.push_back(audio_stream()); | 534 streams.push_back(audio_stream()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 EXPECT_TRUE(pipeline_->HasVideo()); | 653 EXPECT_TRUE(pipeline_->HasVideo()); |
| 568 | 654 |
| 569 // Verify that ended event is fired when video ends. | 655 // Verify that ended event is fired when video ends. |
| 570 EXPECT_CALL(callbacks_, OnEnded()); | 656 EXPECT_CALL(callbacks_, OnEnded()); |
| 571 pipeline_->OnVideoRendererEnded(); | 657 pipeline_->OnVideoRendererEnded(); |
| 572 } | 658 } |
| 573 | 659 |
| 574 TEST_F(PipelineTest, EndedCallback) { | 660 TEST_F(PipelineTest, EndedCallback) { |
| 575 CreateAudioStream(); | 661 CreateAudioStream(); |
| 576 CreateVideoStream(); | 662 CreateVideoStream(); |
| 663 CreateTextStream(); |
| 577 MockDemuxerStreamVector streams; | 664 MockDemuxerStreamVector streams; |
| 578 streams.push_back(audio_stream()); | 665 streams.push_back(audio_stream()); |
| 579 streams.push_back(video_stream()); | 666 streams.push_back(video_stream()); |
| 580 | 667 |
| 581 InitializeDemuxer(&streams); | 668 InitializeDemuxer(&streams); |
| 582 InitializeAudioRenderer(audio_stream(), false); | 669 InitializeAudioRenderer(audio_stream(), false); |
| 583 InitializeVideoRenderer(video_stream()); | 670 InitializeVideoRenderer(video_stream()); |
| 584 InitializePipeline(PIPELINE_OK); | 671 InitializePipeline(PIPELINE_OK); |
| 585 | 672 |
| 586 // The ended callback shouldn't run until both renderers have ended. | 673 AddTextStream(); |
| 674 |
| 675 // The ended callback shouldn't run until all renderers have ended. |
| 587 pipeline_->OnAudioRendererEnded(); | 676 pipeline_->OnAudioRendererEnded(); |
| 588 message_loop_.RunUntilIdle(); | 677 message_loop_.RunUntilIdle(); |
| 589 | 678 |
| 679 pipeline_->OnVideoRendererEnded(); |
| 680 message_loop_.RunUntilIdle(); |
| 681 |
| 590 EXPECT_CALL(callbacks_, OnEnded()); | 682 EXPECT_CALL(callbacks_, OnEnded()); |
| 591 pipeline_->OnVideoRendererEnded(); | 683 text_stream()->SendEosNotification(); |
| 592 message_loop_.RunUntilIdle(); | 684 message_loop_.RunUntilIdle(); |
| 593 } | 685 } |
| 594 | 686 |
| 595 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { | 687 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { |
| 596 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); | 688 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); |
| 597 | 689 |
| 598 CreateAudioStream(); | 690 CreateAudioStream(); |
| 599 CreateVideoStream(); | 691 CreateVideoStream(); |
| 600 MockDemuxerStreamVector streams; | 692 MockDemuxerStreamVector streams; |
| 601 streams.push_back(audio_stream()); | 693 streams.push_back(audio_stream()); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 } | 1008 } |
| 917 | 1009 |
| 918 PipelineStatus SetInitializeExpectations(TeardownState state, | 1010 PipelineStatus SetInitializeExpectations(TeardownState state, |
| 919 StopOrError stop_or_error) { | 1011 StopOrError stop_or_error) { |
| 920 PipelineStatus status = PIPELINE_OK; | 1012 PipelineStatus status = PIPELINE_OK; |
| 921 base::Closure stop_cb = base::Bind( | 1013 base::Closure stop_cb = base::Bind( |
| 922 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); | 1014 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); |
| 923 | 1015 |
| 924 if (state == kInitDemuxer) { | 1016 if (state == kInitDemuxer) { |
| 925 if (stop_or_error == kStop) { | 1017 if (stop_or_error == kStop) { |
| 926 EXPECT_CALL(*demuxer_, Initialize(_, _)) | 1018 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) |
| 927 .WillOnce(DoAll(Stop(pipeline_.get(), stop_cb), | 1019 .WillOnce(DoAll(Stop(pipeline_.get(), stop_cb), |
| 928 RunCallback<1>(PIPELINE_OK))); | 1020 RunCallback<1>(PIPELINE_OK))); |
| 929 EXPECT_CALL(callbacks_, OnStop()); | 1021 EXPECT_CALL(callbacks_, OnStop()); |
| 930 } else { | 1022 } else { |
| 931 status = DEMUXER_ERROR_COULD_NOT_OPEN; | 1023 status = DEMUXER_ERROR_COULD_NOT_OPEN; |
| 932 EXPECT_CALL(*demuxer_, Initialize(_, _)) | 1024 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) |
| 933 .WillOnce(RunCallback<1>(status)); | 1025 .WillOnce(RunCallback<1>(status)); |
| 934 } | 1026 } |
| 935 | 1027 |
| 936 EXPECT_CALL(*demuxer_, Stop(_)).WillOnce(RunClosure<0>()); | 1028 EXPECT_CALL(*demuxer_, Stop(_)).WillOnce(RunClosure<0>()); |
| 937 return status; | 1029 return status; |
| 938 } | 1030 } |
| 939 | 1031 |
| 940 CreateAudioStream(); | 1032 CreateAudioStream(); |
| 941 CreateVideoStream(); | 1033 CreateVideoStream(); |
| 942 MockDemuxerStreamVector streams; | 1034 MockDemuxerStreamVector streams; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); | 1267 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); |
| 1176 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); | 1268 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); |
| 1177 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1269 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
| 1178 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); | 1270 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); |
| 1179 INSTANTIATE_TEARDOWN_TEST(Error, Starting); | 1271 INSTANTIATE_TEARDOWN_TEST(Error, Starting); |
| 1180 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1272 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
| 1181 | 1273 |
| 1182 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); | 1274 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); |
| 1183 | 1275 |
| 1184 } // namespace media | 1276 } // namespace media |
| OLD | NEW |