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

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

Issue 257323003: Remove the IPC to request DemuxerConfigs when config changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adding CHECK to enforce the optional demuxer_configs only has 0 or 1 element Created 6 years, 7 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager); 129 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager);
130 }; 130 };
131 131
132 class MockDemuxerAndroid : public DemuxerAndroid { 132 class MockDemuxerAndroid : public DemuxerAndroid {
133 public: 133 public:
134 explicit MockDemuxerAndroid(base::MessageLoop* message_loop) 134 explicit MockDemuxerAndroid(base::MessageLoop* message_loop)
135 : message_loop_(message_loop), 135 : message_loop_(message_loop),
136 num_data_requests_(0), 136 num_data_requests_(0),
137 num_seek_requests_(0), 137 num_seek_requests_(0),
138 num_browser_seek_requests_(0), 138 num_browser_seek_requests_(0) {}
139 num_config_requests_(0) {}
140 virtual ~MockDemuxerAndroid() {} 139 virtual ~MockDemuxerAndroid() {}
141 140
142 virtual void Initialize(DemuxerAndroidClient* client) OVERRIDE {} 141 virtual void Initialize(DemuxerAndroidClient* client) OVERRIDE {}
143 virtual void RequestDemuxerConfigs() OVERRIDE {
144 num_config_requests_++;
145 }
146 virtual void RequestDemuxerData(DemuxerStream::Type type) OVERRIDE { 142 virtual void RequestDemuxerData(DemuxerStream::Type type) OVERRIDE {
147 num_data_requests_++; 143 num_data_requests_++;
148 if (message_loop_->is_running()) 144 if (message_loop_->is_running())
149 message_loop_->Quit(); 145 message_loop_->Quit();
150 } 146 }
151 virtual void RequestDemuxerSeek(const base::TimeDelta& time_to_seek, 147 virtual void RequestDemuxerSeek(const base::TimeDelta& time_to_seek,
152 bool is_browser_seek) OVERRIDE { 148 bool is_browser_seek) OVERRIDE {
153 num_seek_requests_++; 149 num_seek_requests_++;
154 if (is_browser_seek) 150 if (is_browser_seek)
155 num_browser_seek_requests_++; 151 num_browser_seek_requests_++;
156 } 152 }
157 153
158 int num_data_requests() const { return num_data_requests_; } 154 int num_data_requests() const { return num_data_requests_; }
159 int num_seek_requests() const { return num_seek_requests_; } 155 int num_seek_requests() const { return num_seek_requests_; }
160 int num_browser_seek_requests() const { return num_browser_seek_requests_; } 156 int num_browser_seek_requests() const { return num_browser_seek_requests_; }
161 int num_config_requests() const { return num_config_requests_; }
162 157
163 private: 158 private:
164 base::MessageLoop* message_loop_; 159 base::MessageLoop* message_loop_;
165 160
166 // The number of encoded data requests this object has seen. 161 // The number of encoded data requests this object has seen.
167 int num_data_requests_; 162 int num_data_requests_;
168 163
169 // The number of regular and browser seek requests this object has seen. 164 // The number of regular and browser seek requests this object has seen.
170 int num_seek_requests_; 165 int num_seek_requests_;
171 166
172 // The number of browser seek requests this object has seen. 167 // The number of browser seek requests this object has seen.
173 int num_browser_seek_requests_; 168 int num_browser_seek_requests_;
174 169
175 // The number of demuxer config requests this object has seen.
176 int num_config_requests_;
177
178 DISALLOW_COPY_AND_ASSIGN(MockDemuxerAndroid); 170 DISALLOW_COPY_AND_ASSIGN(MockDemuxerAndroid);
179 }; 171 };
180 172
181 class MediaSourcePlayerTest : public testing::Test { 173 class MediaSourcePlayerTest : public testing::Test {
182 public: 174 public:
183 MediaSourcePlayerTest() 175 MediaSourcePlayerTest()
184 : manager_(&message_loop_), 176 : manager_(&message_loop_),
185 demuxer_(new MockDemuxerAndroid(&message_loop_)), 177 demuxer_(new MockDemuxerAndroid(&message_loop_)),
186 player_(0, &manager_, 178 player_(0, &manager_,
187 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested, 179 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 302
311 if (have_audio && !have_video) 303 if (have_audio && !have_video)
312 return CreateAudioDemuxerConfigs(kCodecVorbis); 304 return CreateAudioDemuxerConfigs(kCodecVorbis);
313 305
314 if (have_video && !have_audio) 306 if (have_video && !have_audio)
315 return CreateVideoDemuxerConfigs(); 307 return CreateVideoDemuxerConfigs();
316 308
317 return CreateAudioVideoDemuxerConfigs(); 309 return CreateAudioVideoDemuxerConfigs();
318 } 310 }
319 311
320 // Starts an audio decoder job. Verifies player behavior relative to 312 // Starts an audio decoder job.
321 // |expect_player_requests_data|. 313 void StartAudioDecoderJob() {
322 void StartAudioDecoderJob(bool expect_player_requests_data) { 314 Start(CreateAudioDemuxerConfigs(kCodecVorbis));
323 Start(CreateAudioDemuxerConfigs(kCodecVorbis), expect_player_requests_data);
324 } 315 }
325 316
326 // Starts a video decoder job. Verifies player behavior relative to 317 // Starts a video decoder job.
327 // |expect_player_requests_data|. 318 void StartVideoDecoderJob() {
328 void StartVideoDecoderJob(bool expect_player_requests_data) { 319 Start(CreateVideoDemuxerConfigs());
329 Start(CreateVideoDemuxerConfigs(), expect_player_requests_data);
330 } 320 }
331 321
332 // Starts decoding the data. Verifies player behavior relative to 322 // Starts decoding the data.
333 // |expect_player_requests_data|. 323 void Start(const DemuxerConfigs& configs) {
334 void Start(const DemuxerConfigs& configs, bool expect_player_requests_data) { 324 EXPECT_EQ(demuxer_->num_data_requests(), 0);
335 bool has_audio = configs.audio_codec != kUnknownAudioCodec; 325 player_.OnDemuxerConfigsAvailable(configs);
336 bool has_video = configs.video_codec != kUnknownVideoCodec; 326 player_.Start();
327
328 EXPECT_TRUE(player_.IsPlaying());
329 int expected_num_requests = (GetMediaDecoderJob(true) ? 1 : 0) +
330 (GetMediaDecoderJob(false) ? 1 : 0);
331 EXPECT_EQ(expected_num_requests, demuxer_->num_data_requests());
332 }
333
334 // Resumes decoding the data. Verifies player behavior relative to
335 // |expect_player_requests_audio_data| and
336 // |expect_player_requests_video_data|.
337 void Resume(bool expect_player_requests_audio_data,
338 bool expect_player_requests_video_data) {
339 EXPECT_FALSE(player_.IsPlaying());
340 EXPECT_TRUE(player_.HasVideo() || player_.HasAudio());
337 int original_num_data_requests = demuxer_->num_data_requests(); 341 int original_num_data_requests = demuxer_->num_data_requests();
338 int expected_request_delta = expect_player_requests_data ? 342 int expected_request_delta =
339 ((has_audio ? 1 : 0) + (has_video ? 1 : 0)) : 0; 343 (expect_player_requests_audio_data ? 1 : 0) +
344 (expect_player_requests_video_data ? 1 : 0);
340 345
341 player_.OnDemuxerConfigsAvailable(configs);
342 player_.Start(); 346 player_.Start();
343 347
344 EXPECT_TRUE(player_.IsPlaying()); 348 EXPECT_TRUE(player_.IsPlaying());
345 EXPECT_EQ(original_num_data_requests + expected_request_delta, 349 EXPECT_EQ(original_num_data_requests + expected_request_delta,
346 demuxer_->num_data_requests()); 350 demuxer_->num_data_requests());
347 351 EXPECT_EQ(expect_player_requests_audio_data,
348 // Verify player has decoder job iff the config included the media type for 352 expect_player_requests_audio_data && GetMediaDecoderJob(true));
349 // the job and the player is expected to request data due to Start(), above. 353 EXPECT_EQ(expect_player_requests_video_data,
350 EXPECT_EQ(expect_player_requests_data && has_audio, 354 expect_player_requests_video_data && GetMediaDecoderJob(false));
351 GetMediaDecoderJob(true) != NULL);
352 EXPECT_EQ(expect_player_requests_data && has_video,
353 GetMediaDecoderJob(false) != NULL);
354 } 355 }
355 356
356 // Keeps decoding audio data until the decoder starts to output samples. 357 // Keeps decoding audio data until the decoder starts to output samples.
357 // Gives up if no audio output after decoding 10 frames. 358 // Gives up if no audio output after decoding 10 frames.
358 void DecodeAudioDataUntilOutputBecomesAvailable() { 359 void DecodeAudioDataUntilOutputBecomesAvailable() {
359 EXPECT_TRUE(player_.IsPlaying()); 360 EXPECT_TRUE(player_.IsPlaying());
360 base::TimeDelta current_time = player_.GetCurrentTime(); 361 base::TimeDelta current_time = player_.GetCurrentTime();
361 base::TimeDelta start_timestamp = current_time; 362 base::TimeDelta start_timestamp = current_time;
362 for (int i = 0; i < 10; ++i) { 363 for (int i = 0; i < 10; ++i) {
363 manager_.ResetTimestampUpdated(); 364 manager_.ResetTimestampUpdated();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // the player should not yet have sent the DemuxerSeek IPC request, though 437 // the player should not yet have sent the DemuxerSeek IPC request, though
437 // seek event should be pending. The audio decoder job will also still be 438 // seek event should be pending. The audio decoder job will also still be
438 // decoding. 439 // decoding.
439 void StartAudioDecoderJobAndSeekToWhileDecoding( 440 void StartAudioDecoderJobAndSeekToWhileDecoding(
440 const base::TimeDelta& seek_time) { 441 const base::TimeDelta& seek_time) {
441 EXPECT_FALSE(GetMediaDecoderJob(true)); 442 EXPECT_FALSE(GetMediaDecoderJob(true));
442 EXPECT_FALSE(player_.IsPlaying()); 443 EXPECT_FALSE(player_.IsPlaying());
443 EXPECT_EQ(0, demuxer_->num_data_requests()); 444 EXPECT_EQ(0, demuxer_->num_data_requests());
444 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); 445 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF());
445 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp()); 446 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp());
446 StartAudioDecoderJob(true); 447 StartAudioDecoderJob();
447 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 448 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
448 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 449 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
449 EXPECT_EQ(2, demuxer_->num_data_requests()); 450 EXPECT_EQ(2, demuxer_->num_data_requests());
450 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 451 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
451 player_.SeekTo(seek_time); 452 player_.SeekTo(seek_time);
452 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); 453 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF());
453 EXPECT_EQ(0, demuxer_->num_seek_requests()); 454 EXPECT_EQ(0, demuxer_->num_seek_requests());
454 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 455 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
455 } 456 }
456 457
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 DemuxerData CreateReadFromDemuxerAckWithConfigChanged(bool is_audio, 523 DemuxerData CreateReadFromDemuxerAckWithConfigChanged(bool is_audio,
523 int config_unit_index) { 524 int config_unit_index) {
524 DemuxerData data; 525 DemuxerData data;
525 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO; 526 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO;
526 data.access_units.resize(config_unit_index + 1); 527 data.access_units.resize(config_unit_index + 1);
527 528
528 for (int i = 0; i < config_unit_index; ++i) 529 for (int i = 0; i < config_unit_index; ++i)
529 data.access_units[i] = CreateAccessUnitWithData(is_audio, i); 530 data.access_units[i] = CreateAccessUnitWithData(is_audio, i);
530 531
531 data.access_units[config_unit_index].status = DemuxerStream::kConfigChanged; 532 data.access_units[config_unit_index].status = DemuxerStream::kConfigChanged;
533 data.demuxer_configs.resize(1);
534 data.demuxer_configs[0] = CreateDemuxerConfigs(is_audio, !is_audio);
532 return data; 535 return data;
533 } 536 }
534 537
535 // Valid only for video-only player tests. If |trigger_with_release_start| is 538 // Valid only for video-only player tests. If |trigger_with_release_start| is
536 // true, triggers the browser seek with a Release() + video data received + 539 // true, triggers the browser seek with a Release() + video data received +
537 // Start() with a new surface. If false, triggers the browser seek by 540 // Start() with a new surface. If false, triggers the browser seek by
538 // setting a new video surface after beginning decode of received video data. 541 // setting a new video surface after beginning decode of received video data.
539 // Such data receipt causes possibility that an I-frame is not next, and 542 // Such data receipt causes possibility that an I-frame is not next, and
540 // browser seek results once decode completes and surface change processing 543 // browser seek results once decode completes and surface change processing
541 // begins. 544 // begins.
542 void BrowserSeekPlayer(bool trigger_with_release_start) { 545 void BrowserSeekPlayer(bool trigger_with_release_start) {
543 int expected_num_data_requests = demuxer_->num_data_requests() + 546 int expected_num_data_requests = demuxer_->num_data_requests() +
544 (trigger_with_release_start ? 1 : 2); 547 (trigger_with_release_start ? 1 : 2);
545 int expected_num_seek_requests = demuxer_->num_seek_requests(); 548 int expected_num_seek_requests = demuxer_->num_seek_requests();
546 int expected_num_browser_seek_requests = 549 int expected_num_browser_seek_requests =
547 demuxer_->num_browser_seek_requests(); 550 demuxer_->num_browser_seek_requests();
548 551
549 EXPECT_FALSE(GetMediaDecoderJob(false)); 552 EXPECT_FALSE(GetMediaDecoderJob(false));
550 CreateNextTextureAndSetVideoSurface(); 553 CreateNextTextureAndSetVideoSurface();
551 StartVideoDecoderJob(true); 554 StartVideoDecoderJob();
552
553 if (trigger_with_release_start) { 555 if (trigger_with_release_start) {
554 ReleasePlayer(); 556 ReleasePlayer();
555
556 // Simulate demuxer's response to the video data request. The data will be 557 // Simulate demuxer's response to the video data request. The data will be
557 // discarded. 558 // discarded.
558 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 559 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
559 EXPECT_FALSE(GetMediaDecoderJob(false)); 560 EXPECT_FALSE(GetMediaDecoderJob(false));
560 EXPECT_FALSE(player_.IsPlaying()); 561 EXPECT_FALSE(player_.IsPlaying());
561 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 562 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
562 563
563 CreateNextTextureAndSetVideoSurface(); 564 CreateNextTextureAndSetVideoSurface();
564 StartVideoDecoderJob(false); 565 Resume(false, false);
565 EXPECT_FALSE(GetMediaDecoderJob(false)); 566 EXPECT_FALSE(GetMediaDecoderJob(false));
566 } else { 567 } else {
567 // Simulate demuxer's response to the video data request. 568 // Simulate demuxer's response to the video data request.
568 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 569 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
569 570
570 // While the decoder is decoding, trigger a browser seek by changing 571 // While the decoder is decoding, trigger a browser seek by changing
571 // surface. Demuxer does not know of browser seek in advance, so no 572 // surface. Demuxer does not know of browser seek in advance, so no
572 // |kAborted| data is required (though |kAborted| can certainly occur for 573 // |kAborted| data is required (though |kAborted| can certainly occur for
573 // any pending read in reality due to renderer preparing for a regular 574 // any pending read in reality due to renderer preparing for a regular
574 // seek). 575 // seek).
(...skipping 21 matching lines...) Expand all
596 597
597 // Creates a new decoder job and feeds it data ending with a |kConfigChanged| 598 // Creates a new decoder job and feeds it data ending with a |kConfigChanged|
598 // access unit. If |config_unit_in_prefetch| is true, sends feeds the config 599 // access unit. If |config_unit_in_prefetch| is true, sends feeds the config
599 // change AU in response to the job's first read request (prefetch). If 600 // change AU in response to the job's first read request (prefetch). If
600 // false, regular data is fed and decoded prior to feeding the config change 601 // false, regular data is fed and decoded prior to feeding the config change
601 // AU in response to the second data request (after prefetch completed). 602 // AU in response to the second data request (after prefetch completed).
602 // |config_unit_index| controls which access unit is |kConfigChanged|. 603 // |config_unit_index| controls which access unit is |kConfigChanged|.
603 void StartConfigChange(bool is_audio, 604 void StartConfigChange(bool is_audio,
604 bool config_unit_in_prefetch, 605 bool config_unit_in_prefetch,
605 int config_unit_index) { 606 int config_unit_index) {
606 int expected_num_config_requests = demuxer_->num_config_requests();
607
608 EXPECT_FALSE(GetMediaDecoderJob(is_audio)); 607 EXPECT_FALSE(GetMediaDecoderJob(is_audio));
609 if (is_audio) { 608 if (is_audio) {
610 StartAudioDecoderJob(true); 609 StartAudioDecoderJob();
611 } else { 610 } else {
612 CreateNextTextureAndSetVideoSurface(); 611 CreateNextTextureAndSetVideoSurface();
613 StartVideoDecoderJob(true); 612 StartVideoDecoderJob();
614 } 613 }
615 614
616 int expected_num_data_requests = demuxer_->num_data_requests(); 615 int expected_num_data_requests = demuxer_->num_data_requests();
617 616
618 // Feed and decode a standalone access unit so the player exits prefetch. 617 // Feed and decode a standalone access unit so the player exits prefetch.
619 if (!config_unit_in_prefetch) { 618 if (!config_unit_in_prefetch) {
620 if (is_audio) 619 if (is_audio)
621 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 620 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
622 else 621 else
623 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 622 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
624 623
625 WaitForDecodeDone(is_audio, !is_audio); 624 WaitForDecodeDone(is_audio, !is_audio);
626 625
627 // We should have completed the prefetch phase at this point. 626 // We should have completed the prefetch phase at this point.
628 expected_num_data_requests++; 627 expected_num_data_requests++;
629 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); 628 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
630 } 629 }
631 630
632 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests());
633
634 // Feed and decode access units with data for any units prior to 631 // Feed and decode access units with data for any units prior to
635 // |config_unit_index|, and a |kConfigChanged| unit at that index. 632 // |config_unit_index|, and a |kConfigChanged| unit at that index.
636 // Player should prepare to reconfigure the decoder job, and should request 633 // Player should prepare to reconfigure the decoder job, and should request
637 // new demuxer configs. 634 // new demuxer configs.
638 player_.OnDemuxerDataAvailable( 635 player_.OnDemuxerDataAvailable(
639 CreateReadFromDemuxerAckWithConfigChanged(is_audio, config_unit_index)); 636 CreateReadFromDemuxerAckWithConfigChanged(is_audio, config_unit_index));
640 WaitForDecodeDone(is_audio, !is_audio); 637 // Run until decoder starts to request new data.
641 638 while (demuxer_->num_data_requests() == expected_num_data_requests)
642 expected_num_config_requests++; 639 message_loop_.RunUntilIdle();
643 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
644 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests());
645 } 640 }
646 641
647 void CreateNextTextureAndSetVideoSurface() { 642 void CreateNextTextureAndSetVideoSurface() {
648 gfx::SurfaceTexture* surface_texture; 643 gfx::SurfaceTexture* surface_texture;
649 if (surface_texture_a_is_next_) { 644 if (surface_texture_a_is_next_) {
650 surface_texture_a_ = gfx::SurfaceTexture::Create(next_texture_id_++); 645 surface_texture_a_ = gfx::SurfaceTexture::Create(next_texture_id_++);
651 surface_texture = surface_texture_a_.get(); 646 surface_texture = surface_texture_a_.get();
652 } else { 647 } else {
653 surface_texture_b_ = gfx::SurfaceTexture::Create(next_texture_id_++); 648 surface_texture_b_ = gfx::SurfaceTexture::Create(next_texture_id_++);
654 surface_texture = surface_texture_b_.get(); 649 surface_texture = surface_texture_b_.get();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 } 697 }
703 698
704 void VerifyCompletedPlaybackResumesOnSeekPlusStart(bool have_audio, 699 void VerifyCompletedPlaybackResumesOnSeekPlusStart(bool have_audio,
705 bool have_video) { 700 bool have_video) {
706 DCHECK(have_audio || have_video); 701 DCHECK(have_audio || have_video);
707 702
708 EXPECT_TRUE(manager_.playback_completed()); 703 EXPECT_TRUE(manager_.playback_completed());
709 704
710 player_.SeekTo(base::TimeDelta()); 705 player_.SeekTo(base::TimeDelta());
711 player_.OnDemuxerSeekDone(kNoTimestamp()); 706 player_.OnDemuxerSeekDone(kNoTimestamp());
712 Start(CreateDemuxerConfigs(have_audio, have_video), true); 707 Resume(have_audio, have_video);
713 } 708 }
714 709
715 // Starts the appropriate decoder jobs according to |have_audio| and 710 // Starts the appropriate decoder jobs according to |have_audio| and
716 // |have_video|. Then starts seek during decode of EOS or non-EOS according to 711 // |have_video|. Then starts seek during decode of EOS or non-EOS according to
717 // |eos_audio| and |eos_video|. Simulates seek completion and verifies that 712 // |eos_audio| and |eos_video|. Simulates seek completion and verifies that
718 // playback never completed. |eos_{audio,video}| is ignored if the 713 // playback never completed. |eos_{audio,video}| is ignored if the
719 // corresponding |have_{audio,video}| is false. 714 // corresponding |have_{audio,video}| is false.
720 void VerifySeekDuringEOSDecodePreventsPlaybackCompletion(bool have_audio, 715 void VerifySeekDuringEOSDecodePreventsPlaybackCompletion(bool have_audio,
721 bool have_video, 716 bool have_video,
722 bool eos_audio, 717 bool eos_audio,
723 bool eos_video) { 718 bool eos_video) {
724 DCHECK(have_audio || have_video); 719 DCHECK(have_audio || have_video);
725 720
726 if (have_video) 721 if (have_video)
727 CreateNextTextureAndSetVideoSurface(); 722 CreateNextTextureAndSetVideoSurface();
728 723
729 Start(CreateDemuxerConfigs(have_audio, have_video), true); 724 Start(CreateDemuxerConfigs(have_audio, have_video));
730 725
731 if (have_audio) 726 if (have_audio)
732 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 727 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
733 728
734 if (have_video) 729 if (have_video)
735 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 730 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
736 731
737 // Run until more data is requested a number of times equal to the number of 732 // Run until more data is requested a number of times equal to the number of
738 // media types configured. Since prefetching may be in progress, we cannot 733 // media types configured. Since prefetching may be in progress, we cannot
739 // reliably expect Run() to complete until we have sent demuxer data for all 734 // reliably expect Run() to complete until we have sent demuxer data for all
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 bool surface_texture_a_is_next_; 784 bool surface_texture_a_is_next_;
790 int next_texture_id_; 785 int next_texture_id_;
791 786
792 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest); 787 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest);
793 }; 788 };
794 789
795 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) { 790 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) {
796 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 791 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
797 792
798 // Test audio decoder job will be created when codec is successfully started. 793 // Test audio decoder job will be created when codec is successfully started.
799 StartAudioDecoderJob(true); 794 StartAudioDecoderJob();
800 EXPECT_EQ(0, demuxer_->num_seek_requests()); 795 EXPECT_EQ(0, demuxer_->num_seek_requests());
801 } 796 }
802 797
803 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { 798 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) {
804 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 799 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
805 800
806 // Test audio decoder job will not be created when failed to start the codec. 801 // Test audio decoder job will not be created when failed to start the codec.
807 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 802 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis);
808 // Replace with invalid |audio_extra_data| 803 // Replace with invalid |audio_extra_data|
809 configs.audio_extra_data.clear(); 804 configs.audio_extra_data.clear();
810 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; 805 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff };
811 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), 806 configs.audio_extra_data.insert(configs.audio_extra_data.begin(),
812 invalid_codec_data, invalid_codec_data + 4); 807 invalid_codec_data, invalid_codec_data + 4);
813 Start(configs, false); 808 Start(configs);
814 EXPECT_EQ(0, demuxer_->num_seek_requests()); 809 EXPECT_EQ(0, demuxer_->num_seek_requests());
815 } 810 }
816 811
817 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { 812 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) {
818 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 813 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
819 814
820 // Test video decoder job will be created when surface is valid. 815 // Test video decoder job will be created when surface is valid.
821 // Video decoder job will not be created until surface is available. 816 // Video decoder job will not be created until surface is available.
822 StartVideoDecoderJob(false); 817 StartVideoDecoderJob();
823 818
824 // Set both an initial and a later video surface without receiving any 819 // Set both an initial and a later video surface without receiving any
825 // demuxed data yet. 820 // demuxed data yet.
826 CreateNextTextureAndSetVideoSurface(); 821 CreateNextTextureAndSetVideoSurface();
827 MediaDecoderJob* first_job = GetMediaDecoderJob(false); 822 MediaDecoderJob* first_job = GetMediaDecoderJob(false);
828 EXPECT_TRUE(first_job); 823 EXPECT_TRUE(first_job);
829 CreateNextTextureAndSetVideoSurface(); 824 CreateNextTextureAndSetVideoSurface();
830 825
831 // Setting another surface will not create a new job until any pending 826 // Setting another surface will not create a new job until any pending
832 // read is satisfied (and job is no longer decoding). 827 // read is satisfied (and job is no longer decoding).
833 EXPECT_EQ(first_job, GetMediaDecoderJob(false)); 828 EXPECT_EQ(first_job, GetMediaDecoderJob(false));
834 829
835 // No seeks, even on setting surface, should have occurred. (Browser seeks can 830 // No seeks, even on setting surface, should have occurred. (Browser seeks can
836 // occur on setting surface, but only after previously receiving video data.) 831 // occur on setting surface, but only after previously receiving video data.)
837 EXPECT_EQ(0, demuxer_->num_seek_requests()); 832 EXPECT_EQ(0, demuxer_->num_seek_requests());
838 833
839 // Note, the decoder job for the second surface set, above, will be created 834 // Note, the decoder job for the second surface set, above, will be created
840 // only after the pending read is satisfied and decoded, and the resulting 835 // only after the pending read is satisfied and decoded, and the resulting
841 // browser seek is done. See BrowserSeek_* tests for this coverage. 836 // browser seek is done. See BrowserSeek_* tests for this coverage.
842 } 837 }
843 838
844 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { 839 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) {
845 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 840 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
846 841
847 // Test video decoder job will not be created when surface is invalid. 842 // Test video decoder job will not be created when surface is invalid.
848 scoped_refptr<gfx::SurfaceTexture> surface_texture( 843 scoped_refptr<gfx::SurfaceTexture> surface_texture(
849 gfx::SurfaceTexture::Create(0)); 844 gfx::SurfaceTexture::Create(0));
850 gfx::ScopedJavaSurface surface(surface_texture.get()); 845 gfx::ScopedJavaSurface surface(surface_texture.get());
851 StartVideoDecoderJob(false); 846 StartVideoDecoderJob();
852 847
853 // Release the surface texture. 848 // Release the surface texture.
854 surface_texture = NULL; 849 surface_texture = NULL;
855 player_.SetVideoSurface(surface.Pass()); 850 player_.SetVideoSurface(surface.Pass());
856 851
857 // Player should not seek the demuxer on setting initial surface. 852 // Player should not seek the demuxer on setting initial surface.
858 EXPECT_EQ(0, demuxer_->num_seek_requests()); 853 EXPECT_EQ(0, demuxer_->num_seek_requests());
859 854
860 EXPECT_FALSE(GetMediaDecoderJob(false)); 855 EXPECT_FALSE(GetMediaDecoderJob(false));
861 EXPECT_EQ(0, demuxer_->num_data_requests()); 856 EXPECT_EQ(0, demuxer_->num_data_requests());
862 } 857 }
863 858
864 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) { 859 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) {
865 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 860 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
866 861
867 // Test decoder job will resend a ReadFromDemuxer request after seek. 862 // Test decoder job will resend a ReadFromDemuxer request after seek.
868 StartAudioDecoderJob(true); 863 StartAudioDecoderJob();
869 SeekPlayerWithAbort(true, base::TimeDelta()); 864 SeekPlayerWithAbort(true, base::TimeDelta());
870 } 865 }
871 866
872 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { 867 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) {
873 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 868 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
874 869
875 // Test SetVideoSurface() will not cause an extra seek while the player is 870 // Test SetVideoSurface() will not cause an extra seek while the player is
876 // waiting for demuxer to indicate seek is done. 871 // waiting for demuxer to indicate seek is done.
877 // Player is still waiting for SetVideoSurface(), so no request is sent. 872 // Player is still waiting for SetVideoSurface(), so no request is sent.
878 StartVideoDecoderJob(false); // Verifies no data requested. 873 StartVideoDecoderJob(); // Verifies no data requested.
879 874
880 // Initiate a seek. Skip requesting element seek of renderer. 875 // Initiate a seek. Skip requesting element seek of renderer.
881 // Instead behave as if the renderer has asked us to seek. 876 // Instead behave as if the renderer has asked us to seek.
882 EXPECT_EQ(0, demuxer_->num_seek_requests()); 877 EXPECT_EQ(0, demuxer_->num_seek_requests());
883 player_.SeekTo(base::TimeDelta()); 878 player_.SeekTo(base::TimeDelta());
884 EXPECT_EQ(1, demuxer_->num_seek_requests()); 879 EXPECT_EQ(1, demuxer_->num_seek_requests());
885 880
886 CreateNextTextureAndSetVideoSurface(); 881 CreateNextTextureAndSetVideoSurface();
887 EXPECT_FALSE(GetMediaDecoderJob(false)); 882 EXPECT_FALSE(GetMediaDecoderJob(false));
888 EXPECT_EQ(1, demuxer_->num_seek_requests()); 883 EXPECT_EQ(1, demuxer_->num_seek_requests());
(...skipping 10 matching lines...) Expand all
899 // was not a browser seek request. 894 // was not a browser seek request.
900 EXPECT_EQ(1, demuxer_->num_seek_requests()); 895 EXPECT_EQ(1, demuxer_->num_seek_requests());
901 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 896 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
902 } 897 }
903 898
904 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) { 899 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) {
905 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 900 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
906 901
907 // Test MediaSourcePlayer can switch multiple surfaces during decoding. 902 // Test MediaSourcePlayer can switch multiple surfaces during decoding.
908 CreateNextTextureAndSetVideoSurface(); 903 CreateNextTextureAndSetVideoSurface();
909 StartVideoDecoderJob(true); 904 StartVideoDecoderJob();
910 EXPECT_EQ(0, demuxer_->num_seek_requests()); 905 EXPECT_EQ(0, demuxer_->num_seek_requests());
911 906
912 // Send the first input chunk. 907 // Send the first input chunk.
913 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 908 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
914 909
915 // While the decoder is decoding, change multiple surfaces. Pass an empty 910 // While the decoder is decoding, change multiple surfaces. Pass an empty
916 // surface first. 911 // surface first.
917 gfx::ScopedJavaSurface empty_surface; 912 gfx::ScopedJavaSurface empty_surface;
918 player_.SetVideoSurface(empty_surface.Pass()); 913 player_.SetVideoSurface(empty_surface.Pass());
919 // Next, pass a new non-empty surface. 914 // Next, pass a new non-empty surface.
(...skipping 16 matching lines...) Expand all
936 EXPECT_TRUE(GetMediaDecoderJob(false)); 931 EXPECT_TRUE(GetMediaDecoderJob(false));
937 EXPECT_EQ(3, demuxer_->num_data_requests()); 932 EXPECT_EQ(3, demuxer_->num_data_requests());
938 EXPECT_EQ(1, demuxer_->num_seek_requests()); 933 EXPECT_EQ(1, demuxer_->num_seek_requests());
939 } 934 }
940 935
941 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) { 936 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) {
942 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 937 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
943 938
944 // Test player pauses if an empty surface is passed. 939 // Test player pauses if an empty surface is passed.
945 CreateNextTextureAndSetVideoSurface(); 940 CreateNextTextureAndSetVideoSurface();
946 StartVideoDecoderJob(true); 941 StartVideoDecoderJob();
947 EXPECT_EQ(1, demuxer_->num_data_requests()); 942 EXPECT_EQ(1, demuxer_->num_data_requests());
948 943
949 // Send the first input chunk. 944 // Send the first input chunk.
950 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 945 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
951 946
952 // While the decoder is decoding, pass an empty surface. 947 // While the decoder is decoding, pass an empty surface.
953 gfx::ScopedJavaSurface empty_surface; 948 gfx::ScopedJavaSurface empty_surface;
954 player_.SetVideoSurface(empty_surface.Pass()); 949 player_.SetVideoSurface(empty_surface.Pass());
955 // Let the player starve. However, it should not issue any new data request in 950 // Let the player starve. However, it should not issue any new data request in
956 // this case. 951 // this case.
(...skipping 12 matching lines...) Expand all
969 CreateNextTextureAndSetVideoSurface(); 964 CreateNextTextureAndSetVideoSurface();
970 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 965 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
971 } 966 }
972 967
973 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { 968 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) {
974 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 969 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
975 970
976 // Test that if video decoder is released while decoding, the resources will 971 // Test that if video decoder is released while decoding, the resources will
977 // not be immediately released. 972 // not be immediately released.
978 CreateNextTextureAndSetVideoSurface(); 973 CreateNextTextureAndSetVideoSurface();
979 StartVideoDecoderJob(true); 974 StartVideoDecoderJob();
980 EXPECT_EQ(1, manager_.num_resources_requested()); 975 EXPECT_EQ(1, manager_.num_resources_requested());
981 ReleasePlayer(); 976 ReleasePlayer();
982 // The resources will be immediately released since the decoder is idle. 977 // The resources will be immediately released since the decoder is idle.
983 EXPECT_EQ(1, manager_.num_resources_released()); 978 EXPECT_EQ(1, manager_.num_resources_released());
984 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 979 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
985 980
986 // Recreate the video decoder. 981 // Recreate the video decoder.
987 CreateNextTextureAndSetVideoSurface(); 982 CreateNextTextureAndSetVideoSurface();
988 player_.Start(); 983 player_.Start();
989 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 984 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 1044
1050 // Reconfirm exactly 1 seek request has been made of demuxer. 1045 // Reconfirm exactly 1 seek request has been made of demuxer.
1051 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1046 EXPECT_EQ(1, demuxer_->num_seek_requests());
1052 } 1047 }
1053 1048
1054 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) { 1049 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) {
1055 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1050 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1056 1051
1057 // Test that if the decoding job is not fully stopped after Pause(), 1052 // Test that if the decoding job is not fully stopped after Pause(),
1058 // calling Start() will be a noop. 1053 // calling Start() will be a noop.
1059 StartAudioDecoderJob(true); 1054 StartAudioDecoderJob();
1060 1055
1061 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 1056 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true);
1062 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 1057 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
1063 1058
1064 // Sending data to player. 1059 // Sending data to player.
1065 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1060 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1066 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1061 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1067 EXPECT_EQ(2, demuxer_->num_data_requests()); 1062 EXPECT_EQ(2, demuxer_->num_data_requests());
1068 1063
1069 // Decoder job will not immediately stop after Pause() since it is 1064 // Decoder job will not immediately stop after Pause() since it is
(...skipping 12 matching lines...) Expand all
1082 EXPECT_EQ(2, demuxer_->num_data_requests()); 1077 EXPECT_EQ(2, demuxer_->num_data_requests());
1083 EXPECT_TRUE(GetMediaDecoderJob(true)->is_requesting_demuxer_data()); 1078 EXPECT_TRUE(GetMediaDecoderJob(true)->is_requesting_demuxer_data());
1084 } 1079 }
1085 1080
1086 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { 1081 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) {
1087 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1082 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1088 1083
1089 // Test that when Start() is called, video decoder jobs will wait for audio 1084 // Test that when Start() is called, video decoder jobs will wait for audio
1090 // decoder job before start decoding the data. 1085 // decoder job before start decoding the data.
1091 CreateNextTextureAndSetVideoSurface(); 1086 CreateNextTextureAndSetVideoSurface();
1092 Start(CreateAudioVideoDemuxerConfigs(), true); 1087 Start(CreateAudioVideoDemuxerConfigs());
1093 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true); 1088 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true);
1094 MediaDecoderJob* video_decoder_job = GetMediaDecoderJob(false); 1089 MediaDecoderJob* video_decoder_job = GetMediaDecoderJob(false);
1095 1090
1096 EXPECT_FALSE(audio_decoder_job->is_decoding()); 1091 EXPECT_FALSE(audio_decoder_job->is_decoding());
1097 EXPECT_FALSE(video_decoder_job->is_decoding()); 1092 EXPECT_FALSE(video_decoder_job->is_decoding());
1098 1093
1099 // Sending video data to player, video decoder should not start. 1094 // Sending video data to player, video decoder should not start.
1100 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1095 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1101 EXPECT_FALSE(video_decoder_job->is_decoding()); 1096 EXPECT_FALSE(video_decoder_job->is_decoding());
1102 1097
1103 // Sending audio data to player, both decoders should start now. 1098 // Sending audio data to player, both decoders should start now.
1104 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1099 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1105 EXPECT_TRUE(audio_decoder_job->is_decoding()); 1100 EXPECT_TRUE(audio_decoder_job->is_decoding());
1106 EXPECT_TRUE(video_decoder_job->is_decoding()); 1101 EXPECT_TRUE(video_decoder_job->is_decoding());
1107 1102
1108 // No seeks should have occurred. 1103 // No seeks should have occurred.
1109 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1104 EXPECT_EQ(0, demuxer_->num_seek_requests());
1110 } 1105 }
1111 1106
1112 TEST_F(MediaSourcePlayerTest, StartTimeTicksResetAfterDecoderUnderruns) { 1107 TEST_F(MediaSourcePlayerTest, StartTimeTicksResetAfterDecoderUnderruns) {
1113 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1108 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1114 1109
1115 // Test start time ticks will reset after decoder job underruns. 1110 // Test start time ticks will reset after decoder job underruns.
1116 StartAudioDecoderJob(true); 1111 StartAudioDecoderJob();
1117 1112
1118 DecodeAudioDataUntilOutputBecomesAvailable(); 1113 DecodeAudioDataUntilOutputBecomesAvailable();
1119 1114
1120 // The decoder job should finish and a new request will be sent. 1115 // The decoder job should finish and a new request will be sent.
1121 base::TimeTicks previous = StartTimeTicks(); 1116 base::TimeTicks previous = StartTimeTicks();
1122 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1117 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1123 1118
1124 // Let the decoder starve. 1119 // Let the decoder starve.
1125 TriggerPlayerStarvation(); 1120 TriggerPlayerStarvation();
1126 WaitForAudioDecodeDone(); 1121 WaitForAudioDecodeDone();
1127 1122
1128 // Verify the start time ticks is cleared at this point because the 1123 // Verify the start time ticks is cleared at this point because the
1129 // player is prefetching. 1124 // player is prefetching.
1130 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks()); 1125 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks());
1131 1126
1132 // Send new data to the decoder so it can finish prefetching. This should 1127 // Send new data to the decoder so it can finish prefetching. This should
1133 // reset the start time ticks. 1128 // reset the start time ticks.
1134 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1129 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1135 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); 1130 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks());
1136 1131
1137 base::TimeTicks current = StartTimeTicks(); 1132 base::TimeTicks current = StartTimeTicks();
1138 EXPECT_LE(0, (current - previous).InMillisecondsF()); 1133 EXPECT_LE(0, (current - previous).InMillisecondsF());
1139 } 1134 }
1140 1135
1141 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) { 1136 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) {
1142 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1137 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1143 1138
1144 // Test MediaSourcePlayer can replay video after input EOS is reached. 1139 // Test MediaSourcePlayer can replay video after input EOS is reached.
1145 CreateNextTextureAndSetVideoSurface(); 1140 CreateNextTextureAndSetVideoSurface();
1146 StartVideoDecoderJob(true); 1141 StartVideoDecoderJob();
1147 1142
1148 // Send the first input chunk. 1143 // Send the first input chunk.
1149 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1144 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1150 WaitForVideoDecodeDone(); 1145 WaitForVideoDecodeDone();
1151 1146
1152 VerifyPlaybackCompletesOnEOSDecode(true, false); 1147 VerifyPlaybackCompletesOnEOSDecode(true, false);
1153 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true); 1148 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true);
1154 } 1149 }
1155 1150
1156 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) { 1151 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) {
1157 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1152 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1158 1153
1159 // Test decode of audio EOS buffer without any prior decode. See also 1154 // Test decode of audio EOS buffer without any prior decode. See also
1160 // http://b/11696552. 1155 // http://b/11696552.
1161 // Also tests that seeking+Start() after completing audio playback resumes 1156 // Also tests that seeking+Start() after completing audio playback resumes
1162 // playback. 1157 // playback.
1163 Start(CreateAudioDemuxerConfigs(kCodecAAC), true); 1158 Start(CreateAudioDemuxerConfigs(kCodecAAC));
1164 VerifyPlaybackCompletesOnEOSDecode(true, true); 1159 VerifyPlaybackCompletesOnEOSDecode(true, true);
1165 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, false); 1160 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, false);
1166 } 1161 }
1167 1162
1168 TEST_F(MediaSourcePlayerTest, V_FirstAccessUnitAfterSeekIsEOS) { 1163 TEST_F(MediaSourcePlayerTest, V_FirstAccessUnitAfterSeekIsEOS) {
1169 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1164 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1170 1165
1171 // Test decode of video EOS buffer, just after seeking, without any prior 1166 // Test decode of video EOS buffer, just after seeking, without any prior
1172 // decode (other than the simulated |kAborted| resulting from the seek 1167 // decode (other than the simulated |kAborted| resulting from the seek
1173 // process.) 1168 // process.)
1174 CreateNextTextureAndSetVideoSurface(); 1169 CreateNextTextureAndSetVideoSurface();
1175 StartVideoDecoderJob(true); 1170 StartVideoDecoderJob();
1176 SeekPlayerWithAbort(false, base::TimeDelta()); 1171 SeekPlayerWithAbort(false, base::TimeDelta());
1177 VerifyPlaybackCompletesOnEOSDecode(true, false); 1172 VerifyPlaybackCompletesOnEOSDecode(true, false);
1178 } 1173 }
1179 1174
1180 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitAfterSeekIsEOS) { 1175 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitAfterSeekIsEOS) {
1181 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1176 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1182 1177
1183 // Test decode of audio EOS buffer, just after seeking, without any prior 1178 // Test decode of audio EOS buffer, just after seeking, without any prior
1184 // decode (other than the simulated |kAborted| resulting from the seek 1179 // decode (other than the simulated |kAborted| resulting from the seek
1185 // process.) See also http://b/11696552. 1180 // process.) See also http://b/11696552.
1186 Start(CreateAudioDemuxerConfigs(kCodecAAC), true); 1181 Start(CreateAudioDemuxerConfigs(kCodecAAC));
1187 SeekPlayerWithAbort(true, base::TimeDelta()); 1182 SeekPlayerWithAbort(true, base::TimeDelta());
1188 VerifyPlaybackCompletesOnEOSDecode(true, true); 1183 VerifyPlaybackCompletesOnEOSDecode(true, true);
1189 } 1184 }
1190 1185
1191 TEST_F(MediaSourcePlayerTest, AV_PlaybackCompletionAcrossConfigChange) { 1186 TEST_F(MediaSourcePlayerTest, AV_PlaybackCompletionAcrossConfigChange) {
1192 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1187 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1193 1188
1194 // Test that if one stream (audio) has completed decode of EOS and the other 1189 // Test that if one stream (audio) has completed decode of EOS and the other
1195 // stream (video) processes config change, that subsequent video EOS completes 1190 // stream (video) processes config change, that subsequent video EOS completes
1196 // A/V playback. 1191 // A/V playback.
1197 // Also tests that seeking+Start() after completing playback resumes playback. 1192 // Also tests that seeking+Start() after completing playback resumes playback.
1198 CreateNextTextureAndSetVideoSurface(); 1193 CreateNextTextureAndSetVideoSurface();
1199 Start(CreateAudioVideoDemuxerConfigs(), true); 1194 Start(CreateAudioVideoDemuxerConfigs());
1200 1195
1201 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS 1196 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1202 EXPECT_EQ(0, demuxer_->num_config_requests());
1203 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( 1197 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1204 false, 0)); // Video |kConfigChanged| as first unit. 1198 false, 0)); // Video |kConfigChanged| as first unit.
1205 1199
1206 WaitForAudioVideoDecodeDone(); 1200 WaitForAudioVideoDecodeDone();
1207 1201
1208 EXPECT_EQ(1, demuxer_->num_config_requests());
1209 EXPECT_EQ(2, demuxer_->num_data_requests());
1210 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs());
1211 EXPECT_EQ(3, demuxer_->num_data_requests()); 1202 EXPECT_EQ(3, demuxer_->num_data_requests());
1212 1203
1213 // At no time after completing audio EOS decode, above, should the 1204 // At no time after completing audio EOS decode, above, should the
1214 // audio decoder job resume decoding. Send and decode video EOS. 1205 // audio decoder job resume decoding. Send and decode video EOS.
1215 VerifyPlaybackCompletesOnEOSDecode(true, false); 1206 VerifyPlaybackCompletesOnEOSDecode(true, false);
1216 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); 1207 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
1217 } 1208 }
1218 1209
1219 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) { 1210 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) {
1220 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1211 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1221 1212
1222 // Test that if one stream (video) has completed decode of EOS and the other 1213 // Test that if one stream (video) has completed decode of EOS and the other
1223 // stream (audio) processes config change, that subsequent audio EOS completes 1214 // stream (audio) processes config change, that subsequent audio EOS completes
1224 // A/V playback. 1215 // A/V playback.
1225 // Also tests that seeking+Start() after completing playback resumes playback. 1216 // Also tests that seeking+Start() after completing playback resumes playback.
1226 CreateNextTextureAndSetVideoSurface(); 1217 CreateNextTextureAndSetVideoSurface();
1227 Start(CreateAudioVideoDemuxerConfigs(), true); 1218 Start(CreateAudioVideoDemuxerConfigs());
1228 1219
1229 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS 1220 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1230 EXPECT_EQ(0, demuxer_->num_config_requests());
1231 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( 1221 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1232 true, 0)); // Audio |kConfigChanged| as first unit. 1222 true, 0)); // Audio |kConfigChanged| as first unit.
1233 1223
1234 WaitForAudioVideoDecodeDone(); 1224 WaitForAudioVideoDecodeDone();
1235 1225
1236 // TODO(wolenetz/qinmin): Prevent redundant demuxer config request and change
1237 // expectation to 1 here. See http://crbug.com/325528.
1238 EXPECT_EQ(2, demuxer_->num_config_requests());
1239 EXPECT_EQ(2, demuxer_->num_data_requests());
1240 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs());
1241 EXPECT_EQ(3, demuxer_->num_data_requests()); 1226 EXPECT_EQ(3, demuxer_->num_data_requests());
1242 1227
1243 // At no time after completing video EOS decode, above, should the 1228 // At no time after completing video EOS decode, above, should the
1244 // video decoder job resume decoding. Send and decode audio EOS. 1229 // video decoder job resume decoding. Send and decode audio EOS.
1245 VerifyPlaybackCompletesOnEOSDecode(true, true); 1230 VerifyPlaybackCompletesOnEOSDecode(true, true);
1246 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); 1231 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
1247 } 1232 }
1248 1233
1249 TEST_F(MediaSourcePlayerTest, AV_NoPrefetchForFinishedVideoOnAudioStarvation) { 1234 TEST_F(MediaSourcePlayerTest, AV_NoPrefetchForFinishedVideoOnAudioStarvation) {
1250 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1235 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1251 1236
1252 // Test that if one stream (video) has completed decode of EOS, prefetch 1237 // Test that if one stream (video) has completed decode of EOS, prefetch
1253 // resulting from player starvation occurs only for the other stream (audio), 1238 // resulting from player starvation occurs only for the other stream (audio),
1254 // and responding to that prefetch with EOS completes A/V playback, even if 1239 // and responding to that prefetch with EOS completes A/V playback, even if
1255 // another starvation occurs during the latter EOS's decode. 1240 // another starvation occurs during the latter EOS's decode.
1256 CreateNextTextureAndSetVideoSurface(); 1241 CreateNextTextureAndSetVideoSurface();
1257 Start(CreateAudioVideoDemuxerConfigs(), true); 1242 Start(CreateAudioVideoDemuxerConfigs());
1258 1243
1259 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1244 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1260 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS 1245 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1261 1246
1262 // Wait until video EOS is processed and more data (assumed to be audio) is 1247 // Wait until video EOS is processed and more data (assumed to be audio) is
1263 // requested. 1248 // requested.
1264 WaitForAudioVideoDecodeDone(); 1249 WaitForAudioVideoDecodeDone();
1265 EXPECT_EQ(3, demuxer_->num_data_requests()); 1250 EXPECT_EQ(3, demuxer_->num_data_requests());
1266 1251
1267 // Simulate decoder underrun to trigger prefetch while still decoding audio. 1252 // Simulate decoder underrun to trigger prefetch while still decoding audio.
(...skipping 14 matching lines...) Expand all
1282 TriggerPlayerStarvation(); 1267 TriggerPlayerStarvation();
1283 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */); 1268 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */);
1284 } 1269 }
1285 1270
1286 TEST_F(MediaSourcePlayerTest, V_StarvationDuringEOSDecode) { 1271 TEST_F(MediaSourcePlayerTest, V_StarvationDuringEOSDecode) {
1287 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1272 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1288 1273
1289 // Test that video-only playback completes without further data requested when 1274 // Test that video-only playback completes without further data requested when
1290 // starvation occurs during EOS decode. 1275 // starvation occurs during EOS decode.
1291 CreateNextTextureAndSetVideoSurface(); 1276 CreateNextTextureAndSetVideoSurface();
1292 StartVideoDecoderJob(true); 1277 StartVideoDecoderJob();
1293 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1278 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1294 WaitForVideoDecodeDone(); 1279 WaitForVideoDecodeDone();
1295 1280
1296 // Simulate decoder underrun to trigger prefetch while decoding EOS. 1281 // Simulate decoder underrun to trigger prefetch while decoding EOS.
1297 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS 1282 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1298 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding()); 1283 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding());
1299 TriggerPlayerStarvation(); 1284 TriggerPlayerStarvation();
1300 VerifyPlaybackCompletesOnEOSDecode(false, false /* ignored */); 1285 VerifyPlaybackCompletesOnEOSDecode(false, false /* ignored */);
1301 } 1286 }
1302 1287
1303 TEST_F(MediaSourcePlayerTest, A_StarvationDuringEOSDecode) { 1288 TEST_F(MediaSourcePlayerTest, A_StarvationDuringEOSDecode) {
1304 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1289 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1305 1290
1306 // Test that audio-only playback completes without further data requested when 1291 // Test that audio-only playback completes without further data requested when
1307 // starvation occurs during EOS decode. 1292 // starvation occurs during EOS decode.
1308 StartAudioDecoderJob(true); 1293 StartAudioDecoderJob();
1309 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1294 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1310 WaitForAudioDecodeDone(); 1295 WaitForAudioDecodeDone();
1311 1296
1312 // Simulate decoder underrun to trigger prefetch while decoding EOS. 1297 // Simulate decoder underrun to trigger prefetch while decoding EOS.
1313 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS 1298 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1314 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1299 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1315 TriggerPlayerStarvation(); 1300 TriggerPlayerStarvation();
1316 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */); 1301 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */);
1317 } 1302 }
1318 1303
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 // Test that seek supercedes audio-only playback completion on EOS decode, if 1341 // Test that seek supercedes audio-only playback completion on EOS decode, if
1357 // SeekTo() occurs during EOS decode. 1342 // SeekTo() occurs during EOS decode.
1358 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(true, false, true, false); 1343 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(true, false, true, false);
1359 } 1344 }
1360 1345
1361 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterAbort) { 1346 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterAbort) {
1362 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1347 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1363 1348
1364 // Test that the decoder will not request new data after receiving an aborted 1349 // Test that the decoder will not request new data after receiving an aborted
1365 // access unit. 1350 // access unit.
1366 StartAudioDecoderJob(true); 1351 StartAudioDecoderJob();
1367 1352
1368 // Send an aborted access unit. 1353 // Send an aborted access unit.
1369 player_.OnDemuxerDataAvailable(CreateAbortedAck(true)); 1354 player_.OnDemuxerDataAvailable(CreateAbortedAck(true));
1370 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1355 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1371 WaitForAudioDecodeDone(); 1356 WaitForAudioDecodeDone();
1372 1357
1373 // No request will be sent for new data. 1358 // No request will be sent for new data.
1374 EXPECT_EQ(1, demuxer_->num_data_requests()); 1359 EXPECT_EQ(1, demuxer_->num_data_requests());
1375 1360
1376 // No seek requests should have occurred. 1361 // No seek requests should have occurred.
1377 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1362 EXPECT_EQ(0, demuxer_->num_seek_requests());
1378 } 1363 }
1379 1364
1380 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) { 1365 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) {
1381 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1366 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1382 1367
1383 // Test that the decoder should not crash if demuxer data arrives after 1368 // Test that the decoder should not crash if demuxer data arrives after
1384 // Release(). 1369 // Release().
1385 StartAudioDecoderJob(true); 1370 StartAudioDecoderJob();
1386 1371
1387 ReleasePlayer(); 1372 ReleasePlayer();
1388 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1373 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1389 1374
1390 // The decoder job should have been released. 1375 // The decoder job should have been released.
1391 EXPECT_FALSE(player_.IsPlaying()); 1376 EXPECT_FALSE(player_.IsPlaying());
1392 1377
1393 // No further data should have been requested. 1378 // No further data should have been requested.
1394 EXPECT_EQ(1, demuxer_->num_data_requests()); 1379 EXPECT_EQ(1, demuxer_->num_data_requests());
1395 1380
(...skipping 29 matching lines...) Expand all
1425 EXPECT_EQ(3, demuxer_->num_data_requests()); 1410 EXPECT_EQ(3, demuxer_->num_data_requests());
1426 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1411 EXPECT_EQ(2, demuxer_->num_seek_requests());
1427 } 1412 }
1428 1413
1429 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) { 1414 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) {
1430 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1415 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1431 1416
1432 // Test that browser seek is requested if player Release() + Start() occurs 1417 // Test that browser seek is requested if player Release() + Start() occurs
1433 // prior to receiving any data. 1418 // prior to receiving any data.
1434 CreateNextTextureAndSetVideoSurface(); 1419 CreateNextTextureAndSetVideoSurface();
1435 StartVideoDecoderJob(true); 1420 StartVideoDecoderJob();
1436 ReleasePlayer(); 1421 ReleasePlayer();
1437 1422
1438 // Pass a new non-empty surface. 1423 // Pass a new non-empty surface.
1439 CreateNextTextureAndSetVideoSurface(); 1424 CreateNextTextureAndSetVideoSurface();
1440 1425
1441 player_.Start(); 1426 player_.Start();
1442 1427
1443 // The new player won't be created until the pending data request is 1428 // The new player won't be created until the pending data request is
1444 // processed. 1429 // processed.
1445 EXPECT_EQ(1, demuxer_->num_data_requests()); 1430 EXPECT_EQ(1, demuxer_->num_data_requests());
(...skipping 16 matching lines...) Expand all
1462 player_.OnDemuxerSeekDone(base::TimeDelta()); 1447 player_.OnDemuxerSeekDone(base::TimeDelta());
1463 EXPECT_TRUE(GetMediaDecoderJob(false)); 1448 EXPECT_TRUE(GetMediaDecoderJob(false));
1464 EXPECT_EQ(2, demuxer_->num_data_requests()); 1449 EXPECT_EQ(2, demuxer_->num_data_requests());
1465 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1450 EXPECT_EQ(1, demuxer_->num_seek_requests());
1466 } 1451 }
1467 1452
1468 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { 1453 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) {
1469 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1454 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1470 1455
1471 // Test decoder job will preroll the media to the seek position. 1456 // Test decoder job will preroll the media to the seek position.
1472 StartAudioDecoderJob(true); 1457 StartAudioDecoderJob();
1473 1458
1474 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); 1459 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1475 EXPECT_TRUE(IsPrerolling(true)); 1460 EXPECT_TRUE(IsPrerolling(true));
1476 PrerollDecoderToTime( 1461 PrerollDecoderToTime(
1477 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1462 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1478 } 1463 }
1479 1464
1480 TEST_F(MediaSourcePlayerTest, PrerollVideoAfterSeek) { 1465 TEST_F(MediaSourcePlayerTest, PrerollVideoAfterSeek) {
1481 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1466 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1482 1467
1483 // Test decoder job will preroll the media to the seek position. 1468 // Test decoder job will preroll the media to the seek position.
1484 CreateNextTextureAndSetVideoSurface(); 1469 CreateNextTextureAndSetVideoSurface();
1485 StartVideoDecoderJob(true); 1470 StartVideoDecoderJob();
1486 1471
1487 SeekPlayerWithAbort(false, base::TimeDelta::FromMilliseconds(100)); 1472 SeekPlayerWithAbort(false, base::TimeDelta::FromMilliseconds(100));
1488 EXPECT_TRUE(IsPrerolling(false)); 1473 EXPECT_TRUE(IsPrerolling(false));
1489 PrerollDecoderToTime( 1474 PrerollDecoderToTime(
1490 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1475 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1491 } 1476 }
1492 1477
1493 TEST_F(MediaSourcePlayerTest, SeekingAfterCompletingPrerollRestartsPreroll) { 1478 TEST_F(MediaSourcePlayerTest, SeekingAfterCompletingPrerollRestartsPreroll) {
1494 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1479 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1495 1480
1496 // Test decoder job will begin prerolling upon seek, when it was not 1481 // Test decoder job will begin prerolling upon seek, when it was not
1497 // prerolling prior to the seek. 1482 // prerolling prior to the seek.
1498 StartAudioDecoderJob(true); 1483 StartAudioDecoderJob();
1499 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 1484 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true);
1500 EXPECT_TRUE(IsPrerolling(true)); 1485 EXPECT_TRUE(IsPrerolling(true));
1501 1486
1502 // Complete the initial preroll by feeding data to the decoder. 1487 // Complete the initial preroll by feeding data to the decoder.
1503 DecodeAudioDataUntilOutputBecomesAvailable(); 1488 DecodeAudioDataUntilOutputBecomesAvailable();
1504 EXPECT_FALSE(IsPrerolling(true)); 1489 EXPECT_FALSE(IsPrerolling(true));
1505 1490
1506 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(500)); 1491 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(500));
1507 1492
1508 // Prerolling should have begun again. 1493 // Prerolling should have begun again.
(...skipping 16 matching lines...) Expand all
1525 // IsPrerolling() transition from false to true was not due to constructor 1510 // IsPrerolling() transition from false to true was not due to constructor
1526 // initialization. It was due to BeginPrerolling(). 1511 // initialization. It was due to BeginPrerolling().
1527 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 1512 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
1528 } 1513 }
1529 1514
1530 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossReleaseAndStart) { 1515 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossReleaseAndStart) {
1531 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1516 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1532 1517
1533 // Test decoder job will resume media prerolling if interrupted by Release() 1518 // Test decoder job will resume media prerolling if interrupted by Release()
1534 // and Start(). 1519 // and Start().
1535 StartAudioDecoderJob(true); 1520 StartAudioDecoderJob();
1536 1521
1537 base::TimeDelta target_timestamp = base::TimeDelta::FromMilliseconds(100); 1522 base::TimeDelta target_timestamp = base::TimeDelta::FromMilliseconds(100);
1538 SeekPlayerWithAbort(true, target_timestamp); 1523 SeekPlayerWithAbort(true, target_timestamp);
1539 EXPECT_TRUE(IsPrerolling(true)); 1524 EXPECT_TRUE(IsPrerolling(true));
1540 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1525 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1541 1526
1542 // Send some data before the seek position. 1527 // Send some data before the seek position.
1543 // Test uses 'large' number of iterations because decoder job may not get 1528 // Test uses 'large' number of iterations because decoder job may not get
1544 // MEDIA_CODEC_OK output status until after a few dequeue output attempts. 1529 // MEDIA_CODEC_OK output status until after a few dequeue output attempts.
1545 // This allows decoder status to stabilize prior to AU timestamp reaching 1530 // This allows decoder status to stabilize prior to AU timestamp reaching
1546 // the preroll target. 1531 // the preroll target.
1547 DemuxerData data; 1532 DemuxerData data;
1548 for (int i = 0; i < 10; ++i) { 1533 for (int i = 0; i < 10; ++i) {
1549 data = CreateReadFromDemuxerAckForAudio(3); 1534 data = CreateReadFromDemuxerAckForAudio(3);
1550 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 10); 1535 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 10);
1551 if (i == 1) { 1536 if (i == 1) {
1552 // While still prerolling, Release() and Start() the player. 1537 // While still prerolling, Release() and Start() the player.
1553 // TODO(qinmin): Simulation of multiple in-flight data requests (one from 1538 // TODO(qinmin): Simulation of multiple in-flight data requests (one from
1554 // before Release(), one from after Start()) is not included here, and 1539 // before Release(), one from after Start()) is not included here, and
1555 // neither is any data enqueued for later decode if it arrives after 1540 // neither is any data enqueued for later decode if it arrives after
1556 // Release() and before Start(). See http://crbug.com/306314. Assumption 1541 // Release() and before Start(). See http://crbug.com/306314. Assumption
1557 // for this test, to prevent flakiness until the bug is fixed, is the 1542 // for this test, to prevent flakiness until the bug is fixed, is the
1558 // first request's data arrives before Start(). Though that data is not 1543 // first request's data arrives before Start(). Though that data is not
1559 // seen by decoder, this assumption allows preroll continuation 1544 // seen by decoder, this assumption allows preroll continuation
1560 // verification and prevents multiple in-flight data requests. 1545 // verification and prevents multiple in-flight data requests.
1561 ReleasePlayer(); 1546 ReleasePlayer();
1562 player_.OnDemuxerDataAvailable(data); 1547 player_.OnDemuxerDataAvailable(data);
1563 WaitForAudioDecodeDone(); 1548 WaitForAudioDecodeDone();
1564 EXPECT_FALSE(GetMediaDecoderJob(true)); 1549 EXPECT_FALSE(GetMediaDecoderJob(true));
1565 StartAudioDecoderJob(true); 1550 Resume(true, false);
1566 } else { 1551 } else {
1567 player_.OnDemuxerDataAvailable(data); 1552 player_.OnDemuxerDataAvailable(data);
1568 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1553 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1569 WaitForAudioDecodeDone(); 1554 WaitForAudioDecodeDone();
1570 } 1555 }
1571 EXPECT_TRUE(IsPrerolling(true)); 1556 EXPECT_TRUE(IsPrerolling(true));
1572 } 1557 }
1573 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1558 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1574 EXPECT_TRUE(IsPrerolling(true)); 1559 EXPECT_TRUE(IsPrerolling(true));
1575 1560
1576 // Send data after the seek position. 1561 // Send data after the seek position.
1577 PrerollDecoderToTime(true, target_timestamp, target_timestamp); 1562 PrerollDecoderToTime(true, target_timestamp, target_timestamp);
1578 } 1563 }
1579 1564
1580 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) { 1565 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) {
1581 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1566 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1582 1567
1583 // Test decoder job will resume media prerolling if interrupted by 1568 // Test decoder job will resume media prerolling if interrupted by
1584 // |kConfigChanged| and OnDemuxerConfigsAvailable(). 1569 // |kConfigChanged| and OnDemuxerConfigsAvailable().
1585 StartAudioDecoderJob(true); 1570 StartAudioDecoderJob();
1586 1571
1587 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); 1572 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1588 EXPECT_TRUE(IsPrerolling(true)); 1573 EXPECT_TRUE(IsPrerolling(true));
1589 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1574 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1590 1575
1576
1591 // In response to data request, simulate that demuxer signals config change by 1577 // In response to data request, simulate that demuxer signals config change by
1592 // sending an AU with |kConfigChanged|. Player should prepare to reconfigure 1578 // sending an AU with |kConfigChanged|. Player should reconfigure the
1593 // the audio decoder job, and should request new demuxer configs. 1579 // audio decoder job with the supplied configs.
1594 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); 1580 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0);
1595 EXPECT_EQ(0, demuxer_->num_config_requests());
1596 player_.OnDemuxerDataAvailable(data); 1581 player_.OnDemuxerDataAvailable(data);
1597 EXPECT_EQ(1, demuxer_->num_config_requests());
1598
1599 // Simulate arrival of new configs.
1600 player_.OnDemuxerConfigsAvailable(CreateAudioDemuxerConfigs(kCodecVorbis));
1601
1602 PrerollDecoderToTime( 1582 PrerollDecoderToTime(
1603 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1583 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1604 } 1584 }
1605 1585
1606 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) { 1586 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) {
1607 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1587 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1608 1588
1609 // Test that the player allows simultaneous audio and video config change, 1589 // Test that the player allows simultaneous audio and video config change,
1610 // such as might occur during OnPrefetchDone() if next access unit for both 1590 // such as might occur during OnPrefetchDone() if next access unit for both
1611 // audio and video jobs is |kConfigChanged|. 1591 // audio and video jobs is |kConfigChanged|.
1612 CreateNextTextureAndSetVideoSurface(); 1592 CreateNextTextureAndSetVideoSurface();
1613 Start(CreateAudioVideoDemuxerConfigs(), true); 1593 Start(CreateAudioVideoDemuxerConfigs());
1614 MediaDecoderJob* first_audio_job = GetMediaDecoderJob(true); 1594 MediaDecoderJob* first_audio_job = GetMediaDecoderJob(true);
1615 MediaDecoderJob* first_video_job = GetMediaDecoderJob(false); 1595 MediaDecoderJob* first_video_job = GetMediaDecoderJob(false);
1616 1596
1617 // Simulate audio |kConfigChanged| prefetched as standalone access unit. 1597 // Simulate audio |kConfigChanged| prefetched as standalone access unit.
1618 player_.OnDemuxerDataAvailable( 1598 player_.OnDemuxerDataAvailable(
1619 CreateReadFromDemuxerAckWithConfigChanged(true, 0)); 1599 CreateReadFromDemuxerAckWithConfigChanged(true, 0));
1620 EXPECT_EQ(0, demuxer_->num_config_requests()); // No OnPrefetchDone() yet.
1621 1600
1622 // Simulate video |kConfigChanged| prefetched as standalone access unit. 1601 // Simulate video |kConfigChanged| prefetched as standalone access unit.
1623 player_.OnDemuxerDataAvailable( 1602 player_.OnDemuxerDataAvailable(
1624 CreateReadFromDemuxerAckWithConfigChanged(false, 0)); 1603 CreateReadFromDemuxerAckWithConfigChanged(false, 0));
1625 EXPECT_EQ(1, demuxer_->num_config_requests()); // OnPrefetchDone() occurred. 1604 EXPECT_EQ(4, demuxer_->num_data_requests());
1626 EXPECT_EQ(2, demuxer_->num_data_requests()); // No more data requested yet.
1627 1605
1628 // No job re-creation should occur until the requested configs arrive. 1606 // Both jobs should have been reconfigured by now.
1629 EXPECT_EQ(first_audio_job, GetMediaDecoderJob(true)); 1607 // TODO(qinmin): Fix flaky pointer-based MDJ inequality testing.
1630 EXPECT_EQ(first_video_job, GetMediaDecoderJob(false)); 1608 // See http://crbug.com/327839.
1631 1609 EXPECT_NE(first_audio_job, GetMediaDecoderJob(true));
1632 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs()); 1610 EXPECT_NE(first_video_job, GetMediaDecoderJob(false));
1633 EXPECT_EQ(4, demuxer_->num_data_requests()); 1611 EXPECT_TRUE(GetMediaDecoderJob(true) && GetMediaDecoderJob(false));
1634 MediaDecoderJob* second_audio_job = GetMediaDecoderJob(true);
1635 MediaDecoderJob* second_video_job = GetMediaDecoderJob(false);
1636 EXPECT_NE(first_audio_job, second_audio_job);
1637 EXPECT_NE(first_video_job, second_video_job);
1638 EXPECT_TRUE(second_audio_job && second_video_job);
1639
1640 // Confirm no further demuxer configs requested.
1641 EXPECT_EQ(1, demuxer_->num_config_requests());
1642 } 1612 }
1643 1613
1644 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) { 1614 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) {
1645 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1615 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1646 1616
1647 // Test that the player detects need for and requests demuxer configs if 1617 // Test that the player detects need for and requests demuxer configs if
1648 // the |kConfigChanged| unit is the very first unit in the set of units 1618 // the |kConfigChanged| unit is the very first unit in the set of units
1649 // received in OnDemuxerDataAvailable() ostensibly while 1619 // received in OnDemuxerDataAvailable() ostensibly while
1650 // |PREFETCH_DONE_EVENT_PENDING|. 1620 // |PREFETCH_DONE_EVENT_PENDING|.
1651 StartConfigChange(true, true, 0); 1621 StartConfigChange(true, true, 0);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1666 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1697 EXPECT_EQ(3, demuxer_->num_data_requests()); 1667 EXPECT_EQ(3, demuxer_->num_data_requests());
1698 1668
1699 PrerollDecoderToTime( 1669 PrerollDecoderToTime(
1700 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1670 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1701 } 1671 }
1702 1672
1703 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) { 1673 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) {
1704 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1674 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1705 1675
1706 // Test that video config change notification results in request for demuxer 1676 // Test that video config change notification results in creating a new
1707 // configuration, and that a video decoder job results without any browser 1677 // video decoder job results without any browser seek.
1708 // seek necessary once the new demuxer config arrives.
1709 StartConfigChange(false, true, 1); 1678 StartConfigChange(false, true, 1);
1710 MediaDecoderJob* first_job = GetMediaDecoderJob(false); 1679 EXPECT_TRUE(GetMediaDecoderJob(false));
1711 EXPECT_TRUE(first_job);
1712 EXPECT_EQ(1, demuxer_->num_data_requests());
1713 EXPECT_EQ(1, demuxer_->num_config_requests());
1714
1715 // Simulate arrival of new configs.
1716 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs());
1717
1718 // New video decoder job should have been created and configured, without any
1719 // browser seek.
1720 MediaDecoderJob* second_job = GetMediaDecoderJob(false);
1721 EXPECT_TRUE(second_job);
1722 EXPECT_NE(first_job, second_job);
1723 EXPECT_EQ(2, demuxer_->num_data_requests()); 1680 EXPECT_EQ(2, demuxer_->num_data_requests());
1724 EXPECT_EQ(1, demuxer_->num_config_requests());
1725 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1681 EXPECT_EQ(0, demuxer_->num_seek_requests());
1726 } 1682 }
1727 1683
1728 TEST_F(MediaSourcePlayerTest, VideoConfigChangeContinuesAcrossSeek) { 1684 TEST_F(MediaSourcePlayerTest, NewSurfaceAfterChangingConfigs) {
1729 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1685 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1730 1686
1731 // Test if a demuxer config request is pending (due to previously receiving 1687 // Test that no seek results from a SetVideoSurface() that occurs after
1732 // |kConfigChanged|), and a seek request arrives prior to demuxer configs, 1688 // the player processes new demuxer configs. This test may be good to keep
1733 // then seek is processed first, followed by the decoder config change. 1689 // beyond browser seek hack.
1734 // This assumes the demuxer sends |kConfigChanged| read response prior to
1735 // canceling any reads pending seek; no |kAborted| is involved in this test.
1736 StartConfigChange(false, false, 1); 1690 StartConfigChange(false, false, 1);
1737 MediaDecoderJob* first_job = GetMediaDecoderJob(false); 1691 EXPECT_TRUE(GetMediaDecoderJob(false));
1738 EXPECT_TRUE(first_job);
1739 EXPECT_EQ(1, demuxer_->num_config_requests());
1740 EXPECT_EQ(2, demuxer_->num_data_requests());
1741 EXPECT_EQ(0, demuxer_->num_seek_requests());
1742
1743 player_.SeekTo(base::TimeDelta::FromMilliseconds(100));
1744
1745 // Verify that the seek is requested immediately.
1746 EXPECT_EQ(1, demuxer_->num_seek_requests());
1747
1748 // Simulate unlikely delayed arrival of the demuxer configs, completing the
1749 // config change.
1750 // TODO(wolenetz): Is it even possible for requested demuxer configs to be
1751 // delayed until after a SeekTo request arrives?
1752 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs());
1753
1754 MediaDecoderJob* second_job = GetMediaDecoderJob(false);
1755 EXPECT_NE(first_job, second_job);
1756 EXPECT_TRUE(second_job);
1757
1758 // Send back the seek done notification. This should finish the seek and
1759 // trigger the player to request more data.
1760 EXPECT_EQ(2, demuxer_->num_data_requests());
1761 player_.OnDemuxerSeekDone(kNoTimestamp());
1762 EXPECT_EQ(3, demuxer_->num_data_requests()); 1692 EXPECT_EQ(3, demuxer_->num_data_requests());
1763 }
1764
1765 TEST_F(MediaSourcePlayerTest, NewSurfaceWhileChangingConfigs) {
1766 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1767
1768 // Test that no seek or duplicated demuxer config request results from a
1769 // SetVideoSurface() that occurs while the player is expecting new demuxer
1770 // configs. This test may be good to keep beyond browser seek hack.
1771 StartConfigChange(false, false, 1);
1772 MediaDecoderJob* first_job = GetMediaDecoderJob(false);
1773 EXPECT_TRUE(first_job);
1774 EXPECT_EQ(1, demuxer_->num_config_requests());
1775 EXPECT_EQ(2, demuxer_->num_data_requests());
1776 1693
1777 CreateNextTextureAndSetVideoSurface(); 1694 CreateNextTextureAndSetVideoSurface();
1778 1695 EXPECT_TRUE(GetMediaDecoderJob(false));
1779 // Surface change processing (including decoder job re-creation) should
1780 // not occur until the pending video config change is completed.
1781 EXPECT_EQ(first_job, GetMediaDecoderJob(false));
1782
1783 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs());
1784 MediaDecoderJob* second_job = GetMediaDecoderJob(false);
1785 EXPECT_NE(first_job, second_job);
1786 EXPECT_TRUE(second_job);
1787
1788 EXPECT_EQ(3, demuxer_->num_data_requests()); 1696 EXPECT_EQ(3, demuxer_->num_data_requests());
1789 EXPECT_EQ(1, demuxer_->num_config_requests());
1790 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1697 EXPECT_EQ(0, demuxer_->num_seek_requests());
1791 } 1698 }
1792 1699
1793 TEST_F(MediaSourcePlayerTest, 1700 TEST_F(MediaSourcePlayerTest,
1794 BrowserSeek_DecoderStarvationWhilePendingSurfaceChange) { 1701 BrowserSeek_DecoderStarvationWhilePendingSurfaceChange) {
1795 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1702 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1796 1703
1797 // Test video decoder starvation while handling a pending surface change 1704 // Test video decoder starvation while handling a pending surface change
1798 // should not cause any crashes. 1705 // should not cause any crashes.
1799 CreateNextTextureAndSetVideoSurface(); 1706 CreateNextTextureAndSetVideoSurface();
1800 StartVideoDecoderJob(true); 1707 StartVideoDecoderJob();
1801 DemuxerData data = CreateReadFromDemuxerAckForVideo(); 1708 DemuxerData data = CreateReadFromDemuxerAckForVideo();
1802 player_.OnDemuxerDataAvailable(data); 1709 player_.OnDemuxerDataAvailable(data);
1803 1710
1804 // Trigger a surface change and decoder starvation. 1711 // Trigger a surface change and decoder starvation.
1805 CreateNextTextureAndSetVideoSurface(); 1712 CreateNextTextureAndSetVideoSurface();
1806 TriggerPlayerStarvation(); 1713 TriggerPlayerStarvation();
1807 WaitForVideoDecodeDone(); 1714 WaitForVideoDecodeDone();
1808 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 1715 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
1809 1716
1810 // Surface change should trigger a seek. 1717 // Surface change should trigger a seek.
1811 player_.OnDemuxerDataAvailable(data); 1718 player_.OnDemuxerDataAvailable(data);
1812 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1719 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
1813 player_.OnDemuxerSeekDone(base::TimeDelta()); 1720 player_.OnDemuxerSeekDone(base::TimeDelta());
1814 EXPECT_TRUE(GetMediaDecoderJob(false)); 1721 EXPECT_TRUE(GetMediaDecoderJob(false));
1815 1722
1816 // A new data request should be sent. 1723 // A new data request should be sent.
1817 EXPECT_EQ(3, demuxer_->num_data_requests()); 1724 EXPECT_EQ(3, demuxer_->num_data_requests());
1818 } 1725 }
1819 1726
1820 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { 1727 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) {
1821 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1728 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1822 1729
1823 // Test if OnPrefetchDone() had already been posted before and is executed 1730 // Test if OnPrefetchDone() had already been posted before and is executed
1824 // after Release(), then player does not DCHECK. This test is fragile to 1731 // after Release(), then player does not DCHECK. This test is fragile to
1825 // change to MediaDecoderJob::Prefetch() implementation; it assumes task 1732 // change to MediaDecoderJob::Prefetch() implementation; it assumes task
1826 // is posted to run |prefetch_cb| if the job already HasData(). 1733 // is posted to run |prefetch_cb| if the job already HasData().
1827 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test 1734 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test
1828 // becomes obsolete. See http://crbug.com/304234. 1735 // becomes obsolete. See http://crbug.com/304234.
1829 StartAudioDecoderJob(true); 1736 StartAudioDecoderJob();
1830 1737
1831 // Escape the original prefetch by decoding a single access unit. 1738 // Escape the original prefetch by decoding a single access unit.
1832 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1739 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1833 WaitForAudioDecodeDone(); 1740 WaitForAudioDecodeDone();
1834 1741
1835 // Prime the job with a few more access units, so that a later prefetch, 1742 // Prime the job with a few more access units, so that a later prefetch,
1836 // triggered by starvation to simulate decoder underrun, can trivially 1743 // triggered by starvation to simulate decoder underrun, can trivially
1837 // post task to run OnPrefetchDone(). 1744 // post task to run OnPrefetchDone().
1838 player_.OnDemuxerDataAvailable( 1745 player_.OnDemuxerDataAvailable(
1839 CreateReadFromDemuxerAckWithConfigChanged(true, 4)); 1746 CreateReadFromDemuxerAckWithConfigChanged(true, 4));
1840 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1747 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1841 1748
1842 // Simulate decoder underrun, so trivial prefetch starts while still decoding. 1749 // Simulate decoder underrun, so trivial prefetch starts while still decoding.
1843 // The prefetch and posting of OnPrefetchDone() will not occur until next 1750 // The prefetch and posting of OnPrefetchDone() will not occur until next
1844 // MediaDecoderCallBack() occurs. 1751 // MediaDecoderCallBack() occurs.
1845 TriggerPlayerStarvation(); 1752 TriggerPlayerStarvation();
1846 1753
1847 // Upon the next successful decode callback, post a task to call Release() on 1754 // Upon the next successful decode callback, post a task to call Release() on
1848 // the |player_|, such that the trivial OnPrefetchDone() task posting also 1755 // the |player_|, such that the trivial OnPrefetchDone() task posting also
1849 // occurs and should execute after the Release(). 1756 // occurs and should execute after the Release().
1850 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); 1757 OnNextTestDecodeCallbackPostTaskToReleasePlayer();
1851 1758
1852 WaitForAudioDecodeDone(); 1759 WaitForAudioDecodeDone();
1853 EXPECT_TRUE(decoder_callback_hook_executed_); 1760 EXPECT_TRUE(decoder_callback_hook_executed_);
1854 EXPECT_EQ(2, demuxer_->num_data_requests()); 1761 EXPECT_EQ(2, demuxer_->num_data_requests());
1855 1762
1856 // Player should have no decoder job until after Start(). 1763 // Player should have no decoder job until after Start().
1857 StartAudioDecoderJob(true); 1764 Resume(true, false);
1858 } 1765 }
1859 1766
1860 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { 1767 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) {
1861 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1768 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1862 1769
1863 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1770 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request
1864 // has not yet been sent, then the seek request is sent after Release(). Also, 1771 // has not yet been sent, then the seek request is sent after Release(). Also,
1865 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player 1772 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player
1866 // will resume correct post-seek preroll upon Start(). 1773 // will resume correct post-seek preroll upon Start().
1867 StartAudioDecoderJobAndSeekToWhileDecoding( 1774 StartAudioDecoderJobAndSeekToWhileDecoding(
1868 base::TimeDelta::FromMilliseconds(100)); 1775 base::TimeDelta::FromMilliseconds(100));
1869 ReleasePlayer(); 1776 ReleasePlayer();
1870 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1777 EXPECT_EQ(1, demuxer_->num_seek_requests());
1871 1778
1872 player_.OnDemuxerSeekDone(kNoTimestamp()); 1779 player_.OnDemuxerSeekDone(kNoTimestamp());
1873 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1780 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1874 EXPECT_FALSE(GetMediaDecoderJob(true)); 1781 EXPECT_FALSE(GetMediaDecoderJob(true));
1875 EXPECT_FALSE(player_.IsPlaying()); 1782 EXPECT_FALSE(player_.IsPlaying());
1876 1783
1877 // Player should begin prefetch and resume preroll upon Start(). 1784 // Player should begin prefetch and resume preroll upon Start().
1878 EXPECT_EQ(2, demuxer_->num_data_requests()); 1785 EXPECT_EQ(2, demuxer_->num_data_requests());
1879 StartAudioDecoderJob(true); 1786 Resume(true, false);
1880 EXPECT_TRUE(IsPrerolling(true)); 1787 EXPECT_TRUE(IsPrerolling(true));
1881 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1788 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1882 1789
1883 // No further seek should have been requested since Release(), above. 1790 // No further seek should have been requested since Release(), above.
1884 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1791 EXPECT_EQ(1, demuxer_->num_seek_requests());
1885 } 1792 }
1886 1793
1887 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { 1794 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) {
1888 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1795 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1889 1796
1890 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1797 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request
1891 // has not yet been sent, then the seek request is sent after Release(). Also, 1798 // has not yet been sent, then the seek request is sent after Release(). Also,
1892 // test if OnDemuxerSeekDone() does not occur until after the next Start(), 1799 // test if OnDemuxerSeekDone() does not occur until after the next Start(),
1893 // then the player remains pending seek done until (and resumes correct 1800 // then the player remains pending seek done until (and resumes correct
1894 // post-seek preroll after) OnDemuxerSeekDone(). 1801 // post-seek preroll after) OnDemuxerSeekDone().
1895 StartAudioDecoderJobAndSeekToWhileDecoding( 1802 StartAudioDecoderJobAndSeekToWhileDecoding(
1896 base::TimeDelta::FromMilliseconds(100)); 1803 base::TimeDelta::FromMilliseconds(100));
1897 ReleasePlayer(); 1804 ReleasePlayer();
1898 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1805 EXPECT_EQ(1, demuxer_->num_seek_requests());
1899 1806
1900 // Player should not prefetch upon Start() nor create the decoder job, due to 1807 // Player should not prefetch upon Start() nor create the decoder job, due to
1901 // awaiting DemuxerSeekDone. 1808 // awaiting DemuxerSeekDone.
1902 EXPECT_EQ(2, demuxer_->num_data_requests()); 1809 EXPECT_EQ(2, demuxer_->num_data_requests());
1903 StartAudioDecoderJob(false); 1810 Resume(false, false);
1904 1811
1905 player_.OnDemuxerSeekDone(kNoTimestamp()); 1812 player_.OnDemuxerSeekDone(kNoTimestamp());
1906 EXPECT_TRUE(GetMediaDecoderJob(true)); 1813 EXPECT_TRUE(GetMediaDecoderJob(true));
1907 EXPECT_TRUE(IsPrerolling(true)); 1814 EXPECT_TRUE(IsPrerolling(true));
1908 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1815 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1909 EXPECT_EQ(3, demuxer_->num_data_requests()); 1816 EXPECT_EQ(3, demuxer_->num_data_requests());
1910 1817
1911 // No further seek should have been requested since Release(), above. 1818 // No further seek should have been requested since Release(), above.
1912 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1819 EXPECT_EQ(1, demuxer_->num_seek_requests());
1913 } 1820 }
(...skipping 10 matching lines...) Expand all
1924 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1831 EXPECT_EQ(1, demuxer_->num_seek_requests());
1925 1832
1926 ReleasePlayer(); 1833 ReleasePlayer();
1927 player_.OnDemuxerSeekDone(kNoTimestamp()); 1834 player_.OnDemuxerSeekDone(kNoTimestamp());
1928 EXPECT_FALSE(player_.IsPlaying()); 1835 EXPECT_FALSE(player_.IsPlaying());
1929 EXPECT_FALSE(GetMediaDecoderJob(true)); 1836 EXPECT_FALSE(GetMediaDecoderJob(true));
1930 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1837 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1931 1838
1932 // Player should begin prefetch and resume preroll upon Start(). 1839 // Player should begin prefetch and resume preroll upon Start().
1933 EXPECT_EQ(2, demuxer_->num_data_requests()); 1840 EXPECT_EQ(2, demuxer_->num_data_requests());
1934 StartAudioDecoderJob(true); 1841 Resume(true, false);
1935 EXPECT_TRUE(IsPrerolling(true)); 1842 EXPECT_TRUE(IsPrerolling(true));
1936 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1843 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1937 1844
1938 // No further seek should have been requested since before Release(), above. 1845 // No further seek should have been requested since before Release(), above.
1939 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1846 EXPECT_EQ(1, demuxer_->num_seek_requests());
1940 } 1847 }
1941 1848
1942 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { 1849 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) {
1943 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1850 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1944 1851
1945 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC 1852 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC
1946 // request and OnDemuxerSeekDone() does not occur until after the next 1853 // request and OnDemuxerSeekDone() does not occur until after the next
1947 // Start(), then the player remains pending seek done until (and resumes 1854 // Start(), then the player remains pending seek done until (and resumes
1948 // correct post-seek preroll after) OnDemuxerSeekDone(). 1855 // correct post-seek preroll after) OnDemuxerSeekDone().
1949 StartAudioDecoderJobAndSeekToWhileDecoding( 1856 StartAudioDecoderJobAndSeekToWhileDecoding(
1950 base::TimeDelta::FromMilliseconds(100)); 1857 base::TimeDelta::FromMilliseconds(100));
1951 WaitForAudioDecodeDone(); 1858 WaitForAudioDecodeDone();
1952 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1859 EXPECT_EQ(1, demuxer_->num_seek_requests());
1953 1860
1954 ReleasePlayer(); 1861 ReleasePlayer();
1955 EXPECT_EQ(2, demuxer_->num_data_requests()); 1862 EXPECT_EQ(2, demuxer_->num_data_requests());
1956 StartAudioDecoderJob(false); 1863 Resume(false, false);
1957 1864
1958 player_.OnDemuxerSeekDone(kNoTimestamp()); 1865 player_.OnDemuxerSeekDone(kNoTimestamp());
1959 EXPECT_TRUE(GetMediaDecoderJob(true)); 1866 EXPECT_TRUE(GetMediaDecoderJob(true));
1960 EXPECT_TRUE(IsPrerolling(true)); 1867 EXPECT_TRUE(IsPrerolling(true));
1961 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1868 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1962 EXPECT_EQ(3, demuxer_->num_data_requests()); 1869 EXPECT_EQ(3, demuxer_->num_data_requests());
1963 1870
1964 // No further seek should have been requested since before Release(), above. 1871 // No further seek should have been requested since before Release(), above.
1965 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1872 EXPECT_EQ(1, demuxer_->num_seek_requests());
1966 } 1873 }
1967 1874
1968 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenConfigsAvailable) {
1969 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1970
1971 // Test if Release() occurs after |kConfigChanged| detected, new configs
1972 // requested of demuxer, and the requested configs arrive before the next
1973 // Start(), then the player completes the pending config change processing on
1974 // their receipt.
1975 StartConfigChange(true, true, 0);
1976 ReleasePlayer();
1977
1978 player_.OnDemuxerConfigsAvailable(CreateAudioDemuxerConfigs(kCodecVorbis));
1979 EXPECT_FALSE(GetMediaDecoderJob(true));
1980 EXPECT_FALSE(player_.IsPlaying());
1981 EXPECT_EQ(1, demuxer_->num_data_requests());
1982
1983 // Player should resume upon Start(), even without further configs supplied.
1984 player_.Start();
1985 EXPECT_TRUE(GetMediaDecoderJob(true));
1986 EXPECT_TRUE(player_.IsPlaying());
1987 EXPECT_EQ(2, demuxer_->num_data_requests());
1988
1989 // No further config request should have occurred since StartConfigChange().
1990 EXPECT_EQ(1, demuxer_->num_config_requests());
1991 }
1992
1993 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenStart) { 1875 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenStart) {
1994 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1876 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1995 1877
1996 // Test if Release() occurs after |kConfigChanged| detected, new configs 1878 // Test if Release() occurs after |kConfigChanged| detected, and then Start()
1997 // requested of demuxer, and the requested configs arrive after the next 1879 // is called, then the player does not issue any new data request since it is
1998 // Start(), then the player pends job creation until the new configs arrive. 1880 // still waiting for the previous one.
1999 StartConfigChange(true, true, 0); 1881 StartConfigChange(true, true, 0);
2000 ReleasePlayer(); 1882 ReleasePlayer();
2001 1883
2002 player_.Start();
2003 EXPECT_TRUE(player_.IsPlaying());
2004 EXPECT_FALSE(GetMediaDecoderJob(true)); 1884 EXPECT_FALSE(GetMediaDecoderJob(true));
2005 EXPECT_EQ(1, demuxer_->num_data_requests()); 1885 EXPECT_FALSE(player_.IsPlaying());
2006
2007 player_.OnDemuxerConfigsAvailable(CreateAudioDemuxerConfigs(kCodecVorbis));
2008 EXPECT_TRUE(GetMediaDecoderJob(true));
2009 EXPECT_EQ(2, demuxer_->num_data_requests()); 1886 EXPECT_EQ(2, demuxer_->num_data_requests());
2010 1887
2011 // No further config request should have occurred since StartConfigChange(). 1888 // Player should resume upon Start().
2012 EXPECT_EQ(1, demuxer_->num_config_requests()); 1889 Resume(false, false);
1890 EXPECT_TRUE(GetMediaDecoderJob(true));
1891 EXPECT_TRUE(player_.IsPlaying());
1892 EXPECT_EQ(2, demuxer_->num_data_requests());
2013 } 1893 }
2014 1894
2015 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenDemuxerSeekDone) { 1895 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenDemuxerSeekDone) {
2016 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1896 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
2017 1897
2018 // Test that Release() after a browser seek's DemuxerSeek IPC request has been 1898 // Test that Release() after a browser seek's DemuxerSeek IPC request has been
2019 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() occurs 1899 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() occurs
2020 // before the next Start()+SetVideoSurface(), then the player will resume 1900 // before the next Start()+SetVideoSurface(), then the player will resume
2021 // correct post-seek preroll upon Start()+SetVideoSurface(). 1901 // correct post-seek preroll upon Start()+SetVideoSurface().
2022 BrowserSeekPlayer(false); 1902 BrowserSeekPlayer(false);
2023 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 1903 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
2024 ReleasePlayer(); 1904 ReleasePlayer();
2025 1905
2026 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 1906 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
2027 EXPECT_FALSE(player_.IsPlaying()); 1907 EXPECT_FALSE(player_.IsPlaying());
2028 EXPECT_FALSE(GetMediaDecoderJob(false)); 1908 EXPECT_FALSE(GetMediaDecoderJob(false));
2029 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 1909 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
2030 1910
2031 // Player should begin prefetch and resume preroll upon Start(). 1911 // Player should begin prefetch and resume preroll upon Start().
2032 EXPECT_EQ(2, demuxer_->num_data_requests()); 1912 EXPECT_EQ(2, demuxer_->num_data_requests());
2033 CreateNextTextureAndSetVideoSurface(); 1913 CreateNextTextureAndSetVideoSurface();
2034 StartVideoDecoderJob(true); 1914 Resume(false, true);
2035 EXPECT_TRUE(IsPrerolling(false)); 1915 EXPECT_TRUE(IsPrerolling(false));
2036 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 1916 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
2037 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 1917 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
2038 1918
2039 // No further seek should have been requested since BrowserSeekPlayer(). 1919 // No further seek should have been requested since BrowserSeekPlayer().
2040 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1920 EXPECT_EQ(1, demuxer_->num_seek_requests());
2041 } 1921 }
2042 1922
2043 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenStart) { 1923 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenStart) {
2044 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1924 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
2045 1925
2046 // Test that Release() after a browser seek's DemuxerSeek IPC request has been 1926 // Test that Release() after a browser seek's DemuxerSeek IPC request has been
2047 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() does not 1927 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() does not
2048 // occur until after the next Start()+SetVideoSurface(), then the player 1928 // occur until after the next Start()+SetVideoSurface(), then the player
2049 // remains pending seek done until (and resumes correct post-seek preroll 1929 // remains pending seek done until (and resumes correct post-seek preroll
2050 // after) OnDemuxerSeekDone(). 1930 // after) OnDemuxerSeekDone().
2051 BrowserSeekPlayer(false); 1931 BrowserSeekPlayer(false);
2052 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 1932 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
2053 ReleasePlayer(); 1933 ReleasePlayer();
2054 1934
2055 EXPECT_EQ(2, demuxer_->num_data_requests()); 1935 EXPECT_EQ(2, demuxer_->num_data_requests());
2056 CreateNextTextureAndSetVideoSurface(); 1936 CreateNextTextureAndSetVideoSurface();
2057 StartVideoDecoderJob(false); 1937 Resume(false, false);
2058 1938
2059 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 1939 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
2060 EXPECT_TRUE(GetMediaDecoderJob(false)); 1940 EXPECT_TRUE(GetMediaDecoderJob(false));
2061 EXPECT_TRUE(IsPrerolling(false)); 1941 EXPECT_TRUE(IsPrerolling(false));
2062 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 1942 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
2063 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 1943 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
2064 EXPECT_EQ(3, demuxer_->num_data_requests()); 1944 EXPECT_EQ(3, demuxer_->num_data_requests());
2065 1945
2066 // No further seek should have been requested since BrowserSeekPlayer(). 1946 // No further seek should have been requested since BrowserSeekPlayer().
2067 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1947 EXPECT_EQ(1, demuxer_->num_seek_requests());
(...skipping 16 matching lines...) Expand all
2084 player_.OnDemuxerConfigsAvailable(configs); 1964 player_.OnDemuxerConfigsAvailable(configs);
2085 CreateNextTextureAndSetVideoSurface(); 1965 CreateNextTextureAndSetVideoSurface();
2086 EXPECT_FALSE(IsPendingSurfaceChange()); 1966 EXPECT_FALSE(IsPendingSurfaceChange());
2087 EXPECT_FALSE(GetMediaDecoderJob(false)); 1967 EXPECT_FALSE(GetMediaDecoderJob(false));
2088 } 1968 }
2089 1969
2090 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) { 1970 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) {
2091 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1971 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
2092 1972
2093 // Test that current time is updated while decoder is starved. 1973 // Test that current time is updated while decoder is starved.
2094 StartAudioDecoderJob(true); 1974 StartAudioDecoderJob();
2095 DecodeAudioDataUntilOutputBecomesAvailable(); 1975 DecodeAudioDataUntilOutputBecomesAvailable();
2096 1976
2097 // Trigger starvation while the decoder is decoding. 1977 // Trigger starvation while the decoder is decoding.
2098 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1978 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
2099 manager_.ResetTimestampUpdated(); 1979 manager_.ResetTimestampUpdated();
2100 TriggerPlayerStarvation(); 1980 TriggerPlayerStarvation();
2101 WaitForAudioDecodeDone(); 1981 WaitForAudioDecodeDone();
2102 1982
2103 // Current time should be updated. 1983 // Current time should be updated.
2104 EXPECT_TRUE(manager_.timestamp_updated()); 1984 EXPECT_TRUE(manager_.timestamp_updated());
2105 } 1985 }
2106 1986
2107 TEST_F(MediaSourcePlayerTest, CurrentTimeKeepsIncreasingAfterConfigChange) { 1987 TEST_F(MediaSourcePlayerTest, CurrentTimeKeepsIncreasingAfterConfigChange) {
2108 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1988 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
2109 1989
2110 // Test current time keep on increasing after audio config change. 1990 // Test current time keep on increasing after audio config change.
2111 // Test that current time is updated while decoder is starved. 1991 // Test that current time is updated while decoder is starved.
2112 StartAudioDecoderJob(true); 1992 StartAudioDecoderJob();
2113 1993
2114 DecodeAudioDataUntilOutputBecomesAvailable(); 1994 DecodeAudioDataUntilOutputBecomesAvailable();
2115 1995
2116 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); 1996 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0);
2117 player_.OnDemuxerDataAvailable(data); 1997 player_.OnDemuxerDataAvailable(data);
2118 WaitForAudioDecodeDone(); 1998 WaitForAudioDecodeDone();
2119
2120 // Simulate arrival of new configs.
2121 player_.OnDemuxerConfigsAvailable(CreateAudioDemuxerConfigs(kCodecVorbis));
2122 DecodeAudioDataUntilOutputBecomesAvailable(); 1999 DecodeAudioDataUntilOutputBecomesAvailable();
2123 } 2000 }
2124 2001
2125 } // namespace media 2002 } // 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