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

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

Issue 1242913004: MediaCodecPlayer implementation (stage 3 - browser seek and surface change) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mtplayer-seek
Patch Set: Rebased, changed DCHECKs. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/android/media_codec_decoder.cc ('k') | media/base/android/media_codec_player.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "base/timer/timer.h" 8 #include "base/timer/timer.h"
9 #include "media/base/android/media_codec_audio_decoder.h" 9 #include "media/base/android/media_codec_audio_decoder.h"
10 #include "media/base/android/media_codec_bridge.h" 10 #include "media/base/android/media_codec_bridge.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 task_runner_->PostDelayedTask(FROM_HERE, base::Bind(data_available_cb_, data), 270 task_runner_->PostDelayedTask(FROM_HERE, base::Bind(data_available_cb_, data),
271 delay); 271 delay);
272 } 272 }
273 273
274 void MediaCodecDecoderTest::SetVideoSurface() { 274 void MediaCodecDecoderTest::SetVideoSurface() {
275 surface_texture_ = gfx::SurfaceTexture::Create(0); 275 surface_texture_ = gfx::SurfaceTexture::Create(0);
276 gfx::ScopedJavaSurface surface(surface_texture_.get()); 276 gfx::ScopedJavaSurface surface(surface_texture_.get());
277 ASSERT_NE(nullptr, decoder_.get()); 277 ASSERT_NE(nullptr, decoder_.get());
278 MediaCodecVideoDecoder* video_decoder = 278 MediaCodecVideoDecoder* video_decoder =
279 static_cast<MediaCodecVideoDecoder*>(decoder_.get()); 279 static_cast<MediaCodecVideoDecoder*>(decoder_.get());
280 video_decoder->SetPendingSurface(surface.Pass()); 280 video_decoder->SetVideoSurface(surface.Pass());
281 } 281 }
282 282
283 TEST_F(MediaCodecDecoderTest, AudioPrefetch) { 283 TEST_F(MediaCodecDecoderTest, AudioPrefetch) {
284 CreateAudioDecoder(); 284 CreateAudioDecoder();
285 285
286 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); 286 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500);
287 SetDataFactory(scoped_ptr<TestDataFactory>(new AudioFactory(duration))); 287 SetDataFactory(scoped_ptr<TestDataFactory>(new AudioFactory(duration)));
288 288
289 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, 289 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched,
290 base::Unretained(this), true)); 290 base::Unretained(this), true));
(...skipping 14 matching lines...) Expand all
305 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, 305 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched,
306 base::Unretained(this)))); 306 base::Unretained(this))));
307 } 307 }
308 308
309 TEST_F(MediaCodecDecoderTest, AudioConfigureNoParams) { 309 TEST_F(MediaCodecDecoderTest, AudioConfigureNoParams) {
310 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 310 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
311 311
312 CreateAudioDecoder(); 312 CreateAudioDecoder();
313 313
314 // Cannot configure without config parameters. 314 // Cannot configure without config parameters.
315 EXPECT_EQ(MediaCodecDecoder::CONFIG_FAILURE, decoder_->Configure()); 315 EXPECT_EQ(MediaCodecDecoder::kConfigFailure, decoder_->Configure());
316 } 316 }
317 317
318 TEST_F(MediaCodecDecoderTest, AudioConfigureValidParams) { 318 TEST_F(MediaCodecDecoderTest, AudioConfigureValidParams) {
319 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 319 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
320 320
321 CreateAudioDecoder(); 321 CreateAudioDecoder();
322 322
323 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); 323 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500);
324 scoped_ptr<AudioFactory> factory(new AudioFactory(duration)); 324 scoped_ptr<AudioFactory> factory(new AudioFactory(duration));
325 decoder_->SetDemuxerConfigs(factory->GetConfigs()); 325 decoder_->SetDemuxerConfigs(factory->GetConfigs());
326 326
327 EXPECT_EQ(MediaCodecDecoder::CONFIG_OK, decoder_->Configure()); 327 EXPECT_EQ(MediaCodecDecoder::kConfigOk, decoder_->Configure());
328 } 328 }
329 329
330 TEST_F(MediaCodecDecoderTest, VideoConfigureNoParams) { 330 TEST_F(MediaCodecDecoderTest, VideoConfigureNoParams) {
331 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 331 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
332 332
333 CreateVideoDecoder(); 333 CreateVideoDecoder();
334 334
335 // decoder_->Configure() searches back for the key frame.
336 // We have to prefetch decoder.
337
338 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500);
339 SetDataFactory(scoped_ptr<VideoFactory>(new VideoFactory(duration)));
340
341 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched,
342 base::Unretained(this), true));
343
344 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched,
345 base::Unretained(this))));
346
347 SetVideoSurface();
348
335 // Cannot configure without config parameters. 349 // Cannot configure without config parameters.
336 EXPECT_EQ(MediaCodecDecoder::CONFIG_FAILURE, decoder_->Configure()); 350 EXPECT_EQ(MediaCodecDecoder::kConfigFailure, decoder_->Configure());
337 } 351 }
338 352
339 TEST_F(MediaCodecDecoderTest, VideoConfigureNoSurface) { 353 TEST_F(MediaCodecDecoderTest, VideoConfigureNoSurface) {
340 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 354 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
341 355
342 CreateVideoDecoder(); 356 CreateVideoDecoder();
343 357
344 // decoder_->Configure() searches back for the key frame. 358 // decoder_->Configure() searches back for the key frame.
345 // We have to prefetch decoder. 359 // We have to prefetch decoder.
346 360
347 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); 361 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500);
348 SetDataFactory(scoped_ptr<VideoFactory>(new VideoFactory(duration))); 362 SetDataFactory(scoped_ptr<VideoFactory>(new VideoFactory(duration)));
349 363
350 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, 364 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched,
351 base::Unretained(this), true)); 365 base::Unretained(this), true));
352 366
353 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, 367 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched,
354 base::Unretained(this)))); 368 base::Unretained(this))));
355 369
356 decoder_->SetDemuxerConfigs(GetConfigs()); 370 decoder_->SetDemuxerConfigs(GetConfigs());
357 371
358 // Surface is not set, Configure() should fail. 372 // Surface is not set, Configure() should fail.
359 373
360 EXPECT_EQ(MediaCodecDecoder::CONFIG_FAILURE, decoder_->Configure()); 374 EXPECT_EQ(MediaCodecDecoder::kConfigFailure, decoder_->Configure());
361 } 375 }
362 376
363 TEST_F(MediaCodecDecoderTest, VideoConfigureInvalidSurface) { 377 TEST_F(MediaCodecDecoderTest, VideoConfigureInvalidSurface) {
364 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 378 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
365 379
366 CreateVideoDecoder(); 380 CreateVideoDecoder();
367 381
368 // decoder_->Configure() searches back for the key frame. 382 // decoder_->Configure() searches back for the key frame.
369 // We have to prefetch decoder. 383 // We have to prefetch decoder.
370 384
(...skipping 11 matching lines...) Expand all
382 // Prepare the surface. 396 // Prepare the surface.
383 scoped_refptr<gfx::SurfaceTexture> surface_texture( 397 scoped_refptr<gfx::SurfaceTexture> surface_texture(
384 gfx::SurfaceTexture::Create(0)); 398 gfx::SurfaceTexture::Create(0));
385 gfx::ScopedJavaSurface surface(surface_texture.get()); 399 gfx::ScopedJavaSurface surface(surface_texture.get());
386 400
387 // Release the surface texture. 401 // Release the surface texture.
388 surface_texture = NULL; 402 surface_texture = NULL;
389 403
390 MediaCodecVideoDecoder* video_decoder = 404 MediaCodecVideoDecoder* video_decoder =
391 static_cast<MediaCodecVideoDecoder*>(decoder_.get()); 405 static_cast<MediaCodecVideoDecoder*>(decoder_.get());
392 video_decoder->SetPendingSurface(surface.Pass()); 406 video_decoder->SetVideoSurface(surface.Pass());
393 407
394 EXPECT_EQ(MediaCodecDecoder::CONFIG_FAILURE, decoder_->Configure()); 408 EXPECT_EQ(MediaCodecDecoder::kConfigFailure, decoder_->Configure());
395 } 409 }
396 410
397 TEST_F(MediaCodecDecoderTest, VideoConfigureValidParams) { 411 TEST_F(MediaCodecDecoderTest, VideoConfigureValidParams) {
398 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 412 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
399 413
400 CreateVideoDecoder(); 414 CreateVideoDecoder();
401 415
402 // decoder_->Configure() searches back for the key frame. 416 // decoder_->Configure() searches back for the key frame.
403 // We have to prefetch decoder. 417 // We have to prefetch decoder.
404 418
405 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); 419 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500);
406 SetDataFactory(scoped_ptr<VideoFactory>(new VideoFactory(duration))); 420 SetDataFactory(scoped_ptr<VideoFactory>(new VideoFactory(duration)));
407 421
408 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, 422 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched,
409 base::Unretained(this), true)); 423 base::Unretained(this), true));
410 424
411 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, 425 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched,
412 base::Unretained(this)))); 426 base::Unretained(this))));
413 427
414 decoder_->SetDemuxerConfigs(GetConfigs()); 428 decoder_->SetDemuxerConfigs(GetConfigs());
415 429
416 SetVideoSurface(); 430 SetVideoSurface();
417 431
418 // Now we can expect Configure() to succeed. 432 // Now we can expect Configure() to succeed.
419 433
420 EXPECT_EQ(MediaCodecDecoder::CONFIG_OK, decoder_->Configure()); 434 EXPECT_EQ(MediaCodecDecoder::kConfigOk, decoder_->Configure());
421 } 435 }
422 436
423 TEST_F(MediaCodecDecoderTest, AudioStartWithoutConfigure) { 437 TEST_F(MediaCodecDecoderTest, AudioStartWithoutConfigure) {
424 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 438 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
425 439
426 CreateAudioDecoder(); 440 CreateAudioDecoder();
427 441
428 // Decoder has to be prefetched and configured before the start. 442 // Decoder has to be prefetched and configured before the start.
429 443
430 // Wrong state: not prefetched 444 // Wrong state: not prefetched
(...skipping 26 matching lines...) Expand all
457 471
458 // Prefetch to avoid starvation at the beginning of playback. 472 // Prefetch to avoid starvation at the beginning of playback.
459 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, 473 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched,
460 base::Unretained(this), true)); 474 base::Unretained(this), true));
461 475
462 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, 476 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched,
463 base::Unretained(this)))); 477 base::Unretained(this))));
464 478
465 decoder_->SetDemuxerConfigs(GetConfigs()); 479 decoder_->SetDemuxerConfigs(GetConfigs());
466 480
467 EXPECT_EQ(MediaCodecDecoder::CONFIG_OK, decoder_->Configure()); 481 EXPECT_EQ(MediaCodecDecoder::kConfigOk, decoder_->Configure());
468 482
469 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); 483 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0)));
470 484
471 EXPECT_TRUE(WaitForCondition( 485 EXPECT_TRUE(WaitForCondition(
472 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)), 486 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)),
473 timeout)); 487 timeout));
474 488
475 EXPECT_TRUE(decoder_->IsStopped()); 489 EXPECT_TRUE(decoder_->IsStopped());
476 EXPECT_TRUE(decoder_->IsCompleted()); 490 EXPECT_TRUE(decoder_->IsCompleted());
477 491
(...skipping 18 matching lines...) Expand all
496 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, 510 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched,
497 base::Unretained(this), true)); 511 base::Unretained(this), true));
498 512
499 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, 513 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched,
500 base::Unretained(this)))); 514 base::Unretained(this))));
501 515
502 decoder_->SetDemuxerConfigs(GetConfigs()); 516 decoder_->SetDemuxerConfigs(GetConfigs());
503 517
504 SetVideoSurface(); 518 SetVideoSurface();
505 519
506 EXPECT_EQ(MediaCodecDecoder::CONFIG_OK, decoder_->Configure()); 520 EXPECT_EQ(MediaCodecDecoder::kConfigOk, decoder_->Configure());
507 521
508 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); 522 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0)));
509 523
510 EXPECT_TRUE(WaitForCondition( 524 EXPECT_TRUE(WaitForCondition(
511 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)), 525 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)),
512 timeout)); 526 timeout));
513 527
514 EXPECT_TRUE(decoder_->IsStopped()); 528 EXPECT_TRUE(decoder_->IsStopped());
515 EXPECT_TRUE(decoder_->IsCompleted()); 529 EXPECT_TRUE(decoder_->IsCompleted());
516 530
(...skipping 16 matching lines...) Expand all
533 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, 547 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched,
534 base::Unretained(this), true)); 548 base::Unretained(this), true));
535 549
536 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, 550 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched,
537 base::Unretained(this)))); 551 base::Unretained(this))));
538 552
539 decoder_->SetDemuxerConfigs(GetConfigs()); 553 decoder_->SetDemuxerConfigs(GetConfigs());
540 554
541 SetVideoSurface(); 555 SetVideoSurface();
542 556
543 EXPECT_EQ(MediaCodecDecoder::CONFIG_OK, decoder_->Configure()); 557 EXPECT_EQ(MediaCodecDecoder::kConfigOk, decoder_->Configure());
544 558
545 SetStopRequestAtTime(stop_request_time); 559 SetStopRequestAtTime(stop_request_time);
546 560
547 // Start from the beginning. 561 // Start from the beginning.
548 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); 562 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0)));
549 563
550 EXPECT_TRUE(WaitForCondition( 564 EXPECT_TRUE(WaitForCondition(
551 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)), 565 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)),
552 timeout)); 566 timeout));
553 567
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 // Prefetch. 615 // Prefetch.
602 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, 616 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched,
603 base::Unretained(this), true)); 617 base::Unretained(this), true));
604 618
605 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, 619 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched,
606 base::Unretained(this)))); 620 base::Unretained(this))));
607 621
608 // Configure. 622 // Configure.
609 decoder_->SetDemuxerConfigs(GetConfigs()); 623 decoder_->SetDemuxerConfigs(GetConfigs());
610 624
611 EXPECT_EQ(MediaCodecDecoder::CONFIG_OK, decoder_->Configure()); 625 EXPECT_EQ(MediaCodecDecoder::kConfigOk, decoder_->Configure());
612 626
613 // Start. 627 // Start.
614 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); 628 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0)));
615 629
616 // Wait for starvation. 630 // Wait for starvation.
617 EXPECT_TRUE(WaitForCondition( 631 EXPECT_TRUE(WaitForCondition(
618 base::Bind(&MediaCodecDecoderTest::is_starved, base::Unretained(this)), 632 base::Bind(&MediaCodecDecoderTest::is_starved, base::Unretained(this)),
619 timeout)); 633 timeout));
620 634
621 EXPECT_FALSE(decoder_->IsStopped()); 635 EXPECT_FALSE(decoder_->IsStopped());
622 EXPECT_FALSE(decoder_->IsCompleted()); 636 EXPECT_FALSE(decoder_->IsCompleted());
623 637
624 EXPECT_GT(pts_stat_.num_values(), 0); 638 EXPECT_GT(pts_stat_.num_values(), 0);
625 639
626 // After starvation we should be able to stop decoder. 640 // After starvation we should be able to stop decoder.
627 decoder_->RequestToStop(); 641 decoder_->RequestToStop();
628 642
629 EXPECT_TRUE(WaitForCondition( 643 EXPECT_TRUE(WaitForCondition(
630 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)))); 644 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this))));
631 645
632 EXPECT_TRUE(decoder_->IsStopped()); 646 EXPECT_TRUE(decoder_->IsStopped());
633 EXPECT_FALSE(decoder_->IsCompleted()); 647 EXPECT_FALSE(decoder_->IsCompleted());
634 } 648 }
635 649
636 } // namespace media 650 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_codec_decoder.cc ('k') | media/base/android/media_codec_player.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698