| OLD | NEW |
| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 #endif | 67 #endif |
| 68 #if defined(ARCH_CPU_X86_FAMILY) | 68 #if defined(ARCH_CPU_X86_FAMILY) |
| 69 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" | 69 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
| 70 #include "content/common/gpu/media/vaapi_wrapper.h" | 70 #include "content/common/gpu/media/vaapi_wrapper.h" |
| 71 #endif // defined(ARCH_CPU_X86_FAMILY) | 71 #endif // defined(ARCH_CPU_X86_FAMILY) |
| 72 #else | 72 #else |
| 73 #error The VideoAccelerator tests are not supported on this platform. | 73 #error The VideoAccelerator tests are not supported on this platform. |
| 74 #endif // OS_WIN | 74 #endif // OS_WIN |
| 75 | 75 |
| 76 #if defined(USE_OZONE) | 76 #if defined(USE_OZONE) |
| 77 #include "ui/ozone/public/native_pixmap.h" |
| 77 #include "ui/ozone/public/ozone_gpu_test_helper.h" | 78 #include "ui/ozone/public/ozone_gpu_test_helper.h" |
| 78 #include "ui/ozone/public/ozone_platform.h" | 79 #include "ui/ozone/public/ozone_platform.h" |
| 80 #include "ui/ozone/public/surface_factory_ozone.h" |
| 79 #endif // defined(USE_OZONE) | 81 #endif // defined(USE_OZONE) |
| 80 | 82 |
| 81 using media::VideoDecodeAccelerator; | 83 using media::VideoDecodeAccelerator; |
| 82 | 84 |
| 83 namespace content { | 85 namespace content { |
| 84 namespace { | 86 namespace { |
| 85 | 87 |
| 86 using base::MakeTuple; | 88 using base::MakeTuple; |
| 87 | 89 |
| 88 // Values optionally filled in from flags; see main() below. | 90 // Values optionally filled in from flags; see main() below. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 118 int g_rendering_warm_up = 0; | 120 int g_rendering_warm_up = 0; |
| 119 | 121 |
| 120 // The value is set by the switch "--num_play_throughs". The video will play | 122 // The value is set by the switch "--num_play_throughs". The video will play |
| 121 // the specified number of times. In different test cases, we have different | 123 // the specified number of times. In different test cases, we have different |
| 122 // values for |num_play_throughs|. This setting will override the value. A | 124 // values for |num_play_throughs|. This setting will override the value. A |
| 123 // special value "0" means no override. | 125 // special value "0" means no override. |
| 124 int g_num_play_throughs = 0; | 126 int g_num_play_throughs = 0; |
| 125 // Fake decode | 127 // Fake decode |
| 126 int g_fake_decoder = 0; | 128 int g_fake_decoder = 0; |
| 127 | 129 |
| 130 // Test buffer import into VDA, providing buffers allocated by us, instead of |
| 131 // requesting the VDA itself to allocate buffers. |
| 132 bool g_test_import = false; |
| 133 |
| 128 // Environment to store rendering thread. | 134 // Environment to store rendering thread. |
| 129 class VideoDecodeAcceleratorTestEnvironment; | 135 class VideoDecodeAcceleratorTestEnvironment; |
| 130 VideoDecodeAcceleratorTestEnvironment* g_env; | 136 VideoDecodeAcceleratorTestEnvironment* g_env; |
| 131 | 137 |
| 132 // Magic constants for differentiating the reasons for NotifyResetDone being | 138 // Magic constants for differentiating the reasons for NotifyResetDone being |
| 133 // called. | 139 // called. |
| 134 enum ResetPoint { | 140 enum ResetPoint { |
| 135 // Reset() just after calling Decode() with a fragment containing config info. | 141 // Reset() just after calling Decode() with a fragment containing config info. |
| 136 RESET_AFTER_FIRST_CONFIG_INFO = -4, | 142 RESET_AFTER_FIRST_CONFIG_INFO = -4, |
| 137 START_OF_STREAM_RESET = -3, | 143 START_OF_STREAM_RESET = -3, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 #if defined(USE_OZONE) | 271 #if defined(USE_OZONE) |
| 266 std::unique_ptr<ui::OzoneGpuTestHelper> gpu_helper_; | 272 std::unique_ptr<ui::OzoneGpuTestHelper> gpu_helper_; |
| 267 #endif | 273 #endif |
| 268 | 274 |
| 269 DISALLOW_COPY_AND_ASSIGN(VideoDecodeAcceleratorTestEnvironment); | 275 DISALLOW_COPY_AND_ASSIGN(VideoDecodeAcceleratorTestEnvironment); |
| 270 }; | 276 }; |
| 271 | 277 |
| 272 // A helper class used to manage the lifetime of a Texture. | 278 // A helper class used to manage the lifetime of a Texture. |
| 273 class TextureRef : public base::RefCounted<TextureRef> { | 279 class TextureRef : public base::RefCounted<TextureRef> { |
| 274 public: | 280 public: |
| 275 TextureRef(uint32_t texture_id, const base::Closure& no_longer_needed_cb) | 281 TextureRef(uint32_t texture_id, |
| 276 : texture_id_(texture_id), no_longer_needed_cb_(no_longer_needed_cb) {} | 282 const scoped_refptr<ui::NativePixmap>& pixmap, |
| 283 const base::Closure& no_longer_needed_cb) |
| 284 : texture_id_(texture_id), |
| 285 pixmap_(pixmap), |
| 286 no_longer_needed_cb_(no_longer_needed_cb) {} |
| 277 | 287 |
| 278 int32_t texture_id() const { return texture_id_; } | 288 int32_t texture_id() const { return texture_id_; } |
| 289 scoped_refptr<ui::NativePixmap> pixmap() { return pixmap_; } |
| 279 | 290 |
| 280 private: | 291 private: |
| 281 friend class base::RefCounted<TextureRef>; | 292 friend class base::RefCounted<TextureRef>; |
| 282 ~TextureRef(); | 293 ~TextureRef(); |
| 283 | 294 |
| 284 uint32_t texture_id_; | 295 uint32_t texture_id_; |
| 296 scoped_refptr<ui::NativePixmap> pixmap_; |
| 285 base::Closure no_longer_needed_cb_; | 297 base::Closure no_longer_needed_cb_; |
| 286 }; | 298 }; |
| 287 | 299 |
| 288 TextureRef::~TextureRef() { | 300 TextureRef::~TextureRef() { |
| 289 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 301 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
| 290 } | 302 } |
| 291 | 303 |
| 292 // Client that can accept callbacks from a VideoDecodeAccelerator and is used by | 304 // Client that can accept callbacks from a VideoDecodeAccelerator and is used by |
| 293 // the TESTs below. | 305 // the TESTs below. |
| 294 class GLRenderingVDAClient | 306 class GLRenderingVDAClient |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } else { | 536 } else { |
| 525 if (!vda_factory_) { | 537 if (!vda_factory_) { |
| 526 vda_factory_ = GpuVideoDecodeAcceleratorFactoryImpl::Create( | 538 vda_factory_ = GpuVideoDecodeAcceleratorFactoryImpl::Create( |
| 527 base::Bind(&RenderingHelper::GetGLContext, | 539 base::Bind(&RenderingHelper::GetGLContext, |
| 528 base::Unretained(rendering_helper_)), | 540 base::Unretained(rendering_helper_)), |
| 529 base::Bind(&DoNothingReturnTrue), base::Bind(&DummyBindImage)); | 541 base::Bind(&DoNothingReturnTrue), base::Bind(&DummyBindImage)); |
| 530 LOG_ASSERT(vda_factory_); | 542 LOG_ASSERT(vda_factory_); |
| 531 } | 543 } |
| 532 | 544 |
| 533 VideoDecodeAccelerator::Config config(profile_); | 545 VideoDecodeAccelerator::Config config(profile_); |
| 546 if (g_test_import) { |
| 547 config.output_mode = |
| 548 media::VideoDecodeAccelerator::Config::OutputMode::IMPORT; |
| 549 } |
| 534 gpu::GpuPreferences gpu_preferences; | 550 gpu::GpuPreferences gpu_preferences; |
| 535 decoder_ = vda_factory_->CreateVDA(this, config, gpu_preferences); | 551 decoder_ = vda_factory_->CreateVDA(this, config, gpu_preferences); |
| 536 } | 552 } |
| 537 | 553 |
| 538 LOG_ASSERT(decoder_) << "Failed creating a VDA"; | 554 LOG_ASSERT(decoder_) << "Failed creating a VDA"; |
| 539 | 555 |
| 540 decoder_->TryToSetupDecodeOnSeparateThread( | 556 decoder_->TryToSetupDecodeOnSeparateThread( |
| 541 weak_this_, base::ThreadTaskRunnerHandle::Get()); | 557 weak_this_, base::ThreadTaskRunnerHandle::Get()); |
| 542 | 558 |
| 543 SetState(CS_DECODER_SET); | 559 SetState(CS_DECODER_SET); |
| 544 FinishInitialization(); | 560 FinishInitialization(); |
| 545 } | 561 } |
| 546 | 562 |
| 563 namespace { |
| 564 gfx::BufferFormat VideoPixelFormatToGfxBufferFormat( |
| 565 media::VideoPixelFormat pixel_format) { |
| 566 switch (pixel_format) { |
| 567 case media::VideoPixelFormat::PIXEL_FORMAT_ARGB: |
| 568 return gfx::BufferFormat::BGRA_8888; |
| 569 case media::VideoPixelFormat::PIXEL_FORMAT_XRGB: |
| 570 return gfx::BufferFormat::BGRX_8888; |
| 571 case media::VideoPixelFormat::PIXEL_FORMAT_NV12: |
| 572 return gfx::BufferFormat::YUV_420_BIPLANAR; |
| 573 default: |
| 574 LOG_ASSERT(false) << "Unknown VideoPixelFormat"; |
| 575 return gfx::BufferFormat::BGRX_8888; |
| 576 } |
| 577 } |
| 578 } |
| 579 |
| 547 void GLRenderingVDAClient::ProvidePictureBuffers( | 580 void GLRenderingVDAClient::ProvidePictureBuffers( |
| 548 uint32_t requested_num_of_buffers, | 581 uint32_t requested_num_of_buffers, |
| 549 uint32_t textures_per_buffer, | 582 uint32_t textures_per_buffer, |
| 550 const gfx::Size& dimensions, | 583 const gfx::Size& dimensions, |
| 551 uint32_t texture_target) { | 584 uint32_t texture_target) { |
| 552 if (decoder_deleted()) | 585 if (decoder_deleted()) |
| 553 return; | 586 return; |
| 554 LOG_ASSERT(textures_per_buffer == 1u); | 587 LOG_ASSERT(textures_per_buffer == 1u); |
| 555 std::vector<media::PictureBuffer> buffers; | 588 std::vector<media::PictureBuffer> buffers; |
| 556 | 589 |
| 557 requested_num_of_buffers += kExtraPictureBuffers; | 590 requested_num_of_buffers += kExtraPictureBuffers; |
| 558 | 591 |
| 559 texture_target_ = texture_target; | 592 texture_target_ = texture_target; |
| 560 for (uint32_t i = 0; i < requested_num_of_buffers; ++i) { | 593 for (uint32_t i = 0; i < requested_num_of_buffers; ++i) { |
| 561 uint32_t texture_id; | 594 uint32_t texture_id; |
| 562 base::WaitableEvent done(false, false); | 595 base::WaitableEvent done(false, false); |
| 563 rendering_helper_->CreateTexture( | 596 rendering_helper_->CreateTexture( |
| 564 texture_target_, &texture_id, dimensions, &done); | 597 texture_target_, &texture_id, dimensions, &done); |
| 565 done.Wait(); | 598 done.Wait(); |
| 566 | 599 |
| 600 scoped_refptr<ui::NativePixmap> pixmap; |
| 601 if (g_test_import) { |
| 602 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); |
| 603 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); |
| 604 media::VideoPixelFormat pixel_format = decoder_->GetOutputFormat(); |
| 605 if (pixel_format == media::PIXEL_FORMAT_UNKNOWN) |
| 606 pixel_format = media::PIXEL_FORMAT_ARGB; |
| 607 gfx::BufferFormat buffer_format = |
| 608 VideoPixelFormatToGfxBufferFormat(pixel_format); |
| 609 pixmap = |
| 610 factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, dimensions, |
| 611 buffer_format, gfx::BufferUsage::SCANOUT); |
| 612 LOG_ASSERT(pixmap); |
| 613 } |
| 614 |
| 567 int32_t picture_buffer_id = next_picture_buffer_id_++; | 615 int32_t picture_buffer_id = next_picture_buffer_id_++; |
| 568 LOG_ASSERT(active_textures_ | 616 LOG_ASSERT( |
| 569 .insert(std::make_pair( | 617 active_textures_ |
| 570 picture_buffer_id, | 618 .insert(std::make_pair( |
| 571 new TextureRef(texture_id, | 619 picture_buffer_id, |
| 572 base::Bind(&RenderingHelper::DeleteTexture, | 620 new TextureRef(texture_id, pixmap, |
| 573 base::Unretained(rendering_helper_), | 621 base::Bind(&RenderingHelper::DeleteTexture, |
| 574 texture_id)))) | 622 base::Unretained(rendering_helper_), |
| 575 .second); | 623 texture_id)))) |
| 624 .second); |
| 576 | 625 |
| 577 media::PictureBuffer::TextureIds ids; | 626 media::PictureBuffer::TextureIds ids; |
| 578 ids.push_back(texture_id); | 627 ids.push_back(texture_id); |
| 579 buffers.push_back(media::PictureBuffer(picture_buffer_id, dimensions, ids)); | 628 buffers.push_back(media::PictureBuffer(picture_buffer_id, dimensions, ids)); |
| 580 } | 629 } |
| 581 decoder_->AssignPictureBuffers(buffers); | 630 decoder_->AssignPictureBuffers(buffers); |
| 631 |
| 632 if (g_test_import) { |
| 633 for (const auto& buffer : buffers) { |
| 634 TextureRefMap::iterator texture_it = active_textures_.find(buffer.id()); |
| 635 ASSERT_NE(active_textures_.end(), texture_it); |
| 636 |
| 637 scoped_refptr<ui::NativePixmap> pixmap = texture_it->second->pixmap(); |
| 638 int duped_fd = HANDLE_EINTR(dup(pixmap->GetDmaBufFd())); |
| 639 ASSERT_NE(duped_fd, -1); |
| 640 gfx::GpuMemoryBufferHandle handle; |
| 641 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
| 642 handle.native_pixmap_handle.fd = base::FileDescriptor(duped_fd, true); |
| 643 std::vector<gfx::GpuMemoryBufferHandle> handles; |
| 644 handles.push_back(handle); |
| 645 decoder_->ImportBufferForPicture(buffer.id(), handles); |
| 646 } |
| 647 } |
| 582 } | 648 } |
| 583 | 649 |
| 584 void GLRenderingVDAClient::DismissPictureBuffer(int32_t picture_buffer_id) { | 650 void GLRenderingVDAClient::DismissPictureBuffer(int32_t picture_buffer_id) { |
| 585 LOG_ASSERT(1U == active_textures_.erase(picture_buffer_id)); | 651 LOG_ASSERT(1U == active_textures_.erase(picture_buffer_id)); |
| 586 } | 652 } |
| 587 | 653 |
| 588 void GLRenderingVDAClient::PictureReady(const media::Picture& picture) { | 654 void GLRenderingVDAClient::PictureReady(const media::Picture& picture) { |
| 589 // We shouldn't be getting pictures delivered after Reset has completed. | 655 // We shouldn't be getting pictures delivered after Reset has completed. |
| 590 LOG_ASSERT(state_ < CS_RESET); | 656 LOG_ASSERT(state_ < CS_RESET); |
| 591 | 657 |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 continue; | 1616 continue; |
| 1551 } | 1617 } |
| 1552 if (it->first == "fake_decoder") { | 1618 if (it->first == "fake_decoder") { |
| 1553 content::g_fake_decoder = 1; | 1619 content::g_fake_decoder = 1; |
| 1554 continue; | 1620 continue; |
| 1555 } | 1621 } |
| 1556 if (it->first == "v" || it->first == "vmodule") | 1622 if (it->first == "v" || it->first == "vmodule") |
| 1557 continue; | 1623 continue; |
| 1558 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") | 1624 if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless") |
| 1559 continue; | 1625 continue; |
| 1626 if (it->first == "test_import") { |
| 1627 content::g_test_import = true; |
| 1628 continue; |
| 1629 } |
| 1560 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1630 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
| 1561 } | 1631 } |
| 1562 | 1632 |
| 1563 base::ShadowingAtExitManager at_exit_manager; | 1633 base::ShadowingAtExitManager at_exit_manager; |
| 1564 #if defined(OS_WIN) || defined(USE_OZONE) | 1634 #if defined(OS_WIN) || defined(USE_OZONE) |
| 1565 // For windows the decoding thread initializes the media foundation decoder | 1635 // For windows the decoding thread initializes the media foundation decoder |
| 1566 // which uses COM. We need the thread to be a UI thread. | 1636 // which uses COM. We need the thread to be a UI thread. |
| 1567 // On Ozone, the backend initializes the event system using a UI | 1637 // On Ozone, the backend initializes the event system using a UI |
| 1568 // thread. | 1638 // thread. |
| 1569 base::MessageLoopForUI main_loop; | 1639 base::MessageLoopForUI main_loop; |
| 1570 #else | 1640 #else |
| 1571 base::MessageLoop main_loop; | 1641 base::MessageLoop main_loop; |
| 1572 #endif // OS_WIN || USE_OZONE | 1642 #endif // OS_WIN || USE_OZONE |
| 1573 | 1643 |
| 1574 #if defined(USE_OZONE) | 1644 #if defined(USE_OZONE) |
| 1575 ui::OzonePlatform::InitializeForUI(); | 1645 ui::OzonePlatform::InitializeForUI(); |
| 1576 #endif | 1646 #endif |
| 1577 | 1647 |
| 1578 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 1648 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 1579 content::VaapiWrapper::PreSandboxInitialization(); | 1649 content::VaapiWrapper::PreSandboxInitialization(); |
| 1580 #endif | 1650 #endif |
| 1581 | 1651 |
| 1582 content::g_env = | 1652 content::g_env = |
| 1583 reinterpret_cast<content::VideoDecodeAcceleratorTestEnvironment*>( | 1653 reinterpret_cast<content::VideoDecodeAcceleratorTestEnvironment*>( |
| 1584 testing::AddGlobalTestEnvironment( | 1654 testing::AddGlobalTestEnvironment( |
| 1585 new content::VideoDecodeAcceleratorTestEnvironment())); | 1655 new content::VideoDecodeAcceleratorTestEnvironment())); |
| 1586 | 1656 |
| 1587 return RUN_ALL_TESTS(); | 1657 return RUN_ALL_TESTS(); |
| 1588 } | 1658 } |
| OLD | NEW |