OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/test/simple_test_tick_clock.h" | 14 #include "base/test/simple_test_tick_clock.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" |
15 #include "media/base/gmock_callback_support.h" | 16 #include "media/base/gmock_callback_support.h" |
16 #include "media/base/mock_filters.h" | 17 #include "media/base/mock_filters.h" |
17 #include "media/base/test_helpers.h" | 18 #include "media/base/test_helpers.h" |
18 #include "media/renderers/renderer_impl.h" | 19 #include "media/renderers/renderer_impl.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 using ::testing::_; | 22 using ::testing::_; |
22 using ::testing::DoAll; | 23 using ::testing::DoAll; |
23 using ::testing::InSequence; | 24 using ::testing::InSequence; |
24 using ::testing::Mock; | 25 using ::testing::Mock; |
25 using ::testing::Return; | 26 using ::testing::Return; |
26 using ::testing::SaveArg; | 27 using ::testing::SaveArg; |
27 using ::testing::StrictMock; | 28 using ::testing::StrictMock; |
| 29 using ::testing::WithArg; |
28 | 30 |
29 namespace media { | 31 namespace media { |
30 | 32 |
31 const int64_t kStartPlayingTimeInMs = 100; | 33 const int64_t kStartPlayingTimeInMs = 100; |
32 | 34 |
33 ACTION_P2(SetBufferingState, renderer_client, buffering_state) { | 35 ACTION_P2(SetBufferingState, renderer_client, buffering_state) { |
34 (*renderer_client)->OnBufferingStateChange(buffering_state); | 36 (*renderer_client)->OnBufferingStateChange(buffering_state); |
35 } | 37 } |
36 | 38 |
37 ACTION_P2(SetError, renderer_client, error) { | 39 ACTION_P2(SetError, renderer_client, error) { |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 .WillOnce(SaveArg<0>(&audio_stream_status_change_cb)); | 748 .WillOnce(SaveArg<0>(&audio_stream_status_change_cb)); |
747 EXPECT_CALL(*video_stream_, SetStreamStatusChangeCB(_)) | 749 EXPECT_CALL(*video_stream_, SetStreamStatusChangeCB(_)) |
748 .WillOnce(SaveArg<0>(&video_stream_status_change_cb)); | 750 .WillOnce(SaveArg<0>(&video_stream_status_change_cb)); |
749 SetAudioRendererInitializeExpectations(PIPELINE_OK); | 751 SetAudioRendererInitializeExpectations(PIPELINE_OK); |
750 SetVideoRendererInitializeExpectations(PIPELINE_OK); | 752 SetVideoRendererInitializeExpectations(PIPELINE_OK); |
751 InitializeAndExpect(PIPELINE_OK); | 753 InitializeAndExpect(PIPELINE_OK); |
752 Play(); | 754 Play(); |
753 | 755 |
754 // Verify that DemuxerStream status changes cause the corresponding | 756 // Verify that DemuxerStream status changes cause the corresponding |
755 // audio/video renderer to be flushed and restarted. | 757 // audio/video renderer to be flushed and restarted. |
756 base::TimeDelta time0; | |
757 EXPECT_CALL(time_source_, StopTicking()); | 758 EXPECT_CALL(time_source_, StopTicking()); |
758 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce(RunClosure<0>()); | 759 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce(RunClosure<0>()); |
759 EXPECT_CALL(*audio_renderer_, StartPlaying()).Times(1); | 760 EXPECT_CALL(*audio_renderer_, StartPlaying()).Times(1); |
760 audio_stream_status_change_cb.Run(false, time0); | 761 audio_stream_status_change_cb.Run(false, base::TimeDelta()); |
761 | 762 |
762 EXPECT_CALL(*video_renderer_, Flush(_)).WillOnce(RunClosure<0>()); | 763 EXPECT_CALL(*video_renderer_, Flush(_)).WillOnce(RunClosure<0>()); |
763 EXPECT_CALL(*video_renderer_, StartPlayingFrom(_)).Times(1); | 764 EXPECT_CALL(*video_renderer_, StartPlayingFrom(_)).Times(1); |
764 video_stream_status_change_cb.Run(false, time0); | 765 video_stream_status_change_cb.Run(false, base::TimeDelta()); |
| 766 } |
| 767 |
| 768 ACTION(PostCallback) { |
| 769 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, arg0); |
| 770 } |
| 771 |
| 772 ACTION(PostQuitWhenIdle) { |
| 773 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 774 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 775 } |
| 776 |
| 777 // Stream status changes are handled asynchronously by the renderer and may take |
| 778 // some time to process. This test verifies that all status changes are |
| 779 // processed correctly by the renderer even if status changes of the stream |
| 780 // happen much faster than the renderer can process them. In that case the |
| 781 // renderer may postpone processing status changes, but still must process all |
| 782 // of them eventually. |
| 783 TEST_F(RendererImplTest, PostponedStreamStatusNotificationHandling) { |
| 784 CreateAudioAndVideoStream(); |
| 785 |
| 786 DemuxerStream::StreamStatusChangeCB audio_stream_status_change_cb; |
| 787 DemuxerStream::StreamStatusChangeCB video_stream_status_change_cb; |
| 788 EXPECT_CALL(*audio_stream_, SetStreamStatusChangeCB(_)) |
| 789 .WillOnce(SaveArg<0>(&audio_stream_status_change_cb)); |
| 790 EXPECT_CALL(*video_stream_, SetStreamStatusChangeCB(_)) |
| 791 .WillOnce(SaveArg<0>(&video_stream_status_change_cb)); |
| 792 SetAudioRendererInitializeExpectations(PIPELINE_OK); |
| 793 SetVideoRendererInitializeExpectations(PIPELINE_OK); |
| 794 InitializeAndExpect(PIPELINE_OK); |
| 795 Play(); |
| 796 |
| 797 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 798 .Times(2); |
| 799 |
| 800 EXPECT_CALL(time_source_, StopTicking()).Times(2); |
| 801 EXPECT_CALL(time_source_, StartTicking()).Times(2); |
| 802 EXPECT_CALL(*audio_renderer_, Flush(_)) |
| 803 .Times(2) |
| 804 .WillRepeatedly(DoAll( |
| 805 SetBufferingState(&audio_renderer_client_, BUFFERING_HAVE_NOTHING), |
| 806 WithArg<0>(PostCallback()))); |
| 807 EXPECT_CALL(*audio_renderer_, StartPlaying()) |
| 808 .Times(2) |
| 809 .WillOnce( |
| 810 SetBufferingState(&audio_renderer_client_, BUFFERING_HAVE_ENOUGH)) |
| 811 .WillOnce(DoAll( |
| 812 SetBufferingState(&audio_renderer_client_, BUFFERING_HAVE_ENOUGH), |
| 813 PostQuitWhenIdle())); |
| 814 // The first stream status change will be processed immediately. Each status |
| 815 // change processing involves Flush + StartPlaying when the Flush is done. The |
| 816 // Flush operation is async in this case, so the second status change will be |
| 817 // postponed by renderer until after processing the first one is finished. But |
| 818 // we must still get two pairs of Flush/StartPlaying calls eventually. |
| 819 audio_stream_status_change_cb.Run(false, base::TimeDelta()); |
| 820 audio_stream_status_change_cb.Run(true, base::TimeDelta()); |
| 821 base::RunLoop().Run(); |
| 822 |
| 823 EXPECT_CALL(*video_renderer_, Flush(_)) |
| 824 .Times(2) |
| 825 .WillRepeatedly(DoAll( |
| 826 SetBufferingState(&video_renderer_client_, BUFFERING_HAVE_NOTHING), |
| 827 WithArg<0>(PostCallback()))); |
| 828 EXPECT_CALL(*video_renderer_, StartPlayingFrom(base::TimeDelta())) |
| 829 .Times(2) |
| 830 .WillOnce( |
| 831 SetBufferingState(&video_renderer_client_, BUFFERING_HAVE_ENOUGH)) |
| 832 .WillOnce(DoAll( |
| 833 SetBufferingState(&video_renderer_client_, BUFFERING_HAVE_ENOUGH), |
| 834 PostQuitWhenIdle())); |
| 835 // The first stream status change will be processed immediately. Each status |
| 836 // change processing involves Flush + StartPlaying when the Flush is done. The |
| 837 // Flush operation is async in this case, so the second status change will be |
| 838 // postponed by renderer until after processing the first one is finished. But |
| 839 // we must still get two pairs of Flush/StartPlaying calls eventually. |
| 840 video_stream_status_change_cb.Run(false, base::TimeDelta()); |
| 841 video_stream_status_change_cb.Run(true, base::TimeDelta()); |
| 842 base::RunLoop().Run(); |
765 } | 843 } |
766 | 844 |
767 } // namespace media | 845 } // namespace media |
OLD | NEW |