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

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: Address qinmin's nits from PS7 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. |eos_{audio,video}| is ignored if the
623 // corresponding |have_{audio,video}| is false.
624 void VerifySeekDuringEOSDecodePreventsPlaybackCompletion(bool have_audio,
625 bool have_video,
626 bool eos_audio,
627 bool eos_video) {
628 DCHECK(have_audio || have_video);
629
630 if (have_video)
631 CreateNextTextureAndSetVideoSurface();
632
633 Start(CreateDemuxerConfigs(have_audio, have_video), true);
634
635 if (have_audio)
636 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
637
638 if (have_video)
639 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
640
641 // Run until more data is requested a number of times equal to the number of
642 // media types configured. Since prefetching may be in progress, we cannot
643 // reliably expect Run() to complete until we have sent demuxer data for all
644 // configured media types, above.
645 for (int i = 0; i < (have_audio ? 1 : 0) + (have_video ? 1 : 0); i++)
646 message_loop_.Run();
647
648 // Simulate seek while decoding EOS or non-EOS for the appropriate
649 // stream(s).
650 if (have_audio) {
651 if (eos_audio)
652 player_.OnDemuxerDataAvailable(CreateEOSAck(true));
653 else
654 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(1));
655 }
656
657 if (have_video) {
658 if (eos_video)
659 player_.OnDemuxerDataAvailable(CreateEOSAck(false));
660 else
661 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
662 }
663
664 player_.SeekTo(base::TimeDelta());
665 EXPECT_EQ(0, demuxer_->num_seek_requests());
666 WaitForDecodeDone(have_audio, have_video);
667 EXPECT_EQ(1, demuxer_->num_seek_requests());
668
669 player_.OnDemuxerSeekDone(kNoTimestamp());
670 EXPECT_FALSE(manager_.playback_completed());
671 }
672
554 base::TimeTicks StartTimeTicks() { 673 base::TimeTicks StartTimeTicks() {
555 return player_.start_time_ticks_; 674 return player_.start_time_ticks_;
556 } 675 }
557 676
558 bool IsTypeSupported(const std::vector<uint8>& scheme_uuid, 677 bool IsTypeSupported(const std::vector<uint8>& scheme_uuid,
559 const std::string& security_level, 678 const std::string& security_level,
560 const std::string& container, 679 const std::string& container,
561 const std::vector<std::string>& codecs) { 680 const std::vector<std::string>& codecs) {
562 return MediaSourcePlayer::IsTypeSupported( 681 return MediaSourcePlayer::IsTypeSupported(
563 scheme_uuid, security_level, container, codecs); 682 scheme_uuid, security_level, container, codecs);
(...skipping 19 matching lines...) Expand all
583 bool surface_texture_a_is_next_; 702 bool surface_texture_a_is_next_;
584 int next_texture_id_; 703 int next_texture_id_;
585 704
586 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest); 705 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest);
587 }; 706 };
588 707
589 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) { 708 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) {
590 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 709 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
591 710
592 // Test audio decoder job will be created when codec is successfully started. 711 // Test audio decoder job will be created when codec is successfully started.
593 StartAudioDecoderJob(); 712 StartAudioDecoderJob(true);
594 EXPECT_TRUE(GetMediaDecoderJob(true));
595 EXPECT_EQ(1, demuxer_->num_data_requests());
596 EXPECT_EQ(0, demuxer_->num_seek_requests()); 713 EXPECT_EQ(0, demuxer_->num_seek_requests());
597 } 714 }
598 715
599 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { 716 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) {
600 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 717 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
601 718
602 // Test audio decoder job will not be created when failed to start the codec. 719 // Test audio decoder job will not be created when failed to start the codec.
603 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 720 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis);
604 // Replace with invalid |audio_extra_data| 721 // Replace with invalid |audio_extra_data|
605 configs.audio_extra_data.clear(); 722 configs.audio_extra_data.clear();
606 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; 723 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff };
607 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), 724 configs.audio_extra_data.insert(configs.audio_extra_data.begin(),
608 invalid_codec_data, invalid_codec_data + 4); 725 invalid_codec_data, invalid_codec_data + 4);
609 Start(configs); 726 Start(configs, false);
610 EXPECT_FALSE(GetMediaDecoderJob(true));
611 EXPECT_EQ(0, demuxer_->num_data_requests());
612 EXPECT_EQ(0, demuxer_->num_seek_requests()); 727 EXPECT_EQ(0, demuxer_->num_seek_requests());
613 } 728 }
614 729
615 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { 730 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) {
616 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 731 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
617 732
618 // Test video decoder job will be created when surface is valid. 733 // 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. 734 // Video decoder job will not be created until surface is available.
621 EXPECT_FALSE(GetMediaDecoderJob(false)); 735 StartVideoDecoderJob(false);
622 EXPECT_EQ(0, demuxer_->num_data_requests());
623 736
624 // Set both an initial and a later video surface without receiving any 737 // Set both an initial and a later video surface without receiving any
625 // demuxed data yet. 738 // demuxed data yet.
626 CreateNextTextureAndSetVideoSurface(); 739 CreateNextTextureAndSetVideoSurface();
627 MediaDecoderJob* first_job = GetMediaDecoderJob(false); 740 MediaDecoderJob* first_job = GetMediaDecoderJob(false);
628 EXPECT_TRUE(first_job); 741 EXPECT_TRUE(first_job);
629 CreateNextTextureAndSetVideoSurface(); 742 CreateNextTextureAndSetVideoSurface();
630 743
631 // Setting another surface will not create a new job until any pending 744 // Setting another surface will not create a new job until any pending
632 // read is satisfied (and job is no longer decoding). 745 // read is satisfied (and job is no longer decoding).
633 EXPECT_EQ(first_job, GetMediaDecoderJob(false)); 746 EXPECT_EQ(first_job, GetMediaDecoderJob(false));
634 747
635 // No seeks, even on setting surface, should have occurred. (Browser seeks can 748 // No seeks, even on setting surface, should have occurred. (Browser seeks can
636 // occur on setting surface, but only after previously receiving video data.) 749 // occur on setting surface, but only after previously receiving video data.)
637 EXPECT_EQ(0, demuxer_->num_seek_requests()); 750 EXPECT_EQ(0, demuxer_->num_seek_requests());
638 751
639 // Note, the decoder job for the second surface set, above, will be created 752 // 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 753 // only after the pending read is satisfied and decoded, and the resulting
641 // browser seek is done. See BrowserSeek_* tests for this coverage. 754 // browser seek is done. See BrowserSeek_* tests for this coverage.
642 } 755 }
643 756
644 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { 757 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) {
645 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 758 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
646 759
647 // Test video decoder job will be created when surface is valid. 760 // Test video decoder job will not be created when surface is invalid.
648 scoped_refptr<gfx::SurfaceTexture> surface_texture( 761 scoped_refptr<gfx::SurfaceTexture> surface_texture(
649 new gfx::SurfaceTexture(0)); 762 new gfx::SurfaceTexture(0));
650 gfx::ScopedJavaSurface surface(surface_texture.get()); 763 gfx::ScopedJavaSurface surface(surface_texture.get());
651 StartVideoDecoderJob(); 764 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 765
656 // Release the surface texture. 766 // Release the surface texture.
657 surface_texture = NULL; 767 surface_texture = NULL;
658 player_.SetVideoSurface(surface.Pass()); 768 player_.SetVideoSurface(surface.Pass());
659 769
660 // Player should not seek the demuxer on setting initial surface. 770 // Player should not seek the demuxer on setting initial surface.
661 EXPECT_EQ(0, demuxer_->num_seek_requests()); 771 EXPECT_EQ(0, demuxer_->num_seek_requests());
662 772
663 EXPECT_FALSE(GetMediaDecoderJob(false)); 773 EXPECT_FALSE(GetMediaDecoderJob(false));
664 EXPECT_EQ(0, demuxer_->num_data_requests()); 774 EXPECT_EQ(0, demuxer_->num_data_requests());
665 } 775 }
666 776
667 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) { 777 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) {
668 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 778 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
669 779
670 // Test decoder job will resend a ReadFromDemuxer request after seek. 780 // Test decoder job will resend a ReadFromDemuxer request after seek.
671 StartAudioDecoderJob(); 781 StartAudioDecoderJob(true);
672 EXPECT_TRUE(GetMediaDecoderJob(true)); 782 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 } 783 }
677 784
678 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { 785 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) {
679 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 786 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
680 787
681 // Test SetVideoSurface() will not cause an extra seek while the player is 788 // Test SetVideoSurface() will not cause an extra seek while the player is
682 // waiting for demuxer to indicate seek is done. 789 // waiting for demuxer to indicate seek is done.
683 StartVideoDecoderJob();
684 // Player is still waiting for SetVideoSurface(), so no request is sent. 790 // Player is still waiting for SetVideoSurface(), so no request is sent.
685 EXPECT_EQ(0, demuxer_->num_data_requests()); 791 StartVideoDecoderJob(false); // Verifies no data requested.
686 792
687 // Initiate a seek. Skip requesting element seek of renderer. 793 // Initiate a seek. Skip requesting element seek of renderer.
688 // Instead behave as if the renderer has asked us to seek. 794 // Instead behave as if the renderer has asked us to seek.
689 EXPECT_EQ(0, demuxer_->num_seek_requests()); 795 EXPECT_EQ(0, demuxer_->num_seek_requests());
690 player_.SeekTo(base::TimeDelta()); 796 player_.SeekTo(base::TimeDelta());
691 EXPECT_EQ(1, demuxer_->num_seek_requests()); 797 EXPECT_EQ(1, demuxer_->num_seek_requests());
692 798
693 CreateNextTextureAndSetVideoSurface(); 799 CreateNextTextureAndSetVideoSurface();
694 EXPECT_FALSE(GetMediaDecoderJob(false)); 800 EXPECT_FALSE(GetMediaDecoderJob(false));
695 EXPECT_EQ(1, demuxer_->num_seek_requests()); 801 EXPECT_EQ(1, demuxer_->num_seek_requests());
(...skipping 10 matching lines...) Expand all
706 // was not a browser seek request. 812 // was not a browser seek request.
707 EXPECT_EQ(1, demuxer_->num_seek_requests()); 813 EXPECT_EQ(1, demuxer_->num_seek_requests());
708 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 814 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
709 } 815 }
710 816
711 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) { 817 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) {
712 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 818 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
713 819
714 // Test MediaSourcePlayer can switch multiple surfaces during decoding. 820 // Test MediaSourcePlayer can switch multiple surfaces during decoding.
715 CreateNextTextureAndSetVideoSurface(); 821 CreateNextTextureAndSetVideoSurface();
716 StartVideoDecoderJob(); 822 StartVideoDecoderJob(true);
717 EXPECT_EQ(1, demuxer_->num_data_requests());
718 EXPECT_EQ(0, demuxer_->num_seek_requests()); 823 EXPECT_EQ(0, demuxer_->num_seek_requests());
719 EXPECT_TRUE(GetMediaDecoderJob(false));
720 824
721 // Send the first input chunk. 825 // Send the first input chunk.
722 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 826 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
723 827
724 // While the decoder is decoding, change multiple surfaces. Pass an empty 828 // While the decoder is decoding, change multiple surfaces. Pass an empty
725 // surface first. 829 // surface first.
726 gfx::ScopedJavaSurface empty_surface; 830 gfx::ScopedJavaSurface empty_surface;
727 player_.SetVideoSurface(empty_surface.Pass()); 831 player_.SetVideoSurface(empty_surface.Pass());
728 // Next, pass a new non-empty surface. 832 // Next, pass a new non-empty surface.
729 CreateNextTextureAndSetVideoSurface(); 833 CreateNextTextureAndSetVideoSurface();
730 834
731 // Wait for the decoder job to finish decoding and be reset pending a browser 835 // Wait for the decoder job to finish decoding and be reset pending a browser
732 // seek. 836 // seek.
733 while (GetMediaDecoderJob(false) && GetMediaDecoderJob(false)->is_decoding()) 837 while (GetMediaDecoderJob(false))
734 message_loop_.RunUntilIdle(); 838 message_loop_.RunUntilIdle();
735 EXPECT_FALSE(GetMediaDecoderJob(false));
736 839
737 // Only one browser seek should have been initiated. No further data request 840 // Only one browser seek should have been initiated. No further data request
738 // should have been processed on |message_loop_| before surface change event 841 // should have been processed on |message_loop_| before surface change event
739 // became pending, above. 842 // became pending, above.
740 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 843 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
741 EXPECT_EQ(1, demuxer_->num_data_requests()); 844 EXPECT_EQ(1, demuxer_->num_data_requests());
742 845
743 // Simulate browser seek is done and confirm player requests more data for new 846 // Simulate browser seek is done and confirm player requests more data for new
744 // video decoder job. 847 // video decoder job.
745 player_.OnDemuxerSeekDone(player_.GetCurrentTime()); 848 player_.OnDemuxerSeekDone(player_.GetCurrentTime());
746 EXPECT_TRUE(GetMediaDecoderJob(false)); 849 EXPECT_TRUE(GetMediaDecoderJob(false));
747 EXPECT_EQ(2, demuxer_->num_data_requests()); 850 EXPECT_EQ(2, demuxer_->num_data_requests());
748 EXPECT_EQ(1, demuxer_->num_seek_requests()); 851 EXPECT_EQ(1, demuxer_->num_seek_requests());
749 } 852 }
750 853
751 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) { 854 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) {
752 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 855 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
753 856
754 // Test audio decoder job will not start until pending seek event is handled. 857 // Test audio decoder job will not start until pending seek event is handled.
755 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 858 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis);
756 player_.OnDemuxerConfigsAvailable(configs); 859 player_.OnDemuxerConfigsAvailable(configs);
757 EXPECT_FALSE(GetMediaDecoderJob(true)); 860 EXPECT_FALSE(GetMediaDecoderJob(true));
758 EXPECT_EQ(0, demuxer_->num_data_requests());
759 861
760 // Initiate a seek. Skip requesting element seek of renderer. 862 // Initiate a seek. Skip requesting element seek of renderer.
761 // Instead behave as if the renderer has asked us to seek. 863 // Instead behave as if the renderer has asked us to seek.
762 player_.SeekTo(base::TimeDelta()); 864 player_.SeekTo(base::TimeDelta());
763 EXPECT_EQ(1, demuxer_->num_seek_requests()); 865 EXPECT_EQ(1, demuxer_->num_seek_requests());
764 866
765 player_.Start(); 867 player_.Start();
766 EXPECT_FALSE(GetMediaDecoderJob(true)); 868 EXPECT_FALSE(GetMediaDecoderJob(true));
767 EXPECT_EQ(0, demuxer_->num_data_requests()); 869 EXPECT_EQ(0, demuxer_->num_data_requests());
768 870
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 902
801 // Reconfirm exactly 1 seek request has been made of demuxer. 903 // Reconfirm exactly 1 seek request has been made of demuxer.
802 EXPECT_EQ(1, demuxer_->num_seek_requests()); 904 EXPECT_EQ(1, demuxer_->num_seek_requests());
803 } 905 }
804 906
805 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) { 907 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) {
806 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 908 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
807 909
808 // Test that if the decoding job is not fully stopped after Pause(), 910 // Test that if the decoding job is not fully stopped after Pause(),
809 // calling Start() will be a noop. 911 // calling Start() will be a noop.
810 StartAudioDecoderJob(); 912 StartAudioDecoderJob(true);
811 913
812 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 914 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()); 915 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
816 916
817 // Sending data to player. 917 // Sending data to player.
818 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 918 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
819 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 919 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
820 920
821 // Decoder job will not immediately stop after Pause() since it is 921 // Decoder job will not immediately stop after Pause() since it is
822 // running on another thread. 922 // running on another thread.
823 player_.Pause(true); 923 player_.Pause(true);
824 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 924 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
825 925
826 // Nothing happens when calling Start() again. 926 // Nothing happens when calling Start() again.
827 player_.Start(); 927 player_.Start();
828 // Verify that Start() will not destroy and recreate the decoder job. 928 // Verify that Start() will not destroy and recreate the decoder job.
829 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 929 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
830 EXPECT_EQ(1, demuxer_->num_data_requests()); 930 EXPECT_EQ(1, demuxer_->num_data_requests());
831 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 931 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
832 message_loop_.Run(); 932 message_loop_.Run();
833 // The decoder job should finish and a new request will be sent. 933 // The decoder job should finish and a new request will be sent.
834 EXPECT_EQ(2, demuxer_->num_data_requests()); 934 EXPECT_EQ(2, demuxer_->num_data_requests());
835 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 935 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
836 } 936 }
837 937
838 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { 938 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) {
839 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 939 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
840 940
841 // Test that when Start() is called, video decoder jobs will wait for audio 941 // Test that when Start() is called, video decoder jobs will wait for audio
842 // decoder job before start decoding the data. 942 // 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(); 943 CreateNextTextureAndSetVideoSurface();
848 944 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); 945 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true);
853 MediaDecoderJob* video_decoder_job = GetMediaDecoderJob(false); 946 MediaDecoderJob* video_decoder_job = GetMediaDecoderJob(false);
854 EXPECT_EQ(2, demuxer_->num_data_requests()); 947
855 EXPECT_FALSE(audio_decoder_job->is_decoding()); 948 EXPECT_FALSE(audio_decoder_job->is_decoding());
856 EXPECT_FALSE(video_decoder_job->is_decoding()); 949 EXPECT_FALSE(video_decoder_job->is_decoding());
857 950
858 // Sending video data to player, audio decoder should not start. 951 // Sending video data to player, video decoder should not start.
859 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 952 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
860 EXPECT_FALSE(video_decoder_job->is_decoding()); 953 EXPECT_FALSE(video_decoder_job->is_decoding());
861 954
862 // Sending audio data to player, both decoders should start now. 955 // Sending audio data to player, both decoders should start now.
863 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 956 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
864 EXPECT_TRUE(audio_decoder_job->is_decoding()); 957 EXPECT_TRUE(audio_decoder_job->is_decoding());
865 EXPECT_TRUE(video_decoder_job->is_decoding()); 958 EXPECT_TRUE(video_decoder_job->is_decoding());
866 959
867 // Reconfirm no seek occurred. 960 // No seeks should have occurred.
868 EXPECT_EQ(0, demuxer_->num_seek_requests()); 961 EXPECT_EQ(0, demuxer_->num_seek_requests());
869 } 962 }
870 963
871 TEST_F(MediaSourcePlayerTest, StartTimeTicksResetAfterDecoderUnderruns) { 964 TEST_F(MediaSourcePlayerTest, StartTimeTicksResetAfterDecoderUnderruns) {
872 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 965 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
873 966
874 // Test start time ticks will reset after decoder job underruns. 967 // Test start time ticks will reset after decoder job underruns.
875 StartAudioDecoderJob(); 968 StartAudioDecoderJob(true);
876 EXPECT_TRUE(GetMediaDecoderJob(true)); 969
877 EXPECT_EQ(1, demuxer_->num_data_requests());
878 // For the first couple chunks, the decoder job may return 970 // For the first couple chunks, the decoder job may return
879 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode 971 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode
880 // more frames to guarantee that DECODE_SUCCEEDED will be returned. 972 // more frames to guarantee that DECODE_SUCCEEDED will be returned.
881 for (int i = 0; i < 4; ++i) { 973 for (int i = 0; i < 4; ++i) {
882 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); 974 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i));
883 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 975 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
884 message_loop_.Run(); 976 message_loop_.Run();
885 } 977 }
886 978
887 // The decoder job should finish and a new request will be sent. 979 // The decoder job should finish and a new request will be sent.
888 EXPECT_EQ(5, demuxer_->num_data_requests()); 980 EXPECT_EQ(5, demuxer_->num_data_requests());
889 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 981 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
890 base::TimeTicks previous = StartTimeTicks(); 982 base::TimeTicks previous = StartTimeTicks();
891 983
892 // Let the decoder timeout and execute the OnDecoderStarved() callback. 984 // Let the decoder timeout and execute the OnDecoderStarved() callback.
893 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 985 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
894 986
895 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 987 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
896 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); 988 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks());
897 message_loop_.RunUntilIdle(); 989 message_loop_.RunUntilIdle();
898 990
899 // Send new data to the decoder so it can finish the currently 991 // Send new data to the decoder so it can finish the currently
900 // pending decode. 992 // pending decode.
901 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 993 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
902 while (GetMediaDecoderJob(true)->is_decoding()) 994 WaitForAudioDecodeDone();
903 message_loop_.RunUntilIdle();
904 995
905 // Verify the start time ticks is cleared at this point because the 996 // Verify the start time ticks is cleared at this point because the
906 // player is prefetching. 997 // player is prefetching.
907 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks()); 998 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks());
908 999
909 // Send new data to the decoder so it can finish prefetching. This should 1000 // Send new data to the decoder so it can finish prefetching. This should
910 // reset the start time ticks. 1001 // reset the start time ticks.
911 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1002 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
912 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); 1003 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks());
913 1004
914 base::TimeTicks current = StartTimeTicks(); 1005 base::TimeTicks current = StartTimeTicks();
915 EXPECT_LE(100.0, (current - previous).InMillisecondsF()); 1006 EXPECT_LE(100.0, (current - previous).InMillisecondsF());
916 } 1007 }
917 1008
918 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterInputEOS) { 1009 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) {
919 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1010 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
920 1011
921 // Test MediaSourcePlayer will not request for new data after input EOS is 1012 // Test MediaSourcePlayer can replay video after input EOS is reached.
922 // reached. 1013 CreateNextTextureAndSetVideoSurface();
923 CreateNextTextureAndSetVideoSurface(); 1014 StartVideoDecoderJob(true);
924 StartVideoDecoderJob(); 1015
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. 1016 // Send the first input chunk.
930 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1017 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
931 message_loop_.Run(); 1018 message_loop_.Run();
1019
1020 VerifyPlaybackCompletesOnEOSDecode(true, false);
1021 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true);
1022 }
1023
1024 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) {
1025 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1026
1027 // Test decode of audio EOS buffer without any prior decode. See also
1028 // http://b/11696552.
1029 // Also tests that seeking+Start() after completing audio playback resumes
1030 // playback.
1031 Start(CreateAudioDemuxerConfigs(kCodecAAC), true);
1032 VerifyPlaybackCompletesOnEOSDecode(true, true);
1033 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, false);
1034 }
1035
1036 TEST_F(MediaSourcePlayerTest, V_FirstAccessUnitAfterSeekIsEOS) {
1037 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1038
1039 // Test decode of video EOS buffer, just after seeking, without any prior
1040 // decode (other than the simulated |kAborted| resulting from the seek
1041 // process.)
1042 CreateNextTextureAndSetVideoSurface();
1043 StartVideoDecoderJob(true);
1044 SeekPlayerWithAbort(false, base::TimeDelta());
1045 VerifyPlaybackCompletesOnEOSDecode(true, false);
1046 }
1047
1048 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitAfterSeekIsEOS) {
1049 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1050
1051 // Test decode of audio EOS buffer, just after seeking, without any prior
1052 // decode (other than the simulated |kAborted| resulting from the seek
1053 // process.) See also http://b/11696552.
1054 Start(CreateAudioDemuxerConfigs(kCodecAAC), true);
1055 SeekPlayerWithAbort(true, base::TimeDelta());
1056 VerifyPlaybackCompletesOnEOSDecode(true, true);
1057 }
1058
1059 TEST_F(MediaSourcePlayerTest, AV_PlaybackCompletionAcrossConfigChange) {
1060 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1061
1062 // Test that if one stream (audio) has completed decode of EOS and the other
1063 // stream (video) processes config change, that subsequent video EOS completes
1064 // A/V playback.
1065 // Also tests that seeking+Start() after completing playback resumes playback.
1066 CreateNextTextureAndSetVideoSurface();
1067 Start(CreateAudioVideoDemuxerConfigs(), true);
1068
1069 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1070 EXPECT_EQ(0, demuxer_->num_config_requests());
1071 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1072 false, 0)); // Video |kConfigChanged| as first unit.
1073
1074 WaitForAudioVideoDecodeDone();
1075
1076 EXPECT_EQ(1, demuxer_->num_config_requests());
932 EXPECT_EQ(2, demuxer_->num_data_requests()); 1077 EXPECT_EQ(2, demuxer_->num_data_requests());
933 1078 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs());
934 // Send EOS. 1079 EXPECT_EQ(3, demuxer_->num_data_requests());
935 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); 1080
936 message_loop_.Run(); 1081 // At no time after completing audio EOS decode, above, should the
937 // No more request for data should be made. 1082 // audio decoder job resume decoding. Send and decode video EOS.
1083 VerifyPlaybackCompletesOnEOSDecode(true, false);
1084 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
1085 }
1086
1087 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) {
1088 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1089
1090 // Test that if one stream (video) has completed decode of EOS and the other
1091 // stream (audio) processes config change, that subsequent audio EOS completes
1092 // A/V playback.
1093 // Also tests that seeking+Start() after completing playback resumes playback.
1094 CreateNextTextureAndSetVideoSurface();
1095 Start(CreateAudioVideoDemuxerConfigs(), true);
1096
1097 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1098 EXPECT_EQ(0, demuxer_->num_config_requests());
1099 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1100 true, 0)); // Audio |kConfigChanged| as first unit.
1101
1102 WaitForAudioVideoDecodeDone();
1103
1104 // TODO(wolenetz/qinmin): Prevent redundant demuxer config request and change
1105 // expectation to 1 here. See http://crbug.com/325528.
1106 EXPECT_EQ(2, demuxer_->num_config_requests());
938 EXPECT_EQ(2, demuxer_->num_data_requests()); 1107 EXPECT_EQ(2, demuxer_->num_data_requests());
939 1108 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs());
940 // Reconfirm no seek request has occurred. 1109 EXPECT_EQ(3, demuxer_->num_data_requests());
941 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1110
942 } 1111 // At no time after completing video EOS decode, above, should the
943 1112 // video decoder job resume decoding. Send and decode audio EOS.
944 TEST_F(MediaSourcePlayerTest, ReplayAfterInputEOS) { 1113 VerifyPlaybackCompletesOnEOSDecode(true, true);
945 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1114 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
946 1115 }
947 // Test MediaSourcePlayer can replay after input EOS is 1116
948 // reached. 1117 TEST_F(MediaSourcePlayerTest, AV_NoPrefetchForFinishedVideoOnAudioStarvation) {
949 CreateNextTextureAndSetVideoSurface(); 1118 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
950 StartVideoDecoderJob(); 1119
951 1120 // Test that if one stream (video) has completed decode of EOS, prefetch
952 // Player should not seek the demuxer on setting initial surface. 1121 // resulting from player starvation occurs only for the other stream (audio),
953 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1122 // and responding to that prefetch with EOS completes A/V playback, even if
954 1123 // another starvation occurs during the latter EOS's decode.
955 EXPECT_EQ(1, demuxer_->num_data_requests()); 1124 CreateNextTextureAndSetVideoSurface();
956 // Send the first input chunk. 1125 Start(CreateAudioVideoDemuxerConfigs(), true);
1126
1127 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1128 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1129
1130 // Wait until video EOS is processed and more data (assumed to be audio) is
1131 // requested.
1132 while (demuxer_->num_data_requests() < 3)
1133 message_loop_.RunUntilIdle();
1134 WaitForVideoDecodeDone();
1135 EXPECT_EQ(3, demuxer_->num_data_requests());
1136
1137 // Simulate decoder underrun to trigger prefetch while still decoding audio.
1138 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(1));
1139 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding() &&
1140 !GetMediaDecoderJob(false)->is_decoding());
1141 TriggerPlayerStarvation();
1142
1143 // Complete the audio decode that was in progress when simulated player
1144 // starvation was triggered.
1145 WaitForAudioDecodeDone();
1146 EXPECT_EQ(4, demuxer_->num_data_requests());
1147
1148 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1149 EXPECT_FALSE(GetMediaDecoderJob(false)->is_decoding());
1150 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1151
1152 // Simulate another decoder underrun to trigger prefetch while decoding EOS.
1153 TriggerPlayerStarvation();
1154 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */);
1155 }
1156
1157 TEST_F(MediaSourcePlayerTest, V_StarvationDuringEOSDecode) {
1158 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1159
1160 // Test that video-only playback completes without further data requested when
1161 // starvation occurs during EOS decode.
1162 CreateNextTextureAndSetVideoSurface();
1163 StartVideoDecoderJob(true);
957 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1164 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
958 message_loop_.Run(); 1165 message_loop_.Run();
959 EXPECT_EQ(2, demuxer_->num_data_requests()); 1166
960 1167 // Simulate decoder underrun to trigger prefetch while decoding EOS.
961 // Send EOS. 1168 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
962 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); 1169 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding());
1170 TriggerPlayerStarvation();
1171 VerifyPlaybackCompletesOnEOSDecode(false, false /* ignored */);
1172 }
1173
1174 TEST_F(MediaSourcePlayerTest, A_StarvationDuringEOSDecode) {
1175 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1176
1177 // Test that audio-only playback completes without further data requested when
1178 // starvation occurs during EOS decode.
1179 StartAudioDecoderJob(true);
1180 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
963 message_loop_.Run(); 1181 message_loop_.Run();
964 // No more request for data should be made. 1182
965 EXPECT_EQ(2, demuxer_->num_data_requests()); 1183 // Simulate decoder underrun to trigger prefetch while decoding EOS.
966 1184 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
967 // Initiate a seek. Skip requesting element seek of renderer. 1185 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
968 // Instead behave as if the renderer has asked us to seek. 1186 TriggerPlayerStarvation();
969 player_.SeekTo(base::TimeDelta()); 1187 VerifyPlaybackCompletesOnEOSDecode(false, true /* ignored */);
970 StartVideoDecoderJob(); 1188 }
971 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1189
972 player_.OnDemuxerSeekDone(kNoTimestamp()); 1190 TEST_F(MediaSourcePlayerTest, AV_SeekDuringEOSDecodePreventsCompletion) {
973 // Seek/Play after EOS should request more data. 1191 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
974 EXPECT_EQ(3, demuxer_->num_data_requests()); 1192
975 1193 // Test that seek supercedes audio+video playback completion on simultaneous
976 // Reconfirm only 1 seek request has occurred. 1194 // audio and video EOS decode, if SeekTo() occurs during these EOS decodes.
977 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1195 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(true, true, true, true);
978 } 1196 }
979 1197
980 TEST_F(MediaSourcePlayerTest, FirstDataIsEOS) { 1198 TEST_F(MediaSourcePlayerTest, AV_SeekDuringAudioEOSDecodePreventsCompletion) {
981 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1199 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
982 1200
983 // Test decode of EOS buffer without any prior decode. See also 1201 // Test that seek supercedes audio+video playback completion on simultaneous
984 // http://b/11696552. 1202 // audio EOS and video non-EOS decode, if SeekTo() occurs during these
985 Start(CreateAudioDemuxerConfigs(kCodecAAC)); 1203 // decodes.
986 EXPECT_TRUE(GetMediaDecoderJob(true)); 1204 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(true, true, true, false);
987 1205 }
988 EXPECT_EQ(1, demuxer_->num_data_requests()); 1206
989 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); 1207 TEST_F(MediaSourcePlayerTest, AV_SeekDuringVideoEOSDecodePreventsCompletion) {
990 EXPECT_FALSE(manager_.playback_completed()); 1208 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
991 1209
992 message_loop_.Run(); 1210 // Test that seek supercedes audio+video playback completion on simultaneous
993 EXPECT_TRUE(manager_.playback_completed()); 1211 // audio non-EOS and video EOS decode, if SeekTo() occurs during these
994 EXPECT_EQ(1, demuxer_->num_data_requests()); 1212 // decodes.
995 } 1213 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(true, true, false, true);
996 1214 }
997 TEST_F(MediaSourcePlayerTest, FirstDataAfterSeekIsEOS) { 1215
998 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1216 TEST_F(MediaSourcePlayerTest, V_SeekDuringEOSDecodePreventsCompletion) {
999 1217 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1000 // Test decode of EOS buffer, just after seeking, without any prior decode 1218
1001 // (other than the simulated |kAborted| resulting from the seek process.) 1219 // Test that seek supercedes video-only playback completion on EOS decode, if
1002 // See also http://b/11696552. 1220 // SeekTo() occurs during EOS decode.
1003 Start(CreateAudioDemuxerConfigs(kCodecAAC)); 1221 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(false, true, false, true);
1004 EXPECT_TRUE(GetMediaDecoderJob(true)); 1222 }
1005 1223
1006 SeekPlayer(true, base::TimeDelta()); 1224 TEST_F(MediaSourcePlayerTest, A_SeekDuringEOSDecodePreventsCompletion) {
1007 EXPECT_EQ(2, demuxer_->num_data_requests()); 1225 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1008 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); 1226
1009 EXPECT_FALSE(manager_.playback_completed()); 1227 // Test that seek supercedes audio-only playback completion on EOS decode, if
1010 1228 // SeekTo() occurs during EOS decode.
1011 message_loop_.Run(); 1229 VerifySeekDuringEOSDecodePreventsPlaybackCompletion(true, false, true, false);
1012 EXPECT_TRUE(manager_.playback_completed());
1013 EXPECT_EQ(2, demuxer_->num_data_requests());
1014 } 1230 }
1015 1231
1016 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterAbort) { 1232 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterAbort) {
1017 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1233 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1018 1234
1019 // Test that the decoder will not request new data after receiving an aborted 1235 // Test that the decoder will not request new data after receiving an aborted
1020 // access unit. 1236 // access unit.
1021 StartAudioDecoderJob(); 1237 StartAudioDecoderJob(true);
1022 EXPECT_EQ(1, demuxer_->num_data_requests());
1023 1238
1024 // Send an aborted access unit. 1239 // Send an aborted access unit.
1025 player_.OnDemuxerDataAvailable(CreateAbortedAck(true)); 1240 player_.OnDemuxerDataAvailable(CreateAbortedAck(true));
1026
1027 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1241 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1028 // Wait for the decoder job to finish decoding. 1242 WaitForAudioDecodeDone();
1029 while (GetMediaDecoderJob(true)->is_decoding())
1030 message_loop_.RunUntilIdle();
1031 1243
1032 // No request will be sent for new data. 1244 // No request will be sent for new data.
1033 EXPECT_EQ(1, demuxer_->num_data_requests()); 1245 EXPECT_EQ(1, demuxer_->num_data_requests());
1034 1246
1035 // No seek requests should have occurred. 1247 // No seek requests should have occurred.
1036 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1248 EXPECT_EQ(0, demuxer_->num_seek_requests());
1037 } 1249 }
1038 1250
1039 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) { 1251 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) {
1040 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1252 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1041 1253
1042 // Test that the decoder should not crash if demuxer data arrives after 1254 // Test that the decoder should not crash if demuxer data arrives after
1043 // Release(). 1255 // Release().
1044 StartAudioDecoderJob(); 1256 StartAudioDecoderJob(true);
1045 EXPECT_EQ(1, demuxer_->num_data_requests());
1046 EXPECT_TRUE(GetMediaDecoderJob(true));
1047 1257
1048 ReleasePlayer(); 1258 ReleasePlayer();
1049 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1259 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1050 1260
1051 // The decoder job should have been released. 1261 // The decoder job should have been released.
1052 EXPECT_FALSE(player_.IsPlaying()); 1262 EXPECT_FALSE(player_.IsPlaying());
1263
1264 // No further data should have been requested.
1053 EXPECT_EQ(1, demuxer_->num_data_requests()); 1265 EXPECT_EQ(1, demuxer_->num_data_requests());
1054 1266
1055 // No seek requests should have occurred. 1267 // No seek requests should have occurred.
1056 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1268 EXPECT_EQ(0, demuxer_->num_seek_requests());
1057 } 1269 }
1058 1270
1059 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) { 1271 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) {
1060 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1272 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1061 1273
1062 // Test that a browser seek, once started, delays a newly arrived regular 1274 // Test that a browser seek, once started, delays a newly arrived regular
1063 // SeekTo() request's demuxer seek until the browser seek is done. 1275 // SeekTo() request's demuxer seek until the browser seek is done.
1064 BrowserSeekPlayer(false); 1276 BrowserSeekPlayer(false);
1065 EXPECT_EQ(1, demuxer_->num_data_requests());
1066 1277
1067 // Simulate renderer requesting a regular seek while browser seek in progress. 1278 // Simulate renderer requesting a regular seek while browser seek in progress.
1068 player_.SeekTo(base::TimeDelta()); 1279 player_.SeekTo(base::TimeDelta());
1069 EXPECT_FALSE(GetMediaDecoderJob(false)); 1280 EXPECT_FALSE(GetMediaDecoderJob(false));
1070 1281
1071 // Simulate browser seek is done. Confirm player requests the regular seek, 1282 // Simulate browser seek is done. Confirm player requests the regular seek,
1072 // still has no video decoder job configured, and has not requested any 1283 // still has no video decoder job configured, and has not requested any
1073 // further data since the surface change event became pending in 1284 // further data since the surface change event became pending in
1074 // BrowserSeekPlayer(). 1285 // BrowserSeekPlayer().
1075 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1286 EXPECT_EQ(1, demuxer_->num_seek_requests());
(...skipping 10 matching lines...) Expand all
1086 EXPECT_EQ(2, demuxer_->num_data_requests()); 1297 EXPECT_EQ(2, demuxer_->num_data_requests());
1087 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1298 EXPECT_EQ(2, demuxer_->num_seek_requests());
1088 } 1299 }
1089 1300
1090 TEST_F(MediaSourcePlayerTest, NoSeekForInitialReleaseAndStart) { 1301 TEST_F(MediaSourcePlayerTest, NoSeekForInitialReleaseAndStart) {
1091 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1302 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1092 1303
1093 // Test that no seek is requested if player Release() + Start() occurs prior 1304 // Test that no seek is requested if player Release() + Start() occurs prior
1094 // to receiving any data. 1305 // to receiving any data.
1095 CreateNextTextureAndSetVideoSurface(); 1306 CreateNextTextureAndSetVideoSurface();
1096 StartVideoDecoderJob(); 1307 StartVideoDecoderJob(true);
1097 EXPECT_EQ(1, demuxer_->num_data_requests());
1098 EXPECT_TRUE(GetMediaDecoderJob(false));
1099
1100 ReleasePlayer(); 1308 ReleasePlayer();
1101 1309
1102 // Pass a new non-empty surface. 1310 // Pass a new non-empty surface.
1103 CreateNextTextureAndSetVideoSurface(); 1311 CreateNextTextureAndSetVideoSurface();
1104 1312
1105 player_.Start(); 1313 player_.Start();
1106 1314
1107 // TODO(wolenetz/qinmin): Multiple in-flight data requests for same stream 1315 // TODO(wolenetz/qinmin): Multiple in-flight data requests for same stream
1108 // should be prevented. See http://crbug.com/306314. 1316 // should be prevented. See http://crbug.com/306314.
1109 EXPECT_EQ(2, demuxer_->num_data_requests()); 1317 EXPECT_EQ(2, demuxer_->num_data_requests());
1318 EXPECT_TRUE(GetMediaDecoderJob(false));
1110 1319
1111 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1320 EXPECT_EQ(0, demuxer_->num_seek_requests());
1112 EXPECT_TRUE(GetMediaDecoderJob(false));
1113 } 1321 }
1114 1322
1115 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) { 1323 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) {
1116 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1324 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1117 1325
1118 // Test that one browser seek is requested if player Release() + Start(), with 1326 // Test that one browser seek is requested if player Release() + Start(), with
1119 // video data received between Release() and Start(). 1327 // video data received between Release() and Start().
1120 BrowserSeekPlayer(true); 1328 BrowserSeekPlayer(true);
1121 EXPECT_EQ(1, demuxer_->num_data_requests()); 1329 EXPECT_EQ(1, demuxer_->num_data_requests());
1122 1330
1123 // Simulate browser seek is done and confirm player requests more data. 1331 // Simulate browser seek is done and confirm player requests more data.
1124 player_.OnDemuxerSeekDone(base::TimeDelta()); 1332 player_.OnDemuxerSeekDone(base::TimeDelta());
1125 EXPECT_TRUE(GetMediaDecoderJob(false)); 1333 EXPECT_TRUE(GetMediaDecoderJob(false));
1126 EXPECT_EQ(2, demuxer_->num_data_requests()); 1334 EXPECT_EQ(2, demuxer_->num_data_requests());
1127 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1335 EXPECT_EQ(1, demuxer_->num_seek_requests());
1128 } 1336 }
1129 1337
1130 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { 1338 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) {
1131 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1339 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1132 1340
1133 // Test decoder job will preroll the media to the seek position. 1341 // Test decoder job will preroll the media to the seek position.
1134 StartAudioDecoderJob(); 1342 StartAudioDecoderJob(true);
1135 EXPECT_TRUE(GetMediaDecoderJob(true));
1136 EXPECT_EQ(1, demuxer_->num_data_requests());
1137 1343
1138 SeekPlayer(true, base::TimeDelta::FromMilliseconds(100)); 1344 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1139 EXPECT_TRUE(IsPrerolling(true)); 1345 EXPECT_TRUE(IsPrerolling(true));
1140 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1346 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1141 1347
1142 // Send some data before the seek position. 1348 // Send some data before the seek position.
1143 for (int i = 1; i < 4; ++i) { 1349 for (int i = 1; i < 4; ++i) {
1144 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); 1350 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i));
1145 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1351 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1146 message_loop_.Run(); 1352 message_loop_.Run();
1147 } 1353 }
1148 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1354 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1149 EXPECT_TRUE(IsPrerolling(true)); 1355 EXPECT_TRUE(IsPrerolling(true));
1150 1356
1151 // Send data after the seek position. 1357 // Send data after the seek position.
1152 DemuxerData data = CreateReadFromDemuxerAckForAudio(3); 1358 DemuxerData data = CreateReadFromDemuxerAckForAudio(3);
1153 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100); 1359 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100);
1154 player_.OnDemuxerDataAvailable(data); 1360 player_.OnDemuxerDataAvailable(data);
1155 message_loop_.Run(); 1361 message_loop_.Run();
1156 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF()); 1362 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF());
1157 EXPECT_FALSE(IsPrerolling(true)); 1363 EXPECT_FALSE(IsPrerolling(true));
1158 } 1364 }
1159 1365
1160 TEST_F(MediaSourcePlayerTest, PrerollVideoAfterSeek) { 1366 TEST_F(MediaSourcePlayerTest, PrerollVideoAfterSeek) {
1161 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1367 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1162 1368
1163 // Test decoder job will preroll the media to the seek position. 1369 // Test decoder job will preroll the media to the seek position.
1164 CreateNextTextureAndSetVideoSurface(); 1370 CreateNextTextureAndSetVideoSurface();
1165 StartVideoDecoderJob(); 1371 StartVideoDecoderJob(true);
1166 EXPECT_TRUE(GetMediaDecoderJob(false));
1167 EXPECT_EQ(1, demuxer_->num_data_requests());
1168 1372
1169 SeekPlayer(false, base::TimeDelta::FromMilliseconds(100)); 1373 SeekPlayerWithAbort(false, base::TimeDelta::FromMilliseconds(100));
1170 EXPECT_TRUE(IsPrerolling(false)); 1374 EXPECT_TRUE(IsPrerolling(false));
1171 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1375 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1172 1376
1173 // Send some data before the seek position. 1377 // Send some data before the seek position.
1174 DemuxerData data; 1378 DemuxerData data;
1175 for (int i = 1; i < 4; ++i) { 1379 for (int i = 1; i < 4; ++i) {
1176 data = CreateReadFromDemuxerAckForVideo(); 1380 data = CreateReadFromDemuxerAckForVideo();
1177 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 30); 1381 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 30);
1178 player_.OnDemuxerDataAvailable(data); 1382 player_.OnDemuxerDataAvailable(data);
1179 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding()); 1383 EXPECT_TRUE(GetMediaDecoderJob(false)->is_decoding());
1180 message_loop_.Run(); 1384 message_loop_.Run();
1181 } 1385 }
1182 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1386 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1183 EXPECT_TRUE(IsPrerolling(false)); 1387 EXPECT_TRUE(IsPrerolling(false));
1184 1388
1185 // Send data at the seek position. 1389 // Send data at the seek position.
1186 data = CreateReadFromDemuxerAckForVideo(); 1390 data = CreateReadFromDemuxerAckForVideo();
1187 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100); 1391 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100);
1188 player_.OnDemuxerDataAvailable(data); 1392 player_.OnDemuxerDataAvailable(data);
1189 message_loop_.Run(); 1393 message_loop_.Run();
1190 1394
1191 // TODO(wolenetz/qinmin): Player's maintenance of current time for video-only 1395 // TODO(wolenetz/qinmin): Player's maintenance of current time for video-only
1192 // streams depends on decoder output, which may be initially inaccurate, and 1396 // 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 1397 // encoded video test data may also need updating. Verify at least that AU
1194 // timestamp-based preroll logic has determined video preroll has completed. 1398 // timestamp-based preroll logic has determined video preroll has completed.
1399 // See http://crbug.com/310823 and http://b/11356652.
1195 EXPECT_FALSE(IsPrerolling(false)); 1400 EXPECT_FALSE(IsPrerolling(false));
1196 } 1401 }
1197 1402
1198 TEST_F(MediaSourcePlayerTest, SeekingAfterCompletingPrerollRestartsPreroll) { 1403 TEST_F(MediaSourcePlayerTest, SeekingAfterCompletingPrerollRestartsPreroll) {
1199 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1404 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1200 1405
1201 // Test decoder job will begin prerolling upon seek, when it was not 1406 // Test decoder job will begin prerolling upon seek, when it was not
1202 // prerolling prior to the seek. 1407 // prerolling prior to the seek.
1203 StartAudioDecoderJob(); 1408 StartAudioDecoderJob(true);
1204 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 1409 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true);
1205 EXPECT_TRUE(decoder_job);
1206 EXPECT_EQ(1, demuxer_->num_data_requests());
1207 EXPECT_TRUE(IsPrerolling(true)); 1410 EXPECT_TRUE(IsPrerolling(true));
1208 1411
1209 // Complete the initial preroll by feeding data to the decoder. 1412 // Complete the initial preroll by feeding data to the decoder.
1210 for (int i = 0; i < 4; ++i) { 1413 for (int i = 0; i < 4; ++i) {
1211 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); 1414 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i));
1212 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1415 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1213 message_loop_.Run(); 1416 message_loop_.Run();
1214 } 1417 }
1215 EXPECT_LT(0.0, player_.GetCurrentTime().InMillisecondsF()); 1418 EXPECT_LT(0.0, player_.GetCurrentTime().InMillisecondsF());
1216 EXPECT_FALSE(IsPrerolling(true)); 1419 EXPECT_FALSE(IsPrerolling(true));
1217 1420
1218 SeekPlayer(true, base::TimeDelta::FromMilliseconds(500)); 1421 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(500));
1219 1422
1220 // Prerolling should have begun again. 1423 // Prerolling should have begun again.
1221 EXPECT_TRUE(IsPrerolling(true)); 1424 EXPECT_TRUE(IsPrerolling(true));
1222 EXPECT_EQ(500.0, GetPrerollTimestamp().InMillisecondsF()); 1425 EXPECT_EQ(500.0, GetPrerollTimestamp().InMillisecondsF());
1223 1426
1224 // Send data at and after the seek position. Prerolling should complete. 1427 // Send data at and after the seek position. Prerolling should complete.
1225 for (int i = 0; i < 4; ++i) { 1428 for (int i = 0; i < 4; ++i) {
1226 DemuxerData data = CreateReadFromDemuxerAckForAudio(i); 1429 DemuxerData data = CreateReadFromDemuxerAckForAudio(i);
1227 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds( 1430 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(
1228 500 + 30 * (i - 1)); 1431 500 + 30 * (i - 1));
1229 player_.OnDemuxerDataAvailable(data); 1432 player_.OnDemuxerDataAvailable(data);
1230 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1433 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1231 message_loop_.Run(); 1434 message_loop_.Run();
1232 } 1435 }
1233 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF()); 1436 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF());
1234 EXPECT_FALSE(IsPrerolling(true)); 1437 EXPECT_FALSE(IsPrerolling(true));
1235 1438
1236 // Throughout this test, we should have not re-created the decoder job, so 1439 // 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 1440 // IsPrerolling() transition from false to true was not due to constructor
1238 // initialization. It was due to BeginPrerolling(). 1441 // initialization. It was due to BeginPrerolling().
1239 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 1442 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
1240 } 1443 }
1241 1444
1242 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossReleaseAndStart) { 1445 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossReleaseAndStart) {
1243 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1446 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1244 1447
1245 // Test decoder job will resume media prerolling if interrupted by Release() 1448 // Test decoder job will resume media prerolling if interrupted by Release()
1246 // and Start(). 1449 // and Start().
1247 StartAudioDecoderJob(); 1450 StartAudioDecoderJob(true);
1248 EXPECT_TRUE(GetMediaDecoderJob(true));
1249 EXPECT_EQ(1, demuxer_->num_data_requests());
1250 1451
1251 SeekPlayer(true, base::TimeDelta::FromMilliseconds(100)); 1452 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1252 EXPECT_TRUE(IsPrerolling(true)); 1453 EXPECT_TRUE(IsPrerolling(true));
1253 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1454 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1254 1455
1255 // Send some data before the seek position. 1456 // Send some data before the seek position.
1256 // Test uses 'large' number of iterations because decoder job may not get 1457 // 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. 1458 // MEDIA_CODEC_OK output status until after a few dequeue output attempts.
1258 // This allows decoder status to stabilize prior to AU timestamp reaching 1459 // This allows decoder status to stabilize prior to AU timestamp reaching
1259 // the preroll target. 1460 // the preroll target.
1260 DemuxerData data; 1461 DemuxerData data;
1261 for (int i = 0; i < 10; ++i) { 1462 for (int i = 0; i < 10; ++i) {
1262 data = CreateReadFromDemuxerAckForAudio(3); 1463 data = CreateReadFromDemuxerAckForAudio(3);
1263 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 10); 1464 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 10);
1264 if (i == 1) { 1465 if (i == 1) {
1265 // While still prerolling, Release() and Start() the player. 1466 // While still prerolling, Release() and Start() the player.
1266 // TODO(qinmin): Simulation of multiple in-flight data requests (one from 1467 // TODO(qinmin): Simulation of multiple in-flight data requests (one from
1267 // before Release(), one from after Start()) is not included here, and 1468 // before Release(), one from after Start()) is not included here, and
1268 // neither is any data enqueued for later decode if it arrives after 1469 // neither is any data enqueued for later decode if it arrives after
1269 // Release() and before Start(). See http://crbug.com/306314. Assumption 1470 // Release() and before Start(). See http://crbug.com/306314. Assumption
1270 // for this test, to prevent flakiness until the bug is fixed, is the 1471 // 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 1472 // first request's data arrives before Start(). Though that data is not
1272 // seen by decoder, this assumption allows preroll continuation 1473 // seen by decoder, this assumption allows preroll continuation
1273 // verification and prevents multiple in-flight data requests. 1474 // verification and prevents multiple in-flight data requests.
1274 ReleasePlayer(); 1475 ReleasePlayer();
1275 player_.OnDemuxerDataAvailable(data); 1476 player_.OnDemuxerDataAvailable(data);
1276 message_loop_.RunUntilIdle(); 1477 message_loop_.RunUntilIdle();
1277 EXPECT_FALSE(GetMediaDecoderJob(true)); 1478 EXPECT_FALSE(GetMediaDecoderJob(true));
1278 StartAudioDecoderJob(); 1479 StartAudioDecoderJob(true);
1279 EXPECT_TRUE(GetMediaDecoderJob(true));
1280 } else { 1480 } else {
1281 player_.OnDemuxerDataAvailable(data); 1481 player_.OnDemuxerDataAvailable(data);
1282 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1482 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1283 message_loop_.Run(); 1483 message_loop_.Run();
1284 } 1484 }
1285 EXPECT_TRUE(IsPrerolling(true)); 1485 EXPECT_TRUE(IsPrerolling(true));
1286 } 1486 }
1287 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1487 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1288 EXPECT_TRUE(IsPrerolling(true)); 1488 EXPECT_TRUE(IsPrerolling(true));
1289 1489
1290 // Send data after the seek position. 1490 // Send data after the seek position.
1291 data = CreateReadFromDemuxerAckForAudio(3); 1491 data = CreateReadFromDemuxerAckForAudio(3);
1292 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100); 1492 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(100);
1293 player_.OnDemuxerDataAvailable(data); 1493 player_.OnDemuxerDataAvailable(data);
1294 message_loop_.Run(); 1494 message_loop_.Run();
1295 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF()); 1495 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF());
1296 EXPECT_FALSE(IsPrerolling(true)); 1496 EXPECT_FALSE(IsPrerolling(true));
1297 } 1497 }
1298 1498
1299 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) { 1499 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) {
1300 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1500 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1301 1501
1302 // Test decoder job will resume media prerolling if interrupted by 1502 // Test decoder job will resume media prerolling if interrupted by
1303 // |kConfigChanged| and OnDemuxerConfigsAvailable(). 1503 // |kConfigChanged| and OnDemuxerConfigsAvailable().
1304 StartAudioDecoderJob(); 1504 StartAudioDecoderJob(true);
1305 EXPECT_TRUE(GetMediaDecoderJob(true));
1306 EXPECT_EQ(1, demuxer_->num_data_requests());
1307 1505
1308 SeekPlayer(true, base::TimeDelta::FromMilliseconds(100)); 1506 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1309 EXPECT_TRUE(IsPrerolling(true)); 1507 EXPECT_TRUE(IsPrerolling(true));
1310 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1508 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1311 1509
1312 // In response to data request, simulate that demuxer signals config change by 1510 // In response to data request, simulate that demuxer signals config change by
1313 // sending an AU with |kConfigChanged|. Player should prepare to reconfigure 1511 // sending an AU with |kConfigChanged|. Player should prepare to reconfigure
1314 // the audio decoder job, and should request new demuxer configs. 1512 // the audio decoder job, and should request new demuxer configs.
1315 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); 1513 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0);
1316 EXPECT_EQ(0, demuxer_->num_config_requests()); 1514 EXPECT_EQ(0, demuxer_->num_config_requests());
1317 player_.OnDemuxerDataAvailable(data); 1515 player_.OnDemuxerDataAvailable(data);
1318 EXPECT_EQ(1, demuxer_->num_config_requests()); 1516 EXPECT_EQ(1, demuxer_->num_config_requests());
(...skipping 18 matching lines...) Expand all
1337 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF()); 1535 EXPECT_LT(100.0, player_.GetCurrentTime().InMillisecondsF());
1338 EXPECT_FALSE(IsPrerolling(true)); 1536 EXPECT_FALSE(IsPrerolling(true));
1339 } 1537 }
1340 1538
1341 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) { 1539 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) {
1342 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1540 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1343 1541
1344 // Test that the player allows simultaneous audio and video config change, 1542 // Test that the player allows simultaneous audio and video config change,
1345 // such as might occur during OnPrefetchDone() if next access unit for both 1543 // such as might occur during OnPrefetchDone() if next access unit for both
1346 // audio and video jobs is |kConfigChanged|. 1544 // audio and video jobs is |kConfigChanged|.
1347 Start(CreateAudioVideoDemuxerConfigs());
1348 CreateNextTextureAndSetVideoSurface(); 1545 CreateNextTextureAndSetVideoSurface();
1546 Start(CreateAudioVideoDemuxerConfigs(), true);
1349 MediaDecoderJob* first_audio_job = GetMediaDecoderJob(true); 1547 MediaDecoderJob* first_audio_job = GetMediaDecoderJob(true);
1350 MediaDecoderJob* first_video_job = GetMediaDecoderJob(false); 1548 MediaDecoderJob* first_video_job = GetMediaDecoderJob(false);
1351 EXPECT_TRUE(first_audio_job && first_video_job);
1352 1549
1353 // Simulate audio |kConfigChanged| prefetched as standalone access unit. 1550 // Simulate audio |kConfigChanged| prefetched as standalone access unit.
1354 player_.OnDemuxerDataAvailable( 1551 player_.OnDemuxerDataAvailable(
1355 CreateReadFromDemuxerAckWithConfigChanged(true, 0)); 1552 CreateReadFromDemuxerAckWithConfigChanged(true, 0));
1356 EXPECT_EQ(0, demuxer_->num_config_requests()); // No OnPrefetchDone() yet. 1553 EXPECT_EQ(0, demuxer_->num_config_requests()); // No OnPrefetchDone() yet.
1357 1554
1358 // Simulate video |kConfigChanged| prefetched as standalone access unit. 1555 // Simulate video |kConfigChanged| prefetched as standalone access unit.
1359 player_.OnDemuxerDataAvailable( 1556 player_.OnDemuxerDataAvailable(
1360 CreateReadFromDemuxerAckWithConfigChanged(false, 0)); 1557 CreateReadFromDemuxerAckWithConfigChanged(false, 0));
1361 EXPECT_EQ(1, demuxer_->num_config_requests()); // OnPrefetchDone() occurred. 1558 EXPECT_EQ(1, demuxer_->num_config_requests()); // OnPrefetchDone() occurred.
1362 EXPECT_EQ(2, demuxer_->num_data_requests()); 1559 EXPECT_EQ(2, demuxer_->num_data_requests()); // No more data requested yet.
1363 1560
1364 // No job re-creation should occur until the requested configs arrive. 1561 // No job re-creation should occur until the requested configs arrive.
1365 EXPECT_EQ(first_audio_job, GetMediaDecoderJob(true)); 1562 EXPECT_EQ(first_audio_job, GetMediaDecoderJob(true));
1366 EXPECT_EQ(first_video_job, GetMediaDecoderJob(false)); 1563 EXPECT_EQ(first_video_job, GetMediaDecoderJob(false));
1367 1564
1368 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs()); 1565 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs());
1369 EXPECT_EQ(4, demuxer_->num_data_requests()); 1566 EXPECT_EQ(4, demuxer_->num_data_requests());
1370 MediaDecoderJob* second_audio_job = GetMediaDecoderJob(true); 1567 MediaDecoderJob* second_audio_job = GetMediaDecoderJob(true);
1371 MediaDecoderJob* second_video_job = GetMediaDecoderJob(false); 1568 MediaDecoderJob* second_video_job = GetMediaDecoderJob(false);
1372 EXPECT_NE(first_audio_job, second_audio_job); 1569 EXPECT_NE(first_audio_job, second_audio_job);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 1748
1552 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { 1749 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) {
1553 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1750 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1554 1751
1555 // Test if OnPrefetchDone() had already been posted before and is executed 1752 // Test if OnPrefetchDone() had already been posted before and is executed
1556 // after Release(), then player does not DCHECK. This test is fragile to 1753 // after Release(), then player does not DCHECK. This test is fragile to
1557 // change to MediaDecoderJob::Prefetch() implementation; it assumes task 1754 // change to MediaDecoderJob::Prefetch() implementation; it assumes task
1558 // is posted to run |prefetch_cb| if the job already HasData(). 1755 // is posted to run |prefetch_cb| if the job already HasData().
1559 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test 1756 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test
1560 // becomes obsolete. See http://crbug.com/304234. 1757 // becomes obsolete. See http://crbug.com/304234.
1561 StartAudioDecoderJob(); 1758 StartAudioDecoderJob(true);
1562 1759
1563 // Escape the original prefetch by decoding a single access unit. 1760 // Escape the original prefetch by decoding a single access unit.
1564 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1761 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1565 message_loop_.Run(); 1762 message_loop_.Run();
1566 1763
1567 // Prime the job with a few more access units, so that a later prefetch, 1764 // Prime the job with a few more access units, so that a later prefetch,
1568 // triggered by starvation to simulate decoder underrun, can trivially 1765 // triggered by starvation to simulate decoder underrun, can trivially
1569 // post task to run OnPrefetchDone(). 1766 // post task to run OnPrefetchDone().
1570 player_.OnDemuxerDataAvailable( 1767 player_.OnDemuxerDataAvailable(
1571 CreateReadFromDemuxerAckWithConfigChanged(true, 4)); 1768 CreateReadFromDemuxerAckWithConfigChanged(true, 4));
1572 EXPECT_TRUE(GetMediaDecoderJob(true) && 1769 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1573 GetMediaDecoderJob(true)->is_decoding());
1574 1770
1575 // Simulate decoder underrun, so trivial prefetch starts while still decoding. 1771 // Simulate decoder underrun, so trivial prefetch starts while still decoding.
1576 // The prefetch and posting of OnPrefetchDone() will not occur until next 1772 // The prefetch and posting of OnPrefetchDone() will not occur until next
1577 // MediaDecoderCallBack() occurs. 1773 // MediaDecoderCallBack() occurs.
1578 TriggerPlayerStarvation(); 1774 TriggerPlayerStarvation();
1579 1775
1580 // Upon the next successful decode callback, post a task to call Release() on 1776 // Upon the next successful decode callback, post a task to call Release() on
1581 // the |player_|, such that the trivial OnPrefetchDone() task posting also 1777 // the |player_|, such that the trivial OnPrefetchDone() task posting also
1582 // occurs and should execute after the Release(). 1778 // occurs and should execute after the Release().
1583 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); 1779 OnNextTestDecodeCallbackPostTaskToReleasePlayer();
1584 1780
1585 while (GetMediaDecoderJob(true)) 1781 while (GetMediaDecoderJob(true))
1586 message_loop_.RunUntilIdle(); 1782 message_loop_.RunUntilIdle();
1587 EXPECT_TRUE(decoder_callback_hook_executed_); 1783 EXPECT_TRUE(decoder_callback_hook_executed_);
1588 EXPECT_EQ(2, demuxer_->num_data_requests()); 1784 EXPECT_EQ(2, demuxer_->num_data_requests());
1589 1785
1590 // Player should have no decoder job until after Start(). 1786 // Player should have no decoder job until after Start().
1591 StartAudioDecoderJob(); 1787 StartAudioDecoderJob(true);
1592 EXPECT_TRUE(GetMediaDecoderJob(true));
1593 } 1788 }
1594 1789
1595 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { 1790 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) {
1596 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1791 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1597 1792
1598 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1793 // 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, 1794 // 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 1795 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player
1601 // will resume correct post-seek preroll upon Start(). 1796 // will resume correct post-seek preroll upon Start().
1602 StartAudioDecoderJobAndSeekToWhileDecoding( 1797 StartAudioDecoderJobAndSeekToWhileDecoding(
1603 base::TimeDelta::FromMilliseconds(100)); 1798 base::TimeDelta::FromMilliseconds(100));
1604 ReleasePlayer(); 1799 ReleasePlayer();
1605 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1800 EXPECT_EQ(1, demuxer_->num_seek_requests());
1606 1801
1607 player_.OnDemuxerSeekDone(kNoTimestamp()); 1802 player_.OnDemuxerSeekDone(kNoTimestamp());
1608 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1803 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1609 EXPECT_FALSE(GetMediaDecoderJob(true)); 1804 EXPECT_FALSE(GetMediaDecoderJob(true));
1610 EXPECT_FALSE(player_.IsPlaying()); 1805 EXPECT_FALSE(player_.IsPlaying());
1611 1806
1612 // Player should begin prefetch and resume preroll upon Start(). 1807 // Player should begin prefetch and resume preroll upon Start().
1613 EXPECT_EQ(1, demuxer_->num_data_requests()); 1808 EXPECT_EQ(1, demuxer_->num_data_requests());
1614 StartAudioDecoderJob(); 1809 StartAudioDecoderJob(true);
1615 EXPECT_TRUE(GetMediaDecoderJob(true));
1616 EXPECT_TRUE(IsPrerolling(true)); 1810 EXPECT_TRUE(IsPrerolling(true));
1617 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1811 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1618 EXPECT_EQ(2, demuxer_->num_data_requests());
1619 1812
1620 // No further seek should have been requested since Release(), above. 1813 // No further seek should have been requested since Release(), above.
1621 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1814 EXPECT_EQ(1, demuxer_->num_seek_requests());
1622 } 1815 }
1623 1816
1624 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { 1817 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) {
1625 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1818 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1626 1819
1627 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1820 // 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, 1821 // 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(), 1822 // test if OnDemuxerSeekDone() does not occur until after the next Start(),
1630 // then the player remains pending seek done until (and resumes correct 1823 // then the player remains pending seek done until (and resumes correct
1631 // post-seek preroll after) OnDemuxerSeekDone(). 1824 // post-seek preroll after) OnDemuxerSeekDone().
1632 StartAudioDecoderJobAndSeekToWhileDecoding( 1825 StartAudioDecoderJobAndSeekToWhileDecoding(
1633 base::TimeDelta::FromMilliseconds(100)); 1826 base::TimeDelta::FromMilliseconds(100));
1634 ReleasePlayer(); 1827 ReleasePlayer();
1635 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1828 EXPECT_EQ(1, demuxer_->num_seek_requests());
1636 1829
1637 // Player should not prefetch upon Start() nor create the decoder job, due to 1830 // Player should not prefetch upon Start() nor create the decoder job, due to
1638 // awaiting DemuxerSeekDone. 1831 // awaiting DemuxerSeekDone.
1639 StartAudioDecoderJob();
1640 EXPECT_FALSE(GetMediaDecoderJob(true));
1641 EXPECT_EQ(1, demuxer_->num_data_requests()); 1832 EXPECT_EQ(1, demuxer_->num_data_requests());
1833 StartAudioDecoderJob(false);
1642 1834
1643 player_.OnDemuxerSeekDone(kNoTimestamp()); 1835 player_.OnDemuxerSeekDone(kNoTimestamp());
1644 EXPECT_TRUE(GetMediaDecoderJob(true)); 1836 EXPECT_TRUE(GetMediaDecoderJob(true));
1645 EXPECT_TRUE(IsPrerolling(true)); 1837 EXPECT_TRUE(IsPrerolling(true));
1646 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1838 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1647 EXPECT_EQ(2, demuxer_->num_data_requests()); 1839 EXPECT_EQ(2, demuxer_->num_data_requests());
1648 1840
1649 // No further seek should have been requested since Release(), above. 1841 // No further seek should have been requested since Release(), above.
1650 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1842 EXPECT_EQ(1, demuxer_->num_seek_requests());
1651 } 1843 }
1652 1844
1653 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) { 1845 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) {
1654 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1846 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1655 1847
1656 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC 1848 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC
1657 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the 1849 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the
1658 // player will resume correct post-seek preroll upon Start(). 1850 // player will resume correct post-seek preroll upon Start().
1659 StartAudioDecoderJobAndSeekToWhileDecoding( 1851 StartAudioDecoderJobAndSeekToWhileDecoding(
1660 base::TimeDelta::FromMilliseconds(100)); 1852 base::TimeDelta::FromMilliseconds(100));
1661 while (GetMediaDecoderJob(true)->is_decoding()) 1853 WaitForAudioDecodeDone();
1662 message_loop_.RunUntilIdle();
1663 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1854 EXPECT_EQ(1, demuxer_->num_seek_requests());
1664 1855
1665 ReleasePlayer(); 1856 ReleasePlayer();
1666 player_.OnDemuxerSeekDone(kNoTimestamp()); 1857 player_.OnDemuxerSeekDone(kNoTimestamp());
1667 EXPECT_FALSE(player_.IsPlaying()); 1858 EXPECT_FALSE(player_.IsPlaying());
1668 EXPECT_FALSE(GetMediaDecoderJob(true)); 1859 EXPECT_FALSE(GetMediaDecoderJob(true));
1669 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1860 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1670 1861
1671 // Player should begin prefetch and resume preroll upon Start(). 1862 // Player should begin prefetch and resume preroll upon Start().
1672 EXPECT_EQ(1, demuxer_->num_data_requests()); 1863 EXPECT_EQ(1, demuxer_->num_data_requests());
1673 StartAudioDecoderJob(); 1864 StartAudioDecoderJob(true);
1674 EXPECT_TRUE(GetMediaDecoderJob(true));
1675 EXPECT_TRUE(IsPrerolling(true)); 1865 EXPECT_TRUE(IsPrerolling(true));
1676 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1866 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1677 EXPECT_EQ(2, demuxer_->num_data_requests());
1678 1867
1679 // No further seek should have been requested since before Release(), above. 1868 // No further seek should have been requested since before Release(), above.
1680 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1869 EXPECT_EQ(1, demuxer_->num_seek_requests());
1681 } 1870 }
1682 1871
1683 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { 1872 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) {
1684 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1873 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1685 1874
1686 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC 1875 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC
1687 // request OnDemuxerSeekDone() does not occur until after the next Start(), 1876 // request and OnDemuxerSeekDone() does not occur until after the next
1688 // then the player remains pending seek done until (and resumes correct 1877 // Start(), then the player remains pending seek done until (and resumes
1689 // post-seek preroll after) OnDemuxerSeekDone(). 1878 // correct post-seek preroll after) OnDemuxerSeekDone().
1690 StartAudioDecoderJobAndSeekToWhileDecoding( 1879 StartAudioDecoderJobAndSeekToWhileDecoding(
1691 base::TimeDelta::FromMilliseconds(100)); 1880 base::TimeDelta::FromMilliseconds(100));
1692 while (GetMediaDecoderJob(true)->is_decoding()) 1881 WaitForAudioDecodeDone();
1693 message_loop_.RunUntilIdle();
1694 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1882 EXPECT_EQ(1, demuxer_->num_seek_requests());
1695 1883
1696 ReleasePlayer(); 1884 ReleasePlayer();
1697 StartAudioDecoderJob();
1698 EXPECT_FALSE(GetMediaDecoderJob(true));
1699 EXPECT_EQ(1, demuxer_->num_data_requests()); 1885 EXPECT_EQ(1, demuxer_->num_data_requests());
1886 StartAudioDecoderJob(false);
1700 1887
1701 player_.OnDemuxerSeekDone(kNoTimestamp()); 1888 player_.OnDemuxerSeekDone(kNoTimestamp());
1702 EXPECT_TRUE(GetMediaDecoderJob(true)); 1889 EXPECT_TRUE(GetMediaDecoderJob(true));
1703 EXPECT_TRUE(IsPrerolling(true)); 1890 EXPECT_TRUE(IsPrerolling(true));
1704 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1891 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1705 EXPECT_EQ(2, demuxer_->num_data_requests()); 1892 EXPECT_EQ(2, demuxer_->num_data_requests());
1706 1893
1707 // No further seek should have been requested since before Release(), above. 1894 // No further seek should have been requested since before Release(), above.
1708 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1895 EXPECT_EQ(1, demuxer_->num_seek_requests());
1709 } 1896 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 1953 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
1767 ReleasePlayer(); 1954 ReleasePlayer();
1768 1955
1769 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 1956 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
1770 EXPECT_FALSE(player_.IsPlaying()); 1957 EXPECT_FALSE(player_.IsPlaying());
1771 EXPECT_FALSE(GetMediaDecoderJob(false)); 1958 EXPECT_FALSE(GetMediaDecoderJob(false));
1772 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 1959 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1773 1960
1774 // Player should begin prefetch and resume preroll upon Start(). 1961 // Player should begin prefetch and resume preroll upon Start().
1775 EXPECT_EQ(1, demuxer_->num_data_requests()); 1962 EXPECT_EQ(1, demuxer_->num_data_requests());
1776 StartVideoDecoderJob();
1777 CreateNextTextureAndSetVideoSurface(); 1963 CreateNextTextureAndSetVideoSurface();
1778 EXPECT_TRUE(GetMediaDecoderJob(false)); 1964 StartVideoDecoderJob(true);
1779 EXPECT_TRUE(IsPrerolling(false)); 1965 EXPECT_TRUE(IsPrerolling(false));
1780 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 1966 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1781 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 1967 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
1782 EXPECT_EQ(2, demuxer_->num_data_requests());
1783 1968
1784 // No further seek should have been requested since BrowserSeekPlayer(). 1969 // No further seek should have been requested since BrowserSeekPlayer().
1785 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1970 EXPECT_EQ(1, demuxer_->num_seek_requests());
1786 } 1971 }
1787 1972
1788 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenStart) { 1973 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenStart) {
1789 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1974 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1790 1975
1791 // Test that Release() after a browser seek's DemuxerSeek IPC request has been 1976 // 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 1977 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() does not
1793 // occur until after the next Start()+SetVideoSurface(), then the player 1978 // occur until after the next Start()+SetVideoSurface(), then the player
1794 // remains pending seek done until (and resumes correct post-seek preroll 1979 // remains pending seek done until (and resumes correct post-seek preroll
1795 // after) OnDemuxerSeekDone(). 1980 // after) OnDemuxerSeekDone().
1796 BrowserSeekPlayer(false); 1981 BrowserSeekPlayer(false);
1797 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 1982 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
1798 ReleasePlayer(); 1983 ReleasePlayer();
1799 1984
1800 StartVideoDecoderJob(); 1985 EXPECT_EQ(1, demuxer_->num_data_requests());
1801 CreateNextTextureAndSetVideoSurface(); 1986 CreateNextTextureAndSetVideoSurface();
1802 EXPECT_FALSE(GetMediaDecoderJob(false)); 1987 StartVideoDecoderJob(false);
1803 EXPECT_EQ(1, demuxer_->num_data_requests());
1804 1988
1805 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 1989 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
1806 EXPECT_TRUE(GetMediaDecoderJob(false)); 1990 EXPECT_TRUE(GetMediaDecoderJob(false));
1807 EXPECT_TRUE(IsPrerolling(false)); 1991 EXPECT_TRUE(IsPrerolling(false));
1808 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 1992 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1809 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 1993 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
1810 EXPECT_EQ(2, demuxer_->num_data_requests()); 1994 EXPECT_EQ(2, demuxer_->num_data_requests());
1811 1995
1812 // No further seek should have been requested since BrowserSeekPlayer(). 1996 // No further seek should have been requested since BrowserSeekPlayer().
1813 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1997 EXPECT_EQ(1, demuxer_->num_seek_requests());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 2084
1901 std::vector<std::string> codec_avc(1, "avc1"); 2085 std::vector<std::string> codec_avc(1, "avc1");
1902 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L3", kVideoMp4, codec_avc)); 2086 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L3", kVideoMp4, codec_avc));
1903 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L1", kVideoMp4, codec_avc)); 2087 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L1", kVideoMp4, codec_avc));
1904 } 2088 }
1905 2089
1906 // TODO(xhwang): Are these IsTypeSupported tests device specific? 2090 // TODO(xhwang): Are these IsTypeSupported tests device specific?
1907 // TODO(xhwang): Add more IsTypeSupported tests. 2091 // TODO(xhwang): Add more IsTypeSupported tests.
1908 2092
1909 } // namespace media 2093 } // 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