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

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

Issue 79283006: Let only seeks reset Android MSE stream playback completion (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased, addressed ps6 comments. includes some test cleanup Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/android/media_source_player.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "media/base/android/media_codec_bridge.h" 10 #include "media/base/android/media_codec_bridge.h"
(...skipping 17 matching lines...) Expand all
28 } \ 28 } \
29 } while (0) 29 } while (0)
30 30
31 static const int kDefaultDurationInMs = 10000; 31 static const int kDefaultDurationInMs = 10000;
32 32
33 static const char kAudioMp4[] = "audio/mp4"; 33 static const char kAudioMp4[] = "audio/mp4";
34 static const char kVideoMp4[] = "video/mp4"; 34 static const char kVideoMp4[] = "video/mp4";
35 static const char kAudioWebM[] = "audio/webm"; 35 static const char kAudioWebM[] = "audio/webm";
36 static const char kVideoWebM[] = "video/webm"; 36 static const char kVideoWebM[] = "video/webm";
37 37
38 // TODO(wolenetz/qinmin): Simplify tests with more effective mock usage, and
39 // fix flaky pointer-based MDJ inequality testing. See http://crbug.com/327839.
40
38 // Mock of MediaPlayerManager for testing purpose 41 // Mock of MediaPlayerManager for testing purpose
39 class MockMediaPlayerManager : public MediaPlayerManager { 42 class MockMediaPlayerManager : public MediaPlayerManager {
40 public: 43 public:
41 explicit MockMediaPlayerManager(base::MessageLoop* message_loop) 44 explicit MockMediaPlayerManager(base::MessageLoop* message_loop)
42 : message_loop_(message_loop), 45 : message_loop_(message_loop),
43 playback_completed_(false) {} 46 playback_completed_(false) {}
44 virtual ~MockMediaPlayerManager() {} 47 virtual ~MockMediaPlayerManager() {}
45 48
46 // MediaPlayerManager implementation. 49 // MediaPlayerManager implementation.
47 virtual void RequestMediaResources(int player_id) OVERRIDE {} 50 virtual void RequestMediaResources(int player_id) OVERRIDE {}
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 EXPECT_EQ(audio_codec, kCodecAAC); 248 EXPECT_EQ(audio_codec, kCodecAAC);
246 249
247 configs.audio_sampling_rate = 48000; 250 configs.audio_sampling_rate = 48000;
248 uint8 aac_extra_data[] = { 0x13, 0x10 }; 251 uint8 aac_extra_data[] = { 0x13, 0x10 };
249 configs.audio_extra_data = std::vector<uint8>( 252 configs.audio_extra_data = std::vector<uint8>(
250 aac_extra_data, 253 aac_extra_data,
251 aac_extra_data + 2); 254 aac_extra_data + 2);
252 return configs; 255 return configs;
253 } 256 }
254 257
255 // Starts an audio decoder job.
256 void StartAudioDecoderJob() {
257 Start(CreateAudioDemuxerConfigs(kCodecVorbis));
258 }
259
260 DemuxerConfigs CreateVideoDemuxerConfigs() { 258 DemuxerConfigs CreateVideoDemuxerConfigs() {
261 DemuxerConfigs configs; 259 DemuxerConfigs configs;
262 configs.video_codec = kCodecVP8; 260 configs.video_codec = kCodecVP8;
263 configs.video_size = gfx::Size(320, 240); 261 configs.video_size = gfx::Size(320, 240);
264 configs.is_video_encrypted = false; 262 configs.is_video_encrypted = false;
265 configs.duration_ms = kDefaultDurationInMs; 263 configs.duration_ms = kDefaultDurationInMs;
266 return configs; 264 return configs;
267 } 265 }
268 266
269 DemuxerConfigs CreateAudioVideoDemuxerConfigs() { 267 DemuxerConfigs CreateAudioVideoDemuxerConfigs() {
270 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 268 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis);
271 configs.video_codec = kCodecVP8; 269 configs.video_codec = kCodecVP8;
272 configs.video_size = gfx::Size(320, 240); 270 configs.video_size = gfx::Size(320, 240);
273 configs.is_video_encrypted = false; 271 configs.is_video_encrypted = false;
274 return configs; 272 return configs;
275 } 273 }
276 274
277 void StartVideoDecoderJob() { 275 DemuxerConfigs CreateDemuxerConfigs(bool have_audio, bool have_video) {
278 Start(CreateVideoDemuxerConfigs()); 276 DCHECK(have_audio || have_video);
277
278 if (have_audio && !have_video)
279 return CreateAudioDemuxerConfigs(kCodecVorbis);
280
281 if (have_video && !have_audio)
282 return CreateVideoDemuxerConfigs();
283
284 return CreateAudioVideoDemuxerConfigs();
279 } 285 }
280 286
281 // Starts decoding the data. 287 // Starts an audio decoder job. Verifies player behavior relative to
282 void Start(const DemuxerConfigs& configs) { 288 // |expect_player_requests_data|.
289 void StartAudioDecoderJob(bool expect_player_requests_data) {
290 Start(CreateAudioDemuxerConfigs(kCodecVorbis), expect_player_requests_data);
291 }
292
293 // Starts a video decoder job. Verifies player behavior relative to
294 // |expect_player_requests_data|.
295 void StartVideoDecoderJob(bool expect_player_requests_data) {
296 Start(CreateVideoDemuxerConfigs(), expect_player_requests_data);
297 }
298
299 // Starts decoding the data. Verifies player behavior relative to
300 // |expect_player_requests_data|.
301 void Start(const DemuxerConfigs& configs, bool expect_player_requests_data) {
302 bool has_audio = configs.audio_codec != kUnknownAudioCodec;
303 bool has_video = configs.video_codec != kUnknownVideoCodec;
304 int original_num_data_requests = demuxer_->num_data_requests();
305 int expected_request_delta = expect_player_requests_data ?
306 ((has_audio ? 1 : 0) + (has_video ? 1 : 0)) : 0;
307
283 player_.OnDemuxerConfigsAvailable(configs); 308 player_.OnDemuxerConfigsAvailable(configs);
284 player_.Start(); 309 player_.Start();
310
285 EXPECT_TRUE(player_.IsPlaying()); 311 EXPECT_TRUE(player_.IsPlaying());
312 EXPECT_EQ(original_num_data_requests + expected_request_delta,
313 demuxer_->num_data_requests());
314
315 // Verify player has decoder job iff the config included the media type for
316 // the job and the player is expected to request data due to Start(), above.
317 EXPECT_EQ(expect_player_requests_data && has_audio,
318 GetMediaDecoderJob(true) != NULL);
319 EXPECT_EQ(expect_player_requests_data && has_video,
320 GetMediaDecoderJob(false) != NULL);
286 } 321 }
287 322
288 AccessUnit CreateAccessUnitWithData(bool is_audio, int audio_packet_id) { 323 AccessUnit CreateAccessUnitWithData(bool is_audio, int audio_packet_id) {
289 AccessUnit unit; 324 AccessUnit unit;
290 325
291 unit.status = DemuxerStream::kOk; 326 unit.status = DemuxerStream::kOk;
292 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile( 327 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(
293 is_audio ? base::StringPrintf("vorbis-packet-%d", audio_packet_id) 328 is_audio ? base::StringPrintf("vorbis-packet-%d", audio_packet_id)
294 : "vp8-I-frame-320x240"); 329 : "vp8-I-frame-320x240");
295 unit.data = std::vector<uint8>( 330 unit.data = std::vector<uint8>(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // the player should not yet have sent the DemuxerSeek IPC request, though 379 // the player should not yet have sent the DemuxerSeek IPC request, though
345 // seek event should be pending. The audio decoder job will also still be 380 // seek event should be pending. The audio decoder job will also still be
346 // decoding. 381 // decoding.
347 void StartAudioDecoderJobAndSeekToWhileDecoding( 382 void StartAudioDecoderJobAndSeekToWhileDecoding(
348 const base::TimeDelta& seek_time) { 383 const base::TimeDelta& seek_time) {
349 EXPECT_FALSE(GetMediaDecoderJob(true)); 384 EXPECT_FALSE(GetMediaDecoderJob(true));
350 EXPECT_FALSE(player_.IsPlaying()); 385 EXPECT_FALSE(player_.IsPlaying());
351 EXPECT_EQ(0, demuxer_->num_data_requests()); 386 EXPECT_EQ(0, demuxer_->num_data_requests());
352 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); 387 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF());
353 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp()); 388 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp());
354 StartAudioDecoderJob(); 389 StartAudioDecoderJob(true);
355 EXPECT_TRUE(GetMediaDecoderJob(true));
356 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 390 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
357 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 391 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
358 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 392 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
359 player_.SeekTo(seek_time); 393 player_.SeekTo(seek_time);
360 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); 394 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF());
361 EXPECT_EQ(1, demuxer_->num_data_requests());
362 EXPECT_EQ(0, demuxer_->num_seek_requests()); 395 EXPECT_EQ(0, demuxer_->num_seek_requests());
363 } 396 }
364 397
365 // Seek, including simulated receipt of |kAborted| read between SeekTo() 398 // Seek, including simulated receipt of |kAborted| read between SeekTo() and
366 // and OnDemuxerSeekDone(). Use this helper method only when the player 399 // OnDemuxerSeekDone(). Use this helper method only when the player already
367 // already has created the decoder job. 400 // has created the decoder job. Exactly one request for more data is expected
368 void SeekPlayer(bool is_audio, const base::TimeDelta& seek_time) { 401 // following the seek, so use this helper for players with only audio or only
369 EXPECT_TRUE(GetMediaDecoderJob(is_audio)); 402 // video.
370 403 void SeekPlayerWithAbort(bool is_audio, const base::TimeDelta& seek_time) {
371 int original_num_seeks = demuxer_->num_seek_requests(); 404 int original_num_seeks = demuxer_->num_seek_requests();
372 int original_num_data_requests = demuxer_->num_data_requests(); 405 int original_num_data_requests = demuxer_->num_data_requests();
373 406
374 // Initiate a seek. Skip the round-trip of requesting seek from renderer. 407 // Initiate a seek. Skip the round-trip of requesting seek from renderer.
375 // Instead behave as if the renderer has asked us to seek. 408 // Instead behave as if the renderer has asked us to seek.
376 player_.SeekTo(seek_time); 409 player_.SeekTo(seek_time);
377 410
378 // Verify that the seek does not occur until previously outstanding data 411 // Verify that the seek does not occur until previously outstanding data
379 // request is satisfied. 412 // request is satisfied.
380 EXPECT_EQ(original_num_seeks, demuxer_->num_seek_requests()); 413 EXPECT_EQ(original_num_seeks, demuxer_->num_seek_requests());
381 414
382 // Simulate seeking causes the demuxer to abort the outstanding read caused 415 // Simulate seeking causes the demuxer to abort the outstanding read
383 // by the seek. 416 // caused by the seek.
384 player_.OnDemuxerDataAvailable(CreateAbortedAck(is_audio)); 417 player_.OnDemuxerDataAvailable(CreateAbortedAck(is_audio));
385 418
386 // Verify that the seek is requested now that the outstanding read is 419 // Verify that the seek is requested.
387 // completed by aborted access unit.
388 EXPECT_EQ(original_num_seeks + 1, demuxer_->num_seek_requests()); 420 EXPECT_EQ(original_num_seeks + 1, demuxer_->num_seek_requests());
389 421
390 // Send back the seek done notification. This should trigger the player to 422 // Send back the seek done notification. This should trigger the player to
391 // call OnReadFromDemuxer() again. 423 // call OnReadFromDemuxer() again.
392 EXPECT_EQ(original_num_data_requests, demuxer_->num_data_requests()); 424 EXPECT_EQ(original_num_data_requests, demuxer_->num_data_requests());
393 player_.OnDemuxerSeekDone(kNoTimestamp()); 425 player_.OnDemuxerSeekDone(kNoTimestamp());
394 EXPECT_EQ(original_num_data_requests + 1, demuxer_->num_data_requests()); 426 EXPECT_EQ(original_num_data_requests + 1, demuxer_->num_data_requests());
395 427
396 // No other seek should have been requested. 428 // No other seek should have been requested.
397 EXPECT_EQ(original_num_seeks + 1, demuxer_->num_seek_requests()); 429 EXPECT_EQ(original_num_seeks + 1, demuxer_->num_seek_requests());
(...skipping 13 matching lines...) Expand all
411 } 443 }
412 444
413 // Valid only for video-only player tests. If |trigger_with_release_start| is 445 // Valid only for video-only player tests. If |trigger_with_release_start| is
414 // true, triggers the browser seek with a Release() + video data received + 446 // true, triggers the browser seek with a Release() + video data received +
415 // Start() with a new surface. If false, triggers the browser seek by 447 // Start() with a new surface. If false, triggers the browser seek by
416 // setting a new video surface after beginning decode of received video data. 448 // setting a new video surface after beginning decode of received video data.
417 // Such data receipt causes possibility that an I-frame is not next, and 449 // Such data receipt causes possibility that an I-frame is not next, and
418 // browser seek results once decode completes and surface change processing 450 // browser seek results once decode completes and surface change processing
419 // begins. 451 // begins.
420 void BrowserSeekPlayer(bool trigger_with_release_start) { 452 void BrowserSeekPlayer(bool trigger_with_release_start) {
421 int expected_num_data_requests = demuxer_->num_data_requests(); 453 int expected_num_data_requests = demuxer_->num_data_requests() + 1;
422 int expected_num_seek_requests = demuxer_->num_seek_requests(); 454 int expected_num_seek_requests = demuxer_->num_seek_requests();
423 int expected_num_browser_seek_requests = 455 int expected_num_browser_seek_requests =
424 demuxer_->num_browser_seek_requests(); 456 demuxer_->num_browser_seek_requests();
425 457
426 EXPECT_FALSE(GetMediaDecoderJob(false)); 458 EXPECT_FALSE(GetMediaDecoderJob(false));
427 CreateNextTextureAndSetVideoSurface(); 459 CreateNextTextureAndSetVideoSurface();
428 StartVideoDecoderJob(); 460 StartVideoDecoderJob(true);
429 EXPECT_TRUE(GetMediaDecoderJob(false));
430 expected_num_data_requests++;
431 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
432 461
433 if (trigger_with_release_start) { 462 if (trigger_with_release_start) {
434 ReleasePlayer(); 463 ReleasePlayer();
435 464
436 // Simulate demuxer's response to the video data request. 465 // Simulate demuxer's response to the video data request.
437 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 466 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
438 EXPECT_FALSE(GetMediaDecoderJob(false)); 467 EXPECT_FALSE(GetMediaDecoderJob(false));
439 EXPECT_FALSE(player_.IsPlaying()); 468 EXPECT_FALSE(player_.IsPlaying());
440 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 469 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
441 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
442 470
443 CreateNextTextureAndSetVideoSurface(); 471 CreateNextTextureAndSetVideoSurface();
444 player_.Start(); 472 StartVideoDecoderJob(false);
445 } else { 473 } else {
446 // Simulate demuxer's response to the video data request. 474 // Simulate demuxer's response to the video data request.
447 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 475 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
448 476
449 // While the decoder is decoding, trigger a browser seek by changing 477 // While the decoder is decoding, trigger a browser seek by changing
450 // surface. Demuxer does not know of browser seek in advance, so no 478 // surface. Demuxer does not know of browser seek in advance, so no
451 // |kAborted| data is required (though |kAborted| can certainly occur for 479 // |kAborted| data is required (though |kAborted| can certainly occur for
452 // any pending read in reality due to renderer preparing for a regular 480 // any pending read in reality due to renderer preparing for a regular
453 // seek). 481 // seek).
454 CreateNextTextureAndSetVideoSurface(); 482 CreateNextTextureAndSetVideoSurface();
455 483
456 // Browser seek should not begin until decoding has completed. 484 // Browser seek should not begin until decoding has completed.
457 EXPECT_TRUE(GetMediaDecoderJob(false)); 485 EXPECT_TRUE(GetMediaDecoderJob(false));
458 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 486 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
459 EXPECT_EQ(expected_num_browser_seek_requests,
460 demuxer_->num_browser_seek_requests());
461 487
462 // Wait for the decoder job to finish decoding and be reset pending the 488 // Wait for the decoder job to finish decoding and be reset pending the
463 // browser seek. 489 // browser seek.
464 while (GetMediaDecoderJob(false) && 490 while (GetMediaDecoderJob(false))
465 GetMediaDecoderJob(false)->is_decoding()) {
466 message_loop_.RunUntilIdle(); 491 message_loop_.RunUntilIdle();
467 }
468 } 492 }
469 493
470 EXPECT_FALSE(GetMediaDecoderJob(false));
471 EXPECT_TRUE(player_.IsPlaying());
472
473 // Only one browser seek should have been initiated, and no further data 494 // Only one browser seek should have been initiated, and no further data
474 // should have been requested. 495 // should have been requested.
475 expected_num_seek_requests++; 496 expected_num_seek_requests++;
476 expected_num_browser_seek_requests++; 497 expected_num_browser_seek_requests++;
477 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 498 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
478 EXPECT_EQ(expected_num_browser_seek_requests, 499 EXPECT_EQ(expected_num_browser_seek_requests,
479 demuxer_->num_browser_seek_requests()); 500 demuxer_->num_browser_seek_requests());
480 EXPECT_EQ(expected_num_data_requests, demuxer_->num_seek_requests()); 501 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
481 } 502 }
482 503
483 // Creates a new decoder job and feeds it data ending with a |kConfigChanged| 504 // Creates a new decoder job and feeds it data ending with a |kConfigChanged|
484 // access unit. If |config_unit_in_prefetch| is true, sends feeds the config 505 // access unit. If |config_unit_in_prefetch| is true, sends feeds the config
485 // change AU in response to the job's first read request (prefetch). If 506 // change AU in response to the job's first read request (prefetch). If
486 // false, regular data is fed and decoded prior to feeding the config change 507 // false, regular data is fed and decoded prior to feeding the config change
487 // AU in response to the second data request (after prefetch completed). 508 // AU in response to the second data request (after prefetch completed).
488 // |config_unit_index| controls which access unit is |kConfigChanged|. 509 // |config_unit_index| controls which access unit is |kConfigChanged|.
489 void StartConfigChange(bool is_audio, 510 void StartConfigChange(bool is_audio,
490 bool config_unit_in_prefetch, 511 bool config_unit_in_prefetch,
491 int config_unit_index) { 512 int config_unit_index) {
492 int expected_num_data_requests = demuxer_->num_data_requests();
493 int expected_num_config_requests = demuxer_->num_config_requests(); 513 int expected_num_config_requests = demuxer_->num_config_requests();
494 514
495 EXPECT_FALSE(GetMediaDecoderJob(is_audio)); 515 EXPECT_FALSE(GetMediaDecoderJob(is_audio));
496 if (is_audio) { 516 if (is_audio) {
497 StartAudioDecoderJob(); 517 StartAudioDecoderJob(true);
498 } else { 518 } else {
499 CreateNextTextureAndSetVideoSurface(); 519 CreateNextTextureAndSetVideoSurface();
500 StartVideoDecoderJob(); 520 StartVideoDecoderJob(true);
501 } 521 }
502 EXPECT_TRUE(GetMediaDecoderJob(is_audio)); 522
503 expected_num_data_requests++; 523 int expected_num_data_requests = demuxer_->num_data_requests();
504 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
505 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests());
506 524
507 // Feed and decode a standalone access unit so the player exits prefetch. 525 // Feed and decode a standalone access unit so the player exits prefetch.
508 if (!config_unit_in_prefetch) { 526 if (!config_unit_in_prefetch) {
509 if (is_audio) 527 if (is_audio)
510 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 528 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
511 else 529 else
512 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 530 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
513 531
514 message_loop_.Run(); 532 message_loop_.Run();
515 533
516 // We should have completed the prefetch phase at this point. 534 // We should have completed the prefetch phase at this point.
517 EXPECT_TRUE(GetMediaDecoderJob(is_audio));
518 expected_num_data_requests++; 535 expected_num_data_requests++;
519 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); 536 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
520 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests());
521 } 537 }
522 538
539 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests());
540
523 // Feed and decode access units with data for any units prior to 541 // Feed and decode access units with data for any units prior to
524 // |config_unit_index|, and a |kConfigChanged| unit at that index. 542 // |config_unit_index|, and a |kConfigChanged| unit at that index.
525 // Player should prepare to reconfigure the decoder job, and should request 543 // Player should prepare to reconfigure the decoder job, and should request
526 // new demuxer configs. 544 // new demuxer configs.
527 player_.OnDemuxerDataAvailable( 545 player_.OnDemuxerDataAvailable(
528 CreateReadFromDemuxerAckWithConfigChanged(is_audio, config_unit_index)); 546 CreateReadFromDemuxerAckWithConfigChanged(is_audio, config_unit_index));
529 while (GetMediaDecoderJob(is_audio)->is_decoding()) 547 WaitForDecodeDone(is_audio, !is_audio);
530 message_loop_.RunUntilIdle();
531 548
532 expected_num_config_requests++; 549 expected_num_config_requests++;
533 EXPECT_TRUE(player_.IsPlaying());
534 EXPECT_TRUE(GetMediaDecoderJob(is_audio));
535 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); 550 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
536 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests()); 551 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests());
537 } 552 }
538 553
539 void CreateNextTextureAndSetVideoSurface() { 554 void CreateNextTextureAndSetVideoSurface() {
540 gfx::SurfaceTexture* surface_texture; 555 gfx::SurfaceTexture* surface_texture;
541 if (surface_texture_a_is_next_) { 556 if (surface_texture_a_is_next_) {
542 surface_texture_a_ = new gfx::SurfaceTexture(next_texture_id_++); 557 surface_texture_a_ = new gfx::SurfaceTexture(next_texture_id_++);
543 surface_texture = surface_texture_a_.get(); 558 surface_texture = surface_texture_a_.get();
544 } else { 559 } else {
545 surface_texture_b_ = new gfx::SurfaceTexture(next_texture_id_++); 560 surface_texture_b_ = new gfx::SurfaceTexture(next_texture_id_++);
546 surface_texture = surface_texture_b_.get(); 561 surface_texture = surface_texture_b_.get();
547 } 562 }
548 563
549 surface_texture_a_is_next_ = !surface_texture_a_is_next_; 564 surface_texture_a_is_next_ = !surface_texture_a_is_next_;
550 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture); 565 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture);
551 player_.SetVideoSurface(surface.Pass()); 566 player_.SetVideoSurface(surface.Pass());
552 } 567 }
553 568
569 // Wait for one or both of the jobs to complete decoding. Decoder jobs are
570 // assumed to exist for any stream whose decode completion is awaited.
571 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) {
572 DCHECK(wait_for_audio || wait_for_video);
573
574 while ((wait_for_audio && GetMediaDecoderJob(true)->is_decoding()) ||
575 (wait_for_video && GetMediaDecoderJob(false)->is_decoding())) {
576 message_loop_.RunUntilIdle();
577 }
578 }
579
580 void WaitForAudioDecodeDone() {
581 WaitForDecodeDone(true, false);
582 }
583
584 void WaitForVideoDecodeDone() {
585 WaitForDecodeDone(false, true);
586 }
587
588 void WaitForAudioVideoDecodeDone() {
589 WaitForDecodeDone(true, true);
590 }
591
592 // If |send_eos| is true, generates EOS for the stream corresponding to
593 // |eos_for_audio|. Verifies that playback completes and no further data
594 // is requested.
595 // If |send_eos| is false, then it is assumed that caller previously arranged
596 // for player to receive EOS for each stream, but the player has not yet
597 // decoded all of them. In this case, |eos_for_audio| is ignored.
598 void VerifyPlaybackCompletesOnEOSDecode(bool send_eos, bool eos_for_audio) {
599 int original_num_data_requests = demuxer_->num_data_requests();
600 if (send_eos)
601 player_.OnDemuxerDataAvailable(CreateEOSAck(eos_for_audio));
602 EXPECT_FALSE(manager_.playback_completed());
603 message_loop_.Run();
604 EXPECT_TRUE(manager_.playback_completed());
605 EXPECT_EQ(original_num_data_requests, demuxer_->num_data_requests());
606 }
607
608 void VerifyCompletedPlaybackResumesOnSeekPlusStart(bool have_audio,
609 bool have_video) {
610 DCHECK(have_audio || have_video);
611
612 EXPECT_TRUE(manager_.playback_completed());
613
614 player_.SeekTo(base::TimeDelta());
615 player_.OnDemuxerSeekDone(kNoTimestamp());
616 Start(CreateDemuxerConfigs(have_audio, have_video), true);
617 }
618
619 // Starts the appropriate decoder jobs according to |have_audio| and
620 // |have_video|. Then starts seek during decode of EOS or non-EOS according to
621 // |eos_audio| and |eos_video|. Simulates seek completion and verifies that
622 // playback never completed.
623 void VerifySeekDuringEOSDecodePreventsPlaybackCompletion(bool have_audio,
624 bool have_video,
625 bool eos_audio,
626 bool eos_video) {
627 DCHECK(have_audio || have_video);
628 DCHECK(have_audio || !eos_audio);
qinmin 2013/12/12 19:40:22 nit: this feels redundant. If have_audio is false,
wolenetz 2013/12/12 21:26:06 Done.
629 DCHECK(have_video || !eos_video);
630
631 if (have_video)
632 CreateNextTextureAndSetVideoSurface();
633
634 Start(CreateDemuxerConfigs(have_audio, have_video), true);
635
636 if (have_audio)
637 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
638
639 if (have_video)
640 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
641
642 // Run until more data is requested a number of times equal to the number of
643 // media types configured. Since prefetching may be in progress, we cannot
644 // reliably expect Run() to complete until we have sent demuxer data for all
645 // configured media types, above.
646 for (int i = 0; i < (have_audio ? 1 : 0) + (have_video ? 1 : 0); i++)
647 message_loop_.Run();
648
649 // Simulate seek while decoding EOS or non-EOS for the appropriate
650 // stream(s).
651 if (eos_audio) {
652 player_.OnDemuxerDataAvailable(CreateEOSAck(true));
653 } else if (have_audio) {
654 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(1));
655 }
656
657 if (eos_video) {
658 player_.OnDemuxerDataAvailable(CreateEOSAck(false));
659 } else if (have_video) {
660 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
661 }
662
663 player_.SeekTo(base::TimeDelta());
664 EXPECT_EQ(0, demuxer_->num_seek_requests());
665 WaitForDecodeDone(have_audio, have_video);
666 EXPECT_EQ(1, demuxer_->num_seek_requests());
667
668 player_.OnDemuxerSeekDone(kNoTimestamp());
669 EXPECT_FALSE(manager_.playback_completed());
670 }
671
554 base::TimeTicks StartTimeTicks() { 672 base::TimeTicks StartTimeTicks() {
555 return player_.start_time_ticks_; 673 return player_.start_time_ticks_;
556 } 674 }
557 675
558 bool IsTypeSupported(const std::vector<uint8>& scheme_uuid, 676 bool IsTypeSupported(const std::vector<uint8>& scheme_uuid,
559 const std::string& security_level, 677 const std::string& security_level,
560 const std::string& container, 678 const std::string& container,
561 const std::vector<std::string>& codecs) { 679 const std::vector<std::string>& codecs) {
562 return MediaSourcePlayer::IsTypeSupported( 680 return MediaSourcePlayer::IsTypeSupported(
563 scheme_uuid, security_level, container, codecs); 681 scheme_uuid, security_level, container, codecs);
(...skipping 19 matching lines...) Expand all
583 bool surface_texture_a_is_next_; 701 bool surface_texture_a_is_next_;
584 int next_texture_id_; 702 int next_texture_id_;
585 703
586 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest); 704 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest);
587 }; 705 };
588 706
589 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) { 707 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) {
590 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 708 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
591 709
592 // Test audio decoder job will be created when codec is successfully started. 710 // Test audio decoder job will be created when codec is successfully started.
593 StartAudioDecoderJob(); 711 StartAudioDecoderJob(true);
594 EXPECT_TRUE(GetMediaDecoderJob(true));
595 EXPECT_EQ(1, demuxer_->num_data_requests());
596 EXPECT_EQ(0, demuxer_->num_seek_requests()); 712 EXPECT_EQ(0, demuxer_->num_seek_requests());
597 } 713 }
598 714
599 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { 715 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) {
600 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 716 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
601 717
602 // Test audio decoder job will not be created when failed to start the codec. 718 // Test audio decoder job will not be created when failed to start the codec.
603 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 719 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis);
604 // Replace with invalid |audio_extra_data| 720 // Replace with invalid |audio_extra_data|
605 configs.audio_extra_data.clear(); 721 configs.audio_extra_data.clear();
606 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; 722 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff };
607 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), 723 configs.audio_extra_data.insert(configs.audio_extra_data.begin(),
608 invalid_codec_data, invalid_codec_data + 4); 724 invalid_codec_data, invalid_codec_data + 4);
609 Start(configs); 725 Start(configs, false);
610 EXPECT_FALSE(GetMediaDecoderJob(true));
611 EXPECT_EQ(0, demuxer_->num_data_requests());
612 EXPECT_EQ(0, demuxer_->num_seek_requests()); 726 EXPECT_EQ(0, demuxer_->num_seek_requests());
613 } 727 }
614 728
615 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { 729 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) {
616 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 730 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
617 731
618 // Test video decoder job will be created when surface is valid. 732 // Test video decoder job will be created when surface is valid.
619 StartVideoDecoderJob();
620 // Video decoder job will not be created until surface is available. 733 // Video decoder job will not be created until surface is available.
621 EXPECT_FALSE(GetMediaDecoderJob(false)); 734 StartVideoDecoderJob(false);
622 EXPECT_EQ(0, demuxer_->num_data_requests());
623 735
624 // Set both an initial and a later video surface without receiving any 736 // Set both an initial and a later video surface without receiving any
625 // demuxed data yet. 737 // demuxed data yet.
626 CreateNextTextureAndSetVideoSurface(); 738 CreateNextTextureAndSetVideoSurface();
627 MediaDecoderJob* first_job = GetMediaDecoderJob(false); 739 MediaDecoderJob* first_job = GetMediaDecoderJob(false);
628 EXPECT_TRUE(first_job); 740 EXPECT_TRUE(first_job);
629 CreateNextTextureAndSetVideoSurface(); 741 CreateNextTextureAndSetVideoSurface();
630 742
631 // Setting another surface will not create a new job until any pending 743 // Setting another surface will not create a new job until any pending
632 // read is satisfied (and job is no longer decoding). 744 // read is satisfied (and job is no longer decoding).
633 EXPECT_EQ(first_job, GetMediaDecoderJob(false)); 745 EXPECT_EQ(first_job, GetMediaDecoderJob(false));
634 746
635 // No seeks, even on setting surface, should have occurred. (Browser seeks can 747 // No seeks, even on setting surface, should have occurred. (Browser seeks can
636 // occur on setting surface, but only after previously receiving video data.) 748 // occur on setting surface, but only after previously receiving video data.)
637 EXPECT_EQ(0, demuxer_->num_seek_requests()); 749 EXPECT_EQ(0, demuxer_->num_seek_requests());
638 750
639 // Note, the decoder job for the second surface set, above, will be created 751 // Note, the decoder job for the second surface set, above, will be created
640 // only after the pending read is satisfied and decoded, and the resulting 752 // only after the pending read is satisfied and decoded, and the resulting
641 // browser seek is done. See BrowserSeek_* tests for this coverage. 753 // browser seek is done. See BrowserSeek_* tests for this coverage.
642 } 754 }
643 755
644 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { 756 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) {
645 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 757 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
646 758
647 // Test video decoder job will be created when surface is valid. 759 // Test video decoder job will not be created when surface is invalid.
648 scoped_refptr<gfx::SurfaceTexture> surface_texture( 760 scoped_refptr<gfx::SurfaceTexture> surface_texture(
649 new gfx::SurfaceTexture(0)); 761 new gfx::SurfaceTexture(0));
650 gfx::ScopedJavaSurface surface(surface_texture.get()); 762 gfx::ScopedJavaSurface surface(surface_texture.get());
651 StartVideoDecoderJob(); 763 StartVideoDecoderJob(false);
652 // Video decoder job will not be created until surface is available.
653 EXPECT_FALSE(GetMediaDecoderJob(false));
654 EXPECT_EQ(0, demuxer_->num_data_requests());
655 764
656 // Release the surface texture. 765 // Release the surface texture.
657 surface_texture = NULL; 766 surface_texture = NULL;
658 player_.SetVideoSurface(surface.Pass()); 767 player_.SetVideoSurface(surface.Pass());
659 768
660 // Player should not seek the demuxer on setting initial surface. 769 // Player should not seek the demuxer on setting initial surface.
661 EXPECT_EQ(0, demuxer_->num_seek_requests()); 770 EXPECT_EQ(0, demuxer_->num_seek_requests());
662 771
663 EXPECT_FALSE(GetMediaDecoderJob(false)); 772 EXPECT_FALSE(GetMediaDecoderJob(false));
664 EXPECT_EQ(0, demuxer_->num_data_requests()); 773 EXPECT_EQ(0, demuxer_->num_data_requests());
665 } 774 }
666 775
667 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) { 776 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) {
668 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 777 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
669 778
670 // Test decoder job will resend a ReadFromDemuxer request after seek. 779 // Test decoder job will resend a ReadFromDemuxer request after seek.
671 StartAudioDecoderJob(); 780 StartAudioDecoderJob(true);
672 EXPECT_TRUE(GetMediaDecoderJob(true)); 781 SeekPlayerWithAbort(true, base::TimeDelta());
673 EXPECT_EQ(1, demuxer_->num_data_requests());
674 SeekPlayer(true, base::TimeDelta());
675 EXPECT_EQ(2, demuxer_->num_data_requests());
676 } 782 }
677 783
678 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { 784 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) {
679 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 785 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
680 786
681 // Test SetVideoSurface() will not cause an extra seek while the player is 787 // Test SetVideoSurface() will not cause an extra seek while the player is
682 // waiting for demuxer to indicate seek is done. 788 // waiting for demuxer to indicate seek is done.
683 StartVideoDecoderJob();
684 // Player is still waiting for SetVideoSurface(), so no request is sent. 789 // Player is still waiting for SetVideoSurface(), so no request is sent.
685 EXPECT_EQ(0, demuxer_->num_data_requests()); 790 StartVideoDecoderJob(false); // Verifies no data requested.
686 791
687 // Initiate a seek. Skip requesting element seek of renderer. 792 // Initiate a seek. Skip requesting element seek of renderer.
688 // Instead behave as if the renderer has asked us to seek. 793 // Instead behave as if the renderer has asked us to seek.
689 EXPECT_EQ(0, demuxer_->num_seek_requests()); 794 EXPECT_EQ(0, demuxer_->num_seek_requests());
690 player_.SeekTo(base::TimeDelta()); 795 player_.SeekTo(base::TimeDelta());
691 EXPECT_EQ(1, demuxer_->num_seek_requests()); 796 EXPECT_EQ(1, demuxer_->num_seek_requests());
692 797
693 CreateNextTextureAndSetVideoSurface(); 798 CreateNextTextureAndSetVideoSurface();
694 EXPECT_FALSE(GetMediaDecoderJob(false)); 799 EXPECT_FALSE(GetMediaDecoderJob(false));
695 EXPECT_EQ(1, demuxer_->num_seek_requests()); 800 EXPECT_EQ(1, demuxer_->num_seek_requests());
(...skipping 10 matching lines...) Expand all
706 // was not a browser seek request. 811 // was not a browser seek request.
707 EXPECT_EQ(1, demuxer_->num_seek_requests()); 812 EXPECT_EQ(1, demuxer_->num_seek_requests());
708 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 813 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
709 } 814 }
710 815
711 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) { 816 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) {
712 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 817 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
713 818
714 // Test MediaSourcePlayer can switch multiple surfaces during decoding. 819 // Test MediaSourcePlayer can switch multiple surfaces during decoding.
715 CreateNextTextureAndSetVideoSurface(); 820 CreateNextTextureAndSetVideoSurface();
716 StartVideoDecoderJob(); 821 StartVideoDecoderJob(true);
717 EXPECT_EQ(1, demuxer_->num_data_requests());
718 EXPECT_EQ(0, demuxer_->num_seek_requests()); 822 EXPECT_EQ(0, demuxer_->num_seek_requests());
719 EXPECT_TRUE(GetMediaDecoderJob(false));
720 823
721 // Send the first input chunk. 824 // Send the first input chunk.
722 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 825 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
723 826
724 // While the decoder is decoding, change multiple surfaces. Pass an empty 827 // While the decoder is decoding, change multiple surfaces. Pass an empty
725 // surface first. 828 // surface first.
726 gfx::ScopedJavaSurface empty_surface; 829 gfx::ScopedJavaSurface empty_surface;
727 player_.SetVideoSurface(empty_surface.Pass()); 830 player_.SetVideoSurface(empty_surface.Pass());
728 // Next, pass a new non-empty surface. 831 // Next, pass a new non-empty surface.
729 CreateNextTextureAndSetVideoSurface(); 832 CreateNextTextureAndSetVideoSurface();
730 833
731 // Wait for the decoder job to finish decoding and be reset pending a browser 834 // Wait for the decoder job to finish decoding and be reset pending a browser
732 // seek. 835 // seek.
733 while (GetMediaDecoderJob(false) && GetMediaDecoderJob(false)->is_decoding()) 836 while (GetMediaDecoderJob(false))
734 message_loop_.RunUntilIdle(); 837 message_loop_.RunUntilIdle();
735 EXPECT_FALSE(GetMediaDecoderJob(false));
736 838
737 // Only one browser seek should have been initiated. No further data request 839 // Only one browser seek should have been initiated. No further data request
738 // should have been processed on |message_loop_| before surface change event 840 // should have been processed on |message_loop_| before surface change event
739 // became pending, above. 841 // became pending, above.
740 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 842 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
741 EXPECT_EQ(1, demuxer_->num_data_requests()); 843 EXPECT_EQ(1, demuxer_->num_data_requests());
742 844
743 // Simulate browser seek is done and confirm player requests more data for new 845 // Simulate browser seek is done and confirm player requests more data for new
744 // video decoder job. 846 // video decoder job.
745 player_.OnDemuxerSeekDone(player_.GetCurrentTime()); 847 player_.OnDemuxerSeekDone(player_.GetCurrentTime());
746 EXPECT_TRUE(GetMediaDecoderJob(false)); 848 EXPECT_TRUE(GetMediaDecoderJob(false));
747 EXPECT_EQ(2, demuxer_->num_data_requests()); 849 EXPECT_EQ(2, demuxer_->num_data_requests());
748 EXPECT_EQ(1, demuxer_->num_seek_requests()); 850 EXPECT_EQ(1, demuxer_->num_seek_requests());
749 } 851 }
750 852
751 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) { 853 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) {
752 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 854 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
753 855
754 // Test audio decoder job will not start until pending seek event is handled. 856 // Test audio decoder job will not start until pending seek event is handled.
755 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 857 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis);
756 player_.OnDemuxerConfigsAvailable(configs); 858 player_.OnDemuxerConfigsAvailable(configs);
757 EXPECT_FALSE(GetMediaDecoderJob(true)); 859 EXPECT_FALSE(GetMediaDecoderJob(true));
758 EXPECT_EQ(0, demuxer_->num_data_requests());
759 860
760 // Initiate a seek. Skip requesting element seek of renderer. 861 // Initiate a seek. Skip requesting element seek of renderer.
761 // Instead behave as if the renderer has asked us to seek. 862 // Instead behave as if the renderer has asked us to seek.
762 player_.SeekTo(base::TimeDelta()); 863 player_.SeekTo(base::TimeDelta());
763 EXPECT_EQ(1, demuxer_->num_seek_requests()); 864 EXPECT_EQ(1, demuxer_->num_seek_requests());
764 865
765 player_.Start(); 866 player_.Start();
766 EXPECT_FALSE(GetMediaDecoderJob(true)); 867 EXPECT_FALSE(GetMediaDecoderJob(true));
767 EXPECT_EQ(0, demuxer_->num_data_requests()); 868 EXPECT_EQ(0, demuxer_->num_data_requests());
768 869
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 901
801 // Reconfirm exactly 1 seek request has been made of demuxer. 902 // Reconfirm exactly 1 seek request has been made of demuxer.
802 EXPECT_EQ(1, demuxer_->num_seek_requests()); 903 EXPECT_EQ(1, demuxer_->num_seek_requests());
803 } 904 }
804 905
805 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) { 906 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) {
806 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 907 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
807 908
808 // Test that if the decoding job is not fully stopped after Pause(), 909 // Test that if the decoding job is not fully stopped after Pause(),
809 // calling Start() will be a noop. 910 // calling Start() will be a noop.
810 StartAudioDecoderJob(); 911 StartAudioDecoderJob(true);
811 912
812 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 913 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true);
813 EXPECT_TRUE(decoder_job);
814 EXPECT_EQ(1, demuxer_->num_data_requests());
815 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 914 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
816 915
817 // Sending data to player. 916 // Sending data to player.
818 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 917 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
819 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 918 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
820 919
821 // Decoder job will not immediately stop after Pause() since it is 920 // Decoder job will not immediately stop after Pause() since it is
822 // running on another thread. 921 // running on another thread.
823 player_.Pause(true); 922 player_.Pause(true);
824 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 923 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
825 924
826 // Nothing happens when calling Start() again. 925 // Nothing happens when calling Start() again.
827 player_.Start(); 926 player_.Start();
828 // Verify that Start() will not destroy and recreate the decoder job. 927 // Verify that Start() will not destroy and recreate the decoder job.
829 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 928 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
830 EXPECT_EQ(1, demuxer_->num_data_requests()); 929 EXPECT_EQ(1, demuxer_->num_data_requests());
831 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 930 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
832 message_loop_.Run(); 931 message_loop_.Run();
833 // The decoder job should finish and a new request will be sent. 932 // The decoder job should finish and a new request will be sent.
834 EXPECT_EQ(2, demuxer_->num_data_requests()); 933 EXPECT_EQ(2, demuxer_->num_data_requests());
835 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 934 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
836 } 935 }
837 936
838 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { 937 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) {
839 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 938 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
840 939
841 // Test that when Start() is called, video decoder jobs will wait for audio 940 // Test that when Start() is called, video decoder jobs will wait for audio
842 // decoder job before start decoding the data. 941 // decoder job before start decoding the data.
843 DemuxerConfigs configs = CreateAudioVideoDemuxerConfigs();
844 Start(configs);
845 EXPECT_EQ(0, demuxer_->num_data_requests());
846
847 CreateNextTextureAndSetVideoSurface(); 942 CreateNextTextureAndSetVideoSurface();
848 943 Start(CreateAudioVideoDemuxerConfigs(), true);
849 // Player should not seek the demuxer on setting initial surface.
850 EXPECT_EQ(0, demuxer_->num_seek_requests());
851
852 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true); 944 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true);
853 MediaDecoderJob* video_decoder_job = GetMediaDecoderJob(false); 945 MediaDecoderJob* video_decoder_job = GetMediaDecoderJob(false);
854 EXPECT_EQ(2, demuxer_->num_data_requests()); 946
855 EXPECT_FALSE(audio_decoder_job->is_decoding()); 947 EXPECT_FALSE(audio_decoder_job->is_decoding());
856 EXPECT_FALSE(video_decoder_job->is_decoding()); 948 EXPECT_FALSE(video_decoder_job->is_decoding());
857 949
858 // Sending video data to player, audio decoder should not start. 950 // Sending video data to player, video decoder should not start.
859 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 951 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
860 EXPECT_FALSE(video_decoder_job->is_decoding()); 952 EXPECT_FALSE(video_decoder_job->is_decoding());
861 953
862 // Sending audio data to player, both decoders should start now. 954 // Sending audio data to player, both decoders should start now.
863 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 955 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
864 EXPECT_TRUE(audio_decoder_job->is_decoding()); 956 EXPECT_TRUE(audio_decoder_job->is_decoding());
865 EXPECT_TRUE(video_decoder_job->is_decoding()); 957 EXPECT_TRUE(video_decoder_job->is_decoding());
866 958
867 // Reconfirm no seek occurred. 959 // No seeks should have occurred.
868 EXPECT_EQ(0, demuxer_->num_seek_requests()); 960 EXPECT_EQ(0, demuxer_->num_seek_requests());
869 } 961 }
870 962
871 TEST_F(MediaSourcePlayerTest, StartTimeTicksResetAfterDecoderUnderruns) { 963 TEST_F(MediaSourcePlayerTest, StartTimeTicksResetAfterDecoderUnderruns) {
872 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 964 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
873 965
874 // Test start time ticks will reset after decoder job underruns. 966 // Test start time ticks will reset after decoder job underruns.
875 StartAudioDecoderJob(); 967 StartAudioDecoderJob(true);
876 EXPECT_TRUE(GetMediaDecoderJob(true)); 968
877 EXPECT_EQ(1, demuxer_->num_data_requests());
878 // For the first couple chunks, the decoder job may return 969 // For the first couple chunks, the decoder job may return
879 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode 970 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode
880 // more frames to guarantee that DECODE_SUCCEEDED will be returned. 971 // more frames to guarantee that DECODE_SUCCEEDED will be returned.
881 for (int i = 0; i < 4; ++i) { 972 for (int i = 0; i < 4; ++i) {
882 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); 973 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i));
883 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 974 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
884 message_loop_.Run(); 975 message_loop_.Run();
885 } 976 }
886 977
887 // The decoder job should finish and a new request will be sent. 978 // The decoder job should finish and a new request will be sent.
888 EXPECT_EQ(5, demuxer_->num_data_requests()); 979 EXPECT_EQ(5, demuxer_->num_data_requests());
889 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 980 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
890 base::TimeTicks previous = StartTimeTicks(); 981 base::TimeTicks previous = StartTimeTicks();
891 982
892 // Let the decoder timeout and execute the OnDecoderStarved() callback. 983 // Let the decoder timeout and execute the OnDecoderStarved() callback.
893 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 984 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
894 985
895 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 986 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
896 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); 987 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks());
897 message_loop_.RunUntilIdle(); 988 message_loop_.RunUntilIdle();
898 989
899 // Send new data to the decoder so it can finish the currently 990 // Send new data to the decoder so it can finish the currently
900 // pending decode. 991 // pending decode.
901 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 992 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
902 while (GetMediaDecoderJob(true)->is_decoding()) 993 WaitForAudioDecodeDone();
903 message_loop_.RunUntilIdle();
904 994
905 // Verify the start time ticks is cleared at this point because the 995 // Verify the start time ticks is cleared at this point because the
906 // player is prefetching. 996 // player is prefetching.
907 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks()); 997 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks());
908 998
909 // Send new data to the decoder so it can finish prefetching. This should 999 // Send new data to the decoder so it can finish prefetching. This should
910 // reset the start time ticks. 1000 // reset the start time ticks.
911 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1001 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
912 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); 1002 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks());
913 1003
914 base::TimeTicks current = StartTimeTicks(); 1004 base::TimeTicks current = StartTimeTicks();
915 EXPECT_LE(100.0, (current - previous).InMillisecondsF()); 1005 EXPECT_LE(100.0, (current - previous).InMillisecondsF());
916 } 1006 }
917 1007
918 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterInputEOS) { 1008 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) {
919 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1009 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
920 1010
921 // Test MediaSourcePlayer will not request for new data after input EOS is 1011 // Test MediaSourcePlayer can replay video after input EOS is reached.
922 // reached. 1012 CreateNextTextureAndSetVideoSurface();
923 CreateNextTextureAndSetVideoSurface(); 1013 StartVideoDecoderJob(true);
924 StartVideoDecoderJob(); 1014
925 // Player should not seek the demuxer on setting initial surface.
926 EXPECT_EQ(0, demuxer_->num_seek_requests());
927
928 EXPECT_EQ(1, demuxer_->num_data_requests());
929 // Send the first input chunk. 1015 // Send the first input chunk.
930 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1016 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
931 message_loop_.Run(); 1017 message_loop_.Run();
1018
1019 VerifyPlaybackCompletesOnEOSDecode(true, false);
1020 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true);
1021 }
1022
1023 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) {
1024 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1025
1026 // Test decode of audio EOS buffer without any prior decode. See also
1027 // http://b/11696552.
1028 // Also tests that seeking+Start() after completing audio playback resumes
1029 // playback.
1030 Start(CreateAudioDemuxerConfigs(kCodecAAC), true);
1031 VerifyPlaybackCompletesOnEOSDecode(true, true);
1032 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, false);
1033 }
1034
1035 TEST_F(MediaSourcePlayerTest, V_FirstAccessUnitAfterSeekIsEOS) {
1036 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1037
1038 // Test decode of video EOS buffer, just after seeking, without any prior
1039 // decode (other than the simulated |kAborted| resulting from the seek
1040 // process.)
1041 CreateNextTextureAndSetVideoSurface();
1042 StartVideoDecoderJob(true);
1043 SeekPlayerWithAbort(false, base::TimeDelta());
1044 VerifyPlaybackCompletesOnEOSDecode(true, false);
1045 }
1046
1047 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitAfterSeekIsEOS) {
1048 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1049
1050 // Test decode of audio EOS buffer, just after seeking, without any prior
1051 // decode (other than the simulated |kAborted| resulting from the seek
1052 // process.) See also http://b/11696552.
1053 Start(CreateAudioDemuxerConfigs(kCodecAAC), true);
1054 SeekPlayerWithAbort(true, base::TimeDelta());
1055 VerifyPlaybackCompletesOnEOSDecode(true, true);
1056 }
1057
1058 TEST_F(MediaSourcePlayerTest, AV_PlaybackCompletionAcrossConfigChange) {
1059 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1060
1061 // Test that if one stream (audio) has completed decode of EOS and the other
1062 // stream (video) processes config change, that subsequent video EOS completes
1063 // A/V playback.
1064 // Also tests that seeking+Start() after completing playback resumes playback.
1065 CreateNextTextureAndSetVideoSurface();
1066 Start(CreateAudioVideoDemuxerConfigs(), true);
1067
1068 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1069 EXPECT_EQ(0, demuxer_->num_config_requests());
1070 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1071 false, 0)); // Video |kConfigChanged| as first unit.
1072
1073 WaitForAudioVideoDecodeDone();
1074
1075 EXPECT_EQ(1, demuxer_->num_config_requests());
932 EXPECT_EQ(2, demuxer_->num_data_requests()); 1076 EXPECT_EQ(2, demuxer_->num_data_requests());
933 1077 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs());
934 // Send EOS. 1078 EXPECT_EQ(3, demuxer_->num_data_requests());
935 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); 1079
936 message_loop_.Run(); 1080 // At no time after completing audio EOS decode, above, should the
937 // No more request for data should be made. 1081 // audio decoder job resume decoding. Send and decode video EOS.
1082 VerifyPlaybackCompletesOnEOSDecode(true, false);
1083 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
1084 }
1085
1086 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) {
1087 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1088
1089 // Test that if one stream (video) has completed decode of EOS and the other
1090 // stream (audio) processes config change, that subsequent audio EOS completes
1091 // A/V playback.
1092 // Also tests that seeking+Start() after completing playback resumes playback.
1093 CreateNextTextureAndSetVideoSurface();
1094 Start(CreateAudioVideoDemuxerConfigs(), true);
1095
1096 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1097 EXPECT_EQ(0, demuxer_->num_config_requests());
1098 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1099 true, 0)); // Audio |kConfigChanged| as first unit.
1100
1101 WaitForAudioVideoDecodeDone();
1102
1103 // TODO(wolenetz/qinmin): Prevent redundant demuxer config request and change
1104 // expectation to 1 here. See http://crbug.com/325528.
1105 EXPECT_EQ(2, demuxer_->num_config_requests());
938 EXPECT_EQ(2, demuxer_->num_data_requests()); 1106 EXPECT_EQ(2, demuxer_->num_data_requests());
939 1107 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs());
940 // Reconfirm no seek request has occurred. 1108 EXPECT_EQ(3, demuxer_->num_data_requests());
941 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1109
942 } 1110 // At no time after completing video EOS decode, above, should the
943 1111 // video decoder job resume decoding. Send and decode audio EOS.
944 TEST_F(MediaSourcePlayerTest, ReplayAfterInputEOS) { 1112 VerifyPlaybackCompletesOnEOSDecode(true, true);
945 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1113 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
946 1114 }
947 // Test MediaSourcePlayer can replay after input EOS is 1115
948 // reached. 1116 TEST_F(MediaSourcePlayerTest, AV_NoPrefetchForFinishedVideoOnAudioStarvation) {
949 CreateNextTextureAndSetVideoSurface(); 1117 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
950 StartVideoDecoderJob(); 1118
951 1119 // Test that if one stream (video) has completed decode of EOS, prefetch
952 // Player should not seek the demuxer on setting initial surface. 1120 // resulting from player starvation occurs only for the other stream (audio),
953 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1121 // and responding to that prefetch with EOS completes A/V playback, even if
954 1122 // another starvation occurs during the latter EOS's decode.
955 EXPECT_EQ(1, demuxer_->num_data_requests()); 1123 CreateNextTextureAndSetVideoSurface();
956 // Send the first input chunk. 1124 Start(CreateAudioVideoDemuxerConfigs(), true);
1125
1126 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1127 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1128
1129 // Wait until video EOS is processed and more data (assumed to be audio) is
1130 // requested.
1131 while (demuxer_->num_data_requests() < 3)
1132 message_loop_.RunUntilIdle();
1133 WaitForVideoDecodeDone();
1134 EXPECT_EQ(3, demuxer_->num_data_requests());
1135
1136 // Simulate decoder underrun to trigger prefetch while still decoding audio.
1137 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(1));
1138 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding() &&
1139 !GetMediaDecoderJob(false)->is_decoding());
1140 TriggerPlayerStarvation();
1141
1142 // Complete the audio decode that was in progress when simulated player
1143 // starvation was triggered.
1144 WaitForAudioDecodeDone();
1145 EXPECT_EQ(4, demuxer_->num_data_requests());
1146
1147 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1148 EXPECT_FALSE(GetMediaDecoderJob(false)->is_decoding());
1149 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1150
1151 // Simulate another decoder underrun to trigger prefetch while decoding EOS.
1152 TriggerPlayerStarvation();
1153 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */);
1154 }
1155
1156 TEST_F(MediaSourcePlayerTest, V_StarvationDuringEOSDecode) {
1157 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1158
1159 // Test that video-only playback completes without further data requested when
1160 // starvation occurs during EOS decode.
1161 CreateNextTextureAndSetVideoSurface();
1162 StartVideoDecoderJob(true);
957 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1163 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
958 message_loop_.Run(); 1164 message_loop_.Run();
959 EXPECT_EQ(2, demuxer_->num_data_requests()); 1165
960 1166 // Simulate decoder underrun to trigger prefetch while decoding EOS.
961 // Send EOS. 1167 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
962 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); 1168 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding());
1169 TriggerPlayerStarvation();
1170 VerifyPlaybackCompletesOnEOSDecode(false, false /* ignored */);
1171 }
1172
1173 TEST_F(MediaSourcePlayerTest, A_StarvationDuringEOSDecode) {
1174 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1175
1176 // Test that audio-only playback completes without further data requested when
1177 // starvation occurs during EOS decode.
1178 StartAudioDecoderJob(true);
1179 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
963 message_loop_.Run(); 1180 message_loop_.Run();
964 // No more request for data should be made. 1181
965 EXPECT_EQ(2, demuxer_->num_data_requests()); 1182 // Simulate decoder underrun to trigger prefetch while decoding EOS.
966 1183 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
967 // Initiate a seek. Skip requesting element seek of renderer. 1184 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
968 // Instead behave as if the renderer has asked us to seek. 1185 TriggerPlayerStarvation();
969 player_.SeekTo(base::TimeDelta()); 1186 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */);
970 StartVideoDecoderJob(); 1187 }
971 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1188
972 player_.OnDemuxerSeekDone(kNoTimestamp()); 1189 TEST_F(MediaSourcePlayerTest, AV_SeekDuringEOSDecodePreventsCompletion) {
973 // Seek/Play after EOS should request more data. 1190 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
974 EXPECT_EQ(3, demuxer_->num_data_requests()); 1191
975 1192 // Test that seek supercedes audio+video playback completion on simultaneous
976 // Reconfirm only 1 seek request has occurred. 1193 // audio and video EOS decode, if SeekTo() occurs during these EOS decodes.
977 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1194 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(true, true, true, true);
978 } 1195 }
979 1196
980 TEST_F(MediaSourcePlayerTest, FirstDataIsEOS) { 1197 TEST_F(MediaSourcePlayerTest, AV_SeekDuringAudioEOSDecodePreventsCompletion) {
981 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1198 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
982 1199
983 // Test decode of EOS buffer without any prior decode. See also 1200 // Test that seek supercedes audio+video playback completion on simultaneous
984 // http://b/11696552. 1201 // audio EOS and video non-EOS decode, if SeekTo() occurs during these
985 Start(CreateAudioDemuxerConfigs(kCodecAAC)); 1202 // decodes.
986 EXPECT_TRUE(GetMediaDecoderJob(true)); 1203 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(true, true, true, false);
987 1204 }
988 EXPECT_EQ(1, demuxer_->num_data_requests()); 1205
989 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); 1206 TEST_F(MediaSourcePlayerTest, AV_SeekDuringVideoEOSDecodePreventsCompletion) {
990 EXPECT_FALSE(manager_.playback_completed()); 1207 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
991 1208
992 message_loop_.Run(); 1209 // Test that seek supercedes audio+video playback completion on simultaneous
993 EXPECT_TRUE(manager_.playback_completed()); 1210 // audio non-EOS and video EOS decode, if SeekTo() occurs during these
994 EXPECT_EQ(1, demuxer_->num_data_requests()); 1211 // decodes.
995 } 1212 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(true, true, false, true);
996 1213 }
997 TEST_F(MediaSourcePlayerTest, FirstDataAfterSeekIsEOS) { 1214
998 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1215 TEST_F(MediaSourcePlayerTest, V_SeekDuringEOSDecodePreventsCompletion) {
999 1216 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1000 // Test decode of EOS buffer, just after seeking, without any prior decode 1217
1001 // (other than the simulated |kAborted| resulting from the seek process.) 1218 // Test that seek supercedes video-only playback completion on EOS decode, if
1002 // See also http://b/11696552. 1219 // SeekTo() occurs during EOS decode.
1003 Start(CreateAudioDemuxerConfigs(kCodecAAC)); 1220 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(false, true, false, true);
1004 EXPECT_TRUE(GetMediaDecoderJob(true)); 1221 }
1005 1222
1006 SeekPlayer(true, base::TimeDelta()); 1223 TEST_F(MediaSourcePlayerTest, A_SeekDuringEOSDecodePreventsCompletion) {
1007 EXPECT_EQ(2, demuxer_->num_data_requests()); 1224 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1008 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); 1225
1009 EXPECT_FALSE(manager_.playback_completed()); 1226 // Test that seek supercedes audio-only playback completion on EOS decode, if
1010 1227 // SeekTo() occurs during EOS decode.
1011 message_loop_.Run(); 1228 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(true, false, true, false);
1012 EXPECT_TRUE(manager_.playback_completed());
1013 EXPECT_EQ(2, demuxer_->num_data_requests());
1014 } 1229 }
1015 1230
1016 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterAbort) { 1231 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterAbort) {
1017 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1232 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1018 1233
1019 // Test that the decoder will not request new data after receiving an aborted 1234 // Test that the decoder will not request new data after receiving an aborted
1020 // access unit. 1235 // access unit.
1021 StartAudioDecoderJob(); 1236 StartAudioDecoderJob(true);
1022 EXPECT_EQ(1, demuxer_->num_data_requests());
1023 1237
1024 // Send an aborted access unit. 1238 // Send an aborted access unit.
1025 player_.OnDemuxerDataAvailable(CreateAbortedAck(true)); 1239 player_.OnDemuxerDataAvailable(CreateAbortedAck(true));
1026
1027 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1240 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1028 // Wait for the decoder job to finish decoding. 1241 WaitForAudioDecodeDone();
1029 while (GetMediaDecoderJob(true)->is_decoding())
1030 message_loop_.RunUntilIdle();
1031 1242
1032 // No request will be sent for new data. 1243 // No request will be sent for new data.
1033 EXPECT_EQ(1, demuxer_->num_data_requests()); 1244 EXPECT_EQ(1, demuxer_->num_data_requests());
1034 1245
1035 // No seek requests should have occurred. 1246 // No seek requests should have occurred.
1036 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1247 EXPECT_EQ(0, demuxer_->num_seek_requests());
1037 } 1248 }
1038 1249
1039 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) { 1250 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) {
1040 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1251 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1041 1252
1042 // Test that the decoder should not crash if demuxer data arrives after 1253 // Test that the decoder should not crash if demuxer data arrives after
1043 // Release(). 1254 // Release().
1044 StartAudioDecoderJob(); 1255 StartAudioDecoderJob(true);
1045 EXPECT_EQ(1, demuxer_->num_data_requests());
1046 EXPECT_TRUE(GetMediaDecoderJob(true));
1047 1256
1048 ReleasePlayer(); 1257 ReleasePlayer();
1049 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1258 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1050 1259
1051 // The decoder job should have been released. 1260 // The decoder job should have been released.
1052 EXPECT_FALSE(player_.IsPlaying()); 1261 EXPECT_FALSE(player_.IsPlaying());
1262
1263 // No further data should have been requested.
1053 EXPECT_EQ(1, demuxer_->num_data_requests()); 1264 EXPECT_EQ(1, demuxer_->num_data_requests());
1054 1265
1055 // No seek requests should have occurred. 1266 // No seek requests should have occurred.
1056 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1267 EXPECT_EQ(0, demuxer_->num_seek_requests());
1057 } 1268 }
1058 1269
1059 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) { 1270 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) {
1060 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1271 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1061 1272
1062 // Test that a browser seek, once started, delays a newly arrived regular 1273 // Test that a browser seek, once started, delays a newly arrived regular
1063 // SeekTo() request's demuxer seek until the browser seek is done. 1274 // SeekTo() request's demuxer seek until the browser seek is done.
1064 BrowserSeekPlayer(false); 1275 BrowserSeekPlayer(false);
1065 EXPECT_EQ(1, demuxer_->num_data_requests());
1066 1276
1067 // Simulate renderer requesting a regular seek while browser seek in progress. 1277 // Simulate renderer requesting a regular seek while browser seek in progress.
1068 player_.SeekTo(base::TimeDelta()); 1278 player_.SeekTo(base::TimeDelta());
1069 EXPECT_FALSE(GetMediaDecoderJob(false)); 1279 EXPECT_FALSE(GetMediaDecoderJob(false));
1070 1280
1071 // Simulate browser seek is done. Confirm player requests the regular seek, 1281 // Simulate browser seek is done. Confirm player requests the regular seek,
1072 // still has no video decoder job configured, and has not requested any 1282 // still has no video decoder job configured, and has not requested any
1073 // further data since the surface change event became pending in 1283 // further data since the surface change event became pending in
1074 // BrowserSeekPlayer(). 1284 // BrowserSeekPlayer().
1075 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1285 EXPECT_EQ(1, demuxer_->num_seek_requests());
(...skipping 10 matching lines...) Expand all
1086 EXPECT_EQ(2, demuxer_->num_data_requests()); 1296 EXPECT_EQ(2, demuxer_->num_data_requests());
1087 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1297 EXPECT_EQ(2, demuxer_->num_seek_requests());
1088 } 1298 }
1089 1299
1090 TEST_F(MediaSourcePlayerTest, NoSeekForInitialReleaseAndStart) { 1300 TEST_F(MediaSourcePlayerTest, NoSeekForInitialReleaseAndStart) {
1091 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1301 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1092 1302
1093 // Test that no seek is requested if player Release() + Start() occurs prior 1303 // Test that no seek is requested if player Release() + Start() occurs prior
1094 // to receiving any data. 1304 // to receiving any data.
1095 CreateNextTextureAndSetVideoSurface(); 1305 CreateNextTextureAndSetVideoSurface();
1096 StartVideoDecoderJob(); 1306 StartVideoDecoderJob(true);
1097 EXPECT_EQ(1, demuxer_->num_data_requests());
1098 EXPECT_TRUE(GetMediaDecoderJob(false));
1099
1100 ReleasePlayer(); 1307 ReleasePlayer();
1101 1308
1102 // Pass a new non-empty surface. 1309 // Pass a new non-empty surface.
1103 CreateNextTextureAndSetVideoSurface(); 1310 CreateNextTextureAndSetVideoSurface();
1104 1311
1105 player_.Start(); 1312 player_.Start();
1106 1313
1107 // TODO(wolenetz/qinmin): Multiple in-flight data requests for same stream 1314 // TODO(wolenetz/qinmin): Multiple in-flight data requests for same stream
1108 // should be prevented. See http://crbug.com/306314. 1315 // should be prevented. See http://crbug.com/306314.
1109 EXPECT_EQ(2, demuxer_->num_data_requests()); 1316 EXPECT_EQ(2, demuxer_->num_data_requests());
1317 EXPECT_TRUE(GetMediaDecoderJob(false));
1110 1318
1111 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1319 EXPECT_EQ(0, demuxer_->num_seek_requests());
1112 EXPECT_TRUE(GetMediaDecoderJob(false));
1113 } 1320 }
1114 1321
1115 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) { 1322 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) {
1116 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1323 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1117 1324
1118 // Test that one browser seek is requested if player Release() + Start(), with 1325 // Test that one browser seek is requested if player Release() + Start(), with
1119 // video data received between Release() and Start(). 1326 // video data received between Release() and Start().
1120 BrowserSeekPlayer(true); 1327 BrowserSeekPlayer(true);
1121 EXPECT_EQ(1, demuxer_->num_data_requests()); 1328 EXPECT_EQ(1, demuxer_->num_data_requests());
1122 1329
1123 // Simulate browser seek is done and confirm player requests more data. 1330 // Simulate browser seek is done and confirm player requests more data.
1124 player_.OnDemuxerSeekDone(base::TimeDelta()); 1331 player_.OnDemuxerSeekDone(base::TimeDelta());
1125 EXPECT_TRUE(GetMediaDecoderJob(false)); 1332 EXPECT_TRUE(GetMediaDecoderJob(false));
1126 EXPECT_EQ(2, demuxer_->num_data_requests()); 1333 EXPECT_EQ(2, demuxer_->num_data_requests());
1127 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1334 EXPECT_EQ(1, demuxer_->num_seek_requests());
1128 } 1335 }
1129 1336
1130 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { 1337 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) {
1131 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1338 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1132 1339
1133 // Test decoder job will preroll the media to the seek position. 1340 // Test decoder job will preroll the media to the seek position.
1134 StartAudioDecoderJob(); 1341 StartAudioDecoderJob(true);
1135 EXPECT_TRUE(GetMediaDecoderJob(true));
1136 EXPECT_EQ(1, demuxer_->num_data_requests());
1137 1342
1138 SeekPlayer(true, base::TimeDelta::FromMilliseconds(100)); 1343 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1139 EXPECT_TRUE(IsPrerolling(true)); 1344 EXPECT_TRUE(IsPrerolling(true));
1140 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1345 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1141 1346
1142 // Send some data before the seek position. 1347 // Send some data before the seek position.
1143 for (int i = 1; i < 4; ++i) { 1348 for (int i = 1; i < 4; ++i) {
1144 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); 1349 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i));
1145 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1350 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1146 message_loop_.Run(); 1351 message_loop_.Run();
1147 } 1352 }
1148 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1353 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1149 EXPECT_TRUE(IsPrerolling(true)); 1354 EXPECT_TRUE(IsPrerolling(true));
1150 1355
1151 // Send data after the seek position. 1356 // Send data after the seek position.
1152 DemuxerData data = CreateReadFromDemuxerAckForAudio(3); 1357 DemuxerData data = CreateReadFromDemuxerAckForAudio(3);
1153 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100); 1358 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100);
1154 player_.OnDemuxerDataAvailable(data); 1359 player_.OnDemuxerDataAvailable(data);
1155 message_loop_.Run(); 1360 message_loop_.Run();
1156 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF()); 1361 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF());
1157 EXPECT_FALSE(IsPrerolling(true)); 1362 EXPECT_FALSE(IsPrerolling(true));
1158 } 1363 }
1159 1364
1160 TEST_F(MediaSourcePlayerTest, PrerollVideoAfterSeek) { 1365 TEST_F(MediaSourcePlayerTest, PrerollVideoAfterSeek) {
1161 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1366 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1162 1367
1163 // Test decoder job will preroll the media to the seek position. 1368 // Test decoder job will preroll the media to the seek position.
1164 CreateNextTextureAndSetVideoSurface(); 1369 CreateNextTextureAndSetVideoSurface();
1165 StartVideoDecoderJob(); 1370 StartVideoDecoderJob(true);
1166 EXPECT_TRUE(GetMediaDecoderJob(false));
1167 EXPECT_EQ(1, demuxer_->num_data_requests());
1168 1371
1169 SeekPlayer(false, base::TimeDelta::FromMilliseconds(100)); 1372 SeekPlayerWithAbort(false, base::TimeDelta::FromMilliseconds(100));
1170 EXPECT_TRUE(IsPrerolling(false)); 1373 EXPECT_TRUE(IsPrerolling(false));
1171 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1374 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1172 1375
1173 // Send some data before the seek position. 1376 // Send some data before the seek position.
1174 DemuxerData data; 1377 DemuxerData data;
1175 for (int i = 1; i < 4; ++i) { 1378 for (int i = 1; i < 4; ++i) {
1176 data = CreateReadFromDemuxerAckForVideo(); 1379 data = CreateReadFromDemuxerAckForVideo();
1177 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 30); 1380 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 30);
1178 player_.OnDemuxerDataAvailable(data); 1381 player_.OnDemuxerDataAvailable(data);
1179 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding()); 1382 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding());
1180 message_loop_.Run(); 1383 message_loop_.Run();
1181 } 1384 }
1182 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1385 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1183 EXPECT_TRUE(IsPrerolling(false)); 1386 EXPECT_TRUE(IsPrerolling(false));
1184 1387
1185 // Send data at the seek position. 1388 // Send data at the seek position.
1186 data = CreateReadFromDemuxerAckForVideo(); 1389 data = CreateReadFromDemuxerAckForVideo();
1187 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100); 1390 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100);
1188 player_.OnDemuxerDataAvailable(data); 1391 player_.OnDemuxerDataAvailable(data);
1189 message_loop_.Run(); 1392 message_loop_.Run();
1190 1393
1191 // TODO(wolenetz/qinmin): Player's maintenance of current time for video-only 1394 // TODO(wolenetz/qinmin): Player's maintenance of current time for video-only
1192 // streams depends on decoder output, which may be initially inaccurate, and 1395 // streams depends on decoder output, which may be initially inaccurate, and
1193 // encoded video test data may also need updating. Verify at least that AU 1396 // encoded video test data may also need updating. Verify at least that AU
1194 // timestamp-based preroll logic has determined video preroll has completed. 1397 // timestamp-based preroll logic has determined video preroll has completed.
1398 // See http://crbug.com/310823 and http://b/11356652.
1195 EXPECT_FALSE(IsPrerolling(false)); 1399 EXPECT_FALSE(IsPrerolling(false));
1196 } 1400 }
1197 1401
1198 TEST_F(MediaSourcePlayerTest, SeekingAfterCompletingPrerollRestartsPreroll) { 1402 TEST_F(MediaSourcePlayerTest, SeekingAfterCompletingPrerollRestartsPreroll) {
1199 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1403 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1200 1404
1201 // Test decoder job will begin prerolling upon seek, when it was not 1405 // Test decoder job will begin prerolling upon seek, when it was not
1202 // prerolling prior to the seek. 1406 // prerolling prior to the seek.
1203 StartAudioDecoderJob(); 1407 StartAudioDecoderJob(true);
1204 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 1408 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true);
1205 EXPECT_TRUE(decoder_job);
1206 EXPECT_EQ(1, demuxer_->num_data_requests());
1207 EXPECT_TRUE(IsPrerolling(true)); 1409 EXPECT_TRUE(IsPrerolling(true));
1208 1410
1209 // Complete the initial preroll by feeding data to the decoder. 1411 // Complete the initial preroll by feeding data to the decoder.
1210 for (int i = 0; i < 4; ++i) { 1412 for (int i = 0; i < 4; ++i) {
1211 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); 1413 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i));
1212 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1414 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1213 message_loop_.Run(); 1415 message_loop_.Run();
1214 } 1416 }
1215 EXPECT_LT(0.0, player_.GetCurrentTime().InMillisecondsF()); 1417 EXPECT_LT(0.0, player_.GetCurrentTime().InMillisecondsF());
1216 EXPECT_FALSE(IsPrerolling(true)); 1418 EXPECT_FALSE(IsPrerolling(true));
1217 1419
1218 SeekPlayer(true, base::TimeDelta::FromMilliseconds(500)); 1420 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(500));
1219 1421
1220 // Prerolling should have begun again. 1422 // Prerolling should have begun again.
1221 EXPECT_TRUE(IsPrerolling(true)); 1423 EXPECT_TRUE(IsPrerolling(true));
1222 EXPECT_EQ(500.0, GetPrerollTimestamp().InMillisecondsF()); 1424 EXPECT_EQ(500.0, GetPrerollTimestamp().InMillisecondsF());
1223 1425
1224 // Send data at and after the seek position. Prerolling should complete. 1426 // Send data at and after the seek position. Prerolling should complete.
1225 for (int i = 0; i < 4; ++i) { 1427 for (int i = 0; i < 4; ++i) {
1226 DemuxerData data = CreateReadFromDemuxerAckForAudio(i); 1428 DemuxerData data = CreateReadFromDemuxerAckForAudio(i);
1227 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds( 1429 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(
1228 500 + 30 * (i - 1)); 1430 500 + 30 * (i - 1));
1229 player_.OnDemuxerDataAvailable(data); 1431 player_.OnDemuxerDataAvailable(data);
1230 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1432 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1231 message_loop_.Run(); 1433 message_loop_.Run();
1232 } 1434 }
1233 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF()); 1435 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF());
1234 EXPECT_FALSE(IsPrerolling(true)); 1436 EXPECT_FALSE(IsPrerolling(true));
1235 1437
1236 // Throughout this test, we should have not re-created the decoder job, so 1438 // Throughout this test, we should have not re-created the decoder job, so
1237 // IsPrerolling() transition from false to true was not due to constructor 1439 // IsPrerolling() transition from false to true was not due to constructor
1238 // initialization. It was due to BeginPrerolling(). 1440 // initialization. It was due to BeginPrerolling().
1239 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 1441 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
1240 } 1442 }
1241 1443
1242 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossReleaseAndStart) { 1444 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossReleaseAndStart) {
1243 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1445 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1244 1446
1245 // Test decoder job will resume media prerolling if interrupted by Release() 1447 // Test decoder job will resume media prerolling if interrupted by Release()
1246 // and Start(). 1448 // and Start().
1247 StartAudioDecoderJob(); 1449 StartAudioDecoderJob(true);
1248 EXPECT_TRUE(GetMediaDecoderJob(true));
1249 EXPECT_EQ(1, demuxer_->num_data_requests());
1250 1450
1251 SeekPlayer(true, base::TimeDelta::FromMilliseconds(100)); 1451 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1252 EXPECT_TRUE(IsPrerolling(true)); 1452 EXPECT_TRUE(IsPrerolling(true));
1253 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1453 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1254 1454
1255 // Send some data before the seek position. 1455 // Send some data before the seek position.
1256 // Test uses 'large' number of iterations because decoder job may not get 1456 // Test uses 'large' number of iterations because decoder job may not get
1257 // MEDIA_CODEC_OK output status until after a few dequeue output attempts. 1457 // MEDIA_CODEC_OK output status until after a few dequeue output attempts.
1258 // This allows decoder status to stabilize prior to AU timestamp reaching 1458 // This allows decoder status to stabilize prior to AU timestamp reaching
1259 // the preroll target. 1459 // the preroll target.
1260 DemuxerData data; 1460 DemuxerData data;
1261 for (int i = 0; i < 10; ++i) { 1461 for (int i = 0; i < 10; ++i) {
1262 data = CreateReadFromDemuxerAckForAudio(3); 1462 data = CreateReadFromDemuxerAckForAudio(3);
1263 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 10); 1463 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 10);
1264 if (i == 1) { 1464 if (i == 1) {
1265 // While still prerolling, Release() and Start() the player. 1465 // While still prerolling, Release() and Start() the player.
1266 // TODO(qinmin): Simulation of multiple in-flight data requests (one from 1466 // TODO(qinmin): Simulation of multiple in-flight data requests (one from
1267 // before Release(), one from after Start()) is not included here, and 1467 // before Release(), one from after Start()) is not included here, and
1268 // neither is any data enqueued for later decode if it arrives after 1468 // neither is any data enqueued for later decode if it arrives after
1269 // Release() and before Start(). See http://crbug.com/306314. Assumption 1469 // Release() and before Start(). See http://crbug.com/306314. Assumption
1270 // for this test, to prevent flakiness until the bug is fixed, is the 1470 // for this test, to prevent flakiness until the bug is fixed, is the
1271 // first request's data arrives before Start(). Though that data is not 1471 // first request's data arrives before Start(). Though that data is not
1272 // seen by decoder, this assumption allows preroll continuation 1472 // seen by decoder, this assumption allows preroll continuation
1273 // verification and prevents multiple in-flight data requests. 1473 // verification and prevents multiple in-flight data requests.
1274 ReleasePlayer(); 1474 ReleasePlayer();
1275 player_.OnDemuxerDataAvailable(data); 1475 player_.OnDemuxerDataAvailable(data);
1276 message_loop_.RunUntilIdle(); 1476 message_loop_.RunUntilIdle();
1277 EXPECT_FALSE(GetMediaDecoderJob(true)); 1477 EXPECT_FALSE(GetMediaDecoderJob(true));
1278 StartAudioDecoderJob(); 1478 StartAudioDecoderJob(true);
1279 EXPECT_TRUE(GetMediaDecoderJob(true));
1280 } else { 1479 } else {
1281 player_.OnDemuxerDataAvailable(data); 1480 player_.OnDemuxerDataAvailable(data);
1282 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1481 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1283 message_loop_.Run(); 1482 message_loop_.Run();
1284 } 1483 }
1285 EXPECT_TRUE(IsPrerolling(true)); 1484 EXPECT_TRUE(IsPrerolling(true));
1286 } 1485 }
1287 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1486 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1288 EXPECT_TRUE(IsPrerolling(true)); 1487 EXPECT_TRUE(IsPrerolling(true));
1289 1488
1290 // Send data after the seek position. 1489 // Send data after the seek position.
1291 data = CreateReadFromDemuxerAckForAudio(3); 1490 data = CreateReadFromDemuxerAckForAudio(3);
1292 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100); 1491 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100);
1293 player_.OnDemuxerDataAvailable(data); 1492 player_.OnDemuxerDataAvailable(data);
1294 message_loop_.Run(); 1493 message_loop_.Run();
1295 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF()); 1494 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF());
1296 EXPECT_FALSE(IsPrerolling(true)); 1495 EXPECT_FALSE(IsPrerolling(true));
1297 } 1496 }
1298 1497
1299 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) { 1498 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) {
1300 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1499 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1301 1500
1302 // Test decoder job will resume media prerolling if interrupted by 1501 // Test decoder job will resume media prerolling if interrupted by
1303 // |kConfigChanged| and OnDemuxerConfigsAvailable(). 1502 // |kConfigChanged| and OnDemuxerConfigsAvailable().
1304 StartAudioDecoderJob(); 1503 StartAudioDecoderJob(true);
1305 EXPECT_TRUE(GetMediaDecoderJob(true));
1306 EXPECT_EQ(1, demuxer_->num_data_requests());
1307 1504
1308 SeekPlayer(true, base::TimeDelta::FromMilliseconds(100)); 1505 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1309 EXPECT_TRUE(IsPrerolling(true)); 1506 EXPECT_TRUE(IsPrerolling(true));
1310 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1507 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1311 1508
1312 // In response to data request, simulate that demuxer signals config change by 1509 // In response to data request, simulate that demuxer signals config change by
1313 // sending an AU with |kConfigChanged|. Player should prepare to reconfigure 1510 // sending an AU with |kConfigChanged|. Player should prepare to reconfigure
1314 // the audio decoder job, and should request new demuxer configs. 1511 // the audio decoder job, and should request new demuxer configs.
1315 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); 1512 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0);
1316 EXPECT_EQ(0, demuxer_->num_config_requests()); 1513 EXPECT_EQ(0, demuxer_->num_config_requests());
1317 player_.OnDemuxerDataAvailable(data); 1514 player_.OnDemuxerDataAvailable(data);
1318 EXPECT_EQ(1, demuxer_->num_config_requests()); 1515 EXPECT_EQ(1, demuxer_->num_config_requests());
(...skipping 18 matching lines...) Expand all
1337 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF()); 1534 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF());
1338 EXPECT_FALSE(IsPrerolling(true)); 1535 EXPECT_FALSE(IsPrerolling(true));
1339 } 1536 }
1340 1537
1341 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) { 1538 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) {
1342 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1539 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1343 1540
1344 // Test that the player allows simultaneous audio and video config change, 1541 // Test that the player allows simultaneous audio and video config change,
1345 // such as might occur during OnPrefetchDone() if next access unit for both 1542 // such as might occur during OnPrefetchDone() if next access unit for both
1346 // audio and video jobs is |kConfigChanged|. 1543 // audio and video jobs is |kConfigChanged|.
1347 Start(CreateAudioVideoDemuxerConfigs());
1348 CreateNextTextureAndSetVideoSurface(); 1544 CreateNextTextureAndSetVideoSurface();
1545 Start(CreateAudioVideoDemuxerConfigs(), true);
1349 MediaDecoderJob* first_audio_job = GetMediaDecoderJob(true); 1546 MediaDecoderJob* first_audio_job = GetMediaDecoderJob(true);
1350 MediaDecoderJob* first_video_job = GetMediaDecoderJob(false); 1547 MediaDecoderJob* first_video_job = GetMediaDecoderJob(false);
1351 EXPECT_TRUE(first_audio_job && first_video_job);
1352 1548
1353 // Simulate audio |kConfigChanged| prefetched as standalone access unit. 1549 // Simulate audio |kConfigChanged| prefetched as standalone access unit.
1354 player_.OnDemuxerDataAvailable( 1550 player_.OnDemuxerDataAvailable(
1355 CreateReadFromDemuxerAckWithConfigChanged(true, 0)); 1551 CreateReadFromDemuxerAckWithConfigChanged(true, 0));
1356 EXPECT_EQ(0, demuxer_->num_config_requests()); // No OnPrefetchDone() yet. 1552 EXPECT_EQ(0, demuxer_->num_config_requests()); // No OnPrefetchDone() yet.
1357 1553
1358 // Simulate video |kConfigChanged| prefetched as standalone access unit. 1554 // Simulate video |kConfigChanged| prefetched as standalone access unit.
1359 player_.OnDemuxerDataAvailable( 1555 player_.OnDemuxerDataAvailable(
1360 CreateReadFromDemuxerAckWithConfigChanged(false, 0)); 1556 CreateReadFromDemuxerAckWithConfigChanged(false, 0));
1361 EXPECT_EQ(1, demuxer_->num_config_requests()); // OnPrefetchDone() occurred. 1557 EXPECT_EQ(1, demuxer_->num_config_requests()); // OnPrefetchDone() occurred.
1362 EXPECT_EQ(2, demuxer_->num_data_requests()); 1558 EXPECT_EQ(2, demuxer_->num_data_requests()); // No more data requested yet.
1363 1559
1364 // No job re-creation should occur until the requested configs arrive. 1560 // No job re-creation should occur until the requested configs arrive.
1365 EXPECT_EQ(first_audio_job, GetMediaDecoderJob(true)); 1561 EXPECT_EQ(first_audio_job, GetMediaDecoderJob(true));
1366 EXPECT_EQ(first_video_job, GetMediaDecoderJob(false)); 1562 EXPECT_EQ(first_video_job, GetMediaDecoderJob(false));
1367 1563
1368 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs()); 1564 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs());
1369 EXPECT_EQ(4, demuxer_->num_data_requests()); 1565 EXPECT_EQ(4, demuxer_->num_data_requests());
1370 MediaDecoderJob* second_audio_job = GetMediaDecoderJob(true); 1566 MediaDecoderJob* second_audio_job = GetMediaDecoderJob(true);
1371 MediaDecoderJob* second_video_job = GetMediaDecoderJob(false); 1567 MediaDecoderJob* second_video_job = GetMediaDecoderJob(false);
1372 EXPECT_NE(first_audio_job, second_audio_job); 1568 EXPECT_NE(first_audio_job, second_audio_job);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 1747
1552 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { 1748 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) {
1553 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1749 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1554 1750
1555 // Test if OnPrefetchDone() had already been posted before and is executed 1751 // Test if OnPrefetchDone() had already been posted before and is executed
1556 // after Release(), then player does not DCHECK. This test is fragile to 1752 // after Release(), then player does not DCHECK. This test is fragile to
1557 // change to MediaDecoderJob::Prefetch() implementation; it assumes task 1753 // change to MediaDecoderJob::Prefetch() implementation; it assumes task
1558 // is posted to run |prefetch_cb| if the job already HasData(). 1754 // is posted to run |prefetch_cb| if the job already HasData().
1559 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test 1755 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test
1560 // becomes obsolete. See http://crbug.com/304234. 1756 // becomes obsolete. See http://crbug.com/304234.
1561 StartAudioDecoderJob(); 1757 StartAudioDecoderJob(true);
1562 1758
1563 // Escape the original prefetch by decoding a single access unit. 1759 // Escape the original prefetch by decoding a single access unit.
1564 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1760 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1565 message_loop_.Run(); 1761 message_loop_.Run();
1566 1762
1567 // Prime the job with a few more access units, so that a later prefetch, 1763 // Prime the job with a few more access units, so that a later prefetch,
1568 // triggered by starvation to simulate decoder underrun, can trivially 1764 // triggered by starvation to simulate decoder underrun, can trivially
1569 // post task to run OnPrefetchDone(). 1765 // post task to run OnPrefetchDone().
1570 player_.OnDemuxerDataAvailable( 1766 player_.OnDemuxerDataAvailable(
1571 CreateReadFromDemuxerAckWithConfigChanged(true, 4)); 1767 CreateReadFromDemuxerAckWithConfigChanged(true, 4));
1572 EXPECT_TRUE(GetMediaDecoderJob(true) && 1768 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1573 GetMediaDecoderJob(true)->is_decoding());
1574 1769
1575 // Simulate decoder underrun, so trivial prefetch starts while still decoding. 1770 // Simulate decoder underrun, so trivial prefetch starts while still decoding.
1576 // The prefetch and posting of OnPrefetchDone() will not occur until next 1771 // The prefetch and posting of OnPrefetchDone() will not occur until next
1577 // MediaDecoderCallBack() occurs. 1772 // MediaDecoderCallBack() occurs.
1578 TriggerPlayerStarvation(); 1773 TriggerPlayerStarvation();
1579 1774
1580 // Upon the next successful decode callback, post a task to call Release() on 1775 // Upon the next successful decode callback, post a task to call Release() on
1581 // the |player_|, such that the trivial OnPrefetchDone() task posting also 1776 // the |player_|, such that the trivial OnPrefetchDone() task posting also
1582 // occurs and should execute after the Release(). 1777 // occurs and should execute after the Release().
1583 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); 1778 OnNextTestDecodeCallbackPostTaskToReleasePlayer();
1584 1779
1585 while (GetMediaDecoderJob(true)) 1780 while (GetMediaDecoderJob(true))
1586 message_loop_.RunUntilIdle(); 1781 message_loop_.RunUntilIdle();
1587 EXPECT_TRUE(decoder_callback_hook_executed_); 1782 EXPECT_TRUE(decoder_callback_hook_executed_);
1588 EXPECT_EQ(2, demuxer_->num_data_requests()); 1783 EXPECT_EQ(2, demuxer_->num_data_requests());
1589 1784
1590 // Player should have no decoder job until after Start(). 1785 // Player should have no decoder job until after Start().
1591 StartAudioDecoderJob(); 1786 StartAudioDecoderJob(true);
1592 EXPECT_TRUE(GetMediaDecoderJob(true));
1593 } 1787 }
1594 1788
1595 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { 1789 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) {
1596 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1790 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1597 1791
1598 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1792 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request
1599 // has not yet been sent, then the seek request is sent after Release(). Also, 1793 // has not yet been sent, then the seek request is sent after Release(). Also,
1600 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player 1794 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player
1601 // will resume correct post-seek preroll upon Start(). 1795 // will resume correct post-seek preroll upon Start().
1602 StartAudioDecoderJobAndSeekToWhileDecoding( 1796 StartAudioDecoderJobAndSeekToWhileDecoding(
1603 base::TimeDelta::FromMilliseconds(100)); 1797 base::TimeDelta::FromMilliseconds(100));
1604 ReleasePlayer(); 1798 ReleasePlayer();
1605 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1799 EXPECT_EQ(1, demuxer_->num_seek_requests());
1606 1800
1607 player_.OnDemuxerSeekDone(kNoTimestamp()); 1801 player_.OnDemuxerSeekDone(kNoTimestamp());
1608 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1802 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1609 EXPECT_FALSE(GetMediaDecoderJob(true)); 1803 EXPECT_FALSE(GetMediaDecoderJob(true));
1610 EXPECT_FALSE(player_.IsPlaying()); 1804 EXPECT_FALSE(player_.IsPlaying());
1611 1805
1612 // Player should begin prefetch and resume preroll upon Start(). 1806 // Player should begin prefetch and resume preroll upon Start().
1613 EXPECT_EQ(1, demuxer_->num_data_requests()); 1807 EXPECT_EQ(1, demuxer_->num_data_requests());
1614 StartAudioDecoderJob(); 1808 StartAudioDecoderJob(true);
1615 EXPECT_TRUE(GetMediaDecoderJob(true));
1616 EXPECT_TRUE(IsPrerolling(true)); 1809 EXPECT_TRUE(IsPrerolling(true));
1617 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1810 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1618 EXPECT_EQ(2, demuxer_->num_data_requests());
1619 1811
1620 // No further seek should have been requested since Release(), above. 1812 // No further seek should have been requested since Release(), above.
1621 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1813 EXPECT_EQ(1, demuxer_->num_seek_requests());
1622 } 1814 }
1623 1815
1624 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { 1816 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) {
1625 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1817 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1626 1818
1627 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1819 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request
1628 // has not yet been sent, then the seek request is sent after Release(). Also, 1820 // has not yet been sent, then the seek request is sent after Release(). Also,
1629 // test if OnDemuxerSeekDone() does not occur until after the next Start(), 1821 // test if OnDemuxerSeekDone() does not occur until after the next Start(),
1630 // then the player remains pending seek done until (and resumes correct 1822 // then the player remains pending seek done until (and resumes correct
1631 // post-seek preroll after) OnDemuxerSeekDone(). 1823 // post-seek preroll after) OnDemuxerSeekDone().
1632 StartAudioDecoderJobAndSeekToWhileDecoding( 1824 StartAudioDecoderJobAndSeekToWhileDecoding(
1633 base::TimeDelta::FromMilliseconds(100)); 1825 base::TimeDelta::FromMilliseconds(100));
1634 ReleasePlayer(); 1826 ReleasePlayer();
1635 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1827 EXPECT_EQ(1, demuxer_->num_seek_requests());
1636 1828
1637 // Player should not prefetch upon Start() nor create the decoder job, due to 1829 // Player should not prefetch upon Start() nor create the decoder job, due to
1638 // awaiting DemuxerSeekDone. 1830 // awaiting DemuxerSeekDone.
1639 StartAudioDecoderJob();
1640 EXPECT_FALSE(GetMediaDecoderJob(true));
1641 EXPECT_EQ(1, demuxer_->num_data_requests()); 1831 EXPECT_EQ(1, demuxer_->num_data_requests());
1832 StartAudioDecoderJob(false);
1642 1833
1643 player_.OnDemuxerSeekDone(kNoTimestamp()); 1834 player_.OnDemuxerSeekDone(kNoTimestamp());
1644 EXPECT_TRUE(GetMediaDecoderJob(true)); 1835 EXPECT_TRUE(GetMediaDecoderJob(true));
1645 EXPECT_TRUE(IsPrerolling(true)); 1836 EXPECT_TRUE(IsPrerolling(true));
1646 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1837 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1647 EXPECT_EQ(2, demuxer_->num_data_requests()); 1838 EXPECT_EQ(2, demuxer_->num_data_requests());
1648 1839
1649 // No further seek should have been requested since Release(), above. 1840 // No further seek should have been requested since Release(), above.
1650 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1841 EXPECT_EQ(1, demuxer_->num_seek_requests());
1651 } 1842 }
1652 1843
1653 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) { 1844 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) {
1654 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1845 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1655 1846
1656 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC 1847 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC
1657 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the 1848 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the
1658 // player will resume correct post-seek preroll upon Start(). 1849 // player will resume correct post-seek preroll upon Start().
1659 StartAudioDecoderJobAndSeekToWhileDecoding( 1850 StartAudioDecoderJobAndSeekToWhileDecoding(
1660 base::TimeDelta::FromMilliseconds(100)); 1851 base::TimeDelta::FromMilliseconds(100));
1661 while (GetMediaDecoderJob(true)->is_decoding()) 1852 WaitForAudioDecodeDone();
1662 message_loop_.RunUntilIdle();
1663 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1853 EXPECT_EQ(1, demuxer_->num_seek_requests());
1664 1854
1665 ReleasePlayer(); 1855 ReleasePlayer();
1666 player_.OnDemuxerSeekDone(kNoTimestamp()); 1856 player_.OnDemuxerSeekDone(kNoTimestamp());
1667 EXPECT_FALSE(player_.IsPlaying()); 1857 EXPECT_FALSE(player_.IsPlaying());
1668 EXPECT_FALSE(GetMediaDecoderJob(true)); 1858 EXPECT_FALSE(GetMediaDecoderJob(true));
1669 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1859 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1670 1860
1671 // Player should begin prefetch and resume preroll upon Start(). 1861 // Player should begin prefetch and resume preroll upon Start().
1672 EXPECT_EQ(1, demuxer_->num_data_requests()); 1862 EXPECT_EQ(1, demuxer_->num_data_requests());
1673 StartAudioDecoderJob(); 1863 StartAudioDecoderJob(true);
1674 EXPECT_TRUE(GetMediaDecoderJob(true));
1675 EXPECT_TRUE(IsPrerolling(true)); 1864 EXPECT_TRUE(IsPrerolling(true));
1676 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1865 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1677 EXPECT_EQ(2, demuxer_->num_data_requests());
1678 1866
1679 // No further seek should have been requested since before Release(), above. 1867 // No further seek should have been requested since before Release(), above.
1680 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1868 EXPECT_EQ(1, demuxer_->num_seek_requests());
1681 } 1869 }
1682 1870
1683 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { 1871 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) {
1684 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1872 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1685 1873
1686 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC 1874 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC
1687 // request OnDemuxerSeekDone() does not occur until after the next Start(), 1875 // request and OnDemuxerSeekDone() does not occur until after the next
1688 // then the player remains pending seek done until (and resumes correct 1876 // Start(), then the player remains pending seek done until (and resumes
1689 // post-seek preroll after) OnDemuxerSeekDone(). 1877 // correct post-seek preroll after) OnDemuxerSeekDone().
1690 StartAudioDecoderJobAndSeekToWhileDecoding( 1878 StartAudioDecoderJobAndSeekToWhileDecoding(
1691 base::TimeDelta::FromMilliseconds(100)); 1879 base::TimeDelta::FromMilliseconds(100));
1692 while (GetMediaDecoderJob(true)->is_decoding()) 1880 WaitForAudioDecodeDone();
1693 message_loop_.RunUntilIdle();
1694 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1881 EXPECT_EQ(1, demuxer_->num_seek_requests());
1695 1882
1696 ReleasePlayer(); 1883 ReleasePlayer();
1697 StartAudioDecoderJob();
1698 EXPECT_FALSE(GetMediaDecoderJob(true));
1699 EXPECT_EQ(1, demuxer_->num_data_requests()); 1884 EXPECT_EQ(1, demuxer_->num_data_requests());
1885 StartAudioDecoderJob(false);
1700 1886
1701 player_.OnDemuxerSeekDone(kNoTimestamp()); 1887 player_.OnDemuxerSeekDone(kNoTimestamp());
1702 EXPECT_TRUE(GetMediaDecoderJob(true)); 1888 EXPECT_TRUE(GetMediaDecoderJob(true));
1703 EXPECT_TRUE(IsPrerolling(true)); 1889 EXPECT_TRUE(IsPrerolling(true));
1704 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1890 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1705 EXPECT_EQ(2, demuxer_->num_data_requests()); 1891 EXPECT_EQ(2, demuxer_->num_data_requests());
1706 1892
1707 // No further seek should have been requested since before Release(), above. 1893 // No further seek should have been requested since before Release(), above.
1708 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1894 EXPECT_EQ(1, demuxer_->num_seek_requests());
1709 } 1895 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 1952 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
1767 ReleasePlayer(); 1953 ReleasePlayer();
1768 1954
1769 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 1955 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
1770 EXPECT_FALSE(player_.IsPlaying()); 1956 EXPECT_FALSE(player_.IsPlaying());
1771 EXPECT_FALSE(GetMediaDecoderJob(false)); 1957 EXPECT_FALSE(GetMediaDecoderJob(false));
1772 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 1958 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1773 1959
1774 // Player should begin prefetch and resume preroll upon Start(). 1960 // Player should begin prefetch and resume preroll upon Start().
1775 EXPECT_EQ(1, demuxer_->num_data_requests()); 1961 EXPECT_EQ(1, demuxer_->num_data_requests());
1776 StartVideoDecoderJob();
1777 CreateNextTextureAndSetVideoSurface(); 1962 CreateNextTextureAndSetVideoSurface();
1778 EXPECT_TRUE(GetMediaDecoderJob(false)); 1963 StartVideoDecoderJob(true);
1779 EXPECT_TRUE(IsPrerolling(false)); 1964 EXPECT_TRUE(IsPrerolling(false));
1780 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 1965 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1781 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 1966 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
1782 EXPECT_EQ(2, demuxer_->num_data_requests());
1783 1967
1784 // No further seek should have been requested since BrowserSeekPlayer(). 1968 // No further seek should have been requested since BrowserSeekPlayer().
1785 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1969 EXPECT_EQ(1, demuxer_->num_seek_requests());
1786 } 1970 }
1787 1971
1788 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenStart) { 1972 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenStart) {
1789 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1973 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1790 1974
1791 // Test that Release() after a browser seek's DemuxerSeek IPC request has been 1975 // Test that Release() after a browser seek's DemuxerSeek IPC request has been
1792 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() does not 1976 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() does not
1793 // occur until after the next Start()+SetVideoSurface(), then the player 1977 // occur until after the next Start()+SetVideoSurface(), then the player
1794 // remains pending seek done until (and resumes correct post-seek preroll 1978 // remains pending seek done until (and resumes correct post-seek preroll
1795 // after) OnDemuxerSeekDone(). 1979 // after) OnDemuxerSeekDone().
1796 BrowserSeekPlayer(false); 1980 BrowserSeekPlayer(false);
1797 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 1981 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
1798 ReleasePlayer(); 1982 ReleasePlayer();
1799 1983
1800 StartVideoDecoderJob(); 1984 EXPECT_EQ(1, demuxer_->num_data_requests());
1801 CreateNextTextureAndSetVideoSurface(); 1985 CreateNextTextureAndSetVideoSurface();
1802 EXPECT_FALSE(GetMediaDecoderJob(false)); 1986 StartVideoDecoderJob(false);
1803 EXPECT_EQ(1, demuxer_->num_data_requests());
1804 1987
1805 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 1988 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
1806 EXPECT_TRUE(GetMediaDecoderJob(false)); 1989 EXPECT_TRUE(GetMediaDecoderJob(false));
1807 EXPECT_TRUE(IsPrerolling(false)); 1990 EXPECT_TRUE(IsPrerolling(false));
1808 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 1991 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1809 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 1992 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
1810 EXPECT_EQ(2, demuxer_->num_data_requests()); 1993 EXPECT_EQ(2, demuxer_->num_data_requests());
1811 1994
1812 // No further seek should have been requested since BrowserSeekPlayer(). 1995 // No further seek should have been requested since BrowserSeekPlayer().
1813 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1996 EXPECT_EQ(1, demuxer_->num_seek_requests());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 2083
1901 std::vector<std::string> codec_avc(1, "avc1"); 2084 std::vector<std::string> codec_avc(1, "avc1");
1902 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L3", kVideoMp4, codec_avc)); 2085 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L3", kVideoMp4, codec_avc));
1903 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L1", kVideoMp4, codec_avc)); 2086 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L1", kVideoMp4, codec_avc));
1904 } 2087 }
1905 2088
1906 // TODO(xhwang): Are these IsTypeSupported tests device specific? 2089 // TODO(xhwang): Are these IsTypeSupported tests device specific?
1907 // TODO(xhwang): Add more IsTypeSupported tests. 2090 // TODO(xhwang): Add more IsTypeSupported tests.
1908 2091
1909 } // namespace media 2092 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_source_player.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698