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

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

Issue 254473010: Refactor MSE implementation on Android to simplify the logic and improve the performance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase after recent config IPC change 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"
11 #include "media/base/android/audio_decoder_job.h"
11 #include "media/base/android/media_codec_bridge.h" 12 #include "media/base/android/media_codec_bridge.h"
12 #include "media/base/android/media_drm_bridge.h" 13 #include "media/base/android/media_drm_bridge.h"
13 #include "media/base/android/media_player_manager.h" 14 #include "media/base/android/media_player_manager.h"
14 #include "media/base/android/media_source_player.h" 15 #include "media/base/android/media_source_player.h"
16 #include "media/base/android/video_decoder_job.h"
15 #include "media/base/bind_to_current_loop.h" 17 #include "media/base/bind_to_current_loop.h"
16 #include "media/base/decoder_buffer.h" 18 #include "media/base/decoder_buffer.h"
17 #include "media/base/test_data_util.h" 19 #include "media/base/test_data_util.h"
18 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
19 #include "ui/gl/android/surface_texture.h" 21 #include "ui/gl/android/surface_texture.h"
20 22
21 namespace media { 23 namespace media {
22 24
23 // Helper macro to skip the test if MediaCodecBridge isn't available. 25 // Helper macro to skip the test if MediaCodecBridge isn't available.
24 #define SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE() \ 26 #define SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE() \
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // Get the decoder job from the MediaSourcePlayer. 191 // Get the decoder job from the MediaSourcePlayer.
190 MediaDecoderJob* GetMediaDecoderJob(bool is_audio) { 192 MediaDecoderJob* GetMediaDecoderJob(bool is_audio) {
191 if (is_audio) { 193 if (is_audio) {
192 return reinterpret_cast<MediaDecoderJob*>( 194 return reinterpret_cast<MediaDecoderJob*>(
193 player_.audio_decoder_job_.get()); 195 player_.audio_decoder_job_.get());
194 } 196 }
195 return reinterpret_cast<MediaDecoderJob*>( 197 return reinterpret_cast<MediaDecoderJob*>(
196 player_.video_decoder_job_.get()); 198 player_.video_decoder_job_.get());
197 } 199 }
198 200
201 // Get the MediaCodecBridge from the decoder job.
202 MediaCodecBridge* GetMediaCodecBridge(bool is_audio) {
203 if (is_audio)
204 return player_.audio_decoder_job_->media_codec_bridge_.get();
205 return player_.video_decoder_job_->media_codec_bridge_.get();
206 }
207
199 // Get the per-job prerolling status from the MediaSourcePlayer's job matching 208 // Get the per-job prerolling status from the MediaSourcePlayer's job matching
200 // |is_audio|. Caller must guard against NPE if the player's job is NULL. 209 // |is_audio|. Caller must guard against NPE if the player's job is NULL.
201 bool IsPrerolling(bool is_audio) { 210 bool IsPrerolling(bool is_audio) {
202 return GetMediaDecoderJob(is_audio)->prerolling(); 211 return GetMediaDecoderJob(is_audio)->prerolling_;
203 } 212 }
204 213
205 // Get the preroll timestamp from the MediaSourcePlayer. 214 // Get the preroll timestamp from the MediaSourcePlayer.
206 base::TimeDelta GetPrerollTimestamp() { 215 base::TimeDelta GetPrerollTimestamp() {
207 return player_.preroll_timestamp_; 216 return player_.preroll_timestamp_;
208 } 217 }
209 218
210 // Simulate player has reached starvation timeout. 219 // Simulate player has reached starvation timeout.
211 void TriggerPlayerStarvation() { 220 void TriggerPlayerStarvation() {
212 player_.decoder_starvation_callback_.Cancel(); 221 player_.decoder_starvation_callback_.Cancel();
213 player_.OnDecoderStarved(); 222 player_.OnDecoderStarved();
214 } 223 }
215 224
216 // Release() the player. 225 // Release() the player.
217 void ReleasePlayer() { 226 void ReleasePlayer() {
218 EXPECT_TRUE(player_.IsPlaying()); 227 EXPECT_TRUE(player_.IsPlaying());
219 player_.Release(); 228 player_.Release();
220 EXPECT_FALSE(player_.IsPlaying()); 229 EXPECT_FALSE(player_.IsPlaying());
221 EXPECT_FALSE(GetMediaDecoderJob(true));
222 EXPECT_FALSE(GetMediaDecoderJob(false));
223 } 230 }
224 231
225 // Upon the next successful decode callback, post a task to call Release() 232 // Upon the next successful decode callback, post a task to call Release()
226 // on the |player_|. TEST_F's do not have access to the private player 233 // on the |player_|. TEST_F's do not have access to the private player
227 // members, hence this helper method. 234 // members, hence this helper method.
228 // Prevent usage creep of MSP::set_decode_callback_for_testing() by 235 // Prevent usage creep of MSP::set_decode_callback_for_testing() by
229 // only using it for the ReleaseWithOnPrefetchDoneAlreadyPosted test. 236 // only using it for the ReleaseWithOnPrefetchDoneAlreadyPosted test.
230 void OnNextTestDecodeCallbackPostTaskToReleasePlayer() { 237 void OnNextTestDecodeCallbackPostTaskToReleasePlayer() {
231 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); 238 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
232 player_.set_decode_callback_for_testing(media::BindToCurrentLoop( 239 player_.set_decode_callback_for_testing(media::BindToCurrentLoop(
233 base::Bind( 240 base::Bind(
234 &MediaSourcePlayerTest::ReleaseWithPendingPrefetchDoneVerification, 241 &MediaSourcePlayerTest::ReleaseWithPendingPrefetchDoneVerification,
235 base::Unretained(this)))); 242 base::Unretained(this))));
236 } 243 }
237 244
238 // Asynch test callback posted upon decode completion to verify that a pending 245 // Asynch test callback posted upon decode completion to verify that a pending
239 // prefetch done event is cleared across |player_|'s Release(). This helps 246 // prefetch done event is not cleared across |player_|'s Release(). This helps
240 // ensure the ReleaseWithOnPrefetchDoneAlreadyPosted test scenario is met. 247 // ensure the ReleaseWithOnPrefetchDoneAlreadyPosted test scenario is met.
241 void ReleaseWithPendingPrefetchDoneVerification() { 248 void ReleaseWithPendingPrefetchDoneVerification() {
242 EXPECT_TRUE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING)); 249 EXPECT_TRUE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING));
243 ReleasePlayer(); 250 ReleasePlayer();
244 EXPECT_FALSE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING)); 251 EXPECT_TRUE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING));
245 EXPECT_FALSE(decoder_callback_hook_executed_); 252 EXPECT_FALSE(decoder_callback_hook_executed_);
253 EXPECT_FALSE(GetMediaCodecBridge(true));
246 decoder_callback_hook_executed_ = true; 254 decoder_callback_hook_executed_ = true;
247 } 255 }
248 256
249 // Inspect internal pending_event_ state of |player_|. This is for infrequent
250 // use by tests, only where required.
251 bool IsPendingSurfaceChange() {
252 return player_.IsEventPending(player_.SURFACE_CHANGE_EVENT_PENDING);
253 }
254
255 DemuxerConfigs CreateAudioDemuxerConfigs(AudioCodec audio_codec) { 257 DemuxerConfigs CreateAudioDemuxerConfigs(AudioCodec audio_codec) {
256 DemuxerConfigs configs; 258 DemuxerConfigs configs;
257 configs.audio_codec = audio_codec; 259 configs.audio_codec = audio_codec;
258 configs.audio_channels = 2; 260 configs.audio_channels = 2;
259 configs.is_audio_encrypted = false; 261 configs.is_audio_encrypted = false;
260 configs.duration = kDefaultDuration; 262 configs.duration = kDefaultDuration;
261 263
262 if (audio_codec == kCodecVorbis) { 264 if (audio_codec == kCodecVorbis) {
263 configs.audio_sampling_rate = 44100; 265 configs.audio_sampling_rate = 44100;
264 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile( 266 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(
265 "vorbis-extradata"); 267 "vorbis-extradata");
266 configs.audio_extra_data = std::vector<uint8>( 268 configs.audio_extra_data = std::vector<uint8>(
267 buffer->data(), 269 buffer->data(),
268 buffer->data() + buffer->data_size()); 270 buffer->data() + buffer->data_size());
269 return configs; 271 return configs;
270 } 272 }
271 273
272 // Other codecs are not yet supported by this helper. 274 // Other codecs are not yet supported by this helper.
273 EXPECT_EQ(audio_codec, kCodecAAC); 275 EXPECT_EQ(audio_codec, kCodecAAC);
274 276
275 configs.audio_sampling_rate = 48000; 277 configs.audio_sampling_rate = 48000;
276 uint8 aac_extra_data[] = { 0x13, 0x10 }; 278 uint8 aac_extra_data[] = { 0x13, 0x10 };
277 configs.audio_extra_data = std::vector<uint8>( 279 configs.audio_extra_data = std::vector<uint8>(
278 aac_extra_data, 280 aac_extra_data,
279 aac_extra_data + 2); 281 aac_extra_data + 2);
280 return configs; 282 return configs;
281 } 283 }
282 284
283 DemuxerConfigs CreateVideoDemuxerConfigs() { 285 DemuxerConfigs CreateVideoDemuxerConfigs(VideoCodec video_codec) {
284 DemuxerConfigs configs; 286 DemuxerConfigs configs;
285 configs.video_codec = kCodecVP8; 287 configs.video_codec = video_codec;
286 configs.video_size = gfx::Size(320, 240); 288 configs.video_size = gfx::Size(320, 240);
287 configs.is_video_encrypted = false; 289 configs.is_video_encrypted = false;
288 configs.duration = kDefaultDuration; 290 configs.duration = kDefaultDuration;
289 return configs; 291 return configs;
290 } 292 }
291 293
292 DemuxerConfigs CreateAudioVideoDemuxerConfigs() { 294 DemuxerConfigs CreateAudioVideoDemuxerConfigs() {
293 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 295 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis);
294 configs.video_codec = kCodecVP8; 296 configs.video_codec = kCodecVP8;
295 configs.video_size = gfx::Size(320, 240); 297 configs.video_size = gfx::Size(320, 240);
296 configs.is_video_encrypted = false; 298 configs.is_video_encrypted = false;
297 return configs; 299 return configs;
298 } 300 }
299 301
300 DemuxerConfigs CreateDemuxerConfigs(bool have_audio, bool have_video) { 302 DemuxerConfigs CreateDemuxerConfigs(bool have_audio, bool have_video) {
301 DCHECK(have_audio || have_video); 303 DCHECK(have_audio || have_video);
302 304
303 if (have_audio && !have_video) 305 if (have_audio && !have_video)
304 return CreateAudioDemuxerConfigs(kCodecVorbis); 306 return CreateAudioDemuxerConfigs(kCodecVorbis);
305 307
306 if (have_video && !have_audio) 308 if (have_video && !have_audio)
307 return CreateVideoDemuxerConfigs(); 309 return CreateVideoDemuxerConfigs(kCodecVP8);
308 310
309 return CreateAudioVideoDemuxerConfigs(); 311 return CreateAudioVideoDemuxerConfigs();
310 } 312 }
311 313
312 // Starts an audio decoder job. 314 // Starts an audio decoder job.
313 void StartAudioDecoderJob() { 315 void StartAudioDecoderJob() {
314 Start(CreateAudioDemuxerConfigs(kCodecVorbis)); 316 Start(CreateAudioDemuxerConfigs(kCodecVorbis));
315 } 317 }
316 318
317 // Starts a video decoder job. 319 // Starts a video decoder job.
318 void StartVideoDecoderJob() { 320 void StartVideoDecoderJob() {
319 Start(CreateVideoDemuxerConfigs()); 321 Start(CreateVideoDemuxerConfigs(kCodecVP8));
320 } 322 }
321 323
322 // Starts decoding the data. 324 // Starts decoding the data.
323 void Start(const DemuxerConfigs& configs) { 325 void Start(const DemuxerConfigs& configs) {
324 EXPECT_EQ(demuxer_->num_data_requests(), 0); 326 EXPECT_EQ(demuxer_->num_data_requests(), 0);
325 player_.OnDemuxerConfigsAvailable(configs); 327 player_.OnDemuxerConfigsAvailable(configs);
326 player_.Start(); 328 player_.Start();
327 329
328 EXPECT_TRUE(player_.IsPlaying()); 330 EXPECT_TRUE(player_.IsPlaying());
329 int expected_num_requests = (GetMediaDecoderJob(true) ? 1 : 0) + 331 int expected_num_requests = (player_.HasAudio() ? 1 : 0) +
330 (GetMediaDecoderJob(false) ? 1 : 0); 332 (player_.HasVideo() ? 1 : 0);
331 EXPECT_EQ(expected_num_requests, demuxer_->num_data_requests()); 333 EXPECT_EQ(expected_num_requests, demuxer_->num_data_requests());
332 } 334 }
333 335
334 // Resumes decoding the data. Verifies player behavior relative to 336 // Resumes decoding the data. Verifies player behavior relative to
335 // |expect_player_requests_audio_data| and 337 // |expect_player_requests_audio_data| and
336 // |expect_player_requests_video_data|. 338 // |expect_player_requests_video_data|.
337 void Resume(bool expect_player_requests_audio_data, 339 void Resume(bool expect_player_requests_audio_data,
338 bool expect_player_requests_video_data) { 340 bool expect_player_requests_video_data) {
339 EXPECT_FALSE(player_.IsPlaying()); 341 EXPECT_FALSE(player_.IsPlaying());
340 EXPECT_TRUE(player_.HasVideo() || player_.HasAudio()); 342 EXPECT_TRUE(player_.HasVideo() || player_.HasAudio());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 434 }
433 435
434 // Helper method for use at test start. It starts an audio decoder job and 436 // Helper method for use at test start. It starts an audio decoder job and
435 // immediately feeds it some data to decode. Then, without letting the decoder 437 // immediately feeds it some data to decode. Then, without letting the decoder
436 // job complete a decode cycle, it also starts player SeekTo(). Upon return, 438 // job complete a decode cycle, it also starts player SeekTo(). Upon return,
437 // the player should not yet have sent the DemuxerSeek IPC request, though 439 // the player should not yet have sent the DemuxerSeek IPC request, though
438 // seek event should be pending. The audio decoder job will also still be 440 // seek event should be pending. The audio decoder job will also still be
439 // decoding. 441 // decoding.
440 void StartAudioDecoderJobAndSeekToWhileDecoding( 442 void StartAudioDecoderJobAndSeekToWhileDecoding(
441 const base::TimeDelta& seek_time) { 443 const base::TimeDelta& seek_time) {
442 EXPECT_FALSE(GetMediaDecoderJob(true)); 444 EXPECT_FALSE(GetMediaCodecBridge(true));
443 EXPECT_FALSE(player_.IsPlaying()); 445 EXPECT_FALSE(player_.IsPlaying());
444 EXPECT_EQ(0, demuxer_->num_data_requests()); 446 EXPECT_EQ(0, demuxer_->num_data_requests());
445 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); 447 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF());
446 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp()); 448 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp());
447 StartAudioDecoderJob(); 449 StartAudioDecoderJob();
448 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 450 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
449 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 451 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
450 EXPECT_EQ(2, demuxer_->num_data_requests()); 452 EXPECT_EQ(2, demuxer_->num_data_requests());
451 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 453 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
452 player_.SeekTo(seek_time); 454 player_.SeekTo(seek_time);
(...skipping 16 matching lines...) Expand all
469 player_.SeekTo(seek_time); 471 player_.SeekTo(seek_time);
470 472
471 // Verify that the seek does not occur until previously outstanding data 473 // Verify that the seek does not occur until previously outstanding data
472 // request is satisfied. 474 // request is satisfied.
473 EXPECT_EQ(original_num_seeks, demuxer_->num_seek_requests()); 475 EXPECT_EQ(original_num_seeks, demuxer_->num_seek_requests());
474 476
475 // Simulate seeking causes the demuxer to abort the outstanding read 477 // Simulate seeking causes the demuxer to abort the outstanding read
476 // caused by the seek. 478 // caused by the seek.
477 player_.OnDemuxerDataAvailable(CreateAbortedAck(is_audio)); 479 player_.OnDemuxerDataAvailable(CreateAbortedAck(is_audio));
478 480
481 // Wait for the decode job to finish so we can process the seek request.
482 WaitForDecodeDone(is_audio, !is_audio);
483
479 // Verify that the seek is requested. 484 // Verify that the seek is requested.
480 EXPECT_EQ(original_num_seeks + 1, demuxer_->num_seek_requests()); 485 EXPECT_EQ(original_num_seeks + 1, demuxer_->num_seek_requests());
481 486
482 // Send back the seek done notification. This should trigger the player to 487 // Send back the seek done notification. This should trigger the player to
483 // call OnReadFromDemuxer() again. 488 // call OnReadFromDemuxer() again.
484 EXPECT_EQ(original_num_data_requests, demuxer_->num_data_requests()); 489 EXPECT_EQ(original_num_data_requests, demuxer_->num_data_requests());
485 player_.OnDemuxerSeekDone(kNoTimestamp()); 490 player_.OnDemuxerSeekDone(kNoTimestamp());
486 EXPECT_EQ(original_num_data_requests + 1, demuxer_->num_data_requests()); 491 EXPECT_EQ(original_num_data_requests + 1, demuxer_->num_data_requests());
487 492
488 // No other seek should have been requested. 493 // No other seek should have been requested.
(...skipping 24 matching lines...) Expand all
513 base::TimeDelta::FromMilliseconds(current_timestamp); 518 base::TimeDelta::FromMilliseconds(current_timestamp);
514 player_.OnDemuxerDataAvailable(data); 519 player_.OnDemuxerDataAvailable(data);
515 EXPECT_TRUE(GetMediaDecoderJob(is_audio)->is_decoding()); 520 EXPECT_TRUE(GetMediaDecoderJob(is_audio)->is_decoding());
516 EXPECT_EQ(target_timestamp, player_.GetCurrentTime()); 521 EXPECT_EQ(target_timestamp, player_.GetCurrentTime());
517 current_timestamp += 30; 522 current_timestamp += 30;
518 WaitForDecodeDone(is_audio, !is_audio); 523 WaitForDecodeDone(is_audio, !is_audio);
519 } 524 }
520 EXPECT_LE(target_timestamp, player_.GetCurrentTime()); 525 EXPECT_LE(target_timestamp, player_.GetCurrentTime());
521 } 526 }
522 527
523 DemuxerData CreateReadFromDemuxerAckWithConfigChanged(bool is_audio, 528 DemuxerData CreateReadFromDemuxerAckWithConfigChanged(
524 int config_unit_index) { 529 bool is_audio,
530 int config_unit_index,
531 const DemuxerConfigs& configs) {
525 DemuxerData data; 532 DemuxerData data;
526 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO; 533 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO;
527 data.access_units.resize(config_unit_index + 1); 534 data.access_units.resize(config_unit_index + 1);
528 535
529 for (int i = 0; i < config_unit_index; ++i) 536 for (int i = 0; i < config_unit_index; ++i)
530 data.access_units[i] = CreateAccessUnitWithData(is_audio, i); 537 data.access_units[i] = CreateAccessUnitWithData(is_audio, i);
531 538
532 data.access_units[config_unit_index].status = DemuxerStream::kConfigChanged; 539 data.access_units[config_unit_index].status = DemuxerStream::kConfigChanged;
533 data.demuxer_configs.resize(1); 540 data.demuxer_configs.resize(1);
534 data.demuxer_configs[0] = CreateDemuxerConfigs(is_audio, !is_audio); 541 data.demuxer_configs[0] = configs;
535 return data; 542 return data;
536 } 543 }
537 544
538 // Valid only for video-only player tests. If |trigger_with_release_start| is 545 // Valid only for video-only player tests. If |trigger_with_release_start| is
539 // true, triggers the browser seek with a Release() + video data received + 546 // true, triggers the browser seek with a Release() + video data received +
540 // Start() with a new surface. If false, triggers the browser seek by 547 // Start() with a new surface. If false, triggers the browser seek by
541 // setting a new video surface after beginning decode of received video data. 548 // setting a new video surface after beginning decode of received video data.
542 // Such data receipt causes possibility that an I-frame is not next, and 549 // Such data receipt causes possibility that an I-frame is not next, and
543 // browser seek results once decode completes and surface change processing 550 // browser seek results once decode completes and surface change processing
544 // begins. 551 // begins.
545 void BrowserSeekPlayer(bool trigger_with_release_start) { 552 void BrowserSeekPlayer(bool trigger_with_release_start) {
546 int expected_num_data_requests = demuxer_->num_data_requests() + 553 int expected_num_data_requests = demuxer_->num_data_requests() + 2;
547 (trigger_with_release_start ? 1 : 2);
548 int expected_num_seek_requests = demuxer_->num_seek_requests(); 554 int expected_num_seek_requests = demuxer_->num_seek_requests();
549 int expected_num_browser_seek_requests = 555 int expected_num_browser_seek_requests =
550 demuxer_->num_browser_seek_requests(); 556 demuxer_->num_browser_seek_requests();
551 557
552 EXPECT_FALSE(GetMediaDecoderJob(false));
553 CreateNextTextureAndSetVideoSurface(); 558 CreateNextTextureAndSetVideoSurface();
554 StartVideoDecoderJob(); 559 StartVideoDecoderJob();
555 if (trigger_with_release_start) { 560 if (trigger_with_release_start) {
561 // Consume the first frame, so that the next VideoDecoderJob will not
562 // inherit the I-frame from the previous decoder.
563 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
556 ReleasePlayer(); 564 ReleasePlayer();
565 WaitForVideoDecodeDone();
566
557 // Simulate demuxer's response to the video data request. The data will be 567 // Simulate demuxer's response to the video data request. The data will be
558 // discarded. 568 // passed to the next MediaCodecBridge.
559 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 569 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
560 EXPECT_FALSE(GetMediaDecoderJob(false)); 570 EXPECT_FALSE(GetMediaCodecBridge(false));
561 EXPECT_FALSE(player_.IsPlaying()); 571 EXPECT_FALSE(player_.IsPlaying());
562 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 572 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
563 573
564 CreateNextTextureAndSetVideoSurface(); 574 CreateNextTextureAndSetVideoSurface();
565 Resume(false, false); 575 Resume(false, false);
566 EXPECT_FALSE(GetMediaDecoderJob(false)); 576 EXPECT_FALSE(GetMediaCodecBridge(false));
577
578 // Run the message loop so that prefetch will complete.
579 while (expected_num_seek_requests == demuxer_->num_seek_requests())
580 message_loop_.RunUntilIdle();
567 } else { 581 } else {
568 // Simulate demuxer's response to the video data request. 582 // Simulate demuxer's response to the video data request.
569 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 583 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
570 584
571 // While the decoder is decoding, trigger a browser seek by changing 585 // While the decoder is decoding, trigger a browser seek by changing
572 // surface. Demuxer does not know of browser seek in advance, so no 586 // surface. Demuxer does not know of browser seek in advance, so no
573 // |kAborted| data is required (though |kAborted| can certainly occur for 587 // |kAborted| data is required (though |kAborted| can certainly occur for
574 // any pending read in reality due to renderer preparing for a regular 588 // any pending read in reality due to renderer preparing for a regular
575 // seek). 589 // seek).
576 CreateNextTextureAndSetVideoSurface(); 590 CreateNextTextureAndSetVideoSurface();
577 591
578 // Browser seek should not begin until decoding has completed. 592 // Browser seek should not begin until decoding has completed.
579 EXPECT_TRUE(GetMediaDecoderJob(false)); 593 EXPECT_TRUE(GetMediaCodecBridge(false));
580 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 594 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
581 595
582 // Wait for the decoder job to finish decoding and be reset pending the 596 // Wait for the decoder job to finish decoding and be reset pending the
583 // browser seek. 597 // browser seek.
584 WaitForVideoDecodeDone(); 598 WaitForVideoDecodeDone();
585 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 599 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
586 } 600 }
587 601
588 // Only one browser seek should have been initiated, and no further data 602 // Only one browser seek should have been initiated, and no further data
589 // should have been requested. 603 // should have been requested.
590 expected_num_seek_requests++; 604 expected_num_seek_requests++;
591 expected_num_browser_seek_requests++; 605 expected_num_browser_seek_requests++;
592 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 606 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
593 EXPECT_EQ(expected_num_browser_seek_requests, 607 EXPECT_EQ(expected_num_browser_seek_requests,
594 demuxer_->num_browser_seek_requests()); 608 demuxer_->num_browser_seek_requests());
595 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); 609 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
596 } 610 }
597 611
598 // Creates a new decoder job and feeds it data ending with a |kConfigChanged| 612 // Creates a new decoder job and feeds it data ending with a |kConfigChanged|
599 // access unit. If |config_unit_in_prefetch| is true, sends feeds the config 613 // access unit. If |config_unit_in_prefetch| is true, sends feeds the config
600 // change AU in response to the job's first read request (prefetch). If 614 // change AU in response to the job's first read request (prefetch). If
601 // false, regular data is fed and decoded prior to feeding the config change 615 // false, regular data is fed and decoded prior to feeding the config change
602 // AU in response to the second data request (after prefetch completed). 616 // AU in response to the second data request (after prefetch completed).
603 // |config_unit_index| controls which access unit is |kConfigChanged|. 617 // |config_unit_index| controls which access unit is |kConfigChanged|.
604 void StartConfigChange(bool is_audio, 618 void SendConfigChangeToDecoder(bool is_audio,
605 bool config_unit_in_prefetch, 619 bool config_unit_in_prefetch,
606 int config_unit_index) { 620 int config_unit_index) {
607 EXPECT_FALSE(GetMediaDecoderJob(is_audio)); 621 EXPECT_FALSE(GetMediaCodecBridge(is_audio));
608 if (is_audio) { 622 if (is_audio) {
609 StartAudioDecoderJob(); 623 StartAudioDecoderJob();
610 } else { 624 } else {
611 CreateNextTextureAndSetVideoSurface(); 625 CreateNextTextureAndSetVideoSurface();
612 StartVideoDecoderJob(); 626 StartVideoDecoderJob();
613 } 627 }
614 628
615 int expected_num_data_requests = demuxer_->num_data_requests(); 629 int expected_num_data_requests = demuxer_->num_data_requests();
616
617 // Feed and decode a standalone access unit so the player exits prefetch. 630 // Feed and decode a standalone access unit so the player exits prefetch.
618 if (!config_unit_in_prefetch) { 631 if (!config_unit_in_prefetch) {
619 if (is_audio) 632 if (is_audio)
620 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 633 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
621 else 634 else
622 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 635 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
623 636
624 WaitForDecodeDone(is_audio, !is_audio); 637 WaitForDecodeDone(is_audio, !is_audio);
625 638
626 // We should have completed the prefetch phase at this point. 639 // We should have completed the prefetch phase at this point.
627 expected_num_data_requests++; 640 expected_num_data_requests++;
628 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); 641 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
629 } 642 }
630 643
644 DemuxerConfigs configs = is_audio ? CreateAudioDemuxerConfigs(kCodecAAC) :
645 CreateVideoDemuxerConfigs(kCodecVP9);
631 // Feed and decode access units with data for any units prior to 646 // Feed and decode access units with data for any units prior to
632 // |config_unit_index|, and a |kConfigChanged| unit at that index. 647 // |config_unit_index|, and a |kConfigChanged| unit at that index.
633 // Player should prepare to reconfigure the decoder job, and should request 648 // Player should prepare to reconfigure the decoder job, and should request
634 // new demuxer configs. 649 // new demuxer configs.
635 player_.OnDemuxerDataAvailable( 650 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
636 CreateReadFromDemuxerAckWithConfigChanged(is_audio, config_unit_index)); 651 is_audio, config_unit_index, configs));
652
653 expected_num_data_requests++;
654 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
655 if (is_audio)
656 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
657 else
658 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
659 }
660
661 // Send a config change to the decoder job and drain the decoder so that the
662 // config change is processed.
663 void StartConfigChange(bool is_audio,
664 bool config_unit_in_prefetch,
665 int config_unit_index) {
666 SendConfigChangeToDecoder(is_audio, config_unit_in_prefetch,
667 config_unit_index);
668 int expected_num_data_requests = demuxer_->num_data_requests();
637 // Run until decoder starts to request new data. 669 // Run until decoder starts to request new data.
638 while (demuxer_->num_data_requests() == expected_num_data_requests) 670 while (demuxer_->num_data_requests() == expected_num_data_requests)
639 message_loop_.RunUntilIdle(); 671 message_loop_.RunUntilIdle();
640 } 672 }
641 673
642 void CreateNextTextureAndSetVideoSurface() { 674 void CreateNextTextureAndSetVideoSurface() {
643 gfx::SurfaceTexture* surface_texture; 675 gfx::SurfaceTexture* surface_texture;
644 if (surface_texture_a_is_next_) { 676 if (surface_texture_a_is_next_) {
645 surface_texture_a_ = gfx::SurfaceTexture::Create(next_texture_id_++); 677 surface_texture_a_ = gfx::SurfaceTexture::Create(next_texture_id_++);
646 surface_texture = surface_texture_a_.get(); 678 surface_texture = surface_texture_a_.get();
647 } else { 679 } else {
648 surface_texture_b_ = gfx::SurfaceTexture::Create(next_texture_id_++); 680 surface_texture_b_ = gfx::SurfaceTexture::Create(next_texture_id_++);
649 surface_texture = surface_texture_b_.get(); 681 surface_texture = surface_texture_b_.get();
650 } 682 }
651 683
652 surface_texture_a_is_next_ = !surface_texture_a_is_next_; 684 surface_texture_a_is_next_ = !surface_texture_a_is_next_;
653 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture); 685 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture);
654 player_.SetVideoSurface(surface.Pass()); 686 player_.SetVideoSurface(surface.Pass());
655 } 687 }
656 688
657 // Wait for one or both of the jobs to complete decoding. Decoder jobs are 689 // Wait for one or both of the jobs to complete decoding. Decoder jobs are
658 // assumed to exist for any stream whose decode completion is awaited. 690 // assumed to exist for any stream whose decode completion is awaited.
659 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) { 691 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) {
660 DCHECK(wait_for_audio || wait_for_video); 692 DCHECK(wait_for_audio || wait_for_video);
661 while ((wait_for_audio && GetMediaDecoderJob(true) && 693 while ((wait_for_audio && GetMediaCodecBridge(true) &&
662 GetMediaDecoderJob(true)->HasData() && 694 GetMediaDecoderJob(true)->HasData() &&
663 GetMediaDecoderJob(true)->is_decoding()) || 695 GetMediaDecoderJob(true)->is_decoding()) ||
664 (wait_for_video && GetMediaDecoderJob(false) && 696 (wait_for_video && GetMediaCodecBridge(false) &&
665 GetMediaDecoderJob(false)->HasData() && 697 GetMediaDecoderJob(false)->HasData() &&
666 GetMediaDecoderJob(false)->is_decoding())) { 698 GetMediaDecoderJob(false)->is_decoding())) {
667 message_loop_.RunUntilIdle(); 699 message_loop_.RunUntilIdle();
668 } 700 }
669 } 701 }
670 702
671 void WaitForAudioDecodeDone() { 703 void WaitForAudioDecodeDone() {
672 WaitForDecodeDone(true, false); 704 WaitForDecodeDone(true, false);
673 } 705 }
674 706
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 EXPECT_EQ(1, demuxer_->num_seek_requests()); 789 EXPECT_EQ(1, demuxer_->num_seek_requests());
758 790
759 player_.OnDemuxerSeekDone(kNoTimestamp()); 791 player_.OnDemuxerSeekDone(kNoTimestamp());
760 EXPECT_FALSE(manager_.playback_completed()); 792 EXPECT_FALSE(manager_.playback_completed());
761 } 793 }
762 794
763 base::TimeTicks StartTimeTicks() { 795 base::TimeTicks StartTimeTicks() {
764 return player_.start_time_ticks_; 796 return player_.start_time_ticks_;
765 } 797 }
766 798
799 bool IsRequestingDemuxerData(bool is_audio) {
800 return GetMediaDecoderJob(is_audio)->is_requesting_demuxer_data_;
801 }
802
803 bool IsDrainingDecoder(bool is_audio) {
804 return GetMediaDecoderJob(is_audio)->drain_decoder_;
805 }
806
767 base::MessageLoop message_loop_; 807 base::MessageLoop message_loop_;
768 MockMediaPlayerManager manager_; 808 MockMediaPlayerManager manager_;
769 MockDemuxerAndroid* demuxer_; // Owned by |player_|. 809 MockDemuxerAndroid* demuxer_; // Owned by |player_|.
770 MediaSourcePlayer player_; 810 MediaSourcePlayer player_;
771 811
772 // Track whether a possibly async decoder callback test hook has run. 812 // Track whether a possibly async decoder callback test hook has run.
773 bool decoder_callback_hook_executed_; 813 bool decoder_callback_hook_executed_;
774 814
775 // We need to keep the surface texture while the decoder is actively decoding. 815 // We need to keep the surface texture while the decoder is actively decoding.
776 // Otherwise, it may trigger unexpected crashes on some devices. To switch 816 // Otherwise, it may trigger unexpected crashes on some devices. To switch
(...skipping 28 matching lines...) Expand all
805 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; 845 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff };
806 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), 846 configs.audio_extra_data.insert(configs.audio_extra_data.begin(),
807 invalid_codec_data, invalid_codec_data + 4); 847 invalid_codec_data, invalid_codec_data + 4);
808 Start(configs); 848 Start(configs);
809 EXPECT_EQ(0, demuxer_->num_seek_requests()); 849 EXPECT_EQ(0, demuxer_->num_seek_requests());
810 } 850 }
811 851
812 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { 852 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) {
813 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 853 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
814 854
815 // Test video decoder job will be created when surface is valid. 855 // Test video decoder job will not be created until data is received.
816 // Video decoder job will not be created until surface is available.
817 StartVideoDecoderJob(); 856 StartVideoDecoderJob();
818 857
819 // Set both an initial and a later video surface without receiving any 858 // Set both an initial and a later video surface without receiving any
820 // demuxed data yet. 859 // demuxed data yet.
821 CreateNextTextureAndSetVideoSurface(); 860 CreateNextTextureAndSetVideoSurface();
822 MediaDecoderJob* first_job = GetMediaDecoderJob(false); 861 EXPECT_FALSE(GetMediaCodecBridge(false));
823 EXPECT_TRUE(first_job);
824 CreateNextTextureAndSetVideoSurface(); 862 CreateNextTextureAndSetVideoSurface();
825 863 EXPECT_FALSE(GetMediaCodecBridge(false));
826 // Setting another surface will not create a new job until any pending
827 // read is satisfied (and job is no longer decoding).
828 EXPECT_EQ(first_job, GetMediaDecoderJob(false));
829 864
830 // No seeks, even on setting surface, should have occurred. (Browser seeks can 865 // No seeks, even on setting surface, should have occurred. (Browser seeks can
831 // occur on setting surface, but only after previously receiving video data.) 866 // occur on setting surface, but only after previously receiving video data.)
832 EXPECT_EQ(0, demuxer_->num_seek_requests()); 867 EXPECT_EQ(0, demuxer_->num_seek_requests());
833 868
834 // Note, the decoder job for the second surface set, above, will be created 869 // Send the first input chunk and verify that decoder will be created.
835 // only after the pending read is satisfied and decoded, and the resulting 870 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
836 // browser seek is done. See BrowserSeek_* tests for this coverage. 871 EXPECT_TRUE(GetMediaCodecBridge(false));
837 } 872 }
838 873
839 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { 874 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) {
840 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 875 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
841 876
842 // Test video decoder job will not be created when surface is invalid. 877 // Test video decoder job will not be created when surface is invalid.
843 scoped_refptr<gfx::SurfaceTexture> surface_texture( 878 scoped_refptr<gfx::SurfaceTexture> surface_texture(
844 gfx::SurfaceTexture::Create(0)); 879 gfx::SurfaceTexture::Create(0));
845 gfx::ScopedJavaSurface surface(surface_texture.get()); 880 gfx::ScopedJavaSurface surface(surface_texture.get());
846 StartVideoDecoderJob(); 881 StartVideoDecoderJob();
847 882
848 // Release the surface texture. 883 // Release the surface texture.
849 surface_texture = NULL; 884 surface_texture = NULL;
850 player_.SetVideoSurface(surface.Pass()); 885 player_.SetVideoSurface(surface.Pass());
851 886
852 // Player should not seek the demuxer on setting initial surface. 887 // Player should not seek the demuxer on setting initial surface.
853 EXPECT_EQ(0, demuxer_->num_seek_requests()); 888 EXPECT_EQ(0, demuxer_->num_seek_requests());
854 889 EXPECT_FALSE(GetMediaCodecBridge(false));
855 EXPECT_FALSE(GetMediaDecoderJob(false));
856 EXPECT_EQ(0, demuxer_->num_data_requests());
857 } 890 }
858 891
859 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) { 892 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) {
860 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 893 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
861 894
862 // Test decoder job will resend a ReadFromDemuxer request after seek. 895 // Test decoder job will resend a ReadFromDemuxer request after seek.
863 StartAudioDecoderJob(); 896 StartAudioDecoderJob();
864 SeekPlayerWithAbort(true, base::TimeDelta()); 897 SeekPlayerWithAbort(true, base::TimeDelta());
865 } 898 }
866 899
867 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { 900 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) {
868 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 901 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
869 902
870 // Test SetVideoSurface() will not cause an extra seek while the player is 903 // Test SetVideoSurface() will not cause an extra seek while the player is
871 // waiting for demuxer to indicate seek is done. 904 // waiting for demuxer to indicate seek is done.
872 // Player is still waiting for SetVideoSurface(), so no request is sent. 905 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs(kCodecVP8));
873 StartVideoDecoderJob(); // Verifies no data requested.
874 906
875 // Initiate a seek. Skip requesting element seek of renderer. 907 // Initiate a seek. Skip requesting element seek of renderer.
876 // Instead behave as if the renderer has asked us to seek. 908 // Instead behave as if the renderer has asked us to seek.
877 EXPECT_EQ(0, demuxer_->num_seek_requests());
878 player_.SeekTo(base::TimeDelta()); 909 player_.SeekTo(base::TimeDelta());
879 EXPECT_EQ(1, demuxer_->num_seek_requests()); 910 EXPECT_EQ(1, demuxer_->num_seek_requests());
880 911
881 CreateNextTextureAndSetVideoSurface(); 912 CreateNextTextureAndSetVideoSurface();
882 EXPECT_FALSE(GetMediaDecoderJob(false));
883 EXPECT_EQ(1, demuxer_->num_seek_requests()); 913 EXPECT_EQ(1, demuxer_->num_seek_requests());
884 914 player_.Start();
885 // Reconfirm player has not yet requested data.
886 EXPECT_EQ(0, demuxer_->num_data_requests());
887 915
888 // Send the seek done notification. The player should start requesting data. 916 // Send the seek done notification. The player should start requesting data.
889 player_.OnDemuxerSeekDone(kNoTimestamp()); 917 player_.OnDemuxerSeekDone(kNoTimestamp());
890 EXPECT_TRUE(GetMediaDecoderJob(false)); 918 EXPECT_FALSE(GetMediaCodecBridge(false));
891 EXPECT_EQ(1, demuxer_->num_data_requests()); 919 EXPECT_EQ(1, demuxer_->num_data_requests());
920 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
921 EXPECT_TRUE(GetMediaCodecBridge(false));
892 922
893 // Reconfirm exactly 1 seek request has been made of demuxer, and that it 923 // Reconfirm exactly 1 seek request has been made of demuxer, and that it
894 // was not a browser seek request. 924 // was not a browser seek request.
895 EXPECT_EQ(1, demuxer_->num_seek_requests()); 925 EXPECT_EQ(1, demuxer_->num_seek_requests());
896 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 926 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
897 } 927 }
898 928
899 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) { 929 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) {
900 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 930 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
901 931
902 // Test MediaSourcePlayer can switch multiple surfaces during decoding. 932 // Test MediaSourcePlayer can switch multiple surfaces during decoding.
903 CreateNextTextureAndSetVideoSurface(); 933 CreateNextTextureAndSetVideoSurface();
904 StartVideoDecoderJob(); 934 StartVideoDecoderJob();
905 EXPECT_EQ(0, demuxer_->num_seek_requests()); 935 EXPECT_EQ(0, demuxer_->num_seek_requests());
906 936
907 // Send the first input chunk. 937 // Send the first input chunk.
908 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 938 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
909 939
910 // While the decoder is decoding, change multiple surfaces. Pass an empty 940 // While the decoder is decoding, change multiple surfaces. Pass an empty
911 // surface first. 941 // surface first.
912 gfx::ScopedJavaSurface empty_surface; 942 gfx::ScopedJavaSurface empty_surface;
913 player_.SetVideoSurface(empty_surface.Pass()); 943 player_.SetVideoSurface(empty_surface.Pass());
914 // Next, pass a new non-empty surface. 944 // Next, pass a new non-empty surface.
915 CreateNextTextureAndSetVideoSurface(); 945 CreateNextTextureAndSetVideoSurface();
916 946
917 // Wait for the decoder job to finish decoding and be reset pending a browser 947 // Wait for the decoder job to finish decoding and be reset pending a browser
918 // seek. 948 // seek.
919 WaitForVideoDecodeDone(); 949 WaitForVideoDecodeDone();
920 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 950 player_.OnDemuxerDataAvailable(CreateAbortedAck(false));
921 951
922 // Only one browser seek should have been initiated. No further data request 952 // Only one browser seek should have been initiated. No further data request
923 // should have been processed on |message_loop_| before surface change event 953 // should have been processed on |message_loop_| before surface change event
924 // became pending, above. 954 // became pending, above.
925 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 955 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
926 EXPECT_EQ(2, demuxer_->num_data_requests()); 956 EXPECT_EQ(2, demuxer_->num_data_requests());
927 957
928 // Simulate browser seek is done and confirm player requests more data for new 958 // Simulate browser seek is done and confirm player requests more data for new
929 // video decoder job. 959 // video decoder job.
930 player_.OnDemuxerSeekDone(player_.GetCurrentTime()); 960 player_.OnDemuxerSeekDone(player_.GetCurrentTime());
931 EXPECT_TRUE(GetMediaDecoderJob(false)); 961 EXPECT_FALSE(GetMediaCodecBridge(false));
932 EXPECT_EQ(3, demuxer_->num_data_requests()); 962 EXPECT_EQ(3, demuxer_->num_data_requests());
933 EXPECT_EQ(1, demuxer_->num_seek_requests()); 963 EXPECT_EQ(1, demuxer_->num_seek_requests());
964
965 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
966 EXPECT_TRUE(GetMediaCodecBridge(false));
934 } 967 }
935 968
936 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) { 969 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) {
937 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 970 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
938 971
939 // Test player pauses if an empty surface is passed. 972 // Test player pauses if an empty surface is passed.
940 CreateNextTextureAndSetVideoSurface(); 973 CreateNextTextureAndSetVideoSurface();
941 StartVideoDecoderJob(); 974 StartVideoDecoderJob();
942 EXPECT_EQ(1, demuxer_->num_data_requests()); 975 EXPECT_EQ(1, demuxer_->num_data_requests());
943 976
944 // Send the first input chunk. 977 // Send the first input chunk.
945 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 978 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
946 979
947 // While the decoder is decoding, pass an empty surface. 980 // While the decoder is decoding, pass an empty surface.
948 gfx::ScopedJavaSurface empty_surface; 981 gfx::ScopedJavaSurface empty_surface;
949 player_.SetVideoSurface(empty_surface.Pass()); 982 player_.SetVideoSurface(empty_surface.Pass());
950 // Let the player starve. However, it should not issue any new data request in 983 // Let the player starve. However, it should not issue any new data request in
951 // this case. 984 // this case.
952 TriggerPlayerStarvation(); 985 TriggerPlayerStarvation();
953 // Wait for the decoder job to finish decoding and be reset. 986 // Wait for the decoder job to finish decoding and be reset.
954 while (GetMediaDecoderJob(false)) 987 while (GetMediaDecoderJob(false)->is_decoding())
955 message_loop_.RunUntilIdle(); 988 message_loop_.RunUntilIdle();
956 989
957 // No further seek or data requests should have been received since the 990 // No further seek or data requests should have been received since the
958 // surface is empty. 991 // surface is empty.
959 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 992 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
960 EXPECT_EQ(2, demuxer_->num_data_requests()); 993 EXPECT_EQ(2, demuxer_->num_data_requests());
961 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 994 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
962 995
963 // Playback resumes once a non-empty surface is passed. 996 // Playback resumes once a non-empty surface is passed.
964 CreateNextTextureAndSetVideoSurface(); 997 CreateNextTextureAndSetVideoSurface();
965 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 998 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
966 } 999 }
967 1000
968 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { 1001 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) {
969 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1002 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
970 1003
971 // Test that if video decoder is released while decoding, the resources will 1004 // Test that if video decoder is released while decoding, the resources will
972 // not be immediately released. 1005 // not be immediately released.
973 CreateNextTextureAndSetVideoSurface(); 1006 CreateNextTextureAndSetVideoSurface();
974 StartVideoDecoderJob(); 1007 StartVideoDecoderJob();
975 EXPECT_EQ(1, manager_.num_resources_requested()); 1008 // No resource is requested since there is no data to decode.
1009 EXPECT_EQ(0, manager_.num_resources_requested());
976 ReleasePlayer(); 1010 ReleasePlayer();
977 // The resources will be immediately released since the decoder is idle. 1011 EXPECT_EQ(0, manager_.num_resources_released());
978 EXPECT_EQ(1, manager_.num_resources_released());
979 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1012 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
980 1013
981 // Recreate the video decoder. 1014 // Recreate the video decoder.
982 CreateNextTextureAndSetVideoSurface(); 1015 CreateNextTextureAndSetVideoSurface();
983 player_.Start(); 1016 player_.Start();
984 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1017 while (!GetMediaDecoderJob(false)->is_decoding())
985 player_.OnDemuxerSeekDone(base::TimeDelta()); 1018 message_loop_.RunUntilIdle();
986 EXPECT_EQ(2, manager_.num_resources_requested()); 1019 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
987 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1020 EXPECT_EQ(1, manager_.num_resources_requested());
988 ReleasePlayer(); 1021 ReleasePlayer();
989 // The resource is still held by the video decoder until it finishes decoding. 1022 // The resource is still held by the video decoder until it finishes decoding.
990 EXPECT_EQ(1, manager_.num_resources_released()); 1023 EXPECT_EQ(0, manager_.num_resources_released());
991 // Wait for the decoder job to finish decoding and be reset. 1024 // Wait for the decoder job to finish decoding and be reset.
992 while (manager_.num_resources_released() != 2) 1025 while (manager_.num_resources_released() != 1)
993 message_loop_.RunUntilIdle(); 1026 message_loop_.RunUntilIdle();
994 } 1027 }
995 1028
996 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) { 1029 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) {
997 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1030 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
998 1031
999 // Test audio decoder job will not start until pending seek event is handled. 1032 // Test audio decoder job will not start until pending seek event is handled.
1000 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 1033 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis);
1001 player_.OnDemuxerConfigsAvailable(configs); 1034 player_.OnDemuxerConfigsAvailable(configs);
1002 EXPECT_FALSE(GetMediaDecoderJob(true));
1003 1035
1004 // Initiate a seek. Skip requesting element seek of renderer. 1036 // Initiate a seek. Skip requesting element seek of renderer.
1005 // Instead behave as if the renderer has asked us to seek. 1037 // Instead behave as if the renderer has asked us to seek.
1006 player_.SeekTo(base::TimeDelta()); 1038 player_.SeekTo(base::TimeDelta());
1007 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1039 EXPECT_EQ(1, demuxer_->num_seek_requests());
1008 1040
1009 player_.Start(); 1041 player_.Start();
1010 EXPECT_FALSE(GetMediaDecoderJob(true));
1011 EXPECT_EQ(0, demuxer_->num_data_requests()); 1042 EXPECT_EQ(0, demuxer_->num_data_requests());
1012 1043
1013 // Sending back the seek done notification. 1044 // Sending back the seek done notification.
1014 player_.OnDemuxerSeekDone(kNoTimestamp()); 1045 player_.OnDemuxerSeekDone(kNoTimestamp());
1015 EXPECT_TRUE(GetMediaDecoderJob(true)); 1046 EXPECT_FALSE(GetMediaCodecBridge(true));
1016 EXPECT_EQ(1, demuxer_->num_data_requests()); 1047 EXPECT_EQ(1, demuxer_->num_data_requests());
1017 1048
1018 // Reconfirm exactly 1 seek request has been made of demuxer. 1049 // Reconfirm exactly 1 seek request has been made of demuxer.
1019 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1050 EXPECT_EQ(1, demuxer_->num_seek_requests());
1051
1052 // Decoder is created after data is received.
1053 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1054 EXPECT_TRUE(GetMediaCodecBridge(true));
1020 } 1055 }
1021 1056
1022 TEST_F(MediaSourcePlayerTest, VideoOnlyStartAfterSeekFinish) { 1057 TEST_F(MediaSourcePlayerTest, VideoOnlyStartAfterSeekFinish) {
1023 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1058 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1024 1059
1025 // Test video decoder job will not start until pending seek event is handled. 1060 // Test video decoder job will not start until pending seek event is handled.
1026 CreateNextTextureAndSetVideoSurface(); 1061 CreateNextTextureAndSetVideoSurface();
1027 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); 1062 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP8);
1028 player_.OnDemuxerConfigsAvailable(configs); 1063 player_.OnDemuxerConfigsAvailable(configs);
1029 EXPECT_FALSE(GetMediaDecoderJob(false));
1030 1064
1031 // Initiate a seek. Skip requesting element seek of renderer. 1065 // Initiate a seek. Skip requesting element seek of renderer.
1032 // Instead behave as if the renderer has asked us to seek. 1066 // Instead behave as if the renderer has asked us to seek.
1033 player_.SeekTo(base::TimeDelta()); 1067 player_.SeekTo(base::TimeDelta());
1034 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1068 EXPECT_EQ(1, demuxer_->num_seek_requests());
1035 1069
1036 player_.Start(); 1070 player_.Start();
1037 EXPECT_FALSE(GetMediaDecoderJob(false));
1038 EXPECT_EQ(0, demuxer_->num_data_requests()); 1071 EXPECT_EQ(0, demuxer_->num_data_requests());
1039 1072
1040 // Sending back the seek done notification. 1073 // Sending back the seek done notification.
1041 player_.OnDemuxerSeekDone(kNoTimestamp()); 1074 player_.OnDemuxerSeekDone(kNoTimestamp());
1042 EXPECT_TRUE(GetMediaDecoderJob(false)); 1075 EXPECT_FALSE(GetMediaCodecBridge(false));
1043 EXPECT_EQ(1, demuxer_->num_data_requests()); 1076 EXPECT_EQ(1, demuxer_->num_data_requests());
1044 1077
1045 // Reconfirm exactly 1 seek request has been made of demuxer. 1078 // Reconfirm exactly 1 seek request has been made of demuxer.
1046 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1079 EXPECT_EQ(1, demuxer_->num_seek_requests());
1080
1081 // Decoder is created after data is received.
1082 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1083 EXPECT_TRUE(GetMediaCodecBridge(false));
1047 } 1084 }
1048 1085
1049 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) { 1086 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) {
1050 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1087 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1051 1088
1052 // Test that if the decoding job is not fully stopped after Pause(), 1089 // Test that if the decoding job is not fully stopped after Pause(),
1053 // calling Start() will be a noop. 1090 // calling Start() will be a noop.
1054 StartAudioDecoderJob(); 1091 StartAudioDecoderJob();
1055 1092
1056 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 1093 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true);
(...skipping 11 matching lines...) Expand all
1068 1105
1069 // Nothing happens when calling Start() again. 1106 // Nothing happens when calling Start() again.
1070 player_.Start(); 1107 player_.Start();
1071 // Verify that Start() will not destroy and recreate the decoder job. 1108 // Verify that Start() will not destroy and recreate the decoder job.
1072 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 1109 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
1073 1110
1074 while (GetMediaDecoderJob(true)->is_decoding()) 1111 while (GetMediaDecoderJob(true)->is_decoding())
1075 message_loop_.RunUntilIdle(); 1112 message_loop_.RunUntilIdle();
1076 // The decoder job should finish and wait for data. 1113 // The decoder job should finish and wait for data.
1077 EXPECT_EQ(2, demuxer_->num_data_requests()); 1114 EXPECT_EQ(2, demuxer_->num_data_requests());
1078 EXPECT_TRUE(GetMediaDecoderJob(true)->is_requesting_demuxer_data()); 1115 EXPECT_TRUE(IsRequestingDemuxerData(true));
1079 } 1116 }
1080 1117
1081 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { 1118 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) {
1082 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1119 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1083 1120
1084 // Test that when Start() is called, video decoder jobs will wait for audio 1121 // Test that when Start() is called, video decoder jobs will wait for audio
1085 // decoder job before start decoding the data. 1122 // decoder job before start decoding the data.
1086 CreateNextTextureAndSetVideoSurface(); 1123 CreateNextTextureAndSetVideoSurface();
1087 Start(CreateAudioVideoDemuxerConfigs()); 1124 Start(CreateAudioVideoDemuxerConfigs());
1088 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true); 1125 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true);
(...skipping 23 matching lines...) Expand all
1112 1149
1113 DecodeAudioDataUntilOutputBecomesAvailable(); 1150 DecodeAudioDataUntilOutputBecomesAvailable();
1114 1151
1115 // The decoder job should finish and a new request will be sent. 1152 // The decoder job should finish and a new request will be sent.
1116 base::TimeTicks previous = StartTimeTicks(); 1153 base::TimeTicks previous = StartTimeTicks();
1117 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1154 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1118 1155
1119 // Let the decoder starve. 1156 // Let the decoder starve.
1120 TriggerPlayerStarvation(); 1157 TriggerPlayerStarvation();
1121 WaitForAudioDecodeDone(); 1158 WaitForAudioDecodeDone();
1122 1159 EXPECT_TRUE(StartTimeTicks() == previous);
1123 // Verify the start time ticks is cleared at this point because the
1124 // player is prefetching.
1125 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks());
1126 1160
1127 // Send new data to the decoder so it can finish prefetching. This should 1161 // Send new data to the decoder so it can finish prefetching. This should
1128 // reset the start time ticks. 1162 // reset the start time ticks.
1129 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1163 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1130 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); 1164 EXPECT_TRUE(StartTimeTicks() != previous);
1131 1165
1132 base::TimeTicks current = StartTimeTicks(); 1166 base::TimeTicks current = StartTimeTicks();
1133 EXPECT_LE(0, (current - previous).InMillisecondsF()); 1167 EXPECT_LE(0, (current - previous).InMillisecondsF());
1134 } 1168 }
1135 1169
1136 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) { 1170 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) {
1137 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1171 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1138 1172
1139 // Test MediaSourcePlayer can replay video after input EOS is reached. 1173 // Test MediaSourcePlayer can replay video after input EOS is reached.
1140 CreateNextTextureAndSetVideoSurface(); 1174 CreateNextTextureAndSetVideoSurface();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1221 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1188 1222
1189 // Test that if one stream (audio) has completed decode of EOS and the other 1223 // Test that if one stream (audio) has completed decode of EOS and the other
1190 // stream (video) processes config change, that subsequent video EOS completes 1224 // stream (video) processes config change, that subsequent video EOS completes
1191 // A/V playback. 1225 // A/V playback.
1192 // Also tests that seeking+Start() after completing playback resumes playback. 1226 // Also tests that seeking+Start() after completing playback resumes playback.
1193 CreateNextTextureAndSetVideoSurface(); 1227 CreateNextTextureAndSetVideoSurface();
1194 Start(CreateAudioVideoDemuxerConfigs()); 1228 Start(CreateAudioVideoDemuxerConfigs());
1195 1229
1196 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS 1230 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1231 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP9);
1197 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( 1232 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1198 false, 0)); // Video |kConfigChanged| as first unit. 1233 false, 0, configs)); // Video |kConfigChanged| as first unit.
1199 1234
1200 WaitForAudioVideoDecodeDone(); 1235 WaitForAudioVideoDecodeDone();
1201 1236
1202 EXPECT_EQ(3, demuxer_->num_data_requests()); 1237 EXPECT_EQ(3, demuxer_->num_data_requests());
1203 1238
1204 // At no time after completing audio EOS decode, above, should the 1239 // At no time after completing audio EOS decode, above, should the
1205 // audio decoder job resume decoding. Send and decode video EOS. 1240 // audio decoder job resume decoding. Send and decode video EOS.
1206 VerifyPlaybackCompletesOnEOSDecode(true, false); 1241 VerifyPlaybackCompletesOnEOSDecode(true, false);
1207 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); 1242 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
1208 } 1243 }
1209 1244
1210 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) { 1245 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) {
1211 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1246 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1212 1247
1213 // Test that if one stream (video) has completed decode of EOS and the other 1248 // Test that if one stream (video) has completed decode of EOS and the other
1214 // stream (audio) processes config change, that subsequent audio EOS completes 1249 // stream (audio) processes config change, that subsequent audio EOS completes
1215 // A/V playback. 1250 // A/V playback.
1216 // Also tests that seeking+Start() after completing playback resumes playback. 1251 // Also tests that seeking+Start() after completing playback resumes playback.
1217 CreateNextTextureAndSetVideoSurface(); 1252 CreateNextTextureAndSetVideoSurface();
1218 Start(CreateAudioVideoDemuxerConfigs()); 1253 Start(CreateAudioVideoDemuxerConfigs());
1219 1254
1220 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS 1255 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1256 // Audio |kConfigChanged| as first unit.
1221 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( 1257 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1222 true, 0)); // Audio |kConfigChanged| as first unit. 1258 true, 0, CreateAudioDemuxerConfigs(kCodecVorbis)));
1223 1259
1224 WaitForAudioVideoDecodeDone(); 1260 WaitForAudioVideoDecodeDone();
1225 1261
1226 EXPECT_EQ(3, demuxer_->num_data_requests()); 1262 EXPECT_EQ(3, demuxer_->num_data_requests());
1227 1263
1228 // At no time after completing video EOS decode, above, should the 1264 // At no time after completing video EOS decode, above, should the
1229 // video decoder job resume decoding. Send and decode audio EOS. 1265 // video decoder job resume decoding. Send and decode audio EOS.
1230 VerifyPlaybackCompletesOnEOSDecode(true, true); 1266 VerifyPlaybackCompletesOnEOSDecode(true, true);
1231 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); 1267 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
1232 } 1268 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 1420
1385 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) { 1421 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) {
1386 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1422 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1387 1423
1388 // Test that a browser seek, once started, delays a newly arrived regular 1424 // Test that a browser seek, once started, delays a newly arrived regular
1389 // SeekTo() request's demuxer seek until the browser seek is done. 1425 // SeekTo() request's demuxer seek until the browser seek is done.
1390 BrowserSeekPlayer(false); 1426 BrowserSeekPlayer(false);
1391 1427
1392 // Simulate renderer requesting a regular seek while browser seek in progress. 1428 // Simulate renderer requesting a regular seek while browser seek in progress.
1393 player_.SeekTo(base::TimeDelta()); 1429 player_.SeekTo(base::TimeDelta());
1394 EXPECT_FALSE(GetMediaDecoderJob(false));
1395 1430
1396 // Simulate browser seek is done. Confirm player requests the regular seek, 1431 // Simulate browser seek is done. Confirm player requests the regular seek,
1397 // still has no video decoder job configured, and has not requested any 1432 // still has no video decoder job configured, and has not requested any
1398 // further data since the surface change event became pending in 1433 // further data since the surface change event became pending in
1399 // BrowserSeekPlayer(). 1434 // BrowserSeekPlayer().
1400 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1435 EXPECT_EQ(1, demuxer_->num_seek_requests());
1401 player_.OnDemuxerSeekDone(base::TimeDelta()); 1436 player_.OnDemuxerSeekDone(base::TimeDelta());
1402 EXPECT_FALSE(GetMediaDecoderJob(false));
1403 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1437 EXPECT_EQ(2, demuxer_->num_seek_requests());
1404 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1438 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
1405 1439
1406 // Simulate regular seek is done and confirm player requests more data for 1440 // Simulate regular seek is done and confirm player requests more data for
1407 // new video decoder job. 1441 // new video decoder job.
1408 player_.OnDemuxerSeekDone(kNoTimestamp()); 1442 player_.OnDemuxerSeekDone(kNoTimestamp());
1409 EXPECT_TRUE(GetMediaDecoderJob(false)); 1443 EXPECT_FALSE(GetMediaCodecBridge(false));
1410 EXPECT_EQ(3, demuxer_->num_data_requests()); 1444 EXPECT_EQ(3, demuxer_->num_data_requests());
1411 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1445 EXPECT_EQ(2, demuxer_->num_seek_requests());
1446 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1447 EXPECT_TRUE(GetMediaCodecBridge(false));
1412 } 1448 }
1413 1449
1414 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) { 1450 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) {
1415 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1451 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1416 1452
1417 // Test that browser seek is requested if player Release() + Start() occurs 1453 // Test that browser seek is requested if player Release() + Start() occurs
1418 // prior to receiving any data. 1454 // prior to receiving any data.
1419 CreateNextTextureAndSetVideoSurface(); 1455 CreateNextTextureAndSetVideoSurface();
1420 StartVideoDecoderJob(); 1456 StartVideoDecoderJob();
1421 ReleasePlayer(); 1457 ReleasePlayer();
1422 1458
1423 // Pass a new non-empty surface. 1459 // Pass a new non-empty surface.
1424 CreateNextTextureAndSetVideoSurface(); 1460 CreateNextTextureAndSetVideoSurface();
1425 1461
1426 player_.Start(); 1462 player_.Start();
1427 1463
1428 // The new player won't be created until the pending data request is 1464 // No data request is issued since there is still one pending.
1429 // processed.
1430 EXPECT_EQ(1, demuxer_->num_data_requests()); 1465 EXPECT_EQ(1, demuxer_->num_data_requests());
1431 EXPECT_FALSE(GetMediaDecoderJob(false)); 1466 EXPECT_FALSE(GetMediaCodecBridge(false));
1432 1467
1433 // A browser seek should be requested. 1468 // No browser seek is needed.
1434 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1469 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1435 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1470 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
1436 EXPECT_EQ(1, demuxer_->num_data_requests()); 1471 EXPECT_EQ(2, demuxer_->num_data_requests());
1437 } 1472 }
1438 1473
1439 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) { 1474 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) {
1440 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1475 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1441 1476
1442 // Test that one browser seek is requested if player Release() + Start(), with 1477 // Test that one browser seek is requested if player Release() + Start(), with
1443 // video data received between Release() and Start(). 1478 // video data received between Release() and Start().
1444 BrowserSeekPlayer(true); 1479 BrowserSeekPlayer(true);
1445 1480
1446 // Simulate browser seek is done and confirm player requests more data. 1481 // Simulate browser seek is done and confirm player requests more data.
1447 player_.OnDemuxerSeekDone(base::TimeDelta()); 1482 player_.OnDemuxerSeekDone(base::TimeDelta());
1448 EXPECT_TRUE(GetMediaDecoderJob(false)); 1483 EXPECT_EQ(3, demuxer_->num_data_requests());
1449 EXPECT_EQ(2, demuxer_->num_data_requests());
1450 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1484 EXPECT_EQ(1, demuxer_->num_seek_requests());
1451 } 1485 }
1452 1486
1453 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { 1487 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) {
1454 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1488 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1455 1489
1456 // Test decoder job will preroll the media to the seek position. 1490 // Test decoder job will preroll the media to the seek position.
1457 StartAudioDecoderJob(); 1491 StartAudioDecoderJob();
1458 1492
1459 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); 1493 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 // While still prerolling, Release() and Start() the player. 1571 // While still prerolling, Release() and Start() the player.
1538 // TODO(qinmin): Simulation of multiple in-flight data requests (one from 1572 // TODO(qinmin): Simulation of multiple in-flight data requests (one from
1539 // before Release(), one from after Start()) is not included here, and 1573 // before Release(), one from after Start()) is not included here, and
1540 // neither is any data enqueued for later decode if it arrives after 1574 // neither is any data enqueued for later decode if it arrives after
1541 // Release() and before Start(). See http://crbug.com/306314. Assumption 1575 // Release() and before Start(). See http://crbug.com/306314. Assumption
1542 // for this test, to prevent flakiness until the bug is fixed, is the 1576 // for this test, to prevent flakiness until the bug is fixed, is the
1543 // first request's data arrives before Start(). Though that data is not 1577 // first request's data arrives before Start(). Though that data is not
1544 // seen by decoder, this assumption allows preroll continuation 1578 // seen by decoder, this assumption allows preroll continuation
1545 // verification and prevents multiple in-flight data requests. 1579 // verification and prevents multiple in-flight data requests.
1546 ReleasePlayer(); 1580 ReleasePlayer();
1547 player_.OnDemuxerDataAvailable(data); 1581 // The decoder is still decoding and will not be immediately released.
1548 WaitForAudioDecodeDone(); 1582 EXPECT_TRUE(GetMediaCodecBridge(true));
1549 EXPECT_FALSE(GetMediaDecoderJob(true)); 1583 Resume(false, false);
1550 Resume(true, false);
1551 } else { 1584 } else {
1552 player_.OnDemuxerDataAvailable(data); 1585 player_.OnDemuxerDataAvailable(data);
1553 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1586 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1554 WaitForAudioDecodeDone(); 1587 WaitForAudioDecodeDone();
1555 } 1588 }
1556 EXPECT_TRUE(IsPrerolling(true)); 1589 EXPECT_TRUE(IsPrerolling(true));
1557 } 1590 }
1558 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1591 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1559 EXPECT_TRUE(IsPrerolling(true)); 1592 EXPECT_TRUE(IsPrerolling(true));
1560 1593
1561 // Send data after the seek position. 1594 // Send data after the seek position.
1562 PrerollDecoderToTime(true, target_timestamp, target_timestamp); 1595 PrerollDecoderToTime(true, target_timestamp, target_timestamp);
1563 } 1596 }
1564 1597
1565 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) { 1598 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) {
1566 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1599 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1567 1600
1568 // Test decoder job will resume media prerolling if interrupted by 1601 // Test decoder job will resume media prerolling if interrupted by
1569 // |kConfigChanged| and OnDemuxerConfigsAvailable(). 1602 // |kConfigChanged| and OnDemuxerConfigsAvailable().
1570 StartAudioDecoderJob(); 1603 StartAudioDecoderJob();
1571 1604
1572 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); 1605 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1573 EXPECT_TRUE(IsPrerolling(true)); 1606 EXPECT_TRUE(IsPrerolling(true));
1574 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1607 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1575 1608
1609 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis);
1610 configs.audio_sampling_rate = 11025;
1576 1611
1577 // In response to data request, simulate that demuxer signals config change by 1612 // In response to data request, simulate that demuxer signals config change by
1578 // sending an AU with |kConfigChanged|. Player should reconfigure the 1613 // sending an AU with |kConfigChanged|.
1579 // audio decoder job with the supplied configs. 1614 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(
1580 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); 1615 true, 0, configs);
1581 player_.OnDemuxerDataAvailable(data); 1616 player_.OnDemuxerDataAvailable(data);
1582 PrerollDecoderToTime( 1617 PrerollDecoderToTime(
1583 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1618 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1584 } 1619 }
1585 1620
1586 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) { 1621 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) {
1587 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1622 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1588 1623
1589 // Test that the player allows simultaneous audio and video config change, 1624 // Test that the player allows simultaneous audio and video config change,
1590 // such as might occur during OnPrefetchDone() if next access unit for both 1625 // such as might occur during OnPrefetchDone() if next access unit for both
1591 // audio and video jobs is |kConfigChanged|. 1626 // audio and video jobs is |kConfigChanged|.
1592 CreateNextTextureAndSetVideoSurface(); 1627 CreateNextTextureAndSetVideoSurface();
1593 Start(CreateAudioVideoDemuxerConfigs()); 1628 Start(CreateAudioVideoDemuxerConfigs());
1594 MediaDecoderJob* first_audio_job = GetMediaDecoderJob(true); 1629 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1595 MediaDecoderJob* first_video_job = GetMediaDecoderJob(false); 1630 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1631 EXPECT_TRUE(GetMediaCodecBridge(true));
1632 EXPECT_TRUE(GetMediaCodecBridge(false));
1633 WaitForAudioVideoDecodeDone();
1596 1634
1597 // Simulate audio |kConfigChanged| prefetched as standalone access unit. 1635 // Simulate audio |kConfigChanged| prefetched as standalone access unit.
1636 DemuxerConfigs audio_configs = CreateAudioDemuxerConfigs(kCodecVorbis);
1637 audio_configs.audio_sampling_rate = 11025;
1598 player_.OnDemuxerDataAvailable( 1638 player_.OnDemuxerDataAvailable(
1599 CreateReadFromDemuxerAckWithConfigChanged(true, 0)); 1639 CreateReadFromDemuxerAckWithConfigChanged(true, 0, audio_configs));
1600 1640
1601 // Simulate video |kConfigChanged| prefetched as standalone access unit. 1641 // Simulate video |kConfigChanged| prefetched as standalone access unit.
1602 player_.OnDemuxerDataAvailable( 1642 player_.OnDemuxerDataAvailable(
1603 CreateReadFromDemuxerAckWithConfigChanged(false, 0)); 1643 CreateReadFromDemuxerAckWithConfigChanged(
1604 EXPECT_EQ(4, demuxer_->num_data_requests()); 1644 false, 0, CreateVideoDemuxerConfigs(kCodecVP9)));
1645 EXPECT_EQ(6, demuxer_->num_data_requests());
1646 EXPECT_TRUE(IsDrainingDecoder(true));
1647 EXPECT_TRUE(IsDrainingDecoder(false));
1605 1648
1606 // Both jobs should have been reconfigured by now. 1649 // Waiting for decoder to finish draining.
1607 // TODO(qinmin): Fix flaky pointer-based MDJ inequality testing. 1650 while (IsDrainingDecoder(true) || IsDrainingDecoder(false))
1608 // See http://crbug.com/327839. 1651 message_loop_.RunUntilIdle();
1609 EXPECT_NE(first_audio_job, GetMediaDecoderJob(true));
1610 EXPECT_NE(first_video_job, GetMediaDecoderJob(false));
1611 EXPECT_TRUE(GetMediaDecoderJob(true) && GetMediaDecoderJob(false));
1612 } 1652 }
1613 1653
1614 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) { 1654 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) {
1615 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1655 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1616 1656
1617 // Test that the player detects need for and requests demuxer configs if 1657 // Test that the player detects need for and requests demuxer configs if
1618 // the |kConfigChanged| unit is the very first unit in the set of units 1658 // the |kConfigChanged| unit is the very first unit in the set of units
1619 // received in OnDemuxerDataAvailable() ostensibly while 1659 // received in OnDemuxerDataAvailable() ostensibly while
1620 // |PREFETCH_DONE_EVENT_PENDING|. 1660 // |PREFETCH_DONE_EVENT_PENDING|.
1621 StartConfigChange(true, true, 0); 1661 StartConfigChange(true, true, 0);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 TEST_F(MediaSourcePlayerTest, BrowserSeek_PrerollAfterBrowserSeek) { 1694 TEST_F(MediaSourcePlayerTest, BrowserSeek_PrerollAfterBrowserSeek) {
1655 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1695 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1656 1696
1657 // Test decoder job will preroll the media to the actual seek position 1697 // Test decoder job will preroll the media to the actual seek position
1658 // resulting from a browser seek. 1698 // resulting from a browser seek.
1659 BrowserSeekPlayer(false); 1699 BrowserSeekPlayer(false);
1660 1700
1661 // Simulate browser seek is done, but to a later time than was requested. 1701 // Simulate browser seek is done, but to a later time than was requested.
1662 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100); 1702 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100);
1663 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100)); 1703 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100));
1664 EXPECT_TRUE(GetMediaDecoderJob(false)); 1704 // Because next AU is not I-frame, MediaCodecBridge will not be recreated.
1705 EXPECT_FALSE(GetMediaCodecBridge(false));
1665 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1706 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1666 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1707 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1667 EXPECT_EQ(3, demuxer_->num_data_requests()); 1708 EXPECT_EQ(3, demuxer_->num_data_requests());
1668 1709
1669 PrerollDecoderToTime( 1710 PrerollDecoderToTime(
1670 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1711 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1671 } 1712 }
1672 1713
1673 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) { 1714 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) {
1674 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1715 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1675 1716
1676 // Test that video config change notification results in creating a new 1717 // Test that video config change notification results in creating a new
1677 // video decoder job results without any browser seek. 1718 // video decoder job results without any browser seek.
1678 StartConfigChange(false, true, 1); 1719 StartConfigChange(false, true, 1);
1679 EXPECT_TRUE(GetMediaDecoderJob(false));
1680 EXPECT_EQ(2, demuxer_->num_data_requests());
1681 EXPECT_EQ(0, demuxer_->num_seek_requests());
1682 }
1683 1720
1684 TEST_F(MediaSourcePlayerTest, NewSurfaceAfterChangingConfigs) { 1721 // New video decoder job should have been created and configured, without any
1685 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1722 // browser seek.
1686 1723 EXPECT_TRUE(GetMediaCodecBridge(false));
1687 // Test that no seek results from a SetVideoSurface() that occurs after
1688 // the player processes new demuxer configs. This test may be good to keep
1689 // beyond browser seek hack.
1690 StartConfigChange(false, false, 1);
1691 EXPECT_TRUE(GetMediaDecoderJob(false));
1692 EXPECT_EQ(3, demuxer_->num_data_requests());
1693
1694 CreateNextTextureAndSetVideoSurface();
1695 EXPECT_TRUE(GetMediaDecoderJob(false));
1696 EXPECT_EQ(3, demuxer_->num_data_requests()); 1724 EXPECT_EQ(3, demuxer_->num_data_requests());
1697 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1725 EXPECT_EQ(0, demuxer_->num_seek_requests());
1698 } 1726 }
1699 1727
1728 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedBySeek) {
1729 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1730
1731 // Test if a decoder is being drained while receiving a seek request, draining
1732 // is canceled.
1733 SendConfigChangeToDecoder(true, false, 0);
1734 EXPECT_TRUE(IsDrainingDecoder(true));
1735
1736 player_.SeekTo(base::TimeDelta::FromMilliseconds(100));
1737 WaitForAudioDecodeDone();
1738 player_.OnDemuxerSeekDone(kNoTimestamp());
1739
1740 EXPECT_EQ(1, demuxer_->num_seek_requests());
1741 EXPECT_EQ(4, demuxer_->num_data_requests());
1742 EXPECT_FALSE(IsDrainingDecoder(true));
1743 }
1744
1745 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedByRelease) {
1746 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1747
1748 // Test if a decoder is being drained while receiving a release request,
1749 // draining is canceled.
1750 SendConfigChangeToDecoder(true, false, 0);
1751 EXPECT_TRUE(IsDrainingDecoder(true));
1752
1753 ReleasePlayer();
1754 WaitForAudioDecodeDone();
1755 EXPECT_EQ(3, demuxer_->num_data_requests());
1756 EXPECT_FALSE(IsDrainingDecoder(true));
1757
1758 EXPECT_FALSE(GetMediaCodecBridge(true));
1759 EXPECT_FALSE(player_.IsPlaying());
1760
1761 player_.Start();
1762 EXPECT_TRUE(player_.IsPlaying());
1763 EXPECT_EQ(3, demuxer_->num_data_requests());
1764 }
1765
1766 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedBySurfaceChange) {
1767 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1768
1769 // Test if a video decoder is being drained while surface changes, draining
1770 // is canceled.
1771 SendConfigChangeToDecoder(false, false, 0);
1772 EXPECT_TRUE(IsDrainingDecoder(false));
1773
1774 CreateNextTextureAndSetVideoSurface();
1775 WaitForVideoDecodeDone();
1776
1777 EXPECT_FALSE(IsDrainingDecoder(false));
1778 EXPECT_FALSE(GetMediaCodecBridge(false));
1779 EXPECT_TRUE(player_.IsPlaying());
1780 EXPECT_EQ(3, demuxer_->num_data_requests());
1781
1782 // Finish the browser seek introduced by surface change.
1783 player_.OnDemuxerSeekDone(base::TimeDelta());
1784 EXPECT_EQ(4, demuxer_->num_data_requests());
1785 }
1786
1700 TEST_F(MediaSourcePlayerTest, 1787 TEST_F(MediaSourcePlayerTest,
1701 BrowserSeek_DecoderStarvationWhilePendingSurfaceChange) { 1788 BrowserSeek_DecoderStarvationWhilePendingSurfaceChange) {
1702 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1789 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1703 1790
1704 // Test video decoder starvation while handling a pending surface change 1791 // Test video decoder starvation while handling a pending surface change
1705 // should not cause any crashes. 1792 // should not cause any crashes.
1706 CreateNextTextureAndSetVideoSurface(); 1793 CreateNextTextureAndSetVideoSurface();
1707 StartVideoDecoderJob(); 1794 StartVideoDecoderJob();
1708 DemuxerData data = CreateReadFromDemuxerAckForVideo(); 1795 DemuxerData data = CreateReadFromDemuxerAckForVideo();
1709 player_.OnDemuxerDataAvailable(data); 1796 player_.OnDemuxerDataAvailable(data);
1710 1797
1711 // Trigger a surface change and decoder starvation. 1798 // Trigger a surface change and decoder starvation.
1712 CreateNextTextureAndSetVideoSurface(); 1799 CreateNextTextureAndSetVideoSurface();
1713 TriggerPlayerStarvation(); 1800 TriggerPlayerStarvation();
1714 WaitForVideoDecodeDone(); 1801 WaitForVideoDecodeDone();
1715 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 1802 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
1716 1803
1717 // Surface change should trigger a seek. 1804 // Surface change should trigger a seek.
1718 player_.OnDemuxerDataAvailable(data); 1805 player_.OnDemuxerDataAvailable(data);
1719 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1806 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
1720 player_.OnDemuxerSeekDone(base::TimeDelta()); 1807 player_.OnDemuxerSeekDone(base::TimeDelta());
1721 EXPECT_TRUE(GetMediaDecoderJob(false)); 1808 // After seek is done, prefetch is handled first. MediaCodecBridge is not
1809 // created at this moment.
1810 EXPECT_FALSE(GetMediaCodecBridge(false));
1722 1811
1723 // A new data request should be sent. 1812 // A new data request should be sent.
1724 EXPECT_EQ(3, demuxer_->num_data_requests()); 1813 EXPECT_EQ(3, demuxer_->num_data_requests());
1725 } 1814 }
1726 1815
1727 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { 1816 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) {
1728 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1817 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1729 1818
1730 // Test if OnPrefetchDone() had already been posted before and is executed 1819 // Test if OnPrefetchDone() had already been posted before and is executed
1731 // after Release(), then player does not DCHECK. This test is fragile to 1820 // after Release(), then player does not DCHECK. This test is fragile to
1732 // change to MediaDecoderJob::Prefetch() implementation; it assumes task 1821 // change to MediaDecoderJob::Prefetch() implementation; it assumes task
1733 // is posted to run |prefetch_cb| if the job already HasData(). 1822 // is posted to run |prefetch_cb| if the job already HasData().
1734 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test 1823 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test
1735 // becomes obsolete. See http://crbug.com/304234. 1824 // becomes obsolete. See http://crbug.com/304234.
1736 StartAudioDecoderJob(); 1825 StartAudioDecoderJob();
1737 1826
1738 // Escape the original prefetch by decoding a single access unit. 1827 // Escape the original prefetch by decoding a single access unit.
1739 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1828 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1740 WaitForAudioDecodeDone(); 1829 WaitForAudioDecodeDone();
1741 1830
1742 // Prime the job with a few more access units, so that a later prefetch, 1831 // Prime the job with a few more access units, so that a later prefetch,
1743 // triggered by starvation to simulate decoder underrun, can trivially 1832 // triggered by starvation to simulate decoder underrun, can trivially
1744 // post task to run OnPrefetchDone(). 1833 // post task to run OnPrefetchDone().
1745 player_.OnDemuxerDataAvailable( 1834 player_.OnDemuxerDataAvailable(
1746 CreateReadFromDemuxerAckWithConfigChanged(true, 4)); 1835 CreateReadFromDemuxerAckWithConfigChanged(
1836 true, 4, CreateAudioDemuxerConfigs(kCodecVorbis)));
1747 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1837 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1748 1838
1749 // Simulate decoder underrun, so trivial prefetch starts while still decoding. 1839 // Simulate decoder underrun, so trivial prefetch starts while still decoding.
1750 // The prefetch and posting of OnPrefetchDone() will not occur until next 1840 // The prefetch and posting of OnPrefetchDone() will not occur until next
1751 // MediaDecoderCallBack() occurs. 1841 // MediaDecoderCallBack() occurs.
1752 TriggerPlayerStarvation(); 1842 TriggerPlayerStarvation();
1753 1843
1754 // Upon the next successful decode callback, post a task to call Release() on 1844 // Upon the next successful decode callback, post a task to call Release() on
1755 // the |player_|, such that the trivial OnPrefetchDone() task posting also 1845 // the |player_|, such that the trivial OnPrefetchDone() task posting also
1756 // occurs and should execute after the Release(). 1846 // occurs and should execute after the Release().
1757 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); 1847 OnNextTestDecodeCallbackPostTaskToReleasePlayer();
1758 1848
1759 WaitForAudioDecodeDone(); 1849 WaitForAudioDecodeDone();
1760 EXPECT_TRUE(decoder_callback_hook_executed_);
1761 EXPECT_EQ(2, demuxer_->num_data_requests());
1762 1850
1763 // Player should have no decoder job until after Start(). 1851 EXPECT_EQ(3, demuxer_->num_data_requests());
1764 Resume(true, false); 1852
1853 // Player should not request any new data since the access units haven't
1854 // been fully decoded yet.
1855 Resume(false, false);
1765 } 1856 }
1766 1857
1767 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { 1858 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) {
1768 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1859 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1769 1860
1770 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1861 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request
1771 // has not yet been sent, then the seek request is sent after Release(). Also, 1862 // has not yet been sent, then the seek request is sent after Release(). Also,
1772 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player 1863 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player
1773 // will resume correct post-seek preroll upon Start(). 1864 // will resume correct post-seek preroll upon Start().
1774 StartAudioDecoderJobAndSeekToWhileDecoding( 1865 StartAudioDecoderJobAndSeekToWhileDecoding(
1775 base::TimeDelta::FromMilliseconds(100)); 1866 base::TimeDelta::FromMilliseconds(100));
1776 ReleasePlayer(); 1867 ReleasePlayer();
1868 EXPECT_EQ(0, demuxer_->num_seek_requests());
1869 WaitForAudioDecodeDone();
1777 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1870 EXPECT_EQ(1, demuxer_->num_seek_requests());
1778 1871
1779 player_.OnDemuxerSeekDone(kNoTimestamp()); 1872 player_.OnDemuxerSeekDone(kNoTimestamp());
1780 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1873 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1781 EXPECT_FALSE(GetMediaDecoderJob(true)); 1874 EXPECT_FALSE(GetMediaCodecBridge(true));
1782 EXPECT_FALSE(player_.IsPlaying()); 1875 EXPECT_FALSE(player_.IsPlaying());
1783 1876
1784 // Player should begin prefetch and resume preroll upon Start(). 1877 // Player should begin prefetch and resume preroll upon Start().
1785 EXPECT_EQ(2, demuxer_->num_data_requests()); 1878 EXPECT_EQ(2, demuxer_->num_data_requests());
1786 Resume(true, false); 1879 Resume(true, false);
1787 EXPECT_TRUE(IsPrerolling(true)); 1880 EXPECT_TRUE(IsPrerolling(true));
1788 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1881 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1789 1882
1790 // No further seek should have been requested since Release(), above. 1883 // No further seek should have been requested since Release(), above.
1791 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1884 EXPECT_EQ(1, demuxer_->num_seek_requests());
1792 } 1885 }
1793 1886
1794 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { 1887 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) {
1795 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1888 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1796 1889
1797 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1890 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request
1798 // has not yet been sent, then the seek request is sent after Release(). Also, 1891 // has not yet been sent, then the seek request is sent after Release(). Also,
1799 // test if OnDemuxerSeekDone() does not occur until after the next Start(), 1892 // test if OnDemuxerSeekDone() does not occur until after the next Start(),
1800 // then the player remains pending seek done until (and resumes correct 1893 // then the player remains pending seek done until (and resumes correct
1801 // post-seek preroll after) OnDemuxerSeekDone(). 1894 // post-seek preroll after) OnDemuxerSeekDone().
1802 StartAudioDecoderJobAndSeekToWhileDecoding( 1895 StartAudioDecoderJobAndSeekToWhileDecoding(
1803 base::TimeDelta::FromMilliseconds(100)); 1896 base::TimeDelta::FromMilliseconds(100));
1804 ReleasePlayer(); 1897 ReleasePlayer();
1805 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1898 EXPECT_EQ(0, demuxer_->num_seek_requests());
1806 1899
1807 // Player should not prefetch upon Start() nor create the decoder job, due to 1900 // Player should not prefetch upon Start() nor create the decoder job, due to
1808 // awaiting DemuxerSeekDone. 1901 // awaiting DemuxerSeekDone.
1809 EXPECT_EQ(2, demuxer_->num_data_requests()); 1902 EXPECT_EQ(2, demuxer_->num_data_requests());
1810 Resume(false, false); 1903 Resume(false, false);
1811 1904
1905 WaitForAudioDecodeDone();
1906 EXPECT_EQ(1, demuxer_->num_seek_requests());
1812 player_.OnDemuxerSeekDone(kNoTimestamp()); 1907 player_.OnDemuxerSeekDone(kNoTimestamp());
1813 EXPECT_TRUE(GetMediaDecoderJob(true)); 1908 EXPECT_TRUE(GetMediaDecoderJob(true));
1814 EXPECT_TRUE(IsPrerolling(true)); 1909 EXPECT_TRUE(IsPrerolling(true));
1815 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1910 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1816 EXPECT_EQ(3, demuxer_->num_data_requests()); 1911 EXPECT_EQ(3, demuxer_->num_data_requests());
1817 1912
1818 // No further seek should have been requested since Release(), above. 1913 // No further seek should have been requested since Release(), above.
1819 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1914 EXPECT_EQ(1, demuxer_->num_seek_requests());
1820 } 1915 }
1821 1916
1822 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) { 1917 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) {
1823 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1918 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1824 1919
1825 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC 1920 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC
1826 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the 1921 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the
1827 // player will resume correct post-seek preroll upon Start(). 1922 // player will resume correct post-seek preroll upon Start().
1828 StartAudioDecoderJobAndSeekToWhileDecoding( 1923 StartAudioDecoderJobAndSeekToWhileDecoding(
1829 base::TimeDelta::FromMilliseconds(100)); 1924 base::TimeDelta::FromMilliseconds(100));
1830 WaitForAudioDecodeDone(); 1925 WaitForAudioDecodeDone();
1831 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1926 EXPECT_EQ(1, demuxer_->num_seek_requests());
1832 1927
1833 ReleasePlayer(); 1928 ReleasePlayer();
1834 player_.OnDemuxerSeekDone(kNoTimestamp()); 1929 player_.OnDemuxerSeekDone(kNoTimestamp());
1835 EXPECT_FALSE(player_.IsPlaying()); 1930 EXPECT_FALSE(player_.IsPlaying());
1836 EXPECT_FALSE(GetMediaDecoderJob(true)); 1931 EXPECT_FALSE(GetMediaCodecBridge(true));
1837 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1932 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1838 1933
1839 // Player should begin prefetch and resume preroll upon Start(). 1934 // Player should begin prefetch and resume preroll upon Start().
1840 EXPECT_EQ(2, demuxer_->num_data_requests()); 1935 EXPECT_EQ(2, demuxer_->num_data_requests());
1841 Resume(true, false); 1936 Resume(true, false);
1842 EXPECT_TRUE(IsPrerolling(true)); 1937 EXPECT_TRUE(IsPrerolling(true));
1843 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1938 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1844 1939
1845 // No further seek should have been requested since before Release(), above. 1940 // No further seek should have been requested since before Release(), above.
1846 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1941 EXPECT_EQ(1, demuxer_->num_seek_requests());
1847 } 1942 }
1848 1943
1849 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { 1944 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) {
1850 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1945 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1851 1946
1852 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC 1947 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC
1853 // request and OnDemuxerSeekDone() does not occur until after the next 1948 // request and OnDemuxerSeekDone() does not occur until after the next
1854 // Start(), then the player remains pending seek done until (and resumes 1949 // Start(), then the player remains pending seek done until (and resumes
1855 // correct post-seek preroll after) OnDemuxerSeekDone(). 1950 // correct post-seek preroll after) OnDemuxerSeekDone().
1856 StartAudioDecoderJobAndSeekToWhileDecoding( 1951 StartAudioDecoderJobAndSeekToWhileDecoding(
1857 base::TimeDelta::FromMilliseconds(100)); 1952 base::TimeDelta::FromMilliseconds(100));
1858 WaitForAudioDecodeDone(); 1953 WaitForAudioDecodeDone();
1859 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1954 EXPECT_EQ(1, demuxer_->num_seek_requests());
1860 1955
1861 ReleasePlayer(); 1956 ReleasePlayer();
1862 EXPECT_EQ(2, demuxer_->num_data_requests()); 1957 EXPECT_EQ(2, demuxer_->num_data_requests());
1863 Resume(false, false); 1958 Resume(false, false);
1864 1959
1865 player_.OnDemuxerSeekDone(kNoTimestamp()); 1960 player_.OnDemuxerSeekDone(kNoTimestamp());
1866 EXPECT_TRUE(GetMediaDecoderJob(true)); 1961 EXPECT_FALSE(GetMediaCodecBridge(true));
1867 EXPECT_TRUE(IsPrerolling(true)); 1962 EXPECT_TRUE(IsPrerolling(true));
1868 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1963 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1869 EXPECT_EQ(3, demuxer_->num_data_requests()); 1964 EXPECT_EQ(3, demuxer_->num_data_requests());
1870 1965
1871 // No further seek should have been requested since before Release(), above. 1966 // No further seek should have been requested since before Release(), above.
1872 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1967 EXPECT_EQ(1, demuxer_->num_seek_requests());
1873 } 1968 }
1874 1969
1875 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenStart) { 1970 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenStart) {
1876 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1971 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1877 1972
1878 // Test if Release() occurs after |kConfigChanged| detected, and then Start() 1973 // Test if Release() occurs after |kConfigChanged| is processed, new data
1879 // is called, then the player does not issue any new data request since it is 1974 // requested of demuxer, and the requested data arrive before the next
1880 // still waiting for the previous one. 1975 // Start(), then the player starts to decode the new data without any browser
1976 // seek.
1881 StartConfigChange(true, true, 0); 1977 StartConfigChange(true, true, 0);
1882 ReleasePlayer(); 1978 ReleasePlayer();
1883 1979
1884 EXPECT_FALSE(GetMediaDecoderJob(true)); 1980 EXPECT_TRUE(GetMediaCodecBridge(true));
1885 EXPECT_FALSE(player_.IsPlaying()); 1981 EXPECT_FALSE(player_.IsPlaying());
1886 EXPECT_EQ(2, demuxer_->num_data_requests()); 1982 EXPECT_EQ(3, demuxer_->num_data_requests());
1983 player_.OnDemuxerDataAvailable(
1984 CreateReadFromDemuxerAckWithConfigChanged(
1985 true, 4, CreateAudioDemuxerConfigs(kCodecVorbis)));
1986 WaitForAudioDecodeDone();
1987 EXPECT_FALSE(GetMediaCodecBridge(true));
1887 1988
1888 // Player should resume upon Start(). 1989 // Player should resume upon Start(), even without further configs supplied.
1889 Resume(false, false); 1990 player_.Start();
1890 EXPECT_TRUE(GetMediaDecoderJob(true));
1891 EXPECT_TRUE(player_.IsPlaying()); 1991 EXPECT_TRUE(player_.IsPlaying());
1892 EXPECT_EQ(2, demuxer_->num_data_requests()); 1992 EXPECT_EQ(3, demuxer_->num_data_requests());
1993 EXPECT_EQ(0, demuxer_->num_seek_requests());
1893 } 1994 }
1894 1995
1895 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenDemuxerSeekDone) { 1996 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenDemuxerSeekDone) {
1896 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1997 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1897 1998
1898 // Test that Release() after a browser seek's DemuxerSeek IPC request has been 1999 // Test that Release() after a browser seek's DemuxerSeek IPC request has been
1899 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() occurs 2000 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() occurs
1900 // before the next Start()+SetVideoSurface(), then the player will resume 2001 // before the next Start()+SetVideoSurface(), then the player will resume
1901 // correct post-seek preroll upon Start()+SetVideoSurface(). 2002 // correct post-seek preroll upon Start()+SetVideoSurface().
1902 BrowserSeekPlayer(false); 2003 BrowserSeekPlayer(false);
1903 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 2004 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
1904 ReleasePlayer(); 2005 ReleasePlayer();
1905 2006
1906 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 2007 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
1907 EXPECT_FALSE(player_.IsPlaying()); 2008 EXPECT_FALSE(player_.IsPlaying());
1908 EXPECT_FALSE(GetMediaDecoderJob(false)); 2009 EXPECT_FALSE(GetMediaCodecBridge(false));
1909 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 2010 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1910 2011
1911 // Player should begin prefetch and resume preroll upon Start(). 2012 // Player should begin prefetch and resume preroll upon Start().
1912 EXPECT_EQ(2, demuxer_->num_data_requests()); 2013 EXPECT_EQ(2, demuxer_->num_data_requests());
1913 CreateNextTextureAndSetVideoSurface(); 2014 CreateNextTextureAndSetVideoSurface();
1914 Resume(false, true); 2015 Resume(false, true);
1915 EXPECT_TRUE(IsPrerolling(false)); 2016 EXPECT_TRUE(IsPrerolling(false));
1916 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 2017 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1917 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 2018 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
1918 2019
(...skipping 11 matching lines...) Expand all
1930 // after) OnDemuxerSeekDone(). 2031 // after) OnDemuxerSeekDone().
1931 BrowserSeekPlayer(false); 2032 BrowserSeekPlayer(false);
1932 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 2033 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
1933 ReleasePlayer(); 2034 ReleasePlayer();
1934 2035
1935 EXPECT_EQ(2, demuxer_->num_data_requests()); 2036 EXPECT_EQ(2, demuxer_->num_data_requests());
1936 CreateNextTextureAndSetVideoSurface(); 2037 CreateNextTextureAndSetVideoSurface();
1937 Resume(false, false); 2038 Resume(false, false);
1938 2039
1939 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 2040 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
1940 EXPECT_TRUE(GetMediaDecoderJob(false)); 2041 // Prefetch takes place first, and the decoder is not created yet.
2042 EXPECT_FALSE(GetMediaCodecBridge(false));
1941 EXPECT_TRUE(IsPrerolling(false)); 2043 EXPECT_TRUE(IsPrerolling(false));
1942 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 2044 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1943 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 2045 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
1944 EXPECT_EQ(3, demuxer_->num_data_requests()); 2046 EXPECT_EQ(3, demuxer_->num_data_requests());
1945 2047
1946 // No further seek should have been requested since BrowserSeekPlayer(). 2048 // No further seek should have been requested since BrowserSeekPlayer().
1947 EXPECT_EQ(1, demuxer_->num_seek_requests()); 2049 EXPECT_EQ(1, demuxer_->num_seek_requests());
2050
2051 // Decoder will be created once data is received.
2052 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
2053 while (!GetMediaCodecBridge(false))
2054 message_loop_.RunUntilIdle();
1948 } 2055 }
1949 2056
1950 // TODO(xhwang): Once we add tests to cover DrmBridge, update this test to 2057 // TODO(xhwang): Once we add tests to cover DrmBridge, update this test to
1951 // also verify that the job is successfully created if SetDrmBridge(), Start() 2058 // also verify that the job is successfully created if SetDrmBridge(), Start()
1952 // and eventually OnMediaCrypto() occur. This would increase test coverage of 2059 // and eventually OnMediaCrypto() occur. This would increase test coverage of
1953 // http://crbug.com/313470 and allow us to remove inspection of internal player 2060 // http://crbug.com/313470 and allow us to remove inspection of internal player
1954 // pending event state. See http://crbug.com/313860. 2061 // pending event state. See http://crbug.com/313860.
1955 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) { 2062 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) {
1956 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 2063 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1957 2064
1958 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after 2065 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after
1959 // SetVideoSurface() for a player configured for encrypted video, when the 2066 // SetVideoSurface() for a player configured for encrypted video, when the
1960 // player has not yet received media crypto. 2067 // player has not yet received media crypto.
1961 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); 2068 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP8);
1962 configs.is_video_encrypted = true; 2069 configs.is_video_encrypted = true;
1963 2070
1964 player_.OnDemuxerConfigsAvailable(configs); 2071 player_.OnDemuxerConfigsAvailable(configs);
1965 CreateNextTextureAndSetVideoSurface(); 2072 CreateNextTextureAndSetVideoSurface();
1966 EXPECT_FALSE(IsPendingSurfaceChange()); 2073 EXPECT_FALSE(GetMediaCodecBridge(false));
1967 EXPECT_FALSE(GetMediaDecoderJob(false));
1968 } 2074 }
1969 2075
1970 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) { 2076 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) {
1971 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 2077 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1972 2078
1973 // Test that current time is updated while decoder is starved. 2079 // Test that current time is updated while decoder is starved.
1974 StartAudioDecoderJob(); 2080 StartAudioDecoderJob();
1975 DecodeAudioDataUntilOutputBecomesAvailable(); 2081 DecodeAudioDataUntilOutputBecomesAvailable();
1976 2082
1977 // Trigger starvation while the decoder is decoding. 2083 // Trigger starvation while the decoder is decoding.
1978 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 2084 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1979 manager_.ResetTimestampUpdated(); 2085 manager_.ResetTimestampUpdated();
1980 TriggerPlayerStarvation(); 2086 TriggerPlayerStarvation();
1981 WaitForAudioDecodeDone(); 2087 WaitForAudioDecodeDone();
1982 2088
1983 // Current time should be updated. 2089 // Current time should be updated.
1984 EXPECT_TRUE(manager_.timestamp_updated()); 2090 EXPECT_TRUE(manager_.timestamp_updated());
1985 } 2091 }
1986 2092
1987 TEST_F(MediaSourcePlayerTest, CurrentTimeKeepsIncreasingAfterConfigChange) { 2093 TEST_F(MediaSourcePlayerTest, CurrentTimeKeepsIncreasingAfterConfigChange) {
1988 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 2094 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1989 2095
1990 // Test current time keep on increasing after audio config change. 2096 // Test current time keep on increasing after audio config change.
1991 // Test that current time is updated while decoder is starved. 2097 // Test that current time is updated while decoder is starved.
1992 StartAudioDecoderJob(); 2098 StartAudioDecoderJob();
1993 2099
1994 DecodeAudioDataUntilOutputBecomesAvailable(); 2100 DecodeAudioDataUntilOutputBecomesAvailable();
1995 2101
1996 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); 2102 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis);
2103 configs.audio_sampling_rate = 11025;
2104 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(
2105 true, 0, configs);
1997 player_.OnDemuxerDataAvailable(data); 2106 player_.OnDemuxerDataAvailable(data);
1998 WaitForAudioDecodeDone(); 2107 WaitForAudioDecodeDone();
1999 DecodeAudioDataUntilOutputBecomesAvailable(); 2108 DecodeAudioDataUntilOutputBecomesAvailable();
2000 } 2109 }
2001 2110
2002 } // namespace media 2111 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698