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

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