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/clock.h" | |
8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/test/simple_test_clock.h" | |
10 #include "base/threading/simple_thread.h" | 12 #include "base/threading/simple_thread.h" |
11 #include "media/base/clock.h" | 13 #include "media/base/clock.h" |
12 #include "media/base/gmock_callback_support.h" | 14 #include "media/base/gmock_callback_support.h" |
13 #include "media/base/media_log.h" | 15 #include "media/base/media_log.h" |
14 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
15 #include "media/base/pipeline.h" | 17 #include "media/base/pipeline.h" |
16 #include "media/base/test_helpers.h" | 18 #include "media/base/test_helpers.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
19 | 21 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 base::Unretained(&callbacks_))); | 273 base::Unretained(&callbacks_))); |
272 | 274 |
273 // We expect the time to be updated only after the seek has completed. | 275 // We expect the time to be updated only after the seek has completed. |
274 EXPECT_NE(seek_time, pipeline_->GetMediaTime()); | 276 EXPECT_NE(seek_time, pipeline_->GetMediaTime()); |
275 message_loop_.RunUntilIdle(); | 277 message_loop_.RunUntilIdle(); |
276 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); | 278 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); |
277 } | 279 } |
278 | 280 |
279 // Fixture members. | 281 // Fixture members. |
280 StrictMock<CallbackHelper> callbacks_; | 282 StrictMock<CallbackHelper> callbacks_; |
283 base::SimpleTestClock test_clock_; | |
281 MessageLoop message_loop_; | 284 MessageLoop message_loop_; |
282 scoped_refptr<Pipeline> pipeline_; | 285 scoped_refptr<Pipeline> pipeline_; |
283 scoped_ptr<media::MockFilterCollection> mocks_; | 286 scoped_ptr<media::MockFilterCollection> mocks_; |
284 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; | 287 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; |
285 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; | 288 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; |
286 AudioRenderer::TimeCB audio_time_cb_; | 289 AudioRenderer::TimeCB audio_time_cb_; |
287 VideoDecoderConfig video_decoder_config_; | 290 VideoDecoderConfig video_decoder_config_; |
288 | 291 |
289 private: | 292 private: |
290 DISALLOW_COPY_AND_ASSIGN(PipelineTest); | 293 DISALLOW_COPY_AND_ASSIGN(PipelineTest); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 | 577 |
575 // The ended callback shouldn't run until both renderers have ended. | 578 // The ended callback shouldn't run until both renderers have ended. |
576 pipeline_->OnAudioRendererEnded(); | 579 pipeline_->OnAudioRendererEnded(); |
577 message_loop_.RunUntilIdle(); | 580 message_loop_.RunUntilIdle(); |
578 | 581 |
579 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 582 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
580 pipeline_->OnVideoRendererEnded(); | 583 pipeline_->OnVideoRendererEnded(); |
581 message_loop_.RunUntilIdle(); | 584 message_loop_.RunUntilIdle(); |
582 } | 585 } |
583 | 586 |
584 // Static function & time variable used to simulate changes in wallclock time. | |
585 static int64 g_static_clock_time; | |
586 static base::Time StaticClockFunction() { | |
scherkus (not reviewing)
2012/12/17 23:25:47
haha wow am I ever glad this is getting deleted
| |
587 return base::Time::FromInternalValue(g_static_clock_time); | |
588 } | |
589 | |
590 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { | 587 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { |
591 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); | 588 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); |
592 | 589 |
593 CreateAudioStream(); | 590 CreateAudioStream(); |
594 CreateVideoStream(); | 591 CreateVideoStream(); |
595 MockDemuxerStreamVector streams; | 592 MockDemuxerStreamVector streams; |
596 streams.push_back(audio_stream()); | 593 streams.push_back(audio_stream()); |
597 streams.push_back(video_stream()); | 594 streams.push_back(video_stream()); |
598 | 595 |
599 // Replace the clock so we can simulate wallclock time advancing w/o using | 596 // Replace the clock so we can simulate wallclock time advancing w/o using |
600 // Sleep(). | 597 // Sleep(). |
601 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); | 598 pipeline_->SetClockForTesting(new Clock(&test_clock_)); |
602 | 599 |
603 InitializeDemuxer(&streams, duration); | 600 InitializeDemuxer(&streams, duration); |
604 InitializeAudioRenderer(audio_stream(), false); | 601 InitializeAudioRenderer(audio_stream(), false); |
605 InitializeVideoRenderer(video_stream()); | 602 InitializeVideoRenderer(video_stream()); |
606 InitializePipeline(PIPELINE_OK); | 603 InitializePipeline(PIPELINE_OK); |
607 | 604 |
608 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue()); | 605 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue()); |
609 | 606 |
610 float playback_rate = 1.0f; | 607 float playback_rate = 1.0f; |
611 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 608 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
612 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(playback_rate)); | 609 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(playback_rate)); |
613 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 610 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
614 pipeline_->SetPlaybackRate(playback_rate); | 611 pipeline_->SetPlaybackRate(playback_rate); |
615 message_loop_.RunUntilIdle(); | 612 message_loop_.RunUntilIdle(); |
616 | 613 |
617 InSequence s; | 614 InSequence s; |
618 | 615 |
619 // Verify that the clock doesn't advance since it hasn't been started by | 616 // Verify that the clock doesn't advance since it hasn't been started by |
620 // a time update from the audio stream. | 617 // a time update from the audio stream. |
621 int64 start_time = pipeline_->GetMediaTime().ToInternalValue(); | 618 int64 start_time = pipeline_->GetMediaTime().ToInternalValue(); |
622 g_static_clock_time += | 619 test_clock_.Advance(base::TimeDelta::FromMilliseconds(100)); |
623 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); | |
624 EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time); | 620 EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time); |
625 | 621 |
626 // Signal end of audio stream. | 622 // Signal end of audio stream. |
627 pipeline_->OnAudioRendererEnded(); | 623 pipeline_->OnAudioRendererEnded(); |
628 message_loop_.RunUntilIdle(); | 624 message_loop_.RunUntilIdle(); |
629 | 625 |
630 // Verify that the clock advances. | 626 // Verify that the clock advances. |
631 start_time = pipeline_->GetMediaTime().ToInternalValue(); | 627 start_time = pipeline_->GetMediaTime().ToInternalValue(); |
632 g_static_clock_time += | 628 test_clock_.Advance(base::TimeDelta::FromMilliseconds(100)); |
633 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); | |
634 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time); | 629 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time); |
635 | 630 |
636 // Signal end of video stream and make sure OnEnded() callback occurs. | 631 // Signal end of video stream and make sure OnEnded() callback occurs. |
637 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 632 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
638 pipeline_->OnVideoRendererEnded(); | 633 pipeline_->OnVideoRendererEnded(); |
639 } | 634 } |
640 | 635 |
641 TEST_F(PipelineTest, ErrorDuringSeek) { | 636 TEST_F(PipelineTest, ErrorDuringSeek) { |
642 CreateAudioStream(); | 637 CreateAudioStream(); |
643 MockDemuxerStreamVector streams; | 638 MockDemuxerStreamVector streams; |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1202 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); | 1197 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); |
1203 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); | 1198 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); |
1204 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); | 1199 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); |
1205 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); | 1200 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); |
1206 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1201 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
1207 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); | 1202 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); |
1208 INSTANTIATE_TEARDOWN_TEST(Error, Starting); | 1203 INSTANTIATE_TEARDOWN_TEST(Error, Starting); |
1209 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1204 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
1210 | 1205 |
1211 } // namespace media | 1206 } // namespace media |
OLD | NEW |