| 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 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "media/base/fake_demuxer_stream.h" | 13 #include "media/base/fake_demuxer_stream.h" |
| 13 #include "media/base/gmock_callback_support.h" | 14 #include "media/base/gmock_callback_support.h" |
| 14 #include "media/base/mock_filters.h" | 15 #include "media/base/mock_filters.h" |
| 15 #include "media/base/test_helpers.h" | 16 #include "media/base/test_helpers.h" |
| 16 #include "media/base/timestamp_constants.h" | 17 #include "media/base/timestamp_constants.h" |
| 17 #include "media/filters/decoder_stream.h" | 18 #include "media/filters/decoder_stream.h" |
| 18 #include "media/filters/fake_video_decoder.h" | 19 #include "media/filters/fake_video_decoder.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 using ::testing::_; | 22 using ::testing::_; |
| 22 using ::testing::AnyNumber; | 23 using ::testing::AnyNumber; |
| 23 using ::testing::Assign; | 24 using ::testing::Assign; |
| 24 using ::testing::Invoke; | 25 using ::testing::Invoke; |
| 25 using ::testing::InvokeWithoutArgs; | 26 using ::testing::InvokeWithoutArgs; |
| 26 using ::testing::NiceMock; | 27 using ::testing::NiceMock; |
| 27 using ::testing::Return; | 28 using ::testing::Return; |
| 28 using ::testing::SaveArg; | 29 using ::testing::SaveArg; |
| 29 using ::testing::StrictMock; | 30 using ::testing::StrictMock; |
| 30 | 31 |
| 31 static const int kNumConfigs = 4; | 32 namespace media { |
| 32 static const int kNumBuffersInOneConfig = 5; | |
| 33 | 33 |
| 34 namespace media { | 34 const int kNumConfigs = 4; |
| 35 const int kNumBuffersInOneConfig = 5; |
| 36 |
| 37 static std::string GetDecoderName(int i) { |
| 38 return std::string("VideoDecoder") + base::IntToString(i); |
| 39 } |
| 35 | 40 |
| 36 struct VideoFrameStreamTestParams { | 41 struct VideoFrameStreamTestParams { |
| 37 VideoFrameStreamTestParams(bool is_encrypted, | 42 VideoFrameStreamTestParams(bool is_encrypted, |
| 38 bool has_decryptor, | 43 bool has_decryptor, |
| 39 int decoding_delay, | 44 int decoding_delay, |
| 40 int parallel_decoding) | 45 int parallel_decoding) |
| 41 : is_encrypted(is_encrypted), | 46 : is_encrypted(is_encrypted), |
| 42 has_decryptor(has_decryptor), | 47 has_decryptor(has_decryptor), |
| 43 decoding_delay(decoding_delay), | 48 decoding_delay(decoding_delay), |
| 44 parallel_decoding(parallel_decoding) {} | 49 parallel_decoding(parallel_decoding) {} |
| (...skipping 18 matching lines...) Expand all Loading... |
| 63 pending_read_(false), | 68 pending_read_(false), |
| 64 pending_reset_(false), | 69 pending_reset_(false), |
| 65 pending_stop_(false), | 70 pending_stop_(false), |
| 66 num_decoded_bytes_unreported_(0), | 71 num_decoded_bytes_unreported_(0), |
| 67 has_no_key_(false) { | 72 has_no_key_(false) { |
| 68 int decoding_delay = GetParam().decoding_delay; | 73 int decoding_delay = GetParam().decoding_delay; |
| 69 int parallel_decoding = GetParam().parallel_decoding; | 74 int parallel_decoding = GetParam().parallel_decoding; |
| 70 BytesDecodedCB bytes_decoded_cb = base::Bind( | 75 BytesDecodedCB bytes_decoded_cb = base::Bind( |
| 71 &VideoFrameStreamTest::OnBytesDecoded, base::Unretained(this)); | 76 &VideoFrameStreamTest::OnBytesDecoded, base::Unretained(this)); |
| 72 | 77 |
| 73 decoder1_ = new FakeVideoDecoder(decoding_delay, parallel_decoding, | 78 // Provide 3 decoders to test fallback cases. |
| 74 bytes_decoded_cb); | |
| 75 decoder2_ = new FakeVideoDecoder(decoding_delay, parallel_decoding, | |
| 76 bytes_decoded_cb); | |
| 77 decoder3_ = new FakeVideoDecoder(decoding_delay, parallel_decoding, | |
| 78 bytes_decoded_cb); | |
| 79 | |
| 80 // TODO(xhwang): We should test the case where only certain decoder | 79 // TODO(xhwang): We should test the case where only certain decoder |
| 81 // supports encrypted streams. Currently this is hard to test because we use | 80 // supports encrypted streams. Currently this is hard to test because we use |
| 82 // parameterized tests which need to pass in all combinations. | 81 // parameterized tests which need to pass in all combinations. |
| 83 if (GetParam().is_encrypted && !GetParam().has_decryptor) { | 82 ScopedVector<VideoDecoder> decoders; |
| 84 decoder1_->EnableEncryptedConfigSupport(); | 83 for (int i = 0; i < 3; ++i) { |
| 85 decoder2_->EnableEncryptedConfigSupport(); | 84 FakeVideoDecoder* decoder = |
| 86 decoder3_->EnableEncryptedConfigSupport(); | 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); |
| 87 } | 96 } |
| 88 | 97 |
| 89 ScopedVector<VideoDecoder> decoders; | |
| 90 decoders.push_back(decoder1_); | |
| 91 decoders.push_back(decoder2_); | |
| 92 decoders.push_back(decoder3_); | |
| 93 | |
| 94 video_frame_stream_.reset(new VideoFrameStream( | 98 video_frame_stream_.reset(new VideoFrameStream( |
| 95 message_loop_.task_runner(), std::move(decoders), &media_log_)); | 99 message_loop_.task_runner(), std::move(decoders), &media_log_)); |
| 96 | 100 |
| 101 video_frame_stream_->set_decoder_change_observer_for_testing(base::Bind( |
| 102 &VideoFrameStreamTest::OnDecoderChanged, base::Unretained(this))); |
| 103 |
| 97 if (GetParam().is_encrypted && GetParam().has_decryptor) { | 104 if (GetParam().is_encrypted && GetParam().has_decryptor) { |
| 98 decryptor_.reset(new NiceMock<MockDecryptor>()); | 105 decryptor_.reset(new NiceMock<MockDecryptor>()); |
| 99 | 106 |
| 100 // Decryptor can only decrypt (not decrypt-and-decode) so that | 107 // Decryptor can only decrypt (not decrypt-and-decode) so that |
| 101 // DecryptingDemuxerStream will be used. | 108 // DecryptingDemuxerStream will be used. |
| 102 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _)) | 109 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _)) |
| 103 .WillRepeatedly(RunCallback<1>(false)); | 110 .WillRepeatedly(RunCallback<1>(false)); |
| 104 EXPECT_CALL(*decryptor_, Decrypt(_, _, _)) | 111 EXPECT_CALL(*decryptor_, Decrypt(_, _, _)) |
| 105 .WillRepeatedly(Invoke(this, &VideoFrameStreamTest::Decrypt)); | 112 .WillRepeatedly(Invoke(this, &VideoFrameStreamTest::Decrypt)); |
| 106 } | 113 } |
| 107 | 114 |
| 108 if (GetParam().is_encrypted) { | 115 if (GetParam().is_encrypted) { |
| 109 cdm_context_.reset(new StrictMock<MockCdmContext>()); | 116 cdm_context_.reset(new StrictMock<MockCdmContext>()); |
| 110 | 117 |
| 111 EXPECT_CALL(*cdm_context_, GetDecryptor()) | 118 EXPECT_CALL(*cdm_context_, GetDecryptor()) |
| 112 .WillRepeatedly(Return(decryptor_.get())); | 119 .WillRepeatedly(Return(decryptor_.get())); |
| 113 } | 120 } |
| 114 } | 121 } |
| 115 | 122 |
| 116 ~VideoFrameStreamTest() { | 123 ~VideoFrameStreamTest() { |
| 117 // Check that the pipeline statistics callback was fired correctly. | 124 // Check that the pipeline statistics callback was fired correctly. |
| 118 EXPECT_EQ(num_decoded_bytes_unreported_, 0); | 125 EXPECT_EQ(num_decoded_bytes_unreported_, 0); |
| 119 | 126 |
| 120 is_initialized_ = false; | 127 is_initialized_ = false; |
| 121 decoder1_ = NULL; | 128 decoders_.clear(); |
| 122 decoder2_ = NULL; | |
| 123 decoder3_ = NULL; | |
| 124 video_frame_stream_.reset(); | 129 video_frame_stream_.reset(); |
| 125 base::RunLoop().RunUntilIdle(); | 130 base::RunLoop().RunUntilIdle(); |
| 126 | 131 |
| 127 DCHECK(!pending_initialize_); | 132 DCHECK(!pending_initialize_); |
| 128 DCHECK(!pending_read_); | 133 DCHECK(!pending_read_); |
| 129 DCHECK(!pending_reset_); | 134 DCHECK(!pending_reset_); |
| 130 DCHECK(!pending_stop_); | 135 DCHECK(!pending_stop_); |
| 131 } | 136 } |
| 132 | 137 |
| 133 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); | 138 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); |
| 134 | 139 |
| 135 void OnStatistics(const PipelineStatistics& statistics) { | 140 void OnStatistics(const PipelineStatistics& statistics) { |
| 136 num_decoded_bytes_unreported_ -= statistics.video_bytes_decoded; | 141 num_decoded_bytes_unreported_ -= statistics.video_bytes_decoded; |
| 137 } | 142 } |
| 138 | 143 |
| 139 void OnBytesDecoded(int count) { | 144 void OnBytesDecoded(int count) { |
| 140 num_decoded_bytes_unreported_ += count; | 145 num_decoded_bytes_unreported_ += count; |
| 141 } | 146 } |
| 142 | 147 |
| 148 void SimulateDecoderInitFailure(const std::vector<int>& decoder_indices) { |
| 149 for (const auto& i : decoder_indices) |
| 150 decoders_[i]->SimulateFailureToInit(); |
| 151 } |
| 152 |
| 143 void OnInitialized(bool success) { | 153 void OnInitialized(bool success) { |
| 144 DCHECK(!pending_read_); | 154 DCHECK(!pending_read_); |
| 145 DCHECK(!pending_reset_); | 155 DCHECK(!pending_reset_); |
| 146 DCHECK(pending_initialize_); | 156 DCHECK(pending_initialize_); |
| 147 pending_initialize_ = false; | 157 pending_initialize_ = false; |
| 148 | 158 |
| 149 is_initialized_ = success; | 159 is_initialized_ = success; |
| 150 if (!success) { | 160 if (!success) |
| 151 decoder1_ = NULL; | 161 decoders_.clear(); |
| 152 decoder2_ = NULL; | |
| 153 decoder3_ = NULL; | |
| 154 } | |
| 155 } | 162 } |
| 156 | 163 |
| 157 void InitializeVideoFrameStream() { | 164 void Initialize() { |
| 158 pending_initialize_ = true; | 165 pending_initialize_ = true; |
| 159 video_frame_stream_->Initialize( | 166 video_frame_stream_->Initialize( |
| 160 demuxer_stream_.get(), base::Bind(&VideoFrameStreamTest::OnInitialized, | 167 demuxer_stream_.get(), base::Bind(&VideoFrameStreamTest::OnInitialized, |
| 161 base::Unretained(this)), | 168 base::Unretained(this)), |
| 162 cdm_context_.get(), | 169 cdm_context_.get(), |
| 163 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)), | 170 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)), |
| 164 base::Bind(&VideoFrameStreamTest::OnWaitingForDecryptionKey, | 171 base::Bind(&VideoFrameStreamTest::OnWaitingForDecryptionKey, |
| 165 base::Unretained(this))); | 172 base::Unretained(this))); |
| 166 base::RunLoop().RunUntilIdle(); | 173 base::RunLoop().RunUntilIdle(); |
| 167 } | 174 } |
| 168 | 175 |
| 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 |
| 169 // Fake Decrypt() function used by DecryptingDemuxerStream. It does nothing | 188 // Fake Decrypt() function used by DecryptingDemuxerStream. It does nothing |
| 170 // but removes the DecryptConfig to make the buffer unencrypted. | 189 // but removes the DecryptConfig to make the buffer unencrypted. |
| 171 void Decrypt(Decryptor::StreamType stream_type, | 190 void Decrypt(Decryptor::StreamType stream_type, |
| 172 const scoped_refptr<DecoderBuffer>& encrypted, | 191 const scoped_refptr<DecoderBuffer>& encrypted, |
| 173 const Decryptor::DecryptCB& decrypt_cb) { | 192 const Decryptor::DecryptCB& decrypt_cb) { |
| 174 DCHECK(encrypted->decrypt_config()); | 193 DCHECK(encrypted->decrypt_config()); |
| 175 if (has_no_key_) { | 194 if (has_no_key_) { |
| 176 decrypt_cb.Run(Decryptor::kNoKey, NULL); | 195 decrypt_cb.Run(Decryptor::kNoKey, NULL); |
| 177 return; | 196 return; |
| 178 } | 197 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 void ReadAllFrames() { | 252 void ReadAllFrames() { |
| 234 // No frames should have been dropped. | 253 // No frames should have been dropped. |
| 235 ReadAllFrames(kNumConfigs * kNumBuffersInOneConfig); | 254 ReadAllFrames(kNumConfigs * kNumBuffersInOneConfig); |
| 236 } | 255 } |
| 237 | 256 |
| 238 enum PendingState { | 257 enum PendingState { |
| 239 NOT_PENDING, | 258 NOT_PENDING, |
| 240 DEMUXER_READ_NORMAL, | 259 DEMUXER_READ_NORMAL, |
| 241 DEMUXER_READ_CONFIG_CHANGE, | 260 DEMUXER_READ_CONFIG_CHANGE, |
| 242 DECRYPTOR_NO_KEY, | 261 DECRYPTOR_NO_KEY, |
| 243 DECODER_INIT, | |
| 244 DECODER_REINIT, | 262 DECODER_REINIT, |
| 245 DECODER_DECODE, | 263 DECODER_DECODE, |
| 246 DECODER_RESET | 264 DECODER_RESET |
| 247 }; | 265 }; |
| 248 | 266 |
| 249 void EnterPendingState(PendingState state) { | 267 void EnterPendingState(PendingState state) { |
| 250 EnterPendingState(state, decoder1_); | |
| 251 } | |
| 252 | |
| 253 void EnterPendingState(PendingState state, FakeVideoDecoder* decoder) { | |
| 254 DCHECK_NE(state, NOT_PENDING); | 268 DCHECK_NE(state, NOT_PENDING); |
| 255 switch (state) { | 269 switch (state) { |
| 256 case DEMUXER_READ_NORMAL: | 270 case DEMUXER_READ_NORMAL: |
| 257 demuxer_stream_->HoldNextRead(); | 271 demuxer_stream_->HoldNextRead(); |
| 258 ReadUntilPending(); | 272 ReadUntilPending(); |
| 259 break; | 273 break; |
| 260 | 274 |
| 261 case DEMUXER_READ_CONFIG_CHANGE: | 275 case DEMUXER_READ_CONFIG_CHANGE: |
| 262 demuxer_stream_->HoldNextConfigChangeRead(); | 276 demuxer_stream_->HoldNextConfigChangeRead(); |
| 263 ReadUntilPending(); | 277 ReadUntilPending(); |
| 264 break; | 278 break; |
| 265 | 279 |
| 266 case DECRYPTOR_NO_KEY: | 280 case DECRYPTOR_NO_KEY: |
| 267 if (GetParam().is_encrypted && GetParam().has_decryptor) { | 281 if (GetParam().is_encrypted && GetParam().has_decryptor) { |
| 268 EXPECT_CALL(*this, OnWaitingForDecryptionKey()); | 282 EXPECT_CALL(*this, OnWaitingForDecryptionKey()); |
| 269 has_no_key_ = true; | 283 has_no_key_ = true; |
| 270 } | 284 } |
| 271 ReadOneFrame(); | 285 ReadOneFrame(); |
| 272 break; | 286 break; |
| 273 | 287 |
| 274 case DECODER_INIT: | |
| 275 decoder->HoldNextInit(); | |
| 276 InitializeVideoFrameStream(); | |
| 277 break; | |
| 278 | |
| 279 case DECODER_REINIT: | 288 case DECODER_REINIT: |
| 280 decoder->HoldNextInit(); | 289 decoder_->HoldNextInit(); |
| 281 ReadUntilPending(); | 290 ReadUntilPending(); |
| 282 break; | 291 break; |
| 283 | 292 |
| 284 case DECODER_DECODE: | 293 case DECODER_DECODE: |
| 285 decoder->HoldDecode(); | 294 decoder_->HoldDecode(); |
| 286 ReadUntilPending(); | 295 ReadUntilPending(); |
| 287 break; | 296 break; |
| 288 | 297 |
| 289 case DECODER_RESET: | 298 case DECODER_RESET: |
| 290 decoder->HoldNextReset(); | 299 decoder_->HoldNextReset(); |
| 291 pending_reset_ = true; | 300 pending_reset_ = true; |
| 292 video_frame_stream_->Reset(base::Bind(&VideoFrameStreamTest::OnReset, | 301 video_frame_stream_->Reset(base::Bind(&VideoFrameStreamTest::OnReset, |
| 293 base::Unretained(this))); | 302 base::Unretained(this))); |
| 294 base::RunLoop().RunUntilIdle(); | 303 base::RunLoop().RunUntilIdle(); |
| 295 break; | 304 break; |
| 296 | 305 |
| 297 case NOT_PENDING: | 306 case NOT_PENDING: |
| 298 NOTREACHED(); | 307 NOTREACHED(); |
| 299 break; | 308 break; |
| 300 } | 309 } |
| 301 } | 310 } |
| 302 | 311 |
| 303 void SatisfyPendingCallback(PendingState state) { | 312 void SatisfyPendingCallback(PendingState state) { |
| 304 SatisfyPendingCallback(state, decoder1_); | |
| 305 } | |
| 306 | |
| 307 void SatisfyPendingCallback(PendingState state, FakeVideoDecoder* decoder) { | |
| 308 DCHECK_NE(state, NOT_PENDING); | 313 DCHECK_NE(state, NOT_PENDING); |
| 309 switch (state) { | 314 switch (state) { |
| 310 case DEMUXER_READ_NORMAL: | 315 case DEMUXER_READ_NORMAL: |
| 311 case DEMUXER_READ_CONFIG_CHANGE: | 316 case DEMUXER_READ_CONFIG_CHANGE: |
| 312 demuxer_stream_->SatisfyRead(); | 317 demuxer_stream_->SatisfyRead(); |
| 313 break; | 318 break; |
| 314 | 319 |
| 315 // This is only interesting to test during VideoFrameStream destruction. | 320 // This is only interesting to test during VideoFrameStream destruction. |
| 316 // There's no need to satisfy a callback. | 321 // There's no need to satisfy a callback. |
| 317 case DECRYPTOR_NO_KEY: | 322 case DECRYPTOR_NO_KEY: |
| 318 NOTREACHED(); | 323 NOTREACHED(); |
| 319 break; | 324 break; |
| 320 | 325 |
| 321 case DECODER_INIT: | |
| 322 decoder->SatisfyInit(); | |
| 323 break; | |
| 324 | |
| 325 case DECODER_REINIT: | 326 case DECODER_REINIT: |
| 326 decoder->SatisfyInit(); | 327 decoder_->SatisfyInit(); |
| 327 break; | 328 break; |
| 328 | 329 |
| 329 case DECODER_DECODE: | 330 case DECODER_DECODE: |
| 330 decoder->SatisfyDecode(); | 331 decoder_->SatisfyDecode(); |
| 331 break; | 332 break; |
| 332 | 333 |
| 333 case DECODER_RESET: | 334 case DECODER_RESET: |
| 334 decoder->SatisfyReset(); | 335 decoder_->SatisfyReset(); |
| 335 break; | 336 break; |
| 336 | 337 |
| 337 case NOT_PENDING: | 338 case NOT_PENDING: |
| 338 NOTREACHED(); | 339 NOTREACHED(); |
| 339 break; | 340 break; |
| 340 } | 341 } |
| 341 | 342 |
| 342 base::RunLoop().RunUntilIdle(); | 343 base::RunLoop().RunUntilIdle(); |
| 343 } | 344 } |
| 344 | 345 |
| 345 void Initialize() { | |
| 346 EnterPendingState(DECODER_INIT); | |
| 347 SatisfyPendingCallback(DECODER_INIT); | |
| 348 } | |
| 349 | |
| 350 void Read() { | 346 void Read() { |
| 351 EnterPendingState(DECODER_DECODE); | 347 EnterPendingState(DECODER_DECODE); |
| 352 SatisfyPendingCallback(DECODER_DECODE); | 348 SatisfyPendingCallback(DECODER_DECODE); |
| 353 } | 349 } |
| 354 | 350 |
| 355 void Reset() { | 351 void Reset() { |
| 356 EnterPendingState(DECODER_RESET); | 352 EnterPendingState(DECODER_RESET); |
| 357 SatisfyPendingCallback(DECODER_RESET); | 353 SatisfyPendingCallback(DECODER_RESET); |
| 358 } | 354 } |
| 359 | 355 |
| 360 void ReadUntilDecoderReinitialized(FakeVideoDecoder* decoder) { | 356 void ReadUntilDecoderReinitialized() { |
| 361 EnterPendingState(DECODER_REINIT, decoder); | 357 EnterPendingState(DECODER_REINIT); |
| 362 SatisfyPendingCallback(DECODER_REINIT, decoder); | 358 SatisfyPendingCallback(DECODER_REINIT); |
| 363 } | 359 } |
| 364 | 360 |
| 365 base::MessageLoop message_loop_; | 361 base::MessageLoop message_loop_; |
| 366 | 362 |
| 367 MediaLog media_log_; | 363 MediaLog media_log_; |
| 368 std::unique_ptr<VideoFrameStream> video_frame_stream_; | 364 std::unique_ptr<VideoFrameStream> video_frame_stream_; |
| 369 std::unique_ptr<FakeDemuxerStream> demuxer_stream_; | 365 std::unique_ptr<FakeDemuxerStream> demuxer_stream_; |
| 370 std::unique_ptr<StrictMock<MockCdmContext>> cdm_context_; | 366 std::unique_ptr<StrictMock<MockCdmContext>> cdm_context_; |
| 371 | 367 |
| 372 // Use NiceMock since we don't care about most of calls on the decryptor, | 368 // Use NiceMock since we don't care about most of calls on the decryptor, |
| 373 // e.g. RegisterNewKeyCB(). | 369 // e.g. RegisterNewKeyCB(). |
| 374 std::unique_ptr<NiceMock<MockDecryptor>> decryptor_; | 370 std::unique_ptr<NiceMock<MockDecryptor>> decryptor_; |
| 375 | 371 |
| 372 // Raw pointers to the list of decoders to be select from by DecoderSelector. |
| 376 // Three decoders are needed to test that decoder fallback can occur more than | 373 // Three decoders are needed to test that decoder fallback can occur more than |
| 377 // once on a config change. They are owned by |video_frame_stream_|. | 374 // once on a config change. They are owned by |video_frame_stream_|. |
| 378 FakeVideoDecoder* decoder1_; | 375 std::vector<FakeVideoDecoder*> decoders_; |
| 379 FakeVideoDecoder* decoder2_; | 376 |
| 380 FakeVideoDecoder* decoder3_; | 377 // The current decoder used by |video_frame_stream_|. |
| 378 FakeVideoDecoder* decoder_; |
| 381 | 379 |
| 382 bool is_initialized_; | 380 bool is_initialized_; |
| 383 int num_decoded_frames_; | 381 int num_decoded_frames_; |
| 384 bool pending_initialize_; | 382 bool pending_initialize_; |
| 385 bool pending_read_; | 383 bool pending_read_; |
| 386 bool pending_reset_; | 384 bool pending_reset_; |
| 387 bool pending_stop_; | 385 bool pending_stop_; |
| 388 int num_decoded_bytes_unreported_; | 386 int num_decoded_bytes_unreported_; |
| 389 scoped_refptr<VideoFrame> frame_read_; | 387 scoped_refptr<VideoFrame> frame_read_; |
| 390 VideoFrameStream::Status last_read_status_; | 388 VideoFrameStream::Status last_read_status_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 418 VideoFrameStreamTest, | 416 VideoFrameStreamTest, |
| 419 ::testing::Values(VideoFrameStreamTestParams(false, false, 0, 3), | 417 ::testing::Values(VideoFrameStreamTestParams(false, false, 0, 3), |
| 420 VideoFrameStreamTestParams(false, false, 2, 3))); | 418 VideoFrameStreamTestParams(false, false, 2, 3))); |
| 421 | 419 |
| 422 TEST_P(VideoFrameStreamTest, Initialization) { | 420 TEST_P(VideoFrameStreamTest, Initialization) { |
| 423 Initialize(); | 421 Initialize(); |
| 424 EXPECT_TRUE(is_initialized_); | 422 EXPECT_TRUE(is_initialized_); |
| 425 } | 423 } |
| 426 | 424 |
| 427 TEST_P(VideoFrameStreamTest, AllDecoderInitializationFails) { | 425 TEST_P(VideoFrameStreamTest, AllDecoderInitializationFails) { |
| 428 decoder1_->SimulateFailureToInit(); | 426 SimulateDecoderInitFailure({0, 1, 2}); |
| 429 decoder2_->SimulateFailureToInit(); | |
| 430 decoder3_->SimulateFailureToInit(); | |
| 431 Initialize(); | 427 Initialize(); |
| 432 EXPECT_FALSE(is_initialized_); | 428 EXPECT_FALSE(is_initialized_); |
| 433 } | 429 } |
| 434 | 430 |
| 435 TEST_P(VideoFrameStreamTest, PartialDecoderInitializationFails) { | 431 TEST_P(VideoFrameStreamTest, PartialDecoderInitializationFails) { |
| 436 decoder1_->SimulateFailureToInit(); | 432 SimulateDecoderInitFailure({0, 1}); |
| 437 decoder2_->SimulateFailureToInit(); | |
| 438 Initialize(); | 433 Initialize(); |
| 439 EXPECT_TRUE(is_initialized_); | 434 EXPECT_TRUE(is_initialized_); |
| 440 } | 435 } |
| 441 | 436 |
| 442 TEST_P(VideoFrameStreamTest, ReadOneFrame) { | 437 TEST_P(VideoFrameStreamTest, ReadOneFrame) { |
| 443 Initialize(); | 438 Initialize(); |
| 444 Read(); | 439 Read(); |
| 445 } | 440 } |
| 446 | 441 |
| 447 TEST_P(VideoFrameStreamTest, ReadAllFrames) { | 442 TEST_P(VideoFrameStreamTest, ReadAllFrames) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 EXPECT_FALSE(pending_read_); | 481 EXPECT_FALSE(pending_read_); |
| 487 } | 482 } |
| 488 | 483 |
| 489 TEST_P(VideoFrameStreamTest, Read_BlockedDemuxerAndDecoder) { | 484 TEST_P(VideoFrameStreamTest, Read_BlockedDemuxerAndDecoder) { |
| 490 // Test applies only when the decoder allows multiple parallel requests. | 485 // Test applies only when the decoder allows multiple parallel requests. |
| 491 if (GetParam().parallel_decoding == 1) | 486 if (GetParam().parallel_decoding == 1) |
| 492 return; | 487 return; |
| 493 | 488 |
| 494 Initialize(); | 489 Initialize(); |
| 495 demuxer_stream_->HoldNextRead(); | 490 demuxer_stream_->HoldNextRead(); |
| 496 decoder1_->HoldDecode(); | 491 decoder_->HoldDecode(); |
| 497 ReadOneFrame(); | 492 ReadOneFrame(); |
| 498 EXPECT_TRUE(pending_read_); | 493 EXPECT_TRUE(pending_read_); |
| 499 | 494 |
| 500 int demuxed_buffers = 0; | 495 int demuxed_buffers = 0; |
| 501 | 496 |
| 502 // Pass frames from the demuxer to the VideoFrameStream until the first read | 497 // Pass frames from the demuxer to the VideoFrameStream until the first read |
| 503 // request is satisfied, while always keeping one decode request pending. | 498 // request is satisfied, while always keeping one decode request pending. |
| 504 while (pending_read_) { | 499 while (pending_read_) { |
| 505 ++demuxed_buffers; | 500 ++demuxed_buffers; |
| 506 demuxer_stream_->SatisfyReadAndHoldNext(); | 501 demuxer_stream_->SatisfyReadAndHoldNext(); |
| 507 base::RunLoop().RunUntilIdle(); | 502 base::RunLoop().RunUntilIdle(); |
| 508 | 503 |
| 509 // Always keep one decode request pending. | 504 // Always keep one decode request pending. |
| 510 if (demuxed_buffers > 1) { | 505 if (demuxed_buffers > 1) { |
| 511 decoder1_->SatisfySingleDecode(); | 506 decoder_->SatisfySingleDecode(); |
| 512 base::RunLoop().RunUntilIdle(); | 507 base::RunLoop().RunUntilIdle(); |
| 513 } | 508 } |
| 514 } | 509 } |
| 515 | 510 |
| 516 ReadUntilPending(); | 511 ReadUntilPending(); |
| 517 EXPECT_TRUE(pending_read_); | 512 EXPECT_TRUE(pending_read_); |
| 518 | 513 |
| 519 // Unblocking one decode request should unblock read even when demuxer is | 514 // Unblocking one decode request should unblock read even when demuxer is |
| 520 // still blocked. | 515 // still blocked. |
| 521 decoder1_->SatisfySingleDecode(); | 516 decoder_->SatisfySingleDecode(); |
| 522 base::RunLoop().RunUntilIdle(); | 517 base::RunLoop().RunUntilIdle(); |
| 523 EXPECT_FALSE(pending_read_); | 518 EXPECT_FALSE(pending_read_); |
| 524 | 519 |
| 525 // Stream should still be blocked on the demuxer after unblocking the decoder. | 520 // Stream should still be blocked on the demuxer after unblocking the decoder. |
| 526 decoder1_->SatisfyDecode(); | 521 decoder_->SatisfyDecode(); |
| 527 ReadUntilPending(); | 522 ReadUntilPending(); |
| 528 EXPECT_TRUE(pending_read_); | 523 EXPECT_TRUE(pending_read_); |
| 529 | 524 |
| 530 // Verify that the stream has returned all frames that have been demuxed, | 525 // Verify that the stream has returned all frames that have been demuxed, |
| 531 // accounting for the decoder delay. | 526 // accounting for the decoder delay. |
| 532 EXPECT_EQ(demuxed_buffers - GetParam().decoding_delay, num_decoded_frames_); | 527 EXPECT_EQ(demuxed_buffers - GetParam().decoding_delay, num_decoded_frames_); |
| 533 | 528 |
| 534 // Unblocking the demuxer will unblock the stream. | 529 // Unblocking the demuxer will unblock the stream. |
| 535 demuxer_stream_->SatisfyRead(); | 530 demuxer_stream_->SatisfyRead(); |
| 536 base::RunLoop().RunUntilIdle(); | 531 base::RunLoop().RunUntilIdle(); |
| 537 EXPECT_FALSE(pending_read_); | 532 EXPECT_FALSE(pending_read_); |
| 538 } | 533 } |
| 539 | 534 |
| 540 TEST_P(VideoFrameStreamTest, Read_DuringEndOfStreamDecode) { | 535 TEST_P(VideoFrameStreamTest, Read_DuringEndOfStreamDecode) { |
| 541 // Test applies only when the decoder allows multiple parallel requests, and | 536 // Test applies only when the decoder allows multiple parallel requests, and |
| 542 // they are not satisfied in a single batch. | 537 // they are not satisfied in a single batch. |
| 543 if (GetParam().parallel_decoding == 1 || GetParam().decoding_delay != 0) | 538 if (GetParam().parallel_decoding == 1 || GetParam().decoding_delay != 0) |
| 544 return; | 539 return; |
| 545 | 540 |
| 546 Initialize(); | 541 Initialize(); |
| 547 decoder1_->HoldDecode(); | 542 decoder_->HoldDecode(); |
| 548 | 543 |
| 549 // Read all of the frames up to end of stream. Since parallel decoding is | 544 // Read all of the frames up to end of stream. Since parallel decoding is |
| 550 // enabled, the end of stream buffer will be sent to the decoder immediately, | 545 // enabled, the end of stream buffer will be sent to the decoder immediately, |
| 551 // but we don't satisfy it yet. | 546 // but we don't satisfy it yet. |
| 552 for (int configuration = 0; configuration < kNumConfigs; configuration++) { | 547 for (int configuration = 0; configuration < kNumConfigs; configuration++) { |
| 553 for (int frame = 0; frame < kNumBuffersInOneConfig; frame++) { | 548 for (int frame = 0; frame < kNumBuffersInOneConfig; frame++) { |
| 554 ReadOneFrame(); | 549 ReadOneFrame(); |
| 555 while (pending_read_) { | 550 while (pending_read_) { |
| 556 decoder1_->SatisfySingleDecode(); | 551 decoder_->SatisfySingleDecode(); |
| 557 base::RunLoop().RunUntilIdle(); | 552 base::RunLoop().RunUntilIdle(); |
| 558 } | 553 } |
| 559 } | 554 } |
| 560 } | 555 } |
| 561 | 556 |
| 562 // Read() again. The callback must be delayed until the decode completes. | 557 // Read() again. The callback must be delayed until the decode completes. |
| 563 ReadOneFrame(); | 558 ReadOneFrame(); |
| 564 ASSERT_TRUE(pending_read_); | 559 ASSERT_TRUE(pending_read_); |
| 565 | 560 |
| 566 // Satisfy decoding of the end of stream buffer. The read should complete. | 561 // Satisfy decoding of the end of stream buffer. The read should complete. |
| 567 decoder1_->SatisfySingleDecode(); | 562 decoder_->SatisfySingleDecode(); |
| 568 base::RunLoop().RunUntilIdle(); | 563 base::RunLoop().RunUntilIdle(); |
| 569 ASSERT_FALSE(pending_read_); | 564 ASSERT_FALSE(pending_read_); |
| 570 EXPECT_EQ(last_read_status_, VideoFrameStream::OK); | 565 EXPECT_EQ(last_read_status_, VideoFrameStream::OK); |
| 571 | 566 |
| 572 // The read output should indicate end of stream. | 567 // The read output should indicate end of stream. |
| 573 ASSERT_TRUE(frame_read_.get()); | 568 ASSERT_TRUE(frame_read_.get()); |
| 574 EXPECT_TRUE( | 569 EXPECT_TRUE( |
| 575 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); | 570 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); |
| 576 } | 571 } |
| 577 | 572 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 Reset(); | 653 Reset(); |
| 659 } | 654 } |
| 660 | 655 |
| 661 // In the following Destroy_* tests, |video_frame_stream_| is destroyed in | 656 // In the following Destroy_* tests, |video_frame_stream_| is destroyed in |
| 662 // VideoFrameStreamTest dtor. | 657 // VideoFrameStreamTest dtor. |
| 663 | 658 |
| 664 TEST_P(VideoFrameStreamTest, Destroy_BeforeInitialization) { | 659 TEST_P(VideoFrameStreamTest, Destroy_BeforeInitialization) { |
| 665 } | 660 } |
| 666 | 661 |
| 667 TEST_P(VideoFrameStreamTest, Destroy_DuringInitialization) { | 662 TEST_P(VideoFrameStreamTest, Destroy_DuringInitialization) { |
| 668 EnterPendingState(DECODER_INIT); | 663 decoders_[0]->HoldNextInit(); |
| 664 Initialize(); |
| 669 } | 665 } |
| 670 | 666 |
| 671 TEST_P(VideoFrameStreamTest, Destroy_AfterInitialization) { | 667 TEST_P(VideoFrameStreamTest, Destroy_AfterInitialization) { |
| 672 Initialize(); | 668 Initialize(); |
| 673 } | 669 } |
| 674 | 670 |
| 675 TEST_P(VideoFrameStreamTest, Destroy_DuringReinitialization) { | 671 TEST_P(VideoFrameStreamTest, Destroy_DuringReinitialization) { |
| 676 Initialize(); | 672 Initialize(); |
| 677 EnterPendingState(DECODER_REINIT); | 673 EnterPendingState(DECODER_REINIT); |
| 678 } | 674 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 EnterPendingState(DECODER_RESET); | 737 EnterPendingState(DECODER_RESET); |
| 742 SatisfyPendingCallback(DECODER_DECODE); | 738 SatisfyPendingCallback(DECODER_DECODE); |
| 743 } | 739 } |
| 744 | 740 |
| 745 TEST_P(VideoFrameStreamTest, Destroy_AfterRead_AfterReset) { | 741 TEST_P(VideoFrameStreamTest, Destroy_AfterRead_AfterReset) { |
| 746 Initialize(); | 742 Initialize(); |
| 747 Read(); | 743 Read(); |
| 748 Reset(); | 744 Reset(); |
| 749 } | 745 } |
| 750 | 746 |
| 747 // The following tests cover the fallback logic. |
| 748 |
| 751 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitialDecodeError) { | 749 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitialDecodeError) { |
| 752 Initialize(); | 750 Initialize(); |
| 753 decoder1_->SimulateError(); | 751 decoder_->SimulateError(); |
| 754 ReadOneFrame(); | 752 ReadOneFrame(); |
| 755 | 753 |
| 756 // |video_frame_stream_| should have fallen back to |decoder2_|. | 754 // |video_frame_stream_| should have fallen back to a new decoder. |
| 755 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
| 757 ASSERT_FALSE(pending_read_); | 756 ASSERT_FALSE(pending_read_); |
| 758 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); | 757 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); |
| 759 | 758 |
| 760 // Can't check |decoder1_| right now, it might have been destroyed already. | 759 // Check that we fallbacked to Decoder2. |
| 761 ASSERT_GT(decoder2_->total_bytes_decoded(), 0); | 760 ASSERT_GT(decoder_->total_bytes_decoded(), 0); |
| 762 | 761 |
| 763 // Verify no frame was dropped. | 762 // Verify no frame was dropped. |
| 764 ReadAllFrames(); | 763 ReadAllFrames(); |
| 765 } | 764 } |
| 766 | 765 |
| 767 TEST_P(VideoFrameStreamTest, FallbackDecoder_EndOfStreamReachedBeforeFallback) { | 766 TEST_P(VideoFrameStreamTest, FallbackDecoder_EndOfStreamReachedBeforeFallback) { |
| 768 // Only consider cases where there is a decoder delay. For test simplicity, | 767 // Only consider cases where there is a decoder delay. For test simplicity, |
| 769 // omit the parallel case. | 768 // omit the parallel case. |
| 770 if (GetParam().decoding_delay == 0 || GetParam().parallel_decoding > 1) | 769 if (GetParam().decoding_delay == 0 || GetParam().parallel_decoding > 1) |
| 771 return; | 770 return; |
| 772 | 771 |
| 773 Initialize(); | 772 Initialize(); |
| 774 decoder1_->HoldDecode(); | 773 decoder_->HoldDecode(); |
| 775 ReadOneFrame(); | 774 ReadOneFrame(); |
| 776 | 775 |
| 777 // One buffer should have already pulled from the demuxer stream. Set the next | 776 // One buffer should have already pulled from the demuxer stream. Set the next |
| 778 // one to be an EOS. | 777 // one to be an EOS. |
| 779 demuxer_stream_->SeekToEndOfStream(); | 778 demuxer_stream_->SeekToEndOfStream(); |
| 780 | 779 |
| 781 decoder1_->SatisfySingleDecode(); | 780 decoder_->SatisfySingleDecode(); |
| 782 base::RunLoop().RunUntilIdle(); | 781 base::RunLoop().RunUntilIdle(); |
| 783 | 782 |
| 784 // |video_frame_stream_| should not have emited a frame. | 783 // |video_frame_stream_| should not have emited a frame. |
| 785 EXPECT_TRUE(pending_read_); | 784 EXPECT_TRUE(pending_read_); |
| 786 | 785 |
| 787 // Pending buffers should contain a regular buffer and an EOS buffer. | 786 // Pending buffers should contain a regular buffer and an EOS buffer. |
| 788 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 2); | 787 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 2); |
| 789 | 788 |
| 790 decoder1_->SimulateError(); | 789 decoder_->SimulateError(); |
| 791 base::RunLoop().RunUntilIdle(); | 790 base::RunLoop().RunUntilIdle(); |
| 792 | 791 |
| 793 // A frame should have been emited | 792 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
| 793 |
| 794 // A frame should have been emitted. |
| 794 EXPECT_FALSE(pending_read_); | 795 EXPECT_FALSE(pending_read_); |
| 795 EXPECT_EQ(last_read_status_, VideoFrameStream::OK); | 796 EXPECT_EQ(last_read_status_, VideoFrameStream::OK); |
| 796 EXPECT_FALSE( | 797 EXPECT_FALSE( |
| 797 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); | 798 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); |
| 798 EXPECT_GT(decoder2_->total_bytes_decoded(), 0); | 799 EXPECT_GT(decoder_->total_bytes_decoded(), 0); |
| 799 | 800 |
| 800 ReadOneFrame(); | 801 ReadOneFrame(); |
| 801 | 802 |
| 802 EXPECT_FALSE(pending_read_); | 803 EXPECT_FALSE(pending_read_); |
| 803 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); | 804 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); |
| 804 EXPECT_TRUE( | 805 EXPECT_TRUE( |
| 805 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); | 806 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); |
| 806 } | 807 } |
| 807 | 808 |
| 808 TEST_P(VideoFrameStreamTest, FallbackDecoder_DoesReinitializeStompPendingRead) { | 809 TEST_P(VideoFrameStreamTest, FallbackDecoder_DoesReinitializeStompPendingRead) { |
| 809 // Test only the case where there is no decoding delay and parallel decoding. | 810 // Test only the case where there is no decoding delay and parallel decoding. |
| 810 if (GetParam().decoding_delay != 0 || GetParam().parallel_decoding <= 1) | 811 if (GetParam().decoding_delay != 0 || GetParam().parallel_decoding <= 1) |
| 811 return; | 812 return; |
| 812 | 813 |
| 813 Initialize(); | 814 Initialize(); |
| 814 decoder1_->HoldDecode(); | 815 decoder_->HoldDecode(); |
| 815 | 816 |
| 816 // Queue one read, defer the second. | 817 // Queue one read, defer the second. |
| 817 frame_read_ = nullptr; | 818 frame_read_ = nullptr; |
| 818 pending_read_ = true; | 819 pending_read_ = true; |
| 819 video_frame_stream_->Read( | 820 video_frame_stream_->Read( |
| 820 base::Bind(&VideoFrameStreamTest::FrameReady, base::Unretained(this))); | 821 base::Bind(&VideoFrameStreamTest::FrameReady, base::Unretained(this))); |
| 821 demuxer_stream_->HoldNextRead(); | 822 demuxer_stream_->HoldNextRead(); |
| 822 | 823 |
| 823 // Force an error to occur on the first decode, but ensure it isn't propagated | 824 // Force an error to occur on the first decode, but ensure it isn't propagated |
| 824 // until after the next read has been started. | 825 // until after the next read has been started. |
| 825 decoder1_->SimulateError(); | 826 decoder_->SimulateError(); |
| 826 decoder2_->HoldDecode(); | 827 decoders_[1]->HoldDecode(); |
| 827 | 828 |
| 828 // Complete the fallback to the second decoder with the read still pending. | 829 // Complete the fallback to the second decoder with the read still pending. |
| 829 base::RunLoop().RunUntilIdle(); | 830 base::RunLoop().RunUntilIdle(); |
| 830 | 831 |
| 831 // Can't check |decoder1_| right now, it might have been destroyed already. | 832 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
| 832 // Verify that there was nothing decoded until we kicked the decoder. | 833 |
| 833 EXPECT_EQ(decoder2_->total_bytes_decoded(), 0); | 834 // Can't check the original decoder right now, it might have been destroyed |
| 834 decoder2_->SatisfyDecode(); | 835 // already. Verify that there was nothing decoded until we kicked the decoder. |
| 835 const int first_decoded_bytes = decoder2_->total_bytes_decoded(); | 836 EXPECT_EQ(decoder_->total_bytes_decoded(), 0); |
| 837 decoder_->SatisfyDecode(); |
| 838 const int first_decoded_bytes = decoder_->total_bytes_decoded(); |
| 836 ASSERT_GT(first_decoded_bytes, 0); | 839 ASSERT_GT(first_decoded_bytes, 0); |
| 837 | 840 |
| 838 // Satisfy the previously pending read and ensure it is decoded. | 841 // Satisfy the previously pending read and ensure it is decoded. |
| 839 demuxer_stream_->SatisfyRead(); | 842 demuxer_stream_->SatisfyRead(); |
| 840 base::RunLoop().RunUntilIdle(); | 843 base::RunLoop().RunUntilIdle(); |
| 841 ASSERT_GT(decoder2_->total_bytes_decoded(), first_decoded_bytes); | 844 ASSERT_GT(decoder_->total_bytes_decoded(), first_decoded_bytes); |
| 842 } | 845 } |
| 843 | 846 |
| 844 TEST_P(VideoFrameStreamTest, | 847 TEST_P(VideoFrameStreamTest, |
| 845 FallbackDecoder_SelectedOnInitialDecodeError_Twice) { | 848 FallbackDecoder_SelectedOnInitialDecodeError_Twice) { |
| 846 Initialize(); | 849 Initialize(); |
| 847 decoder1_->SimulateError(); | 850 decoder_->SimulateError(); |
| 848 decoder2_->HoldNextInit(); | 851 |
| 852 decoders_[1]->HoldNextInit(); |
| 849 ReadOneFrame(); | 853 ReadOneFrame(); |
| 850 | 854 |
| 851 decoder2_->SatisfyInit(); | 855 decoders_[1]->SatisfyInit(); |
| 852 decoder2_->SimulateError(); | 856 decoders_[1]->SimulateError(); |
| 853 base::RunLoop().RunUntilIdle(); | 857 base::RunLoop().RunUntilIdle(); |
| 854 | 858 |
| 855 // |video_frame_stream_| should have fallen back to |decoder3_|. | 859 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName()); |
| 860 |
| 861 // |video_frame_stream_| should have fallen back to |decoders_[2]|. |
| 856 ASSERT_FALSE(pending_read_); | 862 ASSERT_FALSE(pending_read_); |
| 857 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); | 863 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); |
| 858 | 864 |
| 859 // Can't check |decoder1_| or |decoder2_| right now, they might have been | 865 // Can't check previously selected decoder(s) right now, they might have been |
| 860 // destroyed already. | 866 // destroyed already. |
| 861 ASSERT_GT(decoder3_->total_bytes_decoded(), 0); | 867 ASSERT_GT(decoder_->total_bytes_decoded(), 0); |
| 862 | 868 |
| 863 // Verify no frame was dropped. | 869 // Verify no frame was dropped. |
| 864 ReadAllFrames(); | 870 ReadAllFrames(); |
| 865 } | 871 } |
| 866 | 872 |
| 867 TEST_P(VideoFrameStreamTest, FallbackDecoder_ConfigChangeClearsPendingBuffers) { | 873 TEST_P(VideoFrameStreamTest, FallbackDecoder_ConfigChangeClearsPendingBuffers) { |
| 868 // Test case is only interesting if the decoder can receive a config change | 874 // Test case is only interesting if the decoder can receive a config change |
| 869 // before returning its first frame. | 875 // before returning its first frame. |
| 870 if (GetParam().decoding_delay < kNumBuffersInOneConfig) | 876 if (GetParam().decoding_delay < kNumBuffersInOneConfig) |
| 871 return; | 877 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 884 TEST_P(VideoFrameStreamTest, FallbackDecoder_ErrorDuringConfigChangeFlushing) { | 890 TEST_P(VideoFrameStreamTest, FallbackDecoder_ErrorDuringConfigChangeFlushing) { |
| 885 // Test case is only interesting if the decoder can receive a config change | 891 // Test case is only interesting if the decoder can receive a config change |
| 886 // before returning its first frame. | 892 // before returning its first frame. |
| 887 if (GetParam().decoding_delay < kNumBuffersInOneConfig) | 893 if (GetParam().decoding_delay < kNumBuffersInOneConfig) |
| 888 return; | 894 return; |
| 889 | 895 |
| 890 Initialize(); | 896 Initialize(); |
| 891 EnterPendingState(DEMUXER_READ_CONFIG_CHANGE); | 897 EnterPendingState(DEMUXER_READ_CONFIG_CHANGE); |
| 892 EXPECT_GT(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); | 898 EXPECT_GT(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); |
| 893 | 899 |
| 894 decoder1_->HoldDecode(); | 900 decoder_->HoldDecode(); |
| 895 SatisfyPendingCallback(DEMUXER_READ_CONFIG_CHANGE); | 901 SatisfyPendingCallback(DEMUXER_READ_CONFIG_CHANGE); |
| 896 | 902 |
| 897 // The flush request should have been sent and held. | 903 // The flush request should have been sent and held. |
| 898 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); | 904 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); |
| 899 EXPECT_TRUE(pending_read_); | 905 EXPECT_TRUE(pending_read_); |
| 900 | 906 |
| 901 // Triggering an error here will cause the frames in |decoder1_| to be lost. | 907 // Triggering an error here will cause the frames in selected decoder to be |
| 902 // There are no pending buffers buffers to give to give to |decoder2_| due to | 908 // lost. There are no pending buffers to give to |decoders_[1]| due to |
| 903 // crbug.com/603713. | 909 // http://crbug.com/603713 |
| 904 decoder1_->SimulateError(); | 910 decoder_->SimulateError(); |
| 905 base::RunLoop().RunUntilIdle(); | 911 base::RunLoop().RunUntilIdle(); |
| 906 | 912 |
| 907 // We want to make sure that |decoder2_| can decode the rest of the frames | 913 // We want to make sure the fallback decoder can decode the rest of the frames |
| 908 // in the demuxer stream. | 914 // in the demuxer stream. |
| 909 ReadAllFrames(kNumBuffersInOneConfig * (kNumConfigs - 1)); | 915 ReadAllFrames(kNumBuffersInOneConfig * (kNumConfigs - 1)); |
| 910 } | 916 } |
| 911 | 917 |
| 912 TEST_P(VideoFrameStreamTest, FallbackDecoder_PendingBuffersIsFilledAndCleared) { | 918 TEST_P(VideoFrameStreamTest, FallbackDecoder_PendingBuffersIsFilledAndCleared) { |
| 913 // Test applies only when there is a decoder delay, and the decoder will not | 919 // Test applies only when there is a decoder delay, and the decoder will not |
| 914 // receive a config change before outputing its first frame. Parallel decoding | 920 // receive a config change before outputing its first frame. Parallel decoding |
| 915 // is also disabled in this test case, for readability and simplicity of the | 921 // is also disabled in this test case, for readability and simplicity of the |
| 916 // unit test. | 922 // unit test. |
| 917 if (GetParam().decoding_delay == 0 || | 923 if (GetParam().decoding_delay == 0 || |
| 918 GetParam().decoding_delay > kNumBuffersInOneConfig || | 924 GetParam().decoding_delay > kNumBuffersInOneConfig || |
| 919 GetParam().parallel_decoding > 1) { | 925 GetParam().parallel_decoding > 1) { |
| 920 return; | 926 return; |
| 921 } | 927 } |
| 922 Initialize(); | 928 Initialize(); |
| 923 | 929 |
| 924 // Block on demuxer read and decoder decode so we can step through. | 930 // Block on demuxer read and decoder decode so we can step through. |
| 925 demuxer_stream_->HoldNextRead(); | 931 demuxer_stream_->HoldNextRead(); |
| 926 decoder1_->HoldDecode(); | 932 decoder_->HoldDecode(); |
| 927 ReadOneFrame(); | 933 ReadOneFrame(); |
| 928 | 934 |
| 929 int demuxer_reads_satisfied = 0; | 935 int demuxer_reads_satisfied = 0; |
| 930 // Send back and requests buffers until the next one would fill the decoder | 936 // Send back and requests buffers until the next one would fill the decoder |
| 931 // delay. | 937 // delay. |
| 932 while (demuxer_reads_satisfied < GetParam().decoding_delay - 1) { | 938 while (demuxer_reads_satisfied < GetParam().decoding_delay - 1) { |
| 933 // Send a buffer back. | 939 // Send a buffer back. |
| 934 demuxer_stream_->SatisfyReadAndHoldNext(); | 940 demuxer_stream_->SatisfyReadAndHoldNext(); |
| 935 base::RunLoop().RunUntilIdle(); | 941 base::RunLoop().RunUntilIdle(); |
| 936 ++demuxer_reads_satisfied; | 942 ++demuxer_reads_satisfied; |
| 937 | 943 |
| 938 // Decode one buffer. | 944 // Decode one buffer. |
| 939 decoder1_->SatisfySingleDecode(); | 945 decoder_->SatisfySingleDecode(); |
| 940 base::RunLoop().RunUntilIdle(); | 946 base::RunLoop().RunUntilIdle(); |
| 941 EXPECT_TRUE(pending_read_); | 947 EXPECT_TRUE(pending_read_); |
| 942 EXPECT_EQ(demuxer_reads_satisfied, | 948 EXPECT_EQ(demuxer_reads_satisfied, |
| 943 video_frame_stream_->get_pending_buffers_size_for_testing()); | 949 video_frame_stream_->get_pending_buffers_size_for_testing()); |
| 944 // No fallback buffers should be queued up yet. | 950 // No fallback buffers should be queued up yet. |
| 945 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); | 951 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); |
| 946 } | 952 } |
| 947 | 953 |
| 948 // Hold the init before triggering the error, to verify internal state. | 954 // Hold the init before triggering the error, to verify internal state. |
| 949 demuxer_stream_->SatisfyReadAndHoldNext(); | 955 demuxer_stream_->SatisfyReadAndHoldNext(); |
| 950 ++demuxer_reads_satisfied; | 956 ++demuxer_reads_satisfied; |
| 951 decoder2_->HoldNextInit(); | 957 |
| 952 decoder1_->SimulateError(); | 958 decoder_->SimulateError(); |
| 959 decoders_[1]->HoldNextInit(); |
| 953 base::RunLoop().RunUntilIdle(); | 960 base::RunLoop().RunUntilIdle(); |
| 954 | 961 |
| 955 EXPECT_TRUE(pending_read_); | 962 EXPECT_TRUE(pending_read_); |
| 956 EXPECT_EQ(demuxer_reads_satisfied, | 963 EXPECT_EQ(demuxer_reads_satisfied, |
| 957 video_frame_stream_->get_pending_buffers_size_for_testing()); | 964 video_frame_stream_->get_pending_buffers_size_for_testing()); |
| 958 | 965 |
| 959 decoder2_->SatisfyInit(); | 966 decoders_[1]->SatisfyInit(); |
| 960 decoder2_->HoldDecode(); | 967 decoders_[1]->HoldDecode(); |
| 961 base::RunLoop().RunUntilIdle(); | 968 base::RunLoop().RunUntilIdle(); |
| 962 | 969 |
| 970 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
| 971 |
| 963 // Make sure the pending buffers have been transfered to fallback buffers. | 972 // Make sure the pending buffers have been transfered to fallback buffers. |
| 964 // One call to Decode() during the initialization process, so we expect one | 973 // One call to Decode() during the initialization process, so we expect one |
| 965 // buffer to already have been consumed from the fallback buffers. | 974 // buffer to already have been consumed from the fallback buffers. |
| 966 // Pending buffers should never go down (unless we encounter a config change) | 975 // Pending buffers should never go down (unless we encounter a config change) |
| 967 EXPECT_EQ(demuxer_reads_satisfied - 1, | 976 EXPECT_EQ(demuxer_reads_satisfied - 1, |
| 968 video_frame_stream_->get_fallback_buffers_size_for_testing()); | 977 video_frame_stream_->get_fallback_buffers_size_for_testing()); |
| 969 EXPECT_EQ(demuxer_reads_satisfied, | 978 EXPECT_EQ(demuxer_reads_satisfied, |
| 970 video_frame_stream_->get_pending_buffers_size_for_testing()); | 979 video_frame_stream_->get_pending_buffers_size_for_testing()); |
| 971 | 980 |
| 972 decoder2_->SatisfyDecode(); | 981 decoder_->SatisfyDecode(); |
| 973 base::RunLoop().RunUntilIdle(); | 982 base::RunLoop().RunUntilIdle(); |
| 974 | 983 |
| 975 // Make sure all buffers consumed by |decoder2_| have come from the fallback. | 984 // Make sure all buffers consumed by |decoders_[1]| have come from the |
| 976 // Pending buffers should not have been cleared yet. | 985 // fallback. Pending buffers should not have been cleared yet. |
| 977 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); | 986 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); |
| 978 EXPECT_EQ(demuxer_reads_satisfied, | 987 EXPECT_EQ(demuxer_reads_satisfied, |
| 979 video_frame_stream_->get_pending_buffers_size_for_testing()); | 988 video_frame_stream_->get_pending_buffers_size_for_testing()); |
| 980 EXPECT_TRUE(pending_read_); | 989 EXPECT_TRUE(pending_read_); |
| 981 | 990 |
| 982 // Give the decoder one more buffer, enough to release a frame. | 991 // Give the decoder one more buffer, enough to release a frame. |
| 983 demuxer_stream_->SatisfyReadAndHoldNext(); | 992 demuxer_stream_->SatisfyReadAndHoldNext(); |
| 984 base::RunLoop().RunUntilIdle(); | 993 base::RunLoop().RunUntilIdle(); |
| 985 | 994 |
| 986 // New buffers should not have been added after the frame was released. | 995 // New buffers should not have been added after the frame was released. |
| 987 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); | 996 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); |
| 988 EXPECT_FALSE(pending_read_); | 997 EXPECT_FALSE(pending_read_); |
| 989 | 998 |
| 990 demuxer_stream_->SatisfyRead(); | 999 demuxer_stream_->SatisfyRead(); |
| 991 | 1000 |
| 992 // Confirm no frames were dropped. | 1001 // Confirm no frames were dropped. |
| 993 ReadAllFrames(); | 1002 ReadAllFrames(); |
| 994 } | 1003 } |
| 995 | 1004 |
| 996 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnDecodeThenInitErrors) { | 1005 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnDecodeThenInitErrors) { |
| 997 Initialize(); | 1006 Initialize(); |
| 998 decoder1_->SimulateError(); | 1007 decoder_->SimulateError(); |
| 999 decoder2_->SimulateFailureToInit(); | 1008 SimulateDecoderInitFailure({1}); |
| 1000 ReadOneFrame(); | 1009 ReadOneFrame(); |
| 1001 | 1010 |
| 1002 // |video_frame_stream_| should have fallen back to |decoder3_| | 1011 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName()); |
| 1012 |
| 1013 // |video_frame_stream_| should have fallen back to |decoders_[2]| |
| 1003 ASSERT_FALSE(pending_read_); | 1014 ASSERT_FALSE(pending_read_); |
| 1004 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); | 1015 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); |
| 1005 | 1016 |
| 1006 // Can't check |decoder1_| or |decoder2_| right now, they might have been | 1017 // Can't check previously selected decoder(s) right now, they might have been |
| 1007 // destroyed already. | 1018 // destroyed already. |
| 1008 ASSERT_GT(decoder3_->total_bytes_decoded(), 0); | 1019 ASSERT_GT(decoder_->total_bytes_decoded(), 0); |
| 1009 | 1020 |
| 1010 // Verify no frame was dropped. | 1021 // Verify no frame was dropped. |
| 1011 ReadAllFrames(); | 1022 ReadAllFrames(); |
| 1012 } | 1023 } |
| 1013 | 1024 |
| 1014 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitThenDecodeErrors) { | 1025 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitThenDecodeErrors) { |
| 1015 decoder1_->SimulateFailureToInit(); | 1026 SimulateDecoderInitFailure({0}); |
| 1016 decoder2_->HoldDecode(); | |
| 1017 Initialize(); | 1027 Initialize(); |
| 1028 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
| 1029 |
| 1030 decoder_->HoldDecode(); |
| 1018 ReadOneFrame(); | 1031 ReadOneFrame(); |
| 1019 decoder2_->SimulateError(); | 1032 decoder_->SimulateError(); |
| 1020 base::RunLoop().RunUntilIdle(); | 1033 base::RunLoop().RunUntilIdle(); |
| 1021 | 1034 |
| 1022 // |video_frame_stream_| should have fallen back to |decoder3_| | 1035 // |video_frame_stream_| should have fallen back to |decoders_[2]| |
| 1036 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName()); |
| 1037 |
| 1023 ASSERT_FALSE(pending_read_); | 1038 ASSERT_FALSE(pending_read_); |
| 1024 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); | 1039 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); |
| 1025 | 1040 |
| 1026 // Can't check |decoder1_| or |decoder2_| right now, they might have been | 1041 // Can't check previously selected decoder(s) right now, they might have been |
| 1027 // destroyed already. | 1042 // destroyed already. |
| 1028 ASSERT_GT(decoder3_->total_bytes_decoded(), 0); | 1043 ASSERT_GT(decoder_->total_bytes_decoded(), 0); |
| 1029 | 1044 |
| 1030 // Verify no frame was dropped. | 1045 // Verify no frame was dropped. |
| 1031 ReadAllFrames(); | 1046 ReadAllFrames(); |
| 1032 } | 1047 } |
| 1033 | 1048 |
| 1034 TEST_P(VideoFrameStreamTest, | 1049 TEST_P(VideoFrameStreamTest, |
| 1035 FallbackDecoder_NotSelectedOnMidstreamDecodeError) { | 1050 FallbackDecoder_NotSelectedOnMidstreamDecodeError) { |
| 1036 Initialize(); | 1051 Initialize(); |
| 1037 ReadOneFrame(); | 1052 ReadOneFrame(); |
| 1038 | 1053 |
| 1039 // Successfully received a frame. | 1054 // Successfully received a frame. |
| 1040 EXPECT_FALSE(pending_read_); | 1055 EXPECT_FALSE(pending_read_); |
| 1041 ASSERT_GT(decoder1_->total_bytes_decoded(), 0); | 1056 ASSERT_GT(decoder_->total_bytes_decoded(), 0); |
| 1042 | 1057 |
| 1043 decoder1_->SimulateError(); | 1058 decoder_->SimulateError(); |
| 1044 | 1059 |
| 1045 // The error must surface from Read() as DECODE_ERROR. | 1060 // The error must surface from Read() as DECODE_ERROR. |
| 1046 while (last_read_status_ == VideoFrameStream::OK) { | 1061 while (last_read_status_ == VideoFrameStream::OK) { |
| 1047 ReadOneFrame(); | 1062 ReadOneFrame(); |
| 1048 base::RunLoop().RunUntilIdle(); | 1063 base::RunLoop().RunUntilIdle(); |
| 1049 EXPECT_FALSE(pending_read_); | 1064 EXPECT_FALSE(pending_read_); |
| 1050 } | 1065 } |
| 1051 | 1066 |
| 1052 // Verify the error was surfaced, rather than falling back to |decoder2_|. | 1067 // Verify the error was surfaced, rather than falling back to other decoders. |
| 1068 ASSERT_EQ(GetDecoderName(0), decoder_->GetDisplayName()); |
| 1053 EXPECT_FALSE(pending_read_); | 1069 EXPECT_FALSE(pending_read_); |
| 1054 ASSERT_EQ(decoder2_->total_bytes_decoded(), 0); | |
| 1055 ASSERT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); | 1070 ASSERT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
| 1056 } | 1071 } |
| 1057 | 1072 |
| 1058 TEST_P(VideoFrameStreamTest, DecoderErrorWhenNotReading) { | 1073 TEST_P(VideoFrameStreamTest, DecoderErrorWhenNotReading) { |
| 1059 Initialize(); | 1074 Initialize(); |
| 1060 decoder1_->HoldDecode(); | 1075 decoder_->HoldDecode(); |
| 1061 ReadOneFrame(); | 1076 ReadOneFrame(); |
| 1062 EXPECT_TRUE(pending_read_); | 1077 EXPECT_TRUE(pending_read_); |
| 1063 | 1078 |
| 1064 // Satisfy decode requests until we get the first frame out. | 1079 // Satisfy decode requests until we get the first frame out. |
| 1065 while (pending_read_) { | 1080 while (pending_read_) { |
| 1066 decoder1_->SatisfySingleDecode(); | 1081 decoder_->SatisfySingleDecode(); |
| 1067 base::RunLoop().RunUntilIdle(); | 1082 base::RunLoop().RunUntilIdle(); |
| 1068 } | 1083 } |
| 1069 | 1084 |
| 1070 // Trigger an error in the decoding. | 1085 // Trigger an error in the decoding. |
| 1071 decoder1_->SimulateError(); | 1086 decoder_->SimulateError(); |
| 1072 | 1087 |
| 1073 // The error must surface from Read() as DECODE_ERROR. | 1088 // The error must surface from Read() as DECODE_ERROR. |
| 1074 while (last_read_status_ == VideoFrameStream::OK) { | 1089 while (last_read_status_ == VideoFrameStream::OK) { |
| 1075 ReadOneFrame(); | 1090 ReadOneFrame(); |
| 1076 base::RunLoop().RunUntilIdle(); | 1091 base::RunLoop().RunUntilIdle(); |
| 1077 EXPECT_FALSE(pending_read_); | 1092 EXPECT_FALSE(pending_read_); |
| 1078 } | 1093 } |
| 1079 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); | 1094 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
| 1080 } | 1095 } |
| 1081 | 1096 |
| 1082 TEST_P(VideoFrameStreamTest, FallbackDecoderSelectedOnFailureToReinitialize) { | 1097 TEST_P(VideoFrameStreamTest, FallbackDecoderSelectedOnFailureToReinitialize) { |
| 1083 Initialize(); | 1098 Initialize(); |
| 1084 decoder1_->SimulateFailureToInit(); | 1099 decoder_->SimulateFailureToInit(); |
| 1085 ReadUntilDecoderReinitialized(decoder1_); | 1100 ReadUntilDecoderReinitialized(); |
| 1101 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
| 1086 ReadAllFrames(); | 1102 ReadAllFrames(); |
| 1087 ASSERT_GT(decoder2_->total_bytes_decoded(), 0); | 1103 ASSERT_GT(decoder_->total_bytes_decoded(), 0); |
| 1088 } | 1104 } |
| 1089 | 1105 |
| 1090 TEST_P(VideoFrameStreamTest, | 1106 TEST_P(VideoFrameStreamTest, |
| 1091 FallbackDecoderSelectedOnFailureToReinitialize_Twice) { | 1107 FallbackDecoderSelectedOnFailureToReinitialize_Twice) { |
| 1092 Initialize(); | 1108 Initialize(); |
| 1093 decoder1_->SimulateFailureToInit(); | 1109 decoder_->SimulateFailureToInit(); |
| 1094 ReadUntilDecoderReinitialized(decoder1_); | 1110 ReadUntilDecoderReinitialized(); |
| 1111 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName()); |
| 1095 ReadOneFrame(); | 1112 ReadOneFrame(); |
| 1096 decoder2_->SimulateFailureToInit(); | 1113 decoder_->SimulateFailureToInit(); |
| 1097 ReadUntilDecoderReinitialized(decoder2_); | 1114 ReadUntilDecoderReinitialized(); |
| 1115 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName()); |
| 1098 ReadAllFrames(); | 1116 ReadAllFrames(); |
| 1099 } | 1117 } |
| 1100 | 1118 |
| 1101 TEST_P(VideoFrameStreamTest, DecodeErrorAfterFallbackDecoderSelectionFails) { | 1119 TEST_P(VideoFrameStreamTest, DecodeErrorAfterFallbackDecoderSelectionFails) { |
| 1102 Initialize(); | 1120 Initialize(); |
| 1103 decoder1_->SimulateFailureToInit(); | 1121 decoder_->SimulateFailureToInit(); |
| 1104 decoder2_->SimulateFailureToInit(); | 1122 SimulateDecoderInitFailure({1, 2}); |
| 1105 decoder3_->SimulateFailureToInit(); | 1123 ReadUntilDecoderReinitialized(); |
| 1106 ReadUntilDecoderReinitialized(decoder1_); | |
| 1107 // The error will surface from Read() as DECODE_ERROR. | 1124 // The error will surface from Read() as DECODE_ERROR. |
| 1108 while (last_read_status_ == VideoFrameStream::OK) { | 1125 while (last_read_status_ == VideoFrameStream::OK) { |
| 1109 ReadOneFrame(); | 1126 ReadOneFrame(); |
| 1110 base::RunLoop().RunUntilIdle(); | 1127 base::RunLoop().RunUntilIdle(); |
| 1111 EXPECT_FALSE(pending_read_); | 1128 EXPECT_FALSE(pending_read_); |
| 1112 } | 1129 } |
| 1113 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); | 1130 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
| 1114 } | 1131 } |
| 1115 | 1132 |
| 1116 TEST_P(VideoFrameStreamTest, Destroy_DuringFallbackDecoderSelection) { | 1133 TEST_P(VideoFrameStreamTest, Destroy_DuringFallbackDecoderSelection) { |
| 1117 Initialize(); | 1134 Initialize(); |
| 1118 decoder1_->SimulateFailureToInit(); | 1135 decoder_->SimulateFailureToInit(); |
| 1119 EnterPendingState(DECODER_REINIT); | 1136 EnterPendingState(DECODER_REINIT); |
| 1120 decoder2_->HoldNextInit(); | 1137 decoders_[1]->HoldNextInit(); |
| 1121 SatisfyPendingCallback(DECODER_REINIT); | 1138 SatisfyPendingCallback(DECODER_REINIT); |
| 1122 } | 1139 } |
| 1123 | 1140 |
| 1124 } // namespace media | 1141 } // namespace media |
| OLD | NEW |