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 "media/base/fake_demuxer_stream.h" | 12 #include "media/base/fake_demuxer_stream.h" |
12 #include "media/base/gmock_callback_support.h" | 13 #include "media/base/gmock_callback_support.h" |
13 #include "media/base/mock_filters.h" | 14 #include "media/base/mock_filters.h" |
14 #include "media/base/test_helpers.h" | 15 #include "media/base/test_helpers.h" |
15 #include "media/base/timestamp_constants.h" | 16 #include "media/base/timestamp_constants.h" |
16 #include "media/filters/decoder_stream.h" | 17 #include "media/filters/decoder_stream.h" |
17 #include "media/filters/fake_video_decoder.h" | 18 #include "media/filters/fake_video_decoder.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 using ::testing::_; | 21 using ::testing::_; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 103 |
103 ~VideoFrameStreamTest() { | 104 ~VideoFrameStreamTest() { |
104 // Check that the pipeline statistics callback was fired correctly. | 105 // Check that the pipeline statistics callback was fired correctly. |
105 EXPECT_EQ(num_decoded_bytes_unreported_, 0); | 106 EXPECT_EQ(num_decoded_bytes_unreported_, 0); |
106 | 107 |
107 is_initialized_ = false; | 108 is_initialized_ = false; |
108 decoder1_ = NULL; | 109 decoder1_ = NULL; |
109 decoder2_ = NULL; | 110 decoder2_ = NULL; |
110 decoder3_ = NULL; | 111 decoder3_ = NULL; |
111 video_frame_stream_.reset(); | 112 video_frame_stream_.reset(); |
112 message_loop_.RunUntilIdle(); | 113 base::RunLoop().RunUntilIdle(); |
113 | 114 |
114 DCHECK(!pending_initialize_); | 115 DCHECK(!pending_initialize_); |
115 DCHECK(!pending_read_); | 116 DCHECK(!pending_read_); |
116 DCHECK(!pending_reset_); | 117 DCHECK(!pending_reset_); |
117 DCHECK(!pending_stop_); | 118 DCHECK(!pending_stop_); |
118 } | 119 } |
119 | 120 |
120 MOCK_METHOD1(OnNewSpliceBuffer, void(base::TimeDelta)); | 121 MOCK_METHOD1(OnNewSpliceBuffer, void(base::TimeDelta)); |
121 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); | 122 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); |
122 | 123 |
(...skipping 21 matching lines...) Expand all Loading... |
144 | 145 |
145 void InitializeVideoFrameStream() { | 146 void InitializeVideoFrameStream() { |
146 pending_initialize_ = true; | 147 pending_initialize_ = true; |
147 video_frame_stream_->Initialize( | 148 video_frame_stream_->Initialize( |
148 demuxer_stream_.get(), base::Bind(&VideoFrameStreamTest::OnInitialized, | 149 demuxer_stream_.get(), base::Bind(&VideoFrameStreamTest::OnInitialized, |
149 base::Unretained(this)), | 150 base::Unretained(this)), |
150 cdm_context_.get(), | 151 cdm_context_.get(), |
151 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)), | 152 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)), |
152 base::Bind(&VideoFrameStreamTest::OnWaitingForDecryptionKey, | 153 base::Bind(&VideoFrameStreamTest::OnWaitingForDecryptionKey, |
153 base::Unretained(this))); | 154 base::Unretained(this))); |
154 message_loop_.RunUntilIdle(); | 155 base::RunLoop().RunUntilIdle(); |
155 } | 156 } |
156 | 157 |
157 // Fake Decrypt() function used by DecryptingDemuxerStream. It does nothing | 158 // Fake Decrypt() function used by DecryptingDemuxerStream. It does nothing |
158 // but removes the DecryptConfig to make the buffer unencrypted. | 159 // but removes the DecryptConfig to make the buffer unencrypted. |
159 void Decrypt(Decryptor::StreamType stream_type, | 160 void Decrypt(Decryptor::StreamType stream_type, |
160 const scoped_refptr<DecoderBuffer>& encrypted, | 161 const scoped_refptr<DecoderBuffer>& encrypted, |
161 const Decryptor::DecryptCB& decrypt_cb) { | 162 const Decryptor::DecryptCB& decrypt_cb) { |
162 DCHECK(encrypted->decrypt_config()); | 163 DCHECK(encrypted->decrypt_config()); |
163 if (has_no_key_) { | 164 if (has_no_key_) { |
164 decrypt_cb.Run(Decryptor::kNoKey, NULL); | 165 decrypt_cb.Run(Decryptor::kNoKey, NULL); |
(...skipping 27 matching lines...) Expand all Loading... |
192 DCHECK(!pending_read_); | 193 DCHECK(!pending_read_); |
193 DCHECK(pending_reset_); | 194 DCHECK(pending_reset_); |
194 pending_reset_ = false; | 195 pending_reset_ = false; |
195 } | 196 } |
196 | 197 |
197 void ReadOneFrame() { | 198 void ReadOneFrame() { |
198 frame_read_ = NULL; | 199 frame_read_ = NULL; |
199 pending_read_ = true; | 200 pending_read_ = true; |
200 video_frame_stream_->Read(base::Bind( | 201 video_frame_stream_->Read(base::Bind( |
201 &VideoFrameStreamTest::FrameReady, base::Unretained(this))); | 202 &VideoFrameStreamTest::FrameReady, base::Unretained(this))); |
202 message_loop_.RunUntilIdle(); | 203 base::RunLoop().RunUntilIdle(); |
203 } | 204 } |
204 | 205 |
205 void ReadUntilPending() { | 206 void ReadUntilPending() { |
206 do { | 207 do { |
207 ReadOneFrame(); | 208 ReadOneFrame(); |
208 } while (!pending_read_); | 209 } while (!pending_read_); |
209 } | 210 } |
210 | 211 |
211 void ReadAllFrames(int expected_decoded_frames) { | 212 void ReadAllFrames(int expected_decoded_frames) { |
212 do { | 213 do { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 case DECODER_DECODE: | 272 case DECODER_DECODE: |
272 decoder->HoldDecode(); | 273 decoder->HoldDecode(); |
273 ReadUntilPending(); | 274 ReadUntilPending(); |
274 break; | 275 break; |
275 | 276 |
276 case DECODER_RESET: | 277 case DECODER_RESET: |
277 decoder->HoldNextReset(); | 278 decoder->HoldNextReset(); |
278 pending_reset_ = true; | 279 pending_reset_ = true; |
279 video_frame_stream_->Reset(base::Bind(&VideoFrameStreamTest::OnReset, | 280 video_frame_stream_->Reset(base::Bind(&VideoFrameStreamTest::OnReset, |
280 base::Unretained(this))); | 281 base::Unretained(this))); |
281 message_loop_.RunUntilIdle(); | 282 base::RunLoop().RunUntilIdle(); |
282 break; | 283 break; |
283 | 284 |
284 case NOT_PENDING: | 285 case NOT_PENDING: |
285 NOTREACHED(); | 286 NOTREACHED(); |
286 break; | 287 break; |
287 } | 288 } |
288 } | 289 } |
289 | 290 |
290 void SatisfyPendingCallback(PendingState state) { | 291 void SatisfyPendingCallback(PendingState state) { |
291 SatisfyPendingCallback(state, decoder1_); | 292 SatisfyPendingCallback(state, decoder1_); |
(...skipping 27 matching lines...) Expand all Loading... |
319 | 320 |
320 case DECODER_RESET: | 321 case DECODER_RESET: |
321 decoder->SatisfyReset(); | 322 decoder->SatisfyReset(); |
322 break; | 323 break; |
323 | 324 |
324 case NOT_PENDING: | 325 case NOT_PENDING: |
325 NOTREACHED(); | 326 NOTREACHED(); |
326 break; | 327 break; |
327 } | 328 } |
328 | 329 |
329 message_loop_.RunUntilIdle(); | 330 base::RunLoop().RunUntilIdle(); |
330 } | 331 } |
331 | 332 |
332 void Initialize() { | 333 void Initialize() { |
333 EnterPendingState(DECODER_INIT); | 334 EnterPendingState(DECODER_INIT); |
334 SatisfyPendingCallback(DECODER_INIT); | 335 SatisfyPendingCallback(DECODER_INIT); |
335 } | 336 } |
336 | 337 |
337 void Read() { | 338 void Read() { |
338 EnterPendingState(DECODER_DECODE); | 339 EnterPendingState(DECODER_DECODE); |
339 SatisfyPendingCallback(DECODER_DECODE); | 340 SatisfyPendingCallback(DECODER_DECODE); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 ReadOneFrame(); | 448 ReadOneFrame(); |
448 EXPECT_TRUE(pending_read_); | 449 EXPECT_TRUE(pending_read_); |
449 | 450 |
450 int demuxed_buffers = 0; | 451 int demuxed_buffers = 0; |
451 | 452 |
452 // Pass frames from the demuxer to the VideoFrameStream until the first read | 453 // Pass frames from the demuxer to the VideoFrameStream until the first read |
453 // request is satisfied. | 454 // request is satisfied. |
454 while (pending_read_) { | 455 while (pending_read_) { |
455 ++demuxed_buffers; | 456 ++demuxed_buffers; |
456 demuxer_stream_->SatisfyReadAndHoldNext(); | 457 demuxer_stream_->SatisfyReadAndHoldNext(); |
457 message_loop_.RunUntilIdle(); | 458 base::RunLoop().RunUntilIdle(); |
458 } | 459 } |
459 | 460 |
460 EXPECT_EQ(std::min(GetParam().decoding_delay + 1, kNumBuffersInOneConfig + 1), | 461 EXPECT_EQ(std::min(GetParam().decoding_delay + 1, kNumBuffersInOneConfig + 1), |
461 demuxed_buffers); | 462 demuxed_buffers); |
462 | 463 |
463 // At this point the stream is waiting on read from the demuxer, but there is | 464 // At this point the stream is waiting on read from the demuxer, but there is |
464 // no pending read from the stream. The stream should be blocked if we try | 465 // no pending read from the stream. The stream should be blocked if we try |
465 // reading from it again. | 466 // reading from it again. |
466 ReadUntilPending(); | 467 ReadUntilPending(); |
467 | 468 |
468 demuxer_stream_->SatisfyRead(); | 469 demuxer_stream_->SatisfyRead(); |
469 message_loop_.RunUntilIdle(); | 470 base::RunLoop().RunUntilIdle(); |
470 EXPECT_FALSE(pending_read_); | 471 EXPECT_FALSE(pending_read_); |
471 } | 472 } |
472 | 473 |
473 TEST_P(VideoFrameStreamTest, Read_BlockedDemuxerAndDecoder) { | 474 TEST_P(VideoFrameStreamTest, Read_BlockedDemuxerAndDecoder) { |
474 // Test applies only when the decoder allows multiple parallel requests. | 475 // Test applies only when the decoder allows multiple parallel requests. |
475 if (GetParam().parallel_decoding == 1) | 476 if (GetParam().parallel_decoding == 1) |
476 return; | 477 return; |
477 | 478 |
478 Initialize(); | 479 Initialize(); |
479 demuxer_stream_->HoldNextRead(); | 480 demuxer_stream_->HoldNextRead(); |
480 decoder1_->HoldDecode(); | 481 decoder1_->HoldDecode(); |
481 ReadOneFrame(); | 482 ReadOneFrame(); |
482 EXPECT_TRUE(pending_read_); | 483 EXPECT_TRUE(pending_read_); |
483 | 484 |
484 int demuxed_buffers = 0; | 485 int demuxed_buffers = 0; |
485 | 486 |
486 // Pass frames from the demuxer to the VideoFrameStream until the first read | 487 // Pass frames from the demuxer to the VideoFrameStream until the first read |
487 // request is satisfied, while always keeping one decode request pending. | 488 // request is satisfied, while always keeping one decode request pending. |
488 while (pending_read_) { | 489 while (pending_read_) { |
489 ++demuxed_buffers; | 490 ++demuxed_buffers; |
490 demuxer_stream_->SatisfyReadAndHoldNext(); | 491 demuxer_stream_->SatisfyReadAndHoldNext(); |
491 message_loop_.RunUntilIdle(); | 492 base::RunLoop().RunUntilIdle(); |
492 | 493 |
493 // Always keep one decode request pending. | 494 // Always keep one decode request pending. |
494 if (demuxed_buffers > 1) { | 495 if (demuxed_buffers > 1) { |
495 decoder1_->SatisfySingleDecode(); | 496 decoder1_->SatisfySingleDecode(); |
496 message_loop_.RunUntilIdle(); | 497 base::RunLoop().RunUntilIdle(); |
497 } | 498 } |
498 } | 499 } |
499 | 500 |
500 ReadUntilPending(); | 501 ReadUntilPending(); |
501 EXPECT_TRUE(pending_read_); | 502 EXPECT_TRUE(pending_read_); |
502 | 503 |
503 // Unblocking one decode request should unblock read even when demuxer is | 504 // Unblocking one decode request should unblock read even when demuxer is |
504 // still blocked. | 505 // still blocked. |
505 decoder1_->SatisfySingleDecode(); | 506 decoder1_->SatisfySingleDecode(); |
506 message_loop_.RunUntilIdle(); | 507 base::RunLoop().RunUntilIdle(); |
507 EXPECT_FALSE(pending_read_); | 508 EXPECT_FALSE(pending_read_); |
508 | 509 |
509 // Stream should still be blocked on the demuxer after unblocking the decoder. | 510 // Stream should still be blocked on the demuxer after unblocking the decoder. |
510 decoder1_->SatisfyDecode(); | 511 decoder1_->SatisfyDecode(); |
511 ReadUntilPending(); | 512 ReadUntilPending(); |
512 EXPECT_TRUE(pending_read_); | 513 EXPECT_TRUE(pending_read_); |
513 | 514 |
514 // Verify that the stream has returned all frames that have been demuxed, | 515 // Verify that the stream has returned all frames that have been demuxed, |
515 // accounting for the decoder delay. | 516 // accounting for the decoder delay. |
516 EXPECT_EQ(demuxed_buffers - GetParam().decoding_delay, num_decoded_frames_); | 517 EXPECT_EQ(demuxed_buffers - GetParam().decoding_delay, num_decoded_frames_); |
517 | 518 |
518 // Unblocking the demuxer will unblock the stream. | 519 // Unblocking the demuxer will unblock the stream. |
519 demuxer_stream_->SatisfyRead(); | 520 demuxer_stream_->SatisfyRead(); |
520 message_loop_.RunUntilIdle(); | 521 base::RunLoop().RunUntilIdle(); |
521 EXPECT_FALSE(pending_read_); | 522 EXPECT_FALSE(pending_read_); |
522 } | 523 } |
523 | 524 |
524 TEST_P(VideoFrameStreamTest, Read_DuringEndOfStreamDecode) { | 525 TEST_P(VideoFrameStreamTest, Read_DuringEndOfStreamDecode) { |
525 // Test applies only when the decoder allows multiple parallel requests, and | 526 // Test applies only when the decoder allows multiple parallel requests, and |
526 // they are not satisfied in a single batch. | 527 // they are not satisfied in a single batch. |
527 if (GetParam().parallel_decoding == 1 || GetParam().decoding_delay != 0) | 528 if (GetParam().parallel_decoding == 1 || GetParam().decoding_delay != 0) |
528 return; | 529 return; |
529 | 530 |
530 Initialize(); | 531 Initialize(); |
531 decoder1_->HoldDecode(); | 532 decoder1_->HoldDecode(); |
532 | 533 |
533 // Read all of the frames up to end of stream. Since parallel decoding is | 534 // Read all of the frames up to end of stream. Since parallel decoding is |
534 // enabled, the end of stream buffer will be sent to the decoder immediately, | 535 // enabled, the end of stream buffer will be sent to the decoder immediately, |
535 // but we don't satisfy it yet. | 536 // but we don't satisfy it yet. |
536 for (int configuration = 0; configuration < kNumConfigs; configuration++) { | 537 for (int configuration = 0; configuration < kNumConfigs; configuration++) { |
537 for (int frame = 0; frame < kNumBuffersInOneConfig; frame++) { | 538 for (int frame = 0; frame < kNumBuffersInOneConfig; frame++) { |
538 ReadOneFrame(); | 539 ReadOneFrame(); |
539 while (pending_read_) { | 540 while (pending_read_) { |
540 decoder1_->SatisfySingleDecode(); | 541 decoder1_->SatisfySingleDecode(); |
541 message_loop_.RunUntilIdle(); | 542 base::RunLoop().RunUntilIdle(); |
542 } | 543 } |
543 } | 544 } |
544 } | 545 } |
545 | 546 |
546 // Read() again. The callback must be delayed until the decode completes. | 547 // Read() again. The callback must be delayed until the decode completes. |
547 ReadOneFrame(); | 548 ReadOneFrame(); |
548 ASSERT_TRUE(pending_read_); | 549 ASSERT_TRUE(pending_read_); |
549 | 550 |
550 // Satisfy decoding of the end of stream buffer. The read should complete. | 551 // Satisfy decoding of the end of stream buffer. The read should complete. |
551 decoder1_->SatisfySingleDecode(); | 552 decoder1_->SatisfySingleDecode(); |
552 message_loop_.RunUntilIdle(); | 553 base::RunLoop().RunUntilIdle(); |
553 ASSERT_FALSE(pending_read_); | 554 ASSERT_FALSE(pending_read_); |
554 EXPECT_EQ(last_read_status_, VideoFrameStream::OK); | 555 EXPECT_EQ(last_read_status_, VideoFrameStream::OK); |
555 | 556 |
556 // The read output should indicate end of stream. | 557 // The read output should indicate end of stream. |
557 ASSERT_TRUE(frame_read_.get()); | 558 ASSERT_TRUE(frame_read_.get()); |
558 EXPECT_TRUE( | 559 EXPECT_TRUE( |
559 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); | 560 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); |
560 } | 561 } |
561 | 562 |
562 // No Reset() before initialization is successfully completed. | 563 // No Reset() before initialization is successfully completed. |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 | 777 |
777 Initialize(); | 778 Initialize(); |
778 decoder1_->HoldDecode(); | 779 decoder1_->HoldDecode(); |
779 ReadOneFrame(); | 780 ReadOneFrame(); |
780 | 781 |
781 // One buffer should have already pulled from the demuxer stream. Set the next | 782 // One buffer should have already pulled from the demuxer stream. Set the next |
782 // one to be an EOS. | 783 // one to be an EOS. |
783 demuxer_stream_->SeekToEndOfStream(); | 784 demuxer_stream_->SeekToEndOfStream(); |
784 | 785 |
785 decoder1_->SatisfySingleDecode(); | 786 decoder1_->SatisfySingleDecode(); |
786 message_loop_.RunUntilIdle(); | 787 base::RunLoop().RunUntilIdle(); |
787 | 788 |
788 // |video_frame_stream_| should not have emited a frame. | 789 // |video_frame_stream_| should not have emited a frame. |
789 EXPECT_TRUE(pending_read_); | 790 EXPECT_TRUE(pending_read_); |
790 | 791 |
791 // Pending buffers should contain a regular buffer and an EOS buffer. | 792 // Pending buffers should contain a regular buffer and an EOS buffer. |
792 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 2); | 793 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 2); |
793 | 794 |
794 decoder1_->SimulateError(); | 795 decoder1_->SimulateError(); |
795 message_loop_.RunUntilIdle(); | 796 base::RunLoop().RunUntilIdle(); |
796 | 797 |
797 // A frame should have been emited | 798 // A frame should have been emited |
798 EXPECT_FALSE(pending_read_); | 799 EXPECT_FALSE(pending_read_); |
799 EXPECT_EQ(last_read_status_, VideoFrameStream::OK); | 800 EXPECT_EQ(last_read_status_, VideoFrameStream::OK); |
800 EXPECT_FALSE( | 801 EXPECT_FALSE( |
801 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); | 802 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); |
802 EXPECT_GT(decoder2_->total_bytes_decoded(), 0); | 803 EXPECT_GT(decoder2_->total_bytes_decoded(), 0); |
803 | 804 |
804 ReadOneFrame(); | 805 ReadOneFrame(); |
805 | 806 |
806 EXPECT_FALSE(pending_read_); | 807 EXPECT_FALSE(pending_read_); |
807 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); | 808 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); |
808 EXPECT_TRUE( | 809 EXPECT_TRUE( |
809 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); | 810 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); |
810 } | 811 } |
811 | 812 |
812 TEST_P(VideoFrameStreamTest, | 813 TEST_P(VideoFrameStreamTest, |
813 FallbackDecoder_SelectedOnInitialDecodeError_Twice) { | 814 FallbackDecoder_SelectedOnInitialDecodeError_Twice) { |
814 Initialize(); | 815 Initialize(); |
815 decoder1_->SimulateError(); | 816 decoder1_->SimulateError(); |
816 decoder2_->HoldNextInit(); | 817 decoder2_->HoldNextInit(); |
817 ReadOneFrame(); | 818 ReadOneFrame(); |
818 | 819 |
819 decoder2_->SatisfyInit(); | 820 decoder2_->SatisfyInit(); |
820 decoder2_->SimulateError(); | 821 decoder2_->SimulateError(); |
821 message_loop_.RunUntilIdle(); | 822 base::RunLoop().RunUntilIdle(); |
822 | 823 |
823 // |video_frame_stream_| should have fallen back to |decoder3_|. | 824 // |video_frame_stream_| should have fallen back to |decoder3_|. |
824 ASSERT_FALSE(pending_read_); | 825 ASSERT_FALSE(pending_read_); |
825 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); | 826 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); |
826 | 827 |
827 // Can't check |decoder1_| or |decoder2_| right now, they might have been | 828 // Can't check |decoder1_| or |decoder2_| right now, they might have been |
828 // destroyed already. | 829 // destroyed already. |
829 ASSERT_GT(decoder3_->total_bytes_decoded(), 0); | 830 ASSERT_GT(decoder3_->total_bytes_decoded(), 0); |
830 | 831 |
831 // Verify no frame was dropped. | 832 // Verify no frame was dropped. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 SatisfyPendingCallback(DEMUXER_READ_CONFIG_CHANGE); | 864 SatisfyPendingCallback(DEMUXER_READ_CONFIG_CHANGE); |
864 | 865 |
865 // The flush request should have been sent and held. | 866 // The flush request should have been sent and held. |
866 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); | 867 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); |
867 EXPECT_TRUE(pending_read_); | 868 EXPECT_TRUE(pending_read_); |
868 | 869 |
869 // Triggering an error here will cause the frames in |decoder1_| to be lost. | 870 // Triggering an error here will cause the frames in |decoder1_| to be lost. |
870 // There are no pending buffers buffers to give to give to |decoder2_| due to | 871 // There are no pending buffers buffers to give to give to |decoder2_| due to |
871 // crbug.com/603713. | 872 // crbug.com/603713. |
872 decoder1_->SimulateError(); | 873 decoder1_->SimulateError(); |
873 message_loop_.RunUntilIdle(); | 874 base::RunLoop().RunUntilIdle(); |
874 | 875 |
875 // We want to make sure that |decoder2_| can decode the rest of the frames | 876 // We want to make sure that |decoder2_| can decode the rest of the frames |
876 // in the demuxer stream. | 877 // in the demuxer stream. |
877 ReadAllFrames(kNumBuffersInOneConfig * (kNumConfigs - 1)); | 878 ReadAllFrames(kNumBuffersInOneConfig * (kNumConfigs - 1)); |
878 } | 879 } |
879 | 880 |
880 TEST_P(VideoFrameStreamTest, FallbackDecoder_PendingBuffersIsFilledAndCleared) { | 881 TEST_P(VideoFrameStreamTest, FallbackDecoder_PendingBuffersIsFilledAndCleared) { |
881 // Test applies only when there is a decoder delay, and the decoder will not | 882 // Test applies only when there is a decoder delay, and the decoder will not |
882 // receive a config change before outputing its first frame. Parallel decoding | 883 // receive a config change before outputing its first frame. Parallel decoding |
883 // is also disabled in this test case, for readability and simplicity of the | 884 // is also disabled in this test case, for readability and simplicity of the |
884 // unit test. | 885 // unit test. |
885 if (GetParam().decoding_delay == 0 || | 886 if (GetParam().decoding_delay == 0 || |
886 GetParam().decoding_delay > kNumBuffersInOneConfig || | 887 GetParam().decoding_delay > kNumBuffersInOneConfig || |
887 GetParam().parallel_decoding > 1) { | 888 GetParam().parallel_decoding > 1) { |
888 return; | 889 return; |
889 } | 890 } |
890 Initialize(); | 891 Initialize(); |
891 | 892 |
892 // Block on demuxer read and decoder decode so we can step through. | 893 // Block on demuxer read and decoder decode so we can step through. |
893 demuxer_stream_->HoldNextRead(); | 894 demuxer_stream_->HoldNextRead(); |
894 decoder1_->HoldDecode(); | 895 decoder1_->HoldDecode(); |
895 ReadOneFrame(); | 896 ReadOneFrame(); |
896 | 897 |
897 int demuxer_reads_satisfied = 0; | 898 int demuxer_reads_satisfied = 0; |
898 // Send back and requests buffers until the next one would fill the decoder | 899 // Send back and requests buffers until the next one would fill the decoder |
899 // delay. | 900 // delay. |
900 while (demuxer_reads_satisfied < GetParam().decoding_delay - 1) { | 901 while (demuxer_reads_satisfied < GetParam().decoding_delay - 1) { |
901 // Send a buffer back. | 902 // Send a buffer back. |
902 demuxer_stream_->SatisfyReadAndHoldNext(); | 903 demuxer_stream_->SatisfyReadAndHoldNext(); |
903 message_loop_.RunUntilIdle(); | 904 base::RunLoop().RunUntilIdle(); |
904 ++demuxer_reads_satisfied; | 905 ++demuxer_reads_satisfied; |
905 | 906 |
906 // Decode one buffer. | 907 // Decode one buffer. |
907 decoder1_->SatisfySingleDecode(); | 908 decoder1_->SatisfySingleDecode(); |
908 message_loop_.RunUntilIdle(); | 909 base::RunLoop().RunUntilIdle(); |
909 EXPECT_TRUE(pending_read_); | 910 EXPECT_TRUE(pending_read_); |
910 EXPECT_EQ(demuxer_reads_satisfied, | 911 EXPECT_EQ(demuxer_reads_satisfied, |
911 video_frame_stream_->get_pending_buffers_size_for_testing()); | 912 video_frame_stream_->get_pending_buffers_size_for_testing()); |
912 // No fallback buffers should be queued up yet. | 913 // No fallback buffers should be queued up yet. |
913 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); | 914 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); |
914 } | 915 } |
915 | 916 |
916 // Hold the init before triggering the error, to verify internal state. | 917 // Hold the init before triggering the error, to verify internal state. |
917 demuxer_stream_->SatisfyReadAndHoldNext(); | 918 demuxer_stream_->SatisfyReadAndHoldNext(); |
918 ++demuxer_reads_satisfied; | 919 ++demuxer_reads_satisfied; |
919 decoder2_->HoldNextInit(); | 920 decoder2_->HoldNextInit(); |
920 decoder1_->SimulateError(); | 921 decoder1_->SimulateError(); |
921 message_loop_.RunUntilIdle(); | 922 base::RunLoop().RunUntilIdle(); |
922 | 923 |
923 EXPECT_TRUE(pending_read_); | 924 EXPECT_TRUE(pending_read_); |
924 EXPECT_EQ(demuxer_reads_satisfied, | 925 EXPECT_EQ(demuxer_reads_satisfied, |
925 video_frame_stream_->get_pending_buffers_size_for_testing()); | 926 video_frame_stream_->get_pending_buffers_size_for_testing()); |
926 | 927 |
927 decoder2_->SatisfyInit(); | 928 decoder2_->SatisfyInit(); |
928 decoder2_->HoldDecode(); | 929 decoder2_->HoldDecode(); |
929 message_loop_.RunUntilIdle(); | 930 base::RunLoop().RunUntilIdle(); |
930 | 931 |
931 // Make sure the pending buffers have been transfered to fallback buffers. | 932 // Make sure the pending buffers have been transfered to fallback buffers. |
932 // One call to Decode() during the initialization process, so we expect one | 933 // One call to Decode() during the initialization process, so we expect one |
933 // buffer to already have been consumed from the fallback buffers. | 934 // buffer to already have been consumed from the fallback buffers. |
934 // Pending buffers should never go down (unless we encounter a config change) | 935 // Pending buffers should never go down (unless we encounter a config change) |
935 EXPECT_EQ(demuxer_reads_satisfied - 1, | 936 EXPECT_EQ(demuxer_reads_satisfied - 1, |
936 video_frame_stream_->get_fallback_buffers_size_for_testing()); | 937 video_frame_stream_->get_fallback_buffers_size_for_testing()); |
937 EXPECT_EQ(demuxer_reads_satisfied, | 938 EXPECT_EQ(demuxer_reads_satisfied, |
938 video_frame_stream_->get_pending_buffers_size_for_testing()); | 939 video_frame_stream_->get_pending_buffers_size_for_testing()); |
939 | 940 |
940 decoder2_->SatisfyDecode(); | 941 decoder2_->SatisfyDecode(); |
941 message_loop_.RunUntilIdle(); | 942 base::RunLoop().RunUntilIdle(); |
942 | 943 |
943 // Make sure all buffers consumed by |decoder2_| have come from the fallback. | 944 // Make sure all buffers consumed by |decoder2_| have come from the fallback. |
944 // Pending buffers should not have been cleared yet. | 945 // Pending buffers should not have been cleared yet. |
945 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); | 946 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); |
946 EXPECT_EQ(demuxer_reads_satisfied, | 947 EXPECT_EQ(demuxer_reads_satisfied, |
947 video_frame_stream_->get_pending_buffers_size_for_testing()); | 948 video_frame_stream_->get_pending_buffers_size_for_testing()); |
948 EXPECT_EQ(video_frame_stream_->get_previous_decoder_for_testing(), decoder1_); | 949 EXPECT_EQ(video_frame_stream_->get_previous_decoder_for_testing(), decoder1_); |
949 EXPECT_TRUE(pending_read_); | 950 EXPECT_TRUE(pending_read_); |
950 | 951 |
951 // Give the decoder one more buffer, enough to release a frame. | 952 // Give the decoder one more buffer, enough to release a frame. |
952 demuxer_stream_->SatisfyReadAndHoldNext(); | 953 demuxer_stream_->SatisfyReadAndHoldNext(); |
953 message_loop_.RunUntilIdle(); | 954 base::RunLoop().RunUntilIdle(); |
954 | 955 |
955 // New buffers should not have been added after the frame was released. | 956 // New buffers should not have been added after the frame was released. |
956 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); | 957 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); |
957 EXPECT_FALSE(pending_read_); | 958 EXPECT_FALSE(pending_read_); |
958 | 959 |
959 demuxer_stream_->SatisfyRead(); | 960 demuxer_stream_->SatisfyRead(); |
960 | 961 |
961 // Confirm no frames were dropped. | 962 // Confirm no frames were dropped. |
962 ReadAllFrames(); | 963 ReadAllFrames(); |
963 } | 964 } |
(...skipping 15 matching lines...) Expand all Loading... |
979 // Verify no frame was dropped. | 980 // Verify no frame was dropped. |
980 ReadAllFrames(); | 981 ReadAllFrames(); |
981 } | 982 } |
982 | 983 |
983 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitThenDecodeErrors) { | 984 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitThenDecodeErrors) { |
984 decoder1_->SimulateFailureToInit(); | 985 decoder1_->SimulateFailureToInit(); |
985 decoder2_->HoldDecode(); | 986 decoder2_->HoldDecode(); |
986 Initialize(); | 987 Initialize(); |
987 ReadOneFrame(); | 988 ReadOneFrame(); |
988 decoder2_->SimulateError(); | 989 decoder2_->SimulateError(); |
989 message_loop_.RunUntilIdle(); | 990 base::RunLoop().RunUntilIdle(); |
990 | 991 |
991 // |video_frame_stream_| should have fallen back to |decoder3_| | 992 // |video_frame_stream_| should have fallen back to |decoder3_| |
992 ASSERT_FALSE(pending_read_); | 993 ASSERT_FALSE(pending_read_); |
993 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); | 994 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); |
994 | 995 |
995 // Can't check |decoder1_| or |decoder2_| right now, they might have been | 996 // Can't check |decoder1_| or |decoder2_| right now, they might have been |
996 // destroyed already. | 997 // destroyed already. |
997 ASSERT_GT(decoder3_->total_bytes_decoded(), 0); | 998 ASSERT_GT(decoder3_->total_bytes_decoded(), 0); |
998 | 999 |
999 // Verify no frame was dropped. | 1000 // Verify no frame was dropped. |
1000 ReadAllFrames(); | 1001 ReadAllFrames(); |
1001 } | 1002 } |
1002 | 1003 |
1003 TEST_P(VideoFrameStreamTest, | 1004 TEST_P(VideoFrameStreamTest, |
1004 FallbackDecoder_NotSelectedOnMidstreamDecodeError) { | 1005 FallbackDecoder_NotSelectedOnMidstreamDecodeError) { |
1005 Initialize(); | 1006 Initialize(); |
1006 ReadOneFrame(); | 1007 ReadOneFrame(); |
1007 | 1008 |
1008 // Successfully received a frame. | 1009 // Successfully received a frame. |
1009 EXPECT_FALSE(pending_read_); | 1010 EXPECT_FALSE(pending_read_); |
1010 ASSERT_GT(decoder1_->total_bytes_decoded(), 0); | 1011 ASSERT_GT(decoder1_->total_bytes_decoded(), 0); |
1011 | 1012 |
1012 decoder1_->SimulateError(); | 1013 decoder1_->SimulateError(); |
1013 | 1014 |
1014 // The error must surface from Read() as DECODE_ERROR. | 1015 // The error must surface from Read() as DECODE_ERROR. |
1015 while (last_read_status_ == VideoFrameStream::OK) { | 1016 while (last_read_status_ == VideoFrameStream::OK) { |
1016 ReadOneFrame(); | 1017 ReadOneFrame(); |
1017 message_loop_.RunUntilIdle(); | 1018 base::RunLoop().RunUntilIdle(); |
1018 EXPECT_FALSE(pending_read_); | 1019 EXPECT_FALSE(pending_read_); |
1019 } | 1020 } |
1020 | 1021 |
1021 // Verify the error was surfaced, rather than falling back to |decoder2_|. | 1022 // Verify the error was surfaced, rather than falling back to |decoder2_|. |
1022 EXPECT_FALSE(pending_read_); | 1023 EXPECT_FALSE(pending_read_); |
1023 ASSERT_EQ(decoder2_->total_bytes_decoded(), 0); | 1024 ASSERT_EQ(decoder2_->total_bytes_decoded(), 0); |
1024 ASSERT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); | 1025 ASSERT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
1025 } | 1026 } |
1026 | 1027 |
1027 TEST_P(VideoFrameStreamTest, DecoderErrorWhenNotReading) { | 1028 TEST_P(VideoFrameStreamTest, DecoderErrorWhenNotReading) { |
1028 Initialize(); | 1029 Initialize(); |
1029 decoder1_->HoldDecode(); | 1030 decoder1_->HoldDecode(); |
1030 ReadOneFrame(); | 1031 ReadOneFrame(); |
1031 EXPECT_TRUE(pending_read_); | 1032 EXPECT_TRUE(pending_read_); |
1032 | 1033 |
1033 // Satisfy decode requests until we get the first frame out. | 1034 // Satisfy decode requests until we get the first frame out. |
1034 while (pending_read_) { | 1035 while (pending_read_) { |
1035 decoder1_->SatisfySingleDecode(); | 1036 decoder1_->SatisfySingleDecode(); |
1036 message_loop_.RunUntilIdle(); | 1037 base::RunLoop().RunUntilIdle(); |
1037 } | 1038 } |
1038 | 1039 |
1039 // Trigger an error in the decoding. | 1040 // Trigger an error in the decoding. |
1040 decoder1_->SimulateError(); | 1041 decoder1_->SimulateError(); |
1041 | 1042 |
1042 // The error must surface from Read() as DECODE_ERROR. | 1043 // The error must surface from Read() as DECODE_ERROR. |
1043 while (last_read_status_ == VideoFrameStream::OK) { | 1044 while (last_read_status_ == VideoFrameStream::OK) { |
1044 ReadOneFrame(); | 1045 ReadOneFrame(); |
1045 message_loop_.RunUntilIdle(); | 1046 base::RunLoop().RunUntilIdle(); |
1046 EXPECT_FALSE(pending_read_); | 1047 EXPECT_FALSE(pending_read_); |
1047 } | 1048 } |
1048 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); | 1049 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
1049 } | 1050 } |
1050 | 1051 |
1051 TEST_P(VideoFrameStreamTest, FallbackDecoderSelectedOnFailureToReinitialize) { | 1052 TEST_P(VideoFrameStreamTest, FallbackDecoderSelectedOnFailureToReinitialize) { |
1052 Initialize(); | 1053 Initialize(); |
1053 decoder1_->SimulateFailureToInit(); | 1054 decoder1_->SimulateFailureToInit(); |
1054 // Holding decode, because large decoder delays might cause us to get rid of | 1055 // Holding decode, because large decoder delays might cause us to get rid of |
1055 // |previous_decoder_| before we are in a pending state again. | 1056 // |previous_decoder_| before we are in a pending state again. |
1056 decoder2_->HoldDecode(); | 1057 decoder2_->HoldDecode(); |
1057 ReadUntilDecoderReinitialized(decoder1_); | 1058 ReadUntilDecoderReinitialized(decoder1_); |
1058 ASSERT_TRUE(video_frame_stream_->get_previous_decoder_for_testing()); | 1059 ASSERT_TRUE(video_frame_stream_->get_previous_decoder_for_testing()); |
1059 decoder2_->SatisfyDecode(); | 1060 decoder2_->SatisfyDecode(); |
1060 message_loop_.RunUntilIdle(); | 1061 base::RunLoop().RunUntilIdle(); |
1061 ReadAllFrames(); | 1062 ReadAllFrames(); |
1062 ASSERT_FALSE(video_frame_stream_->get_previous_decoder_for_testing()); | 1063 ASSERT_FALSE(video_frame_stream_->get_previous_decoder_for_testing()); |
1063 } | 1064 } |
1064 | 1065 |
1065 TEST_P(VideoFrameStreamTest, | 1066 TEST_P(VideoFrameStreamTest, |
1066 FallbackDecoderSelectedOnFailureToReinitialize_Twice) { | 1067 FallbackDecoderSelectedOnFailureToReinitialize_Twice) { |
1067 Initialize(); | 1068 Initialize(); |
1068 decoder1_->SimulateFailureToInit(); | 1069 decoder1_->SimulateFailureToInit(); |
1069 ReadUntilDecoderReinitialized(decoder1_); | 1070 ReadUntilDecoderReinitialized(decoder1_); |
1070 ReadOneFrame(); | 1071 ReadOneFrame(); |
1071 decoder2_->SimulateFailureToInit(); | 1072 decoder2_->SimulateFailureToInit(); |
1072 ReadUntilDecoderReinitialized(decoder2_); | 1073 ReadUntilDecoderReinitialized(decoder2_); |
1073 ReadAllFrames(); | 1074 ReadAllFrames(); |
1074 } | 1075 } |
1075 | 1076 |
1076 TEST_P(VideoFrameStreamTest, DecodeErrorAfterFallbackDecoderSelectionFails) { | 1077 TEST_P(VideoFrameStreamTest, DecodeErrorAfterFallbackDecoderSelectionFails) { |
1077 Initialize(); | 1078 Initialize(); |
1078 decoder1_->SimulateFailureToInit(); | 1079 decoder1_->SimulateFailureToInit(); |
1079 decoder2_->SimulateFailureToInit(); | 1080 decoder2_->SimulateFailureToInit(); |
1080 decoder3_->SimulateFailureToInit(); | 1081 decoder3_->SimulateFailureToInit(); |
1081 ReadUntilDecoderReinitialized(decoder1_); | 1082 ReadUntilDecoderReinitialized(decoder1_); |
1082 // The error will surface from Read() as DECODE_ERROR. | 1083 // The error will surface from Read() as DECODE_ERROR. |
1083 while (last_read_status_ == VideoFrameStream::OK) { | 1084 while (last_read_status_ == VideoFrameStream::OK) { |
1084 ReadOneFrame(); | 1085 ReadOneFrame(); |
1085 message_loop_.RunUntilIdle(); | 1086 base::RunLoop().RunUntilIdle(); |
1086 EXPECT_FALSE(pending_read_); | 1087 EXPECT_FALSE(pending_read_); |
1087 } | 1088 } |
1088 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); | 1089 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
1089 } | 1090 } |
1090 | 1091 |
1091 TEST_P(VideoFrameStreamTest, Destroy_DuringFallbackDecoderSelection) { | 1092 TEST_P(VideoFrameStreamTest, Destroy_DuringFallbackDecoderSelection) { |
1092 Initialize(); | 1093 Initialize(); |
1093 decoder1_->SimulateFailureToInit(); | 1094 decoder1_->SimulateFailureToInit(); |
1094 EnterPendingState(DECODER_REINIT); | 1095 EnterPendingState(DECODER_REINIT); |
1095 decoder2_->HoldNextInit(); | 1096 decoder2_->HoldNextInit(); |
1096 SatisfyPendingCallback(DECODER_REINIT); | 1097 SatisfyPendingCallback(DECODER_REINIT); |
1097 } | 1098 } |
1098 | 1099 |
1099 } // namespace media | 1100 } // namespace media |
OLD | NEW |