| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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(kNoTimestamp()); |
| 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 Loading... |
| 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 waiting 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 19 matching lines...) Expand all Loading... |
| 1066 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1075 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 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 // Decode data until decoder started requesting new data again. |
| 1077 message_loop_.Run(); | 1086 WaitForAudioDecodeDone(); |
| 1078 } | 1087 } |
| 1079 | 1088 |
| 1080 // The decoder job should finish and a new request will be sent. | 1089 // The decoder job should finish and a new request will be sent. |
| 1081 EXPECT_EQ(5, demuxer_->num_data_requests()); | 1090 EXPECT_EQ(5, demuxer_->num_data_requests()); |
| 1082 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 1091 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 1083 base::TimeTicks previous = StartTimeTicks(); | 1092 base::TimeTicks previous = StartTimeTicks(); |
| 1084 | 1093 |
| 1085 // Let the decoder timeout and execute the OnDecoderStarved() callback. | 1094 // Let the decoder starve. |
| 1086 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 1095 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)); | 1096 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); |
| 1095 WaitForAudioDecodeDone(); | 1097 WaitForAudioDecodeDone(); |
| 1096 | 1098 |
| 1097 // Verify the start time ticks is cleared at this point because the | 1099 // Verify the start time ticks is cleared at this point because the |
| 1098 // player is prefetching. | 1100 // player is prefetching. |
| 1099 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks()); | 1101 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks()); |
| 1100 | 1102 |
| 1101 // Send new data to the decoder so it can finish prefetching. This should | 1103 // Send new data to the decoder so it can finish prefetching. This should |
| 1102 // reset the start time ticks. | 1104 // reset the start time ticks. |
| 1103 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); | 1105 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); |
| 1104 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); | 1106 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); |
| 1105 | 1107 |
| 1106 base::TimeTicks current = StartTimeTicks(); | 1108 base::TimeTicks current = StartTimeTicks(); |
| 1107 EXPECT_LE(100.0, (current - previous).InMillisecondsF()); | 1109 EXPECT_LE(0, (current - previous).InMillisecondsF()); |
| 1108 } | 1110 } |
| 1109 | 1111 |
| 1110 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) { | 1112 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) { |
| 1111 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1113 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1112 | 1114 |
| 1113 // Test MediaSourcePlayer can replay video after input EOS is reached. | 1115 // Test MediaSourcePlayer can replay video after input EOS is reached. |
| 1114 CreateNextTextureAndSetVideoSurface(); | 1116 CreateNextTextureAndSetVideoSurface(); |
| 1115 StartVideoDecoderJob(true); | 1117 StartVideoDecoderJob(true); |
| 1116 | 1118 |
| 1117 // Send the first input chunk. | 1119 // Send the first input chunk. |
| 1118 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 1120 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 1119 message_loop_.Run(); | 1121 WaitForVideoDecodeDone(); |
| 1120 | 1122 |
| 1121 VerifyPlaybackCompletesOnEOSDecode(true, false); | 1123 VerifyPlaybackCompletesOnEOSDecode(true, false); |
| 1122 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true); | 1124 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true); |
| 1123 } | 1125 } |
| 1124 | 1126 |
| 1125 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) { | 1127 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) { |
| 1126 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1128 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1127 | 1129 |
| 1128 // Test decode of audio EOS buffer without any prior decode. See also | 1130 // Test decode of audio EOS buffer without any prior decode. See also |
| 1129 // http://b/11696552. | 1131 // http://b/11696552. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 // and responding to that prefetch with EOS completes A/V playback, even if | 1225 // and responding to that prefetch with EOS completes A/V playback, even if |
| 1224 // another starvation occurs during the latter EOS's decode. | 1226 // another starvation occurs during the latter EOS's decode. |
| 1225 CreateNextTextureAndSetVideoSurface(); | 1227 CreateNextTextureAndSetVideoSurface(); |
| 1226 Start(CreateAudioVideoDemuxerConfigs(), true); | 1228 Start(CreateAudioVideoDemuxerConfigs(), true); |
| 1227 | 1229 |
| 1228 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | 1230 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
| 1229 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS | 1231 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS |
| 1230 | 1232 |
| 1231 // Wait until video EOS is processed and more data (assumed to be audio) is | 1233 // Wait until video EOS is processed and more data (assumed to be audio) is |
| 1232 // requested. | 1234 // requested. |
| 1233 while (demuxer_->num_data_requests() < 3) | 1235 WaitForAudioVideoDecodeDone(); |
| 1234 message_loop_.RunUntilIdle(); | |
| 1235 WaitForVideoDecodeDone(); | |
| 1236 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1236 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1237 | 1237 |
| 1238 // Simulate decoder underrun to trigger prefetch while still decoding audio. | 1238 // Simulate decoder underrun to trigger prefetch while still decoding audio. |
| 1239 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(1)); | 1239 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(1)); |
| 1240 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding() && | 1240 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding() && |
| 1241 !GetMediaDecoderJob(false)->is_decoding()); | 1241 !GetMediaDecoderJob(false)->is_decoding()); |
| 1242 TriggerPlayerStarvation(); | 1242 TriggerPlayerStarvation(); |
| 1243 | 1243 |
| 1244 // Complete the audio decode that was in progress when simulated player | 1244 // Complete the audio decode that was in progress when simulated player |
| 1245 // starvation was triggered. | 1245 // starvation was triggered. |
| 1246 WaitForAudioDecodeDone(); | 1246 WaitForAudioDecodeDone(); |
| 1247 EXPECT_EQ(4, demuxer_->num_data_requests()); | 1247 EXPECT_EQ(4, demuxer_->num_data_requests()); |
| 1248 | |
| 1249 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS | 1248 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS |
| 1250 EXPECT_FALSE(GetMediaDecoderJob(false)->is_decoding()); | 1249 EXPECT_FALSE(GetMediaDecoderJob(false)->is_decoding()); |
| 1251 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 1250 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 1252 | 1251 |
| 1253 // Simulate another decoder underrun to trigger prefetch while decoding EOS. | 1252 // Simulate another decoder underrun to trigger prefetch while decoding EOS. |
| 1254 TriggerPlayerStarvation(); | 1253 TriggerPlayerStarvation(); |
| 1255 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */); | 1254 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */); |
| 1256 } | 1255 } |
| 1257 | 1256 |
| 1258 TEST_F(MediaSourcePlayerTest, V_StarvationDuringEOSDecode) { | 1257 TEST_F(MediaSourcePlayerTest, V_StarvationDuringEOSDecode) { |
| 1259 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1258 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1260 | 1259 |
| 1261 // Test that video-only playback completes without further data requested when | 1260 // Test that video-only playback completes without further data requested when |
| 1262 // starvation occurs during EOS decode. | 1261 // starvation occurs during EOS decode. |
| 1263 CreateNextTextureAndSetVideoSurface(); | 1262 CreateNextTextureAndSetVideoSurface(); |
| 1264 StartVideoDecoderJob(true); | 1263 StartVideoDecoderJob(true); |
| 1265 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 1264 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 1266 message_loop_.Run(); | 1265 WaitForVideoDecodeDone(); |
| 1267 | 1266 |
| 1268 // Simulate decoder underrun to trigger prefetch while decoding EOS. | 1267 // Simulate decoder underrun to trigger prefetch while decoding EOS. |
| 1269 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS | 1268 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS |
| 1270 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding()); | 1269 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding()); |
| 1271 TriggerPlayerStarvation(); | 1270 TriggerPlayerStarvation(); |
| 1272 VerifyPlaybackCompletesOnEOSDecode(false, false /* ignored */); | 1271 VerifyPlaybackCompletesOnEOSDecode(false, false /* ignored */); |
| 1273 } | 1272 } |
| 1274 | 1273 |
| 1275 TEST_F(MediaSourcePlayerTest, A_StarvationDuringEOSDecode) { | 1274 TEST_F(MediaSourcePlayerTest, A_StarvationDuringEOSDecode) { |
| 1276 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1275 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1277 | 1276 |
| 1278 // Test that audio-only playback completes without further data requested when | 1277 // Test that audio-only playback completes without further data requested when |
| 1279 // starvation occurs during EOS decode. | 1278 // starvation occurs during EOS decode. |
| 1280 StartAudioDecoderJob(true); | 1279 StartAudioDecoderJob(true); |
| 1281 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | 1280 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
| 1282 message_loop_.Run(); | 1281 WaitForAudioDecodeDone(); |
| 1283 | 1282 |
| 1284 // Simulate decoder underrun to trigger prefetch while decoding EOS. | 1283 // Simulate decoder underrun to trigger prefetch while decoding EOS. |
| 1285 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS | 1284 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS |
| 1286 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 1285 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 1287 TriggerPlayerStarvation(); | 1286 TriggerPlayerStarvation(); |
| 1288 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */); | 1287 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */); |
| 1289 } | 1288 } |
| 1290 | 1289 |
| 1291 TEST_F(MediaSourcePlayerTest, AV_SeekDuringEOSDecodePreventsCompletion) { | 1290 TEST_F(MediaSourcePlayerTest, AV_SeekDuringEOSDecodePreventsCompletion) { |
| 1292 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1291 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 | 1381 |
| 1383 // Simulate browser seek is done. Confirm player requests the regular seek, | 1382 // Simulate browser seek is done. Confirm player requests the regular seek, |
| 1384 // still has no video decoder job configured, and has not requested any | 1383 // still has no video decoder job configured, and has not requested any |
| 1385 // further data since the surface change event became pending in | 1384 // further data since the surface change event became pending in |
| 1386 // BrowserSeekPlayer(). | 1385 // BrowserSeekPlayer(). |
| 1387 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1386 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1388 player_.OnDemuxerSeekDone(base::TimeDelta()); | 1387 player_.OnDemuxerSeekDone(base::TimeDelta()); |
| 1389 EXPECT_FALSE(GetMediaDecoderJob(false)); | 1388 EXPECT_FALSE(GetMediaDecoderJob(false)); |
| 1390 EXPECT_EQ(2, demuxer_->num_seek_requests()); | 1389 EXPECT_EQ(2, demuxer_->num_seek_requests()); |
| 1391 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); | 1390 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); |
| 1392 EXPECT_EQ(1, demuxer_->num_data_requests()); | |
| 1393 | 1391 |
| 1394 // Simulate regular seek is done and confirm player requests more data for | 1392 // Simulate regular seek is done and confirm player requests more data for |
| 1395 // new video decoder job. | 1393 // new video decoder job. |
| 1396 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1394 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1397 EXPECT_TRUE(GetMediaDecoderJob(false)); | 1395 EXPECT_TRUE(GetMediaDecoderJob(false)); |
| 1398 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1396 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1399 EXPECT_EQ(2, demuxer_->num_seek_requests()); | 1397 EXPECT_EQ(2, demuxer_->num_seek_requests()); |
| 1400 } | 1398 } |
| 1401 | 1399 |
| 1402 TEST_F(MediaSourcePlayerTest, NoSeekForInitialReleaseAndStart) { | 1400 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) { |
| 1403 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1401 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1404 | 1402 |
| 1405 // Test that no seek is requested if player Release() + Start() occurs prior | 1403 // Test that browser seek is requested if player Release() + Start() occurs |
| 1406 // to receiving any data. | 1404 // prior to receiving any data. |
| 1407 CreateNextTextureAndSetVideoSurface(); | 1405 CreateNextTextureAndSetVideoSurface(); |
| 1408 StartVideoDecoderJob(true); | 1406 StartVideoDecoderJob(true); |
| 1409 ReleasePlayer(); | 1407 ReleasePlayer(); |
| 1410 | 1408 |
| 1411 // Pass a new non-empty surface. | 1409 // Pass a new non-empty surface. |
| 1412 CreateNextTextureAndSetVideoSurface(); | 1410 CreateNextTextureAndSetVideoSurface(); |
| 1413 | 1411 |
| 1414 player_.Start(); | 1412 player_.Start(); |
| 1415 | 1413 |
| 1416 // TODO(wolenetz/qinmin): Multiple in-flight data requests for same stream | 1414 // The new player won't be created until the pending data request is |
| 1417 // should be prevented. See http://crbug.com/306314. | 1415 // processed. |
| 1418 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1416 EXPECT_EQ(1, demuxer_->num_data_requests()); |
| 1419 EXPECT_TRUE(GetMediaDecoderJob(false)); | 1417 EXPECT_FALSE(GetMediaDecoderJob(false)); |
| 1420 | 1418 |
| 1421 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 1419 // A browser seek should be requested. |
| 1420 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 1421 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); |
| 1422 EXPECT_EQ(1, demuxer_->num_data_requests()); |
| 1422 } | 1423 } |
| 1423 | 1424 |
| 1424 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) { | 1425 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) { |
| 1425 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1426 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1426 | 1427 |
| 1427 // Test that one browser seek is requested if player Release() + Start(), with | 1428 // Test that one browser seek is requested if player Release() + Start(), with |
| 1428 // video data received between Release() and Start(). | 1429 // video data received between Release() and Start(). |
| 1429 BrowserSeekPlayer(true); | 1430 BrowserSeekPlayer(true); |
| 1430 EXPECT_EQ(1, demuxer_->num_data_requests()); | |
| 1431 | 1431 |
| 1432 // Simulate browser seek is done and confirm player requests more data. | 1432 // Simulate browser seek is done and confirm player requests more data. |
| 1433 player_.OnDemuxerSeekDone(base::TimeDelta()); | 1433 player_.OnDemuxerSeekDone(base::TimeDelta()); |
| 1434 EXPECT_TRUE(GetMediaDecoderJob(false)); | 1434 EXPECT_TRUE(GetMediaDecoderJob(false)); |
| 1435 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1435 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1436 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1436 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1437 } | 1437 } |
| 1438 | 1438 |
| 1439 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { | 1439 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { |
| 1440 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1440 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1467 // Test decoder job will begin prerolling upon seek, when it was not | 1467 // Test decoder job will begin prerolling upon seek, when it was not |
| 1468 // prerolling prior to the seek. | 1468 // prerolling prior to the seek. |
| 1469 StartAudioDecoderJob(true); | 1469 StartAudioDecoderJob(true); |
| 1470 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); | 1470 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); |
| 1471 EXPECT_TRUE(IsPrerolling(true)); | 1471 EXPECT_TRUE(IsPrerolling(true)); |
| 1472 | 1472 |
| 1473 // Complete the initial preroll by feeding data to the decoder. | 1473 // Complete the initial preroll by feeding data to the decoder. |
| 1474 for (int i = 0; i < 4; ++i) { | 1474 for (int i = 0; i < 4; ++i) { |
| 1475 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); | 1475 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); |
| 1476 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 1476 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 1477 message_loop_.Run(); | 1477 WaitForAudioDecodeDone(); |
| 1478 } | 1478 } |
| 1479 EXPECT_LT(0.0, player_.GetCurrentTime().InMillisecondsF()); | 1479 EXPECT_LT(0.0, player_.GetCurrentTime().InMillisecondsF()); |
| 1480 EXPECT_FALSE(IsPrerolling(true)); | 1480 EXPECT_FALSE(IsPrerolling(true)); |
| 1481 | 1481 |
| 1482 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(500)); | 1482 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(500)); |
| 1483 | 1483 |
| 1484 // Prerolling should have begun again. | 1484 // Prerolling should have begun again. |
| 1485 EXPECT_TRUE(IsPrerolling(true)); | 1485 EXPECT_TRUE(IsPrerolling(true)); |
| 1486 EXPECT_EQ(500.0, GetPrerollTimestamp().InMillisecondsF()); | 1486 EXPECT_EQ(500.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1487 | 1487 |
| 1488 // Send data at and after the seek position. Prerolling should complete. | 1488 // Send data at and after the seek position. Prerolling should complete. |
| 1489 for (int i = 0; i < 4; ++i) { | 1489 for (int i = 0; i < 4; ++i) { |
| 1490 DemuxerData data = CreateReadFromDemuxerAckForAudio(i); | 1490 DemuxerData data = CreateReadFromDemuxerAckForAudio(i); |
| 1491 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds( | 1491 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds( |
| 1492 500 + 30 * (i - 1)); | 1492 500 + 30 * (i - 1)); |
| 1493 player_.OnDemuxerDataAvailable(data); | 1493 player_.OnDemuxerDataAvailable(data); |
| 1494 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 1494 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 1495 message_loop_.Run(); | 1495 WaitForAudioDecodeDone(); |
| 1496 } | 1496 } |
| 1497 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF()); | 1497 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF()); |
| 1498 EXPECT_FALSE(IsPrerolling(true)); | 1498 EXPECT_FALSE(IsPrerolling(true)); |
| 1499 | 1499 |
| 1500 // Throughout this test, we should have not re-created the decoder job, so | 1500 // 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 | 1501 // IsPrerolling() transition from false to true was not due to constructor |
| 1502 // initialization. It was due to BeginPrerolling(). | 1502 // initialization. It was due to BeginPrerolling(). |
| 1503 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); | 1503 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); |
| 1504 } | 1504 } |
| 1505 | 1505 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1529 // TODO(qinmin): Simulation of multiple in-flight data requests (one from | 1529 // TODO(qinmin): Simulation of multiple in-flight data requests (one from |
| 1530 // before Release(), one from after Start()) is not included here, and | 1530 // before Release(), one from after Start()) is not included here, and |
| 1531 // neither is any data enqueued for later decode if it arrives after | 1531 // neither is any data enqueued for later decode if it arrives after |
| 1532 // Release() and before Start(). See http://crbug.com/306314. Assumption | 1532 // Release() and before Start(). See http://crbug.com/306314. Assumption |
| 1533 // for this test, to prevent flakiness until the bug is fixed, is the | 1533 // 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 | 1534 // first request's data arrives before Start(). Though that data is not |
| 1535 // seen by decoder, this assumption allows preroll continuation | 1535 // seen by decoder, this assumption allows preroll continuation |
| 1536 // verification and prevents multiple in-flight data requests. | 1536 // verification and prevents multiple in-flight data requests. |
| 1537 ReleasePlayer(); | 1537 ReleasePlayer(); |
| 1538 player_.OnDemuxerDataAvailable(data); | 1538 player_.OnDemuxerDataAvailable(data); |
| 1539 message_loop_.RunUntilIdle(); | 1539 WaitForAudioDecodeDone(); |
| 1540 EXPECT_FALSE(GetMediaDecoderJob(true)); | 1540 EXPECT_FALSE(GetMediaDecoderJob(true)); |
| 1541 StartAudioDecoderJob(true); | 1541 StartAudioDecoderJob(true); |
| 1542 } else { | 1542 } else { |
| 1543 player_.OnDemuxerDataAvailable(data); | 1543 player_.OnDemuxerDataAvailable(data); |
| 1544 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 1544 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 1545 message_loop_.Run(); | 1545 WaitForAudioDecodeDone(); |
| 1546 } | 1546 } |
| 1547 EXPECT_TRUE(IsPrerolling(true)); | 1547 EXPECT_TRUE(IsPrerolling(true)); |
| 1548 } | 1548 } |
| 1549 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); | 1549 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); |
| 1550 EXPECT_TRUE(IsPrerolling(true)); | 1550 EXPECT_TRUE(IsPrerolling(true)); |
| 1551 | 1551 |
| 1552 // Send data after the seek position. | 1552 // Send data after the seek position. |
| 1553 PrerollDecoderToTime(true, target_timestamp, target_timestamp); | 1553 PrerollDecoderToTime(true, target_timestamp, target_timestamp); |
| 1554 } | 1554 } |
| 1555 | 1555 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 // Test decoder job will preroll the media to the actual seek position | 1663 // Test decoder job will preroll the media to the actual seek position |
| 1664 // resulting from a browser seek. | 1664 // resulting from a browser seek. |
| 1665 BrowserSeekPlayer(false); | 1665 BrowserSeekPlayer(false); |
| 1666 | 1666 |
| 1667 // Simulate browser seek is done, but to a later time than was requested. | 1667 // Simulate browser seek is done, but to a later time than was requested. |
| 1668 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100); | 1668 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100); |
| 1669 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100)); | 1669 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100)); |
| 1670 EXPECT_TRUE(GetMediaDecoderJob(false)); | 1670 EXPECT_TRUE(GetMediaDecoderJob(false)); |
| 1671 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); | 1671 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); |
| 1672 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1672 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1673 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1673 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1674 | 1674 |
| 1675 PrerollDecoderToTime( | 1675 PrerollDecoderToTime( |
| 1676 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); | 1676 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); |
| 1677 } | 1677 } |
| 1678 | 1678 |
| 1679 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) { | 1679 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) { |
| 1680 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1680 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1681 | 1681 |
| 1682 // Test that video config change notification results in request for demuxer | 1682 // Test that video config change notification results in request for demuxer |
| 1683 // configuration, and that a video decoder job results without any browser | 1683 // configuration, and that a video decoder job results without any browser |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1774 // should not cause any crashes. | 1774 // should not cause any crashes. |
| 1775 CreateNextTextureAndSetVideoSurface(); | 1775 CreateNextTextureAndSetVideoSurface(); |
| 1776 StartVideoDecoderJob(true); | 1776 StartVideoDecoderJob(true); |
| 1777 DemuxerData data = CreateReadFromDemuxerAckForVideo(); | 1777 DemuxerData data = CreateReadFromDemuxerAckForVideo(); |
| 1778 player_.OnDemuxerDataAvailable(data); | 1778 player_.OnDemuxerDataAvailable(data); |
| 1779 | 1779 |
| 1780 // Trigger a surface change and decoder starvation. | 1780 // Trigger a surface change and decoder starvation. |
| 1781 CreateNextTextureAndSetVideoSurface(); | 1781 CreateNextTextureAndSetVideoSurface(); |
| 1782 TriggerPlayerStarvation(); | 1782 TriggerPlayerStarvation(); |
| 1783 WaitForVideoDecodeDone(); | 1783 WaitForVideoDecodeDone(); |
| 1784 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); |
| 1784 | 1785 |
| 1785 // Surface change should trigger a seek. | 1786 // Surface change should trigger a seek. |
| 1787 player_.OnDemuxerDataAvailable(data); |
| 1786 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); | 1788 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); |
| 1787 player_.OnDemuxerSeekDone(base::TimeDelta()); | 1789 player_.OnDemuxerSeekDone(base::TimeDelta()); |
| 1788 EXPECT_TRUE(GetMediaDecoderJob(false)); | 1790 EXPECT_TRUE(GetMediaDecoderJob(false)); |
| 1789 | 1791 |
| 1790 // A new data request should be sent. | 1792 // A new data request should be sent. |
| 1791 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1793 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1792 } | 1794 } |
| 1793 | 1795 |
| 1794 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { | 1796 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { |
| 1795 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1797 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1796 | 1798 |
| 1797 // Test if OnPrefetchDone() had already been posted before and is executed | 1799 // Test if OnPrefetchDone() had already been posted before and is executed |
| 1798 // after Release(), then player does not DCHECK. This test is fragile to | 1800 // after Release(), then player does not DCHECK. This test is fragile to |
| 1799 // change to MediaDecoderJob::Prefetch() implementation; it assumes task | 1801 // change to MediaDecoderJob::Prefetch() implementation; it assumes task |
| 1800 // is posted to run |prefetch_cb| if the job already HasData(). | 1802 // is posted to run |prefetch_cb| if the job already HasData(). |
| 1801 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test | 1803 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test |
| 1802 // becomes obsolete. See http://crbug.com/304234. | 1804 // becomes obsolete. See http://crbug.com/304234. |
| 1803 StartAudioDecoderJob(true); | 1805 StartAudioDecoderJob(true); |
| 1804 | 1806 |
| 1805 // Escape the original prefetch by decoding a single access unit. | 1807 // Escape the original prefetch by decoding a single access unit. |
| 1806 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | 1808 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
| 1807 message_loop_.Run(); | 1809 WaitForAudioDecodeDone(); |
| 1808 | 1810 |
| 1809 // Prime the job with a few more access units, so that a later prefetch, | 1811 // Prime the job with a few more access units, so that a later prefetch, |
| 1810 // triggered by starvation to simulate decoder underrun, can trivially | 1812 // triggered by starvation to simulate decoder underrun, can trivially |
| 1811 // post task to run OnPrefetchDone(). | 1813 // post task to run OnPrefetchDone(). |
| 1812 player_.OnDemuxerDataAvailable( | 1814 player_.OnDemuxerDataAvailable( |
| 1813 CreateReadFromDemuxerAckWithConfigChanged(true, 4)); | 1815 CreateReadFromDemuxerAckWithConfigChanged(true, 4)); |
| 1814 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 1816 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 1815 | 1817 |
| 1816 // Simulate decoder underrun, so trivial prefetch starts while still decoding. | 1818 // Simulate decoder underrun, so trivial prefetch starts while still decoding. |
| 1817 // The prefetch and posting of OnPrefetchDone() will not occur until next | 1819 // The prefetch and posting of OnPrefetchDone() will not occur until next |
| 1818 // MediaDecoderCallBack() occurs. | 1820 // MediaDecoderCallBack() occurs. |
| 1819 TriggerPlayerStarvation(); | 1821 TriggerPlayerStarvation(); |
| 1820 | 1822 |
| 1821 // Upon the next successful decode callback, post a task to call Release() on | 1823 // Upon the next successful decode callback, post a task to call Release() on |
| 1822 // the |player_|, such that the trivial OnPrefetchDone() task posting also | 1824 // the |player_|, such that the trivial OnPrefetchDone() task posting also |
| 1823 // occurs and should execute after the Release(). | 1825 // occurs and should execute after the Release(). |
| 1824 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); | 1826 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); |
| 1825 | 1827 |
| 1826 while (GetMediaDecoderJob(true)) | 1828 WaitForAudioDecodeDone(); |
| 1827 message_loop_.RunUntilIdle(); | |
| 1828 EXPECT_TRUE(decoder_callback_hook_executed_); | 1829 EXPECT_TRUE(decoder_callback_hook_executed_); |
| 1829 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1830 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1830 | 1831 |
| 1831 // Player should have no decoder job until after Start(). | 1832 // Player should have no decoder job until after Start(). |
| 1832 StartAudioDecoderJob(true); | 1833 StartAudioDecoderJob(true); |
| 1833 } | 1834 } |
| 1834 | 1835 |
| 1835 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { | 1836 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { |
| 1836 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1837 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1837 | 1838 |
| 1838 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request | 1839 // 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, | 1840 // 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 | 1841 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player |
| 1841 // will resume correct post-seek preroll upon Start(). | 1842 // will resume correct post-seek preroll upon Start(). |
| 1842 StartAudioDecoderJobAndSeekToWhileDecoding( | 1843 StartAudioDecoderJobAndSeekToWhileDecoding( |
| 1843 base::TimeDelta::FromMilliseconds(100)); | 1844 base::TimeDelta::FromMilliseconds(100)); |
| 1844 ReleasePlayer(); | 1845 ReleasePlayer(); |
| 1845 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1846 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1846 | 1847 |
| 1847 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1848 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1848 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1849 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1849 EXPECT_FALSE(GetMediaDecoderJob(true)); | 1850 EXPECT_FALSE(GetMediaDecoderJob(true)); |
| 1850 EXPECT_FALSE(player_.IsPlaying()); | 1851 EXPECT_FALSE(player_.IsPlaying()); |
| 1851 | 1852 |
| 1852 // Player should begin prefetch and resume preroll upon Start(). | 1853 // Player should begin prefetch and resume preroll upon Start(). |
| 1853 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1854 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1854 StartAudioDecoderJob(true); | 1855 StartAudioDecoderJob(true); |
| 1855 EXPECT_TRUE(IsPrerolling(true)); | 1856 EXPECT_TRUE(IsPrerolling(true)); |
| 1856 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1857 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1857 | 1858 |
| 1858 // No further seek should have been requested since Release(), above. | 1859 // No further seek should have been requested since Release(), above. |
| 1859 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1860 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1860 } | 1861 } |
| 1861 | 1862 |
| 1862 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { | 1863 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { |
| 1863 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1864 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1864 | 1865 |
| 1865 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request | 1866 // 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, | 1867 // 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(), | 1868 // test if OnDemuxerSeekDone() does not occur until after the next Start(), |
| 1868 // then the player remains pending seek done until (and resumes correct | 1869 // then the player remains pending seek done until (and resumes correct |
| 1869 // post-seek preroll after) OnDemuxerSeekDone(). | 1870 // post-seek preroll after) OnDemuxerSeekDone(). |
| 1870 StartAudioDecoderJobAndSeekToWhileDecoding( | 1871 StartAudioDecoderJobAndSeekToWhileDecoding( |
| 1871 base::TimeDelta::FromMilliseconds(100)); | 1872 base::TimeDelta::FromMilliseconds(100)); |
| 1872 ReleasePlayer(); | 1873 ReleasePlayer(); |
| 1873 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1874 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1874 | 1875 |
| 1875 // Player should not prefetch upon Start() nor create the decoder job, due to | 1876 // Player should not prefetch upon Start() nor create the decoder job, due to |
| 1876 // awaiting DemuxerSeekDone. | 1877 // awaiting DemuxerSeekDone. |
| 1877 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1878 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1878 StartAudioDecoderJob(false); | 1879 StartAudioDecoderJob(false); |
| 1879 | 1880 |
| 1880 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1881 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1881 EXPECT_TRUE(GetMediaDecoderJob(true)); | 1882 EXPECT_TRUE(GetMediaDecoderJob(true)); |
| 1882 EXPECT_TRUE(IsPrerolling(true)); | 1883 EXPECT_TRUE(IsPrerolling(true)); |
| 1883 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1884 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1884 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1885 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1885 | 1886 |
| 1886 // No further seek should have been requested since Release(), above. | 1887 // No further seek should have been requested since Release(), above. |
| 1887 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1888 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1888 } | 1889 } |
| 1889 | 1890 |
| 1890 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) { | 1891 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) { |
| 1891 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1892 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1892 | 1893 |
| 1893 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC | 1894 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC |
| 1894 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the | 1895 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the |
| 1895 // player will resume correct post-seek preroll upon Start(). | 1896 // player will resume correct post-seek preroll upon Start(). |
| 1896 StartAudioDecoderJobAndSeekToWhileDecoding( | 1897 StartAudioDecoderJobAndSeekToWhileDecoding( |
| 1897 base::TimeDelta::FromMilliseconds(100)); | 1898 base::TimeDelta::FromMilliseconds(100)); |
| 1898 WaitForAudioDecodeDone(); | 1899 WaitForAudioDecodeDone(); |
| 1899 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1900 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1900 | 1901 |
| 1901 ReleasePlayer(); | 1902 ReleasePlayer(); |
| 1902 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1903 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1903 EXPECT_FALSE(player_.IsPlaying()); | 1904 EXPECT_FALSE(player_.IsPlaying()); |
| 1904 EXPECT_FALSE(GetMediaDecoderJob(true)); | 1905 EXPECT_FALSE(GetMediaDecoderJob(true)); |
| 1905 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1906 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1906 | 1907 |
| 1907 // Player should begin prefetch and resume preroll upon Start(). | 1908 // Player should begin prefetch and resume preroll upon Start(). |
| 1908 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1909 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1909 StartAudioDecoderJob(true); | 1910 StartAudioDecoderJob(true); |
| 1910 EXPECT_TRUE(IsPrerolling(true)); | 1911 EXPECT_TRUE(IsPrerolling(true)); |
| 1911 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1912 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1912 | 1913 |
| 1913 // No further seek should have been requested since before Release(), above. | 1914 // No further seek should have been requested since before Release(), above. |
| 1914 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1915 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1915 } | 1916 } |
| 1916 | 1917 |
| 1917 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { | 1918 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { |
| 1918 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1919 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1919 | 1920 |
| 1920 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC | 1921 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC |
| 1921 // request and OnDemuxerSeekDone() does not occur until after the next | 1922 // request and OnDemuxerSeekDone() does not occur until after the next |
| 1922 // Start(), then the player remains pending seek done until (and resumes | 1923 // Start(), then the player remains pending seek done until (and resumes |
| 1923 // correct post-seek preroll after) OnDemuxerSeekDone(). | 1924 // correct post-seek preroll after) OnDemuxerSeekDone(). |
| 1924 StartAudioDecoderJobAndSeekToWhileDecoding( | 1925 StartAudioDecoderJobAndSeekToWhileDecoding( |
| 1925 base::TimeDelta::FromMilliseconds(100)); | 1926 base::TimeDelta::FromMilliseconds(100)); |
| 1926 WaitForAudioDecodeDone(); | 1927 WaitForAudioDecodeDone(); |
| 1927 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1928 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1928 | 1929 |
| 1929 ReleasePlayer(); | 1930 ReleasePlayer(); |
| 1930 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1931 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1931 StartAudioDecoderJob(false); | 1932 StartAudioDecoderJob(false); |
| 1932 | 1933 |
| 1933 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1934 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1934 EXPECT_TRUE(GetMediaDecoderJob(true)); | 1935 EXPECT_TRUE(GetMediaDecoderJob(true)); |
| 1935 EXPECT_TRUE(IsPrerolling(true)); | 1936 EXPECT_TRUE(IsPrerolling(true)); |
| 1936 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1937 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1937 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1938 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1938 | 1939 |
| 1939 // No further seek should have been requested since before Release(), above. | 1940 // No further seek should have been requested since before Release(), above. |
| 1940 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1941 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1941 } | 1942 } |
| 1942 | 1943 |
| 1943 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenConfigsAvailable) { | 1944 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenConfigsAvailable) { |
| 1944 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1945 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1945 | 1946 |
| 1946 // Test if Release() occurs after |kConfigChanged| detected, new configs | 1947 // Test if Release() occurs after |kConfigChanged| detected, new configs |
| 1947 // requested of demuxer, and the requested configs arrive before the next | 1948 // requested of demuxer, and the requested configs arrive before the next |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 BrowserSeekPlayer(false); | 1998 BrowserSeekPlayer(false); |
| 1998 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); | 1999 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); |
| 1999 ReleasePlayer(); | 2000 ReleasePlayer(); |
| 2000 | 2001 |
| 2001 player_.OnDemuxerSeekDone(expected_preroll_timestamp); | 2002 player_.OnDemuxerSeekDone(expected_preroll_timestamp); |
| 2002 EXPECT_FALSE(player_.IsPlaying()); | 2003 EXPECT_FALSE(player_.IsPlaying()); |
| 2003 EXPECT_FALSE(GetMediaDecoderJob(false)); | 2004 EXPECT_FALSE(GetMediaDecoderJob(false)); |
| 2004 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); | 2005 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); |
| 2005 | 2006 |
| 2006 // Player should begin prefetch and resume preroll upon Start(). | 2007 // Player should begin prefetch and resume preroll upon Start(). |
| 2007 EXPECT_EQ(1, demuxer_->num_data_requests()); | 2008 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 2008 CreateNextTextureAndSetVideoSurface(); | 2009 CreateNextTextureAndSetVideoSurface(); |
| 2009 StartVideoDecoderJob(true); | 2010 StartVideoDecoderJob(true); |
| 2010 EXPECT_TRUE(IsPrerolling(false)); | 2011 EXPECT_TRUE(IsPrerolling(false)); |
| 2011 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); | 2012 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); |
| 2012 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); | 2013 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); |
| 2013 | 2014 |
| 2014 // No further seek should have been requested since BrowserSeekPlayer(). | 2015 // No further seek should have been requested since BrowserSeekPlayer(). |
| 2015 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 2016 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 2016 } | 2017 } |
| 2017 | 2018 |
| 2018 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenStart) { | 2019 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenStart) { |
| 2019 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 2020 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2020 | 2021 |
| 2021 // Test that Release() after a browser seek's DemuxerSeek IPC request has been | 2022 // 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 | 2023 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() does not |
| 2023 // occur until after the next Start()+SetVideoSurface(), then the player | 2024 // occur until after the next Start()+SetVideoSurface(), then the player |
| 2024 // remains pending seek done until (and resumes correct post-seek preroll | 2025 // remains pending seek done until (and resumes correct post-seek preroll |
| 2025 // after) OnDemuxerSeekDone(). | 2026 // after) OnDemuxerSeekDone(). |
| 2026 BrowserSeekPlayer(false); | 2027 BrowserSeekPlayer(false); |
| 2027 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); | 2028 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); |
| 2028 ReleasePlayer(); | 2029 ReleasePlayer(); |
| 2029 | 2030 |
| 2030 EXPECT_EQ(1, demuxer_->num_data_requests()); | 2031 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 2031 CreateNextTextureAndSetVideoSurface(); | 2032 CreateNextTextureAndSetVideoSurface(); |
| 2032 StartVideoDecoderJob(false); | 2033 StartVideoDecoderJob(false); |
| 2033 | 2034 |
| 2034 player_.OnDemuxerSeekDone(expected_preroll_timestamp); | 2035 player_.OnDemuxerSeekDone(expected_preroll_timestamp); |
| 2035 EXPECT_TRUE(GetMediaDecoderJob(false)); | 2036 EXPECT_TRUE(GetMediaDecoderJob(false)); |
| 2036 EXPECT_TRUE(IsPrerolling(false)); | 2037 EXPECT_TRUE(IsPrerolling(false)); |
| 2037 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); | 2038 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); |
| 2038 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); | 2039 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); |
| 2039 EXPECT_EQ(2, demuxer_->num_data_requests()); | 2040 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 2040 | 2041 |
| 2041 // No further seek should have been requested since BrowserSeekPlayer(). | 2042 // No further seek should have been requested since BrowserSeekPlayer(). |
| 2042 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 2043 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 2043 } | 2044 } |
| 2044 | 2045 |
| 2045 // TODO(xhwang): Once we add tests to cover DrmBridge, update this test to | 2046 // 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() | 2047 // also verify that the job is successfully created if SetDrmBridge(), Start() |
| 2047 // and eventually OnMediaCrypto() occur. This would increase test coverage of | 2048 // and eventually OnMediaCrypto() occur. This would increase test coverage of |
| 2048 // http://crbug.com/313470 and allow us to remove inspection of internal player | 2049 // http://crbug.com/313470 and allow us to remove inspection of internal player |
| 2049 // pending event state. See http://crbug.com/313860. | 2050 // pending event state. See http://crbug.com/313860. |
| 2050 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) { | 2051 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) { |
| 2051 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 2052 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2052 | 2053 |
| 2053 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after | 2054 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after |
| 2054 // SetVideoSurface() for a player configured for encrypted video, when the | 2055 // SetVideoSurface() for a player configured for encrypted video, when the |
| 2055 // player has not yet received media crypto. | 2056 // player has not yet received media crypto. |
| 2056 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); | 2057 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); |
| 2057 configs.is_video_encrypted = true; | 2058 configs.is_video_encrypted = true; |
| 2058 | 2059 |
| 2059 player_.OnDemuxerConfigsAvailable(configs); | 2060 player_.OnDemuxerConfigsAvailable(configs); |
| 2060 CreateNextTextureAndSetVideoSurface(); | 2061 CreateNextTextureAndSetVideoSurface(); |
| 2061 EXPECT_FALSE(IsPendingSurfaceChange()); | 2062 EXPECT_FALSE(IsPendingSurfaceChange()); |
| 2062 EXPECT_FALSE(GetMediaDecoderJob(false)); | 2063 EXPECT_FALSE(GetMediaDecoderJob(false)); |
| 2063 } | 2064 } |
| 2064 | 2065 |
| 2065 } // namespace media | 2066 } // namespace media |
| OLD | NEW |