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

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.
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/15 02:26:29 Document SetState(CS_RESETTING); should be called
johnylin1 2017/03/15 03:19:27 Done.
817 SetState(CS_RESETTING);
818 // It is necessary to check decoder deleted here because it is possible to
819 // delete decoder in SetState() in some cases.
820 if (decoder_deleted())
821 return;
822 decoder_->Reset();
823 }
824
810 void GLRenderingVDAClient::NotifyEndOfBitstreamBuffer( 825 void GLRenderingVDAClient::NotifyEndOfBitstreamBuffer(
811 int32_t bitstream_buffer_id) { 826 int32_t bitstream_buffer_id) {
812 if (decoder_deleted()) 827 if (decoder_deleted())
813 return; 828 return;
814 829
815 // TODO(fischman): this test currently relies on this notification to make 830 // TODO(fischman): this test currently relies on this notification to make
816 // forward progress during a Reset(). But the VDA::Reset() API doesn't 831 // 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 832 // guarantee this, so stop relying on it (and remove the notifications from
818 // VaapiVideoDecodeAccelerator::FinishReset()). 833 // VaapiVideoDecodeAccelerator::FinishReset()).
819 ++num_done_bitstream_buffers_; 834 ++num_done_bitstream_buffers_;
820 --outstanding_decodes_; 835 --outstanding_decodes_;
821 836
822 // Flush decoder after all BitstreamBuffers are processed. 837 // Flush decoder after all BitstreamBuffers are processed.
823 if (encoded_data_next_pos_to_decode_ == encoded_data_.size()) { 838 if (encoded_data_next_pos_to_decode_ == encoded_data_.size()) {
824 if (state_ != CS_FLUSHING) { 839 if (state_ != CS_FLUSHING) {
825 decoder_->Flush(); 840 decoder_->Flush();
826 SetState(CS_FLUSHING); 841 SetState(CS_FLUSHING);
842 if (reset_after_frame_num_ == RESET_BEFORE_NOTIFY_FLUSH_DONE) {
843 SetState(CS_FLUSHED);
844 ResetDecoderAfterFlush();
845 }
827 } 846 }
828 } else if (decode_calls_per_second_ == 0) { 847 } else if (decode_calls_per_second_ == 0) {
829 DecodeNextFragment(); 848 DecodeNextFragment();
830 } 849 }
831 } 850 }
832 851
833 void GLRenderingVDAClient::NotifyFlushDone() { 852 void GLRenderingVDAClient::NotifyFlushDone() {
834 if (decoder_deleted()) 853 if (decoder_deleted())
835 return; 854 return;
836 855
856 if (reset_after_frame_num_ == RESET_BEFORE_NOTIFY_FLUSH_DONE) {
857 // In ResetBeforeNotifyFlushDone case client is not necessary to wait for
858 // NotifyFlushDone(). But if client gets here, it should be always before
859 // NotifyResetDone().
860 ASSERT_EQ(state_, CS_RESETTING);
861 return;
862 }
863
837 SetState(CS_FLUSHED); 864 SetState(CS_FLUSHED);
838 --remaining_play_throughs_; 865 ResetDecoderAfterFlush();
839 DCHECK_GE(remaining_play_throughs_, 0);
840 if (decoder_deleted())
841 return;
842 decoder_->Reset();
843 SetState(CS_RESETTING);
844 } 866 }
845 867
846 void GLRenderingVDAClient::NotifyResetDone() { 868 void GLRenderingVDAClient::NotifyResetDone() {
847 if (decoder_deleted()) 869 if (decoder_deleted())
848 return; 870 return;
849 871
850 if (reset_after_frame_num_ == MID_STREAM_RESET) { 872 if (reset_after_frame_num_ == MID_STREAM_RESET) {
851 reset_after_frame_num_ = END_OF_STREAM_RESET; 873 reset_after_frame_num_ = END_OF_STREAM_RESET;
852 DecodeNextFragment(); 874 DecodeNextFragment();
853 return; 875 return;
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 if (delete_decoder_state < CS_FLUSHED) 1478 if (delete_decoder_state < CS_FLUSHED)
1457 continue; 1479 continue;
1458 GLRenderingVDAClient* client = clients_[i].get(); 1480 GLRenderingVDAClient* client = clients_[i].get();
1459 TestVideoFile* video_file = 1481 TestVideoFile* video_file =
1460 test_video_files_[i % test_video_files_.size()].get(); 1482 test_video_files_[i % test_video_files_.size()].get();
1461 if (video_file->num_frames > 0) { 1483 if (video_file->num_frames > 0) {
1462 // Expect the decoded frames may be more than the video frames as frames 1484 // Expect the decoded frames may be more than the video frames as frames
1463 // could still be returned until resetting done. 1485 // could still be returned until resetting done.
1464 if (video_file->reset_after_frame_num > 0) 1486 if (video_file->reset_after_frame_num > 0)
1465 EXPECT_GE(client->num_decoded_frames(), video_file->num_frames); 1487 EXPECT_GE(client->num_decoded_frames(), video_file->num_frames);
1466 else 1488 // In ResetBeforeNotifyFlushDone case the decoded frames may be less than
1489 // the video frames because decoder is reset before flush done.
1490 else if (video_file->reset_after_frame_num !=
1491 RESET_BEFORE_NOTIFY_FLUSH_DONE)
1467 EXPECT_EQ(client->num_decoded_frames(), video_file->num_frames); 1492 EXPECT_EQ(client->num_decoded_frames(), video_file->num_frames);
1468 } 1493 }
1469 if (reset_point == END_OF_STREAM_RESET) { 1494 if (reset_point == END_OF_STREAM_RESET) {
1470 EXPECT_EQ(video_file->num_fragments, client->num_skipped_fragments() + 1495 EXPECT_EQ(video_file->num_fragments, client->num_skipped_fragments() +
1471 client->num_queued_fragments()); 1496 client->num_queued_fragments());
1472 EXPECT_EQ(client->num_done_bitstream_buffers(), 1497 EXPECT_EQ(client->num_done_bitstream_buffers(),
1473 client->num_queued_fragments()); 1498 client->num_queued_fragments());
1474 } 1499 }
1475 LOG(INFO) << "Decoder " << i << " fps: " << client->frames_per_second(); 1500 LOG(INFO) << "Decoder " << i << " fps: " << client->frames_per_second();
1476 if (!render_as_thumbnails) { 1501 if (!render_as_thumbnails) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 ResetAfterFirstConfigInfo, 1584 ResetAfterFirstConfigInfo,
1560 VideoDecodeAcceleratorParamTest, 1585 VideoDecodeAcceleratorParamTest,
1561 ::testing::Values(std::make_tuple(1, 1586 ::testing::Values(std::make_tuple(1,
1562 1, 1587 1,
1563 1, 1588 1,
1564 RESET_AFTER_FIRST_CONFIG_INFO, 1589 RESET_AFTER_FIRST_CONFIG_INFO,
1565 CS_RESET, 1590 CS_RESET,
1566 false, 1591 false,
1567 false))); 1592 false)));
1568 1593
1594 // Test Reset() immediately after Flush() and before NotifyFlushDone().
1595 INSTANTIATE_TEST_CASE_P(
1596 ResetBeforeNotifyFlushDone,
1597 VideoDecodeAcceleratorParamTest,
1598 ::testing::Values(std::make_tuple(1,
1599 1,
1600 1,
1601 RESET_BEFORE_NOTIFY_FLUSH_DONE,
1602 CS_RESET,
1603 false,
1604 false)));
1605
1569 // Test that Reset() mid-stream works fine and doesn't affect decoding even when 1606 // Test that Reset() mid-stream works fine and doesn't affect decoding even when
1570 // Decode() calls are made during the reset. 1607 // Decode() calls are made during the reset.
1571 INSTANTIATE_TEST_CASE_P( 1608 INSTANTIATE_TEST_CASE_P(
1572 MidStreamReset, 1609 MidStreamReset,
1573 VideoDecodeAcceleratorParamTest, 1610 VideoDecodeAcceleratorParamTest,
1574 ::testing::Values( 1611 ::testing::Values(
1575 std::make_tuple(1, 1, 1, MID_STREAM_RESET, CS_RESET, false, false))); 1612 std::make_tuple(1, 1, 1, MID_STREAM_RESET, CS_RESET, false, false)));
1576 1613
1577 INSTANTIATE_TEST_CASE_P( 1614 INSTANTIATE_TEST_CASE_P(
1578 SlowRendering, 1615 SlowRendering,
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 continue; 1886 continue;
1850 } 1887 }
1851 } 1888 }
1852 1889
1853 base::ShadowingAtExitManager at_exit_manager; 1890 base::ShadowingAtExitManager at_exit_manager;
1854 1891
1855 return base::LaunchUnitTestsSerially( 1892 return base::LaunchUnitTestsSerially(
1856 argc, argv, 1893 argc, argv,
1857 base::Bind(&media::VDATestSuite::Run, base::Unretained(&test_suite))); 1894 base::Bind(&media::VDATestSuite::Run, base::Unretained(&test_suite)));
1858 } 1895 }
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