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

Side by Side Diff: media/gpu/video_decode_accelerator_unittest.cc

Issue 2713863002: VDA unittest: test for calling Reset before NotifyFlushDone (Closed)
Patch Set: VDA unittest: test for calling Reset before NotifyFlushDone Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // The bulk of this file is support code; sorry about that. Here's an overview 5 // The bulk of this file is support code; sorry about that. Here's an overview
6 // to hopefully help readers of this code: 6 // to hopefully help readers of this code:
7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or 7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or
8 // Win/EGL. 8 // Win/EGL.
9 // - ClientState is an enum for the state of the decode client used by the test. 9 // - ClientState is an enum for the state of the decode client used by the test.
10 // - ClientStateNotification is a barrier abstraction that allows the test code 10 // - ClientStateNotification is a barrier abstraction that allows the test code
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // working directory. 143 // working directory.
144 base::FilePath g_test_file_path; 144 base::FilePath g_test_file_path;
145 145
146 // Environment to store rendering thread. 146 // Environment to store rendering thread.
147 class VideoDecodeAcceleratorTestEnvironment; 147 class VideoDecodeAcceleratorTestEnvironment;
148 VideoDecodeAcceleratorTestEnvironment* g_env; 148 VideoDecodeAcceleratorTestEnvironment* g_env;
149 149
150 // Magic constants for differentiating the reasons for NotifyResetDone being 150 // Magic constants for differentiating the reasons for NotifyResetDone being
151 // called. 151 // called.
152 enum ResetPoint { 152 enum ResetPoint {
153 // Reset() right after calling Flush() (before getting NotifyFlushDone()).
154 RESET_BEFORE_NOTIFY_FLUSH_DONE = -5,
153 // Reset() just after calling Decode() with a fragment containing config info. 155 // Reset() just after calling Decode() with a fragment containing config info.
154 RESET_AFTER_FIRST_CONFIG_INFO = -4, 156 RESET_AFTER_FIRST_CONFIG_INFO = -4,
155 START_OF_STREAM_RESET = -3, 157 START_OF_STREAM_RESET = -3,
156 MID_STREAM_RESET = -2, 158 MID_STREAM_RESET = -2,
157 END_OF_STREAM_RESET = -1 159 END_OF_STREAM_RESET = -1
158 }; 160 };
159 161
160 const int kMaxResetAfterFrameNum = 100; 162 const int kMaxResetAfterFrameNum = 100;
161 const int kMaxFramesToDelayReuse = 64; 163 const int kMaxFramesToDelayReuse = 64;
162 const base::TimeDelta kReuseDelay = base::TimeDelta::FromSeconds(1); 164 const base::TimeDelta kReuseDelay = base::TimeDelta::FromSeconds(1);
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 471
470 private: 472 private:
471 typedef std::map<int32_t, scoped_refptr<TextureRef>> TextureRefMap; 473 typedef std::map<int32_t, scoped_refptr<TextureRef>> TextureRefMap;
472 474
473 void SetState(ClientState new_state); 475 void SetState(ClientState new_state);
474 void FinishInitialization(); 476 void FinishInitialization();
475 void ReturnPicture(int32_t picture_buffer_id); 477 void ReturnPicture(int32_t picture_buffer_id);
476 478
477 // Delete the associated decoder helper. 479 // Delete the associated decoder helper.
478 void DeleteDecoder(); 480 void DeleteDecoder();
481 // Reset the associated decoder after flushing helper.
wuchengli 2017/03/07 14:24:02 s/helper//
johnylin1 2017/03/08 06:46:10 Done.
482 void ResetDecoderAfterFlush();
479 483
480 // Compute & return the first encoded bytes (including a start frame) to send 484 // Compute & return the first encoded bytes (including a start frame) to send
481 // to the decoder, starting at |start_pos| and returning one fragment. Skips 485 // to the decoder, starting at |start_pos| and returning one fragment. Skips
482 // to the first decodable position. 486 // to the first decodable position.
483 std::string GetBytesForFirstFragment(size_t start_pos, size_t* end_pos); 487 std::string GetBytesForFirstFragment(size_t start_pos, size_t* end_pos);
484 // Compute & return the encoded bytes of next fragment to send to the decoder 488 // Compute & return the encoded bytes of next fragment to send to the decoder
485 // (based on |start_pos|). 489 // (based on |start_pos|).
486 std::string GetBytesForNextFragment(size_t start_pos, size_t* end_pos); 490 std::string GetBytesForNextFragment(size_t start_pos, size_t* end_pos);
487 // Helpers for GetBytesForNextFragment above. 491 // Helpers for GetBytesForNextFragment above.
488 void GetBytesForNextNALU(size_t start_pos, size_t* end_pos); // For h.264. 492 void GetBytesForNextNALU(size_t start_pos, size_t* end_pos); // For h.264.
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 if (num_decoded_frames_ > delay_reuse_after_frame_num_) { 804 if (num_decoded_frames_ > delay_reuse_after_frame_num_) {
801 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 805 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
802 FROM_HERE, base::Bind(&VideoDecodeAccelerator::ReusePictureBuffer, 806 FROM_HERE, base::Bind(&VideoDecodeAccelerator::ReusePictureBuffer,
803 weak_vda_, picture_buffer_id), 807 weak_vda_, picture_buffer_id),
804 kReuseDelay); 808 kReuseDelay);
805 } else { 809 } else {
806 decoder_->ReusePictureBuffer(picture_buffer_id); 810 decoder_->ReusePictureBuffer(picture_buffer_id);
807 } 811 }
808 } 812 }
809 813
814 void GLRenderingVDAClient::ResetDecoderAfterFlush() {
815 --remaining_play_throughs_;
816 DCHECK_GE(remaining_play_throughs_, 0);
wuchengli 2017/03/07 14:24:02 Do we need if (decoder_deleted()) return; here? Th
johnylin1 2017/03/08 06:46:11 Yes, in original code since line849 has it so actu
817 decoder_->Reset();
818 SetState(CS_RESETTING);
819 }
820
810 void GLRenderingVDAClient::NotifyEndOfBitstreamBuffer( 821 void GLRenderingVDAClient::NotifyEndOfBitstreamBuffer(
811 int32_t bitstream_buffer_id) { 822 int32_t bitstream_buffer_id) {
812 if (decoder_deleted()) 823 if (decoder_deleted())
813 return; 824 return;
814 825
815 // TODO(fischman): this test currently relies on this notification to make 826 // TODO(fischman): this test currently relies on this notification to make
816 // forward progress during a Reset(). But the VDA::Reset() API doesn't 827 // forward progress during a Reset(). But the VDA::Reset() API doesn't
817 // guarantee this, so stop relying on it (and remove the notifications from 828 // guarantee this, so stop relying on it (and remove the notifications from
818 // VaapiVideoDecodeAccelerator::FinishReset()). 829 // VaapiVideoDecodeAccelerator::FinishReset()).
819 ++num_done_bitstream_buffers_; 830 ++num_done_bitstream_buffers_;
820 --outstanding_decodes_; 831 --outstanding_decodes_;
821 832
822 // Flush decoder after all BitstreamBuffers are processed. 833 // Flush decoder after all BitstreamBuffers are processed.
823 if (encoded_data_next_pos_to_decode_ == encoded_data_.size()) { 834 if (encoded_data_next_pos_to_decode_ == encoded_data_.size()) {
824 if (state_ != CS_FLUSHING) { 835 if (state_ != CS_FLUSHING) {
825 decoder_->Flush(); 836 decoder_->Flush();
826 SetState(CS_FLUSHING); 837 SetState(CS_FLUSHING);
838 if (reset_after_frame_num_ == RESET_BEFORE_NOTIFY_FLUSH_DONE) {
839 SetState(CS_FLUSHED);
840 ResetDecoderAfterFlush();
841 }
827 } 842 }
828 } else if (decode_calls_per_second_ == 0) { 843 } else if (decode_calls_per_second_ == 0) {
829 DecodeNextFragment(); 844 DecodeNextFragment();
830 } 845 }
831 } 846 }
832 847
833 void GLRenderingVDAClient::NotifyFlushDone() { 848 void GLRenderingVDAClient::NotifyFlushDone() {
834 if (decoder_deleted()) 849 if (decoder_deleted())
835 return; 850 return;
836 851
852 if (reset_after_frame_num_ == RESET_BEFORE_NOTIFY_FLUSH_DONE) {
853 // In ResetBeforeNotifyFlushDone case client is not necessary to wait for
854 // NotifyFlushDone(). But if client gets here, it should be always before
855 // NotifyResetDone().
856 ASSERT_EQ(state_, CS_RESETTING);
857 return;
858 }
859
837 SetState(CS_FLUSHED); 860 SetState(CS_FLUSHED);
838 --remaining_play_throughs_; 861 ResetDecoderAfterFlush();
839 DCHECK_GE(remaining_play_throughs_, 0);
840 if (decoder_deleted())
841 return;
842 decoder_->Reset();
843 SetState(CS_RESETTING);
844 } 862 }
845 863
846 void GLRenderingVDAClient::NotifyResetDone() { 864 void GLRenderingVDAClient::NotifyResetDone() {
847 if (decoder_deleted()) 865 if (decoder_deleted())
848 return; 866 return;
849 867
850 if (reset_after_frame_num_ == MID_STREAM_RESET) { 868 if (reset_after_frame_num_ == MID_STREAM_RESET) {
851 reset_after_frame_num_ = END_OF_STREAM_RESET; 869 reset_after_frame_num_ = END_OF_STREAM_RESET;
852 DecodeNextFragment(); 870 DecodeNextFragment();
853 return; 871 return;
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 if (delete_decoder_state < CS_FLUSHED) 1474 if (delete_decoder_state < CS_FLUSHED)
1457 continue; 1475 continue;
1458 GLRenderingVDAClient* client = clients_[i].get(); 1476 GLRenderingVDAClient* client = clients_[i].get();
1459 TestVideoFile* video_file = 1477 TestVideoFile* video_file =
1460 test_video_files_[i % test_video_files_.size()].get(); 1478 test_video_files_[i % test_video_files_.size()].get();
1461 if (video_file->num_frames > 0) { 1479 if (video_file->num_frames > 0) {
1462 // Expect the decoded frames may be more than the video frames as frames 1480 // Expect the decoded frames may be more than the video frames as frames
1463 // could still be returned until resetting done. 1481 // could still be returned until resetting done.
1464 if (video_file->reset_after_frame_num > 0) 1482 if (video_file->reset_after_frame_num > 0)
1465 EXPECT_GE(client->num_decoded_frames(), video_file->num_frames); 1483 EXPECT_GE(client->num_decoded_frames(), video_file->num_frames);
1466 else 1484 // In ResetBeforeNotifyFlushDone case the decoded frames may be less than
1485 // the video frames because decoder is reset before flush done.
1486 else if (video_file->reset_after_frame_num !=
1487 RESET_BEFORE_NOTIFY_FLUSH_DONE)
1467 EXPECT_EQ(client->num_decoded_frames(), video_file->num_frames); 1488 EXPECT_EQ(client->num_decoded_frames(), video_file->num_frames);
1468 } 1489 }
1469 if (reset_point == END_OF_STREAM_RESET) { 1490 if (reset_point == END_OF_STREAM_RESET) {
1470 EXPECT_EQ(video_file->num_fragments, client->num_skipped_fragments() + 1491 EXPECT_EQ(video_file->num_fragments, client->num_skipped_fragments() +
1471 client->num_queued_fragments()); 1492 client->num_queued_fragments());
1472 EXPECT_EQ(client->num_done_bitstream_buffers(), 1493 EXPECT_EQ(client->num_done_bitstream_buffers(),
1473 client->num_queued_fragments()); 1494 client->num_queued_fragments());
1474 } 1495 }
1475 LOG(INFO) << "Decoder " << i << " fps: " << client->frames_per_second(); 1496 LOG(INFO) << "Decoder " << i << " fps: " << client->frames_per_second();
1476 if (!render_as_thumbnails) { 1497 if (!render_as_thumbnails) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 ResetAfterFirstConfigInfo, 1580 ResetAfterFirstConfigInfo,
1560 VideoDecodeAcceleratorParamTest, 1581 VideoDecodeAcceleratorParamTest,
1561 ::testing::Values(std::make_tuple(1, 1582 ::testing::Values(std::make_tuple(1,
1562 1, 1583 1,
1563 1, 1584 1,
1564 RESET_AFTER_FIRST_CONFIG_INFO, 1585 RESET_AFTER_FIRST_CONFIG_INFO,
1565 CS_RESET, 1586 CS_RESET,
1566 false, 1587 false,
1567 false))); 1588 false)));
1568 1589
1590 // Test Reset() immediately after Flush() and before NotifyFlushDone().
1591 INSTANTIATE_TEST_CASE_P(
1592 ResetBeforeNotifyFlushDone,
1593 VideoDecodeAcceleratorParamTest,
1594 ::testing::Values(std::make_tuple(1,
1595 1,
1596 1,
1597 RESET_BEFORE_NOTIFY_FLUSH_DONE,
1598 CS_RESET,
1599 false,
1600 false)));
1601
1569 // Test that Reset() mid-stream works fine and doesn't affect decoding even when 1602 // Test that Reset() mid-stream works fine and doesn't affect decoding even when
1570 // Decode() calls are made during the reset. 1603 // Decode() calls are made during the reset.
1571 INSTANTIATE_TEST_CASE_P( 1604 INSTANTIATE_TEST_CASE_P(
1572 MidStreamReset, 1605 MidStreamReset,
1573 VideoDecodeAcceleratorParamTest, 1606 VideoDecodeAcceleratorParamTest,
1574 ::testing::Values( 1607 ::testing::Values(
1575 std::make_tuple(1, 1, 1, MID_STREAM_RESET, CS_RESET, false, false))); 1608 std::make_tuple(1, 1, 1, MID_STREAM_RESET, CS_RESET, false, false)));
1576 1609
1577 INSTANTIATE_TEST_CASE_P( 1610 INSTANTIATE_TEST_CASE_P(
1578 SlowRendering, 1611 SlowRendering,
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 continue; 1882 continue;
1850 } 1883 }
1851 } 1884 }
1852 1885
1853 base::ShadowingAtExitManager at_exit_manager; 1886 base::ShadowingAtExitManager at_exit_manager;
1854 1887
1855 return base::LaunchUnitTestsSerially( 1888 return base::LaunchUnitTestsSerially(
1856 argc, argv, 1889 argc, argv,
1857 base::Bind(&media::VDATestSuite::Run, base::Unretained(&test_suite))); 1890 base::Bind(&media::VDATestSuite::Run, base::Unretained(&test_suite)));
1858 } 1891 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698