| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 346 } |
| 347 | 347 |
| 348 // Simulate delayed buffering state callbacks. | 348 // Simulate delayed buffering state callbacks. |
| 349 renderer_->OnTimeStateChanged(false); | 349 renderer_->OnTimeStateChanged(false); |
| 350 renderer_->OnTimeStateChanged(true); | 350 renderer_->OnTimeStateChanged(true); |
| 351 | 351 |
| 352 // Receiving end of stream should signal having enough. | 352 // Receiving end of stream should signal having enough. |
| 353 { | 353 { |
| 354 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); | 354 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); |
| 355 WaitableMessageLoopEvent event; | 355 WaitableMessageLoopEvent event; |
| 356 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); |
| 356 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 357 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 357 .WillOnce(RunClosure(event.GetClosure())); | 358 .WillOnce(RunClosure(event.GetClosure())); |
| 358 EXPECT_CALL(mock_cb_, OnEnded()); | 359 EXPECT_CALL(mock_cb_, OnEnded()); |
| 359 SatisfyPendingDecodeWithEndOfStream(); | 360 SatisfyPendingDecodeWithEndOfStream(); |
| 360 event.RunAndWait(); | 361 event.RunAndWait(); |
| 361 } | 362 } |
| 362 | 363 |
| 363 Destroy(); | 364 Destroy(); |
| 364 } | 365 } |
| 365 | 366 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 renderer_->OnTimeStateChanged(false); | 405 renderer_->OnTimeStateChanged(false); |
| 405 EXPECT_EQ(0u, renderer_->frames_queued_for_testing()); | 406 EXPECT_EQ(0u, renderer_->frames_queued_for_testing()); |
| 406 ASSERT_TRUE(IsReadPending()); | 407 ASSERT_TRUE(IsReadPending()); |
| 407 | 408 |
| 408 // Queue some frames, satisfy reads, and make sure expired frames are gone | 409 // Queue some frames, satisfy reads, and make sure expired frames are gone |
| 409 // when the renderer paints the first frame. | 410 // when the renderer paints the first frame. |
| 410 { | 411 { |
| 411 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); | 412 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); |
| 412 WaitableMessageLoopEvent event; | 413 WaitableMessageLoopEvent event; |
| 413 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(80))).Times(1); | 414 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(80))).Times(1); |
| 415 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); |
| 414 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 416 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 415 .WillOnce(RunClosure(event.GetClosure())); | 417 .WillOnce(RunClosure(event.GetClosure())); |
| 416 if (type == UnderflowTestType::NORMAL) | 418 if (type == UnderflowTestType::NORMAL) |
| 417 QueueFrames("80 100 120 140 160"); | 419 QueueFrames("80 100 120 140 160"); |
| 418 else | 420 else |
| 419 QueueFrames("40 60 80 90"); | 421 QueueFrames("40 60 80 90"); |
| 420 SatisfyPendingDecode(); | 422 SatisfyPendingDecode(); |
| 421 event.RunAndWait(); | 423 event.RunAndWait(); |
| 422 } | 424 } |
| 423 | 425 |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 QueueFrames("0 30 60 90"); | 820 QueueFrames("0 30 60 90"); |
| 819 | 821 |
| 820 // Start the sink and wait for the first callback. Set statistics to a non | 822 // Start the sink and wait for the first callback. Set statistics to a non |
| 821 // zero value, once we have some decoded frames they should be overwritten. | 823 // zero value, once we have some decoded frames they should be overwritten. |
| 822 PipelineStatistics last_pipeline_statistics; | 824 PipelineStatistics last_pipeline_statistics; |
| 823 last_pipeline_statistics.video_frames_dropped = 1; | 825 last_pipeline_statistics.video_frames_dropped = 1; |
| 824 { | 826 { |
| 825 WaitableMessageLoopEvent event; | 827 WaitableMessageLoopEvent event; |
| 826 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 828 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 827 .WillOnce(RunClosure(event.GetClosure())); | 829 .WillOnce(RunClosure(event.GetClosure())); |
| 830 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)) |
| 831 .Times(4) |
| 832 .WillRepeatedly(SaveArg<0>(&last_pipeline_statistics)); |
| 828 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | 833 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
| 829 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | 834 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); |
| 830 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); | 835 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); |
| 831 StartPlayingFrom(0); | 836 StartPlayingFrom(0); |
| 832 event.RunAndWait(); | 837 event.RunAndWait(); |
| 833 Mock::VerifyAndClearExpectations(&mock_cb_); | 838 Mock::VerifyAndClearExpectations(&mock_cb_); |
| 834 } | 839 } |
| 835 | 840 |
| 841 // Four calls to update statistics should have been made, each reporting a |
| 842 // single decoded frame and one frame worth of memory usage. No dropped frames |
| 843 // should be reported later since we're in background rendering mode. These |
| 844 // calls must all have occurred before playback starts. |
| 845 EXPECT_EQ(0u, last_pipeline_statistics.video_frames_dropped); |
| 846 EXPECT_EQ(1u, last_pipeline_statistics.video_frames_decoded); |
| 847 EXPECT_EQ(115200, last_pipeline_statistics.video_memory_usage); |
| 848 |
| 836 // Consider the case that rendering is faster than we setup the test event. | 849 // Consider the case that rendering is faster than we setup the test event. |
| 837 // In that case, when we run out of the frames, BUFFERING_HAVE_NOTHING will | 850 // In that case, when we run out of the frames, BUFFERING_HAVE_NOTHING will |
| 838 // be called. And then during SatisfyPendingDecodeWithEndOfStream, | 851 // be called. And then during SatisfyPendingDecodeWithEndOfStream, |
| 839 // BUFFER_HAVE_ENOUGH will be called again. | 852 // BUFFER_HAVE_ENOUGH will be called again. |
| 840 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 853 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 841 .Times(testing::AtMost(1)); | 854 .Times(testing::AtMost(1)); |
| 842 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) | 855 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) |
| 843 .Times(testing::AtMost(1)); | 856 .Times(testing::AtMost(1)); |
| 844 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)) | |
| 845 .WillRepeatedly(SaveArg<0>(&last_pipeline_statistics)); | |
| 846 renderer_->OnTimeStateChanged(true); | 857 renderer_->OnTimeStateChanged(true); |
| 847 time_source_.StartTicking(); | 858 time_source_.StartTicking(); |
| 848 | 859 |
| 849 // Suspend all future callbacks and synthetically advance the media time, | 860 // Suspend all future callbacks and synthetically advance the media time, |
| 850 // because this is a background render, we won't underflow by waiting until | 861 // because this is a background render, we won't underflow by waiting until |
| 851 // a pending read is ready. | 862 // a pending read is ready. |
| 852 null_video_sink_->set_background_render(true); | 863 null_video_sink_->set_background_render(true); |
| 853 AdvanceTimeInMs(91); | 864 AdvanceTimeInMs(91); |
| 854 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90))); | 865 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90))); |
| 855 WaitForPendingDecode(); | 866 WaitForPendingDecode(); |
| 856 SatisfyPendingDecodeWithEndOfStream(); | 867 SatisfyPendingDecodeWithEndOfStream(); |
| 857 | 868 |
| 858 // If this wasn't background rendering mode, this would result in two frames | |
| 859 // being dropped, but since we set background render to true, none should be | |
| 860 // reported | |
| 861 EXPECT_EQ(0u, last_pipeline_statistics.video_frames_dropped); | |
| 862 EXPECT_EQ(4u, last_pipeline_statistics.video_frames_decoded); | |
| 863 EXPECT_EQ(115200, last_pipeline_statistics.video_memory_usage); | |
| 864 | |
| 865 AdvanceTimeInMs(30); | 869 AdvanceTimeInMs(30); |
| 866 WaitForEnded(); | 870 WaitForEnded(); |
| 867 Destroy(); | 871 Destroy(); |
| 868 } | 872 } |
| 869 | 873 |
| 870 // Tests the case where underflow evicts all frames before EOS. | 874 // Tests the case where underflow evicts all frames before EOS. |
| 871 TEST_F(VideoRendererImplTest, UnderflowEvictionBeforeEOS) { | 875 TEST_F(VideoRendererImplTest, UnderflowEvictionBeforeEOS) { |
| 872 Initialize(); | 876 Initialize(); |
| 873 QueueFrames("0 30 60 90 100"); | 877 QueueFrames("0 30 60 90 100"); |
| 874 | 878 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 QueueFrames("0 10 20 30"); | 1141 QueueFrames("0 10 20 30"); |
| 1138 StartPlayingFrom(0); | 1142 StartPlayingFrom(0); |
| 1139 Flush(); | 1143 Flush(); |
| 1140 ASSERT_EQ(1u, frame_ready_cbs_.size()); | 1144 ASSERT_EQ(1u, frame_ready_cbs_.size()); |
| 1141 // This frame will be discarded. | 1145 // This frame will be discarded. |
| 1142 frame_ready_cbs_.front().Run(); | 1146 frame_ready_cbs_.front().Run(); |
| 1143 Destroy(); | 1147 Destroy(); |
| 1144 } | 1148 } |
| 1145 | 1149 |
| 1146 } // namespace media | 1150 } // namespace media |
| OLD | NEW |