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 3 // found in the LICENSE file. 4 5 #include "base/bind.h" 6 #include "base/callback_helpers.h" 7 #include "base/message_loop/message_loop.h" 8 #include "media/base/gmock_callback_support.h" 9 #include "media/base/mock_filters.h" 10 #include "media/base/test_helpers.h" 11 #include "media/filters/decoder_stream.h" 12 #include "media/filters/fake_demuxer_stream.h" 13 #include "media/filters/fake_video_decoder.h" 14 #include "testing/gtest/include/gtest/gtest.h" 15 16 using ::testing::_; 17 using ::testing::AnyNumber; 18 using ::testing::Assign; 19 using ::testing::Invoke; 20 using ::testing::NiceMock; 21 using ::testing::Return; 22 using ::testing::SaveArg; 23 24 static const int kNumConfigs = 3; 25 static const int kNumBuffersInOneConfig = 5; 26 27 namespace media { 28 29 struct VideoFrameStreamTestParams { 30 VideoFrameStreamTestParams(bool is_encrypted, 31 int decoding_delay, 32 int parallel_decoding) 33 : is_encrypted(is_encrypted), 34 decoding_delay(decoding_delay), 35 parallel_decoding(parallel_decoding) {} 36 37 bool is_encrypted; 38 int decoding_delay; 39 int parallel_decoding; 40 }; 41 42 class VideoFrameStreamTest 43 : public testing::Test, 44 public testing::WithParamInterface<VideoFrameStreamTestParams> { 45 public: 46 VideoFrameStreamTest() 47 : demuxer_stream_(new FakeDemuxerStream(kNumConfigs, 48 kNumBuffersInOneConfig, 49 GetParam().is_encrypted)), 50 decryptor_(new NiceMock<MockDecryptor>()), 51 decoder_(new FakeVideoDecoder(GetParam().decoding_delay, 52 GetParam().parallel_decoding)), 53 is_initialized_(false), 54 num_decoded_frames_(0), 55 pending_initialize_(false), 56 pending_read_(false), 57 pending_reset_(false), 58 pending_stop_(false), 59 total_bytes_decoded_(0), 60 has_no_key_(false) { 61 ScopedVector<VideoDecoder> decoders; 62 decoders.push_back(decoder_); 63 64 video_frame_stream_.reset(new VideoFrameStream( 65 message_loop_.message_loop_proxy(), 66 decoders.Pass(), 67 base::Bind(&VideoFrameStreamTest::SetDecryptorReadyCallback, 68 base::Unretained(this)))); 69 70 // Decryptor can only decrypt (not decrypt-and-decode) so that 71 // DecryptingDemuxerStream will be used. 72 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _)) 73 .WillRepeatedly(RunCallback<1>(false)); 74 EXPECT_CALL(*decryptor_, Decrypt(_, _, _)) 75 .WillRepeatedly(Invoke(this, &VideoFrameStreamTest::Decrypt)); 76 } 77 78 ~VideoFrameStreamTest() { 79 DCHECK(!pending_initialize_); 80 DCHECK(!pending_read_); 81 DCHECK(!pending_reset_); 82 DCHECK(!pending_stop_); 83 84 if (is_initialized_) 85 Stop(); 86 EXPECT_FALSE(is_initialized_); 87 } 88 89 MOCK_METHOD1(OnNewSpliceBuffer, void(base::TimeDelta)); 90 MOCK_METHOD1(SetDecryptorReadyCallback, void(const media::DecryptorReadyCB&)); 91 92 void OnStatistics(const PipelineStatistics& statistics) { 93 total_bytes_decoded_ += statistics.video_bytes_decoded; 94 } 95 96 void OnInitialized(bool success) { 97 DCHECK(!pending_read_); 98 DCHECK(!pending_reset_); 99 DCHECK(pending_initialize_); 100 pending_initialize_ = false; 101 102 is_initialized_ = success; 103 if (!success) 104 decoder_ = NULL; 105 } 106 107 void InitializeVideoFrameStream() { 108 pending_initialize_ = true; 109 video_frame_stream_->Initialize( 110 demuxer_stream_.get(), 111 false, 112 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)), 113 base::Bind(&VideoFrameStreamTest::OnInitialized, 114 base::Unretained(this))); 115 message_loop_.RunUntilIdle(); 116 } 117 118 // Fake Decrypt() function used by DecryptingDemuxerStream. It does nothing 119 // but removes the DecryptConfig to make the buffer unencrypted. 120 void Decrypt(Decryptor::StreamType stream_type, 121 const scoped_refptr<DecoderBuffer>& encrypted, 122 const Decryptor::DecryptCB& decrypt_cb) { 123 DCHECK(encrypted->decrypt_config()); 124 if (has_no_key_) { 125 decrypt_cb.Run(Decryptor::kNoKey, NULL); 126 return; 127 } 128 129 DCHECK_EQ(stream_type, Decryptor::kVideo); 130 scoped_refptr<DecoderBuffer> decrypted = 131 DecoderBuffer::CopyFrom(encrypted->data(), encrypted->data_size()); 132 decrypted->set_timestamp(encrypted->timestamp()); 133 decrypted->set_duration(encrypted->duration()); 134 decrypt_cb.Run(Decryptor::kSuccess, decrypted); 135 } 136 137 // Callback for VideoFrameStream::Read(). 138 void FrameReady(VideoFrameStream::Status status, 139 const scoped_refptr<VideoFrame>& frame) { 140 DCHECK(pending_read_); 141 frame_read_ = frame; 142 last_read_status_ = status; 143 if (frame.get() && !frame->end_of_stream()) 144 num_decoded_frames_++; 145 pending_read_ = false; 146 } 147 148 void FrameReadyHoldDemuxer(VideoFrameStream::Status status, 149 const scoped_refptr<VideoFrame>& frame) { 150 FrameReady(status, frame); 151 152 } 153 154 void OnReset() { 155 DCHECK(!pending_read_); 156 DCHECK(pending_reset_); 157 pending_reset_ = false; 158 } 159 160 void OnStopped() { 161 DCHECK(!pending_initialize_); 162 DCHECK(!pending_read_); 163 DCHECK(!pending_reset_); 164 DCHECK(pending_stop_); 165 pending_stop_ = false; 166 is_initialized_ = false; 167 decoder_ = NULL; 168 } 169 170 void ReadOneFrame() { 171 frame_read_ = NULL; 172 pending_read_ = true; 173 video_frame_stream_->Read(base::Bind( 174 &VideoFrameStreamTest::FrameReady, base::Unretained(this))); 175 message_loop_.RunUntilIdle(); 176 } 177 178 void ReadUntilPending() { 179 do { 180 ReadOneFrame(); 181 } while (!pending_read_); 182 } 183 184 void ReadAllFrames() { 185 do { 186 ReadOneFrame(); 187 } while (frame_read_.get() && !frame_read_->end_of_stream()); 188 189 const int total_num_frames = kNumConfigs * kNumBuffersInOneConfig; 190 DCHECK_EQ(num_decoded_frames_, total_num_frames); 191 } 192 193 enum PendingState { 194 NOT_PENDING, 195 DEMUXER_READ_NORMAL, 196 DEMUXER_READ_CONFIG_CHANGE, 197 SET_DECRYPTOR, 198 DECRYPTOR_NO_KEY, 199 DECODER_INIT, 200 DECODER_REINIT, 201 DECODER_DECODE, 202 DECODER_RESET 203 }; 204 205 void EnterPendingState(PendingState state) { 206 DCHECK_NE(state, NOT_PENDING); 207 switch (state) { 208 case DEMUXER_READ_NORMAL: 209 demuxer_stream_->HoldNextRead(); 210 ReadUntilPending(); 211 break; 212 213 case DEMUXER_READ_CONFIG_CHANGE: 214 demuxer_stream_->HoldNextConfigChangeRead(); 215 ReadUntilPending(); 216 break; 217 218 case SET_DECRYPTOR: 219 // Hold DecryptorReadyCB. 220 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) 221 .Times(2); 222 // Initialize will fail because no decryptor is available. 223 InitializeVideoFrameStream(); 224 break; 225 226 case DECRYPTOR_NO_KEY: 227 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) 228 .WillRepeatedly(RunCallback<0>(decryptor_.get())); 229 has_no_key_ = true; 230 ReadOneFrame(); 231 break; 232 233 case DECODER_INIT: 234 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) 235 .WillRepeatedly(RunCallback<0>(decryptor_.get())); 236 decoder_->HoldNextInit(); 237 InitializeVideoFrameStream(); 238 break; 239 240 case DECODER_REINIT: 241 decoder_->HoldNextInit(); 242 ReadUntilPending(); 243 break; 244 245 case DECODER_DECODE: 246 decoder_->HoldDecode(); 247 ReadUntilPending(); 248 break; 249 250 case DECODER_RESET: 251 decoder_->HoldNextReset(); 252 pending_reset_ = true; 253 video_frame_stream_->Reset(base::Bind(&VideoFrameStreamTest::OnReset, 254 base::Unretained(this))); 255 message_loop_.RunUntilIdle(); 256 break; 257 258 case NOT_PENDING: 259 NOTREACHED(); 260 break; 261 } 262 } 263 264 void SatisfyPendingCallback(PendingState state) { 265 DCHECK_NE(state, NOT_PENDING); 266 switch (state) { 267 case DEMUXER_READ_NORMAL: 268 case DEMUXER_READ_CONFIG_CHANGE: 269 demuxer_stream_->SatisfyRead(); 270 break; 271 272 // These two cases are only interesting to test during 273 // VideoFrameStream::Stop(). There's no need to satisfy a callback. 274 case SET_DECRYPTOR: 275 case DECRYPTOR_NO_KEY: 276 NOTREACHED(); 277 break; 278 279 case DECODER_INIT: 280 decoder_->SatisfyInit(); 281 break; 282 283 case DECODER_REINIT: 284 decoder_->SatisfyInit(); 285 break; 286 287 case DECODER_DECODE: 288 decoder_->SatisfyDecode(); 289 break; 290 291 case DECODER_RESET: 292 decoder_->SatisfyReset(); 293 break; 294 295 case NOT_PENDING: 296 NOTREACHED(); 297 break; 298 } 299 300 message_loop_.RunUntilIdle(); 301 } 302 303 void Initialize() { 304 EnterPendingState(DECODER_INIT); 305 SatisfyPendingCallback(DECODER_INIT); 306 } 307 308 void Read() { 309 EnterPendingState(DECODER_DECODE); 310 SatisfyPendingCallback(DECODER_DECODE); 311 } 312 313 void Reset() { 314 EnterPendingState(DECODER_RESET); 315 SatisfyPendingCallback(DECODER_RESET); 316 } 317 318 void Stop() { 319 // Check that the pipeline statistics callback was fired correctly. 320 EXPECT_EQ(decoder_->total_bytes_decoded(), total_bytes_decoded_); 321 pending_stop_ = true; 322 video_frame_stream_->Stop(base::Bind(&VideoFrameStreamTest::OnStopped, 323 base::Unretained(this))); 324 message_loop_.RunUntilIdle(); 325 } 326 327 base::MessageLoop message_loop_; 328 329 scoped_ptr<VideoFrameStream> video_frame_stream_; 330 scoped_ptr<FakeDemuxerStream> demuxer_stream_; 331 // Use NiceMock since we don't care about most of calls on the decryptor, 332 // e.g. RegisterNewKeyCB(). 333 scoped_ptr<NiceMock<MockDecryptor> > decryptor_; 334 FakeVideoDecoder* decoder_; // Owned by |video_frame_stream_|. 335 336 bool is_initialized_; 337 int num_decoded_frames_; 338 bool pending_initialize_; 339 bool pending_read_; 340 bool pending_reset_; 341 bool pending_stop_; 342 int total_bytes_decoded_; 343 scoped_refptr<VideoFrame> frame_read_; 344 VideoFrameStream::Status last_read_status_; 345 346 // Decryptor has no key to decrypt a frame. 347 bool has_no_key_; 348 349 private: 350 DISALLOW_COPY_AND_ASSIGN(VideoFrameStreamTest); 351 }; 352 353 INSTANTIATE_TEST_CASE_P( 354 Clear, 355 VideoFrameStreamTest, 356 ::testing::Values( 357 VideoFrameStreamTestParams(false, 0, 1), 358 VideoFrameStreamTestParams(false, 3, 1), 359 VideoFrameStreamTestParams(false, 7, 1))); 360 INSTANTIATE_TEST_CASE_P( 361 Encrypted, 362 VideoFrameStreamTest, 363 ::testing::Values( 364 VideoFrameStreamTestParams(true, 7, 1))); 365 366 INSTANTIATE_TEST_CASE_P( 367 Clear_Parallel, 368 VideoFrameStreamTest, 369 ::testing::Values( 370 VideoFrameStreamTestParams(false, 0, 3), 371 VideoFrameStreamTestParams(false, 2, 3))); 372 373 374 TEST_P(VideoFrameStreamTest, Initialization) { 375 Initialize(); 376 } 377 378 TEST_P(VideoFrameStreamTest, ReadOneFrame) { 379 Initialize(); 380 Read(); 381 } 382 383 TEST_P(VideoFrameStreamTest, ReadAllFrames) { 384 Initialize(); 385 ReadAllFrames(); 386 } 387 388 TEST_P(VideoFrameStreamTest, Read_AfterReset) { 389 Initialize(); 390 Reset(); 391 Read(); 392 Reset(); 393 Read(); 394 } 395 396 TEST_P(VideoFrameStreamTest, Read_BlockedDemuxer) { 397 Initialize(); 398 demuxer_stream_->HoldNextRead(); 399 ReadOneFrame(); 400 EXPECT_TRUE(pending_read_); 401 402 int demuxed_buffers = 0; 403 404 // Pass frames from the demuxer to the VideoFrameStream until the first read 405 // request is satisfied. 406 while (pending_read_) { 407 ++demuxed_buffers; 408 demuxer_stream_->SatisfyReadAndHoldNext(); 409 message_loop_.RunUntilIdle(); 410 } 411 412 EXPECT_EQ(std::min(GetParam().decoding_delay + 1, kNumBuffersInOneConfig + 1), 413 demuxed_buffers); 414 415 // At this point the stream is waiting on read from the demuxer, but there is 416 // no pending read from the stream. The stream should be blocked if we try 417 // reading from it again. 418 ReadUntilPending(); 419 420 demuxer_stream_->SatisfyRead(); 421 message_loop_.RunUntilIdle(); 422 EXPECT_FALSE(pending_read_); 423 } 424 425 TEST_P(VideoFrameStreamTest, Read_BlockedDemuxerAndDecoder) { 426 // Test applies only when the decoder allows multiple parallel requests. 427 if (GetParam().parallel_decoding == 1) 428 return; 429 430 Initialize(); 431 demuxer_stream_->HoldNextRead(); 432 decoder_->HoldDecode(); 433 ReadOneFrame(); 434 EXPECT_TRUE(pending_read_); 435 436 int demuxed_buffers = 0; 437 438 // Pass frames from the demuxer to the VideoFrameStream until the first read 439 // request is satisfied, while always keeping one decode request pending. 440 while (pending_read_) { 441 ++demuxed_buffers; 442 demuxer_stream_->SatisfyReadAndHoldNext(); 443 message_loop_.RunUntilIdle(); 444 445 // Always keep one decode request pending. 446 if (demuxed_buffers > 1) { 447 decoder_->SatisfySingleDecode(); 448 message_loop_.RunUntilIdle(); 449 } 450 } 451 452 ReadUntilPending(); 453 EXPECT_TRUE(pending_read_); 454 455 // Unblocking one decode request should unblock read even when demuxer is 456 // still blocked. 457 decoder_->SatisfySingleDecode(); 458 message_loop_.RunUntilIdle(); 459 EXPECT_FALSE(pending_read_); 460 461 // Stream should still be blocked on the demuxer after unblocking the decoder. 462 decoder_->SatisfyDecode(); 463 ReadUntilPending(); 464 EXPECT_TRUE(pending_read_); 465 466 // Verify that the stream has returned all frames that have been demuxed, 467 // accounting for the decoder delay. 468 EXPECT_EQ(demuxed_buffers - GetParam().decoding_delay, num_decoded_frames_); 469 470 // Unblocking the demuxer will unblock the stream. 471 demuxer_stream_->SatisfyRead(); 472 message_loop_.RunUntilIdle(); 473 EXPECT_FALSE(pending_read_); 474 } 475 476 // No Reset() before initialization is successfully completed. 477 478 TEST_P(VideoFrameStreamTest, Reset_AfterInitialization) { 479 Initialize(); 480 Reset(); 481 Read(); 482 } 483 484 TEST_P(VideoFrameStreamTest, Reset_DuringReinitialization) { 485 Initialize(); 486 EnterPendingState(DECODER_REINIT); 487 // VideoDecoder::Reset() is not called when we reset during reinitialization. 488 pending_reset_ = true; 489 video_frame_stream_->Reset( 490 base::Bind(&VideoFrameStreamTest::OnReset, base::Unretained(this))); 491 SatisfyPendingCallback(DECODER_REINIT); 492 Read(); 493 } 494 495 TEST_P(VideoFrameStreamTest, Reset_AfterReinitialization) { 496 Initialize(); 497 EnterPendingState(DECODER_REINIT); 498 SatisfyPendingCallback(DECODER_REINIT); 499 Reset(); 500 Read(); 501 } 502 503 TEST_P(VideoFrameStreamTest, Reset_DuringDemuxerRead_Normal) { 504 Initialize(); 505 EnterPendingState(DEMUXER_READ_NORMAL); 506 EnterPendingState(DECODER_RESET); 507 SatisfyPendingCallback(DEMUXER_READ_NORMAL); 508 SatisfyPendingCallback(DECODER_RESET); 509 Read(); 510 } 511 512 TEST_P(VideoFrameStreamTest, Reset_DuringDemuxerRead_ConfigChange) { 513 Initialize(); 514 EnterPendingState(DEMUXER_READ_CONFIG_CHANGE); 515 EnterPendingState(DECODER_RESET); 516 SatisfyPendingCallback(DEMUXER_READ_CONFIG_CHANGE); 517 SatisfyPendingCallback(DECODER_RESET); 518 Read(); 519 } 520 521 TEST_P(VideoFrameStreamTest, Reset_DuringNormalDecoderDecode) { 522 Initialize(); 523 EnterPendingState(DECODER_DECODE); 524 EnterPendingState(DECODER_RESET); 525 SatisfyPendingCallback(DECODER_DECODE); 526 SatisfyPendingCallback(DECODER_RESET); 527 Read(); 528 } 529 530 TEST_P(VideoFrameStreamTest, Reset_AfterNormalRead) { 531 Initialize(); 532 Read(); 533 Reset(); 534 Read(); 535 } 536 537 TEST_P(VideoFrameStreamTest, Reset_AfterNormalReadWithActiveSplice) { 538 video_frame_stream_->set_splice_observer(base::Bind( 539 &VideoFrameStreamTest::OnNewSpliceBuffer, base::Unretained(this))); 540 Initialize(); 541 542 // Send buffers with a splice timestamp, which sets the active splice flag. 543 const base::TimeDelta splice_timestamp = base::TimeDelta(); 544 demuxer_stream_->set_splice_timestamp(splice_timestamp); 545 EXPECT_CALL(*this, OnNewSpliceBuffer(splice_timestamp)).Times(AnyNumber()); 546 Read(); 547 548 // Issue an explicit Reset() and clear the splice timestamp. 549 Reset(); 550 demuxer_stream_->set_splice_timestamp(kNoTimestamp()); 551 552 // Ensure none of the upcoming calls indicate they have a splice timestamp. 553 EXPECT_CALL(*this, OnNewSpliceBuffer(_)).Times(0); 554 Read(); 555 } 556 557 TEST_P(VideoFrameStreamTest, Reset_AfterDemuxerRead_ConfigChange) { 558 Initialize(); 559 EnterPendingState(DEMUXER_READ_CONFIG_CHANGE); 560 SatisfyPendingCallback(DEMUXER_READ_CONFIG_CHANGE); 561 Reset(); 562 Read(); 563 } 564 565 TEST_P(VideoFrameStreamTest, Reset_AfterEndOfStream) { 566 Initialize(); 567 ReadAllFrames(); 568 Reset(); 569 num_decoded_frames_ = 0; 570 demuxer_stream_->SeekToStart(); 571 ReadAllFrames(); 572 } 573 574 TEST_P(VideoFrameStreamTest, Reset_DuringNoKeyRead) { 575 Initialize(); 576 EnterPendingState(DECRYPTOR_NO_KEY); 577 Reset(); 578 } 579 580 TEST_P(VideoFrameStreamTest, Stop_BeforeInitialization) { 581 pending_stop_ = true; 582 video_frame_stream_->Stop( 583 base::Bind(&VideoFrameStreamTest::OnStopped, base::Unretained(this))); 584 message_loop_.RunUntilIdle(); 585 } 586 587 TEST_P(VideoFrameStreamTest, Stop_DuringSetDecryptor) { 588 if (!GetParam().is_encrypted) { 589 DVLOG(1) << "SetDecryptor test only runs when the stream is encrytped."; 590 return; 591 } 592 593 EnterPendingState(SET_DECRYPTOR); 594 pending_stop_ = true; 595 video_frame_stream_->Stop( 596 base::Bind(&VideoFrameStreamTest::OnStopped, base::Unretained(this))); 597 message_loop_.RunUntilIdle(); 598 } 599 600 TEST_P(VideoFrameStreamTest, Stop_DuringInitialization) { 601 EnterPendingState(DECODER_INIT); 602 Stop(); 603 } 604 605 TEST_P(VideoFrameStreamTest, Stop_AfterInitialization) { 606 Initialize(); 607 Stop(); 608 } 609 610 TEST_P(VideoFrameStreamTest, Stop_DuringReinitialization) { 611 Initialize(); 612 EnterPendingState(DECODER_REINIT); 613 Stop(); 614 } 615 616 TEST_P(VideoFrameStreamTest, Stop_AfterReinitialization) { 617 Initialize(); 618 EnterPendingState(DECODER_REINIT); 619 SatisfyPendingCallback(DECODER_REINIT); 620 Stop(); 621 } 622 623 TEST_P(VideoFrameStreamTest, Stop_DuringDemuxerRead_Normal) { 624 Initialize(); 625 EnterPendingState(DEMUXER_READ_NORMAL); 626 Stop(); 627 } 628 629 TEST_P(VideoFrameStreamTest, Stop_DuringDemuxerRead_ConfigChange) { 630 Initialize(); 631 EnterPendingState(DEMUXER_READ_CONFIG_CHANGE); 632 Stop(); 633 } 634 635 TEST_P(VideoFrameStreamTest, Stop_DuringNormalDecoderDecode) { 636 Initialize(); 637 EnterPendingState(DECODER_DECODE); 638 Stop(); 639 } 640 641 TEST_P(VideoFrameStreamTest, Stop_AfterNormalRead) { 642 Initialize(); 643 Read(); 644 Stop(); 645 } 646 647 TEST_P(VideoFrameStreamTest, Stop_AfterConfigChangeRead) { 648 Initialize(); 649 EnterPendingState(DEMUXER_READ_CONFIG_CHANGE); 650 SatisfyPendingCallback(DEMUXER_READ_CONFIG_CHANGE); 651 Stop(); 652 } 653 654 TEST_P(VideoFrameStreamTest, Stop_DuringNoKeyRead) { 655 Initialize(); 656 EnterPendingState(DECRYPTOR_NO_KEY); 657 Stop(); 658 } 659 660 TEST_P(VideoFrameStreamTest, Stop_DuringReset) { 661 Initialize(); 662 EnterPendingState(DECODER_RESET); 663 Stop(); 664 } 665 666 TEST_P(VideoFrameStreamTest, Stop_AfterReset) { 667 Initialize(); 668 Reset(); 669 Stop(); 670 } 671 672 TEST_P(VideoFrameStreamTest, Stop_DuringRead_DuringReset) { 673 Initialize(); 674 EnterPendingState(DECODER_DECODE); 675 EnterPendingState(DECODER_RESET); 676 Stop(); 677 } 678 679 TEST_P(VideoFrameStreamTest, Stop_AfterRead_DuringReset) { 680 Initialize(); 681 EnterPendingState(DECODER_DECODE); 682 EnterPendingState(DECODER_RESET); 683 SatisfyPendingCallback(DECODER_DECODE); 684 Stop(); 685 } 686 687 TEST_P(VideoFrameStreamTest, Stop_AfterRead_AfterReset) { 688 Initialize(); 689 Read(); 690 Reset(); 691 Stop(); 692 } 693 694 TEST_P(VideoFrameStreamTest, DecoderErrorWhenReading) { 695 Initialize(); 696 EnterPendingState(DECODER_DECODE); 697 decoder_->SimulateError(); 698 message_loop_.RunUntilIdle(); 699 ASSERT_FALSE(pending_read_); 700 ASSERT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); 701 } 702 703 TEST_P(VideoFrameStreamTest, DecoderErrorWhenNotReading) { 704 Initialize(); 705 706 decoder_->HoldDecode(); 707 ReadOneFrame(); 708 EXPECT_TRUE(pending_read_); 709 710 // Satisfy decode requests until we get the first frame out. 711 while (pending_read_) { 712 decoder_->SatisfySingleDecode(); 713 message_loop_.RunUntilIdle(); 714 } 715 716 // Trigger an error in the decoding. 717 decoder_->SimulateError(); 718 719 // The error must surface from Read() as DECODE_ERROR. 720 while (last_read_status_ == VideoFrameStream::OK) { 721 ReadOneFrame(); 722 message_loop_.RunUntilIdle(); 723 EXPECT_FALSE(pending_read_); 724 } 725 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); 726 } 727 728 } // namespace media 729