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" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 using ::testing::Mock; | 25 using ::testing::Mock; |
26 using ::testing::Return; | 26 using ::testing::Return; |
27 using ::testing::SaveArg; | 27 using ::testing::SaveArg; |
28 using ::testing::StrictMock; | 28 using ::testing::StrictMock; |
29 using ::testing::WithArg; | 29 using ::testing::WithArg; |
30 | 30 |
31 namespace media { | 31 namespace media { |
32 | 32 |
33 const int64_t kStartPlayingTimeInMs = 100; | 33 const int64_t kStartPlayingTimeInMs = 100; |
34 | 34 |
35 ACTION_P2(SetBool, var, value) { | |
36 *var = value; | |
37 } | |
38 | |
35 ACTION_P2(SetBufferingState, renderer_client, buffering_state) { | 39 ACTION_P2(SetBufferingState, renderer_client, buffering_state) { |
36 (*renderer_client)->OnBufferingStateChange(buffering_state); | 40 (*renderer_client)->OnBufferingStateChange(buffering_state); |
37 } | 41 } |
38 | 42 |
39 ACTION_P2(SetError, renderer_client, error) { | 43 ACTION_P2(SetError, renderer_client, error) { |
40 (*renderer_client)->OnError(error); | 44 (*renderer_client)->OnError(error); |
41 } | 45 } |
42 | 46 |
43 ACTION(PostCallback) { | 47 ACTION(PostCallback) { |
44 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, arg0); | 48 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, arg0); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 if (video_stream_) { | 223 if (video_stream_) { |
220 EXPECT_CALL(*video_renderer_, StartPlayingFrom(start_time)) | 224 EXPECT_CALL(*video_renderer_, StartPlayingFrom(start_time)) |
221 .WillOnce(SetBufferingState(&video_renderer_client_, | 225 .WillOnce(SetBufferingState(&video_renderer_client_, |
222 BUFFERING_HAVE_ENOUGH)); | 226 BUFFERING_HAVE_ENOUGH)); |
223 } | 227 } |
224 | 228 |
225 renderer_impl_->StartPlayingFrom(start_time); | 229 renderer_impl_->StartPlayingFrom(start_time); |
226 base::RunLoop().RunUntilIdle(); | 230 base::RunLoop().RunUntilIdle(); |
227 } | 231 } |
228 | 232 |
229 void Flush(bool underflowed) { | 233 void SetFlushExpectationsForAVRenderers() { |
230 if (!underflowed) | |
231 EXPECT_CALL(time_source_, StopTicking()); | |
232 | |
233 if (audio_stream_) { | 234 if (audio_stream_) { |
234 EXPECT_CALL(*audio_renderer_, Flush(_)) | 235 EXPECT_CALL(*audio_renderer_, Flush(_)) |
235 .WillOnce(DoAll(SetBufferingState(&audio_renderer_client_, | 236 .WillOnce(DoAll(SetBufferingState(&audio_renderer_client_, |
236 BUFFERING_HAVE_NOTHING), | 237 BUFFERING_HAVE_NOTHING), |
237 RunClosure<0>())); | 238 RunClosure<0>())); |
238 } | 239 } |
239 | 240 |
240 if (video_stream_) { | 241 if (video_stream_) { |
241 EXPECT_CALL(*video_renderer_, Flush(_)) | 242 EXPECT_CALL(*video_renderer_, Flush(_)) |
242 .WillOnce(DoAll(SetBufferingState(&video_renderer_client_, | 243 .WillOnce(DoAll(SetBufferingState(&video_renderer_client_, |
243 BUFFERING_HAVE_NOTHING), | 244 BUFFERING_HAVE_NOTHING), |
244 RunClosure<0>())); | 245 RunClosure<0>())); |
245 } | 246 } |
247 } | |
246 | 248 |
249 void Flush(bool underflowed) { | |
250 if (!underflowed) | |
251 EXPECT_CALL(time_source_, StopTicking()); | |
252 | |
253 SetFlushExpectationsForAVRenderers(); | |
247 EXPECT_CALL(callbacks_, OnFlushed()); | 254 EXPECT_CALL(callbacks_, OnFlushed()); |
248 | 255 |
249 renderer_impl_->Flush( | 256 renderer_impl_->Flush( |
250 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); | 257 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); |
251 base::RunLoop().RunUntilIdle(); | 258 base::RunLoop().RunUntilIdle(); |
252 } | 259 } |
253 | 260 |
254 void SetPlaybackRate(double playback_rate) { | 261 void SetPlaybackRate(double playback_rate) { |
255 EXPECT_CALL(time_source_, SetPlaybackRate(playback_rate)); | 262 EXPECT_CALL(time_source_, SetPlaybackRate(playback_rate)); |
256 renderer_impl_->SetPlaybackRate(playback_rate); | 263 renderer_impl_->SetPlaybackRate(playback_rate); |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 // The first stream status change will be processed immediately. Each status | 848 // The first stream status change will be processed immediately. Each status |
842 // change processing involves Flush + StartPlaying when the Flush is done. The | 849 // change processing involves Flush + StartPlaying when the Flush is done. The |
843 // Flush operation is async in this case, so the second status change will be | 850 // Flush operation is async in this case, so the second status change will be |
844 // postponed by renderer until after processing the first one is finished. But | 851 // postponed by renderer until after processing the first one is finished. But |
845 // we must still get two pairs of Flush/StartPlaying calls eventually. | 852 // we must still get two pairs of Flush/StartPlaying calls eventually. |
846 stream_status_change_cb.Run(video_stream_.get(), false, base::TimeDelta()); | 853 stream_status_change_cb.Run(video_stream_.get(), false, base::TimeDelta()); |
847 stream_status_change_cb.Run(video_stream_.get(), true, base::TimeDelta()); | 854 stream_status_change_cb.Run(video_stream_.get(), true, base::TimeDelta()); |
848 base::RunLoop().Run(); | 855 base::RunLoop().Run(); |
849 } | 856 } |
850 | 857 |
858 // Verify that a RendererImpl::Flush gets postponed until after stream status | |
DaleCurtis
2017/03/31 21:22:08
Opposite tests are needed, Flush is ongoing and Re
servolk
2017/03/31 23:53:55
Done.
| |
859 // change handling is completed. | |
860 TEST_F(RendererImplTest, FlushDuringAudioReinit) { | |
861 CreateAudioAndVideoStream(); | |
862 | |
863 StreamStatusChangeCB stream_status_change_cb; | |
864 EXPECT_CALL(*demuxer_, SetStreamStatusChangeCB(_)) | |
865 .WillOnce(SaveArg<0>(&stream_status_change_cb)); | |
866 SetAudioRendererInitializeExpectations(PIPELINE_OK); | |
867 SetVideoRendererInitializeExpectations(PIPELINE_OK); | |
868 InitializeAndExpect(PIPELINE_OK); | |
869 Play(); | |
870 | |
871 EXPECT_CALL(time_source_, StopTicking()).Times(testing::AnyNumber()); | |
872 base::Closure audio_renderer_flush_cb; | |
873 EXPECT_CALL(*audio_renderer_, Flush(_)) | |
874 .WillOnce(SaveArg<0>(&audio_renderer_flush_cb)); | |
875 EXPECT_CALL(*audio_renderer_, StartPlaying()) | |
876 .Times(1) | |
877 .WillOnce( | |
878 SetBufferingState(&audio_renderer_client_, BUFFERING_HAVE_ENOUGH)); | |
879 | |
880 // This should start flushing the audio renderer (due to audio stream status | |
881 // change) and should populate the |audio_renderer_flush_cb|. | |
882 stream_status_change_cb.Run(audio_stream_.get(), false, base::TimeDelta()); | |
883 EXPECT_TRUE(audio_renderer_flush_cb); | |
884 base::RunLoop().RunUntilIdle(); | |
885 | |
886 bool flush_done = false; | |
887 | |
888 // Now that audio stream change is being handled the RendererImpl::Flush | |
889 // should be postponed, instead of being executed immediately. | |
890 EXPECT_CALL(callbacks_, OnFlushed()).WillOnce(SetBool(&flush_done, true)); | |
891 renderer_impl_->Flush( | |
892 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); | |
893 base::RunLoop().RunUntilIdle(); | |
894 EXPECT_FALSE(flush_done); | |
895 | |
896 // The renderer_impl_->Flush invoked above should proceed after the first | |
897 // audio renderer flush (initiated by the stream status change) completes. | |
898 SetFlushExpectationsForAVRenderers(); | |
899 audio_renderer_flush_cb.Run(); | |
900 base::RunLoop().RunUntilIdle(); | |
901 EXPECT_TRUE(flush_done); | |
902 } | |
903 | |
904 TEST_F(RendererImplTest, FlushDuringVideoReinit) { | |
905 CreateAudioAndVideoStream(); | |
906 | |
907 StreamStatusChangeCB stream_status_change_cb; | |
908 EXPECT_CALL(*demuxer_, SetStreamStatusChangeCB(_)) | |
909 .WillOnce(SaveArg<0>(&stream_status_change_cb)); | |
910 SetAudioRendererInitializeExpectations(PIPELINE_OK); | |
911 SetVideoRendererInitializeExpectations(PIPELINE_OK); | |
912 InitializeAndExpect(PIPELINE_OK); | |
913 Play(); | |
914 | |
915 EXPECT_CALL(time_source_, StopTicking()).Times(testing::AnyNumber()); | |
916 base::Closure video_renderer_flush_cb; | |
917 EXPECT_CALL(*video_renderer_, Flush(_)) | |
918 .WillOnce(SaveArg<0>(&video_renderer_flush_cb)); | |
919 EXPECT_CALL(*video_renderer_, StartPlayingFrom(_)) | |
920 .Times(1) | |
921 .WillOnce( | |
922 SetBufferingState(&video_renderer_client_, BUFFERING_HAVE_ENOUGH)); | |
923 | |
924 // This should start flushing the video renderer (due to video stream status | |
925 // change) and should populate the |video_renderer_flush_cb|. | |
926 stream_status_change_cb.Run(video_stream_.get(), false, base::TimeDelta()); | |
927 EXPECT_TRUE(video_renderer_flush_cb); | |
928 base::RunLoop().RunUntilIdle(); | |
929 | |
930 bool flush_done = false; | |
931 | |
932 // Now that video stream change is being handled the RendererImpl::Flush | |
933 // should be postponed, instead of being executed immediately. | |
934 EXPECT_CALL(callbacks_, OnFlushed()).WillOnce(SetBool(&flush_done, true)); | |
935 renderer_impl_->Flush( | |
936 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); | |
937 base::RunLoop().RunUntilIdle(); | |
938 EXPECT_FALSE(flush_done); | |
939 | |
940 // The renderer_impl_->Flush invoked above should proceed after the first | |
941 // video renderer flush (initiated by the stream status change) completes. | |
942 SetFlushExpectationsForAVRenderers(); | |
943 video_renderer_flush_cb.Run(); | |
944 base::RunLoop().RunUntilIdle(); | |
945 EXPECT_TRUE(flush_done); | |
946 } | |
947 | |
851 } // namespace media | 948 } // namespace media |
OLD | NEW |