OLD | NEW |
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 #include <utility> | 5 #include <utility> |
| 6 #include <vector> |
6 | 7 |
7 #include "base/bind.h" | 8 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "media/base/fake_demuxer_stream.h" | 14 #include "media/base/fake_demuxer_stream.h" |
14 #include "media/base/gmock_callback_support.h" | 15 #include "media/base/gmock_callback_support.h" |
15 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 kNumBuffersInOneConfig, | 64 kNumBuffersInOneConfig, |
64 GetParam().is_encrypted)), | 65 GetParam().is_encrypted)), |
65 is_initialized_(false), | 66 is_initialized_(false), |
66 num_decoded_frames_(0), | 67 num_decoded_frames_(0), |
67 pending_initialize_(false), | 68 pending_initialize_(false), |
68 pending_read_(false), | 69 pending_read_(false), |
69 pending_reset_(false), | 70 pending_reset_(false), |
70 pending_stop_(false), | 71 pending_stop_(false), |
71 num_decoded_bytes_unreported_(0), | 72 num_decoded_bytes_unreported_(0), |
72 has_no_key_(false) { | 73 has_no_key_(false) { |
73 int decoding_delay = GetParam().decoding_delay; | |
74 int parallel_decoding = GetParam().parallel_decoding; | |
75 BytesDecodedCB bytes_decoded_cb = base::Bind( | |
76 &VideoFrameStreamTest::OnBytesDecoded, base::Unretained(this)); | |
77 | |
78 // Provide 3 decoders to test fallback cases. | |
79 // TODO(xhwang): We should test the case where only certain decoder | |
80 // supports encrypted streams. Currently this is hard to test because we use | |
81 // parameterized tests which need to pass in all combinations. | |
82 ScopedVector<VideoDecoder> decoders; | |
83 for (int i = 0; i < 3; ++i) { | |
84 FakeVideoDecoder* decoder = | |
85 new FakeVideoDecoder(GetDecoderName(i), decoding_delay, | |
86 parallel_decoding, bytes_decoded_cb); | |
87 | |
88 if (GetParam().is_encrypted && !GetParam().has_decryptor) | |
89 decoder->EnableEncryptedConfigSupport(); | |
90 | |
91 decoders.push_back(decoder); | |
92 | |
93 // Keep a copy of the raw pointers so we can change the behavior of each | |
94 // decoder. | |
95 decoders_.push_back(decoder); | |
96 } | |
97 | |
98 video_frame_stream_.reset(new VideoFrameStream( | 74 video_frame_stream_.reset(new VideoFrameStream( |
99 message_loop_.task_runner(), std::move(decoders), &media_log_)); | 75 message_loop_.task_runner(), |
100 | 76 base::Bind(&VideoFrameStreamTest::CreateVideoDecodersForTest, |
| 77 base::Unretained(this)), |
| 78 &media_log_)); |
101 video_frame_stream_->set_decoder_change_observer_for_testing(base::Bind( | 79 video_frame_stream_->set_decoder_change_observer_for_testing(base::Bind( |
102 &VideoFrameStreamTest::OnDecoderChanged, base::Unretained(this))); | 80 &VideoFrameStreamTest::OnDecoderChanged, base::Unretained(this))); |
103 | 81 |
104 if (GetParam().is_encrypted && GetParam().has_decryptor) { | 82 if (GetParam().is_encrypted && GetParam().has_decryptor) { |
105 decryptor_.reset(new NiceMock<MockDecryptor>()); | 83 decryptor_.reset(new NiceMock<MockDecryptor>()); |
106 | 84 |
107 // Decryptor can only decrypt (not decrypt-and-decode) so that | 85 // Decryptor can only decrypt (not decrypt-and-decode) so that |
108 // DecryptingDemuxerStream will be used. | 86 // DecryptingDemuxerStream will be used. |
109 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _)) | 87 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _)) |
110 .WillRepeatedly(RunCallback<1>(false)); | 88 .WillRepeatedly(RunCallback<1>(false)); |
(...skipping 17 matching lines...) Expand all Loading... |
128 decoders_.clear(); | 106 decoders_.clear(); |
129 video_frame_stream_.reset(); | 107 video_frame_stream_.reset(); |
130 base::RunLoop().RunUntilIdle(); | 108 base::RunLoop().RunUntilIdle(); |
131 | 109 |
132 DCHECK(!pending_initialize_); | 110 DCHECK(!pending_initialize_); |
133 DCHECK(!pending_read_); | 111 DCHECK(!pending_read_); |
134 DCHECK(!pending_reset_); | 112 DCHECK(!pending_reset_); |
135 DCHECK(!pending_stop_); | 113 DCHECK(!pending_stop_); |
136 } | 114 } |
137 | 115 |
| 116 void OnBytesDecoded(int count) { |
| 117 num_decoded_bytes_unreported_ += count; |
| 118 } |
| 119 |
| 120 // Callback to create a list of decoders for the DecoderSelector to select |
| 121 // from. Decoder selection happens |
| 122 // - on the initial selection in Initialize(), |
| 123 // - on decoder reinitialization failure, which can be simulated by calling |
| 124 // decoder_->SimulateFailureToInit(), and |
| 125 // - on decode error of the first buffer, which can be simulated by calling |
| 126 // decoder_->SimulateError() before reading the first frame. |
| 127 ScopedVector<VideoDecoder> CreateVideoDecodersForTest() { |
| 128 // Previously decoders could have been destroyed on decoder reselection. |
| 129 decoders_.clear(); |
| 130 |
| 131 // Provide 3 decoders to test fallback cases. |
| 132 // TODO(xhwang): We should test the case where only certain decoder |
| 133 // supports encrypted streams. Currently this is hard to test because we use |
| 134 // parameterized tests which need to pass in all combinations. |
| 135 ScopedVector<VideoDecoder> decoders; |
| 136 for (int i = 0; i < 3; ++i) { |
| 137 FakeVideoDecoder* decoder = |
| 138 new FakeVideoDecoder(GetDecoderName(i), GetParam().decoding_delay, |
| 139 GetParam().parallel_decoding, |
| 140 base::Bind(&VideoFrameStreamTest::OnBytesDecoded, |
| 141 base::Unretained(this))); |
| 142 |
| 143 if (GetParam().is_encrypted && !GetParam().has_decryptor) |
| 144 decoder->EnableEncryptedConfigSupport(); |
| 145 |
| 146 decoders.push_back(decoder); |
| 147 |
| 148 // Keep a copy of the raw pointers so we can change the behavior of each |
| 149 // decoder. |
| 150 decoders_.push_back(decoder); |
| 151 } |
| 152 |
| 153 for (const auto& i : decoder_indices_to_fail_init_) |
| 154 decoders_[i]->SimulateFailureToInit(); |
| 155 |
| 156 for (const auto& i : decoder_indices_to_hold_init_) |
| 157 decoders_[i]->HoldNextInit(); |
| 158 |
| 159 for (const auto& i : decoder_indices_to_hold_decode_) |
| 160 decoders_[i]->HoldDecode(); |
| 161 |
| 162 decoder_indices_to_fail_init_.clear(); |
| 163 decoder_indices_to_hold_init_.clear(); |
| 164 decoder_indices_to_hold_decode_.clear(); |
| 165 |
| 166 return decoders; |
| 167 } |
| 168 |
| 169 // On next decoder selection, fail initialization on decoders specified by |
| 170 // |decoder_indices|. |
| 171 void FailDecoderInitOnSelection(const std::vector<int>& decoder_indices) { |
| 172 decoder_indices_to_fail_init_ = decoder_indices; |
| 173 } |
| 174 |
| 175 // On next decoder selection, hold initialization on decoders specified by |
| 176 // |decoder_indices|. |
| 177 void HoldDecoderInitOnSelection(const std::vector<int>& decoder_indices) { |
| 178 decoder_indices_to_hold_init_ = decoder_indices; |
| 179 } |
| 180 |
| 181 // After next decoder selection, hold decode on decoders specified by |
| 182 // |decoder_indices|. This is needed because after decoder selection decode |
| 183 // may be resumed immediately and it'll be too late to hold decode then. |
| 184 void HoldDecodeAfterSelection(const std::vector<int>& decoder_indices) { |
| 185 decoder_indices_to_hold_decode_ = decoder_indices; |
| 186 } |
| 187 |
| 188 // Updates the |decoder_| currently being used by VideoFrameStream. |
| 189 void OnDecoderChanged(VideoDecoder* decoder) { |
| 190 if (!decoder) { |
| 191 decoder_ = nullptr; |
| 192 return; |
| 193 } |
| 194 |
| 195 std::string name = decoder->GetDisplayName(); |
| 196 ASSERT_TRUE(GetDecoderName(0) == name || GetDecoderName(1) == name || |
| 197 GetDecoderName(2) == name); |
| 198 decoder_ = static_cast<FakeVideoDecoder*>(decoder); |
| 199 } |
| 200 |
138 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); | 201 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); |
139 | 202 |
140 void OnStatistics(const PipelineStatistics& statistics) { | 203 void OnStatistics(const PipelineStatistics& statistics) { |
141 num_decoded_bytes_unreported_ -= statistics.video_bytes_decoded; | 204 num_decoded_bytes_unreported_ -= statistics.video_bytes_decoded; |
142 } | 205 } |
143 | 206 |
144 void OnBytesDecoded(int count) { | |
145 num_decoded_bytes_unreported_ += count; | |
146 } | |
147 | |
148 void SimulateDecoderInitFailure(const std::vector<int>& decoder_indices) { | |
149 for (const auto& i : decoder_indices) | |
150 decoders_[i]->SimulateFailureToInit(); | |
151 } | |
152 | |
153 void OnInitialized(bool success) { | 207 void OnInitialized(bool success) { |
154 DCHECK(!pending_read_); | 208 DCHECK(!pending_read_); |
155 DCHECK(!pending_reset_); | 209 DCHECK(!pending_reset_); |
156 DCHECK(pending_initialize_); | 210 DCHECK(pending_initialize_); |
157 pending_initialize_ = false; | 211 pending_initialize_ = false; |
158 | 212 |
159 is_initialized_ = success; | 213 is_initialized_ = success; |
160 if (!success) | 214 if (!success) |
161 decoders_.clear(); | 215 decoders_.clear(); |
162 } | 216 } |
163 | 217 |
164 void Initialize() { | 218 void Initialize() { |
165 pending_initialize_ = true; | 219 pending_initialize_ = true; |
166 video_frame_stream_->Initialize( | 220 video_frame_stream_->Initialize( |
167 demuxer_stream_.get(), base::Bind(&VideoFrameStreamTest::OnInitialized, | 221 demuxer_stream_.get(), base::Bind(&VideoFrameStreamTest::OnInitialized, |
168 base::Unretained(this)), | 222 base::Unretained(this)), |
169 cdm_context_.get(), | 223 cdm_context_.get(), |
170 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)), | 224 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)), |
171 base::Bind(&VideoFrameStreamTest::OnWaitingForDecryptionKey, | 225 base::Bind(&VideoFrameStreamTest::OnWaitingForDecryptionKey, |
172 base::Unretained(this))); | 226 base::Unretained(this))); |
173 base::RunLoop().RunUntilIdle(); | 227 base::RunLoop().RunUntilIdle(); |
174 } | 228 } |
175 | 229 |
176 void OnDecoderChanged(VideoDecoder* decoder) { | |
177 if (!decoder) { | |
178 decoder_ = nullptr; | |
179 return; | |
180 } | |
181 | |
182 std::string name = decoder->GetDisplayName(); | |
183 ASSERT_TRUE(GetDecoderName(0) == name || GetDecoderName(1) == name || | |
184 GetDecoderName(2) == name); | |
185 decoder_ = static_cast<FakeVideoDecoder*>(decoder); | |
186 } | |
187 | |
188 // Fake Decrypt() function used by DecryptingDemuxerStream. It does nothing | 230 // Fake Decrypt() function used by DecryptingDemuxerStream. It does nothing |
189 // but removes the DecryptConfig to make the buffer unencrypted. | 231 // but removes the DecryptConfig to make the buffer unencrypted. |
190 void Decrypt(Decryptor::StreamType stream_type, | 232 void Decrypt(Decryptor::StreamType stream_type, |
191 const scoped_refptr<DecoderBuffer>& encrypted, | 233 const scoped_refptr<DecoderBuffer>& encrypted, |
192 const Decryptor::DecryptCB& decrypt_cb) { | 234 const Decryptor::DecryptCB& decrypt_cb) { |
193 DCHECK(encrypted->decrypt_config()); | 235 DCHECK(encrypted->decrypt_config()); |
194 if (has_no_key_) { | 236 if (has_no_key_) { |
195 decrypt_cb.Run(Decryptor::kNoKey, NULL); | 237 decrypt_cb.Run(Decryptor::kNoKey, NULL); |
196 return; | 238 return; |
197 } | 239 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 409 |
368 // Use NiceMock since we don't care about most of calls on the decryptor, | 410 // Use NiceMock since we don't care about most of calls on the decryptor, |
369 // e.g. RegisterNewKeyCB(). | 411 // e.g. RegisterNewKeyCB(). |
370 std::unique_ptr<NiceMock<MockDecryptor>> decryptor_; | 412 std::unique_ptr<NiceMock<MockDecryptor>> decryptor_; |
371 | 413 |
372 // Raw pointers to the list of decoders to be select from by DecoderSelector. | 414 // Raw pointers to the list of decoders to be select from by DecoderSelector. |
373 // Three decoders are needed to test that decoder fallback can occur more than | 415 // Three decoders are needed to test that decoder fallback can occur more than |
374 // once on a config change. They are owned by |video_frame_stream_|. | 416 // once on a config change. They are owned by |video_frame_stream_|. |
375 std::vector<FakeVideoDecoder*> decoders_; | 417 std::vector<FakeVideoDecoder*> decoders_; |
376 | 418 |
| 419 std::vector<int> decoder_indices_to_fail_init_; |
| 420 std::vector<int> decoder_indices_to_hold_init_; |
| 421 std::vector<int> decoder_indices_to_hold_decode_; |
| 422 |
377 // The current decoder used by |video_frame_stream_|. | 423 // The current decoder used by |video_frame_stream_|. |
378 FakeVideoDecoder* decoder_; | 424 FakeVideoDecoder* decoder_; |
379 | 425 |
380 bool is_initialized_; | 426 bool is_initialized_; |
381 int num_decoded_frames_; | 427 int num_decoded_frames_; |
382 bool pending_initialize_; | 428 bool pending_initialize_; |
383 bool pending_read_; | 429 bool pending_read_; |
384 bool pending_reset_; | 430 bool pending_reset_; |
385 bool pending_stop_; | 431 bool pending_stop_; |
386 int num_decoded_bytes_unreported_; | 432 int num_decoded_bytes_unreported_; |
(...skipping 29 matching lines...) Expand all Loading... |
416 VideoFrameStreamTest, | 462 VideoFrameStreamTest, |
417 ::testing::Values(VideoFrameStreamTestParams(false, false, 0, 3), | 463 ::testing::Values(VideoFrameStreamTestParams(false, false, 0, 3), |
418 VideoFrameStreamTestParams(false, false, 2, 3))); | 464 VideoFrameStreamTestParams(false, false, 2, 3))); |
419 | 465 |
420 TEST_P(VideoFrameStreamTest, Initialization) { | 466 TEST_P(VideoFrameStreamTest, Initialization) { |
421 Initialize(); | 467 Initialize(); |
422 EXPECT_TRUE(is_initialized_); | 468 EXPECT_TRUE(is_initialized_); |
423 } | 469 } |
424 | 470 |
425 TEST_P(VideoFrameStreamTest, AllDecoderInitializationFails) { | 471 TEST_P(VideoFrameStreamTest, AllDecoderInitializationFails) { |
426 SimulateDecoderInitFailure({0, 1, 2}); | 472 FailDecoderInitOnSelection({0, 1, 2}); |
427 Initialize(); | 473 Initialize(); |
428 EXPECT_FALSE(is_initialized_); | 474 EXPECT_FALSE(is_initialized_); |
429 } | 475 } |
430 | 476 |
431 TEST_P(VideoFrameStreamTest, PartialDecoderInitializationFails) { | 477 TEST_P(VideoFrameStreamTest, PartialDecoderInitializationFails) { |
432 SimulateDecoderInitFailure({0, 1}); | 478 FailDecoderInitOnSelection({0, 1}); |
433 Initialize(); | 479 Initialize(); |
434 EXPECT_TRUE(is_initialized_); | 480 EXPECT_TRUE(is_initialized_); |
435 } | 481 } |
436 | 482 |
437 TEST_P(VideoFrameStreamTest, ReadOneFrame) { | 483 TEST_P(VideoFrameStreamTest, ReadOneFrame) { |
438 Initialize(); | 484 Initialize(); |
439 Read(); | 485 Read(); |
440 } | 486 } |
441 | 487 |
442 TEST_P(VideoFrameStreamTest, ReadAllFrames) { | 488 TEST_P(VideoFrameStreamTest, ReadAllFrames) { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 Reset(); | 699 Reset(); |
654 } | 700 } |
655 | 701 |
656 // In the following Destroy_* tests, |video_frame_stream_| is destroyed in | 702 // In the following Destroy_* tests, |video_frame_stream_| is destroyed in |
657 // VideoFrameStreamTest dtor. | 703 // VideoFrameStreamTest dtor. |
658 | 704 |
659 TEST_P(VideoFrameStreamTest, Destroy_BeforeInitialization) { | 705 TEST_P(VideoFrameStreamTest, Destroy_BeforeInitialization) { |
660 } | 706 } |
661 | 707 |
662 TEST_P(VideoFrameStreamTest, Destroy_DuringInitialization) { | 708 TEST_P(VideoFrameStreamTest, Destroy_DuringInitialization) { |
663 decoders_[0]->HoldNextInit(); | 709 HoldDecoderInitOnSelection({0}); |
664 Initialize(); | 710 Initialize(); |
665 } | 711 } |
666 | 712 |
667 TEST_P(VideoFrameStreamTest, Destroy_AfterInitialization) { | 713 TEST_P(VideoFrameStreamTest, Destroy_AfterInitialization) { |
668 Initialize(); | 714 Initialize(); |
669 } | 715 } |
670 | 716 |
671 TEST_P(VideoFrameStreamTest, Destroy_DuringReinitialization) { | 717 TEST_P(VideoFrameStreamTest, Destroy_DuringReinitialization) { |
672 Initialize(); | 718 Initialize(); |
673 EnterPendingState(DECODER_REINIT); | 719 EnterPendingState(DECODER_REINIT); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 EnterPendingState(DECODER_RESET); | 783 EnterPendingState(DECODER_RESET); |
738 SatisfyPendingCallback(DECODER_DECODE); | 784 SatisfyPendingCallback(DECODER_DECODE); |
739 } | 785 } |
740 | 786 |
741 TEST_P(VideoFrameStreamTest, Destroy_AfterRead_AfterReset) { | 787 TEST_P(VideoFrameStreamTest, Destroy_AfterRead_AfterReset) { |
742 Initialize(); | 788 Initialize(); |
743 Read(); | 789 Read(); |
744 Reset(); | 790 Reset(); |
745 } | 791 } |
746 | 792 |
747 // The following tests cover the fallback logic. | 793 // The following tests cover the fallback logic after reinitialization error or |
| 794 // decode error of the first buffer after initialization. |
748 | 795 |
749 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitialDecodeError) { | 796 TEST_P(VideoFrameStreamTest, FallbackDecoder_DecodeError) { |
750 Initialize(); | 797 Initialize(); |
751 decoder_->SimulateError(); | 798 decoder_->SimulateError(); |
752 ReadOneFrame(); | 799 ReadOneFrame(); |
753 | 800 |
754 // |video_frame_stream_| should have fallen back to a new decoder. | 801 // |video_frame_stream_| should have fallen back to a new decoder. |
755 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); | 802 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
| 803 |
756 ASSERT_FALSE(pending_read_); | 804 ASSERT_FALSE(pending_read_); |
757 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); | 805 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); |
758 | 806 |
759 // Check that we fallbacked to Decoder2. | 807 // Check that we fallbacked to Decoder2. |
760 ASSERT_GT(decoder_->total_bytes_decoded(), 0); | 808 ASSERT_GT(decoder_->total_bytes_decoded(), 0); |
761 | 809 |
762 // Verify no frame was dropped. | 810 // Verify no frame was dropped. |
763 ReadAllFrames(); | 811 ReadAllFrames(); |
764 } | 812 } |
765 | 813 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 // Queue one read, defer the second. | 865 // Queue one read, defer the second. |
818 frame_read_ = nullptr; | 866 frame_read_ = nullptr; |
819 pending_read_ = true; | 867 pending_read_ = true; |
820 video_frame_stream_->Read( | 868 video_frame_stream_->Read( |
821 base::Bind(&VideoFrameStreamTest::FrameReady, base::Unretained(this))); | 869 base::Bind(&VideoFrameStreamTest::FrameReady, base::Unretained(this))); |
822 demuxer_stream_->HoldNextRead(); | 870 demuxer_stream_->HoldNextRead(); |
823 | 871 |
824 // Force an error to occur on the first decode, but ensure it isn't propagated | 872 // Force an error to occur on the first decode, but ensure it isn't propagated |
825 // until after the next read has been started. | 873 // until after the next read has been started. |
826 decoder_->SimulateError(); | 874 decoder_->SimulateError(); |
827 decoders_[1]->HoldDecode(); | 875 HoldDecodeAfterSelection({1}); |
828 | 876 |
829 // Complete the fallback to the second decoder with the read still pending. | 877 // Complete the fallback to the second decoder with the read still pending. |
830 base::RunLoop().RunUntilIdle(); | 878 base::RunLoop().RunUntilIdle(); |
831 | 879 |
832 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); | 880 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
833 | 881 |
834 // Can't check the original decoder right now, it might have been destroyed | 882 // Can't check the original decoder right now, it might have been destroyed |
835 // already. Verify that there was nothing decoded until we kicked the decoder. | 883 // already. Verify that there was nothing decoded until we kicked the decoder. |
836 EXPECT_EQ(decoder_->total_bytes_decoded(), 0); | 884 EXPECT_EQ(decoder_->total_bytes_decoded(), 0); |
837 decoder_->SatisfyDecode(); | 885 decoder_->SatisfyDecode(); |
838 const int first_decoded_bytes = decoder_->total_bytes_decoded(); | 886 const int first_decoded_bytes = decoder_->total_bytes_decoded(); |
839 ASSERT_GT(first_decoded_bytes, 0); | 887 ASSERT_GT(first_decoded_bytes, 0); |
840 | 888 |
841 // Satisfy the previously pending read and ensure it is decoded. | 889 // Satisfy the previously pending read and ensure it is decoded. |
842 demuxer_stream_->SatisfyRead(); | 890 demuxer_stream_->SatisfyRead(); |
843 base::RunLoop().RunUntilIdle(); | 891 base::RunLoop().RunUntilIdle(); |
844 ASSERT_GT(decoder_->total_bytes_decoded(), first_decoded_bytes); | 892 ASSERT_GT(decoder_->total_bytes_decoded(), first_decoded_bytes); |
845 } | 893 } |
846 | 894 |
847 TEST_P(VideoFrameStreamTest, | 895 TEST_P(VideoFrameStreamTest, FallbackDecoder_DecodeErrorTwice) { |
848 FallbackDecoder_SelectedOnInitialDecodeError_Twice) { | |
849 Initialize(); | 896 Initialize(); |
| 897 |
| 898 // Simulate decode error to trigger the fallback path. |
850 decoder_->SimulateError(); | 899 decoder_->SimulateError(); |
851 | 900 |
852 decoders_[1]->HoldNextInit(); | 901 // Decoder 0 should be blacklisted and never tried. Hold decode on decoder 1 |
| 902 // and simulate decode error again. |
| 903 HoldDecodeAfterSelection({1}); |
853 ReadOneFrame(); | 904 ReadOneFrame(); |
854 | 905 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
855 decoders_[1]->SatisfyInit(); | 906 decoder_->SimulateError(); |
856 decoders_[1]->SimulateError(); | 907 decoder_->SatisfyDecode(); |
857 base::RunLoop().RunUntilIdle(); | 908 base::RunLoop().RunUntilIdle(); |
858 | 909 |
859 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName()); | 910 // Only one fallback is allowed so we are not falling back to other decoders. |
| 911 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
| 912 EXPECT_FALSE(pending_read_); |
| 913 ASSERT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
| 914 } |
860 | 915 |
861 // |video_frame_stream_| should have fallen back to |decoders_[2]|. | 916 TEST_P(VideoFrameStreamTest, |
862 ASSERT_FALSE(pending_read_); | 917 FallbackDecoder_DecodeErrorTwice_AfterReinitialization) { |
863 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); | 918 Initialize(); |
864 | 919 |
865 // Can't check previously selected decoder(s) right now, they might have been | 920 // Simulate decode error to trigger the fallback path. |
866 // destroyed already. | 921 decoder_->SimulateError(); |
867 ASSERT_GT(decoder_->total_bytes_decoded(), 0); | 922 ReadOneFrame(); |
| 923 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
868 | 924 |
869 // Verify no frame was dropped. | 925 // Simulate reinitialize error of decoder 1. |
870 ReadAllFrames(); | 926 decoder_->SimulateFailureToInit(); |
| 927 |
| 928 // Decoder 0 should be selected again. Simulate immediate decode error after |
| 929 // reinitialization. |
| 930 HoldDecodeAfterSelection({0}); |
| 931 ReadUntilDecoderReinitialized(); |
| 932 ASSERT_EQ(GetDecoderName(0), decoder_->GetDisplayName()); |
| 933 decoder_->SimulateError(); |
| 934 decoder_->SatisfyDecode(); |
| 935 base::RunLoop().RunUntilIdle(); |
| 936 |
| 937 // VideoDecoderStream has produced video frames, so we are not trying fallback |
| 938 // again. |
| 939 // TODO(xhwang): Revisit this behavior, e.g. always try to fallback if a newly |
| 940 // selected decoder has not produced any video frames before. |
| 941 ASSERT_EQ(GetDecoderName(0), decoder_->GetDisplayName()); |
| 942 EXPECT_FALSE(pending_read_); |
| 943 ASSERT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
871 } | 944 } |
872 | 945 |
873 TEST_P(VideoFrameStreamTest, FallbackDecoder_ConfigChangeClearsPendingBuffers) { | 946 TEST_P(VideoFrameStreamTest, FallbackDecoder_ConfigChangeClearsPendingBuffers) { |
874 // Test case is only interesting if the decoder can receive a config change | 947 // Test case is only interesting if the decoder can receive a config change |
875 // before returning its first frame. | 948 // before returning its first frame. |
876 if (GetParam().decoding_delay < kNumBuffersInOneConfig) | 949 if (GetParam().decoding_delay < kNumBuffersInOneConfig) |
877 return; | 950 return; |
878 | 951 |
879 Initialize(); | 952 Initialize(); |
880 EnterPendingState(DEMUXER_READ_CONFIG_CHANGE); | 953 EnterPendingState(DEMUXER_READ_CONFIG_CHANGE); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 TEST_P(VideoFrameStreamTest, FallbackDecoder_PendingBuffersIsFilledAndCleared) { | 991 TEST_P(VideoFrameStreamTest, FallbackDecoder_PendingBuffersIsFilledAndCleared) { |
919 // Test applies only when there is a decoder delay, and the decoder will not | 992 // Test applies only when there is a decoder delay, and the decoder will not |
920 // receive a config change before outputing its first frame. Parallel decoding | 993 // receive a config change before outputing its first frame. Parallel decoding |
921 // is also disabled in this test case, for readability and simplicity of the | 994 // is also disabled in this test case, for readability and simplicity of the |
922 // unit test. | 995 // unit test. |
923 if (GetParam().decoding_delay == 0 || | 996 if (GetParam().decoding_delay == 0 || |
924 GetParam().decoding_delay > kNumBuffersInOneConfig || | 997 GetParam().decoding_delay > kNumBuffersInOneConfig || |
925 GetParam().parallel_decoding > 1) { | 998 GetParam().parallel_decoding > 1) { |
926 return; | 999 return; |
927 } | 1000 } |
| 1001 |
928 Initialize(); | 1002 Initialize(); |
929 | 1003 |
930 // Block on demuxer read and decoder decode so we can step through. | 1004 // Block on demuxer read and decoder decode so we can step through. |
931 demuxer_stream_->HoldNextRead(); | 1005 demuxer_stream_->HoldNextRead(); |
932 decoder_->HoldDecode(); | 1006 decoder_->HoldDecode(); |
933 ReadOneFrame(); | 1007 ReadOneFrame(); |
934 | 1008 |
935 int demuxer_reads_satisfied = 0; | 1009 int demuxer_reads_satisfied = 0; |
936 // Send back and requests buffers until the next one would fill the decoder | 1010 // Send back and requests buffers until the next one would fill the decoder |
937 // delay. | 1011 // delay. |
(...skipping 11 matching lines...) Expand all Loading... |
949 video_frame_stream_->get_pending_buffers_size_for_testing()); | 1023 video_frame_stream_->get_pending_buffers_size_for_testing()); |
950 // No fallback buffers should be queued up yet. | 1024 // No fallback buffers should be queued up yet. |
951 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); | 1025 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); |
952 } | 1026 } |
953 | 1027 |
954 // Hold the init before triggering the error, to verify internal state. | 1028 // Hold the init before triggering the error, to verify internal state. |
955 demuxer_stream_->SatisfyReadAndHoldNext(); | 1029 demuxer_stream_->SatisfyReadAndHoldNext(); |
956 ++demuxer_reads_satisfied; | 1030 ++demuxer_reads_satisfied; |
957 | 1031 |
958 decoder_->SimulateError(); | 1032 decoder_->SimulateError(); |
959 decoders_[1]->HoldNextInit(); | 1033 |
| 1034 HoldDecoderInitOnSelection({1}); |
| 1035 HoldDecodeAfterSelection({1}); |
| 1036 |
960 base::RunLoop().RunUntilIdle(); | 1037 base::RunLoop().RunUntilIdle(); |
961 | 1038 |
962 EXPECT_TRUE(pending_read_); | 1039 EXPECT_TRUE(pending_read_); |
963 EXPECT_EQ(demuxer_reads_satisfied, | 1040 EXPECT_EQ(demuxer_reads_satisfied, |
964 video_frame_stream_->get_pending_buffers_size_for_testing()); | 1041 video_frame_stream_->get_pending_buffers_size_for_testing()); |
965 | 1042 |
966 decoders_[1]->SatisfyInit(); | 1043 decoders_[1]->SatisfyInit(); |
967 decoders_[1]->HoldDecode(); | |
968 base::RunLoop().RunUntilIdle(); | 1044 base::RunLoop().RunUntilIdle(); |
969 | 1045 |
970 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); | 1046 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
971 | 1047 |
972 // Make sure the pending buffers have been transfered to fallback buffers. | 1048 // Make sure the pending buffers have been transfered to fallback buffers. |
973 // One call to Decode() during the initialization process, so we expect one | 1049 // One call to Decode() during the initialization process, so we expect one |
974 // buffer to already have been consumed from the fallback buffers. | 1050 // buffer to already have been consumed from the fallback buffers. |
975 // Pending buffers should never go down (unless we encounter a config change) | 1051 // Pending buffers should never go down (unless we encounter a config change) |
976 EXPECT_EQ(demuxer_reads_satisfied - 1, | 1052 EXPECT_EQ(demuxer_reads_satisfied - 1, |
977 video_frame_stream_->get_fallback_buffers_size_for_testing()); | 1053 video_frame_stream_->get_fallback_buffers_size_for_testing()); |
978 EXPECT_EQ(demuxer_reads_satisfied, | 1054 EXPECT_EQ(demuxer_reads_satisfied, |
979 video_frame_stream_->get_pending_buffers_size_for_testing()); | 1055 video_frame_stream_->get_pending_buffers_size_for_testing()); |
980 | 1056 |
981 decoder_->SatisfyDecode(); | 1057 decoder_->SatisfyDecode(); |
982 base::RunLoop().RunUntilIdle(); | 1058 base::RunLoop().RunUntilIdle(); |
983 | 1059 |
984 // Make sure all buffers consumed by |decoders_[1]| have come from the | 1060 // Make sure all buffers consumed by |decoders_| have come from the fallback. |
985 // fallback. Pending buffers should not have been cleared yet. | 1061 // Pending buffers should not have been cleared yet. |
986 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); | 1062 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); |
987 EXPECT_EQ(demuxer_reads_satisfied, | 1063 EXPECT_EQ(demuxer_reads_satisfied, |
988 video_frame_stream_->get_pending_buffers_size_for_testing()); | 1064 video_frame_stream_->get_pending_buffers_size_for_testing()); |
989 EXPECT_TRUE(pending_read_); | 1065 EXPECT_TRUE(pending_read_); |
990 | 1066 |
991 // Give the decoder one more buffer, enough to release a frame. | 1067 // Give the decoder one more buffer, enough to release a frame. |
992 demuxer_stream_->SatisfyReadAndHoldNext(); | 1068 demuxer_stream_->SatisfyReadAndHoldNext(); |
993 base::RunLoop().RunUntilIdle(); | 1069 base::RunLoop().RunUntilIdle(); |
994 | 1070 |
995 // New buffers should not have been added after the frame was released. | 1071 // New buffers should not have been added after the frame was released. |
996 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); | 1072 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); |
997 EXPECT_FALSE(pending_read_); | 1073 EXPECT_FALSE(pending_read_); |
998 | 1074 |
999 demuxer_stream_->SatisfyRead(); | 1075 demuxer_stream_->SatisfyRead(); |
1000 | 1076 |
1001 // Confirm no frames were dropped. | 1077 // Confirm no frames were dropped. |
1002 ReadAllFrames(); | 1078 ReadAllFrames(); |
1003 } | 1079 } |
1004 | 1080 |
1005 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnDecodeThenInitErrors) { | 1081 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnDecodeThenInitErrors) { |
1006 Initialize(); | 1082 Initialize(); |
1007 decoder_->SimulateError(); | 1083 decoder_->SimulateError(); |
1008 SimulateDecoderInitFailure({1}); | 1084 FailDecoderInitOnSelection({1}); |
1009 ReadOneFrame(); | 1085 ReadOneFrame(); |
1010 | 1086 |
| 1087 // Decoder 0 should be blacklisted, and decoder 1 fails to initialize, so |
| 1088 // |video_frame_stream_| should have fallen back to decoder 2. |
1011 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName()); | 1089 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName()); |
1012 | 1090 |
1013 // |video_frame_stream_| should have fallen back to |decoders_[2]| | |
1014 ASSERT_FALSE(pending_read_); | 1091 ASSERT_FALSE(pending_read_); |
1015 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); | 1092 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); |
1016 | 1093 |
1017 // Can't check previously selected decoder(s) right now, they might have been | 1094 // Can't check previously selected decoder(s) right now, they might have been |
1018 // destroyed already. | 1095 // destroyed already. |
1019 ASSERT_GT(decoder_->total_bytes_decoded(), 0); | 1096 ASSERT_GT(decoder_->total_bytes_decoded(), 0); |
1020 | 1097 |
1021 // Verify no frame was dropped. | 1098 // Verify no frame was dropped. |
1022 ReadAllFrames(); | 1099 ReadAllFrames(); |
1023 } | 1100 } |
1024 | 1101 |
1025 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitThenDecodeErrors) { | 1102 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitThenDecodeErrors) { |
1026 SimulateDecoderInitFailure({0}); | 1103 FailDecoderInitOnSelection({0}); |
1027 Initialize(); | 1104 Initialize(); |
1028 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); | 1105 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
1029 | 1106 |
1030 decoder_->HoldDecode(); | 1107 decoder_->HoldDecode(); |
1031 ReadOneFrame(); | 1108 ReadOneFrame(); |
1032 decoder_->SimulateError(); | 1109 decoder_->SimulateError(); |
1033 base::RunLoop().RunUntilIdle(); | 1110 base::RunLoop().RunUntilIdle(); |
1034 | 1111 |
1035 // |video_frame_stream_| should have fallen back to |decoders_[2]| | 1112 // |video_frame_stream_| should have fallen back to decoder 0. |
1036 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName()); | 1113 ASSERT_EQ(GetDecoderName(0), decoder_->GetDisplayName()); |
1037 | 1114 |
1038 ASSERT_FALSE(pending_read_); | 1115 ASSERT_FALSE(pending_read_); |
1039 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); | 1116 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); |
1040 | 1117 |
1041 // Can't check previously selected decoder(s) right now, they might have been | 1118 // Can't check previously selected decoder(s) right now, they might have been |
1042 // destroyed already. | 1119 // destroyed already. |
1043 ASSERT_GT(decoder_->total_bytes_decoded(), 0); | 1120 ASSERT_GT(decoder_->total_bytes_decoded(), 0); |
1044 | 1121 |
1045 // Verify no frame was dropped. | 1122 // Verify no frame was dropped. |
1046 ReadAllFrames(); | 1123 ReadAllFrames(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 | 1164 |
1088 // The error must surface from Read() as DECODE_ERROR. | 1165 // The error must surface from Read() as DECODE_ERROR. |
1089 while (last_read_status_ == VideoFrameStream::OK) { | 1166 while (last_read_status_ == VideoFrameStream::OK) { |
1090 ReadOneFrame(); | 1167 ReadOneFrame(); |
1091 base::RunLoop().RunUntilIdle(); | 1168 base::RunLoop().RunUntilIdle(); |
1092 EXPECT_FALSE(pending_read_); | 1169 EXPECT_FALSE(pending_read_); |
1093 } | 1170 } |
1094 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); | 1171 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
1095 } | 1172 } |
1096 | 1173 |
1097 TEST_P(VideoFrameStreamTest, FallbackDecoderSelectedOnFailureToReinitialize) { | 1174 TEST_P(VideoFrameStreamTest, ReinitializeFailure_Once) { |
1098 Initialize(); | 1175 Initialize(); |
1099 decoder_->SimulateFailureToInit(); | 1176 decoder_->SimulateFailureToInit(); |
1100 ReadUntilDecoderReinitialized(); | 1177 ReadUntilDecoderReinitialized(); |
1101 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); | 1178 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
1102 ReadAllFrames(); | 1179 ReadAllFrames(); |
1103 ASSERT_GT(decoder_->total_bytes_decoded(), 0); | 1180 ASSERT_GT(decoder_->total_bytes_decoded(), 0); |
1104 } | 1181 } |
1105 | 1182 |
1106 TEST_P(VideoFrameStreamTest, | 1183 TEST_P(VideoFrameStreamTest, ReinitializeFailure_Twice) { |
1107 FallbackDecoderSelectedOnFailureToReinitialize_Twice) { | |
1108 Initialize(); | 1184 Initialize(); |
| 1185 |
| 1186 // Trigger reinitialization error, and fallback to decoder 1. |
1109 decoder_->SimulateFailureToInit(); | 1187 decoder_->SimulateFailureToInit(); |
1110 ReadUntilDecoderReinitialized(); | 1188 ReadUntilDecoderReinitialized(); |
1111 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); | 1189 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
| 1190 |
1112 ReadOneFrame(); | 1191 ReadOneFrame(); |
| 1192 |
| 1193 // Trigger reinitialization error again, and fallback back to decoder 0. |
1113 decoder_->SimulateFailureToInit(); | 1194 decoder_->SimulateFailureToInit(); |
1114 ReadUntilDecoderReinitialized(); | 1195 ReadUntilDecoderReinitialized(); |
1115 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName()); | 1196 ASSERT_EQ(GetDecoderName(0), decoder_->GetDisplayName()); |
1116 ReadAllFrames(); | 1197 ReadAllFrames(); |
1117 } | 1198 } |
1118 | 1199 |
1119 TEST_P(VideoFrameStreamTest, DecodeErrorAfterFallbackDecoderSelectionFails) { | 1200 TEST_P(VideoFrameStreamTest, ReinitializeFailure_OneUnsupportedDecoder) { |
1120 Initialize(); | 1201 Initialize(); |
| 1202 |
| 1203 // The current decoder will fail to reinitialize and will be blacklisted. |
1121 decoder_->SimulateFailureToInit(); | 1204 decoder_->SimulateFailureToInit(); |
1122 SimulateDecoderInitFailure({1, 2}); | 1205 |
| 1206 // Decoder 1 will also fail to initialize on decoder selection. |
| 1207 FailDecoderInitOnSelection({1}); |
| 1208 |
1123 ReadUntilDecoderReinitialized(); | 1209 ReadUntilDecoderReinitialized(); |
| 1210 |
| 1211 // As a result, decoder 2 will be selected. |
| 1212 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName()); |
| 1213 |
| 1214 ReadAllFrames(); |
| 1215 } |
| 1216 |
| 1217 TEST_P(VideoFrameStreamTest, ReinitializeFailure_NoSupportedDecoder) { |
| 1218 Initialize(); |
| 1219 |
| 1220 // The current decoder will fail to reinitialize and will be blacklisted. |
| 1221 decoder_->SimulateFailureToInit(); |
| 1222 |
| 1223 // Decoder 1 and 2 will also fail to initialize on decoder selection. |
| 1224 FailDecoderInitOnSelection({1, 2}); |
| 1225 |
| 1226 ReadUntilDecoderReinitialized(); |
| 1227 |
1124 // The error will surface from Read() as DECODE_ERROR. | 1228 // The error will surface from Read() as DECODE_ERROR. |
1125 while (last_read_status_ == VideoFrameStream::OK) { | 1229 while (last_read_status_ == VideoFrameStream::OK) { |
1126 ReadOneFrame(); | 1230 ReadOneFrame(); |
1127 base::RunLoop().RunUntilIdle(); | 1231 base::RunLoop().RunUntilIdle(); |
1128 EXPECT_FALSE(pending_read_); | 1232 EXPECT_FALSE(pending_read_); |
1129 } | 1233 } |
1130 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); | 1234 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
1131 } | 1235 } |
1132 | 1236 |
1133 TEST_P(VideoFrameStreamTest, Destroy_DuringFallbackDecoderSelection) { | 1237 TEST_P(VideoFrameStreamTest, Destroy_DuringFallbackDecoderSelection) { |
1134 Initialize(); | 1238 Initialize(); |
1135 decoder_->SimulateFailureToInit(); | 1239 decoder_->SimulateFailureToInit(); |
1136 EnterPendingState(DECODER_REINIT); | 1240 EnterPendingState(DECODER_REINIT); |
1137 decoders_[1]->HoldNextInit(); | 1241 HoldDecoderInitOnSelection({1}); |
1138 SatisfyPendingCallback(DECODER_REINIT); | 1242 SatisfyPendingCallback(DECODER_REINIT); |
1139 } | 1243 } |
1140 | 1244 |
1141 } // namespace media | 1245 } // namespace media |
OLD | NEW |