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

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