OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 } | 209 } |
210 | 210 |
211 void WaitForEnded() { | 211 void WaitForEnded() { |
212 SCOPED_TRACE("WaitForEnded()"); | 212 SCOPED_TRACE("WaitForEnded()"); |
213 | 213 |
214 WaitableMessageLoopEvent event; | 214 WaitableMessageLoopEvent event; |
215 EXPECT_CALL(mock_cb_, OnEnded()).WillOnce(RunClosure(event.GetClosure())); | 215 EXPECT_CALL(mock_cb_, OnEnded()).WillOnce(RunClosure(event.GetClosure())); |
216 event.RunAndWait(); | 216 event.RunAndWait(); |
217 } | 217 } |
218 | 218 |
219 void WaitForPendingRead() { | 219 void WaitForPendingRead() { |
xhwang
2016/05/24 21:46:29
Should this be renamed to WaitForPendingDecode?
DaleCurtis
2016/05/24 22:58:25
Done.
| |
220 SCOPED_TRACE("WaitForPendingRead()"); | 220 SCOPED_TRACE("WaitForPendingRead()"); |
221 if (!decode_cb_.is_null()) | 221 if (!decode_cb_.is_null()) |
222 return; | 222 return; |
223 | 223 |
224 DCHECK(wait_for_pending_decode_cb_.is_null()); | 224 DCHECK(wait_for_pending_decode_cb_.is_null()); |
225 | 225 |
226 WaitableMessageLoopEvent event; | 226 WaitableMessageLoopEvent event; |
227 wait_for_pending_decode_cb_ = event.GetClosure(); | 227 wait_for_pending_decode_cb_ = event.GetClosure(); |
228 event.RunAndWait(); | 228 event.RunAndWait(); |
229 | 229 |
230 DCHECK(!decode_cb_.is_null()); | 230 DCHECK(!decode_cb_.is_null()); |
231 DCHECK(wait_for_pending_decode_cb_.is_null()); | 231 DCHECK(wait_for_pending_decode_cb_.is_null()); |
232 } | 232 } |
233 | 233 |
234 void SatisfyPendingRead() { | 234 void SatisfyPendingRead() { |
xhwang
2016/05/24 21:46:29
ditto
DaleCurtis
2016/05/24 22:58:25
Done.
| |
235 CHECK(!decode_cb_.is_null()); | 235 CHECK(!decode_cb_.is_null()); |
236 CHECK(!decode_results_.empty()); | 236 CHECK(!decode_results_.empty()); |
237 | 237 |
238 // Post tasks for OutputCB and DecodeCB. | 238 // Post tasks for OutputCB and DecodeCB. |
239 scoped_refptr<VideoFrame> frame = decode_results_.front().second; | 239 scoped_refptr<VideoFrame> frame = decode_results_.front().second; |
240 if (frame.get()) | 240 if (frame.get()) |
241 message_loop_.PostTask(FROM_HERE, base::Bind(output_cb_, frame)); | 241 message_loop_.PostTask(FROM_HERE, base::Bind(output_cb_, frame)); |
242 message_loop_.PostTask( | 242 message_loop_.PostTask( |
243 FROM_HERE, base::Bind(base::ResetAndReturn(&decode_cb_), | 243 FROM_HERE, base::Bind(base::ResetAndReturn(&decode_cb_), |
244 decode_results_.front().first)); | 244 decode_results_.front().first)); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 // when the renderer paints the first frame. | 406 // when the renderer paints the first frame. |
407 { | 407 { |
408 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); | 408 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); |
409 WaitableMessageLoopEvent event; | 409 WaitableMessageLoopEvent event; |
410 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(80))).Times(1); | 410 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(80))).Times(1); |
411 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 411 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
412 .WillOnce(RunClosure(event.GetClosure())); | 412 .WillOnce(RunClosure(event.GetClosure())); |
413 if (type == UnderflowTestType::NORMAL) | 413 if (type == UnderflowTestType::NORMAL) |
414 QueueFrames("80 100 120 140 160"); | 414 QueueFrames("80 100 120 140 160"); |
415 else | 415 else |
416 QueueFrames("40 60 80"); | 416 QueueFrames("40 60 80 90"); |
417 SatisfyPendingRead(); | 417 SatisfyPendingRead(); |
418 event.RunAndWait(); | 418 event.RunAndWait(); |
419 } | 419 } |
420 | 420 |
421 Destroy(); | 421 Destroy(); |
422 } | 422 } |
423 | 423 |
424 protected: | 424 protected: |
425 // Fixture members. | 425 // Fixture members. |
426 std::unique_ptr<VideoRendererImpl> renderer_; | 426 std::unique_ptr<VideoRendererImpl> renderer_; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 | 751 |
752 Destroy(); | 752 Destroy(); |
753 } | 753 } |
754 | 754 |
755 // Verifies that the sink is stopped after rendering the first frame if | 755 // Verifies that the sink is stopped after rendering the first frame if |
756 // playback has started. | 756 // playback has started. |
757 TEST_F(VideoRendererImplTest, RenderingStopsAfterOneFrameWithEOS) { | 757 TEST_F(VideoRendererImplTest, RenderingStopsAfterOneFrameWithEOS) { |
758 InitializeWithLowDelay(true); | 758 InitializeWithLowDelay(true); |
759 QueueFrames("0"); | 759 QueueFrames("0"); |
760 | 760 |
761 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))).Times(2); | 761 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))).Times(1); |
762 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 762 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
763 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); | 763 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); |
764 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | 764 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); |
765 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); | 765 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); |
766 | 766 |
767 { | 767 { |
768 SCOPED_TRACE("Waiting for sink to stop."); | 768 SCOPED_TRACE("Waiting for sink to stop."); |
769 WaitableMessageLoopEvent event; | 769 WaitableMessageLoopEvent event; |
770 | 770 |
771 null_video_sink_->set_stop_cb(event.GetClosure()); | 771 null_video_sink_->set_stop_cb(event.GetClosure()); |
(...skipping 16 matching lines...) Expand all Loading... | |
788 TEST_F(VideoRendererImplTest, RenderingStartedThenStopped) { | 788 TEST_F(VideoRendererImplTest, RenderingStartedThenStopped) { |
789 Initialize(); | 789 Initialize(); |
790 QueueFrames("0 30 60 90"); | 790 QueueFrames("0 30 60 90"); |
791 | 791 |
792 // Start the sink and wait for the first callback. Set statistics to a non | 792 // Start the sink and wait for the first callback. Set statistics to a non |
793 // zero value, once we have some decoded frames they should be overwritten. | 793 // zero value, once we have some decoded frames they should be overwritten. |
794 PipelineStatistics last_pipeline_statistics; | 794 PipelineStatistics last_pipeline_statistics; |
795 last_pipeline_statistics.video_frames_dropped = 1; | 795 last_pipeline_statistics.video_frames_dropped = 1; |
796 { | 796 { |
797 WaitableMessageLoopEvent event; | 797 WaitableMessageLoopEvent event; |
798 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 798 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
799 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))) | |
800 .WillOnce(RunClosure(event.GetClosure())); | 799 .WillOnce(RunClosure(event.GetClosure())); |
800 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | |
801 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | 801 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); |
802 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); | 802 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); |
803 StartPlayingFrom(0); | 803 StartPlayingFrom(0); |
804 event.RunAndWait(); | 804 event.RunAndWait(); |
805 Mock::VerifyAndClearExpectations(&mock_cb_); | 805 Mock::VerifyAndClearExpectations(&mock_cb_); |
806 } | 806 } |
807 | 807 |
808 // Consider the case that rendering is faster than we setup the test event. | 808 // Consider the case that rendering is faster than we setup the test event. |
809 // In that case, when we run out of the frames, BUFFERING_HAVE_NOTHING will | 809 // In that case, when we run out of the frames, BUFFERING_HAVE_NOTHING will |
810 // be called. And then during SatisfyPendingReadWithEndOfStream, | 810 // be called. And then during SatisfyPendingReadWithEndOfStream, |
(...skipping 21 matching lines...) Expand all Loading... | |
832 // reported | 832 // reported |
833 EXPECT_EQ(0u, last_pipeline_statistics.video_frames_dropped); | 833 EXPECT_EQ(0u, last_pipeline_statistics.video_frames_dropped); |
834 EXPECT_EQ(4u, last_pipeline_statistics.video_frames_decoded); | 834 EXPECT_EQ(4u, last_pipeline_statistics.video_frames_decoded); |
835 EXPECT_EQ(115200, last_pipeline_statistics.video_memory_usage); | 835 EXPECT_EQ(115200, last_pipeline_statistics.video_memory_usage); |
836 | 836 |
837 AdvanceTimeInMs(30); | 837 AdvanceTimeInMs(30); |
838 WaitForEnded(); | 838 WaitForEnded(); |
839 Destroy(); | 839 Destroy(); |
840 } | 840 } |
841 | 841 |
842 // Tests the case where underflow evicts all frames before EOS. | |
843 TEST_F(VideoRendererImplTest, UnderflowEvictionBeforeEOS) { | |
844 Initialize(); | |
845 QueueFrames("0 30 60 90 100"); | |
846 | |
847 { | |
848 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); | |
849 WaitableMessageLoopEvent event; | |
850 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | |
851 .WillOnce(RunClosure(event.GetClosure())); | |
852 EXPECT_CALL(mock_cb_, FrameReceived(_)).Times(AnyNumber()); | |
853 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | |
854 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); | |
855 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); | |
856 StartPlayingFrom(0); | |
857 event.RunAndWait(); | |
858 } | |
859 | |
860 { | |
861 SCOPED_TRACE("Waiting for BUFFERING_HAVE_NOTHING"); | |
862 WaitableMessageLoopEvent event; | |
863 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) | |
864 .WillOnce(RunClosure(event.GetClosure())); | |
865 renderer_->OnTimeStateChanged(true); | |
866 time_source_.StartTicking(); | |
867 event.RunAndWait(); | |
868 } | |
869 | |
870 WaitForPendingRead(); | |
871 | |
872 // Jump time far enough forward that no frames are valid. | |
873 renderer_->OnTimeStateChanged(false); | |
874 AdvanceTimeInMs(1000); | |
875 time_source_.StopTicking(); | |
876 | |
877 // Providing the end of stream packet should remove all frames and exit. | |
878 SatisfyPendingReadWithEndOfStream(); | |
879 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); | |
880 WaitForEnded(); | |
881 Destroy(); | |
882 } | |
883 | |
842 TEST_F(VideoRendererImplTest, StartPlayingFromThenFlushThenEOS) { | 884 TEST_F(VideoRendererImplTest, StartPlayingFromThenFlushThenEOS) { |
843 Initialize(); | 885 Initialize(); |
844 QueueFrames("0 30 60 90"); | 886 QueueFrames("0 30 60 90"); |
845 | 887 |
846 WaitableMessageLoopEvent event; | 888 WaitableMessageLoopEvent event; |
847 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | 889 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
848 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 890 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
849 .WillOnce(RunClosure(event.GetClosure())); | 891 .WillOnce(RunClosure(event.GetClosure())); |
850 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); | 892 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); |
851 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | 893 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1067 QueueFrames("0 10 20 30"); | 1109 QueueFrames("0 10 20 30"); |
1068 StartPlayingFrom(0); | 1110 StartPlayingFrom(0); |
1069 Flush(); | 1111 Flush(); |
1070 ASSERT_EQ(1u, frame_ready_cbs_.size()); | 1112 ASSERT_EQ(1u, frame_ready_cbs_.size()); |
1071 // This frame will be discarded. | 1113 // This frame will be discarded. |
1072 frame_ready_cbs_.front().Run(); | 1114 frame_ready_cbs_.front().Run(); |
1073 Destroy(); | 1115 Destroy(); |
1074 } | 1116 } |
1075 | 1117 |
1076 } // namespace media | 1118 } // namespace media |
OLD | NEW |