| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "media/base/pipeline_impl.h" | 9 #include "media/base/pipeline_impl.h" |
| 10 #include "media/base/media_format.h" | 10 #include "media/base/media_format.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 &CallbackHelper::OnStop)); | 83 &CallbackHelper::OnStop)); |
| 84 message_loop_.RunAllPending(); | 84 message_loop_.RunAllPending(); |
| 85 | 85 |
| 86 // Free allocated media formats (if any). | 86 // Free allocated media formats (if any). |
| 87 STLDeleteElements(&stream_media_formats_); | 87 STLDeleteElements(&stream_media_formats_); |
| 88 | 88 |
| 89 mocks_.reset(); | 89 mocks_.reset(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 protected: | 92 protected: |
| 93 // Sets up expectations to allow the data source to initialize. | |
| 94 void InitializeDataSource() { | |
| 95 mocks_->data_source()->SetTotalAndBufferedBytes(kTotalBytes, | |
| 96 kBufferedBytes); | |
| 97 | |
| 98 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); | |
| 99 EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull())) | |
| 100 .WillOnce(Invoke(&RunFilterCallback)); | |
| 101 EXPECT_CALL(*mocks_->data_source(), Stop(NotNull())) | |
| 102 .WillOnce(Invoke(&RunStopFilterCallback)); | |
| 103 } | |
| 104 | |
| 105 // Sets up expectations to allow the demuxer to initialize. | 93 // Sets up expectations to allow the demuxer to initialize. |
| 106 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 94 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
| 107 void InitializeDemuxer(MockDemuxerStreamVector* streams, | 95 void InitializeDemuxer(MockDemuxerStreamVector* streams, |
| 108 const base::TimeDelta& duration) { | 96 const base::TimeDelta& duration) { |
| 109 EXPECT_CALL(*mocks_->demuxer(), | 97 mocks_->demuxer()->SetTotalAndBufferedBytesAndDuration( |
| 110 Initialize(mocks_->data_source(), NotNull())) | 98 kTotalBytes, kBufferedBytes, duration); |
| 111 .WillOnce(DoAll(SetDuration(mocks_->data_source(), duration), | |
| 112 Invoke(&RunFilterCallback))); | |
| 113 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) | 99 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) |
| 114 .WillRepeatedly(Return(streams->size())); | 100 .WillRepeatedly(Return(streams->size())); |
| 115 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 101 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |
| 116 EXPECT_CALL(*mocks_->demuxer(), Seek(base::TimeDelta(), NotNull())) | 102 EXPECT_CALL(*mocks_->demuxer(), Seek(base::TimeDelta(), NotNull())) |
| 117 .WillOnce(Invoke(&RunFilterCallback)); | 103 .WillOnce(Invoke(&RunFilterCallback)); |
| 118 EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull())) | 104 EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull())) |
| 119 .WillOnce(Invoke(&RunStopFilterCallback)); | 105 .WillOnce(Invoke(&RunStopFilterCallback)); |
| 120 | 106 |
| 121 // Configure the demuxer to return the streams. | 107 // Configure the demuxer to return the streams. |
| 122 for (size_t i = 0; i < streams->size(); ++i) { | 108 for (size_t i = 0; i < streams->size(); ++i) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 MockDemuxerStream* audio_stream() { | 211 MockDemuxerStream* audio_stream() { |
| 226 return audio_stream_; | 212 return audio_stream_; |
| 227 } | 213 } |
| 228 | 214 |
| 229 MockDemuxerStream* video_stream() { | 215 MockDemuxerStream* video_stream() { |
| 230 return video_stream_; | 216 return video_stream_; |
| 231 } | 217 } |
| 232 | 218 |
| 233 void ExpectSeek(const base::TimeDelta& seek_time) { | 219 void ExpectSeek(const base::TimeDelta& seek_time) { |
| 234 // Every filter should receive a call to Seek(). | 220 // Every filter should receive a call to Seek(). |
| 235 EXPECT_CALL(*mocks_->data_source(), Seek(seek_time, NotNull())) | |
| 236 .WillOnce(Invoke(&RunFilterCallback)); | |
| 237 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, NotNull())) | 221 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, NotNull())) |
| 238 .WillOnce(Invoke(&RunFilterCallback)); | 222 .WillOnce(Invoke(&RunFilterCallback)); |
| 239 | 223 |
| 240 if (audio_stream_) { | 224 if (audio_stream_) { |
| 241 EXPECT_CALL(*mocks_->audio_decoder(), Seek(seek_time, NotNull())) | 225 EXPECT_CALL(*mocks_->audio_decoder(), Seek(seek_time, NotNull())) |
| 242 .WillOnce(Invoke(&RunFilterCallback)); | 226 .WillOnce(Invoke(&RunFilterCallback)); |
| 243 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, NotNull())) | 227 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, NotNull())) |
| 244 .WillOnce(Invoke(&RunFilterCallback)); | 228 .WillOnce(Invoke(&RunFilterCallback)); |
| 245 } | 229 } |
| 246 | 230 |
| 247 if (video_stream_) { | 231 if (video_stream_) { |
| 248 EXPECT_CALL(*mocks_->video_decoder(), Seek(seek_time, NotNull())) | 232 EXPECT_CALL(*mocks_->video_decoder(), Seek(seek_time, NotNull())) |
| 249 .WillOnce(Invoke(&RunFilterCallback)); | 233 .WillOnce(Invoke(&RunFilterCallback)); |
| 250 EXPECT_CALL(*mocks_->video_renderer(), Seek(seek_time, NotNull())) | 234 EXPECT_CALL(*mocks_->video_renderer(), Seek(seek_time, NotNull())) |
| 251 .WillOnce(Invoke(&RunFilterCallback)); | 235 .WillOnce(Invoke(&RunFilterCallback)); |
| 252 } | 236 } |
| 253 | 237 |
| 254 // We expect a successful seek callback. | 238 // We expect a successful seek callback. |
| 255 EXPECT_CALL(callbacks_, OnSeek()); | 239 EXPECT_CALL(callbacks_, OnSeek()); |
| 256 | 240 |
| 257 } | 241 } |
| 258 | 242 |
| 259 void DoSeek(const base::TimeDelta& seek_time) { | 243 void DoSeek(const base::TimeDelta& seek_time) { |
| 260 pipeline_->Seek(seek_time, | 244 pipeline_->Seek(seek_time, |
| 261 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 245 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
| 262 &CallbackHelper::OnSeek)); | 246 &CallbackHelper::OnSeek)); |
| 263 | 247 |
| 264 // We expect the time to be updated only after the seek has completed. | 248 // We expect the time to be updated only after the seek has completed. |
| 265 EXPECT_TRUE(seek_time != pipeline_->GetCurrentTime()); | 249 EXPECT_NE(seek_time, pipeline_->GetCurrentTime()); |
| 266 message_loop_.RunAllPending(); | 250 message_loop_.RunAllPending(); |
| 267 EXPECT_TRUE(seek_time == pipeline_->GetCurrentTime()); | 251 EXPECT_EQ(seek_time, pipeline_->GetCurrentTime()); |
| 268 } | 252 } |
| 269 | 253 |
| 270 // Fixture members. | 254 // Fixture members. |
| 271 StrictMock<CallbackHelper> callbacks_; | 255 StrictMock<CallbackHelper> callbacks_; |
| 272 MessageLoop message_loop_; | 256 MessageLoop message_loop_; |
| 273 scoped_refptr<PipelineImpl> pipeline_; | 257 scoped_refptr<PipelineImpl> pipeline_; |
| 274 scoped_ptr<media::MockFilterCollection> mocks_; | 258 scoped_ptr<media::MockFilterCollection> mocks_; |
| 275 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; | 259 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; |
| 276 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; | 260 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; |
| 277 | 261 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 EXPECT_CALL(callbacks_, OnError()); | 362 EXPECT_CALL(callbacks_, OnError()); |
| 379 | 363 |
| 380 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); | 364 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); |
| 381 EXPECT_FALSE(pipeline_->IsInitialized()); | 365 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 382 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError()); | 366 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError()); |
| 383 } | 367 } |
| 384 | 368 |
| 385 TEST_F(PipelineImplTest, NoStreams) { | 369 TEST_F(PipelineImplTest, NoStreams) { |
| 386 // Manually set these expectations because SetPlaybackRate() is not called if | 370 // Manually set these expectations because SetPlaybackRate() is not called if |
| 387 // we cannot fully initialize the pipeline. | 371 // we cannot fully initialize the pipeline. |
| 388 EXPECT_CALL(*mocks_->data_source(), Stop(NotNull())) | |
| 389 .WillOnce(Invoke(&RunStopFilterCallback)); | |
| 390 | |
| 391 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull())) | |
| 392 .WillOnce(Invoke(&RunFilterCallback)); | |
| 393 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) | 372 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) |
| 394 .WillRepeatedly(Return(0)); | 373 .WillRepeatedly(Return(0)); |
| 395 EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull())) | 374 EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull())) |
| 396 .WillOnce(Invoke(&RunStopFilterCallback)); | 375 .WillOnce(Invoke(&RunStopFilterCallback)); |
| 397 EXPECT_CALL(callbacks_, OnError()); | 376 EXPECT_CALL(callbacks_, OnError()); |
| 398 | 377 |
| 399 InitializePipeline(); | 378 InitializePipeline(); |
| 400 EXPECT_FALSE(pipeline_->IsInitialized()); | 379 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 401 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError()); | 380 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError()); |
| 402 } | 381 } |
| 403 | 382 |
| 404 TEST_F(PipelineImplTest, AudioStream) { | 383 TEST_F(PipelineImplTest, AudioStream) { |
| 405 CreateAudioStream(); | 384 CreateAudioStream(); |
| 406 MockDemuxerStreamVector streams; | 385 MockDemuxerStreamVector streams; |
| 407 streams.push_back(audio_stream()); | 386 streams.push_back(audio_stream()); |
| 408 | 387 |
| 409 InitializeDataSource(); | |
| 410 InitializeDemuxer(&streams, base::TimeDelta()); | 388 InitializeDemuxer(&streams, base::TimeDelta()); |
| 411 InitializeAudioDecoder(audio_stream()); | 389 InitializeAudioDecoder(audio_stream()); |
| 412 InitializeAudioRenderer(); | 390 InitializeAudioRenderer(); |
| 413 | 391 |
| 414 InitializePipeline(); | 392 InitializePipeline(); |
| 415 EXPECT_TRUE(pipeline_->IsInitialized()); | 393 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 416 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 394 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 417 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); | 395 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); |
| 418 EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); | 396 EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); |
| 419 } | 397 } |
| 420 | 398 |
| 421 TEST_F(PipelineImplTest, VideoStream) { | 399 TEST_F(PipelineImplTest, VideoStream) { |
| 422 CreateVideoStream(); | 400 CreateVideoStream(); |
| 423 MockDemuxerStreamVector streams; | 401 MockDemuxerStreamVector streams; |
| 424 streams.push_back(video_stream()); | 402 streams.push_back(video_stream()); |
| 425 | 403 |
| 426 InitializeDataSource(); | |
| 427 InitializeDemuxer(&streams, base::TimeDelta()); | 404 InitializeDemuxer(&streams, base::TimeDelta()); |
| 428 InitializeVideoDecoder(video_stream()); | 405 InitializeVideoDecoder(video_stream()); |
| 429 InitializeVideoRenderer(); | 406 InitializeVideoRenderer(); |
| 430 | 407 |
| 431 InitializePipeline(); | 408 InitializePipeline(); |
| 432 EXPECT_TRUE(pipeline_->IsInitialized()); | 409 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 433 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 410 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 434 EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); | 411 EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); |
| 435 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); | 412 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); |
| 436 } | 413 } |
| 437 | 414 |
| 438 TEST_F(PipelineImplTest, AudioVideoStream) { | 415 TEST_F(PipelineImplTest, AudioVideoStream) { |
| 439 CreateAudioStream(); | 416 CreateAudioStream(); |
| 440 CreateVideoStream(); | 417 CreateVideoStream(); |
| 441 MockDemuxerStreamVector streams; | 418 MockDemuxerStreamVector streams; |
| 442 streams.push_back(audio_stream()); | 419 streams.push_back(audio_stream()); |
| 443 streams.push_back(video_stream()); | 420 streams.push_back(video_stream()); |
| 444 | 421 |
| 445 InitializeDataSource(); | |
| 446 InitializeDemuxer(&streams, base::TimeDelta()); | 422 InitializeDemuxer(&streams, base::TimeDelta()); |
| 447 InitializeAudioDecoder(audio_stream()); | 423 InitializeAudioDecoder(audio_stream()); |
| 448 InitializeAudioRenderer(); | 424 InitializeAudioRenderer(); |
| 449 InitializeVideoDecoder(video_stream()); | 425 InitializeVideoDecoder(video_stream()); |
| 450 InitializeVideoRenderer(); | 426 InitializeVideoRenderer(); |
| 451 | 427 |
| 452 InitializePipeline(); | 428 InitializePipeline(); |
| 453 EXPECT_TRUE(pipeline_->IsInitialized()); | 429 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 454 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 430 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 455 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); | 431 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); |
| 456 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); | 432 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); |
| 457 } | 433 } |
| 458 | 434 |
| 459 TEST_F(PipelineImplTest, Seek) { | 435 TEST_F(PipelineImplTest, Seek) { |
| 460 CreateAudioStream(); | 436 CreateAudioStream(); |
| 461 CreateVideoStream(); | 437 CreateVideoStream(); |
| 462 MockDemuxerStreamVector streams; | 438 MockDemuxerStreamVector streams; |
| 463 streams.push_back(audio_stream()); | 439 streams.push_back(audio_stream()); |
| 464 streams.push_back(video_stream()); | 440 streams.push_back(video_stream()); |
| 465 | 441 |
| 466 InitializeDataSource(); | |
| 467 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); | 442 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); |
| 468 InitializeAudioDecoder(audio_stream()); | 443 InitializeAudioDecoder(audio_stream()); |
| 469 InitializeAudioRenderer(); | 444 InitializeAudioRenderer(); |
| 470 InitializeVideoDecoder(video_stream()); | 445 InitializeVideoDecoder(video_stream()); |
| 471 InitializeVideoRenderer(); | 446 InitializeVideoRenderer(); |
| 472 | 447 |
| 473 // Every filter should receive a call to Seek(). | 448 // Every filter should receive a call to Seek(). |
| 474 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); | 449 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); |
| 475 ExpectSeek(expected); | 450 ExpectSeek(expected); |
| 476 | 451 |
| 477 // Initialize then seek! | 452 // Initialize then seek! |
| 478 InitializePipeline(); | 453 InitializePipeline(); |
| 479 DoSeek(expected); | 454 DoSeek(expected); |
| 480 } | 455 } |
| 481 | 456 |
| 482 TEST_F(PipelineImplTest, SetVolume) { | 457 TEST_F(PipelineImplTest, SetVolume) { |
| 483 CreateAudioStream(); | 458 CreateAudioStream(); |
| 484 MockDemuxerStreamVector streams; | 459 MockDemuxerStreamVector streams; |
| 485 streams.push_back(audio_stream()); | 460 streams.push_back(audio_stream()); |
| 486 | 461 |
| 487 InitializeDataSource(); | |
| 488 InitializeDemuxer(&streams, base::TimeDelta()); | 462 InitializeDemuxer(&streams, base::TimeDelta()); |
| 489 InitializeAudioDecoder(audio_stream()); | 463 InitializeAudioDecoder(audio_stream()); |
| 490 InitializeAudioRenderer(); | 464 InitializeAudioRenderer(); |
| 491 | 465 |
| 492 // The audio renderer should receive a call to SetVolume(). | 466 // The audio renderer should receive a call to SetVolume(). |
| 493 float expected = 0.5f; | 467 float expected = 0.5f; |
| 494 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); | 468 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); |
| 495 | 469 |
| 496 // Initialize then set volume! | 470 // Initialize then set volume! |
| 497 InitializePipeline(); | 471 InitializePipeline(); |
| 498 pipeline_->SetVolume(expected); | 472 pipeline_->SetVolume(expected); |
| 499 } | 473 } |
| 500 | 474 |
| 501 TEST_F(PipelineImplTest, Properties) { | 475 TEST_F(PipelineImplTest, Properties) { |
| 502 CreateVideoStream(); | 476 CreateVideoStream(); |
| 503 MockDemuxerStreamVector streams; | 477 MockDemuxerStreamVector streams; |
| 504 streams.push_back(video_stream()); | 478 streams.push_back(video_stream()); |
| 505 | 479 |
| 506 InitializeDataSource(); | |
| 507 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 480 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 508 InitializeDemuxer(&streams, kDuration); | 481 InitializeDemuxer(&streams, kDuration); |
| 509 InitializeVideoDecoder(video_stream()); | 482 InitializeVideoDecoder(video_stream()); |
| 510 InitializeVideoRenderer(); | 483 InitializeVideoRenderer(); |
| 511 | 484 |
| 512 InitializePipeline(); | 485 InitializePipeline(); |
| 513 EXPECT_TRUE(pipeline_->IsInitialized()); | 486 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 514 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 487 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 515 EXPECT_EQ(kDuration.ToInternalValue(), | 488 EXPECT_EQ(kDuration.ToInternalValue(), |
| 516 pipeline_->GetMediaDuration().ToInternalValue()); | 489 pipeline_->GetMediaDuration().ToInternalValue()); |
| 517 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); | 490 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); |
| 518 EXPECT_EQ(kBufferedBytes, pipeline_->GetBufferedBytes()); | 491 EXPECT_EQ(kBufferedBytes, pipeline_->GetBufferedBytes()); |
| 519 | 492 |
| 520 // Because kTotalBytes and kBufferedBytes are equal to each other, | 493 // Because kTotalBytes and kBufferedBytes are equal to each other, |
| 521 // the entire video should be buffered. | 494 // the entire video should be buffered. |
| 522 EXPECT_EQ(kDuration.ToInternalValue(), | 495 EXPECT_EQ(kDuration.ToInternalValue(), |
| 523 pipeline_->GetBufferedTime().ToInternalValue()); | 496 pipeline_->GetBufferedTime().ToInternalValue()); |
| 524 } | 497 } |
| 525 | 498 |
| 526 TEST_F(PipelineImplTest, GetBufferedTime) { | 499 TEST_F(PipelineImplTest, GetBufferedTime) { |
| 527 CreateVideoStream(); | 500 CreateVideoStream(); |
| 528 MockDemuxerStreamVector streams; | 501 MockDemuxerStreamVector streams; |
| 529 streams.push_back(video_stream()); | 502 streams.push_back(video_stream()); |
| 530 | 503 |
| 531 InitializeDataSource(); | |
| 532 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 504 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 533 InitializeDemuxer(&streams, kDuration); | 505 InitializeDemuxer(&streams, kDuration); |
| 534 InitializeVideoDecoder(video_stream()); | 506 InitializeVideoDecoder(video_stream()); |
| 535 InitializeVideoRenderer(); | 507 InitializeVideoRenderer(); |
| 536 | 508 |
| 537 InitializePipeline(); | 509 InitializePipeline(); |
| 538 EXPECT_TRUE(pipeline_->IsInitialized()); | 510 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 539 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 511 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 540 | 512 |
| 541 // TODO(vrk): The following mini-test cases are order-dependent, and should | 513 // TODO(vrk): The following mini-test cases are order-dependent, and should |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 pipeline_->GetBufferedTime().ToInternalValue()); | 563 pipeline_->GetBufferedTime().ToInternalValue()); |
| 592 } | 564 } |
| 593 | 565 |
| 594 TEST_F(PipelineImplTest, DisableAudioRenderer) { | 566 TEST_F(PipelineImplTest, DisableAudioRenderer) { |
| 595 CreateAudioStream(); | 567 CreateAudioStream(); |
| 596 CreateVideoStream(); | 568 CreateVideoStream(); |
| 597 MockDemuxerStreamVector streams; | 569 MockDemuxerStreamVector streams; |
| 598 streams.push_back(audio_stream()); | 570 streams.push_back(audio_stream()); |
| 599 streams.push_back(video_stream()); | 571 streams.push_back(video_stream()); |
| 600 | 572 |
| 601 InitializeDataSource(); | |
| 602 InitializeDemuxer(&streams, base::TimeDelta()); | 573 InitializeDemuxer(&streams, base::TimeDelta()); |
| 603 InitializeAudioDecoder(audio_stream()); | 574 InitializeAudioDecoder(audio_stream()); |
| 604 InitializeAudioRenderer(); | 575 InitializeAudioRenderer(); |
| 605 InitializeVideoDecoder(video_stream()); | 576 InitializeVideoDecoder(video_stream()); |
| 606 InitializeVideoRenderer(); | 577 InitializeVideoRenderer(); |
| 607 | 578 |
| 608 InitializePipeline(); | 579 InitializePipeline(); |
| 609 EXPECT_TRUE(pipeline_->IsInitialized()); | 580 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 610 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 581 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 611 EXPECT_TRUE(pipeline_->IsRendered(mime_type::kMajorTypeAudio)); | 582 EXPECT_TRUE(pipeline_->IsRendered(mime_type::kMajorTypeAudio)); |
| 612 EXPECT_TRUE(pipeline_->IsRendered(mime_type::kMajorTypeVideo)); | 583 EXPECT_TRUE(pipeline_->IsRendered(mime_type::kMajorTypeVideo)); |
| 613 | 584 |
| 614 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(1.0f)) | 585 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(1.0f)) |
| 615 .WillOnce(DisableAudioRenderer(mocks_->audio_renderer())); | 586 .WillOnce(DisableAudioRenderer(mocks_->audio_renderer())); |
| 616 EXPECT_CALL(*mocks_->data_source(), | |
| 617 OnAudioRendererDisabled()); | |
| 618 EXPECT_CALL(*mocks_->demuxer(), | 587 EXPECT_CALL(*mocks_->demuxer(), |
| 619 OnAudioRendererDisabled()); | 588 OnAudioRendererDisabled()); |
| 620 EXPECT_CALL(*mocks_->audio_decoder(), | 589 EXPECT_CALL(*mocks_->audio_decoder(), |
| 621 OnAudioRendererDisabled()); | 590 OnAudioRendererDisabled()); |
| 622 EXPECT_CALL(*mocks_->audio_renderer(), | 591 EXPECT_CALL(*mocks_->audio_renderer(), |
| 623 OnAudioRendererDisabled()); | 592 OnAudioRendererDisabled()); |
| 624 EXPECT_CALL(*mocks_->video_decoder(), | 593 EXPECT_CALL(*mocks_->video_decoder(), |
| 625 OnAudioRendererDisabled()); | 594 OnAudioRendererDisabled()); |
| 626 EXPECT_CALL(*mocks_->video_renderer(), | 595 EXPECT_CALL(*mocks_->video_renderer(), |
| 627 OnAudioRendererDisabled()); | 596 OnAudioRendererDisabled()); |
| 628 | 597 |
| 629 mocks_->audio_renderer()->SetPlaybackRate(1.0f); | 598 mocks_->audio_renderer()->SetPlaybackRate(1.0f); |
| 630 | 599 |
| 631 // Verify that ended event is fired when video ends. | 600 // Verify that ended event is fired when video ends. |
| 632 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 601 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
| 633 .WillOnce(Return(true)); | 602 .WillOnce(Return(true)); |
| 634 EXPECT_CALL(callbacks_, OnEnded()); | 603 EXPECT_CALL(callbacks_, OnEnded()); |
| 635 FilterHost* host = pipeline_; | 604 FilterHost* host = pipeline_; |
| 636 host->NotifyEnded(); | 605 host->NotifyEnded(); |
| 637 } | 606 } |
| 638 | 607 |
| 639 TEST_F(PipelineImplTest, DisableAudioRendererDuringInit) { | 608 TEST_F(PipelineImplTest, DisableAudioRendererDuringInit) { |
| 640 CreateAudioStream(); | 609 CreateAudioStream(); |
| 641 CreateVideoStream(); | 610 CreateVideoStream(); |
| 642 MockDemuxerStreamVector streams; | 611 MockDemuxerStreamVector streams; |
| 643 streams.push_back(audio_stream()); | 612 streams.push_back(audio_stream()); |
| 644 streams.push_back(video_stream()); | 613 streams.push_back(video_stream()); |
| 645 | 614 |
| 646 InitializeDataSource(); | |
| 647 InitializeDemuxer(&streams, base::TimeDelta()); | 615 InitializeDemuxer(&streams, base::TimeDelta()); |
| 648 InitializeAudioDecoder(audio_stream()); | 616 InitializeAudioDecoder(audio_stream()); |
| 649 InitializeAudioRenderer(true); | 617 InitializeAudioRenderer(true); |
| 650 InitializeVideoDecoder(video_stream()); | 618 InitializeVideoDecoder(video_stream()); |
| 651 InitializeVideoRenderer(); | 619 InitializeVideoRenderer(); |
| 652 | 620 |
| 653 EXPECT_CALL(*mocks_->data_source(), | |
| 654 OnAudioRendererDisabled()); | |
| 655 EXPECT_CALL(*mocks_->demuxer(), | 621 EXPECT_CALL(*mocks_->demuxer(), |
| 656 OnAudioRendererDisabled()); | 622 OnAudioRendererDisabled()); |
| 657 EXPECT_CALL(*mocks_->audio_decoder(), | 623 EXPECT_CALL(*mocks_->audio_decoder(), |
| 658 OnAudioRendererDisabled()); | 624 OnAudioRendererDisabled()); |
| 659 EXPECT_CALL(*mocks_->audio_renderer(), | 625 EXPECT_CALL(*mocks_->audio_renderer(), |
| 660 OnAudioRendererDisabled()); | 626 OnAudioRendererDisabled()); |
| 661 EXPECT_CALL(*mocks_->video_decoder(), | 627 EXPECT_CALL(*mocks_->video_decoder(), |
| 662 OnAudioRendererDisabled()); | 628 OnAudioRendererDisabled()); |
| 663 EXPECT_CALL(*mocks_->video_renderer(), | 629 EXPECT_CALL(*mocks_->video_renderer(), |
| 664 OnAudioRendererDisabled()); | 630 OnAudioRendererDisabled()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 677 host->NotifyEnded(); | 643 host->NotifyEnded(); |
| 678 } | 644 } |
| 679 | 645 |
| 680 TEST_F(PipelineImplTest, EndedCallback) { | 646 TEST_F(PipelineImplTest, EndedCallback) { |
| 681 CreateAudioStream(); | 647 CreateAudioStream(); |
| 682 CreateVideoStream(); | 648 CreateVideoStream(); |
| 683 MockDemuxerStreamVector streams; | 649 MockDemuxerStreamVector streams; |
| 684 streams.push_back(audio_stream()); | 650 streams.push_back(audio_stream()); |
| 685 streams.push_back(video_stream()); | 651 streams.push_back(video_stream()); |
| 686 | 652 |
| 687 InitializeDataSource(); | |
| 688 InitializeDemuxer(&streams, base::TimeDelta()); | 653 InitializeDemuxer(&streams, base::TimeDelta()); |
| 689 InitializeAudioDecoder(audio_stream()); | 654 InitializeAudioDecoder(audio_stream()); |
| 690 InitializeAudioRenderer(); | 655 InitializeAudioRenderer(); |
| 691 InitializeVideoDecoder(video_stream()); | 656 InitializeVideoDecoder(video_stream()); |
| 692 InitializeVideoRenderer(); | 657 InitializeVideoRenderer(); |
| 693 InitializePipeline(); | 658 InitializePipeline(); |
| 694 | 659 |
| 695 // For convenience to simulate filters calling the methods. | 660 // For convenience to simulate filters calling the methods. |
| 696 FilterHost* host = pipeline_; | 661 FilterHost* host = pipeline_; |
| 697 | 662 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 723 | 688 |
| 724 TEST_F(PipelineImplTest, AudioStreamShorterThanVideo) { | 689 TEST_F(PipelineImplTest, AudioStreamShorterThanVideo) { |
| 725 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); | 690 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); |
| 726 | 691 |
| 727 CreateAudioStream(); | 692 CreateAudioStream(); |
| 728 CreateVideoStream(); | 693 CreateVideoStream(); |
| 729 MockDemuxerStreamVector streams; | 694 MockDemuxerStreamVector streams; |
| 730 streams.push_back(audio_stream()); | 695 streams.push_back(audio_stream()); |
| 731 streams.push_back(video_stream()); | 696 streams.push_back(video_stream()); |
| 732 | 697 |
| 733 InitializeDataSource(); | |
| 734 InitializeDemuxer(&streams, duration); | 698 InitializeDemuxer(&streams, duration); |
| 735 InitializeAudioDecoder(audio_stream()); | 699 InitializeAudioDecoder(audio_stream()); |
| 736 InitializeAudioRenderer(); | 700 InitializeAudioRenderer(); |
| 737 InitializeVideoDecoder(video_stream()); | 701 InitializeVideoDecoder(video_stream()); |
| 738 InitializeVideoRenderer(); | 702 InitializeVideoRenderer(); |
| 739 InitializePipeline(); | 703 InitializePipeline(); |
| 740 | 704 |
| 741 // For convenience to simulate filters calling the methods. | 705 // For convenience to simulate filters calling the methods. |
| 742 FilterHost* host = pipeline_; | 706 FilterHost* host = pipeline_; |
| 743 | 707 |
| 744 // Replace the clock so we can simulate wallclock time advancing w/o using | 708 // Replace the clock so we can simulate wallclock time advancing w/o using |
| 745 // Sleep(). | 709 // Sleep(). |
| 746 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); | 710 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); |
| 747 | 711 |
| 748 EXPECT_EQ(0, host->GetTime().ToInternalValue()); | 712 EXPECT_EQ(0, host->GetTime().ToInternalValue()); |
| 749 | 713 |
| 750 float playback_rate = 1.0f; | 714 float playback_rate = 1.0f; |
| 751 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(playback_rate)); | |
| 752 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 715 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| 753 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(playback_rate)); | 716 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(playback_rate)); |
| 754 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(playback_rate)); | 717 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(playback_rate)); |
| 755 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(playback_rate)); | 718 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(playback_rate)); |
| 756 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 719 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
| 757 pipeline_->SetPlaybackRate(playback_rate); | 720 pipeline_->SetPlaybackRate(playback_rate); |
| 758 message_loop_.RunAllPending(); | 721 message_loop_.RunAllPending(); |
| 759 | 722 |
| 760 InSequence s; | 723 InSequence s; |
| 761 | 724 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 787 .WillOnce(Return(true)); | 750 .WillOnce(Return(true)); |
| 788 EXPECT_CALL(callbacks_, OnEnded()); | 751 EXPECT_CALL(callbacks_, OnEnded()); |
| 789 host->NotifyEnded(); | 752 host->NotifyEnded(); |
| 790 } | 753 } |
| 791 | 754 |
| 792 TEST_F(PipelineImplTest, ErrorDuringSeek) { | 755 TEST_F(PipelineImplTest, ErrorDuringSeek) { |
| 793 CreateAudioStream(); | 756 CreateAudioStream(); |
| 794 MockDemuxerStreamVector streams; | 757 MockDemuxerStreamVector streams; |
| 795 streams.push_back(audio_stream()); | 758 streams.push_back(audio_stream()); |
| 796 | 759 |
| 797 InitializeDataSource(); | |
| 798 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); | 760 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); |
| 799 InitializeAudioDecoder(audio_stream()); | 761 InitializeAudioDecoder(audio_stream()); |
| 800 InitializeAudioRenderer(); | 762 InitializeAudioRenderer(); |
| 801 InitializePipeline(); | 763 InitializePipeline(); |
| 802 | 764 |
| 803 float playback_rate = 1.0f; | 765 float playback_rate = 1.0f; |
| 804 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(playback_rate)); | |
| 805 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 766 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| 806 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(playback_rate)); | 767 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(playback_rate)); |
| 807 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 768 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
| 808 pipeline_->SetPlaybackRate(playback_rate); | 769 pipeline_->SetPlaybackRate(playback_rate); |
| 809 message_loop_.RunAllPending(); | 770 message_loop_.RunAllPending(); |
| 810 | 771 |
| 811 InSequence s; | 772 InSequence s; |
| 812 | 773 |
| 813 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | 774 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); |
| 814 EXPECT_CALL(*mocks_->data_source(), Seek(seek_time, NotNull())) | |
| 815 .WillOnce(Invoke(&RunFilterCallback)); | |
| 816 | 775 |
| 817 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, NotNull())) | 776 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, NotNull())) |
| 818 .WillOnce(DoAll(SetError(mocks_->demuxer(), | 777 .WillOnce(DoAll(SetError(mocks_->demuxer(), |
| 819 PIPELINE_ERROR_READ), | 778 PIPELINE_ERROR_READ), |
| 820 Invoke(&RunFilterCallback))); | 779 Invoke(&RunFilterCallback))); |
| 821 | 780 |
| 822 pipeline_->Seek(seek_time, NewExpectedCallback()); | 781 pipeline_->Seek(seek_time, NewExpectedCallback()); |
| 823 EXPECT_CALL(callbacks_, OnError()); | 782 EXPECT_CALL(callbacks_, OnError()); |
| 824 message_loop_.RunAllPending(); | 783 message_loop_.RunAllPending(); |
| 825 } | 784 } |
| 826 | 785 |
| 827 } // namespace media | 786 } // namespace media |
| OLD | NEW |