Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: media/renderers/renderer_impl_unittest.cc

Issue 2605473002: Fix processing of multiple stream status changes by renderer (Closed)
Patch Set: Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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; 758 base::TimeDelta time0;
xhwang 2017/01/04 19:34:02 What does time0 exactly mean? Maybe this should be
servolk 2017/01/04 21:29:30 There's no special meaning to this, it's just a du
757 EXPECT_CALL(time_source_, StopTicking()); 759 EXPECT_CALL(time_source_, StopTicking());
758 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce(RunClosure<0>()); 760 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce(RunClosure<0>());
759 EXPECT_CALL(*audio_renderer_, StartPlaying()).Times(1); 761 EXPECT_CALL(*audio_renderer_, StartPlaying()).Times(1);
760 audio_stream_status_change_cb.Run(false, time0); 762 audio_stream_status_change_cb.Run(false, time0);
761 763
762 EXPECT_CALL(*video_renderer_, Flush(_)).WillOnce(RunClosure<0>()); 764 EXPECT_CALL(*video_renderer_, Flush(_)).WillOnce(RunClosure<0>());
763 EXPECT_CALL(*video_renderer_, StartPlayingFrom(_)).Times(1); 765 EXPECT_CALL(*video_renderer_, StartPlayingFrom(_)).Times(1);
764 video_stream_status_change_cb.Run(false, time0); 766 video_stream_status_change_cb.Run(false, time0);
765 } 767 }
766 768
769 ACTION(PostCallback) {
770 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, arg0);
771 }
772
773 ACTION(PostQuitWhenIdle) {
774 base::ThreadTaskRunnerHandle::Get()->PostTask(
775 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
776 }
777
778 // Stream status changes are handled asynchronously by the renderer and may take
779 // some time to process. This test verifies that all status changes are
780 // processed correctly by the renderer even if status changes of the stream
781 // happen much faster than the renderer can process them. In that case the
782 // renderer may postpone processing status changes, but still must process all
783 // of them eventually.
784 TEST_F(RendererImplTest, PostponedStreamStatusNotificationHandling) {
785 CreateAudioAndVideoStream();
786
787 DemuxerStream::StreamStatusChangeCB audio_stream_status_change_cb;
788 DemuxerStream::StreamStatusChangeCB video_stream_status_change_cb;
789 EXPECT_CALL(*audio_stream_, SetStreamStatusChangeCB(_))
790 .WillOnce(SaveArg<0>(&audio_stream_status_change_cb));
791 EXPECT_CALL(*video_stream_, SetStreamStatusChangeCB(_))
792 .WillOnce(SaveArg<0>(&video_stream_status_change_cb));
793 SetAudioRendererInitializeExpectations(PIPELINE_OK);
794 SetVideoRendererInitializeExpectations(PIPELINE_OK);
795 InitializeAndExpect(PIPELINE_OK);
796 Play();
797
798 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
799 .Times(2);
800
801 base::TimeDelta time0;
802 EXPECT_CALL(time_source_, StopTicking()).Times(2);
803 EXPECT_CALL(time_source_, StartTicking()).Times(2);
804 EXPECT_CALL(*audio_renderer_, Flush(_))
805 .Times(2)
806 .WillRepeatedly(DoAll(
807 SetBufferingState(&audio_renderer_client_, BUFFERING_HAVE_NOTHING),
808 WithArg<0>(PostCallback())));
809 EXPECT_CALL(*audio_renderer_, StartPlaying())
810 .Times(2)
811 .WillOnce(
812 SetBufferingState(&audio_renderer_client_, BUFFERING_HAVE_ENOUGH))
813 .WillOnce(DoAll(
814 SetBufferingState(&audio_renderer_client_, BUFFERING_HAVE_ENOUGH),
815 PostQuitWhenIdle()));
816 // The first stream status change will be processed immediately. Each status
817 // change processing involves Flush + StartPlaying when the Flush is done. The
818 // Flush operation is async in this case, so the second status change will be
819 // postponed by renderer until after processing the first one is finished. But
820 // we must still get two pairs of Flush/StartPlaying calls eventually.
821 audio_stream_status_change_cb.Run(false, time0);
822 audio_stream_status_change_cb.Run(true, time0);
823 base::RunLoop().Run();
824
825 EXPECT_CALL(*video_renderer_, Flush(_))
826 .Times(2)
827 .WillRepeatedly(DoAll(
828 SetBufferingState(&video_renderer_client_, BUFFERING_HAVE_NOTHING),
829 WithArg<0>(PostCallback())));
830 EXPECT_CALL(*video_renderer_, StartPlayingFrom(time0))
831 .Times(2)
832 .WillOnce(
833 SetBufferingState(&video_renderer_client_, BUFFERING_HAVE_ENOUGH))
834 .WillOnce(DoAll(
835 SetBufferingState(&video_renderer_client_, BUFFERING_HAVE_ENOUGH),
836 PostQuitWhenIdle()));
837 // The first stream status change will be processed immediately. Each status
838 // change processing involves Flush + StartPlaying when the Flush is done. The
839 // Flush operation is async in this case, so the second status change will be
840 // postponed by renderer until after processing the first one is finished. But
841 // we must still get two pairs of Flush/StartPlaying calls eventually.
842 video_stream_status_change_cb.Run(false, time0);
843 video_stream_status_change_cb.Run(true, time0);
844 base::RunLoop().Run();
845 }
846
767 } // namespace media 847 } // namespace media
OLDNEW
« media/renderers/renderer_impl.cc ('K') | « media/renderers/renderer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698