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

Side by Side Diff: content/common/gpu/media/video_decode_accelerator_unittest.cc

Issue 1745903002: Introduce GpuVideoDecodeAcceleratorFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // The bulk of this file is support code; sorry about that. Here's an overview 5 // The bulk of this file is support code; sorry about that. Here's an overview
6 // to hopefully help readers of this code: 6 // to hopefully help readers of this code:
7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or 7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or
8 // Win/EGL. 8 // Win/EGL.
9 // - ClientState is an enum for the state of the decode client used by the test. 9 // - ClientState is an enum for the state of the decode client used by the test.
10 // - ClientStateNotification is a barrier abstraction that allows the test code 10 // - ClientStateNotification is a barrier abstraction that allows the test code
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "base/synchronization/condition_variable.h" 43 #include "base/synchronization/condition_variable.h"
44 #include "base/synchronization/lock.h" 44 #include "base/synchronization/lock.h"
45 #include "base/synchronization/waitable_event.h" 45 #include "base/synchronization/waitable_event.h"
46 #include "base/thread_task_runner_handle.h" 46 #include "base/thread_task_runner_handle.h"
47 #include "base/threading/thread.h" 47 #include "base/threading/thread.h"
48 #include "build/build_config.h" 48 #include "build/build_config.h"
49 #include "content/common/gpu/media/fake_video_decode_accelerator.h" 49 #include "content/common/gpu/media/fake_video_decode_accelerator.h"
50 #include "content/common/gpu/media/rendering_helper.h" 50 #include "content/common/gpu/media/rendering_helper.h"
51 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" 51 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h"
52 #include "content/public/common/content_switches.h" 52 #include "content/public/common/content_switches.h"
53 #include "content/public/common/gpu_video_decode_accelerator_factory.h"
53 #include "media/filters/h264_parser.h" 54 #include "media/filters/h264_parser.h"
54 #include "testing/gtest/include/gtest/gtest.h" 55 #include "testing/gtest/include/gtest/gtest.h"
55 #include "ui/gfx/codec/png_codec.h" 56 #include "ui/gfx/codec/png_codec.h"
56 #include "ui/gl/gl_image.h" 57 #include "ui/gl/gl_image.h"
57 58
58 #if defined(OS_WIN) 59 #if defined(OS_WIN)
59 #include "base/win/windows_version.h" 60 #include "base/win/windows_version.h"
60 #include "content/common/gpu/media/dxva_video_decode_accelerator_win.h" 61 #include "content/common/gpu/media/dxva_video_decode_accelerator_win.h"
61 #elif defined(OS_CHROMEOS) 62 #elif defined(OS_CHROMEOS)
62 #if defined(USE_V4L2_CODEC) 63 #if defined(USE_V4L2_CODEC)
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 int num_queued_fragments() { return num_queued_fragments_; } 353 int num_queued_fragments() { return num_queued_fragments_; }
353 int num_decoded_frames() { return num_decoded_frames_; } 354 int num_decoded_frames() { return num_decoded_frames_; }
354 double frames_per_second(); 355 double frames_per_second();
355 // Return the median of the decode time of all decoded frames. 356 // Return the median of the decode time of all decoded frames.
356 base::TimeDelta decode_time_median(); 357 base::TimeDelta decode_time_median();
357 bool decoder_deleted() { return !decoder_.get(); } 358 bool decoder_deleted() { return !decoder_.get(); }
358 359
359 private: 360 private:
360 typedef std::map<int32_t, scoped_refptr<TextureRef>> TextureRefMap; 361 typedef std::map<int32_t, scoped_refptr<TextureRef>> TextureRefMap;
361 362
362 scoped_ptr<media::VideoDecodeAccelerator> CreateFakeVDA();
363 scoped_ptr<media::VideoDecodeAccelerator> CreateDXVAVDA();
364 scoped_ptr<media::VideoDecodeAccelerator> CreateV4L2VDA();
365 scoped_ptr<media::VideoDecodeAccelerator> CreateV4L2SliceVDA();
366 scoped_ptr<media::VideoDecodeAccelerator> CreateVaapiVDA();
367
368 void BindImage(uint32_t client_texture_id,
369 uint32_t texture_target,
370 scoped_refptr<gl::GLImage> image);
371
372 void SetState(ClientState new_state); 363 void SetState(ClientState new_state);
373 void FinishInitialization(); 364 void FinishInitialization();
374 void ReturnPicture(int32_t picture_buffer_id); 365 void ReturnPicture(int32_t picture_buffer_id);
375 366
376 // Delete the associated decoder helper. 367 // Delete the associated decoder helper.
377 void DeleteDecoder(); 368 void DeleteDecoder();
378 369
379 // Compute & return the first encoded bytes (including a start frame) to send 370 // Compute & return the first encoded bytes (including a start frame) to send
380 // to the decoder, starting at |start_pos| and returning one fragment. Skips 371 // to the decoder, starting at |start_pos| and returning one fragment. Skips
381 // to the first decodable position. 372 // to the first decodable position.
(...skipping 12 matching lines...) Expand all
394 size_t window_id_; 385 size_t window_id_;
395 RenderingHelper* rendering_helper_; 386 RenderingHelper* rendering_helper_;
396 gfx::Size frame_size_; 387 gfx::Size frame_size_;
397 std::string encoded_data_; 388 std::string encoded_data_;
398 const int num_in_flight_decodes_; 389 const int num_in_flight_decodes_;
399 int outstanding_decodes_; 390 int outstanding_decodes_;
400 size_t encoded_data_next_pos_to_decode_; 391 size_t encoded_data_next_pos_to_decode_;
401 int next_bitstream_buffer_id_; 392 int next_bitstream_buffer_id_;
402 ClientStateNotification<ClientState>* note_; 393 ClientStateNotification<ClientState>* note_;
403 scoped_ptr<VideoDecodeAccelerator> decoder_; 394 scoped_ptr<VideoDecodeAccelerator> decoder_;
404 scoped_ptr<base::WeakPtrFactory<VideoDecodeAccelerator> > 395 base::WeakPtr<VideoDecodeAccelerator> weak_vda_;
405 weak_decoder_factory_; 396 scoped_ptr<base::WeakPtrFactory<VideoDecodeAccelerator>>
397 weak_vda_ptr_factory_;
398 scoped_ptr<GpuVideoDecodeAcceleratorFactory> vda_factory_;
406 int remaining_play_throughs_; 399 int remaining_play_throughs_;
407 int reset_after_frame_num_; 400 int reset_after_frame_num_;
408 int delete_decoder_state_; 401 int delete_decoder_state_;
409 ClientState state_; 402 ClientState state_;
410 int num_skipped_fragments_; 403 int num_skipped_fragments_;
411 int num_queued_fragments_; 404 int num_queued_fragments_;
412 int num_decoded_frames_; 405 int num_decoded_frames_;
413 int num_done_bitstream_buffers_; 406 int num_done_bitstream_buffers_;
414 base::TimeTicks initialize_done_ticks_; 407 base::TimeTicks initialize_done_ticks_;
415 media::VideoCodecProfile profile_; 408 media::VideoCodecProfile profile_;
(...skipping 17 matching lines...) Expand all
433 // textures. 426 // textures.
434 TextureRefMap active_textures_; 427 TextureRefMap active_textures_;
435 428
436 // A map of the textures that are still pending in the renderer. 429 // A map of the textures that are still pending in the renderer.
437 // We check this to ensure all frames are rendered before entering the 430 // We check this to ensure all frames are rendered before entering the
438 // CS_RESET_State. 431 // CS_RESET_State.
439 TextureRefMap pending_textures_; 432 TextureRefMap pending_textures_;
440 433
441 int32_t next_picture_buffer_id_; 434 int32_t next_picture_buffer_id_;
442 435
436 base::WeakPtr<GLRenderingVDAClient> weak_this_;
437 base::WeakPtrFactory<GLRenderingVDAClient> weak_this_factory_;
438
443 DISALLOW_IMPLICIT_CONSTRUCTORS(GLRenderingVDAClient); 439 DISALLOW_IMPLICIT_CONSTRUCTORS(GLRenderingVDAClient);
444 }; 440 };
445 441
442 static bool DoNothingReturnTrue() {
443 return true;
444 }
445
446 static bool DummyBindImage(uint32_t client_texture_id,
447 uint32_t texture_target,
448 const scoped_refptr<gl::GLImage>& image) {
449 return true;
450 }
451
446 GLRenderingVDAClient::GLRenderingVDAClient( 452 GLRenderingVDAClient::GLRenderingVDAClient(
447 size_t window_id, 453 size_t window_id,
448 RenderingHelper* rendering_helper, 454 RenderingHelper* rendering_helper,
449 ClientStateNotification<ClientState>* note, 455 ClientStateNotification<ClientState>* note,
450 const std::string& encoded_data, 456 const std::string& encoded_data,
451 int num_in_flight_decodes, 457 int num_in_flight_decodes,
452 int num_play_throughs, 458 int num_play_throughs,
453 int reset_after_frame_num, 459 int reset_after_frame_num,
454 int delete_decoder_state, 460 int delete_decoder_state,
455 int frame_width, 461 int frame_width,
(...skipping 20 matching lines...) Expand all
476 num_skipped_fragments_(0), 482 num_skipped_fragments_(0),
477 num_queued_fragments_(0), 483 num_queued_fragments_(0),
478 num_decoded_frames_(0), 484 num_decoded_frames_(0),
479 num_done_bitstream_buffers_(0), 485 num_done_bitstream_buffers_(0),
480 fake_decoder_(fake_decoder), 486 fake_decoder_(fake_decoder),
481 texture_target_(0), 487 texture_target_(0),
482 suppress_rendering_(suppress_rendering), 488 suppress_rendering_(suppress_rendering),
483 delay_reuse_after_frame_num_(delay_reuse_after_frame_num), 489 delay_reuse_after_frame_num_(delay_reuse_after_frame_num),
484 decode_calls_per_second_(decode_calls_per_second), 490 decode_calls_per_second_(decode_calls_per_second),
485 render_as_thumbnails_(render_as_thumbnails), 491 render_as_thumbnails_(render_as_thumbnails),
486 next_picture_buffer_id_(1) { 492 next_picture_buffer_id_(1),
493 weak_this_factory_(this) {
487 LOG_ASSERT(num_in_flight_decodes > 0); 494 LOG_ASSERT(num_in_flight_decodes > 0);
488 LOG_ASSERT(num_play_throughs > 0); 495 LOG_ASSERT(num_play_throughs > 0);
489 // |num_in_flight_decodes_| is unsupported if |decode_calls_per_second_| > 0. 496 // |num_in_flight_decodes_| is unsupported if |decode_calls_per_second_| > 0.
490 if (decode_calls_per_second_ > 0) 497 if (decode_calls_per_second_ > 0)
491 LOG_ASSERT(1 == num_in_flight_decodes_); 498 LOG_ASSERT(1 == num_in_flight_decodes_);
492 499
493 // Default to H264 baseline if no profile provided. 500 // Default to H264 baseline if no profile provided.
494 profile_ = (profile != media::VIDEO_CODEC_PROFILE_UNKNOWN 501 profile_ = (profile != media::VIDEO_CODEC_PROFILE_UNKNOWN
495 ? profile 502 ? profile
496 : media::H264PROFILE_BASELINE); 503 : media::H264PROFILE_BASELINE);
504
505 weak_this_ = weak_this_factory_.GetWeakPtr();
497 } 506 }
498 507
499 GLRenderingVDAClient::~GLRenderingVDAClient() { 508 GLRenderingVDAClient::~GLRenderingVDAClient() {
500 DeleteDecoder(); // Clean up in case of expected error. 509 DeleteDecoder(); // Clean up in case of expected error.
501 LOG_ASSERT(decoder_deleted()); 510 LOG_ASSERT(decoder_deleted());
502 SetState(CS_DESTROYED); 511 SetState(CS_DESTROYED);
503 } 512 }
504 513
505 static bool DoNothingReturnTrue() { return true; }
506
507 scoped_ptr<media::VideoDecodeAccelerator>
508 GLRenderingVDAClient::CreateFakeVDA() {
509 scoped_ptr<media::VideoDecodeAccelerator> decoder;
510 if (fake_decoder_) {
511 decoder.reset(new FakeVideoDecodeAccelerator(
512 static_cast<gfx::GLContext*> (rendering_helper_->GetGLContextHandle()),
513 frame_size_,
514 base::Bind(&DoNothingReturnTrue)));
515 }
516 return decoder;
517 }
518
519 scoped_ptr<media::VideoDecodeAccelerator>
520 GLRenderingVDAClient::CreateDXVAVDA() {
521 scoped_ptr<media::VideoDecodeAccelerator> decoder;
522 #if defined(OS_WIN)
523 if (base::win::GetVersion() >= base::win::VERSION_WIN7)
524 decoder.reset(
525 new DXVAVideoDecodeAccelerator(
526 base::Bind(&DoNothingReturnTrue),
527 rendering_helper_->GetGLContext().get()));
528 #endif
529 return decoder;
530 }
531
532 scoped_ptr<media::VideoDecodeAccelerator>
533 GLRenderingVDAClient::CreateV4L2VDA() {
534 scoped_ptr<media::VideoDecodeAccelerator> decoder;
535 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
536 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
537 if (device.get()) {
538 base::WeakPtr<VideoDecodeAccelerator::Client> weak_client = AsWeakPtr();
539 decoder.reset(new V4L2VideoDecodeAccelerator(
540 static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()),
541 static_cast<EGLContext>(rendering_helper_->GetGLContextHandle()),
542 weak_client, base::Bind(&DoNothingReturnTrue), device,
543 base::ThreadTaskRunnerHandle::Get()));
544 }
545 #endif
546 return decoder;
547 }
548
549 scoped_ptr<media::VideoDecodeAccelerator>
550 GLRenderingVDAClient::CreateV4L2SliceVDA() {
551 scoped_ptr<media::VideoDecodeAccelerator> decoder;
552 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
553 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
554 if (device.get()) {
555 base::WeakPtr<VideoDecodeAccelerator::Client> weak_client = AsWeakPtr();
556 decoder.reset(new V4L2SliceVideoDecodeAccelerator(
557 device, static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()),
558 static_cast<EGLContext>(rendering_helper_->GetGLContextHandle()),
559 weak_client, base::Bind(&DoNothingReturnTrue),
560 base::ThreadTaskRunnerHandle::Get()));
561 }
562 #endif
563 return decoder;
564 }
565
566 scoped_ptr<media::VideoDecodeAccelerator>
567 GLRenderingVDAClient::CreateVaapiVDA() {
568 scoped_ptr<media::VideoDecodeAccelerator> decoder;
569 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
570 decoder.reset(new VaapiVideoDecodeAccelerator(
571 base::Bind(&DoNothingReturnTrue),
572 base::Bind(&GLRenderingVDAClient::BindImage, base::Unretained(this))));
573 #endif
574 return decoder;
575 }
576
577 void GLRenderingVDAClient::BindImage(uint32_t client_texture_id,
578 uint32_t texture_target,
579 scoped_refptr<gl::GLImage> image) {}
580
581 void GLRenderingVDAClient::CreateAndStartDecoder() { 514 void GLRenderingVDAClient::CreateAndStartDecoder() {
582 LOG_ASSERT(decoder_deleted()); 515 LOG_ASSERT(decoder_deleted());
583 LOG_ASSERT(!decoder_.get()); 516 LOG_ASSERT(!decoder_.get());
584 517
585 VideoDecodeAccelerator::Client* client = this; 518 if (fake_decoder_) {
519 decoder_.reset(new FakeVideoDecodeAccelerator(
520 frame_size_, base::Bind(&DoNothingReturnTrue)));
kcwu 2016/03/02 09:00:12 decoder_->Initialize()
Pawel Osciak 2016/03/02 10:16:49 Done.
521 } else {
522 if (!vda_factory_) {
523 vda_factory_ = GpuVideoDecodeAcceleratorFactory::Create(
524 base::Bind(&RenderingHelper::GetGLContext,
525 base::Unretained(rendering_helper_)),
526 base::Bind(&DoNothingReturnTrue), base::Bind(&DummyBindImage));
527 LOG_ASSERT(vda_factory_);
528 }
586 529
587 scoped_ptr<media::VideoDecodeAccelerator> decoders[] = { 530 VideoDecodeAccelerator::Config config(profile_);
588 CreateFakeVDA(), 531 decoder_ = vda_factory_->CreateVDA(this, config);
589 CreateDXVAVDA(), 532 }
590 CreateV4L2VDA(),
591 CreateV4L2SliceVDA(),
592 CreateVaapiVDA(),
593 };
594 533
595 for (size_t i = 0; i < arraysize(decoders); ++i) { 534 LOG_ASSERT(decoder_) << "Failed creating a VDA";
596 if (!decoders[i]) 535
597 continue; 536 decoder_->TryInitializeDecodeOnSeparateThread(
598 decoder_ = std::move(decoders[i]); 537 weak_this_, base::ThreadTaskRunnerHandle::Get());
599 weak_decoder_factory_.reset( 538
600 new base::WeakPtrFactory<VideoDecodeAccelerator>(decoder_.get())); 539 SetState(CS_DECODER_SET);
601 if (decoder_->Initialize(profile_, client)) { 540 FinishInitialization();
602 SetState(CS_DECODER_SET);
603 FinishInitialization();
604 return;
605 }
606 }
607 // Decoders are all initialize failed.
608 LOG(ERROR) << "VideoDecodeAccelerator::Initialize() failed";
609 LOG_ASSERT(false);
610 } 541 }
611 542
612 void GLRenderingVDAClient::ProvidePictureBuffers( 543 void GLRenderingVDAClient::ProvidePictureBuffers(
613 uint32_t requested_num_of_buffers, 544 uint32_t requested_num_of_buffers,
614 const gfx::Size& dimensions, 545 const gfx::Size& dimensions,
615 uint32_t texture_target) { 546 uint32_t texture_target) {
616 if (decoder_deleted()) 547 if (decoder_deleted())
617 return; 548 return;
618 std::vector<media::PictureBuffer> buffers; 549 std::vector<media::PictureBuffer> buffers;
619 550
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 LOG_ASSERT(1U == pending_textures_.erase(picture_buffer_id)); 634 LOG_ASSERT(1U == pending_textures_.erase(picture_buffer_id));
704 635
705 if (pending_textures_.empty() && state_ == CS_RESETTING) { 636 if (pending_textures_.empty() && state_ == CS_RESETTING) {
706 SetState(CS_RESET); 637 SetState(CS_RESET);
707 DeleteDecoder(); 638 DeleteDecoder();
708 return; 639 return;
709 } 640 }
710 641
711 if (num_decoded_frames_ > delay_reuse_after_frame_num_) { 642 if (num_decoded_frames_ > delay_reuse_after_frame_num_) {
712 base::MessageLoop::current()->PostDelayedTask( 643 base::MessageLoop::current()->PostDelayedTask(
713 FROM_HERE, 644 FROM_HERE, base::Bind(&VideoDecodeAccelerator::ReusePictureBuffer,
714 base::Bind(&VideoDecodeAccelerator::ReusePictureBuffer, 645 weak_vda_, picture_buffer_id),
715 weak_decoder_factory_->GetWeakPtr(),
716 picture_buffer_id),
717 kReuseDelay); 646 kReuseDelay);
718 } else { 647 } else {
719 decoder_->ReusePictureBuffer(picture_buffer_id); 648 decoder_->ReusePictureBuffer(picture_buffer_id);
720 } 649 }
721 } 650 }
722 651
723 void GLRenderingVDAClient::NotifyEndOfBitstreamBuffer( 652 void GLRenderingVDAClient::NotifyEndOfBitstreamBuffer(
724 int32_t bitstream_buffer_id) { 653 int32_t bitstream_buffer_id) {
725 // TODO(fischman): this test currently relies on this notification to make 654 // TODO(fischman): this test currently relies on this notification to make
726 // forward progress during a Reset(). But the VDA::Reset() API doesn't 655 // forward progress during a Reset(). But the VDA::Reset() API doesn't
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 } 757 }
829 758
830 for (int i = 0; i < num_in_flight_decodes_; ++i) 759 for (int i = 0; i < num_in_flight_decodes_; ++i)
831 DecodeNextFragment(); 760 DecodeNextFragment();
832 DCHECK_EQ(outstanding_decodes_, num_in_flight_decodes_); 761 DCHECK_EQ(outstanding_decodes_, num_in_flight_decodes_);
833 } 762 }
834 763
835 void GLRenderingVDAClient::DeleteDecoder() { 764 void GLRenderingVDAClient::DeleteDecoder() {
836 if (decoder_deleted()) 765 if (decoder_deleted())
837 return; 766 return;
838 weak_decoder_factory_.reset(); 767 weak_vda_ptr_factory_.reset();
839 decoder_.reset(); 768 decoder_.reset();
840 STLClearObject(&encoded_data_); 769 STLClearObject(&encoded_data_);
841 active_textures_.clear(); 770 active_textures_.clear();
842 771
843 // Cascade through the rest of the states to simplify test code below. 772 // Cascade through the rest of the states to simplify test code below.
844 for (int i = state_ + 1; i < CS_MAX; ++i) 773 for (int i = state_ + 1; i < CS_MAX; ++i)
845 SetState(static_cast<ClientState>(i)); 774 SetState(static_cast<ClientState>(i));
846 } 775 }
847 776
848 std::string GLRenderingVDAClient::GetBytesForFirstFragment( 777 std::string GLRenderingVDAClient::GetBytesForFirstFragment(
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 content::VaapiWrapper::PreSandboxInitialization(); 1572 content::VaapiWrapper::PreSandboxInitialization();
1644 #endif 1573 #endif
1645 1574
1646 content::g_env = 1575 content::g_env =
1647 reinterpret_cast<content::VideoDecodeAcceleratorTestEnvironment*>( 1576 reinterpret_cast<content::VideoDecodeAcceleratorTestEnvironment*>(
1648 testing::AddGlobalTestEnvironment( 1577 testing::AddGlobalTestEnvironment(
1649 new content::VideoDecodeAcceleratorTestEnvironment())); 1578 new content::VideoDecodeAcceleratorTestEnvironment()));
1650 1579
1651 return RUN_ALL_TESTS(); 1580 return RUN_ALL_TESTS();
1652 } 1581 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698