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

Side by Side Diff: media/base/android/media_source_player_unittest.cc

Issue 196133020: Reducing the IPC latency for MSE video decoding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang warning Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/android/media_source_player.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 void StartAudioDecoderJobAndSeekToWhileDecoding( 401 void StartAudioDecoderJobAndSeekToWhileDecoding(
402 const base::TimeDelta& seek_time) { 402 const base::TimeDelta& seek_time) {
403 EXPECT_FALSE(GetMediaDecoderJob(true)); 403 EXPECT_FALSE(GetMediaDecoderJob(true));
404 EXPECT_FALSE(player_.IsPlaying()); 404 EXPECT_FALSE(player_.IsPlaying());
405 EXPECT_EQ(0, demuxer_->num_data_requests()); 405 EXPECT_EQ(0, demuxer_->num_data_requests());
406 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); 406 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF());
407 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp()); 407 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp());
408 StartAudioDecoderJob(true); 408 StartAudioDecoderJob(true);
409 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 409 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
410 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 410 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
411 EXPECT_EQ(2, demuxer_->num_data_requests());
411 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 412 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
412 player_.SeekTo(seek_time); 413 player_.SeekTo(seek_time);
413 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); 414 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF());
414 EXPECT_EQ(0, demuxer_->num_seek_requests()); 415 EXPECT_EQ(0, demuxer_->num_seek_requests());
416 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
415 } 417 }
416 418
417 // Seek, including simulated receipt of |kAborted| read between SeekTo() and 419 // Seek, including simulated receipt of |kAborted| read between SeekTo() and
418 // OnDemuxerSeekDone(). Use this helper method only when the player already 420 // OnDemuxerSeekDone(). Use this helper method only when the player already
419 // has created the decoder job. Exactly one request for more data is expected 421 // has created the decoder job. Exactly one request for more data is expected
420 // following the seek, so use this helper for players with only audio or only 422 // following the seek, so use this helper for players with only audio or only
421 // video. 423 // video.
422 void SeekPlayerWithAbort(bool is_audio, const base::TimeDelta& seek_time) { 424 void SeekPlayerWithAbort(bool is_audio, const base::TimeDelta& seek_time) {
423 int original_num_seeks = demuxer_->num_seek_requests(); 425 int original_num_seeks = demuxer_->num_seek_requests();
424 int original_num_data_requests = demuxer_->num_data_requests(); 426 int original_num_data_requests = demuxer_->num_data_requests();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // This simulates the common condition that AUs received after browser 469 // This simulates the common condition that AUs received after browser
468 // seek begin with timestamps before the seek target, and don't 470 // seek begin with timestamps before the seek target, and don't
469 // immediately complete preroll. 471 // immediately complete preroll.
470 while (IsPrerolling(is_audio)) { 472 while (IsPrerolling(is_audio)) {
471 data.access_units[0].timestamp = 473 data.access_units[0].timestamp =
472 base::TimeDelta::FromMilliseconds(current_timestamp); 474 base::TimeDelta::FromMilliseconds(current_timestamp);
473 player_.OnDemuxerDataAvailable(data); 475 player_.OnDemuxerDataAvailable(data);
474 EXPECT_TRUE(GetMediaDecoderJob(is_audio)->is_decoding()); 476 EXPECT_TRUE(GetMediaDecoderJob(is_audio)->is_decoding());
475 EXPECT_EQ(target_timestamp, player_.GetCurrentTime()); 477 EXPECT_EQ(target_timestamp, player_.GetCurrentTime());
476 current_timestamp += 30; 478 current_timestamp += 30;
477 message_loop_.Run(); 479 WaitForDecodeDone(is_audio, !is_audio);
478 } 480 }
479 EXPECT_LE(target_timestamp, player_.GetCurrentTime()); 481 EXPECT_LE(target_timestamp, player_.GetCurrentTime());
480 } 482 }
481 483
482 DemuxerData CreateReadFromDemuxerAckWithConfigChanged(bool is_audio, 484 DemuxerData CreateReadFromDemuxerAckWithConfigChanged(bool is_audio,
483 int config_unit_index) { 485 int config_unit_index) {
484 DemuxerData data; 486 DemuxerData data;
485 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO; 487 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO;
486 data.access_units.resize(config_unit_index + 1); 488 data.access_units.resize(config_unit_index + 1);
487 489
488 for (int i = 0; i < config_unit_index; ++i) 490 for (int i = 0; i < config_unit_index; ++i)
489 data.access_units[i] = CreateAccessUnitWithData(is_audio, i); 491 data.access_units[i] = CreateAccessUnitWithData(is_audio, i);
490 492
491 data.access_units[config_unit_index].status = DemuxerStream::kConfigChanged; 493 data.access_units[config_unit_index].status = DemuxerStream::kConfigChanged;
492 return data; 494 return data;
493 } 495 }
494 496
495 // Valid only for video-only player tests. If |trigger_with_release_start| is 497 // Valid only for video-only player tests. If |trigger_with_release_start| is
496 // true, triggers the browser seek with a Release() + video data received + 498 // true, triggers the browser seek with a Release() + video data received +
497 // Start() with a new surface. If false, triggers the browser seek by 499 // Start() with a new surface. If false, triggers the browser seek by
498 // setting a new video surface after beginning decode of received video data. 500 // setting a new video surface after beginning decode of received video data.
499 // Such data receipt causes possibility that an I-frame is not next, and 501 // Such data receipt causes possibility that an I-frame is not next, and
500 // browser seek results once decode completes and surface change processing 502 // browser seek results once decode completes and surface change processing
501 // begins. 503 // begins.
502 void BrowserSeekPlayer(bool trigger_with_release_start) { 504 void BrowserSeekPlayer(bool trigger_with_release_start) {
503 int expected_num_data_requests = demuxer_->num_data_requests() + 1; 505 int expected_num_data_requests = demuxer_->num_data_requests() +
506 (trigger_with_release_start ? 1 : 2);
504 int expected_num_seek_requests = demuxer_->num_seek_requests(); 507 int expected_num_seek_requests = demuxer_->num_seek_requests();
505 int expected_num_browser_seek_requests = 508 int expected_num_browser_seek_requests =
506 demuxer_->num_browser_seek_requests(); 509 demuxer_->num_browser_seek_requests();
507 510
508 EXPECT_FALSE(GetMediaDecoderJob(false)); 511 EXPECT_FALSE(GetMediaDecoderJob(false));
509 CreateNextTextureAndSetVideoSurface(); 512 CreateNextTextureAndSetVideoSurface();
510 StartVideoDecoderJob(true); 513 StartVideoDecoderJob(true);
511 514
512 if (trigger_with_release_start) { 515 if (trigger_with_release_start) {
513 ReleasePlayer(); 516 ReleasePlayer();
514 517
515 // Simulate demuxer's response to the video data request. 518 // Simulate demuxer's response to the video data request. The data will be
519 // discarded.
516 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 520 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
517 EXPECT_FALSE(GetMediaDecoderJob(false)); 521 EXPECT_FALSE(GetMediaDecoderJob(false));
518 EXPECT_FALSE(player_.IsPlaying()); 522 EXPECT_FALSE(player_.IsPlaying());
519 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 523 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
520 524
521 CreateNextTextureAndSetVideoSurface(); 525 CreateNextTextureAndSetVideoSurface();
522 StartVideoDecoderJob(false); 526 StartVideoDecoderJob(false);
527 EXPECT_FALSE(GetMediaDecoderJob(false));
523 } else { 528 } else {
524 // Simulate demuxer's response to the video data request. 529 // Simulate demuxer's response to the video data request.
525 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 530 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
526 531
527 // While the decoder is decoding, trigger a browser seek by changing 532 // While the decoder is decoding, trigger a browser seek by changing
528 // surface. Demuxer does not know of browser seek in advance, so no 533 // surface. Demuxer does not know of browser seek in advance, so no
529 // |kAborted| data is required (though |kAborted| can certainly occur for 534 // |kAborted| data is required (though |kAborted| can certainly occur for
530 // any pending read in reality due to renderer preparing for a regular 535 // any pending read in reality due to renderer preparing for a regular
531 // seek). 536 // seek).
532 CreateNextTextureAndSetVideoSurface(); 537 CreateNextTextureAndSetVideoSurface();
533 538
534 // Browser seek should not begin until decoding has completed. 539 // Browser seek should not begin until decoding has completed.
535 EXPECT_TRUE(GetMediaDecoderJob(false)); 540 EXPECT_TRUE(GetMediaDecoderJob(false));
536 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 541 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
537 542
538 // Wait for the decoder job to finish decoding and be reset pending the 543 // Wait for the decoder job to finish decoding and be reset pending the
539 // browser seek. 544 // browser seek.
540 while (GetMediaDecoderJob(false)) 545 WaitForVideoDecodeDone();
541 message_loop_.RunUntilIdle(); 546 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
542 } 547 }
543 548
544 // Only one browser seek should have been initiated, and no further data 549 // Only one browser seek should have been initiated, and no further data
545 // should have been requested. 550 // should have been requested.
546 expected_num_seek_requests++; 551 expected_num_seek_requests++;
547 expected_num_browser_seek_requests++; 552 expected_num_browser_seek_requests++;
548 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 553 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
549 EXPECT_EQ(expected_num_browser_seek_requests, 554 EXPECT_EQ(expected_num_browser_seek_requests,
550 demuxer_->num_browser_seek_requests()); 555 demuxer_->num_browser_seek_requests());
551 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); 556 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
(...skipping 20 matching lines...) Expand all
572 577
573 int expected_num_data_requests = demuxer_->num_data_requests(); 578 int expected_num_data_requests = demuxer_->num_data_requests();
574 579
575 // Feed and decode a standalone access unit so the player exits prefetch. 580 // Feed and decode a standalone access unit so the player exits prefetch.
576 if (!config_unit_in_prefetch) { 581 if (!config_unit_in_prefetch) {
577 if (is_audio) 582 if (is_audio)
578 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 583 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
579 else 584 else
580 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 585 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
581 586
582 message_loop_.Run(); 587 WaitForDecodeDone(is_audio, !is_audio);
583 588
584 // We should have completed the prefetch phase at this point. 589 // We should have completed the prefetch phase at this point.
585 expected_num_data_requests++; 590 expected_num_data_requests++;
586 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); 591 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
587 } 592 }
588 593
589 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests()); 594 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests());
590 595
591 // Feed and decode access units with data for any units prior to 596 // Feed and decode access units with data for any units prior to
592 // |config_unit_index|, and a |kConfigChanged| unit at that index. 597 // |config_unit_index|, and a |kConfigChanged| unit at that index.
(...skipping 20 matching lines...) Expand all
613 618
614 surface_texture_a_is_next_ = !surface_texture_a_is_next_; 619 surface_texture_a_is_next_ = !surface_texture_a_is_next_;
615 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture); 620 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture);
616 player_.SetVideoSurface(surface.Pass()); 621 player_.SetVideoSurface(surface.Pass());
617 } 622 }
618 623
619 // Wait for one or both of the jobs to complete decoding. Decoder jobs are 624 // Wait for one or both of the jobs to complete decoding. Decoder jobs are
620 // assumed to exist for any stream whose decode completion is awaited. 625 // assumed to exist for any stream whose decode completion is awaited.
621 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) { 626 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) {
622 DCHECK(wait_for_audio || wait_for_video); 627 DCHECK(wait_for_audio || wait_for_video);
623
624 while ((wait_for_audio && GetMediaDecoderJob(true) && 628 while ((wait_for_audio && GetMediaDecoderJob(true) &&
629 GetMediaDecoderJob(true)->HasData() &&
625 GetMediaDecoderJob(true)->is_decoding()) || 630 GetMediaDecoderJob(true)->is_decoding()) ||
626 (wait_for_video && GetMediaDecoderJob(false) && 631 (wait_for_video && GetMediaDecoderJob(false) &&
632 GetMediaDecoderJob(false)->HasData() &&
627 GetMediaDecoderJob(false)->is_decoding())) { 633 GetMediaDecoderJob(false)->is_decoding())) {
628 message_loop_.RunUntilIdle(); 634 message_loop_.RunUntilIdle();
629 } 635 }
630 } 636 }
631 637
632 void WaitForAudioDecodeDone() { 638 void WaitForAudioDecodeDone() {
633 WaitForDecodeDone(true, false); 639 WaitForDecodeDone(true, false);
634 } 640 }
635 641
636 void WaitForVideoDecodeDone() { 642 void WaitForVideoDecodeDone() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 if (have_audio) 693 if (have_audio)
688 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 694 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
689 695
690 if (have_video) 696 if (have_video)
691 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 697 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
692 698
693 // Run until more data is requested a number of times equal to the number of 699 // Run until more data is requested a number of times equal to the number of
694 // media types configured. Since prefetching may be in progress, we cannot 700 // media types configured. Since prefetching may be in progress, we cannot
695 // reliably expect Run() to complete until we have sent demuxer data for all 701 // reliably expect Run() to complete until we have sent demuxer data for all
696 // configured media types, above. 702 // configured media types, above.
697 for (int i = 0; i < (have_audio ? 1 : 0) + (have_video ? 1 : 0); i++) 703 WaitForDecodeDone(have_audio, have_video);
698 message_loop_.Run();
699 704
700 // Simulate seek while decoding EOS or non-EOS for the appropriate 705 // Simulate seek while decoding EOS or non-EOS for the appropriate
701 // stream(s). 706 // stream(s).
702 if (have_audio) { 707 if (have_audio) {
703 if (eos_audio) 708 if (eos_audio)
704 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); 709 player_.OnDemuxerDataAvailable(CreateEOSAck(true));
705 else 710 else
706 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(1)); 711 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(1));
707 } 712 }
708 713
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 876
872 // While the decoder is decoding, change multiple surfaces. Pass an empty 877 // While the decoder is decoding, change multiple surfaces. Pass an empty
873 // surface first. 878 // surface first.
874 gfx::ScopedJavaSurface empty_surface; 879 gfx::ScopedJavaSurface empty_surface;
875 player_.SetVideoSurface(empty_surface.Pass()); 880 player_.SetVideoSurface(empty_surface.Pass());
876 // Next, pass a new non-empty surface. 881 // Next, pass a new non-empty surface.
877 CreateNextTextureAndSetVideoSurface(); 882 CreateNextTextureAndSetVideoSurface();
878 883
879 // Wait for the decoder job to finish decoding and be reset pending a browser 884 // Wait for the decoder job to finish decoding and be reset pending a browser
880 // seek. 885 // seek.
881 while (GetMediaDecoderJob(false)) 886 WaitForVideoDecodeDone();
882 message_loop_.RunUntilIdle(); 887 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
883 888
884 // Only one browser seek should have been initiated. No further data request 889 // Only one browser seek should have been initiated. No further data request
885 // should have been processed on |message_loop_| before surface change event 890 // should have been processed on |message_loop_| before surface change event
886 // became pending, above. 891 // became pending, above.
887 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 892 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
888 EXPECT_EQ(1, demuxer_->num_data_requests()); 893 EXPECT_EQ(2, demuxer_->num_data_requests());
889 894
890 // Simulate browser seek is done and confirm player requests more data for new 895 // Simulate browser seek is done and confirm player requests more data for new
891 // video decoder job. 896 // video decoder job.
892 player_.OnDemuxerSeekDone(player_.GetCurrentTime()); 897 player_.OnDemuxerSeekDone(player_.GetCurrentTime());
893 EXPECT_TRUE(GetMediaDecoderJob(false)); 898 EXPECT_TRUE(GetMediaDecoderJob(false));
894 EXPECT_EQ(2, demuxer_->num_data_requests()); 899 EXPECT_EQ(3, demuxer_->num_data_requests());
895 EXPECT_EQ(1, demuxer_->num_seek_requests()); 900 EXPECT_EQ(1, demuxer_->num_seek_requests());
896 } 901 }
897 902
898 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) { 903 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) {
899 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 904 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
900 905
901 // Test player pauses if an empty surface is passed. 906 // Test player pauses if an empty surface is passed.
902 CreateNextTextureAndSetVideoSurface(); 907 CreateNextTextureAndSetVideoSurface();
903 StartVideoDecoderJob(true); 908 StartVideoDecoderJob(true);
904 EXPECT_EQ(1, demuxer_->num_data_requests()); 909 EXPECT_EQ(1, demuxer_->num_data_requests());
905 910
906 // Send the first input chunk. 911 // Send the first input chunk.
907 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 912 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
908 913
909 // While the decoder is decoding, pass an empty surface. 914 // While the decoder is decoding, pass an empty surface.
910 gfx::ScopedJavaSurface empty_surface; 915 gfx::ScopedJavaSurface empty_surface;
911 player_.SetVideoSurface(empty_surface.Pass()); 916 player_.SetVideoSurface(empty_surface.Pass());
912
913 // Let the player starve. However, it should not issue any new data request in 917 // Let the player starve. However, it should not issue any new data request in
914 // this case. 918 // this case.
915 TriggerPlayerStarvation(); 919 TriggerPlayerStarvation();
916 // Wait for the decoder job to finish decoding and be reset. 920 // Wait for the decoder job to finish decoding and be reset.
917 while (GetMediaDecoderJob(false)) 921 while (GetMediaDecoderJob(false))
918 message_loop_.RunUntilIdle(); 922 message_loop_.RunUntilIdle();
919 923
920 // No further seek or data requests should have been received since the 924 // No further seek or data requests should have been received since the
921 // surface is empty. 925 // surface is empty.
922 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 926 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
923 EXPECT_EQ(1, demuxer_->num_data_requests()); 927 EXPECT_EQ(2, demuxer_->num_data_requests());
928 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
924 929
925 // Playback resumes once a non-empty surface is passed. 930 // Playback resumes once a non-empty surface is passed.
926 CreateNextTextureAndSetVideoSurface(); 931 CreateNextTextureAndSetVideoSurface();
927 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 932 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
928 } 933 }
929 934
930 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { 935 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) {
931 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 936 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
932 937
933 // Test that if video decoder is released while decoding, the resources will 938 // Test that if video decoder is released while decoding, the resources will
934 // not be immediately released. 939 // not be immediately released.
935 CreateNextTextureAndSetVideoSurface(); 940 CreateNextTextureAndSetVideoSurface();
936 StartVideoDecoderJob(true); 941 StartVideoDecoderJob(true);
937 EXPECT_EQ(1, manager_.num_resources_requested()); 942 EXPECT_EQ(1, manager_.num_resources_requested());
938 ReleasePlayer(); 943 ReleasePlayer();
939 // The resources will be immediately released since the decoder is idle. 944 // The resources will be immediately released since the decoder is idle.
940 EXPECT_EQ(1, manager_.num_resources_released()); 945 EXPECT_EQ(1, manager_.num_resources_released());
946 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
941 947
942 // Recreate the video decoder. 948 // Recreate the video decoder.
943 CreateNextTextureAndSetVideoSurface(); 949 CreateNextTextureAndSetVideoSurface();
944 player_.Start(); 950 player_.Start();
951 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
952 player_.OnDemuxerSeekDone(base::TimeDelta());
945 EXPECT_EQ(2, manager_.num_resources_requested()); 953 EXPECT_EQ(2, manager_.num_resources_requested());
946 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 954 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
947 ReleasePlayer(); 955 ReleasePlayer();
948 // The resource is still held by the video decoder until it finishes decoding. 956 // The resource is still held by the video decoder until it finishes decoding.
949 EXPECT_EQ(1, manager_.num_resources_released()); 957 EXPECT_EQ(1, manager_.num_resources_released());
950 // Wait for the decoder job to finish decoding and be reset. 958 // Wait for the decoder job to finish decoding and be reset.
951 while (manager_.num_resources_released() != 2) 959 while (manager_.num_resources_released() != 2)
952 message_loop_.RunUntilIdle(); 960 message_loop_.RunUntilIdle();
953 } 961 }
954 962
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 // Test that if the decoding job is not fully stopped after Pause(), 1019 // Test that if the decoding job is not fully stopped after Pause(),
1012 // calling Start() will be a noop. 1020 // calling Start() will be a noop.
1013 StartAudioDecoderJob(true); 1021 StartAudioDecoderJob(true);
1014 1022
1015 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 1023 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true);
1016 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 1024 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
1017 1025
1018 // Sending data to player. 1026 // Sending data to player.
1019 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1027 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1020 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1028 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1029 EXPECT_EQ(2, demuxer_->num_data_requests());
1021 1030
1022 // Decoder job will not immediately stop after Pause() since it is 1031 // Decoder job will not immediately stop after Pause() since it is
1023 // running on another thread. 1032 // running on another thread.
1024 player_.Pause(true); 1033 player_.Pause(true);
1025 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1034 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1026 1035
1027 // Nothing happens when calling Start() again. 1036 // Nothing happens when calling Start() again.
1028 player_.Start(); 1037 player_.Start();
1029 // Verify that Start() will not destroy and recreate the decoder job. 1038 // Verify that Start() will not destroy and recreate the decoder job.
1030 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 1039 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
1031 EXPECT_EQ(1, demuxer_->num_data_requests()); 1040
1032 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1041 while (GetMediaDecoderJob(true)->is_decoding())
1033 message_loop_.Run(); 1042 message_loop_.RunUntilIdle();
1034 // The decoder job should finish and a new request will be sent. 1043 // The decoder job should finish and wait for data.
1035 EXPECT_EQ(2, demuxer_->num_data_requests()); 1044 EXPECT_EQ(2, demuxer_->num_data_requests());
1036 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 1045 EXPECT_TRUE(GetMediaDecoderJob(true)->is_requesting_demuxer_data());
1037 } 1046 }
1038 1047
1039 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { 1048 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) {
1040 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1049 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1041 1050
1042 // Test that when Start() is called, video decoder jobs will wait for audio 1051 // Test that when Start() is called, video decoder jobs will wait for audio
1043 // decoder job before start decoding the data. 1052 // decoder job before start decoding the data.
1044 CreateNextTextureAndSetVideoSurface(); 1053 CreateNextTextureAndSetVideoSurface();
1045 Start(CreateAudioVideoDemuxerConfigs(), true); 1054 Start(CreateAudioVideoDemuxerConfigs(), true);
1046 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true); 1055 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true);
(...skipping 20 matching lines...) Expand all
1067 1076
1068 // Test start time ticks will reset after decoder job underruns. 1077 // Test start time ticks will reset after decoder job underruns.
1069 StartAudioDecoderJob(true); 1078 StartAudioDecoderJob(true);
1070 1079
1071 // For the first couple chunks, the decoder job may return 1080 // For the first couple chunks, the decoder job may return
1072 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode 1081 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode
1073 // more frames to guarantee that DECODE_SUCCEEDED will be returned. 1082 // more frames to guarantee that DECODE_SUCCEEDED will be returned.
1074 for (int i = 0; i < 4; ++i) { 1083 for (int i = 0; i < 4; ++i) {
1075 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); 1084 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i));
1076 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1085 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1077 message_loop_.Run(); 1086 // Decode data until decoder started requesting new data again.
1087 WaitForAudioDecodeDone();
1078 } 1088 }
1079 1089
1080 // The decoder job should finish and a new request will be sent. 1090 // The decoder job should finish and a new request will be sent.
1081 EXPECT_EQ(5, demuxer_->num_data_requests()); 1091 EXPECT_EQ(5, demuxer_->num_data_requests());
1082 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1092 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1083 base::TimeTicks previous = StartTimeTicks(); 1093 base::TimeTicks previous = StartTimeTicks();
1084 1094
1085 // Let the decoder timeout and execute the OnDecoderStarved() callback. 1095 // Let the decoder starve.
1086 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 1096 TriggerPlayerStarvation();
1087
1088 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1089 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks());
1090 message_loop_.RunUntilIdle();
1091
1092 // Send new data to the decoder so it can finish the currently
1093 // pending decode.
1094 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1097 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1095 WaitForAudioDecodeDone(); 1098 WaitForAudioDecodeDone();
1096 1099
1097 // Verify the start time ticks is cleared at this point because the 1100 // Verify the start time ticks is cleared at this point because the
1098 // player is prefetching. 1101 // player is prefetching.
1099 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks()); 1102 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks());
1100 1103
1101 // Send new data to the decoder so it can finish prefetching. This should 1104 // Send new data to the decoder so it can finish prefetching. This should
1102 // reset the start time ticks. 1105 // reset the start time ticks.
1103 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1106 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1104 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); 1107 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks());
1105 1108
1106 base::TimeTicks current = StartTimeTicks(); 1109 base::TimeTicks current = StartTimeTicks();
1107 EXPECT_LE(100.0, (current - previous).InMillisecondsF()); 1110 EXPECT_LE(0, (current - previous).InMillisecondsF());
1108 } 1111 }
1109 1112
1110 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) { 1113 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) {
1111 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1114 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1112 1115
1113 // Test MediaSourcePlayer can replay video after input EOS is reached. 1116 // Test MediaSourcePlayer can replay video after input EOS is reached.
1114 CreateNextTextureAndSetVideoSurface(); 1117 CreateNextTextureAndSetVideoSurface();
1115 StartVideoDecoderJob(true); 1118 StartVideoDecoderJob(true);
1116 1119
1117 // Send the first input chunk. 1120 // Send the first input chunk.
1118 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1121 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1119 message_loop_.Run(); 1122 WaitForVideoDecodeDone();
1120 1123
1121 VerifyPlaybackCompletesOnEOSDecode(true, false); 1124 VerifyPlaybackCompletesOnEOSDecode(true, false);
1122 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true); 1125 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true);
1123 } 1126 }
1124 1127
1125 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) { 1128 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) {
1126 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1129 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1127 1130
1128 // Test decode of audio EOS buffer without any prior decode. See also 1131 // Test decode of audio EOS buffer without any prior decode. See also
1129 // http://b/11696552. 1132 // http://b/11696552.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 // and responding to that prefetch with EOS completes A/V playback, even if 1226 // and responding to that prefetch with EOS completes A/V playback, even if
1224 // another starvation occurs during the latter EOS's decode. 1227 // another starvation occurs during the latter EOS's decode.
1225 CreateNextTextureAndSetVideoSurface(); 1228 CreateNextTextureAndSetVideoSurface();
1226 Start(CreateAudioVideoDemuxerConfigs(), true); 1229 Start(CreateAudioVideoDemuxerConfigs(), true);
1227 1230
1228 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1231 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1229 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS 1232 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1230 1233
1231 // Wait until video EOS is processed and more data (assumed to be audio) is 1234 // Wait until video EOS is processed and more data (assumed to be audio) is
1232 // requested. 1235 // requested.
1233 while (demuxer_->num_data_requests() < 3) 1236 WaitForAudioVideoDecodeDone();
1234 message_loop_.RunUntilIdle();
1235 WaitForVideoDecodeDone();
1236 EXPECT_EQ(3, demuxer_->num_data_requests()); 1237 EXPECT_EQ(3, demuxer_->num_data_requests());
1237 1238
1238 // Simulate decoder underrun to trigger prefetch while still decoding audio. 1239 // Simulate decoder underrun to trigger prefetch while still decoding audio.
1239 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(1)); 1240 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(1));
1240 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding() && 1241 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding() &&
1241 !GetMediaDecoderJob(false)->is_decoding()); 1242 !GetMediaDecoderJob(false)->is_decoding());
1242 TriggerPlayerStarvation(); 1243 TriggerPlayerStarvation();
1243 1244
1244 // Complete the audio decode that was in progress when simulated player 1245 // Complete the audio decode that was in progress when simulated player
1245 // starvation was triggered. 1246 // starvation was triggered.
1246 WaitForAudioDecodeDone(); 1247 WaitForAudioDecodeDone();
1247 EXPECT_EQ(4, demuxer_->num_data_requests()); 1248 EXPECT_EQ(4, demuxer_->num_data_requests());
1248
1249 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS 1249 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1250 EXPECT_FALSE(GetMediaDecoderJob(false)->is_decoding()); 1250 EXPECT_FALSE(GetMediaDecoderJob(false)->is_decoding());
1251 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1251 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1252 1252
1253 // Simulate another decoder underrun to trigger prefetch while decoding EOS. 1253 // Simulate another decoder underrun to trigger prefetch while decoding EOS.
1254 TriggerPlayerStarvation(); 1254 TriggerPlayerStarvation();
1255 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */); 1255 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */);
1256 } 1256 }
1257 1257
1258 TEST_F(MediaSourcePlayerTest, V_StarvationDuringEOSDecode) { 1258 TEST_F(MediaSourcePlayerTest, V_StarvationDuringEOSDecode) {
1259 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1259 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1260 1260
1261 // Test that video-only playback completes without further data requested when 1261 // Test that video-only playback completes without further data requested when
1262 // starvation occurs during EOS decode. 1262 // starvation occurs during EOS decode.
1263 CreateNextTextureAndSetVideoSurface(); 1263 CreateNextTextureAndSetVideoSurface();
1264 StartVideoDecoderJob(true); 1264 StartVideoDecoderJob(true);
1265 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1265 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1266 message_loop_.Run(); 1266 WaitForVideoDecodeDone();
1267 1267
1268 // Simulate decoder underrun to trigger prefetch while decoding EOS. 1268 // Simulate decoder underrun to trigger prefetch while decoding EOS.
1269 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS 1269 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1270 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding()); 1270 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding());
1271 TriggerPlayerStarvation(); 1271 TriggerPlayerStarvation();
1272 VerifyPlaybackCompletesOnEOSDecode(false, false /* ignored */); 1272 VerifyPlaybackCompletesOnEOSDecode(false, false /* ignored */);
1273 } 1273 }
1274 1274
1275 TEST_F(MediaSourcePlayerTest, A_StarvationDuringEOSDecode) { 1275 TEST_F(MediaSourcePlayerTest, A_StarvationDuringEOSDecode) {
1276 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1276 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1277 1277
1278 // Test that audio-only playback completes without further data requested when 1278 // Test that audio-only playback completes without further data requested when
1279 // starvation occurs during EOS decode. 1279 // starvation occurs during EOS decode.
1280 StartAudioDecoderJob(true); 1280 StartAudioDecoderJob(true);
1281 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1281 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1282 message_loop_.Run(); 1282 WaitForAudioDecodeDone();
1283 1283
1284 // Simulate decoder underrun to trigger prefetch while decoding EOS. 1284 // Simulate decoder underrun to trigger prefetch while decoding EOS.
1285 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS 1285 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1286 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1286 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1287 TriggerPlayerStarvation(); 1287 TriggerPlayerStarvation();
1288 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */); 1288 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */);
1289 } 1289 }
1290 1290
1291 TEST_F(MediaSourcePlayerTest, AV_SeekDuringEOSDecodePreventsCompletion) { 1291 TEST_F(MediaSourcePlayerTest, AV_SeekDuringEOSDecodePreventsCompletion) {
1292 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1292 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 1382
1383 // Simulate browser seek is done. Confirm player requests the regular seek, 1383 // Simulate browser seek is done. Confirm player requests the regular seek,
1384 // still has no video decoder job configured, and has not requested any 1384 // still has no video decoder job configured, and has not requested any
1385 // further data since the surface change event became pending in 1385 // further data since the surface change event became pending in
1386 // BrowserSeekPlayer(). 1386 // BrowserSeekPlayer().
1387 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1387 EXPECT_EQ(1, demuxer_->num_seek_requests());
1388 player_.OnDemuxerSeekDone(base::TimeDelta()); 1388 player_.OnDemuxerSeekDone(base::TimeDelta());
1389 EXPECT_FALSE(GetMediaDecoderJob(false)); 1389 EXPECT_FALSE(GetMediaDecoderJob(false));
1390 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1390 EXPECT_EQ(2, demuxer_->num_seek_requests());
1391 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1391 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
1392 EXPECT_EQ(1, demuxer_->num_data_requests());
1393 1392
1394 // Simulate regular seek is done and confirm player requests more data for 1393 // Simulate regular seek is done and confirm player requests more data for
1395 // new video decoder job. 1394 // new video decoder job.
1396 player_.OnDemuxerSeekDone(kNoTimestamp()); 1395 player_.OnDemuxerSeekDone(kNoTimestamp());
1397 EXPECT_TRUE(GetMediaDecoderJob(false)); 1396 EXPECT_TRUE(GetMediaDecoderJob(false));
1398 EXPECT_EQ(2, demuxer_->num_data_requests()); 1397 EXPECT_EQ(3, demuxer_->num_data_requests());
1399 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1398 EXPECT_EQ(2, demuxer_->num_seek_requests());
1400 } 1399 }
1401 1400
1402 TEST_F(MediaSourcePlayerTest, NoSeekForInitialReleaseAndStart) { 1401 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) {
1403 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1402 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1404 1403
1405 // Test that no seek is requested if player Release() + Start() occurs prior 1404 // Test that browser seek is requested if player Release() + Start() occurs
1406 // to receiving any data. 1405 // prior to receiving any data.
1407 CreateNextTextureAndSetVideoSurface(); 1406 CreateNextTextureAndSetVideoSurface();
1408 StartVideoDecoderJob(true); 1407 StartVideoDecoderJob(true);
1409 ReleasePlayer(); 1408 ReleasePlayer();
1410 1409
1411 // Pass a new non-empty surface. 1410 // Pass a new non-empty surface.
1412 CreateNextTextureAndSetVideoSurface(); 1411 CreateNextTextureAndSetVideoSurface();
1413 1412
1414 player_.Start(); 1413 player_.Start();
1415 1414
1416 // TODO(wolenetz/qinmin): Multiple in-flight data requests for same stream 1415 // The new player won't be created until the pending data request is
1417 // should be prevented. See http://crbug.com/306314. 1416 // processed.
1418 EXPECT_EQ(2, demuxer_->num_data_requests()); 1417 EXPECT_EQ(1, demuxer_->num_data_requests());
1419 EXPECT_TRUE(GetMediaDecoderJob(false)); 1418 EXPECT_FALSE(GetMediaDecoderJob(false));
1420 1419
1421 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1420 // A browser seek should be requested.
1421 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1422 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
1423 EXPECT_EQ(1, demuxer_->num_data_requests());
1422 } 1424 }
1423 1425
1424 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) { 1426 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) {
1425 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1427 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1426 1428
1427 // Test that one browser seek is requested if player Release() + Start(), with 1429 // Test that one browser seek is requested if player Release() + Start(), with
1428 // video data received between Release() and Start(). 1430 // video data received between Release() and Start().
1429 BrowserSeekPlayer(true); 1431 BrowserSeekPlayer(true);
1430 EXPECT_EQ(1, demuxer_->num_data_requests());
1431 1432
1432 // Simulate browser seek is done and confirm player requests more data. 1433 // Simulate browser seek is done and confirm player requests more data.
1433 player_.OnDemuxerSeekDone(base::TimeDelta()); 1434 player_.OnDemuxerSeekDone(base::TimeDelta());
1434 EXPECT_TRUE(GetMediaDecoderJob(false)); 1435 EXPECT_TRUE(GetMediaDecoderJob(false));
1435 EXPECT_EQ(2, demuxer_->num_data_requests()); 1436 EXPECT_EQ(2, demuxer_->num_data_requests());
1436 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1437 EXPECT_EQ(1, demuxer_->num_seek_requests());
1437 } 1438 }
1438 1439
1439 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { 1440 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) {
1440 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1441 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
(...skipping 26 matching lines...) Expand all
1467 // Test decoder job will begin prerolling upon seek, when it was not 1468 // Test decoder job will begin prerolling upon seek, when it was not
1468 // prerolling prior to the seek. 1469 // prerolling prior to the seek.
1469 StartAudioDecoderJob(true); 1470 StartAudioDecoderJob(true);
1470 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 1471 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true);
1471 EXPECT_TRUE(IsPrerolling(true)); 1472 EXPECT_TRUE(IsPrerolling(true));
1472 1473
1473 // Complete the initial preroll by feeding data to the decoder. 1474 // Complete the initial preroll by feeding data to the decoder.
1474 for (int i = 0; i < 4; ++i) { 1475 for (int i = 0; i < 4; ++i) {
1475 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); 1476 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i));
1476 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1477 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1477 message_loop_.Run(); 1478 WaitForAudioDecodeDone();
1478 } 1479 }
1479 EXPECT_LT(0.0, player_.GetCurrentTime().InMillisecondsF()); 1480 EXPECT_LT(0.0, player_.GetCurrentTime().InMillisecondsF());
1480 EXPECT_FALSE(IsPrerolling(true)); 1481 EXPECT_FALSE(IsPrerolling(true));
1481 1482
1482 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(500)); 1483 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(500));
1483 1484
1484 // Prerolling should have begun again. 1485 // Prerolling should have begun again.
1485 EXPECT_TRUE(IsPrerolling(true)); 1486 EXPECT_TRUE(IsPrerolling(true));
1486 EXPECT_EQ(500.0, GetPrerollTimestamp().InMillisecondsF()); 1487 EXPECT_EQ(500.0, GetPrerollTimestamp().InMillisecondsF());
1487 1488
1488 // Send data at and after the seek position. Prerolling should complete. 1489 // Send data at and after the seek position. Prerolling should complete.
1489 for (int i = 0; i < 4; ++i) { 1490 for (int i = 0; i < 4; ++i) {
1490 DemuxerData data = CreateReadFromDemuxerAckForAudio(i); 1491 DemuxerData data = CreateReadFromDemuxerAckForAudio(i);
1491 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds( 1492 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(
1492 500 + 30 * (i - 1)); 1493 500 + 30 * (i - 1));
1493 player_.OnDemuxerDataAvailable(data); 1494 player_.OnDemuxerDataAvailable(data);
1494 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1495 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1495 message_loop_.Run(); 1496 WaitForAudioDecodeDone();
1496 } 1497 }
1497 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF()); 1498 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF());
1498 EXPECT_FALSE(IsPrerolling(true)); 1499 EXPECT_FALSE(IsPrerolling(true));
1499 1500
1500 // Throughout this test, we should have not re-created the decoder job, so 1501 // Throughout this test, we should have not re-created the decoder job, so
1501 // IsPrerolling() transition from false to true was not due to constructor 1502 // IsPrerolling() transition from false to true was not due to constructor
1502 // initialization. It was due to BeginPrerolling(). 1503 // initialization. It was due to BeginPrerolling().
1503 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 1504 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
1504 } 1505 }
1505 1506
(...skipping 23 matching lines...) Expand all
1529 // TODO(qinmin): Simulation of multiple in-flight data requests (one from 1530 // TODO(qinmin): Simulation of multiple in-flight data requests (one from
1530 // before Release(), one from after Start()) is not included here, and 1531 // before Release(), one from after Start()) is not included here, and
1531 // neither is any data enqueued for later decode if it arrives after 1532 // neither is any data enqueued for later decode if it arrives after
1532 // Release() and before Start(). See http://crbug.com/306314. Assumption 1533 // Release() and before Start(). See http://crbug.com/306314. Assumption
1533 // for this test, to prevent flakiness until the bug is fixed, is the 1534 // for this test, to prevent flakiness until the bug is fixed, is the
1534 // first request's data arrives before Start(). Though that data is not 1535 // first request's data arrives before Start(). Though that data is not
1535 // seen by decoder, this assumption allows preroll continuation 1536 // seen by decoder, this assumption allows preroll continuation
1536 // verification and prevents multiple in-flight data requests. 1537 // verification and prevents multiple in-flight data requests.
1537 ReleasePlayer(); 1538 ReleasePlayer();
1538 player_.OnDemuxerDataAvailable(data); 1539 player_.OnDemuxerDataAvailable(data);
1539 message_loop_.RunUntilIdle(); 1540 WaitForAudioDecodeDone();
1540 EXPECT_FALSE(GetMediaDecoderJob(true)); 1541 EXPECT_FALSE(GetMediaDecoderJob(true));
1541 StartAudioDecoderJob(true); 1542 StartAudioDecoderJob(true);
1542 } else { 1543 } else {
1543 player_.OnDemuxerDataAvailable(data); 1544 player_.OnDemuxerDataAvailable(data);
1544 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1545 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1545 message_loop_.Run(); 1546 WaitForAudioDecodeDone();
1546 } 1547 }
1547 EXPECT_TRUE(IsPrerolling(true)); 1548 EXPECT_TRUE(IsPrerolling(true));
1548 } 1549 }
1549 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1550 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1550 EXPECT_TRUE(IsPrerolling(true)); 1551 EXPECT_TRUE(IsPrerolling(true));
1551 1552
1552 // Send data after the seek position. 1553 // Send data after the seek position.
1553 PrerollDecoderToTime(true, target_timestamp, target_timestamp); 1554 PrerollDecoderToTime(true, target_timestamp, target_timestamp);
1554 } 1555 }
1555 1556
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 // Test decoder job will preroll the media to the actual seek position 1664 // Test decoder job will preroll the media to the actual seek position
1664 // resulting from a browser seek. 1665 // resulting from a browser seek.
1665 BrowserSeekPlayer(false); 1666 BrowserSeekPlayer(false);
1666 1667
1667 // Simulate browser seek is done, but to a later time than was requested. 1668 // Simulate browser seek is done, but to a later time than was requested.
1668 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100); 1669 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100);
1669 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100)); 1670 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100));
1670 EXPECT_TRUE(GetMediaDecoderJob(false)); 1671 EXPECT_TRUE(GetMediaDecoderJob(false));
1671 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1672 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1672 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1673 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1673 EXPECT_EQ(2, demuxer_->num_data_requests()); 1674 EXPECT_EQ(3, demuxer_->num_data_requests());
1674 1675
1675 PrerollDecoderToTime( 1676 PrerollDecoderToTime(
1676 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1677 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1677 } 1678 }
1678 1679
1679 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) { 1680 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) {
1680 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1681 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1681 1682
1682 // Test that video config change notification results in request for demuxer 1683 // Test that video config change notification results in request for demuxer
1683 // configuration, and that a video decoder job results without any browser 1684 // configuration, and that a video decoder job results without any browser
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 // should not cause any crashes. 1775 // should not cause any crashes.
1775 CreateNextTextureAndSetVideoSurface(); 1776 CreateNextTextureAndSetVideoSurface();
1776 StartVideoDecoderJob(true); 1777 StartVideoDecoderJob(true);
1777 DemuxerData data = CreateReadFromDemuxerAckForVideo(); 1778 DemuxerData data = CreateReadFromDemuxerAckForVideo();
1778 player_.OnDemuxerDataAvailable(data); 1779 player_.OnDemuxerDataAvailable(data);
1779 1780
1780 // Trigger a surface change and decoder starvation. 1781 // Trigger a surface change and decoder starvation.
1781 CreateNextTextureAndSetVideoSurface(); 1782 CreateNextTextureAndSetVideoSurface();
1782 TriggerPlayerStarvation(); 1783 TriggerPlayerStarvation();
1783 WaitForVideoDecodeDone(); 1784 WaitForVideoDecodeDone();
1785 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
1784 1786
1785 // Surface change should trigger a seek. 1787 // Surface change should trigger a seek.
1788 player_.OnDemuxerDataAvailable(data);
1786 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1789 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
1787 player_.OnDemuxerSeekDone(base::TimeDelta()); 1790 player_.OnDemuxerSeekDone(base::TimeDelta());
1788 EXPECT_TRUE(GetMediaDecoderJob(false)); 1791 EXPECT_TRUE(GetMediaDecoderJob(false));
1789 1792
1790 // A new data request should be sent. 1793 // A new data request should be sent.
1791 EXPECT_EQ(2, demuxer_->num_data_requests()); 1794 EXPECT_EQ(3, demuxer_->num_data_requests());
1792 } 1795 }
1793 1796
1794 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { 1797 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) {
1795 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1798 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1796 1799
1797 // Test if OnPrefetchDone() had already been posted before and is executed 1800 // Test if OnPrefetchDone() had already been posted before and is executed
1798 // after Release(), then player does not DCHECK. This test is fragile to 1801 // after Release(), then player does not DCHECK. This test is fragile to
1799 // change to MediaDecoderJob::Prefetch() implementation; it assumes task 1802 // change to MediaDecoderJob::Prefetch() implementation; it assumes task
1800 // is posted to run |prefetch_cb| if the job already HasData(). 1803 // is posted to run |prefetch_cb| if the job already HasData().
1801 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test 1804 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test
1802 // becomes obsolete. See http://crbug.com/304234. 1805 // becomes obsolete. See http://crbug.com/304234.
1803 StartAudioDecoderJob(true); 1806 StartAudioDecoderJob(true);
1804 1807
1805 // Escape the original prefetch by decoding a single access unit. 1808 // Escape the original prefetch by decoding a single access unit.
1806 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1809 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1807 message_loop_.Run(); 1810 WaitForAudioDecodeDone();
1808 1811
1809 // Prime the job with a few more access units, so that a later prefetch, 1812 // Prime the job with a few more access units, so that a later prefetch,
1810 // triggered by starvation to simulate decoder underrun, can trivially 1813 // triggered by starvation to simulate decoder underrun, can trivially
1811 // post task to run OnPrefetchDone(). 1814 // post task to run OnPrefetchDone().
1812 player_.OnDemuxerDataAvailable( 1815 player_.OnDemuxerDataAvailable(
1813 CreateReadFromDemuxerAckWithConfigChanged(true, 4)); 1816 CreateReadFromDemuxerAckWithConfigChanged(true, 4));
1814 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1817 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1815 1818
1816 // Simulate decoder underrun, so trivial prefetch starts while still decoding. 1819 // Simulate decoder underrun, so trivial prefetch starts while still decoding.
1817 // The prefetch and posting of OnPrefetchDone() will not occur until next 1820 // The prefetch and posting of OnPrefetchDone() will not occur until next
1818 // MediaDecoderCallBack() occurs. 1821 // MediaDecoderCallBack() occurs.
1819 TriggerPlayerStarvation(); 1822 TriggerPlayerStarvation();
1820 1823
1821 // Upon the next successful decode callback, post a task to call Release() on 1824 // Upon the next successful decode callback, post a task to call Release() on
1822 // the |player_|, such that the trivial OnPrefetchDone() task posting also 1825 // the |player_|, such that the trivial OnPrefetchDone() task posting also
1823 // occurs and should execute after the Release(). 1826 // occurs and should execute after the Release().
1824 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); 1827 OnNextTestDecodeCallbackPostTaskToReleasePlayer();
1825 1828
1826 while (GetMediaDecoderJob(true)) 1829 WaitForAudioDecodeDone();
1827 message_loop_.RunUntilIdle();
1828 EXPECT_TRUE(decoder_callback_hook_executed_); 1830 EXPECT_TRUE(decoder_callback_hook_executed_);
1829 EXPECT_EQ(2, demuxer_->num_data_requests()); 1831 EXPECT_EQ(2, demuxer_->num_data_requests());
1830 1832
1831 // Player should have no decoder job until after Start(). 1833 // Player should have no decoder job until after Start().
1832 StartAudioDecoderJob(true); 1834 StartAudioDecoderJob(true);
1833 } 1835 }
1834 1836
1835 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { 1837 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) {
1836 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1838 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1837 1839
1838 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1840 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request
1839 // has not yet been sent, then the seek request is sent after Release(). Also, 1841 // has not yet been sent, then the seek request is sent after Release(). Also,
1840 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player 1842 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player
1841 // will resume correct post-seek preroll upon Start(). 1843 // will resume correct post-seek preroll upon Start().
1842 StartAudioDecoderJobAndSeekToWhileDecoding( 1844 StartAudioDecoderJobAndSeekToWhileDecoding(
1843 base::TimeDelta::FromMilliseconds(100)); 1845 base::TimeDelta::FromMilliseconds(100));
1844 ReleasePlayer(); 1846 ReleasePlayer();
1845 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1847 EXPECT_EQ(1, demuxer_->num_seek_requests());
1846 1848
1847 player_.OnDemuxerSeekDone(kNoTimestamp()); 1849 player_.OnDemuxerSeekDone(kNoTimestamp());
1848 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1850 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1849 EXPECT_FALSE(GetMediaDecoderJob(true)); 1851 EXPECT_FALSE(GetMediaDecoderJob(true));
1850 EXPECT_FALSE(player_.IsPlaying()); 1852 EXPECT_FALSE(player_.IsPlaying());
1851 1853
1852 // Player should begin prefetch and resume preroll upon Start(). 1854 // Player should begin prefetch and resume preroll upon Start().
1853 EXPECT_EQ(1, demuxer_->num_data_requests()); 1855 EXPECT_EQ(2, demuxer_->num_data_requests());
1854 StartAudioDecoderJob(true); 1856 StartAudioDecoderJob(true);
1855 EXPECT_TRUE(IsPrerolling(true)); 1857 EXPECT_TRUE(IsPrerolling(true));
1856 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1858 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1857 1859
1858 // No further seek should have been requested since Release(), above. 1860 // No further seek should have been requested since Release(), above.
1859 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1861 EXPECT_EQ(1, demuxer_->num_seek_requests());
1860 } 1862 }
1861 1863
1862 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { 1864 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) {
1863 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1865 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1864 1866
1865 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1867 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request
1866 // has not yet been sent, then the seek request is sent after Release(). Also, 1868 // has not yet been sent, then the seek request is sent after Release(). Also,
1867 // test if OnDemuxerSeekDone() does not occur until after the next Start(), 1869 // test if OnDemuxerSeekDone() does not occur until after the next Start(),
1868 // then the player remains pending seek done until (and resumes correct 1870 // then the player remains pending seek done until (and resumes correct
1869 // post-seek preroll after) OnDemuxerSeekDone(). 1871 // post-seek preroll after) OnDemuxerSeekDone().
1870 StartAudioDecoderJobAndSeekToWhileDecoding( 1872 StartAudioDecoderJobAndSeekToWhileDecoding(
1871 base::TimeDelta::FromMilliseconds(100)); 1873 base::TimeDelta::FromMilliseconds(100));
1872 ReleasePlayer(); 1874 ReleasePlayer();
1873 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1875 EXPECT_EQ(1, demuxer_->num_seek_requests());
1874 1876
1875 // Player should not prefetch upon Start() nor create the decoder job, due to 1877 // Player should not prefetch upon Start() nor create the decoder job, due to
1876 // awaiting DemuxerSeekDone. 1878 // awaiting DemuxerSeekDone.
1877 EXPECT_EQ(1, demuxer_->num_data_requests()); 1879 EXPECT_EQ(2, demuxer_->num_data_requests());
1878 StartAudioDecoderJob(false); 1880 StartAudioDecoderJob(false);
1879 1881
1880 player_.OnDemuxerSeekDone(kNoTimestamp()); 1882 player_.OnDemuxerSeekDone(kNoTimestamp());
1881 EXPECT_TRUE(GetMediaDecoderJob(true)); 1883 EXPECT_TRUE(GetMediaDecoderJob(true));
1882 EXPECT_TRUE(IsPrerolling(true)); 1884 EXPECT_TRUE(IsPrerolling(true));
1883 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1885 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1884 EXPECT_EQ(2, demuxer_->num_data_requests()); 1886 EXPECT_EQ(3, demuxer_->num_data_requests());
1885 1887
1886 // No further seek should have been requested since Release(), above. 1888 // No further seek should have been requested since Release(), above.
1887 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1889 EXPECT_EQ(1, demuxer_->num_seek_requests());
1888 } 1890 }
1889 1891
1890 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) { 1892 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) {
1891 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1893 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1892 1894
1893 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC 1895 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC
1894 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the 1896 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the
1895 // player will resume correct post-seek preroll upon Start(). 1897 // player will resume correct post-seek preroll upon Start().
1896 StartAudioDecoderJobAndSeekToWhileDecoding( 1898 StartAudioDecoderJobAndSeekToWhileDecoding(
1897 base::TimeDelta::FromMilliseconds(100)); 1899 base::TimeDelta::FromMilliseconds(100));
1898 WaitForAudioDecodeDone(); 1900 WaitForAudioDecodeDone();
1899 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1901 EXPECT_EQ(1, demuxer_->num_seek_requests());
1900 1902
1901 ReleasePlayer(); 1903 ReleasePlayer();
1902 player_.OnDemuxerSeekDone(kNoTimestamp()); 1904 player_.OnDemuxerSeekDone(kNoTimestamp());
1903 EXPECT_FALSE(player_.IsPlaying()); 1905 EXPECT_FALSE(player_.IsPlaying());
1904 EXPECT_FALSE(GetMediaDecoderJob(true)); 1906 EXPECT_FALSE(GetMediaDecoderJob(true));
1905 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1907 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1906 1908
1907 // Player should begin prefetch and resume preroll upon Start(). 1909 // Player should begin prefetch and resume preroll upon Start().
1908 EXPECT_EQ(1, demuxer_->num_data_requests()); 1910 EXPECT_EQ(2, demuxer_->num_data_requests());
1909 StartAudioDecoderJob(true); 1911 StartAudioDecoderJob(true);
1910 EXPECT_TRUE(IsPrerolling(true)); 1912 EXPECT_TRUE(IsPrerolling(true));
1911 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1913 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1912 1914
1913 // No further seek should have been requested since before Release(), above. 1915 // No further seek should have been requested since before Release(), above.
1914 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1916 EXPECT_EQ(1, demuxer_->num_seek_requests());
1915 } 1917 }
1916 1918
1917 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { 1919 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) {
1918 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1920 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1919 1921
1920 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC 1922 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC
1921 // request and OnDemuxerSeekDone() does not occur until after the next 1923 // request and OnDemuxerSeekDone() does not occur until after the next
1922 // Start(), then the player remains pending seek done until (and resumes 1924 // Start(), then the player remains pending seek done until (and resumes
1923 // correct post-seek preroll after) OnDemuxerSeekDone(). 1925 // correct post-seek preroll after) OnDemuxerSeekDone().
1924 StartAudioDecoderJobAndSeekToWhileDecoding( 1926 StartAudioDecoderJobAndSeekToWhileDecoding(
1925 base::TimeDelta::FromMilliseconds(100)); 1927 base::TimeDelta::FromMilliseconds(100));
1926 WaitForAudioDecodeDone(); 1928 WaitForAudioDecodeDone();
1927 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1929 EXPECT_EQ(1, demuxer_->num_seek_requests());
1928 1930
1929 ReleasePlayer(); 1931 ReleasePlayer();
1930 EXPECT_EQ(1, demuxer_->num_data_requests()); 1932 EXPECT_EQ(2, demuxer_->num_data_requests());
1931 StartAudioDecoderJob(false); 1933 StartAudioDecoderJob(false);
1932 1934
1933 player_.OnDemuxerSeekDone(kNoTimestamp()); 1935 player_.OnDemuxerSeekDone(kNoTimestamp());
1934 EXPECT_TRUE(GetMediaDecoderJob(true)); 1936 EXPECT_TRUE(GetMediaDecoderJob(true));
1935 EXPECT_TRUE(IsPrerolling(true)); 1937 EXPECT_TRUE(IsPrerolling(true));
1936 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1938 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1937 EXPECT_EQ(2, demuxer_->num_data_requests()); 1939 EXPECT_EQ(3, demuxer_->num_data_requests());
1938 1940
1939 // No further seek should have been requested since before Release(), above. 1941 // No further seek should have been requested since before Release(), above.
1940 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1942 EXPECT_EQ(1, demuxer_->num_seek_requests());
1941 } 1943 }
1942 1944
1943 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenConfigsAvailable) { 1945 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenConfigsAvailable) {
1944 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1946 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1945 1947
1946 // Test if Release() occurs after |kConfigChanged| detected, new configs 1948 // Test if Release() occurs after |kConfigChanged| detected, new configs
1947 // requested of demuxer, and the requested configs arrive before the next 1949 // requested of demuxer, and the requested configs arrive before the next
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 BrowserSeekPlayer(false); 1999 BrowserSeekPlayer(false);
1998 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 2000 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
1999 ReleasePlayer(); 2001 ReleasePlayer();
2000 2002
2001 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 2003 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
2002 EXPECT_FALSE(player_.IsPlaying()); 2004 EXPECT_FALSE(player_.IsPlaying());
2003 EXPECT_FALSE(GetMediaDecoderJob(false)); 2005 EXPECT_FALSE(GetMediaDecoderJob(false));
2004 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 2006 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
2005 2007
2006 // Player should begin prefetch and resume preroll upon Start(). 2008 // Player should begin prefetch and resume preroll upon Start().
2007 EXPECT_EQ(1, demuxer_->num_data_requests()); 2009 EXPECT_EQ(2, demuxer_->num_data_requests());
2008 CreateNextTextureAndSetVideoSurface(); 2010 CreateNextTextureAndSetVideoSurface();
2009 StartVideoDecoderJob(true); 2011 StartVideoDecoderJob(true);
2010 EXPECT_TRUE(IsPrerolling(false)); 2012 EXPECT_TRUE(IsPrerolling(false));
2011 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 2013 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
2012 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 2014 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
2013 2015
2014 // No further seek should have been requested since BrowserSeekPlayer(). 2016 // No further seek should have been requested since BrowserSeekPlayer().
2015 EXPECT_EQ(1, demuxer_->num_seek_requests()); 2017 EXPECT_EQ(1, demuxer_->num_seek_requests());
2016 } 2018 }
2017 2019
2018 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenStart) { 2020 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenStart) {
2019 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 2021 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
2020 2022
2021 // Test that Release() after a browser seek's DemuxerSeek IPC request has been 2023 // Test that Release() after a browser seek's DemuxerSeek IPC request has been
2022 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() does not 2024 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() does not
2023 // occur until after the next Start()+SetVideoSurface(), then the player 2025 // occur until after the next Start()+SetVideoSurface(), then the player
2024 // remains pending seek done until (and resumes correct post-seek preroll 2026 // remains pending seek done until (and resumes correct post-seek preroll
2025 // after) OnDemuxerSeekDone(). 2027 // after) OnDemuxerSeekDone().
2026 BrowserSeekPlayer(false); 2028 BrowserSeekPlayer(false);
2027 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 2029 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
2028 ReleasePlayer(); 2030 ReleasePlayer();
2029 2031
2030 EXPECT_EQ(1, demuxer_->num_data_requests()); 2032 EXPECT_EQ(2, demuxer_->num_data_requests());
2031 CreateNextTextureAndSetVideoSurface(); 2033 CreateNextTextureAndSetVideoSurface();
2032 StartVideoDecoderJob(false); 2034 StartVideoDecoderJob(false);
2033 2035
2034 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 2036 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
2035 EXPECT_TRUE(GetMediaDecoderJob(false)); 2037 EXPECT_TRUE(GetMediaDecoderJob(false));
2036 EXPECT_TRUE(IsPrerolling(false)); 2038 EXPECT_TRUE(IsPrerolling(false));
2037 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 2039 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
2038 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 2040 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
2039 EXPECT_EQ(2, demuxer_->num_data_requests()); 2041 EXPECT_EQ(3, demuxer_->num_data_requests());
2040 2042
2041 // No further seek should have been requested since BrowserSeekPlayer(). 2043 // No further seek should have been requested since BrowserSeekPlayer().
2042 EXPECT_EQ(1, demuxer_->num_seek_requests()); 2044 EXPECT_EQ(1, demuxer_->num_seek_requests());
2043 } 2045 }
2044 2046
2045 // TODO(xhwang): Once we add tests to cover DrmBridge, update this test to 2047 // TODO(xhwang): Once we add tests to cover DrmBridge, update this test to
2046 // also verify that the job is successfully created if SetDrmBridge(), Start() 2048 // also verify that the job is successfully created if SetDrmBridge(), Start()
2047 // and eventually OnMediaCrypto() occur. This would increase test coverage of 2049 // and eventually OnMediaCrypto() occur. This would increase test coverage of
2048 // http://crbug.com/313470 and allow us to remove inspection of internal player 2050 // http://crbug.com/313470 and allow us to remove inspection of internal player
2049 // pending event state. See http://crbug.com/313860. 2051 // pending event state. See http://crbug.com/313860.
2050 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) { 2052 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) {
2051 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 2053 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
2052 2054
2053 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after 2055 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after
2054 // SetVideoSurface() for a player configured for encrypted video, when the 2056 // SetVideoSurface() for a player configured for encrypted video, when the
2055 // player has not yet received media crypto. 2057 // player has not yet received media crypto.
2056 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); 2058 DemuxerConfigs configs = CreateVideoDemuxerConfigs();
2057 configs.is_video_encrypted = true; 2059 configs.is_video_encrypted = true;
2058 2060
2059 player_.OnDemuxerConfigsAvailable(configs); 2061 player_.OnDemuxerConfigsAvailable(configs);
2060 CreateNextTextureAndSetVideoSurface(); 2062 CreateNextTextureAndSetVideoSurface();
2061 EXPECT_FALSE(IsPendingSurfaceChange()); 2063 EXPECT_FALSE(IsPendingSurfaceChange());
2062 EXPECT_FALSE(GetMediaDecoderJob(false)); 2064 EXPECT_FALSE(GetMediaDecoderJob(false));
2063 } 2065 }
2064 2066
2065 } // namespace media 2067 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_source_player.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698