diff options
Diffstat (limited to 'chromium/media/gpu')
428 files changed, 2532 insertions, 1421 deletions
diff --git a/chromium/media/gpu/BUILD.gn b/chromium/media/gpu/BUILD.gn index 622adc0cdc6..0ee3b898918 100644 --- a/chromium/media/gpu/BUILD.gn +++ b/chromium/media/gpu/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. +# Copyright 2016 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -56,6 +56,7 @@ component("gpu") { "//media/gpu/vaapi/*", "//media/mojo/*", "//remoting/codec:encoder", + "//third_party/blink/renderer/modules:unit_tests", # TODO(crbug.com/1184041): Remove //remoting/host:common when the usage is removed. "//remoting/host:common", diff --git a/chromium/media/gpu/OWNERS b/chromium/media/gpu/OWNERS index 07a34f0d708..2530348a614 100644 --- a/chromium/media/gpu/OWNERS +++ b/chromium/media/gpu/OWNERS @@ -10,4 +10,3 @@ hiroh@chromium.org jcliang@chromium.org jkardatzke@chromium.org mcasas@chromium.org -posciak@chromium.org diff --git a/chromium/media/gpu/accelerated_video_decoder.h b/chromium/media/gpu/accelerated_video_decoder.h index 5cf9e48d09c..97b2a302925 100644 --- a/chromium/media/gpu/accelerated_video_decoder.h +++ b/chromium/media/gpu/accelerated_video_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/android_video_encode_accelerator.cc b/chromium/media/gpu/android/android_video_encode_accelerator.cc index 7a1890b67ba..44058854472 100644 --- a/chromium/media/gpu/android/android_video_encode_accelerator.cc +++ b/chromium/media/gpu/android/android_video_encode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/android_video_encode_accelerator.h b/chromium/media/gpu/android/android_video_encode_accelerator.h index e4166931641..c9ed49068d2 100644 --- a/chromium/media/gpu/android/android_video_encode_accelerator.h +++ b/chromium/media/gpu/android/android_video_encode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/android_video_surface_chooser.cc b/chromium/media/gpu/android/android_video_surface_chooser.cc index dc038a884aa..c5f4a3d0e82 100644 --- a/chromium/media/gpu/android/android_video_surface_chooser.cc +++ b/chromium/media/gpu/android/android_video_surface_chooser.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/android_video_surface_chooser.h b/chromium/media/gpu/android/android_video_surface_chooser.h index 0d108a16f40..acae9bf56e7 100644 --- a/chromium/media/gpu/android/android_video_surface_chooser.h +++ b/chromium/media/gpu/android/android_video_surface_chooser.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/android_video_surface_chooser_impl.cc b/chromium/media/gpu/android/android_video_surface_chooser_impl.cc index 110fad5bbc5..02e67c13881 100644 --- a/chromium/media/gpu/android/android_video_surface_chooser_impl.cc +++ b/chromium/media/gpu/android/android_video_surface_chooser_impl.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/android_video_surface_chooser_impl.h b/chromium/media/gpu/android/android_video_surface_chooser_impl.h index ab66ff01a82..0086bc0205e 100644 --- a/chromium/media/gpu/android/android_video_surface_chooser_impl.h +++ b/chromium/media/gpu/android/android_video_surface_chooser_impl.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/android_video_surface_chooser_impl_unittest.cc b/chromium/media/gpu/android/android_video_surface_chooser_impl_unittest.cc index 47d814a3d42..c479aaf3527 100644 --- a/chromium/media/gpu/android/android_video_surface_chooser_impl_unittest.cc +++ b/chromium/media/gpu/android/android_video_surface_chooser_impl_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_allocator.cc b/chromium/media/gpu/android/codec_allocator.cc index 1b2afd194b8..07d4477859d 100644 --- a/chromium/media/gpu/android/codec_allocator.cc +++ b/chromium/media/gpu/android/codec_allocator.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,12 +6,12 @@ #include <stddef.h> -#include <algorithm> #include <memory> #include "base/callback_helpers.h" #include "base/logging.h" #include "base/no_destructor.h" +#include "base/ranges/algorithm.h" #include "base/task/task_runner_util.h" #include "base/task/task_traits.h" #include "base/task/thread_pool.h" @@ -215,8 +215,8 @@ base::SequencedTaskRunner* CodecAllocator::SelectCodecTaskRunner() { void CodecAllocator::CompletePendingOperation(base::TimeTicks start_time) { // Note: This intentionally only erases the first instance, since there may be // multiple instances of the same value. - pending_operations_.erase(std::find(pending_operations_.begin(), - pending_operations_.end(), start_time)); + pending_operations_.erase( + base::ranges::find(pending_operations_, start_time)); } } // namespace media diff --git a/chromium/media/gpu/android/codec_allocator.h b/chromium/media/gpu/android/codec_allocator.h index 1043198ca45..be14c88e6ba 100644 --- a/chromium/media/gpu/android/codec_allocator.h +++ b/chromium/media/gpu/android/codec_allocator.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_allocator_unittest.cc b/chromium/media/gpu/android/codec_allocator_unittest.cc index 12db243408b..60285e80e06 100644 --- a/chromium/media/gpu/android/codec_allocator_unittest.cc +++ b/chromium/media/gpu/android/codec_allocator_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_buffer_wait_coordinator.cc b/chromium/media/gpu/android/codec_buffer_wait_coordinator.cc index 5a497a9d758..458bbc2356c 100644 --- a/chromium/media/gpu/android/codec_buffer_wait_coordinator.cc +++ b/chromium/media/gpu/android/codec_buffer_wait_coordinator.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_buffer_wait_coordinator.h b/chromium/media/gpu/android/codec_buffer_wait_coordinator.h index 8c621a990d1..c45890c1fe7 100644 --- a/chromium/media/gpu/android/codec_buffer_wait_coordinator.h +++ b/chromium/media/gpu/android/codec_buffer_wait_coordinator.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_image.cc b/chromium/media/gpu/android/codec_image.cc index 7bb06e065cc..bf8d3d73cd5 100644 --- a/chromium/media/gpu/android/codec_image.cc +++ b/chromium/media/gpu/android/codec_image.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +10,7 @@ #include "base/android/scoped_hardware_buffer_fence_sync.h" #include "base/callback_helpers.h" +#include "base/debug/dump_without_crashing.h" #include "gpu/command_buffer/service/gles2_cmd_decoder.h" #include "gpu/command_buffer/service/texture_manager.h" #include "gpu/config/gpu_finch_features.h" @@ -117,6 +118,18 @@ bool CodecImage::CopyTexImage(unsigned target) { return false; } + // Our hypothesis is that in actuality the rendering to the front buffer and + // binding of the image, if possible, have always already occurred by the time + // that this method is called. The below DumpWithoutCrashing() call serves to + // verify whether this hypothesis is correct. See crbug.com/1310020 for + // details. + // TODO(crbug.com/1310020): Remove this code as part of removing this entire + // function once we have verified that it is indeed no longer needed. + if (!output_buffer_renderer_ + ->render_to_front_buffer_will_be_noop_for_debugging()) { + base::debug::DumpWithoutCrashing(); + } + // On some devices GL_TEXTURE_BINDING_EXTERNAL_OES is not supported as // glGetIntegerv() parameter. In this case the value of |texture_id| will be // zero and we assume that it is properly bound to TextureOwner's texture id. @@ -259,10 +272,6 @@ CodecImage::GetAHardwareBuffer() { return output_buffer_renderer_->texture_owner()->GetAHardwareBuffer(); } -bool CodecImage::HasMutableState() const { - return false; -} - CodecImageHolder::CodecImageHolder( scoped_refptr<base::SequencedTaskRunner> task_runner, scoped_refptr<CodecImage> codec_image, diff --git a/chromium/media/gpu/android/codec_image.h b/chromium/media/gpu/android/codec_image.h index e8a70fc51ab..39888744888 100644 --- a/chromium/media/gpu/android/codec_image.h +++ b/chromium/media/gpu/android/codec_image.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -86,12 +86,6 @@ class MEDIA_GPU_EXPORT CodecImage std::unique_ptr<base::android::ScopedHardwareBufferFenceSync> GetAHardwareBuffer() override; - // If we re-use one CodecImage with different output buffers, then we must - // not claim to have mutable state. Otherwise, CopyTexImage is only called - // once. For pooled shared images, this must return false. For single-use - // images, it works either way. - bool HasMutableState() const override; - // Notify us that we're no longer in-use for display, and may be pointed at // another output buffer via a call to Initialize. void NotifyUnused(); diff --git a/chromium/media/gpu/android/codec_image_group.cc b/chromium/media/gpu/android/codec_image_group.cc index 24b3916928f..d1ad681870c 100644 --- a/chromium/media/gpu/android/codec_image_group.cc +++ b/chromium/media/gpu/android/codec_image_group.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_image_group.h b/chromium/media/gpu/android/codec_image_group.h index 942b5dd7265..43c437c6fff 100644 --- a/chromium/media/gpu/android/codec_image_group.h +++ b/chromium/media/gpu/android/codec_image_group.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_image_group_unittest.cc b/chromium/media/gpu/android/codec_image_group_unittest.cc index f711af31559..a08abc4f2eb 100644 --- a/chromium/media/gpu/android/codec_image_group_unittest.cc +++ b/chromium/media/gpu/android/codec_image_group_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_image_unittest.cc b/chromium/media/gpu/android/codec_image_unittest.cc index e80a5039647..ab0ca2ecc32 100644 --- a/chromium/media/gpu/android/codec_image_unittest.cc +++ b/chromium/media/gpu/android/codec_image_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_output_buffer_renderer.cc b/chromium/media/gpu/android/codec_output_buffer_renderer.cc index a588df80a0f..c9030a5fb06 100644 --- a/chromium/media/gpu/android/codec_output_buffer_renderer.cc +++ b/chromium/media/gpu/android/codec_output_buffer_renderer.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_output_buffer_renderer.h b/chromium/media/gpu/android/codec_output_buffer_renderer.h index b2e24d379d9..439f2811e6b 100644 --- a/chromium/media/gpu/android/codec_output_buffer_renderer.h +++ b/chromium/media/gpu/android/codec_output_buffer_renderer.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -69,6 +69,16 @@ class MEDIA_GPU_EXPORT CodecOutputBufferRenderer return phase_ == Phase::kInFrontBuffer; } + // Whether a call to RenderTextureOwnerFrontBuffer() will be a no-op. Present + // for debugging whether there are cases in which CodecImage::CopyTexImage() + // results in actual rendering happening. + // TODO(crbug.com/1310020): Remove this method once that issue is resolved. + bool render_to_front_buffer_will_be_noop_for_debugging() const { + AssertAcquiredDrDcLock(); + return was_rendered_to_front_buffer() || !codec_buffer_wait_coordinator_ || + phase_ == Phase::kInvalidated; + } + gfx::Size size() const { return output_buffer_->size(); } // Color space of the image. diff --git a/chromium/media/gpu/android/codec_surface_bundle.cc b/chromium/media/gpu/android/codec_surface_bundle.cc index c1a4049dc3b..3d8c8d2e7e1 100644 --- a/chromium/media/gpu/android/codec_surface_bundle.cc +++ b/chromium/media/gpu/android/codec_surface_bundle.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_surface_bundle.h b/chromium/media/gpu/android/codec_surface_bundle.h index fd017cdca8c..4a390a2e9e5 100644 --- a/chromium/media/gpu/android/codec_surface_bundle.h +++ b/chromium/media/gpu/android/codec_surface_bundle.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_wrapper.cc b/chromium/media/gpu/android/codec_wrapper.cc index 85ffc4c457c..9d10297c92b 100644 --- a/chromium/media/gpu/android/codec_wrapper.cc +++ b/chromium/media/gpu/android/codec_wrapper.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_wrapper.h b/chromium/media/gpu/android/codec_wrapper.h index 0637d85291a..a14025c0191 100644 --- a/chromium/media/gpu/android/codec_wrapper.h +++ b/chromium/media/gpu/android/codec_wrapper.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/codec_wrapper_unittest.cc b/chromium/media/gpu/android/codec_wrapper_unittest.cc index 7fc605625eb..74392c22468 100644 --- a/chromium/media/gpu/android/codec_wrapper_unittest.cc +++ b/chromium/media/gpu/android/codec_wrapper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/device_info.cc b/chromium/media/gpu/android/device_info.cc index cea21938e93..d45a26ed58c 100644 --- a/chromium/media/gpu/android/device_info.cc +++ b/chromium/media/gpu/android/device_info.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/device_info.h b/chromium/media/gpu/android/device_info.h index 54f53fe80a3..773c609f172 100644 --- a/chromium/media/gpu/android/device_info.h +++ b/chromium/media/gpu/android/device_info.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/direct_shared_image_video_provider.cc b/chromium/media/gpu/android/direct_shared_image_video_provider.cc index bbb4287be62..dc445d33d01 100644 --- a/chromium/media/gpu/android/direct_shared_image_video_provider.cc +++ b/chromium/media/gpu/android/direct_shared_image_video_provider.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,7 +13,6 @@ #include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_macros.h" #include "base/task/single_thread_task_runner.h" -#include "base/task/task_runner_util.h" #include "gpu/command_buffer/service/abstract_texture.h" #include "gpu/command_buffer/service/mailbox_manager.h" #include "gpu/command_buffer/service/shared_image/android_video_image_backing.h" @@ -219,13 +218,12 @@ bool GpuSharedImageVideoFactory::CreateImageInternal( kPremul_SkAlphaType, std::move(image), std::move(shared_context), std::move(drdc_lock)); - // Register it with shared image mailbox as well as legacy mailbox. This - // keeps |shared_image| around until its destruction cb is called. - // NOTE: Currently none of the video mailbox consumer uses shared image - // mailbox. + // Register it with shared image mailbox. This keeps |shared_image| around + // until its destruction cb is called. NOTE: Currently none of the video + // mailbox consumer uses shared image mailbox. DCHECK(stub_->channel()->gpu_channel_manager()->shared_image_manager()); stub_->channel()->shared_image_stub()->factory()->RegisterBacking( - std::move(shared_image), /*allow_legacy_mailbox=*/false); + std::move(shared_image)); return true; } diff --git a/chromium/media/gpu/android/direct_shared_image_video_provider.h b/chromium/media/gpu/android/direct_shared_image_video_provider.h index 5c6676345a3..faee971c193 100644 --- a/chromium/media/gpu/android/direct_shared_image_video_provider.h +++ b/chromium/media/gpu/android/direct_shared_image_video_provider.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/fake_codec_allocator.cc b/chromium/media/gpu/android/fake_codec_allocator.cc index 612dfc04a62..c62baef0171 100644 --- a/chromium/media/gpu/android/fake_codec_allocator.cc +++ b/chromium/media/gpu/android/fake_codec_allocator.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/fake_codec_allocator.h b/chromium/media/gpu/android/fake_codec_allocator.h index da1c58ea6cd..b68866aa3cb 100644 --- a/chromium/media/gpu/android/fake_codec_allocator.h +++ b/chromium/media/gpu/android/fake_codec_allocator.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/frame_info_helper.cc b/chromium/media/gpu/android/frame_info_helper.cc index 95b9c26df3f..13aebe5c6df 100644 --- a/chromium/media/gpu/android/frame_info_helper.cc +++ b/chromium/media/gpu/android/frame_info_helper.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/frame_info_helper.h b/chromium/media/gpu/android/frame_info_helper.h index f338ce24e84..3473fd79ffd 100644 --- a/chromium/media/gpu/android/frame_info_helper.h +++ b/chromium/media/gpu/android/frame_info_helper.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/frame_info_helper_unittest.cc b/chromium/media/gpu/android/frame_info_helper_unittest.cc index 00d530d18fd..8cac2582e62 100644 --- a/chromium/media/gpu/android/frame_info_helper_unittest.cc +++ b/chromium/media/gpu/android/frame_info_helper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/maybe_render_early_manager.cc b/chromium/media/gpu/android/maybe_render_early_manager.cc index 85a4c103b96..a522325472c 100644 --- a/chromium/media/gpu/android/maybe_render_early_manager.cc +++ b/chromium/media/gpu/android/maybe_render_early_manager.cc @@ -1,11 +1,10 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "media/gpu/android/maybe_render_early_manager.h" -#include <algorithm> - +#include "base/containers/contains.h" #include "base/containers/cxx20_erase.h" #include "base/memory/weak_ptr.h" #include "base/threading/sequence_bound.h" @@ -35,8 +34,7 @@ class GpuMaybeRenderEarlyImpl { codec_image_holder->codec_image_raw()->AddUnusedCB(base::BindOnce( &GpuMaybeRenderEarlyImpl::OnImageUnused, weak_factory_.GetWeakPtr())); - DCHECK(std::find(images_.begin(), images_.end(), - codec_image_holder->codec_image_raw()) == images_.end()); + DCHECK(!base::Contains(images_, codec_image_holder->codec_image_raw())); images_.push_back(codec_image_holder->codec_image_raw()); // Add |image| to our current image group. This makes sure that any overlay @@ -53,7 +51,7 @@ class GpuMaybeRenderEarlyImpl { private: void OnImageUnused(CodecImage* image) { // |image| is no longer used, so try to render a new image speculatively. - DCHECK(std::find(images_.begin(), images_.end(), image) != images_.end()); + DCHECK(base::Contains(images_, image)); // Remember that |image_group_| might not be the same one that |image| // belongs to. base::Erase(images_, image); diff --git a/chromium/media/gpu/android/maybe_render_early_manager.h b/chromium/media/gpu/android/maybe_render_early_manager.h index ddded864534..046cd551c92 100644 --- a/chromium/media/gpu/android/maybe_render_early_manager.h +++ b/chromium/media/gpu/android/maybe_render_early_manager.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/maybe_render_early_manager_unittest.cc b/chromium/media/gpu/android/maybe_render_early_manager_unittest.cc index 66df21a11f0..066c3adeabf 100644 --- a/chromium/media/gpu/android/maybe_render_early_manager_unittest.cc +++ b/chromium/media/gpu/android/maybe_render_early_manager_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/media_codec_video_decoder.cc b/chromium/media/gpu/android/media_codec_video_decoder.cc index 94215b3ede7..8813b14b8ff 100644 --- a/chromium/media/gpu/android/media_codec_video_decoder.cc +++ b/chromium/media/gpu/android/media_codec_video_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -141,17 +141,25 @@ std::vector<SupportedVideoDecoderConfig> GetSupportedConfigsInternal( } if (device_info->IsAv1DecoderAvailable()) { - // Technically we should check which profiles are supported, but since we - // don't have an AV1 SW decoder, just allow them all. See notes below for - // H264 profiles on the reasons why. - supported_configs.emplace_back(AV1PROFILE_MIN, AV1PROFILE_MAX, - gfx::Size(0, 0), gfx::Size(3840, 2160), - true, // allow_encrypted - false); // require_encrypted - supported_configs.emplace_back(AV1PROFILE_MIN, AV1PROFILE_MAX, - gfx::Size(0, 0), gfx::Size(2160, 3840), - true, // allow_encrypted - false); // require_encrypted + if (device_info->IsDecoderKnownUnaccelerated(VideoCodec::kAV1)) { + supported_configs.emplace_back(AV1PROFILE_MIN, AV1PROFILE_MAX, + gfx::Size(0, 0), gfx::Size(3840, 2160), + true, // allow_encrypted + true); // require_encrypted + supported_configs.emplace_back(AV1PROFILE_MIN, AV1PROFILE_MAX, + gfx::Size(0, 0), gfx::Size(2160, 3840), + true, // allow_encrypted + true); // require_encrypted + } else { + supported_configs.emplace_back(AV1PROFILE_MIN, AV1PROFILE_MAX, + gfx::Size(0, 0), gfx::Size(3840, 2160), + true, // allow_encrypted + false); // require_encrypted + supported_configs.emplace_back(AV1PROFILE_MIN, AV1PROFILE_MAX, + gfx::Size(0, 0), gfx::Size(2160, 3840), + true, // allow_encrypted + false); // require_encrypted + } } #if BUILDFLAG(USE_PROPRIETARY_CODECS) diff --git a/chromium/media/gpu/android/media_codec_video_decoder.h b/chromium/media/gpu/android/media_codec_video_decoder.h index c8277943fce..16563ead1cd 100644 --- a/chromium/media/gpu/android/media_codec_video_decoder.h +++ b/chromium/media/gpu/android/media_codec_video_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/media_codec_video_decoder_unittest.cc b/chromium/media/gpu/android/media_codec_video_decoder_unittest.cc index dc96001eaf5..64b01068d0d 100644 --- a/chromium/media/gpu/android/media_codec_video_decoder_unittest.cc +++ b/chromium/media/gpu/android/media_codec_video_decoder_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mediacodec.sigs b/chromium/media/gpu/android/mediacodec.sigs index 6dea818af67..3ecae57e3be 100644 --- a/chromium/media/gpu/android/mediacodec.sigs +++ b/chromium/media/gpu/android/mediacodec.sigs @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_android_video_surface_chooser.cc b/chromium/media/gpu/android/mock_android_video_surface_chooser.cc index f490acf8834..2b25b4eac2e 100644 --- a/chromium/media/gpu/android/mock_android_video_surface_chooser.cc +++ b/chromium/media/gpu/android/mock_android_video_surface_chooser.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_android_video_surface_chooser.h b/chromium/media/gpu/android/mock_android_video_surface_chooser.h index 33c4b41c162..ac36c021487 100644 --- a/chromium/media/gpu/android/mock_android_video_surface_chooser.h +++ b/chromium/media/gpu/android/mock_android_video_surface_chooser.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_codec_buffer_wait_coordinator.cc b/chromium/media/gpu/android/mock_codec_buffer_wait_coordinator.cc index c3ab80eb1b9..8f687beb3d1 100644 --- a/chromium/media/gpu/android/mock_codec_buffer_wait_coordinator.cc +++ b/chromium/media/gpu/android/mock_codec_buffer_wait_coordinator.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_codec_buffer_wait_coordinator.h b/chromium/media/gpu/android/mock_codec_buffer_wait_coordinator.h index 08f69bbda13..48415172b30 100644 --- a/chromium/media/gpu/android/mock_codec_buffer_wait_coordinator.h +++ b/chromium/media/gpu/android/mock_codec_buffer_wait_coordinator.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,7 +31,7 @@ class MockCodecBufferWaitCoordinator : public CodecBufferWaitCoordinator { bool expecting_frame_available; protected: - ~MockCodecBufferWaitCoordinator(); + ~MockCodecBufferWaitCoordinator() override; }; } // namespace media diff --git a/chromium/media/gpu/android/mock_codec_image.cc b/chromium/media/gpu/android/mock_codec_image.cc index d36005e9812..0674b0cf0d6 100644 --- a/chromium/media/gpu/android/mock_codec_image.cc +++ b/chromium/media/gpu/android/mock_codec_image.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_codec_image.h b/chromium/media/gpu/android/mock_codec_image.h index 632dc53a682..4ab1a09b2c5 100644 --- a/chromium/media/gpu/android/mock_codec_image.h +++ b/chromium/media/gpu/android/mock_codec_image.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_device_info.cc b/chromium/media/gpu/android/mock_device_info.cc index 14a668e64a4..aa9ef423242 100644 --- a/chromium/media/gpu/android/mock_device_info.cc +++ b/chromium/media/gpu/android/mock_device_info.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_device_info.h b/chromium/media/gpu/android/mock_device_info.h index b6632f7b3b1..8a0cfd24867 100644 --- a/chromium/media/gpu/android/mock_device_info.h +++ b/chromium/media/gpu/android/mock_device_info.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_promotion_hint_aggregator.cc b/chromium/media/gpu/android/mock_promotion_hint_aggregator.cc index c97c9344bfa..4e630349103 100644 --- a/chromium/media/gpu/android/mock_promotion_hint_aggregator.cc +++ b/chromium/media/gpu/android/mock_promotion_hint_aggregator.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_promotion_hint_aggregator.h b/chromium/media/gpu/android/mock_promotion_hint_aggregator.h index 7470d929035..f8e27051de1 100644 --- a/chromium/media/gpu/android/mock_promotion_hint_aggregator.h +++ b/chromium/media/gpu/android/mock_promotion_hint_aggregator.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_shared_image_video_provider.cc b/chromium/media/gpu/android/mock_shared_image_video_provider.cc index ecde0e54d2a..84b1c6ecf97 100644 --- a/chromium/media/gpu/android/mock_shared_image_video_provider.cc +++ b/chromium/media/gpu/android/mock_shared_image_video_provider.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/mock_shared_image_video_provider.h b/chromium/media/gpu/android/mock_shared_image_video_provider.h index 4412dc95185..c64ae030e9c 100644 --- a/chromium/media/gpu/android/mock_shared_image_video_provider.h +++ b/chromium/media/gpu/android/mock_shared_image_video_provider.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,9 +16,9 @@ namespace media { class MockSharedImageVideoProvider : public SharedImageVideoProvider { public: MockSharedImageVideoProvider(); - ~MockSharedImageVideoProvider(); + ~MockSharedImageVideoProvider() override; - void Initialize(GpuInitCB gpu_init_cb) { + void Initialize(GpuInitCB gpu_init_cb) override { Initialize_(gpu_init_cb); gpu_init_cb_ = std::move(gpu_init_cb); } diff --git a/chromium/media/gpu/android/ndk_constants.cc b/chromium/media/gpu/android/ndk_constants.cc index 7e833eed5b8..b754667acb3 100644 --- a/chromium/media/gpu/android/ndk_constants.cc +++ b/chromium/media/gpu/android/ndk_constants.cc @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/ndk_video_encode_accelerator.cc b/chromium/media/gpu/android/ndk_video_encode_accelerator.cc index e8f192207ce..478cc88fd6a 100644 --- a/chromium/media/gpu/android/ndk_video_encode_accelerator.cc +++ b/chromium/media/gpu/android/ndk_video_encode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -90,8 +90,9 @@ MediaFormatPtr CreateVideoFormat(const std::string& mime, return result; } -const base::Feature kAndroidNdkVideoEncoder{"AndroidNdkVideoEncoder", - base::FEATURE_ENABLED_BY_DEFAULT}; +BASE_FEATURE(kAndroidNdkVideoEncoder, + "AndroidNdkVideoEncoder", + base::FEATURE_ENABLED_BY_DEFAULT); static bool InitMediaCodec() { // We need at least Android P for AMediaCodec_getInputFormat(), but in diff --git a/chromium/media/gpu/android/ndk_video_encode_accelerator.h b/chromium/media/gpu/android/ndk_video_encode_accelerator.h index de5bda1a610..151988023fb 100644 --- a/chromium/media/gpu/android/ndk_video_encode_accelerator.h +++ b/chromium/media/gpu/android/ndk_video_encode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/ndk_video_encode_accelerator_tests.cc b/chromium/media/gpu/android/ndk_video_encode_accelerator_tests.cc index 3e714755753..5d694e785ba 100644 --- a/chromium/media/gpu/android/ndk_video_encode_accelerator_tests.cc +++ b/chromium/media/gpu/android/ndk_video_encode_accelerator_tests.cc @@ -1,14 +1,15 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <algorithm> #include <map> #include <vector> #include "base/android/build_info.h" +#include "base/containers/contains.h" #include "base/logging.h" #include "base/memory/ptr_util.h" +#include "base/ranges/algorithm.h" #include "base/run_loop.h" #include "base/test/task_environment.h" #include "media/base/bitstream_buffer.h" @@ -47,11 +48,8 @@ class NdkVideoEncoderAcceleratorTest pixel_format_ = args.pixel_format; auto profiles = MakeNdkAccelerator()->GetSupportedProfiles(); - bool codec_supported = - std::any_of(profiles.begin(), profiles.end(), - [this](VideoEncodeAccelerator::SupportedProfile p) { - return p.profile == profile_; - }); + bool codec_supported = base::Contains( + profiles, profile_, &VideoEncodeAccelerator::SupportedProfile::profile); if (!codec_supported) { GTEST_SKIP() << "Device doesn't have hw encoder for: " @@ -116,17 +114,19 @@ class NdkVideoEncoderAcceleratorTest auto y = color & 0xFF; auto u = (color >> 8) & 0xFF; auto v = (color >> 16) & 0xFF; - libyuv::I420Rect( - frame->data(VideoFrame::kYPlane), frame->stride(VideoFrame::kYPlane), - frame->data(VideoFrame::kUPlane), frame->stride(VideoFrame::kUPlane), - frame->data(VideoFrame::kVPlane), frame->stride(VideoFrame::kVPlane), - 0, // left - 0, // top - frame->visible_rect().width(), // right - frame->visible_rect().height(), // bottom - y, // Y color - u, // U color - v); // V color + libyuv::I420Rect(frame->writable_data(VideoFrame::kYPlane), + frame->stride(VideoFrame::kYPlane), + frame->writable_data(VideoFrame::kUPlane), + frame->stride(VideoFrame::kUPlane), + frame->writable_data(VideoFrame::kVPlane), + frame->stride(VideoFrame::kVPlane), + 0, // left + 0, // top + frame->visible_rect().width(), // right + frame->visible_rect().height(), // bottom + y, // Y color + u, // U color + v); // V color return frame; } @@ -147,7 +147,7 @@ class NdkVideoEncoderAcceleratorTest auto frame = VideoFrame::CreateFrame(PIXEL_FORMAT_XRGB, size, gfx::Rect(size), size, timestamp); - libyuv::ARGBRect(frame->data(VideoFrame::kARGBPlane), + libyuv::ARGBRect(frame->writable_data(VideoFrame::kARGBPlane), frame->stride(VideoFrame::kARGBPlane), 0, // left 0, // top @@ -291,7 +291,7 @@ TEST_P(NdkVideoEncoderAcceleratorTest, EncodeSeveralFrames) { EXPECT_GT(output.md.payload_size_bytes, 0u); auto span = mapping.GetMemoryAsSpan<uint8_t>(); bool found_not_zero = - std::any_of(span.begin(), span.end(), [](uint8_t x) { return x != 0; }); + base::ranges::any_of(span, [](uint8_t x) { return x != 0; }); EXPECT_TRUE(found_not_zero); } } diff --git a/chromium/media/gpu/android/pooled_shared_image_video_provider.cc b/chromium/media/gpu/android/pooled_shared_image_video_provider.cc index 07f08c8e2eb..1d97773d5d2 100644 --- a/chromium/media/gpu/android/pooled_shared_image_video_provider.cc +++ b/chromium/media/gpu/android/pooled_shared_image_video_provider.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/pooled_shared_image_video_provider.h b/chromium/media/gpu/android/pooled_shared_image_video_provider.h index 24204631018..f940484b72a 100644 --- a/chromium/media/gpu/android/pooled_shared_image_video_provider.h +++ b/chromium/media/gpu/android/pooled_shared_image_video_provider.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/pooled_shared_image_video_provider_unittest.cc b/chromium/media/gpu/android/pooled_shared_image_video_provider_unittest.cc index 9641a1123de..6228728fae0 100644 --- a/chromium/media/gpu/android/pooled_shared_image_video_provider_unittest.cc +++ b/chromium/media/gpu/android/pooled_shared_image_video_provider_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/promotion_hint_aggregator.h b/chromium/media/gpu/android/promotion_hint_aggregator.h index eca6f51bbb3..5ba33c64e7c 100644 --- a/chromium/media/gpu/android/promotion_hint_aggregator.h +++ b/chromium/media/gpu/android/promotion_hint_aggregator.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/promotion_hint_aggregator_impl.cc b/chromium/media/gpu/android/promotion_hint_aggregator_impl.cc index 2e9c0d8d17f..8b4bbbc97f0 100644 --- a/chromium/media/gpu/android/promotion_hint_aggregator_impl.cc +++ b/chromium/media/gpu/android/promotion_hint_aggregator_impl.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/promotion_hint_aggregator_impl.h b/chromium/media/gpu/android/promotion_hint_aggregator_impl.h index 99ffe2a79f7..4a859a4ca6a 100644 --- a/chromium/media/gpu/android/promotion_hint_aggregator_impl.h +++ b/chromium/media/gpu/android/promotion_hint_aggregator_impl.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/promotion_hint_aggregator_impl_unittest.cc b/chromium/media/gpu/android/promotion_hint_aggregator_impl_unittest.cc index 048ddc7b158..fb9d956eaac 100644 --- a/chromium/media/gpu/android/promotion_hint_aggregator_impl_unittest.cc +++ b/chromium/media/gpu/android/promotion_hint_aggregator_impl_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/shared_image_video_provider.cc b/chromium/media/gpu/android/shared_image_video_provider.cc index 49ef289a384..410495d815e 100644 --- a/chromium/media/gpu/android/shared_image_video_provider.cc +++ b/chromium/media/gpu/android/shared_image_video_provider.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/shared_image_video_provider.h b/chromium/media/gpu/android/shared_image_video_provider.h index c12b851def7..ccbbd6fa3fe 100644 --- a/chromium/media/gpu/android/shared_image_video_provider.h +++ b/chromium/media/gpu/android/shared_image_video_provider.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/surface_chooser_helper.cc b/chromium/media/gpu/android/surface_chooser_helper.cc index 9aa4c12b8fc..2a3d92f9712 100644 --- a/chromium/media/gpu/android/surface_chooser_helper.cc +++ b/chromium/media/gpu/android/surface_chooser_helper.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/surface_chooser_helper.h b/chromium/media/gpu/android/surface_chooser_helper.h index 0fb39f727b0..3003056222c 100644 --- a/chromium/media/gpu/android/surface_chooser_helper.h +++ b/chromium/media/gpu/android/surface_chooser_helper.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/surface_chooser_helper_unittest.cc b/chromium/media/gpu/android/surface_chooser_helper_unittest.cc index 0b02b27bfe6..7eacffd4bb8 100644 --- a/chromium/media/gpu/android/surface_chooser_helper_unittest.cc +++ b/chromium/media/gpu/android/surface_chooser_helper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/texture_pool_unittest.cc b/chromium/media/gpu/android/texture_pool_unittest.cc index 299af558dfe..be55c36d973 100644 --- a/chromium/media/gpu/android/texture_pool_unittest.cc +++ b/chromium/media/gpu/android/texture_pool_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/video_frame_factory.h b/chromium/media/gpu/android/video_frame_factory.h index 1e60affdf95..0b72923c880 100644 --- a/chromium/media/gpu/android/video_frame_factory.h +++ b/chromium/media/gpu/android/video_frame_factory.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/video_frame_factory_impl.cc b/chromium/media/gpu/android/video_frame_factory_impl.cc index f03da5443c4..b5345a1ba57 100644 --- a/chromium/media/gpu/android/video_frame_factory_impl.cc +++ b/chromium/media/gpu/android/video_frame_factory_impl.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,7 +14,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/task/single_thread_task_runner.h" -#include "base/task/task_runner_util.h" #include "base/trace_event/trace_event.h" #include "gpu/command_buffer/service/abstract_texture.h" #include "gpu/command_buffer/service/shared_context_state.h" diff --git a/chromium/media/gpu/android/video_frame_factory_impl.h b/chromium/media/gpu/android/video_frame_factory_impl.h index 42109782db7..8a16485d906 100644 --- a/chromium/media/gpu/android/video_frame_factory_impl.h +++ b/chromium/media/gpu/android/video_frame_factory_impl.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/android/video_frame_factory_impl_unittest.cc b/chromium/media/gpu/android/video_frame_factory_impl_unittest.cc index 47ef2f65e0c..9365112d7db 100644 --- a/chromium/media/gpu/android/video_frame_factory_impl_unittest.cc +++ b/chromium/media/gpu/android/video_frame_factory_impl_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/args.gni b/chromium/media/gpu/args.gni index da3ea5a5dc9..813657af180 100644 --- a/chromium/media/gpu/args.gni +++ b/chromium/media/gpu/args.gni @@ -1,4 +1,4 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. +# Copyright 2016 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -18,7 +18,8 @@ declare_args() { # Indicates if Video4Linux2 codec is used. This is used for all CrOS # platforms which have v4l2 hardware encoder / decoder. - use_v4l2_codec = false + use_v4l2_codec = + is_chromeos_lacros && (target_cpu == "arm" || target_cpu == "arm64") # Indicates if Video4Linux2 AML encoder is used. This is used for AML # platforms which have v4l2 hardware encoder diff --git a/chromium/media/gpu/av1_decoder.cc b/chromium/media/gpu/av1_decoder.cc index 761759e90ce..31322bd36b1 100644 --- a/chromium/media/gpu/av1_decoder.cc +++ b/chromium/media/gpu/av1_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/av1_decoder.h b/chromium/media/gpu/av1_decoder.h index 5598f49d668..ff32d4236d6 100644 --- a/chromium/media/gpu/av1_decoder.h +++ b/chromium/media/gpu/av1_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,6 +14,7 @@ #include "media/base/video_color_space.h" #include "media/base/video_types.h" #include "media/gpu/accelerated_video_decoder.h" +#include "media/gpu/av1_picture.h" #include "media/gpu/media_gpu_export.h" #include "third_party/libgav1/src/src/utils/constants.h" @@ -32,7 +33,6 @@ class Vector; } // namespace libgav1 namespace media { -class AV1Picture; using AV1ReferenceFrameVector = std::array<scoped_refptr<AV1Picture>, libgav1::kNumReferenceFrameTypes>; diff --git a/chromium/media/gpu/av1_decoder_fuzzertest.cc b/chromium/media/gpu/av1_decoder_fuzzertest.cc index 6b98e508660..4c1600e8b68 100644 --- a/chromium/media/gpu/av1_decoder_fuzzertest.cc +++ b/chromium/media/gpu/av1_decoder_fuzzertest.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/av1_decoder_unittest.cc b/chromium/media/gpu/av1_decoder_unittest.cc index 862669080fd..4327a04654b 100644 --- a/chromium/media/gpu/av1_decoder_unittest.cc +++ b/chromium/media/gpu/av1_decoder_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,6 +13,7 @@ #include "base/logging.h" #include "base/memory/raw_ptr.h" #include "base/numerics/safe_conversions.h" +#include "base/ranges/algorithm.h" #include "base/stl_util.h" #include "media/base/decoder_buffer.h" #include "media/base/test_data_util.h" @@ -715,11 +716,11 @@ TEST_F(AV1DecoderTest, InconsistentReferenceFrameState) { // And to be consistent, all the reference frames tracked by the AV1Decoder // should also be valid and they should be pointing to the only AV1Picture // so far. - EXPECT_TRUE( - std::all_of(internal_ref_frames.begin(), internal_ref_frames.end(), - [&av1_picture](const scoped_refptr<AV1Picture>& ref_frame) { - return ref_frame.get() == av1_picture.get(); - })); + EXPECT_TRUE(base::ranges::all_of( + internal_ref_frames, + [&av1_picture](const scoped_refptr<AV1Picture>& ref_frame) { + return ref_frame.get() == av1_picture.get(); + })); testing::Mock::VerifyAndClearExpectations(mock_accelerator_); } diff --git a/chromium/media/gpu/av1_picture.cc b/chromium/media/gpu/av1_picture.cc index 393f1072d51..1e1c027a549 100644 --- a/chromium/media/gpu/av1_picture.cc +++ b/chromium/media/gpu/av1_picture.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/av1_picture.h b/chromium/media/gpu/av1_picture.h index d770f9f3f37..2d01d6288f0 100644 --- a/chromium/media/gpu/av1_picture.h +++ b/chromium/media/gpu/av1_picture.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +10,7 @@ #include "third_party/libgav1/src/src/utils/types.h" namespace media { + // AV1Picture carries the parsed frame header needed for decoding an AV1 frame. // It also owns the decoded frame itself. class MEDIA_GPU_EXPORT AV1Picture : public CodecPicture { diff --git a/chromium/media/gpu/buffer_validation.cc b/chromium/media/gpu/buffer_validation.cc index 66499f0b3e0..94e2f4b4717 100644 --- a/chromium/media/gpu/buffer_validation.cc +++ b/chromium/media/gpu/buffer_validation.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/buffer_validation.h b/chromium/media/gpu/buffer_validation.h index a63526d9676..2ddc301693b 100644 --- a/chromium/media/gpu/buffer_validation.h +++ b/chromium/media/gpu/buffer_validation.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/buffer_validation_unittest.cc b/chromium/media/gpu/buffer_validation_unittest.cc index 1e3144d87b0..eadda4e1077 100644 --- a/chromium/media/gpu/buffer_validation_unittest.cc +++ b/chromium/media/gpu/buffer_validation_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/BUILD.gn b/chromium/media/gpu/chromeos/BUILD.gn index 455435bbad9..2b1f70c225b 100644 --- a/chromium/media/gpu/chromeos/BUILD.gn +++ b/chromium/media/gpu/chromeos/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2019 The Chromium Authors. All rights reserved. +# Copyright 2019 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/chromeos_status.h b/chromium/media/gpu/chromeos/chromeos_status.h index 8b5d7d90965..015c502ca51 100644 --- a/chromium/media/gpu/chromeos/chromeos_status.h +++ b/chromium/media/gpu/chromeos/chromeos_status.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/decoder_buffer_transcryptor.cc b/chromium/media/gpu/chromeos/decoder_buffer_transcryptor.cc index e3cd31df09c..238785fbb21 100644 --- a/chromium/media/gpu/chromeos/decoder_buffer_transcryptor.cc +++ b/chromium/media/gpu/chromeos/decoder_buffer_transcryptor.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/decoder_buffer_transcryptor.h b/chromium/media/gpu/chromeos/decoder_buffer_transcryptor.h index f5c157b3cdb..f604f6323a2 100644 --- a/chromium/media/gpu/chromeos/decoder_buffer_transcryptor.h +++ b/chromium/media/gpu/chromeos/decoder_buffer_transcryptor.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/dmabuf_video_frame_pool.cc b/chromium/media/gpu/chromeos/dmabuf_video_frame_pool.cc index 3091f90f8c6..1a4bc69e523 100644 --- a/chromium/media/gpu/chromeos/dmabuf_video_frame_pool.cc +++ b/chromium/media/gpu/chromeos/dmabuf_video_frame_pool.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/dmabuf_video_frame_pool.h b/chromium/media/gpu/chromeos/dmabuf_video_frame_pool.h index 74b0b79e770..51c236bf1b9 100644 --- a/chromium/media/gpu/chromeos/dmabuf_video_frame_pool.h +++ b/chromium/media/gpu/chromeos/dmabuf_video_frame_pool.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/fourcc.cc b/chromium/media/gpu/chromeos/fourcc.cc index dced21fc507..3f3c3338768 100644 --- a/chromium/media/gpu/chromeos/fourcc.cc +++ b/chromium/media/gpu/chromeos/fourcc.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/fourcc.h b/chromium/media/gpu/chromeos/fourcc.h index c4b233ac645..8919591641e 100644 --- a/chromium/media/gpu/chromeos/fourcc.h +++ b/chromium/media/gpu/chromeos/fourcc.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/fourcc_unittests.cc b/chromium/media/gpu/chromeos/fourcc_unittests.cc index 90854296db8..96947ebb824 100644 --- a/chromium/media/gpu/chromeos/fourcc_unittests.cc +++ b/chromium/media/gpu/chromeos/fourcc_unittests.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/generic_dmabuf_video_frame_mapper.cc b/chromium/media/gpu/chromeos/generic_dmabuf_video_frame_mapper.cc index 0993f923bc7..1883444f68b 100644 --- a/chromium/media/gpu/chromeos/generic_dmabuf_video_frame_mapper.cc +++ b/chromium/media/gpu/chromeos/generic_dmabuf_video_frame_mapper.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,11 +6,11 @@ #include <sys/mman.h> -#include <algorithm> #include <utility> #include <vector> #include "base/bind.h" +#include "base/containers/contains.h" #include "base/memory/ptr_util.h" #include "media/gpu/macros.h" @@ -83,8 +83,7 @@ bool IsFormatSupported(VideoPixelFormat format) { // Compressed format. PIXEL_FORMAT_MJPEG, }; - return std::find(std::cbegin(supported_formats), std::cend(supported_formats), - format) != std::cend(supported_formats); + return base::Contains(supported_formats, format); } } // namespace diff --git a/chromium/media/gpu/chromeos/generic_dmabuf_video_frame_mapper.h b/chromium/media/gpu/chromeos/generic_dmabuf_video_frame_mapper.h index 0ab5b4b4fa1..cc62781a69d 100644 --- a/chromium/media/gpu/chromeos/generic_dmabuf_video_frame_mapper.h +++ b/chromium/media/gpu/chromeos/generic_dmabuf_video_frame_mapper.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/gl_image_processor_backend.cc b/chromium/media/gpu/chromeos/gl_image_processor_backend.cc index bfc68162a06..6fc4958d90f 100644 --- a/chromium/media/gpu/chromeos/gl_image_processor_backend.cc +++ b/chromium/media/gpu/chromeos/gl_image_processor_backend.cc @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -262,7 +262,8 @@ bool GLImageProcessorBackend::InitializeTask() { // Create a shader program to convert an MM21 buffer into an NV12 buffer. GLuint program = glCreateProgram(); constexpr GLchar kVertexShader[] = - "#version 300 es\n" + "#version 320 es\n" + "#extension GL_ARM_internal : enable\n" "out vec2 texPos;\n" "void main() {\n" " vec2 pos[4];\n" @@ -292,43 +293,49 @@ bool GLImageProcessorBackend::InitializeTask() { // detiled coordinates. In practice, this second sample pass usually hits the // GPU's cache, so this doesn't influence DRAM bandwidth too negatively. constexpr GLchar kFragmentShader[] = - R"(#version 300 es + R"(#version 320 es #extension GL_EXT_YUV_target : require - precision highp float; - precision highp int; + #extension GL_ARM_internal : enable + #pragma disable_alpha_to_coverage + precision mediump float; + precision mediump int; uniform __samplerExternal2DY2YEXT tex; - const ivec2 kYTileDims = ivec2(16, 32); - const ivec2 kUVTileDims = ivec2(8, 16); - uniform int width; - uniform int height; + const uvec2 kYTileDims = uvec2(16, 32); + const uvec2 kUVTileDims = uvec2(8, 16); + uniform uint width; + uniform uint height; in vec2 texPos; layout(yuv) out vec4 fragColor; void main() { - int col = int(round(texPos.x*float(width))); - int row = int(round(texPos.y*float(height))); - ivec2 iCoord = ivec2(col, row); - ivec2 tileCoords = iCoord / kYTileDims; - int numTilesPerRow = width / kYTileDims.x; - int tileIdx = (tileCoords.y * numTilesPerRow) + tileCoords.x; - ivec2 inTileCoord = iCoord % kYTileDims; - int offsetInTile = (inTileCoord.y * kYTileDims.x) + inTileCoord.x; - int linearIndex = tileIdx * kYTileDims.x * kYTileDims.y + offsetInTile; - int detiledY = linearIndex / width; - int detiledX = linearIndex % width; + uvec2 iCoord = uvec2(gl_FragPositionARM.xy); + uvec2 tileCoords = iCoord / kYTileDims; + uint numTilesPerRow = width / kYTileDims.x; + uint tileIdx = (tileCoords.y * numTilesPerRow) + tileCoords.x; + uvec2 inTileCoord = iCoord % kYTileDims; + uint offsetInTile = (inTileCoord.y * kYTileDims.x) + inTileCoord.x; + highp uint linearIndex = tileIdx; + linearIndex = linearIndex * kYTileDims.x; + linearIndex = linearIndex * kYTileDims.y; + linearIndex = linearIndex + offsetInTile; + uint detiledY = linearIndex / width; + uint detiledX = linearIndex % width; fragColor = vec4(0, 0, 0, 1); fragColor.r = texelFetch(tex, ivec2(detiledX, detiledY), 0).r; - iCoord = iCoord / 2; + iCoord = iCoord / uint(2); tileCoords = iCoord / kUVTileDims; - int uvWidth = width / 2; + uint uvWidth = width / uint(2); numTilesPerRow = uvWidth / kUVTileDims.x; tileIdx = (tileCoords.y * numTilesPerRow) + tileCoords.x; inTileCoord = iCoord % kUVTileDims; offsetInTile = (inTileCoord.y * kUVTileDims.x) + inTileCoord.x; - linearIndex = tileIdx * kUVTileDims.x * kUVTileDims.y + offsetInTile; + linearIndex = tileIdx; + linearIndex = linearIndex * kUVTileDims.x; + linearIndex = linearIndex * kUVTileDims.y; + linearIndex = linearIndex + offsetInTile; detiledY = linearIndex / uvWidth; detiledX = linearIndex % uvWidth; - detiledY = detiledY * 2; - detiledX = detiledX * 2; + detiledY = detiledY * uint(2); + detiledX = detiledX * uint(2); fragColor.gb = texelFetch(tex, ivec2(detiledX, detiledY), 0).gb; })"; if (!CreateAndAttachShader(program, GL_FRAGMENT_SHADER, kFragmentShader, @@ -359,10 +366,10 @@ bool GLImageProcessorBackend::InitializeTask() { glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glUniform1i(glGetUniformLocation(program, "tex"), 0); - glUniform1i(glGetUniformLocation(program, "width"), - ALIGN(output_visible_size.width(), kTileWidth)); - glUniform1i(glGetUniformLocation(program, "height"), - ALIGN(output_visible_size.height(), kTileHeight)); + glUniform1ui(glGetUniformLocation(program, "width"), + ALIGN(output_visible_size.width(), kTileWidth)); + glUniform1ui(glGetUniformLocation(program, "height"), + ALIGN(output_visible_size.height(), kTileHeight)); glViewport(0, 0, output_visible_size.width(), output_visible_size.height()); // This glGetError() blocks until all the commands above have executed. This diff --git a/chromium/media/gpu/chromeos/gl_image_processor_backend.h b/chromium/media/gpu/chromeos/gl_image_processor_backend.h index e5c2d38f5b1..fbd5948292f 100644 --- a/chromium/media/gpu/chromeos/gl_image_processor_backend.h +++ b/chromium/media/gpu/chromeos/gl_image_processor_backend.h @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/gpu_buffer_layout.cc b/chromium/media/gpu/chromeos/gpu_buffer_layout.cc index 578884f536b..fe34f4ca960 100644 --- a/chromium/media/gpu/chromeos/gpu_buffer_layout.cc +++ b/chromium/media/gpu/chromeos/gpu_buffer_layout.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/gpu_buffer_layout.h b/chromium/media/gpu/chromeos/gpu_buffer_layout.h index 3e415a04926..492f326b988 100644 --- a/chromium/media/gpu/chromeos/gpu_buffer_layout.h +++ b/chromium/media/gpu/chromeos/gpu_buffer_layout.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/gpu_memory_buffer_video_frame_mapper.cc b/chromium/media/gpu/chromeos/gpu_memory_buffer_video_frame_mapper.cc index fb0cb05441c..7445e5d84ef 100644 --- a/chromium/media/gpu/chromeos/gpu_memory_buffer_video_frame_mapper.cc +++ b/chromium/media/gpu/chromeos/gpu_memory_buffer_video_frame_mapper.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/gpu_memory_buffer_video_frame_mapper.h b/chromium/media/gpu/chromeos/gpu_memory_buffer_video_frame_mapper.h index 4b662444d87..6514ce8a74b 100644 --- a/chromium/media/gpu/chromeos/gpu_memory_buffer_video_frame_mapper.h +++ b/chromium/media/gpu/chromeos/gpu_memory_buffer_video_frame_mapper.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/image_processor.cc b/chromium/media/gpu/chromeos/image_processor.cc index d959d91a2ed..90731414775 100644 --- a/chromium/media/gpu/chromeos/image_processor.cc +++ b/chromium/media/gpu/chromeos/image_processor.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/image_processor.h b/chromium/media/gpu/chromeos/image_processor.h index a8f4918fb77..58ebc68fcd8 100644 --- a/chromium/media/gpu/chromeos/image_processor.h +++ b/chromium/media/gpu/chromeos/image_processor.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/image_processor_backend.cc b/chromium/media/gpu/chromeos/image_processor_backend.cc index 529ffb44abd..441de7cc631 100644 --- a/chromium/media/gpu/chromeos/image_processor_backend.cc +++ b/chromium/media/gpu/chromeos/image_processor_backend.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/image_processor_backend.h b/chromium/media/gpu/chromeos/image_processor_backend.h index 80a20be6fbf..f07f8119c1d 100644 --- a/chromium/media/gpu/chromeos/image_processor_backend.h +++ b/chromium/media/gpu/chromeos/image_processor_backend.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/image_processor_factory.cc b/chromium/media/gpu/chromeos/image_processor_factory.cc index aad3664c864..f44dd98bb90 100644 --- a/chromium/media/gpu/chromeos/image_processor_factory.cc +++ b/chromium/media/gpu/chromeos/image_processor_factory.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/image_processor_factory.h b/chromium/media/gpu/chromeos/image_processor_factory.h index 6439bcdf18f..7bcb841670b 100644 --- a/chromium/media/gpu/chromeos/image_processor_factory.h +++ b/chromium/media/gpu/chromeos/image_processor_factory.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/image_processor_test.cc b/chromium/media/gpu/chromeos/image_processor_test.cc index bbf844b886a..52e5a41ff28 100644 --- a/chromium/media/gpu/chromeos/image_processor_test.cc +++ b/chromium/media/gpu/chromeos/image_processor_test.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/image_processor_with_pool.cc b/chromium/media/gpu/chromeos/image_processor_with_pool.cc index 0550d5a3da8..b6c599eacce 100644 --- a/chromium/media/gpu/chromeos/image_processor_with_pool.cc +++ b/chromium/media/gpu/chromeos/image_processor_with_pool.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/image_processor_with_pool.h b/chromium/media/gpu/chromeos/image_processor_with_pool.h index e83de420cda..1054729576c 100644 --- a/chromium/media/gpu/chromeos/image_processor_with_pool.h +++ b/chromium/media/gpu/chromeos/image_processor_with_pool.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/libyuv_image_processor_backend.cc b/chromium/media/gpu/chromeos/libyuv_image_processor_backend.cc index 03e1e73994c..56e0eec9cef 100644 --- a/chromium/media/gpu/chromeos/libyuv_image_processor_backend.cc +++ b/chromium/media/gpu/chromeos/libyuv_image_processor_backend.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -384,6 +384,14 @@ int LibYUVImageProcessorBackend::DoConversion(const VideoFrame* const input, fr->visible_data(VideoFrame::kUPlane), fr->stride(VideoFrame::kUPlane), \ fr->visible_data(VideoFrame::kVPlane), fr->stride(VideoFrame::kVPlane) +#define Y_U_V_DATA_W(fr) \ + fr->GetWritableVisibleData(VideoFrame::kYPlane), \ + fr->stride(VideoFrame::kYPlane), \ + fr->GetWritableVisibleData(VideoFrame::kUPlane), \ + fr->stride(VideoFrame::kUPlane), \ + fr->GetWritableVisibleData(VideoFrame::kVPlane), \ + fr->stride(VideoFrame::kVPlane) + #define Y_V_U_DATA(fr) \ fr->visible_data(VideoFrame::kYPlane), fr->stride(VideoFrame::kYPlane), \ fr->visible_data(VideoFrame::kVPlane), fr->stride(VideoFrame::kVPlane), \ @@ -393,6 +401,12 @@ int LibYUVImageProcessorBackend::DoConversion(const VideoFrame* const input, fr->visible_data(VideoFrame::kYPlane), fr->stride(VideoFrame::kYPlane), \ fr->visible_data(VideoFrame::kUVPlane), fr->stride(VideoFrame::kUVPlane) +#define Y_UV_DATA_W(fr) \ + fr->GetWritableVisibleData(VideoFrame::kYPlane), \ + fr->stride(VideoFrame::kYPlane), \ + fr->GetWritableVisibleData(VideoFrame::kUVPlane), \ + fr->stride(VideoFrame::kUVPlane) + #define YUY2_DATA(fr) \ fr->visible_data(VideoFrame::kYPlane), fr->stride(VideoFrame::kYPlane) @@ -403,14 +417,26 @@ int LibYUVImageProcessorBackend::DoConversion(const VideoFrame* const input, if (output->format() == PIXEL_FORMAT_NV12) { switch (input->format()) { case PIXEL_FORMAT_I420: - return LIBYUV_FUNC(I420ToNV12, Y_U_V_DATA(input), Y_UV_DATA(output)); + return LIBYUV_FUNC(I420ToNV12, Y_U_V_DATA(input), Y_UV_DATA_W(output)); case PIXEL_FORMAT_YV12: - return LIBYUV_FUNC(I420ToNV12, Y_V_U_DATA(input), Y_UV_DATA(output)); + return LIBYUV_FUNC(I420ToNV12, Y_V_U_DATA(input), Y_UV_DATA_W(output)); case PIXEL_FORMAT_NV12: // MM21 mode. - if (input_config_.fourcc == Fourcc(Fourcc::MM21)) - return LIBYUV_FUNC(MM21ToNV12, Y_UV_DATA(input), Y_UV_DATA(output)); + if (input_config_.fourcc == Fourcc(Fourcc::MM21)) { + // The X and Y of the input rectangle seem to have a more complicated + // relationship with the channel offsets. This is what we have managed + // to figure out. (b/248991039) + const int luma_offset = + input->visible_rect().x() * (input->visible_rect().y() - 1); + const int chroma_offset = luma_offset / 2 - input->visible_rect().y(); + return libyuv::MM21ToNV12( + input->visible_data(VideoFrame::kYPlane) + luma_offset, + input->stride(VideoFrame::kYPlane), + input->visible_data(VideoFrame::kUVPlane) + chroma_offset, + input->stride(VideoFrame::kUVPlane), Y_UV_DATA_W(output), + output->visible_rect().width(), output->visible_rect().height()); + } // Rotation mode. if (relative_rotation_ != VIDEO_ROTATION_0) { @@ -420,24 +446,25 @@ int LibYUVImageProcessorBackend::DoConversion(const VideoFrame* const input, // temporary U and V planes for I420 data. Although // |intermediate_frame_->data(0)| is much larger than the required // size, we use the frame to simplify the code. - return NV12Rotate(intermediate_frame_->data(0), Y_UV_DATA(input), - Y_UV_DATA(output), input->visible_rect().width(), + return NV12Rotate(intermediate_frame_->writable_data(0), + Y_UV_DATA(input), Y_UV_DATA_W(output), + input->visible_rect().width(), input->visible_rect().height(), relative_rotation_); } // Scaling mode. return libyuv::NV12Scale( Y_UV_DATA(input), input->visible_rect().width(), - input->visible_rect().height(), Y_UV_DATA(output), + input->visible_rect().height(), Y_UV_DATA_W(output), output->visible_rect().width(), output->visible_rect().height(), libyuv::kFilterBilinear); case PIXEL_FORMAT_YUY2: if (input->visible_rect().size() == output->visible_rect().size()) { - return LIBYUV_FUNC(YUY2ToNV12, YUY2_DATA(input), Y_UV_DATA(output)); + return LIBYUV_FUNC(YUY2ToNV12, YUY2_DATA(input), Y_UV_DATA_W(output)); } else { DCHECK_EQ(intermediate_frame_->format(), PIXEL_FORMAT_NV12); int ret = libyuv::YUY2ToNV12( - YUY2_DATA(input), Y_UV_DATA(intermediate_frame_), + YUY2_DATA(input), Y_UV_DATA_W(intermediate_frame_), intermediate_frame_->visible_rect().width(), intermediate_frame_->visible_rect().height()); if (ret != 0) @@ -445,17 +472,18 @@ int LibYUVImageProcessorBackend::DoConversion(const VideoFrame* const input, return libyuv::NV12Scale( Y_UV_DATA(intermediate_frame_), intermediate_frame_->visible_rect().width(), - intermediate_frame_->visible_rect().height(), Y_UV_DATA(output), + intermediate_frame_->visible_rect().height(), Y_UV_DATA_W(output), output->visible_rect().width(), output->visible_rect().height(), libyuv::kFilterBilinear); } case PIXEL_FORMAT_I422: if (input->visible_rect().size() == output->visible_rect().size()) { - return LIBYUV_FUNC(I422ToNV21, Y_V_U_DATA(input), Y_UV_DATA(output)); + return LIBYUV_FUNC(I422ToNV21, Y_V_U_DATA(input), + Y_UV_DATA_W(output)); } else { DCHECK_EQ(intermediate_frame_->format(), PIXEL_FORMAT_NV12); int ret = libyuv::I422ToNV21( - Y_V_U_DATA(input), Y_UV_DATA(intermediate_frame_), + Y_V_U_DATA(input), Y_UV_DATA_W(intermediate_frame_), intermediate_frame_->visible_rect().width(), intermediate_frame_->visible_rect().height()); if (ret != 0) @@ -463,7 +491,7 @@ int LibYUVImageProcessorBackend::DoConversion(const VideoFrame* const input, return libyuv::NV12Scale( Y_UV_DATA(intermediate_frame_), intermediate_frame_->visible_rect().width(), - intermediate_frame_->visible_rect().height(), Y_UV_DATA(output), + intermediate_frame_->visible_rect().height(), Y_UV_DATA_W(output), output->visible_rect().width(), output->visible_rect().height(), libyuv::kFilterBilinear); } @@ -478,16 +506,17 @@ int LibYUVImageProcessorBackend::DoConversion(const VideoFrame* const input, case PIXEL_FORMAT_I420: return libyuv::I420Scale( Y_U_V_DATA(input), input->visible_rect().width(), - input->visible_rect().height(), Y_U_V_DATA(output), + input->visible_rect().height(), Y_U_V_DATA_W(output), output->visible_rect().width(), output->visible_rect().height(), libyuv::kFilterBilinear); case PIXEL_FORMAT_YUY2: if (input->visible_rect().size() == output->visible_rect().size()) { - return LIBYUV_FUNC(YUY2ToI420, YUY2_DATA(input), Y_U_V_DATA(output)); + return LIBYUV_FUNC(YUY2ToI420, YUY2_DATA(input), + Y_U_V_DATA_W(output)); } else { DCHECK_EQ(intermediate_frame_->format(), PIXEL_FORMAT_I420); int ret = libyuv::YUY2ToI420( - YUY2_DATA(input), Y_U_V_DATA(intermediate_frame_), + YUY2_DATA(input), Y_U_V_DATA_W(intermediate_frame_), intermediate_frame_->visible_rect().width(), intermediate_frame_->visible_rect().height()); if (ret != 0) @@ -495,17 +524,18 @@ int LibYUVImageProcessorBackend::DoConversion(const VideoFrame* const input, return libyuv::I420Scale( Y_U_V_DATA(intermediate_frame_), intermediate_frame_->visible_rect().width(), - intermediate_frame_->visible_rect().height(), Y_U_V_DATA(output), - output->visible_rect().width(), output->visible_rect().height(), - libyuv::kFilterBilinear); + intermediate_frame_->visible_rect().height(), + Y_U_V_DATA_W(output), output->visible_rect().width(), + output->visible_rect().height(), libyuv::kFilterBilinear); } case PIXEL_FORMAT_I422: if (input->visible_rect().size() == output->visible_rect().size()) { - return LIBYUV_FUNC(I422ToI420, Y_U_V_DATA(input), Y_U_V_DATA(output)); + return LIBYUV_FUNC(I422ToI420, Y_U_V_DATA(input), + Y_U_V_DATA_W(output)); } else { DCHECK_EQ(intermediate_frame_->format(), PIXEL_FORMAT_I420); int ret = libyuv::I422ToI420( - Y_U_V_DATA(input), Y_U_V_DATA(intermediate_frame_), + Y_U_V_DATA(input), Y_U_V_DATA_W(intermediate_frame_), intermediate_frame_->visible_rect().width(), intermediate_frame_->visible_rect().height()); if (ret != 0) @@ -513,9 +543,9 @@ int LibYUVImageProcessorBackend::DoConversion(const VideoFrame* const input, return libyuv::I420Scale( Y_U_V_DATA(intermediate_frame_), intermediate_frame_->visible_rect().width(), - intermediate_frame_->visible_rect().height(), Y_U_V_DATA(output), - output->visible_rect().width(), output->visible_rect().height(), - libyuv::kFilterBilinear); + intermediate_frame_->visible_rect().height(), + Y_U_V_DATA_W(output), output->visible_rect().width(), + output->visible_rect().height(), libyuv::kFilterBilinear); } default: VLOGF(1) << "Unexpected input format: " << input->format(); diff --git a/chromium/media/gpu/chromeos/libyuv_image_processor_backend.h b/chromium/media/gpu/chromeos/libyuv_image_processor_backend.h index df0b441126e..7a4de18f6ee 100644 --- a/chromium/media/gpu/chromeos/libyuv_image_processor_backend.h +++ b/chromium/media/gpu/chromeos/libyuv_image_processor_backend.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/mailbox_video_frame_converter.cc b/chromium/media/gpu/chromeos/mailbox_video_frame_converter.cc index 5acedfac78e..1577c1b07f9 100644 --- a/chromium/media/gpu/chromeos/mailbox_video_frame_converter.cc +++ b/chromium/media/gpu/chromeos/mailbox_video_frame_converter.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,7 +9,6 @@ #include "base/location.h" #include "base/memory/ptr_util.h" #include "base/task/single_thread_task_runner.h" -#include "base/task/task_runner_util.h" #include "base/trace_event/trace_event.h" #include "gpu/command_buffer/common/shared_image_usage.h" #include "gpu/command_buffer/service/scheduler.h" @@ -454,7 +453,7 @@ bool MailboxVideoFrameConverter::GenerateSharedImageOnGPUThread( // The allocated SharedImages should be usable for the (Display) compositor // and, potentially, for overlays (Scanout). uint32_t shared_image_usage = - gpu::SHARED_IMAGE_USAGE_DISPLAY | gpu::SHARED_IMAGE_USAGE_SCANOUT; + gpu::SHARED_IMAGE_USAGE_DISPLAY_READ | gpu::SHARED_IMAGE_USAGE_SCANOUT; if (enable_unsafe_webgpu_ && video_frame->metadata().is_webgpu_compatible) shared_image_usage |= gpu::SHARED_IMAGE_USAGE_WEBGPU; diff --git a/chromium/media/gpu/chromeos/mailbox_video_frame_converter.h b/chromium/media/gpu/chromeos/mailbox_video_frame_converter.h index 89f76c55600..39e8ad61e41 100644 --- a/chromium/media/gpu/chromeos/mailbox_video_frame_converter.h +++ b/chromium/media/gpu/chromeos/mailbox_video_frame_converter.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/mailbox_video_frame_converter_unittest.cc b/chromium/media/gpu/chromeos/mailbox_video_frame_converter_unittest.cc index d89eba95cbc..f05c73838d6 100644 --- a/chromium/media/gpu/chromeos/mailbox_video_frame_converter_unittest.cc +++ b/chromium/media/gpu/chromeos/mailbox_video_frame_converter_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/oop_video_decoder.cc b/chromium/media/gpu/chromeos/oop_video_decoder.cc index 471e077aba7..2b939e3b1e5 100644 --- a/chromium/media/gpu/chromeos/oop_video_decoder.cc +++ b/chromium/media/gpu/chromeos/oop_video_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -164,7 +164,7 @@ void OOPVideoDecoder::Initialize(const VideoDecoderConfig& config, InitCB init_cb, const OutputCB& output_cb, const WaitingCB& waiting_cb) { - VLOGF(2); + DVLOGF(2) << config.AsHumanReadableString(); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); CHECK(!init_cb_); @@ -222,7 +222,8 @@ void OOPVideoDecoder::OnInitializeDone(const DecoderStatus& status, CHECK(!has_error_); if (!status.is_ok() || - (decoder_type != VideoDecoderType::kVaapi && + (decoder_type != VideoDecoderType::kVda && + decoder_type != VideoDecoderType::kVaapi && decoder_type != VideoDecoderType::kV4L2) || (decoder_type_ != VideoDecoderType::kUnknown && decoder_type_ != decoder_type)) { @@ -235,7 +236,7 @@ void OOPVideoDecoder::OnInitializeDone(const DecoderStatus& status, void OOPVideoDecoder::Decode(scoped_refptr<DecoderBuffer> buffer, DecodeCB decode_cb) { - VLOGF(2); + DVLOGF(4); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); CHECK(!init_cb_); @@ -279,6 +280,7 @@ void OOPVideoDecoder::Decode(scoped_refptr<DecoderBuffer> buffer, void OOPVideoDecoder::OnDecodeDone(uint64_t decode_id, bool is_flushing, const DecoderStatus& status) { + DVLOGF(4); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); CHECK(!has_error_); @@ -306,7 +308,7 @@ void OOPVideoDecoder::OnDecodeDone(uint64_t decode_id, } void OOPVideoDecoder::Reset(base::OnceClosure reset_cb) { - VLOGF(2); + DVLOGF(2); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); CHECK(!init_cb_); @@ -427,7 +429,7 @@ void OOPVideoDecoder::OnVideoFrameDecoded( const scoped_refptr<VideoFrame>& frame, bool can_read_without_stalling, const base::UnguessableToken& release_token) { - VLOGF(2); + DVLOGF(4); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); CHECK(!has_error_); @@ -451,7 +453,7 @@ void OOPVideoDecoder::OnVideoFrameDecoded( } void OOPVideoDecoder::OnWaiting(WaitingReason reason) { - VLOGF(2); + DVLOGF(4); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); CHECK(!has_error_); diff --git a/chromium/media/gpu/chromeos/oop_video_decoder.h b/chromium/media/gpu/chromeos/oop_video_decoder.h index 0ca038a1766..7ec4bddd714 100644 --- a/chromium/media/gpu/chromeos/oop_video_decoder.h +++ b/chromium/media/gpu/chromeos/oop_video_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/platform_video_frame_pool.cc b/chromium/media/gpu/chromeos/platform_video_frame_pool.cc index 1f077cdaf67..882d2e5a0e0 100644 --- a/chromium/media/gpu/chromeos/platform_video_frame_pool.cc +++ b/chromium/media/gpu/chromeos/platform_video_frame_pool.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/platform_video_frame_pool.h b/chromium/media/gpu/chromeos/platform_video_frame_pool.h index e16e9e4419f..9bcfefeb13d 100644 --- a/chromium/media/gpu/chromeos/platform_video_frame_pool.h +++ b/chromium/media/gpu/chromeos/platform_video_frame_pool.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/platform_video_frame_pool_unittest.cc b/chromium/media/gpu/chromeos/platform_video_frame_pool_unittest.cc index 2428ae9465f..3452e85a838 100644 --- a/chromium/media/gpu/chromeos/platform_video_frame_pool_unittest.cc +++ b/chromium/media/gpu/chromeos/platform_video_frame_pool_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/platform_video_frame_utils.cc b/chromium/media/gpu/chromeos/platform_video_frame_utils.cc index 3b5fdac923c..602d88b801b 100644 --- a/chromium/media/gpu/chromeos/platform_video_frame_utils.cc +++ b/chromium/media/gpu/chromeos/platform_video_frame_utils.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/platform_video_frame_utils.h b/chromium/media/gpu/chromeos/platform_video_frame_utils.h index af278c8ce3d..96cd0b1c335 100644 --- a/chromium/media/gpu/chromeos/platform_video_frame_utils.h +++ b/chromium/media/gpu/chromeos/platform_video_frame_utils.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/platform_video_frame_utils_unittest.cc b/chromium/media/gpu/chromeos/platform_video_frame_utils_unittest.cc index fe3ff628261..d4c22b0c717 100644 --- a/chromium/media/gpu/chromeos/platform_video_frame_utils_unittest.cc +++ b/chromium/media/gpu/chromeos/platform_video_frame_utils_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/vd_video_decode_accelerator.cc b/chromium/media/gpu/chromeos/vd_video_decode_accelerator.cc index 804c99262ea..aec2ce99ad2 100644 --- a/chromium/media/gpu/chromeos/vd_video_decode_accelerator.cc +++ b/chromium/media/gpu/chromeos/vd_video_decode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,7 @@ #include "base/callback_helpers.h" #include "base/location.h" #include "base/memory/unsafe_shared_memory_region.h" +#include "gpu/config/gpu_driver_bug_workarounds.h" #include "gpu/ipc/common/gpu_memory_buffer_support.h" #include "media/base/format_utils.h" #include "media/base/media_util.h" @@ -241,7 +242,10 @@ bool VdVideoDecodeAccelerator::Initialize(const Config& config, if (!vd_) { std::unique_ptr<VdaVideoFramePool> frame_pool = std::make_unique<VdaVideoFramePool>(weak_this_, client_task_runner_); - vd_ = create_vd_cb_.Run(client_task_runner_, std::move(frame_pool), + // TODO(b/238684141): Wire a meaningful GpuDriverBugWorkarounds or remove + // its use. + vd_ = create_vd_cb_.Run(gpu::GpuDriverBugWorkarounds(), client_task_runner_, + std::move(frame_pool), std::make_unique<VideoFrameConverter>(), std::make_unique<NullMediaLog>(), /*oop_video_decoder=*/{}); @@ -532,13 +536,12 @@ void VdVideoDecodeAccelerator::ImportBufferForPicture( gmb_handle)); auto buffer_format = VideoPixelFormatToGfxBufferFormat(pixel_format); CHECK(buffer_format); - // Usage is SCANOUT_VDA_WRITE because we are just wrapping the dmabuf in a - // GpuMemoryBuffer. This buffer is just for decoding purposes, so having - // the dmabufs mmapped is not necessary. + // Usage is SCANOUT_CPU_READ_WRITE because we may need to map the buffer in + // order to use the LibYUVImageProcessorBackend. std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer = gpu::GpuMemoryBufferSupport().CreateGpuMemoryBufferImplFromHandle( std::move(gmb_handle), layout_->coded_size(), *buffer_format, - gfx::BufferUsage::SCANOUT_VDA_WRITE, base::NullCallback()); + gfx::BufferUsage::SCANOUT_CPU_READ_WRITE, base::NullCallback()); if (!gpu_memory_buffer) { VLOGF(1) << "Failed to create GpuMemoryBuffer. format: " << gfx::BufferFormatToString(*buffer_format) diff --git a/chromium/media/gpu/chromeos/vd_video_decode_accelerator.h b/chromium/media/gpu/chromeos/vd_video_decode_accelerator.h index 264df424276..c901c245a58 100644 --- a/chromium/media/gpu/chromeos/vd_video_decode_accelerator.h +++ b/chromium/media/gpu/chromeos/vd_video_decode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -21,6 +21,7 @@ #include "media/gpu/chromeos/dmabuf_video_frame_pool.h" #include "media/gpu/chromeos/fourcc.h" #include "media/gpu/chromeos/vda_video_frame_pool.h" +#include "media/gpu/chromeos/video_decoder_pipeline.h" #include "media/gpu/chromeos/video_frame_converter.h" #include "media/gpu/media_gpu_export.h" #include "media/mojo/mojom/stable/stable_video_decoder.mojom.h" @@ -30,7 +31,6 @@ namespace media { -class MediaLog; class VideoFrame; // Implements the VideoDecodeAccelerator backed by a VideoDecoder. @@ -49,12 +49,7 @@ class MEDIA_GPU_EXPORT VdVideoDecodeAccelerator public: // Callback for creating VideoDecoder instance. using CreateVideoDecoderCb = - base::RepeatingCallback<std::unique_ptr<VideoDecoder>( - scoped_refptr<base::SequencedTaskRunner>, - std::unique_ptr<DmabufVideoFramePool>, - std::unique_ptr<VideoFrameConverter>, - std::unique_ptr<MediaLog>, - mojo::PendingRemote<stable::mojom::StableVideoDecoder>)>; + base::RepeatingCallback<decltype(VideoDecoderPipeline::Create)>; // Create VdVideoDecodeAccelerator instance, and call Initialize(). // Return nullptr if Initialize() failed. diff --git a/chromium/media/gpu/chromeos/vda_video_frame_pool.cc b/chromium/media/gpu/chromeos/vda_video_frame_pool.cc index 3c43957b04d..be0f22e8dff 100644 --- a/chromium/media/gpu/chromeos/vda_video_frame_pool.cc +++ b/chromium/media/gpu/chromeos/vda_video_frame_pool.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/vda_video_frame_pool.h b/chromium/media/gpu/chromeos/vda_video_frame_pool.h index e23d36d705b..c2e467dc97e 100644 --- a/chromium/media/gpu/chromeos/vda_video_frame_pool.h +++ b/chromium/media/gpu/chromeos/vda_video_frame_pool.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/video_decoder_pipeline.cc b/chromium/media/gpu/chromeos/video_decoder_pipeline.cc index c491e5f5ac8..c3143c5cfe6 100644 --- a/chromium/media/gpu/chromeos/video_decoder_pipeline.cc +++ b/chromium/media/gpu/chromeos/video_decoder_pipeline.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,7 +18,6 @@ #include "base/task/thread_pool.h" #include "base/threading/thread.h" #include "build/build_config.h" -#include "gpu/config/gpu_driver_bug_workarounds.h" #include "media/base/async_destroy_video_decoder.h" #include "media/base/bind_to_current_loop.h" #include "media/base/limits.h" @@ -47,10 +46,6 @@ namespace { using PixelLayoutCandidate = ImageProcessor::PixelLayoutCandidate; -// The number of requested frames used for the image processor should be the -// number of frames in media::Pipeline plus the current processing frame. -constexpr size_t kNumFramesForImageProcessor = limits::kMaxVideoFrames + 1; - // Preferred output formats in order of preference. // TODO(mcasas): query the platform for its preferred formats and modifiers. constexpr Fourcc kPreferredRenderableFourccs[] = { @@ -185,6 +180,7 @@ bool VideoDecoderMixin::NeedsTranscryption() { // static std::unique_ptr<VideoDecoder> VideoDecoderPipeline::Create( + const gpu::GpuDriverBugWorkarounds& workarounds, scoped_refptr<base::SequencedTaskRunner> client_task_runner, std::unique_ptr<DmabufVideoFramePool> frame_pool, std::unique_ptr<VideoFrameConverter> frame_converter, @@ -199,16 +195,17 @@ std::unique_ptr<VideoDecoder> VideoDecoderPipeline::Create( create_decoder_function_cb = base::BindOnce(&OOPVideoDecoder::Create, std::move(oop_video_decoder)); } else { - create_decoder_function_cb = #if BUILDFLAG(USE_VAAPI) - base::BindOnce(&VaapiVideoDecoder::Create); -#elif BUILDFLAG(USE_V4L2_CODEC) - base::BindOnce(&V4L2VideoDecoder::Create); + create_decoder_function_cb = base::BindOnce(&VaapiVideoDecoder::Create); +#elif BUILDFLAG(USE_V4L2_CODEC) && BUILDFLAG(IS_CHROMEOS_ASH) + create_decoder_function_cb = base::BindOnce(&V4L2VideoDecoder::Create); +#else + return nullptr; #endif } auto* pipeline = new VideoDecoderPipeline( - std::move(client_task_runner), std::move(frame_pool), + workarounds, std::move(client_task_runner), std::move(frame_pool), std::move(frame_converter), std::move(media_log), std::move(create_decoder_function_cb)); return std::make_unique<AsyncDestroyVideoDecoder<VideoDecoderPipeline>>( @@ -256,12 +253,14 @@ VideoDecoderPipeline::GetSupportedConfigs( } VideoDecoderPipeline::VideoDecoderPipeline( + const gpu::GpuDriverBugWorkarounds& gpu_workarounds, scoped_refptr<base::SequencedTaskRunner> client_task_runner, std::unique_ptr<DmabufVideoFramePool> frame_pool, std::unique_ptr<VideoFrameConverter> frame_converter, std::unique_ptr<MediaLog> media_log, CreateDecoderFunctionCB create_decoder_function_cb) - : client_task_runner_(std::move(client_task_runner)), + : gpu_workarounds_(gpu_workarounds), + client_task_runner_(std::move(client_task_runner)), decoder_task_runner_(DecoderThreadPool::CreateTaskRunner()), main_frame_pool_(std::move(frame_pool)), frame_converter_(std::move(frame_converter)), @@ -333,7 +332,9 @@ int VideoDecoderPipeline::GetMaxDecodeRequests() const { DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_); // TODO(mcasas): query |decoder_| instead. - return 4; + // This value comes from the number of buffers in the input queue in + // V4L2VideoDecoder. + return 8; } bool VideoDecoderPipeline::FramesHoldExternalResources() const { @@ -388,6 +389,25 @@ void VideoDecoderPipeline::Initialize(const VideoDecoderConfig& config, } #endif // !BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA) + // Make sure that the configuration requested is supported by the driver, + // which must provide such information. + const auto supported_configs = + supported_configs_for_testing_.empty() + ? VideoDecoderPipeline::GetSupportedConfigs(gpu_workarounds_) + : supported_configs_for_testing_; + if (!supported_configs.has_value()) { + std::move(init_cb).Run(DecoderStatus::Codes::kUnsupportedConfig); + return; + } + if (!IsVideoDecoderConfigSupported(supported_configs.value(), config)) { + VLOGF(1) << "Video configuration is not supported: " + << config.AsHumanReadableString(); + MEDIA_LOG(INFO, media_log_) << "Video configuration is not supported: " + << config.AsHumanReadableString(); + std::move(init_cb).Run(DecoderStatus::Codes::kUnsupportedConfig); + return; + } + needs_bitstream_conversion_ = (config.codec() == VideoCodec::kH264) || (config.codec() == VideoCodec::kHEVC); @@ -812,12 +832,12 @@ VideoDecoderPipeline::PickDecoderOutputFormat( candidates, /*input_visible_rect=*/decoder_visible_rect, output_size ? *output_size : decoder_visible_rect.size(), - kNumFramesForImageProcessor); + num_of_pictures); } else { image_processor = ImageProcessorFactory::CreateWithInputCandidates( candidates, /*input_visible_rect=*/decoder_visible_rect, output_size ? *output_size : decoder_visible_rect.size(), - kNumFramesForImageProcessor, decoder_task_runner_, + num_of_pictures, decoder_task_runner_, base::BindRepeating(&PickRenderableFourcc), BindToCurrentLoop(base::BindRepeating(&VideoDecoderPipeline::OnError, decoder_weak_this_, @@ -858,8 +878,8 @@ VideoDecoderPipeline::PickDecoderOutputFormat( // TODO(b/203240043): Add CHECKs to verify that the image processor is being // created for only valid use cases. Writing to a linear output buffer, e.g. auto status_or_image_processor = ImageProcessorWithPool::Create( - std::move(image_processor), main_frame_pool_.get(), - kNumFramesForImageProcessor, use_protected, decoder_task_runner_); + std::move(image_processor), main_frame_pool_.get(), num_of_pictures, + use_protected, decoder_task_runner_); if (status_or_image_processor.has_error()) { DVLOGF(2) << "Unable to create ImageProcessorWithPool."; return std::move(status_or_image_processor).error(); diff --git a/chromium/media/gpu/chromeos/video_decoder_pipeline.h b/chromium/media/gpu/chromeos/video_decoder_pipeline.h index 2435f8abf21..750154095ad 100644 --- a/chromium/media/gpu/chromeos/video_decoder_pipeline.h +++ b/chromium/media/gpu/chromeos/video_decoder_pipeline.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,6 +12,7 @@ #include "base/sequence_checker.h" #include "build/build_config.h" #include "build/chromeos_buildflags.h" +#include "gpu/config/gpu_driver_bug_workarounds.h" #include "media/base/cdm_context.h" #include "media/base/supported_video_decoder_config.h" #include "media/base/video_decoder.h" @@ -34,10 +35,6 @@ namespace base { class SequencedTaskRunner; } -namespace gpu { -class GpuDriverBugWorkarounds; -} - namespace media { class DmabufVideoFramePool; @@ -142,6 +139,7 @@ class MEDIA_GPU_EXPORT VideoDecoderPipeline : public VideoDecoder, // Creates a VideoDecoderPipeline instance that allocates VideoFrames from // |frame_pool| and converts the decoded VideoFrames using |frame_converter|. static std::unique_ptr<VideoDecoder> Create( + const gpu::GpuDriverBugWorkarounds& workarounds, scoped_refptr<base::SequencedTaskRunner> client_task_runner, std::unique_ptr<DmabufVideoFramePool> frame_pool, std::unique_ptr<VideoFrameConverter> frame_converter, @@ -191,6 +189,7 @@ class MEDIA_GPU_EXPORT VideoDecoderPipeline : public VideoDecoder, #endif VideoDecoderPipeline( + const gpu::GpuDriverBugWorkarounds& workarounds, scoped_refptr<base::SequencedTaskRunner> client_task_runner, std::unique_ptr<DmabufVideoFramePool> frame_pool, std::unique_ptr<VideoFrameConverter> frame_converter, @@ -239,6 +238,11 @@ class MEDIA_GPU_EXPORT VideoDecoderPipeline : public VideoDecoder, DecodeCB decode_callback); #endif // BUILDFLAG(IS_CHROMEOS) + // Used to figure out the supported configurations in Initialize(). + const gpu::GpuDriverBugWorkarounds gpu_workarounds_; + + SupportedVideoDecoderConfigs supported_configs_for_testing_; + // The client task runner and its sequence checker. All public methods should // run on this task runner. const scoped_refptr<base::SequencedTaskRunner> client_task_runner_; diff --git a/chromium/media/gpu/chromeos/video_decoder_pipeline_unittest.cc b/chromium/media/gpu/chromeos/video_decoder_pipeline_unittest.cc index b3875cb258b..3db87ad67d5 100644 --- a/chromium/media/gpu/chromeos/video_decoder_pipeline_unittest.cc +++ b/chromium/media/gpu/chromeos/video_decoder_pipeline_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,6 +14,7 @@ #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" +#include "gpu/config/gpu_driver_bug_workarounds.h" #include "media/base/cdm_context.h" #include "media/base/media_util.h" #include "media/base/mock_filters.h" @@ -72,8 +73,6 @@ class MockVideoFramePool : public DmabufVideoFramePool { bool IsFakeVideoFramePool() override { return true; } }; -constexpr gfx::Size kCodedSize(48, 36); - class MockDecoder : public VideoDecoderMixin { public: MockDecoder() @@ -156,6 +155,16 @@ struct DecoderPipelineTestParams { DecoderStatus::Codes status_code; }; +constexpr gfx::Size kMinSupportedResolution(64, 64); +constexpr gfx::Size kMaxSupportedResolution(2048, 1088); +constexpr gfx::Size kCodedSize(128, 128); + +static_assert(kMinSupportedResolution.width() <= kCodedSize.width() && + kMinSupportedResolution.height() <= kCodedSize.height() && + kCodedSize.width() <= kMaxSupportedResolution.width() && + kCodedSize.height() <= kMaxSupportedResolution.height(), + "kCodedSize must be within the supported resolutions."); + class VideoDecoderPipelineTest : public testing::TestWithParam<DecoderPipelineTestParams> { public: @@ -174,10 +183,18 @@ class VideoDecoderPipelineTest auto pool = std::make_unique<MockVideoFramePool>(); pool_ = pool.get(); decoder_ = base::WrapUnique(new VideoDecoderPipeline( - base::ThreadTaskRunnerHandle::Get(), std::move(pool), - std::move(converter_), std::make_unique<MockMediaLog>(), + gpu::GpuDriverBugWorkarounds(), base::ThreadTaskRunnerHandle::Get(), + std::move(pool), std::move(converter_), + std::make_unique<MockMediaLog>(), // This callback needs to be configured in the individual tests. base::BindOnce(&VideoDecoderPipelineTest::CreateNullMockDecoder))); + + SetSupportedVideoDecoderConfigs({SupportedVideoDecoderConfig( + /*profile_min,=*/VP8PROFILE_ANY, + /*profile_max=*/VP8PROFILE_ANY, kMinSupportedResolution, + kMaxSupportedResolution, + /*allow_encrypted=*/true, + /*require_encrypted=*/false)}); } ~VideoDecoderPipelineTest() override = default; @@ -310,6 +327,11 @@ class VideoDecoderPipelineTest return decoder_->decoder_.get(); } + void SetSupportedVideoDecoderConfigs( + const SupportedVideoDecoderConfigs& configs) { + decoder_->supported_configs_for_testing_ = configs; + } + void DetachDecoderSequenceChecker() NO_THREAD_SAFETY_ANALYSIS { // |decoder_| will be destroyed on its |decoder_task_runner| via // DestroyAsync(). This will trip its |decoder_sequence_checker_| if it has @@ -399,6 +421,24 @@ INSTANTIATE_TEST_SUITE_P(All, VideoDecoderPipelineTest, testing::ValuesIn(kDecoderPipelineTestParams)); +// Verifies that trying to Initialize() with a non-supported config fails. +TEST_F(VideoDecoderPipelineTest, InitializeFailsDueToNotSupportedConfig) { + // Configure the supported configs to something that we know is not supported, + // e.g. making the smallest supported resolution larger than the |config_| + // we'll be requesting. + SetSupportedVideoDecoderConfigs({SupportedVideoDecoderConfig( + /*profile_min=*/config_.profile(), + /*profile_max=*/config_.profile(), + /*coded_size_min=*/config_.coded_size() + gfx::Size(1, 1), + kMaxSupportedResolution, + /*allow_encrypted=*/true, + /*require_encrypted=*/false)}); + + InitializeDecoder( + base::BindOnce(&VideoDecoderPipelineTest::CreateGoodMockDecoder), + DecoderStatus::Codes::kUnsupportedConfig); +} + // Verifies the Reset sequence. TEST_F(VideoDecoderPipelineTest, Reset) { InitializeDecoder( diff --git a/chromium/media/gpu/chromeos/video_frame_converter.cc b/chromium/media/gpu/chromeos/video_frame_converter.cc index 3482e082c8a..6f191713114 100644 --- a/chromium/media/gpu/chromeos/video_frame_converter.cc +++ b/chromium/media/gpu/chromeos/video_frame_converter.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/chromeos/video_frame_converter.h b/chromium/media/gpu/chromeos/video_frame_converter.h index bbd86818a01..5ccd2b665f3 100644 --- a/chromium/media/gpu/chromeos/video_frame_converter.h +++ b/chromium/media/gpu/chromeos/video_frame_converter.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/codec_picture.cc b/chromium/media/gpu/codec_picture.cc index e42bd5096df..db36c663a7e 100644 --- a/chromium/media/gpu/codec_picture.cc +++ b/chromium/media/gpu/codec_picture.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/codec_picture.h b/chromium/media/gpu/codec_picture.h index 285131119cc..872920992c4 100644 --- a/chromium/media/gpu/codec_picture.h +++ b/chromium/media/gpu/codec_picture.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/command_buffer_helper.cc b/chromium/media/gpu/command_buffer_helper.cc index 175adf521d4..adfe94f7f3f 100644 --- a/chromium/media/gpu/command_buffer_helper.cc +++ b/chromium/media/gpu/command_buffer_helper.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -184,19 +184,6 @@ class CommandBufferHelperImpl return decoder_helper_->CreateMailbox(textures_[service_id].get()); } - void ProduceTexture(const gpu::Mailbox& mailbox, GLuint service_id) override { - DVLOG(2) << __func__ << "(" << mailbox.ToDebugString() << ", " << service_id - << ")"; - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - - if (!decoder_helper_) - return; - - DCHECK(textures_.count(service_id)); - return decoder_helper_->ProduceTexture(mailbox, - textures_[service_id].get()); - } - void WaitForSyncToken(gpu::SyncToken sync_token, base::OnceClosure done_cb) override { DVLOG(2) << __func__; diff --git a/chromium/media/gpu/command_buffer_helper.h b/chromium/media/gpu/command_buffer_helper.h index 1b45ba3420f..43e034c32ad 100644 --- a/chromium/media/gpu/command_buffer_helper.h +++ b/chromium/media/gpu/command_buffer_helper.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -122,11 +122,6 @@ class MEDIA_GPU_EXPORT CommandBufferHelper // be to add a HasStub() method, and not define behavior when it is false. virtual gpu::Mailbox CreateMailbox(GLuint service_id) = 0; - // Produce a texture into a mailbox. The context does not have to be current. - // However, this will fail if the stub has been destroyed. - virtual void ProduceTexture(const gpu::Mailbox& mailbox, - GLuint service_id) = 0; - // Waits for a SyncToken, then runs |done_cb|. // // |done_cb| may be destructed without running if the stub is destroyed. diff --git a/chromium/media/gpu/decode_surface_handler.h b/chromium/media/gpu/decode_surface_handler.h index 76f953d4b57..9721bcf8b5b 100644 --- a/chromium/media/gpu/decode_surface_handler.h +++ b/chromium/media/gpu/decode_surface_handler.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/gles2_decoder_helper.cc b/chromium/media/gpu/gles2_decoder_helper.cc index 8d6317d5e04..0722cd80b7f 100644 --- a/chromium/media/gpu/gles2_decoder_helper.cc +++ b/chromium/media/gpu/gles2_decoder_helper.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -88,12 +88,6 @@ class GLES2DecoderHelperImpl : public GLES2DecoderHelper { return mailbox; } - void ProduceTexture(const gpu::Mailbox& mailbox, - AbstractTexture* texture) override { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - mailbox_manager_->ProduceTexture(mailbox, texture->GetTextureBase()); - } - private: raw_ptr<gpu::DecoderContext> decoder_; raw_ptr<gpu::MailboxManager> mailbox_manager_; diff --git a/chromium/media/gpu/gles2_decoder_helper.h b/chromium/media/gpu/gles2_decoder_helper.h index 0c84e31bed9..c3fe8d45dce 100644 --- a/chromium/media/gpu/gles2_decoder_helper.h +++ b/chromium/media/gpu/gles2_decoder_helper.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -61,10 +61,6 @@ class MEDIA_GPU_EXPORT GLES2DecoderHelper { // Creates a mailbox for a texture. virtual gpu::Mailbox CreateMailbox( gpu::gles2::AbstractTexture* texture_ref) = 0; - - // Produce a texture into a mailbox. - virtual void ProduceTexture(const gpu::Mailbox& mailbox, - gpu::gles2::AbstractTexture* texture_ref) = 0; }; } // namespace media diff --git a/chromium/media/gpu/gpu_video_accelerator_util.cc b/chromium/media/gpu/gpu_video_accelerator_util.cc index b6fceed7346..effec2494ce 100644 --- a/chromium/media/gpu/gpu_video_accelerator_util.cc +++ b/chromium/media/gpu/gpu_video_accelerator_util.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/gpu_video_accelerator_util.h b/chromium/media/gpu/gpu_video_accelerator_util.h index c365165f259..2af646790da 100644 --- a/chromium/media/gpu/gpu_video_accelerator_util.h +++ b/chromium/media/gpu/gpu_video_accelerator_util.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/gpu_video_decode_accelerator_factory.cc b/chromium/media/gpu/gpu_video_decode_accelerator_factory.cc index 4785d49e88b..92b9fcde813 100644 --- a/chromium/media/gpu/gpu_video_decode_accelerator_factory.cc +++ b/chromium/media/gpu/gpu_video_decode_accelerator_factory.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -27,7 +27,7 @@ #if BUILDFLAG(USE_VAAPI) #include "media/gpu/vaapi/vaapi_video_decode_accelerator.h" #include "ui/gl/gl_implementation.h" -#elif BUILDFLAG(USE_V4L2_CODEC) +#elif BUILDFLAG(USE_V4L2_CODEC) && BUILDFLAG(IS_CHROMEOS_ASH) #include "media/gpu/v4l2/v4l2_device.h" #include "media/gpu/v4l2/v4l2_slice_video_decode_accelerator.h" #include "media/gpu/v4l2/v4l2_video_decode_accelerator.h" @@ -60,7 +60,7 @@ gpu::VideoDecodeAcceleratorCapabilities GetDecoderCapabilitiesInternal( #if BUILDFLAG(USE_VAAPI) capabilities.supported_profiles = VaapiVideoDecodeAccelerator::GetSupportedProfiles(); -#elif BUILDFLAG(USE_V4L2_CODEC) +#elif BUILDFLAG(USE_V4L2_CODEC) && BUILDFLAG(IS_CHROMEOS_ASH) GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles( V4L2VideoDecodeAccelerator::GetSupportedProfiles(), &capabilities.supported_profiles); @@ -99,7 +99,7 @@ GpuVideoDecodeAcceleratorFactory::GetDecoderCapabilities( static gpu::VideoDecodeAcceleratorCapabilities capabilities = GetDecoderCapabilitiesInternal(gpu_preferences, workarounds); -#if BUILDFLAG(USE_V4L2_CODEC) +#if BUILDFLAG(USE_V4L2_CODEC) && BUILDFLAG(IS_CHROMEOS_ASH) // V4L2-only: the decoder devices may not be visible at the time the GPU // process is starting. If the capabilities vector is empty, try to query the // devices again in the hope that they will have appeared in the meantime. @@ -144,7 +144,7 @@ GpuVideoDecodeAcceleratorFactory::CreateVDA( // both. In those cases prefer the VA creation function. #if BUILDFLAG(USE_VAAPI) &GpuVideoDecodeAcceleratorFactory::CreateVaapiVDA, -#elif BUILDFLAG(USE_V4L2_CODEC) +#elif BUILDFLAG(USE_V4L2_CODEC) && BUILDFLAG(IS_CHROMEOS_ASH) &GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA, &GpuVideoDecodeAcceleratorFactory::CreateV4L2SliceVDA, #endif @@ -191,7 +191,7 @@ GpuVideoDecodeAcceleratorFactory::CreateVaapiVDA( gl_client_.bind_image)); return decoder; } -#elif BUILDFLAG(USE_V4L2_CODEC) +#elif BUILDFLAG(USE_V4L2_CODEC) && BUILDFLAG(IS_CHROMEOS_ASH) std::unique_ptr<VideoDecodeAccelerator> GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA( const gpu::GpuDriverBugWorkarounds& /*workarounds*/, diff --git a/chromium/media/gpu/gpu_video_decode_accelerator_factory.h b/chromium/media/gpu/gpu_video_decode_accelerator_factory.h index b2e1390c5f0..7f3bb5d86a6 100644 --- a/chromium/media/gpu/gpu_video_decode_accelerator_factory.h +++ b/chromium/media/gpu/gpu_video_decode_accelerator_factory.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -99,7 +99,7 @@ class MEDIA_GPU_EXPORT GpuVideoDecodeAcceleratorFactory { const gpu::GpuDriverBugWorkarounds& workarounds, const gpu::GpuPreferences& gpu_preferences, MediaLog* media_log) const; -#elif BUILDFLAG(USE_V4L2_CODEC) +#elif BUILDFLAG(USE_V4L2_CODEC) && BUILDFLAG(IS_CHROMEOS_ASH) std::unique_ptr<VideoDecodeAccelerator> CreateV4L2VDA( const gpu::GpuDriverBugWorkarounds& workarounds, const gpu::GpuPreferences& gpu_preferences, diff --git a/chromium/media/gpu/gpu_video_decode_accelerator_helpers.cc b/chromium/media/gpu/gpu_video_decode_accelerator_helpers.cc index 2de95be733c..98223ba1ee2 100644 --- a/chromium/media/gpu/gpu_video_decode_accelerator_helpers.cc +++ b/chromium/media/gpu/gpu_video_decode_accelerator_helpers.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/gpu_video_decode_accelerator_helpers.h b/chromium/media/gpu/gpu_video_decode_accelerator_helpers.h index 9cb4c981c27..ccab7912905 100644 --- a/chromium/media/gpu/gpu_video_decode_accelerator_helpers.h +++ b/chromium/media/gpu/gpu_video_decode_accelerator_helpers.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/gpu_video_encode_accelerator_factory.cc b/chromium/media/gpu/gpu_video_encode_accelerator_factory.cc index 84fc5725b5e..03dd1e84d45 100644 --- a/chromium/media/gpu/gpu_video_encode_accelerator_factory.cc +++ b/chromium/media/gpu/gpu_video_encode_accelerator_factory.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -137,8 +137,7 @@ std::vector<VEAFactoryFunction> GetVEAFactoryFunctions( VideoEncodeAccelerator::SupportedProfiles GetSupportedProfilesInternal( const gpu::GpuPreferences& gpu_preferences, const gpu::GpuDriverBugWorkarounds& gpu_workarounds, - const gpu::GPUInfo::GPUDevice& gpu_device, - bool populate_extended_info) { + const gpu::GPUInfo::GPUDevice& gpu_device) { if (gpu_preferences.disable_accelerated_video_encode) return VideoEncodeAccelerator::SupportedProfiles(); @@ -148,9 +147,7 @@ VideoEncodeAccelerator::SupportedProfiles GetSupportedProfilesInternal( auto vea = std::move(create_vea).Run(); if (!vea) continue; - auto vea_profiles = populate_extended_info - ? vea->GetSupportedProfiles() - : vea->GetSupportedProfilesLight(); + auto vea_profiles = vea->GetSupportedProfiles(); GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles(vea_profiles, &profiles); } @@ -192,22 +189,12 @@ MEDIA_GPU_EXPORT VideoEncodeAccelerator::SupportedProfiles GpuVideoEncodeAcceleratorFactory::GetSupportedProfiles( const gpu::GpuPreferences& gpu_preferences, const gpu::GpuDriverBugWorkarounds& gpu_workarounds, - const gpu::GPUInfo::GPUDevice& gpu_device, - bool populate_extended_info) { + const gpu::GPUInfo::GPUDevice& gpu_device) { // Cache the supported profiles so that they will not be computed more than // once per GPU process. It is assumed that |gpu_preferences| do not change // between calls. - VideoEncodeAccelerator::SupportedProfiles* profiles_ptr = nullptr; - if (populate_extended_info) { - static auto profiles = GetSupportedProfilesInternal( - gpu_preferences, gpu_workarounds, gpu_device, true); - profiles_ptr = &profiles; - - } else { - static auto profiles = GetSupportedProfilesInternal( - gpu_preferences, gpu_workarounds, gpu_device, false); - profiles_ptr = &profiles; - } + static auto profiles = GetSupportedProfilesInternal( + gpu_preferences, gpu_workarounds, gpu_device); #if BUILDFLAG(USE_V4L2_CODEC) // V4L2-only: the encoder devices may not be visible at the time the GPU @@ -215,39 +202,45 @@ GpuVideoEncodeAcceleratorFactory::GetSupportedProfiles( // devices again in the hope that they will have appeared in the meantime. // TODO(crbug.com/948147): trigger query when an device add/remove event // (e.g. via udev) has happened instead. - if (profiles_ptr->empty()) { + if (profiles.empty()) { VLOGF(1) << "Supported profiles empty, querying again..."; - *profiles_ptr = GetSupportedProfilesInternal( - gpu_preferences, gpu_workarounds, gpu_device, populate_extended_info); + profiles = GetSupportedProfilesInternal(gpu_preferences, gpu_workarounds, gpu_device); } #endif + if (gpu_workarounds.disable_accelerated_av1_encode) { + base::EraseIf(profiles, [](const auto& vea_profile) { + return vea_profile.profile >= AV1PROFILE_PROFILE_MAIN && + vea_profile.profile <= AV1PROFILE_PROFILE_PRO; + }); + } + if (gpu_workarounds.disable_accelerated_vp8_encode) { - base::EraseIf(*profiles_ptr, [](const auto& vea_profile) { + base::EraseIf(profiles, [](const auto& vea_profile) { return vea_profile.profile == VP8PROFILE_ANY; }); } if (gpu_workarounds.disable_accelerated_vp9_encode) { - base::EraseIf(*profiles_ptr, [](const auto& vea_profile) { + base::EraseIf(profiles, [](const auto& vea_profile) { return vea_profile.profile >= VP9PROFILE_PROFILE0 && vea_profile.profile <= VP9PROFILE_PROFILE3; }); } if (gpu_workarounds.disable_accelerated_h264_encode) { - base::EraseIf(*profiles_ptr, [](const auto& vea_profile) { + base::EraseIf(profiles, [](const auto& vea_profile) { return vea_profile.profile >= H264PROFILE_MIN && vea_profile.profile <= H264PROFILE_MAX; }); } - base::EraseIf(*profiles_ptr, [](const auto& vea_profile) { + base::EraseIf(profiles, [](const auto& vea_profile) { return vea_profile.profile >= HEVCPROFILE_MIN && vea_profile.profile <= HEVCPROFILE_MAX; }); - return *profiles_ptr; + return profiles; } } // namespace media diff --git a/chromium/media/gpu/gpu_video_encode_accelerator_factory.h b/chromium/media/gpu/gpu_video_encode_accelerator_factory.h index 87d487cec54..83456d75849 100644 --- a/chromium/media/gpu/gpu_video_encode_accelerator_factory.h +++ b/chromium/media/gpu/gpu_video_encode_accelerator_factory.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -38,13 +38,10 @@ class MEDIA_GPU_EXPORT GpuVideoEncodeAcceleratorFactory { std::unique_ptr<MediaLog> media_log = nullptr); // Gets the supported codec profiles for video encoding on the platform. - // If |populate_extended_info| it false, this function will only populate: - // codec, framerate range and resolution range. It's faster. static VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles( const gpu::GpuPreferences& gpu_preferences, const gpu::GpuDriverBugWorkarounds& gpu_workarounds, - const gpu::GPUInfo::GPUDevice& gpu_device, - bool populate_extended_info = true); + const gpu::GPUInfo::GPUDevice& gpu_device); }; } // namespace media diff --git a/chromium/media/gpu/gpu_video_encode_accelerator_helpers.cc b/chromium/media/gpu/gpu_video_encode_accelerator_helpers.cc index f9221bf18da..13fe64ddcb2 100644 --- a/chromium/media/gpu/gpu_video_encode_accelerator_helpers.cc +++ b/chromium/media/gpu/gpu_video_encode_accelerator_helpers.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/gpu_video_encode_accelerator_helpers.h b/chromium/media/gpu/gpu_video_encode_accelerator_helpers.h index 32d88109e28..9d0de9f041b 100644 --- a/chromium/media/gpu/gpu_video_encode_accelerator_helpers.h +++ b/chromium/media/gpu/gpu_video_encode_accelerator_helpers.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/h264_decoder.cc b/chromium/media/gpu/h264_decoder.cc index 389c29f0cee..6dc535f4ce9 100644 --- a/chromium/media/gpu/h264_decoder.cc +++ b/chromium/media/gpu/h264_decoder.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -152,8 +152,8 @@ void H264Decoder::Reset() { accelerator_->Reset(); last_output_poc_ = std::numeric_limits<int>::min(); - encrypted_sei_nalus_.clear(); - sei_subsamples_.clear(); + prior_cencv1_nalus_.clear(); + prior_cencv1_subsamples_.clear(); recovery_frame_num_.reset(); recovery_frame_cnt_.reset(); @@ -1294,15 +1294,27 @@ H264Decoder::H264Accelerator::Status H264Decoder::ProcessEncryptedSliceHeader( const std::vector<SubsampleEntry>& subsamples) { DCHECK(curr_nalu_); DCHECK(curr_slice_hdr_); - std::vector<base::span<const uint8_t>> spans(encrypted_sei_nalus_.size() + 1); - spans.assign(encrypted_sei_nalus_.begin(), encrypted_sei_nalus_.end()); + std::vector<base::span<const uint8_t>> spans(prior_cencv1_nalus_.begin(), + prior_cencv1_nalus_.end()); spans.emplace_back(curr_nalu_->data, curr_nalu_->size); - std::vector<SubsampleEntry> all_subsamples(sei_subsamples_.size() + 1); - all_subsamples.assign(sei_subsamples_.begin(), sei_subsamples_.end()); + std::vector<SubsampleEntry> all_subsamples(prior_cencv1_subsamples_.begin(), + prior_cencv1_subsamples_.end()); all_subsamples.insert(all_subsamples.end(), subsamples.begin(), subsamples.end()); - return accelerator_->ParseEncryptedSliceHeader(spans, all_subsamples, - curr_slice_hdr_.get()); + auto rv = accelerator_->ParseEncryptedSliceHeader(spans, all_subsamples, + curr_slice_hdr_.get()); + // Return now if this isn't fully processed and don't store the NALU info + // since we will get called again in the kTryAgain case, and on an error we + // want to exist. + if (rv != H264Accelerator::Status::kOk) + return rv; + + // Insert this encrypted slice data as well in case this is a multi-slice + // picture. + prior_cencv1_nalus_.emplace_back(curr_nalu_->data, curr_nalu_->size); + prior_cencv1_subsamples_.insert(prior_cencv1_subsamples_.end(), + subsamples.begin(), subsamples.end()); + return rv; } H264Decoder::H264Accelerator::Status H264Decoder::PreprocessCurrentSlice() { @@ -1405,8 +1417,8 @@ void H264Decoder::SetStream(int32_t id, const DecoderBuffer& decoder_buffer) { current_stream_ = ptr; current_stream_size_ = size; current_stream_has_been_changed_ = true; - encrypted_sei_nalus_.clear(); - sei_subsamples_.clear(); + prior_cencv1_nalus_.clear(); + prior_cencv1_subsamples_.clear(); if (decrypt_config) { parser_.SetEncryptedStream(ptr, size, decrypt_config->subsamples()); current_decrypt_config_ = decrypt_config->Clone(); @@ -1504,8 +1516,6 @@ H264Decoder::DecodeResult H264Decoder::Decode() { CHECK_ACCELERATOR_RESULT(ProcessEncryptedSliceHeader(subsamples)); parsed_header = true; curr_slice_hdr_->pic_parameter_set_id = last_parsed_pps_id_; - encrypted_sei_nalus_.clear(); - sei_subsamples_.clear(); } } if (!parsed_header) { @@ -1610,10 +1620,10 @@ H264Decoder::DecodeResult H264Decoder::Decode() { const std::vector<SubsampleEntry>& subsamples = parser_.GetCurrentSubsamples(); if (!subsamples.empty()) { - encrypted_sei_nalus_.emplace_back(curr_nalu_->data, - curr_nalu_->size); + prior_cencv1_nalus_.emplace_back(curr_nalu_->data, + curr_nalu_->size); DCHECK_EQ(1u, subsamples.size()); - sei_subsamples_.push_back(subsamples[0]); + prior_cencv1_subsamples_.push_back(subsamples[0]); // Since the SEI is encrypted, do not try to parse it below as it // may fail or yield incorrect results. DVLOG(3) << "Skipping parsing of encrypted SEI NALU"; @@ -1761,7 +1771,10 @@ bool H264Decoder::IsNewPrimaryCodedPicture(const H264Picture* curr_pic, // but some encoders neglect changing idr_pic_id for two consecutive // IDRs. Work around this by checking if the next slice contains the // zeroth macroblock, i.e. data that belongs to the next picture. - slice_hdr.first_mb_in_slice == 0))) + // Do not perform this check for CENCv1 encrypted content as the + // first_mb_in_slice field is not correctly populated in that case. + (slice_hdr.first_mb_in_slice == 0 && + !slice_hdr.full_sample_encryption)))) return true; if (!sps) diff --git a/chromium/media/gpu/h264_decoder.h b/chromium/media/gpu/h264_decoder.h index 3f7643fba2b..d17afbef695 100644 --- a/chromium/media/gpu/h264_decoder.h +++ b/chromium/media/gpu/h264_decoder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -390,11 +390,11 @@ class MEDIA_GPU_EXPORT H264Decoder : public AcceleratedVideoDecoder { std::unique_ptr<H264NALU> curr_nalu_; std::unique_ptr<H264SliceHeader> curr_slice_hdr_; - // Encrypted SEI NALUs preceding a fully encrypted slice NALU. We need to + // Encrypted NALUs preceding a fully encrypted (CENCv1) slice NALU. We need to // save these that are part of a single sample so they can all be decrypted // together. - std::vector<base::span<const uint8_t>> encrypted_sei_nalus_; - std::vector<SubsampleEntry> sei_subsamples_; + std::vector<base::span<const uint8_t>> prior_cencv1_nalus_; + std::vector<SubsampleEntry> prior_cencv1_subsamples_; // These are absl::nullopt unless get recovery point SEI message after Reset. // A frame_num of the frame at output order that is correct in content. diff --git a/chromium/media/gpu/h264_decoder_unittest.cc b/chromium/media/gpu/h264_decoder_unittest.cc index 823e8780d7f..7636eb20f2c 100644 --- a/chromium/media/gpu/h264_decoder_unittest.cc +++ b/chromium/media/gpu/h264_decoder_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/h264_dpb.cc b/chromium/media/gpu/h264_dpb.cc index 6a677547fdc..f7ec30fc6a8 100644 --- a/chromium/media/gpu/h264_dpb.cc +++ b/chromium/media/gpu/h264_dpb.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/h264_dpb.h b/chromium/media/gpu/h264_dpb.h index a68b96baeec..8b9aa812a25 100644 --- a/chromium/media/gpu/h264_dpb.h +++ b/chromium/media/gpu/h264_dpb.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // diff --git a/chromium/media/gpu/h265_decoder.cc b/chromium/media/gpu/h265_decoder.cc index f9f9d7bb75e..7ae6ff43b05 100644 --- a/chromium/media/gpu/h265_decoder.cc +++ b/chromium/media/gpu/h265_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/h265_decoder.h b/chromium/media/gpu/h265_decoder.h index 973b130199a..59c4aac56ef 100644 --- a/chromium/media/gpu/h265_decoder.h +++ b/chromium/media/gpu/h265_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/h265_decoder_fuzzertest.cc b/chromium/media/gpu/h265_decoder_fuzzertest.cc index fd25e61adeb..1be447c7a4f 100644 --- a/chromium/media/gpu/h265_decoder_fuzzertest.cc +++ b/chromium/media/gpu/h265_decoder_fuzzertest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/h265_decoder_unittest.cc b/chromium/media/gpu/h265_decoder_unittest.cc index 7a6150901fa..56904f5375b 100644 --- a/chromium/media/gpu/h265_decoder_unittest.cc +++ b/chromium/media/gpu/h265_decoder_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/h265_dpb.cc b/chromium/media/gpu/h265_dpb.cc index 1a7f40158f0..e060bcee7e0 100644 --- a/chromium/media/gpu/h265_dpb.cc +++ b/chromium/media/gpu/h265_dpb.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/h265_dpb.h b/chromium/media/gpu/h265_dpb.h index 9d55528f85e..64f0f1b5bd5 100644 --- a/chromium/media/gpu/h265_dpb.h +++ b/chromium/media/gpu/h265_dpb.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/client/BUILD.gn b/chromium/media/gpu/ipc/client/BUILD.gn index b91049428bc..29164df39cb 100644 --- a/chromium/media/gpu/ipc/client/BUILD.gn +++ b/chromium/media/gpu/ipc/client/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. +# Copyright 2016 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/client/gpu_video_decode_accelerator_host.cc b/chromium/media/gpu/ipc/client/gpu_video_decode_accelerator_host.cc index bdbbd77cb1c..91df424e703 100644 --- a/chromium/media/gpu/ipc/client/gpu_video_decode_accelerator_host.cc +++ b/chromium/media/gpu/ipc/client/gpu_video_decode_accelerator_host.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/client/gpu_video_decode_accelerator_host.h b/chromium/media/gpu/ipc/client/gpu_video_decode_accelerator_host.h index b1bf1b01fc8..29e919732e3 100644 --- a/chromium/media/gpu/ipc/client/gpu_video_decode_accelerator_host.h +++ b/chromium/media/gpu/ipc/client/gpu_video_decode_accelerator_host.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/common/BUILD.gn b/chromium/media/gpu/ipc/common/BUILD.gn index 226bfe81015..416ab6220f0 100644 --- a/chromium/media/gpu/ipc/common/BUILD.gn +++ b/chromium/media/gpu/ipc/common/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. +# Copyright 2016 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/common/media_param_traits.cc b/chromium/media/gpu/ipc/common/media_param_traits.cc index e7f057acf8a..82698589cc9 100644 --- a/chromium/media/gpu/ipc/common/media_param_traits.cc +++ b/chromium/media/gpu/ipc/common/media_param_traits.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/common/media_param_traits.h b/chromium/media/gpu/ipc/common/media_param_traits.h index 8d8bb1dc80b..48fe6865332 100644 --- a/chromium/media/gpu/ipc/common/media_param_traits.h +++ b/chromium/media/gpu/ipc/common/media_param_traits.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/common/media_param_traits_macros.h b/chromium/media/gpu/ipc/common/media_param_traits_macros.h index a15d8d03cd6..02f43993f72 100644 --- a/chromium/media/gpu/ipc/common/media_param_traits_macros.h +++ b/chromium/media/gpu/ipc/common/media_param_traits_macros.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/service/BUILD.gn b/chromium/media/gpu/ipc/service/BUILD.gn index 90d8ccdb66f..8542b352c23 100644 --- a/chromium/media/gpu/ipc/service/BUILD.gn +++ b/chromium/media/gpu/ipc/service/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. +# Copyright 2016 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/service/gpu_video_decode_accelerator.cc b/chromium/media/gpu/ipc/service/gpu_video_decode_accelerator.cc index 0c203bef158..05816d5cb90 100644 --- a/chromium/media/gpu/ipc/service/gpu_video_decode_accelerator.cc +++ b/chromium/media/gpu/ipc/service/gpu_video_decode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/service/gpu_video_decode_accelerator.h b/chromium/media/gpu/ipc/service/gpu_video_decode_accelerator.h index f45fa83f8e5..75472c9acb0 100644 --- a/chromium/media/gpu/ipc/service/gpu_video_decode_accelerator.h +++ b/chromium/media/gpu/ipc/service/gpu_video_decode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/service/media_gpu_channel.cc b/chromium/media/gpu/ipc/service/media_gpu_channel.cc index 885d9db8d36..75b7296de64 100644 --- a/chromium/media/gpu/ipc/service/media_gpu_channel.cc +++ b/chromium/media/gpu/ipc/service/media_gpu_channel.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/service/media_gpu_channel.h b/chromium/media/gpu/ipc/service/media_gpu_channel.h index 41b48a38ec0..cd91d970130 100644 --- a/chromium/media/gpu/ipc/service/media_gpu_channel.h +++ b/chromium/media/gpu/ipc/service/media_gpu_channel.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/service/media_gpu_channel_manager.cc b/chromium/media/gpu/ipc/service/media_gpu_channel_manager.cc index abe2700d9a0..4a5d387f098 100644 --- a/chromium/media/gpu/ipc/service/media_gpu_channel_manager.cc +++ b/chromium/media/gpu/ipc/service/media_gpu_channel_manager.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/service/media_gpu_channel_manager.h b/chromium/media/gpu/ipc/service/media_gpu_channel_manager.h index c9ebef04022..fbc76409769 100644 --- a/chromium/media/gpu/ipc/service/media_gpu_channel_manager.h +++ b/chromium/media/gpu/ipc/service/media_gpu_channel_manager.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/ipc/service/picture_buffer_manager.cc b/chromium/media/gpu/ipc/service/picture_buffer_manager.cc index 47229a7365a..933ae35b8e0 100644 --- a/chromium/media/gpu/ipc/service/picture_buffer_manager.cc +++ b/chromium/media/gpu/ipc/service/picture_buffer_manager.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,6 +15,11 @@ #include "base/thread_annotations.h" #include "components/viz/common/resources/resource_format_utils.h" #include "gpu/command_buffer/common/mailbox_holder.h" +#include "ui/gfx/gpu_memory_buffer.h" + +#if BUILDFLAG(USE_VAAPI) || BUILDFLAG(USE_V4L2_CODEC) +#include "media/gpu/chromeos/platform_video_frame_utils.h" +#endif // BUILDFLAG(USE_VAAPI) || BUILDFLAG(USE_V4L2_CODEC) namespace media { @@ -29,9 +34,10 @@ int32_t NextID(int32_t* counter) { class PictureBufferManagerImpl : public PictureBufferManager { public: - explicit PictureBufferManagerImpl( - ReusePictureBufferCB reuse_picture_buffer_cb) - : reuse_picture_buffer_cb_(std::move(reuse_picture_buffer_cb)) { + PictureBufferManagerImpl(bool allocate_gpu_memory_buffers, + ReusePictureBufferCB reuse_picture_buffer_cb) + : allocate_gpu_memory_buffers_(allocate_gpu_memory_buffers), + reuse_picture_buffer_cb_(std::move(reuse_picture_buffer_cb)) { DVLOG(1) << __func__; } PictureBufferManagerImpl(const PictureBufferManagerImpl&) = delete; @@ -71,7 +77,8 @@ class PictureBufferManagerImpl : public PictureBufferManager { return !has_assigned_picture_buffer; } - std::vector<PictureBuffer> CreatePictureBuffers( + std::vector<std::pair<PictureBuffer, gfx::GpuMemoryBufferHandle>> + CreatePictureBuffers( uint32_t count, VideoPixelFormat pixel_format, uint32_t planes, @@ -84,6 +91,9 @@ class PictureBufferManagerImpl : public PictureBufferManager { DCHECK(count); DCHECK(planes); DCHECK_LE(planes, static_cast<uint32_t>(VideoFrame::kMaxPlanes)); + DCHECK(!allocate_gpu_memory_buffers_ || + mode == VideoDecodeAccelerator::TextureAllocationMode:: + kDoNotAllocateGLTextures); // TODO(sandersd): Consider requiring that CreatePictureBuffers() is // called with the context current. @@ -91,11 +101,12 @@ class PictureBufferManagerImpl : public PictureBufferManager { VideoDecodeAccelerator::TextureAllocationMode::kAllocateGLTextures) { if (!command_buffer_helper_->MakeContextCurrent()) { DVLOG(1) << "Failed to make context current"; - return std::vector<PictureBuffer>(); + return {}; } } - std::vector<PictureBuffer> picture_buffers; + std::vector<std::pair<PictureBuffer, gfx::GpuMemoryBufferHandle>> + picture_buffers_and_gmbs; for (uint32_t i = 0; i < count; i++) { PictureBufferData picture_data = {pixel_format, texture_size}; if (mode == @@ -132,6 +143,46 @@ class PictureBufferManagerImpl : public PictureBufferManager { } } + gfx::GpuMemoryBufferHandle gmb_handle; + if (allocate_gpu_memory_buffers_) { +#if BUILDFLAG(USE_VAAPI) || BUILDFLAG(USE_V4L2_CODEC) + scoped_refptr<VideoFrame> gpu_memory_buffer_video_frame = + CreateGpuMemoryBufferVideoFrame( + pixel_format, texture_size, gfx::Rect(texture_size), + texture_size, base::TimeDelta(), + gfx::BufferUsage::SCANOUT_VDA_WRITE); + if (!gpu_memory_buffer_video_frame) + return {}; + if (gpu_memory_buffer_video_frame->format() != pixel_format) { + // There is a mismatch (maybe deliberate) between + // VideoPixelFormatToGfxBufferFormat() and + // GfxBufferFormatToVideoPixelFormat(). For PIXEL_FORMAT_XBGR, the + // former returns gfx::BufferFormat::RGBX_8888, but for + // gfx::BufferFormat::RGBX_8888, the latter returns PIXEL_FORMAT_XRGB. + // Just fail if the allocated format doesn't match the requested + // format. + // + // TODO(andrescj): does this mismatch need to be fixed or is it + // intentional? + return {}; + } + + gfx::GpuMemoryBuffer* gmb = + gpu_memory_buffer_video_frame->GetGpuMemoryBuffer(); + DCHECK(gmb); + gmb_handle = gmb->CloneHandle(); + if (gmb_handle.type != gfx::NATIVE_PIXMAP || + gmb_handle.native_pixmap_handle.planes.empty()) { + return {}; + } + picture_data.gpu_memory_buffer_video_frame = + std::move(gpu_memory_buffer_video_frame); +#else + NOTREACHED(); + return {}; +#endif // BUILDFLAG(USE_VAAPI) || BUILDFLAG(USE_V4L2_CODEC) + } + // Generate a picture buffer ID and record the picture buffer. int32_t picture_buffer_id = NextID(&picture_buffer_id_); { @@ -145,12 +196,13 @@ class PictureBufferManagerImpl : public PictureBufferManager { // // TODO(sandersd): Refactor the bind image callback to use service IDs so // that we can get rid of the client IDs altogether. - picture_buffers.emplace_back( - picture_buffer_id, texture_size, picture_data.texture_sizes, - picture_data.service_ids, picture_data.service_ids, texture_target, - pixel_format); + picture_buffers_and_gmbs.emplace_back( + PictureBuffer{picture_buffer_id, texture_size, + picture_data.texture_sizes, picture_data.service_ids, + picture_data.service_ids, texture_target, pixel_format}, + std::move(gmb_handle)); } - return picture_buffers; + return picture_buffers_and_gmbs; } bool DismissPictureBuffer(int32_t picture_buffer_id) override { @@ -236,15 +288,31 @@ class PictureBufferManagerImpl : public PictureBufferManager { } // Create and return a VideoFrame for the picture buffer. - scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTextures( - picture_buffer_data.pixel_format, picture_buffer_data.mailbox_holders, - base::BindOnce(&PictureBufferManagerImpl::OnVideoFrameDestroyed, this, - picture_buffer_id), - picture_buffer_data.texture_size, visible_rect, natural_size, - timestamp); - if (!frame) { - DLOG(ERROR) << "Failed to create VideoFrame for picture."; - return nullptr; + scoped_refptr<VideoFrame> frame; + if (picture_buffer_data.gpu_memory_buffer_video_frame) { + frame = VideoFrame::WrapVideoFrame( + picture_buffer_data.gpu_memory_buffer_video_frame, + picture_buffer_data.gpu_memory_buffer_video_frame->format(), + visible_rect, natural_size); + if (!frame) { + DLOG(ERROR) << "Failed to create VideoFrame for picture."; + return nullptr; + } + frame->set_timestamp(timestamp); + frame->AddDestructionObserver( + base::BindOnce(&PictureBufferManagerImpl::OnVideoFrameDestroyed, this, + picture_buffer_id, gpu::SyncToken())); + } else { + frame = VideoFrame::WrapNativeTextures( + picture_buffer_data.pixel_format, picture_buffer_data.mailbox_holders, + base::BindOnce(&PictureBufferManagerImpl::OnVideoFrameDestroyed, this, + picture_buffer_id), + picture_buffer_data.texture_size, visible_rect, natural_size, + timestamp); + if (!frame) { + DLOG(ERROR) << "Failed to create VideoFrame for picture."; + return nullptr; + } } frame->set_color_space(picture.color_space()); @@ -263,7 +331,8 @@ class PictureBufferManagerImpl : public PictureBufferManager { private: ~PictureBufferManagerImpl() override { DVLOG(1) << __func__; - DCHECK(picture_buffers_.empty() || !command_buffer_helper_->HasStub()); + DCHECK(picture_buffers_.empty() || + (!command_buffer_helper_ || !command_buffer_helper_->HasStub())); } void OnVideoFrameDestroyed(int32_t picture_buffer_id, @@ -280,14 +349,21 @@ class PictureBufferManagerImpl : public PictureBufferManager { it->second.output_count--; it->second.waiting_for_synctoken_count++; - // Wait for the SyncToken release. - gpu_task_runner_->PostTask( - FROM_HERE, - base::BindOnce( - &CommandBufferHelper::WaitForSyncToken, command_buffer_helper_, - sync_token, - base::BindOnce(&PictureBufferManagerImpl::OnSyncTokenReleased, this, - picture_buffer_id))); + if (command_buffer_helper_) { + // Wait for the SyncToken release. + gpu_task_runner_->PostTask( + FROM_HERE, + base::BindOnce( + &CommandBufferHelper::WaitForSyncToken, command_buffer_helper_, + sync_token, + base::BindOnce(&PictureBufferManagerImpl::OnSyncTokenReleased, + this, picture_buffer_id))); + } else { + gpu_task_runner_->PostTask( + FROM_HERE, + base::BindOnce(&PictureBufferManagerImpl::OnSyncTokenReleased, this, + picture_buffer_id)); + } } void OnSyncTokenReleased(int32_t picture_buffer_id) { @@ -353,6 +429,7 @@ class PictureBufferManagerImpl : public PictureBufferManager { command_buffer_helper_->DestroyTexture(service_id); } + const bool allocate_gpu_memory_buffers_; ReusePictureBufferCB reuse_picture_buffer_cb_; scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; @@ -369,6 +446,7 @@ class PictureBufferManagerImpl : public PictureBufferManager { std::array<scoped_refptr<Picture::ScopedSharedImage>, VideoFrame::kMaxPlanes> scoped_shared_images; + scoped_refptr<VideoFrame> gpu_memory_buffer_video_frame; bool dismissed = false; // The same picture buffer can be output from the VDA multiple times @@ -393,9 +471,10 @@ class PictureBufferManagerImpl : public PictureBufferManager { // static scoped_refptr<PictureBufferManager> PictureBufferManager::Create( + bool allocate_gpu_memory_buffers, ReusePictureBufferCB reuse_picture_buffer_cb) { return base::MakeRefCounted<PictureBufferManagerImpl>( - std::move(reuse_picture_buffer_cb)); + allocate_gpu_memory_buffers, std::move(reuse_picture_buffer_cb)); } } // namespace media diff --git a/chromium/media/gpu/ipc/service/picture_buffer_manager.h b/chromium/media/gpu/ipc/service/picture_buffer_manager.h index 20452605397..dd6cbb20853 100644 --- a/chromium/media/gpu/ipc/service/picture_buffer_manager.h +++ b/chromium/media/gpu/ipc/service/picture_buffer_manager.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -22,6 +22,10 @@ #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" +namespace gfx { +struct GpuMemoryBufferHandle; +} // namespace gfx + namespace media { class PictureBufferManager @@ -33,9 +37,14 @@ class PictureBufferManager // Creates a PictureBufferManager. // + // |allocate_gpu_memory_buffers|: If true, the PictureBufferManager will + // allocate a GpuMemoryBuffer for each PictureBuffer in + // CreatePictureBuffers(), and CreateVideoFrame() will return VideoFrames + // backed by the allocated GpuMemoryBuffers. // |reuse_picture_buffer_cb|: Called when a picture is returned to the pool // after its VideoFrame has been destructed. static scoped_refptr<PictureBufferManager> Create( + bool allocate_gpu_memory_buffers, ReusePictureBufferCB reuse_picture_buffer_cb); // Provides access to a CommandBufferHelper. This must be done before calling @@ -53,7 +62,8 @@ class PictureBufferManager // preroll than to hang waiting for an output that can never come. virtual bool CanReadWithoutStalling() = 0; - // Creates and returns a vector of picture buffers, or an empty vector on + // Creates and returns a vector of picture buffers and the corresponding + // GpuMemoryBuffer (if applicable, see constructor), or an empty vector on // failure. // // |count|: Number of picture buffers to create. @@ -72,13 +82,13 @@ class PictureBufferManager // are not automatically allocated.) // TODO(sandersd): The current implementation makes the context current. // Consider requiring that the context is already current. - virtual std::vector<PictureBuffer> CreatePictureBuffers( - uint32_t count, - VideoPixelFormat pixel_format, - uint32_t planes, - gfx::Size texture_size, - uint32_t texture_target, - VideoDecodeAccelerator::TextureAllocationMode mode) = 0; + virtual std::vector<std::pair<PictureBuffer, gfx::GpuMemoryBufferHandle>> + CreatePictureBuffers(uint32_t count, + VideoPixelFormat pixel_format, + uint32_t planes, + gfx::Size texture_size, + uint32_t texture_target, + VideoDecodeAccelerator::TextureAllocationMode mode) = 0; // Dismisses a picture buffer from the pool. // diff --git a/chromium/media/gpu/ipc/service/picture_buffer_manager_unittest.cc b/chromium/media/gpu/ipc/service/picture_buffer_manager_unittest.cc index ef2098bb70e..0a12715412d 100644 --- a/chromium/media/gpu/ipc/service/picture_buffer_manager_unittest.cc +++ b/chromium/media/gpu/ipc/service/picture_buffer_manager_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -22,7 +22,8 @@ class PictureBufferManagerImplTest : public testing::Test { // TODO(sandersd): Use a separate thread for the GPU task runner. cbh_ = base::MakeRefCounted<FakeCommandBufferHelper>( environment_.GetMainThreadTaskRunner()); - pbm_ = PictureBufferManager::Create(reuse_cb_.Get()); + pbm_ = PictureBufferManager::Create(/*allocate_gpu_memory_buffers=*/false, + reuse_cb_.Get()); } PictureBufferManagerImplTest(const PictureBufferManagerImplTest&) = delete; @@ -47,8 +48,15 @@ class PictureBufferManagerImplTest : public testing::Test { uint32_t count, VideoDecodeAccelerator::TextureAllocationMode mode = VideoDecodeAccelerator::TextureAllocationMode::kAllocateGLTextures) { - return pbm_->CreatePictureBuffers(count, PIXEL_FORMAT_ARGB, 1, - gfx::Size(320, 240), GL_TEXTURE_2D, mode); + std::vector<std::pair<PictureBuffer, gfx::GpuMemoryBufferHandle>> + picture_buffers_and_gmbs = pbm_->CreatePictureBuffers( + count, PIXEL_FORMAT_ARGB, 1, gfx::Size(320, 240), GL_TEXTURE_2D, + mode); + std::vector<PictureBuffer> picture_buffers; + for (const auto& picture_buffer_and_gmb : picture_buffers_and_gmbs) { + picture_buffers.push_back(picture_buffer_and_gmb.first); + } + return picture_buffers; } PictureBuffer CreateARGBPictureBuffer( diff --git a/chromium/media/gpu/ipc/service/vda_video_decoder.cc b/chromium/media/gpu/ipc/service/vda_video_decoder.cc index ccf7b1fd7f6..73633231502 100644 --- a/chromium/media/gpu/ipc/service/vda_video_decoder.cc +++ b/chromium/media/gpu/ipc/service/vda_video_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -74,14 +74,19 @@ std::unique_ptr<VideoDecodeAccelerator> CreateAndInitializeVda( MediaLog* media_log, const VideoDecodeAccelerator::Config& config) { GpuVideoDecodeGLClient gl_client; - gl_client.get_context = base::BindRepeating( - &CommandBufferHelper::GetGLContext, command_buffer_helper); - gl_client.make_context_current = base::BindRepeating( - &CommandBufferHelper::MakeContextCurrent, command_buffer_helper); - gl_client.bind_image = base::BindRepeating(&BindImage, command_buffer_helper); - gl_client.is_passthrough = command_buffer_helper->IsPassthrough(); - gl_client.supports_arb_texture_rectangle = - command_buffer_helper->SupportsTextureRectangle(); + // |command_buffer_helper| is nullptr in IMPORT mode in which case, we + // shouldn't need to do any GL calls. + if (command_buffer_helper) { + gl_client.get_context = base::BindRepeating( + &CommandBufferHelper::GetGLContext, command_buffer_helper); + gl_client.make_context_current = base::BindRepeating( + &CommandBufferHelper::MakeContextCurrent, command_buffer_helper); + gl_client.bind_image = + base::BindRepeating(&BindImage, command_buffer_helper); + gl_client.is_passthrough = command_buffer_helper->IsPassthrough(); + gl_client.supports_arb_texture_rectangle = + command_buffer_helper->SupportsTextureRectangle(); + } std::unique_ptr<GpuVideoDecodeAcceleratorFactory> factory = GpuVideoDecodeAcceleratorFactory::Create(gl_client); @@ -119,17 +124,23 @@ std::unique_ptr<VideoDecoder> VdaVideoDecoder::Create( const gfx::ColorSpace& target_color_space, const gpu::GpuPreferences& gpu_preferences, const gpu::GpuDriverBugWorkarounds& gpu_workarounds, - GetStubCB get_stub_cb) { + GetStubCB get_stub_cb, + VideoDecodeAccelerator::Config::OutputMode output_mode) { auto* decoder = new VdaVideoDecoder( std::move(parent_task_runner), std::move(gpu_task_runner), std::move(media_log), target_color_space, - base::BindOnce(&PictureBufferManager::Create), - base::BindOnce(&CreateCommandBufferHelper, std::move(get_stub_cb)), + base::BindOnce(&PictureBufferManager::Create, + /*allocate_gpu_memory_buffers=*/output_mode == + VideoDecodeAccelerator::Config::OutputMode::IMPORT), + output_mode == VideoDecodeAccelerator::Config::OutputMode::ALLOCATE + ? base::BindOnce(&CreateCommandBufferHelper, std::move(get_stub_cb)) + : base::NullCallback(), base::BindRepeating(&CreateAndInitializeVda, gpu_preferences, gpu_workarounds), GpuVideoAcceleratorUtil::ConvertGpuToMediaDecodeCapabilities( GpuVideoDecodeAcceleratorFactory::GetDecoderCapabilities( - gpu_preferences, gpu_workarounds))); + gpu_preferences, gpu_workarounds)), + output_mode); return std::make_unique<AsyncDestroyVideoDecoder<VdaVideoDecoder>>( base::WrapUnique(decoder)); @@ -143,7 +154,8 @@ VdaVideoDecoder::VdaVideoDecoder( CreatePictureBufferManagerCB create_picture_buffer_manager_cb, CreateCommandBufferHelperCB create_command_buffer_helper_cb, CreateAndInitializeVdaCB create_and_initialize_vda_cb, - const VideoDecodeAccelerator::Capabilities& vda_capabilities) + const VideoDecodeAccelerator::Capabilities& vda_capabilities, + VideoDecodeAccelerator::Config::OutputMode output_mode) : parent_task_runner_(std::move(parent_task_runner)), gpu_task_runner_(std::move(gpu_task_runner)), media_log_(std::move(media_log)), @@ -152,6 +164,7 @@ VdaVideoDecoder::VdaVideoDecoder( std::move(create_command_buffer_helper_cb)), create_and_initialize_vda_cb_(std::move(create_and_initialize_vda_cb)), vda_capabilities_(vda_capabilities), + output_mode_(output_mode), timestamps_(128) { DVLOG(1) << __func__; DCHECK(parent_task_runner_->BelongsToCurrentThread()); @@ -262,7 +275,10 @@ void VdaVideoDecoder::Initialize(const VideoDecoderConfig& config, // TODO(sandersd): Change this to a capability if any VDA starts supporting // alpha channels. This is believed to be impossible right now because VPx // alpha channel data is passed in side data, which isn't sent to VDAs. - if (config.alpha_mode() != VideoDecoderConfig::AlphaMode::kIsOpaque) { + // HEVC is the codec that only has platform hardware decoder support, and + // macOS currently support HEVC with alpha, so don't block HEVC here. + if (config.alpha_mode() != VideoDecoderConfig::AlphaMode::kIsOpaque && + config.codec() != VideoCodec::kHEVC) { MEDIA_LOG(INFO, media_log_) << "Alpha formats are not supported"; EnterErrorState(); return; @@ -339,13 +355,16 @@ void VdaVideoDecoder::InitializeOnGpuThread() { // Set up |command_buffer_helper_|. if (!reinitializing_) { - command_buffer_helper_ = std::move(create_command_buffer_helper_cb_).Run(); - if (!command_buffer_helper_) { - parent_task_runner_->PostTask( - FROM_HERE, - base::BindOnce(&VdaVideoDecoder::InitializeDone, parent_weak_this_, - DecoderStatus::Codes::kFailed)); - return; + if (output_mode_ == VideoDecodeAccelerator::Config::OutputMode::ALLOCATE) { + command_buffer_helper_ = + std::move(create_command_buffer_helper_cb_).Run(); + if (!command_buffer_helper_) { + parent_task_runner_->PostTask( + FROM_HERE, + base::BindOnce(&VdaVideoDecoder::InitializeDone, parent_weak_this_, + DecoderStatus::Codes::kFailed)); + return; + } } picture_buffer_manager_->Initialize(gpu_task_runner_, @@ -365,7 +384,7 @@ void VdaVideoDecoder::InitializeOnGpuThread() { vda_config.hdr_metadata = config_.hdr_metadata(); // vda_config.sps = [Only used by AVDA] // vda_config.pps = [Only used by AVDA] - // vda_config.output_mode = [Only used by ARC] + vda_config.output_mode = output_mode_; // vda_config.supported_output_formats = [Only used by PPAPI] // Create and initialize the VDA. @@ -505,6 +524,13 @@ int VdaVideoDecoder::GetMaxDecodeRequests() const { return 4; } +bool VdaVideoDecoder::FramesHoldExternalResources() const { + DVLOG(3) << __func__; + DCHECK(parent_task_runner_->BelongsToCurrentThread()); + + return output_mode_ == VideoDecodeAccelerator::Config::OutputMode::IMPORT; +} + void VdaVideoDecoder::NotifyInitializationComplete(DecoderStatus status) { DVLOG(2) << __func__ << "(" << static_cast<int>(status.code()) << ")"; DCHECK(gpu_task_runner_->BelongsToCurrentThread()); @@ -531,6 +557,27 @@ void VdaVideoDecoder::ProvidePictureBuffers(uint32_t requested_num_of_buffers, textures_per_buffer, dimensions, texture_target)); } +void VdaVideoDecoder::ProvidePictureBuffersWithVisibleRect( + uint32_t requested_num_of_buffers, + VideoPixelFormat format, + uint32_t textures_per_buffer, + const gfx::Size& dimensions, + const gfx::Rect& visible_rect, + uint32_t texture_target) { + if (output_mode_ == VideoDecodeAccelerator::Config::OutputMode::IMPORT) { + // In IMPORT mode, we (as the client of the underlying VDA) are responsible + // for buffer allocation with no textures (i.e., |texture_target| is + // irrelevant). Therefore, the logic in the base version of + // ProvidePictureBuffersWithVisibleRect() is not applicable. + ProvidePictureBuffers(requested_num_of_buffers, format, textures_per_buffer, + dimensions, texture_target); + return; + } + VideoDecodeAccelerator::Client::ProvidePictureBuffersWithVisibleRect( + requested_num_of_buffers, format, textures_per_buffer, dimensions, + visible_rect, texture_target); +} + void VdaVideoDecoder::ProvidePictureBuffersAsync(uint32_t count, VideoPixelFormat pixel_format, uint32_t planes, @@ -547,11 +594,14 @@ void VdaVideoDecoder::ProvidePictureBuffersAsync(uint32_t count, if (pixel_format == PIXEL_FORMAT_UNKNOWN) pixel_format = PIXEL_FORMAT_XRGB; - std::vector<PictureBuffer> picture_buffers = - picture_buffer_manager_->CreatePictureBuffers( + std::vector<std::pair<PictureBuffer, gfx::GpuMemoryBufferHandle>> + picture_buffers_and_gmbs = picture_buffer_manager_->CreatePictureBuffers( count, pixel_format, planes, texture_size, texture_target, - vda_->GetSharedImageTextureAllocationMode()); - if (picture_buffers.empty()) { + output_mode_ == VideoDecodeAccelerator::Config::OutputMode::IMPORT + ? VideoDecodeAccelerator::TextureAllocationMode:: + kDoNotAllocateGLTextures + : vda_->GetSharedImageTextureAllocationMode()); + if (picture_buffers_and_gmbs.empty()) { parent_task_runner_->PostTask( FROM_HERE, base::BindOnce(&VdaVideoDecoder::EnterErrorState, parent_weak_this_)); @@ -559,7 +609,19 @@ void VdaVideoDecoder::ProvidePictureBuffersAsync(uint32_t count, } DCHECK(gpu_weak_vda_); + std::vector<PictureBuffer> picture_buffers; + for (const auto& picture_buffer_and_gmb : picture_buffers_and_gmbs) { + picture_buffers.push_back(picture_buffer_and_gmb.first); + } vda_->AssignPictureBuffers(std::move(picture_buffers)); + + if (output_mode_ == VideoDecodeAccelerator::Config::OutputMode::IMPORT) { + for (auto& picture_buffer_and_gmb : picture_buffers_and_gmbs) { + vda_->ImportBufferForPicture(picture_buffer_and_gmb.first.id(), + pixel_format, + std::move(picture_buffer_and_gmb.second)); + } + } } void VdaVideoDecoder::DismissPictureBuffer(int32_t picture_buffer_id) { @@ -771,10 +833,12 @@ void VdaVideoDecoder::NotifyError(VideoDecodeAccelerator::Error error) { } gpu::SharedImageStub* VdaVideoDecoder::GetSharedImageStub() const { + DCHECK_EQ(output_mode_, VideoDecodeAccelerator::Config::OutputMode::ALLOCATE); return command_buffer_helper_->GetSharedImageStub(); } CommandBufferHelper* VdaVideoDecoder::GetCommandBufferHelper() const { + DCHECK_EQ(output_mode_, VideoDecodeAccelerator::Config::OutputMode::ALLOCATE); return command_buffer_helper_.get(); } diff --git a/chromium/media/gpu/ipc/service/vda_video_decoder.h b/chromium/media/gpu/ipc/service/vda_video_decoder.h index 83b8653094c..12f0b1ac23e 100644 --- a/chromium/media/gpu/ipc/service/vda_video_decoder.h +++ b/chromium/media/gpu/ipc/service/vda_video_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -59,8 +59,9 @@ class VdaVideoDecoder : public VideoDecoder, // unique_ptr<VideoDecoder>. // // |get_stub_cb|: Callback to retrieve the CommandBufferStub that should be - // used for allocating textures and mailboxes. This callback will be - // called on the GPU thread. + // used for allocating textures and mailboxes. This is only used when + // |output_mode| is ALLOCATE. This callback will be called on the GPU + // thread. // // See VdaVideoDecoder() for other arguments. static std::unique_ptr<VideoDecoder> Create( @@ -70,7 +71,8 @@ class VdaVideoDecoder : public VideoDecoder, const gfx::ColorSpace& target_color_space, const gpu::GpuPreferences& gpu_preferences, const gpu::GpuDriverBugWorkarounds& gpu_workarounds, - GetStubCB get_stub_cb); + GetStubCB get_stub_cb, + VideoDecodeAccelerator::Config::OutputMode output_mode); VdaVideoDecoder(const VdaVideoDecoder&) = delete; VdaVideoDecoder& operator=(const VdaVideoDecoder&) = delete; @@ -90,6 +92,7 @@ class VdaVideoDecoder : public VideoDecoder, bool NeedsBitstreamConversion() const override; bool CanReadWithoutStalling() const override; int GetMaxDecodeRequests() const override; + bool FramesHoldExternalResources() const override; private: friend class VdaVideoDecoderTest; @@ -102,10 +105,21 @@ class VdaVideoDecoder : public VideoDecoder, // |media_log|: MediaLog object to log to. // |target_color_space|: Color space of the output device. // |create_picture_buffer_manager_cb|: PictureBufferManager factory. - // |create_command_buffer_helper_cb|: CommandBufferHelper factory. + // |create_command_buffer_helper_cb|: CommandBufferHelper factory. This is + // only used when |output_mode| is ALLOCATE. // |create_and_initialize_vda_cb|: VideoDecodeAccelerator factory. // |vda_capabilities|: Capabilities of the VDA that // |create_and_initialize_vda_cb| will produce. + // |output_mode|: How to manage memory for output frames: + // - ALLOCATE: output buffer allocation is expected to be done by a + // combination of the PictureBufferManager (for texture allocation, + // possibly) and the VDA when AssignPictureBuffers() is called. In this + // case, the VdaVideoDecoder will output Mailbox-backed VideoFrames. + // - IMPORT, output buffer allocation is done by the PictureBufferManager + // (to allocate GpuMemoryBuffers without textures) and these buffers are + // imported into the VDA by calling ImportBufferForPicture(). In this + // case, the VdaVideoDecoder will output GpuMemoryBuffer-backed + // VideoFrames. VdaVideoDecoder( scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner, scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner, @@ -114,7 +128,8 @@ class VdaVideoDecoder : public VideoDecoder, CreatePictureBufferManagerCB create_picture_buffer_manager_cb, CreateCommandBufferHelperCB create_command_buffer_helper_cb, CreateAndInitializeVdaCB create_and_initialize_vda_cb, - const VideoDecodeAccelerator::Capabilities& vda_capabilities); + const VideoDecodeAccelerator::Capabilities& vda_capabilities, + VideoDecodeAccelerator::Config::OutputMode output_mode); // media::VideoDecodeAccelerator::Client implementation. void NotifyInitializationComplete(DecoderStatus status) override; @@ -123,6 +138,12 @@ class VdaVideoDecoder : public VideoDecoder, uint32_t textures_per_buffer, const gfx::Size& dimensions, uint32_t texture_target) override; + void ProvidePictureBuffersWithVisibleRect(uint32_t requested_num_of_buffers, + VideoPixelFormat format, + uint32_t textures_per_buffer, + const gfx::Size& dimensions, + const gfx::Rect& visible_rect, + uint32_t texture_target) override; void DismissPictureBuffer(int32_t picture_buffer_id) override; void PictureReady(const Picture& picture) override; void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override; @@ -167,6 +188,7 @@ class VdaVideoDecoder : public VideoDecoder, CreateCommandBufferHelperCB create_command_buffer_helper_cb_; CreateAndInitializeVdaCB create_and_initialize_vda_cb_; const VideoDecodeAccelerator::Capabilities vda_capabilities_; + const VideoDecodeAccelerator::Config::OutputMode output_mode_; // // Parent thread state. diff --git a/chromium/media/gpu/ipc/service/vda_video_decoder_unittest.cc b/chromium/media/gpu/ipc/service/vda_video_decoder_unittest.cc index 4755884b259..0a97765164c 100644 --- a/chromium/media/gpu/ipc/service/vda_video_decoder_unittest.cc +++ b/chromium/media/gpu/ipc/service/vda_video_decoder_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -107,7 +107,8 @@ class VdaVideoDecoderTest : public testing::TestWithParam<bool> { base::Unretained(this)), base::BindRepeating(&VdaVideoDecoderTest::CreateAndInitializeVda, base::Unretained(this)), - GetCapabilities()); + GetCapabilities(), + VideoDecodeAccelerator::Config::OutputMode::ALLOCATE); vdavd_ = std::make_unique<AsyncDestroyVideoDecoder<VdaVideoDecoder>>( base::WrapUnique(vdavd)); client_ = vdavd; @@ -280,7 +281,8 @@ class VdaVideoDecoderTest : public testing::TestWithParam<bool> { scoped_refptr<PictureBufferManager> CreatePictureBufferManager( PictureBufferManager::ReusePictureBufferCB reuse_cb) { DCHECK(!pbm_); - pbm_ = PictureBufferManager::Create(std::move(reuse_cb)); + pbm_ = PictureBufferManager::Create(/*allocate_gpu_memory_buffers=*/false, + std::move(reuse_cb)); return pbm_; } diff --git a/chromium/media/gpu/mac/BUILD.gn b/chromium/media/gpu/mac/BUILD.gn index b537122064d..160394ce3df 100644 --- a/chromium/media/gpu/mac/BUILD.gn +++ b/chromium/media/gpu/mac/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2019 The Chromium Authors. All rights reserved. +# Copyright 2019 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter.cc b/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter.cc index a760ddc7509..c3cd4b4df38 100644 --- a/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter.cc +++ b/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter.h b/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter.h index 5019fe81292..51a4e1a5b5d 100644 --- a/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter.h +++ b/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter_unittest.cc b/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter_unittest.cc index 22286d7f863..91b8ed43e93 100644 --- a/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter_unittest.cc +++ b/chromium/media/gpu/mac/vp9_super_frame_bitstream_filter_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/mac/vt_config_util.h b/chromium/media/gpu/mac/vt_config_util.h index ea86e465f56..8e4f7eaea8e 100644 --- a/chromium/media/gpu/mac/vt_config_util.h +++ b/chromium/media/gpu/mac/vt_config_util.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/mac/vt_config_util.mm b/chromium/media/gpu/mac/vt_config_util.mm index 5977ce5bc62..1a99fdbe34b 100644 --- a/chromium/media/gpu/mac/vt_config_util.mm +++ b/chromium/media/gpu/mac/vt_config_util.mm @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,7 @@ #include "base/mac/foundation_util.h" #include "media/base/mac/color_space_util_mac.h" +#include "ui/gfx/hdr_metadata_mac.h" namespace { @@ -137,10 +138,9 @@ CFStringRef GetMatrix(media::VideoColorSpace::MatrixID matrix_id) { void SetContentLightLevelInfo(const gfx::HDRMetadata& hdr_metadata, NSMutableDictionary<NSString*, id>* extensions) { - SetDictionaryValue(extensions, - kCMFormatDescriptionExtension_ContentLightLevelInfo, - base::mac::CFToNSCast( - media::GenerateContentLightLevelInfo(hdr_metadata))); + SetDictionaryValue( + extensions, kCMFormatDescriptionExtension_ContentLightLevelInfo, + base::mac::CFToNSCast(gfx::GenerateContentLightLevelInfo(hdr_metadata))); } void SetColorVolumeMetadata(const gfx::HDRMetadata& hdr_metadata, @@ -148,7 +148,7 @@ void SetColorVolumeMetadata(const gfx::HDRMetadata& hdr_metadata, SetDictionaryValue( extensions, kCMFormatDescriptionExtension_MasteringDisplayColorVolume, base::mac::CFToNSCast( - media::GenerateMasteringDisplayColorVolume(hdr_metadata))); + gfx::GenerateMasteringDisplayColorVolume(hdr_metadata))); } void SetVp9CodecConfigurationBox( diff --git a/chromium/media/gpu/mac/vt_config_util_unittest.cc b/chromium/media/gpu/mac/vt_config_util_unittest.cc index f56c45267d0..28830391976 100644 --- a/chromium/media/gpu/mac/vt_config_util_unittest.cc +++ b/chromium/media/gpu/mac/vt_config_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/mac/vt_video_decode_accelerator_mac.cc b/chromium/media/gpu/mac/vt_video_decode_accelerator_mac.cc index da5ca206ed0..b3b3a4a4943 100644 --- a/chromium/media/gpu/mac/vt_video_decode_accelerator_mac.cc +++ b/chromium/media/gpu/mac/vt_video_decode_accelerator_mac.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,12 +10,13 @@ #include <OpenGL/gl.h> #include <stddef.h> -#include <algorithm> #include <iterator> #include <memory> #include "base/atomic_sequence_num.h" #include "base/bind.h" +#include "base/containers/contains.h" +#include "base/containers/span.h" #include "base/cxx17_backports.h" #include "base/logging.h" #include "base/mac/mac_logging.h" @@ -68,6 +69,9 @@ namespace media { namespace { +// Parameter sets vector contain all PPSs/SPSs(/VPSs) +using ParameterSets = std::vector<base::span<const uint8_t>>; + // A sequence of ids for memory tracing. base::AtomicSequenceNumber g_memory_dump_ids; @@ -144,7 +148,8 @@ constexpr int kMinOutputsBeforeRASL = 5; // Build an |image_config| dictionary for VideoToolbox initialization. base::ScopedCFTypeRef<CFMutableDictionaryRef> BuildImageConfig( CMVideoDimensions coded_dimensions, - bool is_hbd) { + bool is_hbd, + bool has_alpha) { base::ScopedCFTypeRef<CFMutableDictionaryRef> image_config; // Note that 4:2:0 textures cannot be used directly as RGBA in OpenGL, but are @@ -152,6 +157,11 @@ base::ScopedCFTypeRef<CFMutableDictionaryRef> BuildImageConfig( int32_t pixel_format = is_hbd ? kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange : kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange; + // macOS support 8 bit (they actually only recommand main profile) + // HEVC with alpha layer well. + if (has_alpha) + pixel_format = kCVPixelFormatType_32BGRA; + #define CFINT(i) CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &i) base::ScopedCFTypeRef<CFNumberRef> cf_pixel_format(CFINT(pixel_format)); base::ScopedCFTypeRef<CFNumberRef> cf_width(CFINT(coded_dimensions.width)); @@ -176,26 +186,20 @@ base::ScopedCFTypeRef<CFMutableDictionaryRef> BuildImageConfig( } #if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER) -// Create a CMFormatDescription using the provided |pps|, |sps| and |vps|. +// Create a CMFormatDescription using the provided |param_sets|. base::ScopedCFTypeRef<CMFormatDescriptionRef> CreateVideoFormatHEVC( - const std::vector<uint8_t>& vps, - const std::vector<uint8_t>& sps, - const std::vector<uint8_t>& pps) { - DCHECK(!vps.empty()); - DCHECK(!sps.empty()); - DCHECK(!pps.empty()); + ParameterSets param_sets) { + DCHECK(!param_sets.empty()); // Build the configuration records. std::vector<const uint8_t*> nalu_data_ptrs; std::vector<size_t> nalu_data_sizes; - nalu_data_ptrs.reserve(3); - nalu_data_sizes.reserve(3); - nalu_data_ptrs.push_back(&vps.front()); - nalu_data_sizes.push_back(vps.size()); - nalu_data_ptrs.push_back(&sps.front()); - nalu_data_sizes.push_back(sps.size()); - nalu_data_ptrs.push_back(&pps.front()); - nalu_data_sizes.push_back(pps.size()); + nalu_data_ptrs.reserve(param_sets.size()); + nalu_data_sizes.reserve(param_sets.size()); + for (auto& param : param_sets) { + nalu_data_ptrs.push_back(param.data()); + nalu_data_sizes.push_back(param.size()); + } // For some unknown reason, even if apple has claimed that this API is // available after macOS 10.13, however base on the result on macOS 10.15.7, @@ -206,10 +210,10 @@ base::ScopedCFTypeRef<CMFormatDescriptionRef> CreateVideoFormatHEVC( if (__builtin_available(macOS 11.0, *)) { OSStatus status = CMVideoFormatDescriptionCreateFromHEVCParameterSets( kCFAllocatorDefault, - nalu_data_ptrs.size(), // parameter_set_count - &nalu_data_ptrs.front(), // ¶meter_set_pointers - &nalu_data_sizes.front(), // ¶meter_set_sizes - kNALUHeaderLength, // nal_unit_header_length + nalu_data_ptrs.size(), // parameter_set_count + nalu_data_ptrs.data(), // ¶meter_set_pointers + nalu_data_sizes.data(), // ¶meter_set_sizes + kNALUHeaderLength, // nal_unit_header_length NULL, format.InitializeInto()); OSSTATUS_DLOG_IF(WARNING, status != noErr, status) << "CMVideoFormatDescriptionCreateFromHEVCParameterSets()"; @@ -283,6 +287,7 @@ bool CreateVideoToolboxSession( const CMFormatDescriptionRef format, bool require_hardware, bool is_hbd, + bool has_alpha, const VTDecompressionOutputCallbackRecord* callback, base::ScopedCFTypeRef<VTDecompressionSessionRef>* session, gfx::Size* configured_size) { @@ -314,7 +319,7 @@ bool CreateVideoToolboxSession( base::ClampFloor(visible_rect.size.width), base::ClampFloor(visible_rect.size.height)}; base::ScopedCFTypeRef<CFMutableDictionaryRef> image_config( - BuildImageConfig(visible_dimensions, is_hbd)); + BuildImageConfig(visible_dimensions, is_hbd, has_alpha)); if (!image_config) { DLOG(ERROR) << "Failed to create decoder image configuration"; return false; @@ -358,8 +363,8 @@ bool InitializeVideoToolboxInternal() { if (!CreateVideoToolboxSession( CreateVideoFormatH264(sps_h264_normal, std::vector<uint8_t>(), pps_h264_normal), - /*require_hardware=*/true, /*is_hbd=*/false, &callback, &session, - &configured_size)) { + /*require_hardware=*/true, /*is_hbd=*/false, /*has_alpha=*/false, + &callback, &session, &configured_size)) { DVLOG(1) << "Hardware H264 decoding with VideoToolbox is not supported"; return false; } @@ -375,8 +380,8 @@ bool InitializeVideoToolboxInternal() { if (!CreateVideoToolboxSession( CreateVideoFormatH264(sps_h264_small, std::vector<uint8_t>(), pps_h264_small), - /*require_hardware=*/false, /*is_hbd=*/false, &callback, &session, - &configured_size)) { + /*require_hardware=*/false, /*is_hbd=*/false, /*has_alpha=*/false, + &callback, &session, &configured_size)) { DVLOG(1) << "Software H264 decoding with VideoToolbox is not supported"; return false; } @@ -390,8 +395,8 @@ bool InitializeVideoToolboxInternal() { if (!CreateVideoToolboxSession( CreateVideoFormatVP9(VideoColorSpace::REC709(), VP9PROFILE_PROFILE0, absl::nullopt, gfx::Size(720, 480)), - /*require_hardware=*/true, /*is_hbd=*/false, &callback, &session, - &configured_size)) { + /*require_hardware=*/true, /*is_hbd=*/false, /*has_alpha=*/false, + &callback, &session, &configured_size)) { DVLOG(1) << "Hardware VP9 decoding with VideoToolbox is not supported"; // We don't return false here since VP9 support is optional. @@ -424,10 +429,10 @@ bool InitializeVideoToolboxInternal() { 0xb4, 0x62, 0x40}; if (!CreateVideoToolboxSession( - CreateVideoFormatHEVC(vps_hevc_normal, sps_hevc_normal, - pps_hevc_normal), - /*require_hardware=*/true, /*is_hbd=*/false, &callback, &session, - &configured_size)) { + CreateVideoFormatHEVC(ParameterSets( + {vps_hevc_normal, sps_hevc_normal, pps_hevc_normal})), + /*require_hardware=*/true, /*is_hbd=*/false, /*has_alpha=*/false, + &callback, &session, &configured_size)) { DVLOG(1) << "Hardware HEVC decoding with VideoToolbox is not supported"; // We don't return false here since HEVC support is optional. @@ -453,10 +458,10 @@ bool InitializeVideoToolboxInternal() { 0xb4, 0x62, 0x40}; if (!CreateVideoToolboxSession( - CreateVideoFormatHEVC(vps_hevc_small, sps_hevc_small, - pps_hevc_small), - /*require_hardware=*/false, /*is_hbd=*/false, &callback, &session, - &configured_size)) { + CreateVideoFormatHEVC(ParameterSets( + {vps_hevc_small, sps_hevc_small, pps_hevc_small})), + /*require_hardware=*/false, /*is_hbd=*/false, /*has_alpha=*/false, + &callback, &session, &configured_size)) { DVLOG(1) << "Software HEVC decoding with VideoToolbox is not supported"; // We don't return false here since HEVC support is optional. @@ -736,10 +741,8 @@ bool VTVideoDecodeAccelerator::Initialize(const Config& config, static const base::NoDestructor<VideoDecodeAccelerator::SupportedProfiles> kActualSupportedProfiles(GetSupportedProfiles(workarounds_)); - if (std::find_if(kActualSupportedProfiles->begin(), - kActualSupportedProfiles->end(), [config](const auto& p) { - return p.profile == config.profile; - }) == kActualSupportedProfiles->end()) { + if (!base::Contains(*kActualSupportedProfiles, config.profile, + &VideoDecodeAccelerator::SupportedProfile::profile)) { DVLOG(2) << "Unsupported profile"; return false; } @@ -806,9 +809,17 @@ bool VTVideoDecodeAccelerator::ConfigureDecoder() { format = CreateVideoFormatH264(active_sps_, active_spsext_, active_pps_); break; #if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER) - case VideoCodec::kHEVC: - format = CreateVideoFormatHEVC(active_vps_, active_sps_, active_pps_); + case VideoCodec::kHEVC: { + ParameterSets param_sets; + for (auto& it : seen_vps_) + param_sets.push_back(it.second); + for (auto& it : seen_sps_) + param_sets.push_back(it.second); + for (auto& it : seen_pps_) + param_sets.push_back(it.second); + format = CreateVideoFormatHEVC(param_sets); break; + } #endif // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER) case VideoCodec::kVP9: format = CreateVideoFormatVP9( @@ -848,8 +859,8 @@ bool VTVideoDecodeAccelerator::ConfigureDecoder() { const bool is_hbd = config_.profile == VP9PROFILE_PROFILE2 || config_.profile == HEVCPROFILE_MAIN10 || config_.profile == HEVCPROFILE_REXT; - if (!CreateVideoToolboxSession(format_, require_hardware, is_hbd, &callback_, - &session_, &configured_size_)) { + if (!CreateVideoToolboxSession(format_, require_hardware, is_hbd, has_alpha_, + &callback_, &session_, &configured_size_)) { NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); return false; } @@ -871,7 +882,13 @@ bool VTVideoDecodeAccelerator::ConfigureDecoder() { // Record that the configuration change is complete. #if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER) - configured_vps_ = active_vps_; + // Actually seen vps/sps/pps may contain outdated parameter + // sets, VideoToolbox perhaps can handle this well since those + // outdated ones are not referenced by current pictures. + // Let's see what will happens in this way. + configured_vpss_ = seen_vps_; + configured_spss_ = seen_sps_; + configured_ppss_ = seen_pps_; #endif // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER) configured_sps_ = active_sps_; configured_spsext_ = active_spsext_; @@ -1176,6 +1193,9 @@ void VTVideoDecodeAccelerator::DecodeTaskH264( return; } else { // Only |data| and |size| are read later, other fields are left empty. + // In case that their are new PPS/SPS/SPSext appears after an IDR, or + // videos that have multiple PPSs and we are referring to the one that + // is not used to create video format. media::H264NALU sps_nalu; sps_nalu.data = active_sps_.data(); sps_nalu.size = active_sps_.size(); @@ -1198,6 +1218,12 @@ void VTVideoDecodeAccelerator::DecodeTaskH264( nalus.insert(nalus.begin() + first_slice_index, pps_nalu); data_size += kNALUHeaderLength + pps_nalu.size; first_slice_index += 1; + + // Update the configured SPS/SPSext/PPS in case VT referrence to the wrong + // parameter sets. + configured_sps_ = active_sps_; + configured_spsext_ = active_spsext_; + configured_pps_ = active_pps_; } } @@ -1315,6 +1341,11 @@ void VTVideoDecodeAccelerator::DecodeTaskHEVC( // from the previous one if dependent_slice_segment_flag exists std::unique_ptr<H265SliceHeader> curr_slice_hdr; std::unique_ptr<H265SliceHeader> last_slice_hdr; + size_t first_slice_index = 0; + // ID of the VPS/SPS/PPS that most recently activated by an IDR. + int active_vps_id = 0; + int active_sps_id = 0; + int active_pps_id = 0; hevc_parser_.SetStream(buffer->data(), buffer->data_size()); H265NALU nalu; while (true) { @@ -1337,13 +1368,6 @@ void VTVideoDecodeAccelerator::DecodeTaskHEVC( return; } - // 8.1.2 We only want nuh_layer_id of zero. - if (nalu.nuh_layer_id) { - MEDIA_LOG(INFO, media_log_) - << "Skipping NALU with nuh_layer_id=" << nalu.nuh_layer_id; - continue; - } - switch (nalu.nal_unit_type) { case H265NALU::SPS_NUT: { int sps_id = -1; @@ -1382,11 +1406,6 @@ void VTVideoDecodeAccelerator::DecodeTaskHEVC( return; } seen_pps_[pps_id].assign(nalu.data, nalu.data + nalu.size); - // Pass PPS as data to the platform decoder, it helps in cases - // when there are more than one PPS, Video Toolbox is smart enough - // to find and recognize them there. - nalus.push_back(nalu); - data_size += kNALUHeaderLength + nalu.size; break; } @@ -1406,6 +1425,20 @@ void VTVideoDecodeAccelerator::DecodeTaskHEVC( seen_vps_[vps_id].assign(nalu.data, nalu.data + nalu.size); break; } + + case H265NALU::PREFIX_SEI_NUT: { + H265SEIMessage sei_msg; + result = hevc_parser_.ParseSEI(&sei_msg); + if (result == H265Parser::kOk && + sei_msg.type == H265SEIMessage::kSEIAlphaChannelInfo && + sei_msg.alpha_channel_info.alpha_channel_cancel_flag == 0) { + has_alpha_ = true; + } + nalus.push_back(nalu); + data_size += kNALUHeaderLength + nalu.size; + break; + } + case H265NALU::EOS_NUT: hevc_poc_.Reset(); nalus.push_back(nalu); @@ -1491,12 +1524,15 @@ void VTVideoDecodeAccelerator::DecodeTaskHEVC( } // Record the configuration. - DCHECK(seen_pps_.contains(curr_slice_hdr->slice_pic_parameter_set_id)); - DCHECK(seen_sps_.contains(pps->pps_seq_parameter_set_id)); - DCHECK(seen_vps_.contains(sps->sps_video_parameter_set_id)); - active_vps_ = seen_vps_[sps->sps_video_parameter_set_id]; - active_sps_ = seen_sps_[pps->pps_seq_parameter_set_id]; - active_pps_ = seen_pps_[curr_slice_hdr->slice_pic_parameter_set_id]; + active_vps_id = sps->sps_video_parameter_set_id; + active_sps_id = pps->pps_seq_parameter_set_id; + active_pps_id = curr_slice_hdr->slice_pic_parameter_set_id; + DCHECK(seen_vps_.contains(active_vps_id)); + DCHECK(seen_sps_.contains(active_sps_id)); + DCHECK(seen_pps_.contains(active_pps_id)); + active_vps_ = seen_vps_[active_vps_id]; + active_sps_ = seen_sps_[active_sps_id]; + active_pps_ = seen_pps_[active_pps_id]; // Compute and store frame properties. |image_size| gets filled in // later, since it comes from the decoder configuration. @@ -1509,6 +1545,8 @@ void VTVideoDecodeAccelerator::DecodeTaskHEVC( frame->pic_order_cnt = pic_order_cnt; frame->reorder_window = ComputeHEVCReorderWindow(vps); + first_slice_index = nalus.size(); + last_slice_hdr.swap(curr_slice_hdr); curr_slice_hdr.reset(); [[fallthrough]]; @@ -1524,7 +1562,7 @@ void VTVideoDecodeAccelerator::DecodeTaskHEVC( waiting_for_idr_ = false; // If no IDR has been seen yet, skip decoding. Note that Flash sends - // configuration changes as a bitstream with only SPS/PPS; we don't print + // configuration changes as a bitstream with only SPS/PPS/VPS; we don't print // error messages for those. if (frame->has_slice && waiting_for_idr_) { if (!missing_idr_logged_) { @@ -1547,31 +1585,64 @@ void VTVideoDecodeAccelerator::DecodeTaskHEVC( // Apply any configuration change, but only at an IDR. If there is no IDR, we // just hope for the best from the decoder. - if (frame->is_idr && - (configured_vps_ != active_vps_ || configured_sps_ != active_sps_ || - configured_pps_ != active_pps_)) { - if (active_vps_.empty()) { - WriteToMediaLog(MediaLogMessageLevel::kERROR, - "Invalid configuration (no VPS)"); - NotifyError(INVALID_ARGUMENT, SFT_INVALID_STREAM); - return; - } - if (active_sps_.empty()) { - WriteToMediaLog(MediaLogMessageLevel::kERROR, - "Invalid configuration (no SPS)"); - NotifyError(INVALID_ARGUMENT, SFT_INVALID_STREAM); - return; - } - if (active_pps_.empty()) { - WriteToMediaLog(MediaLogMessageLevel::kERROR, - "Invalid configuration (no PPS)"); - NotifyError(INVALID_ARGUMENT, SFT_INVALID_STREAM); - return; - } + if (seen_vps_ != configured_vpss_ || seen_sps_ != configured_spss_ || + seen_pps_ != configured_ppss_) { + if (frame->is_idr) { + if (seen_vps_.empty()) { + WriteToMediaLog(MediaLogMessageLevel::kERROR, + "Invalid configuration (no VPS)"); + NotifyError(INVALID_ARGUMENT, SFT_INVALID_STREAM); + return; + } + if (seen_sps_.empty()) { + WriteToMediaLog(MediaLogMessageLevel::kERROR, + "Invalid configuration (no SPS)"); + NotifyError(INVALID_ARGUMENT, SFT_INVALID_STREAM); + return; + } + if (seen_pps_.empty()) { + WriteToMediaLog(MediaLogMessageLevel::kERROR, + "Invalid configuration (no PPS)"); + NotifyError(INVALID_ARGUMENT, SFT_INVALID_STREAM); + return; + } - // ConfigureDecoder() calls NotifyError() on failure. - if (!ConfigureDecoder()) { - return; + // ConfigureDecoder() calls NotifyError() on failure. + if (!ConfigureDecoder()) { + return; + } + } else { + // Only |data| and |size| are read later, other fields are left empty. + // In case that their are new VPS/SPS/PPS appears after an IDR. + media::H265NALU vps_nalu; + vps_nalu.data = active_vps_.data(); + vps_nalu.size = active_vps_.size(); + nalus.insert(nalus.begin() + first_slice_index, vps_nalu); + data_size += kNALUHeaderLength + vps_nalu.size; + first_slice_index += 1; + + media::H265NALU sps_nalu; + sps_nalu.data = active_sps_.data(); + sps_nalu.size = active_sps_.size(); + nalus.insert(nalus.begin() + first_slice_index, sps_nalu); + data_size += kNALUHeaderLength + sps_nalu.size; + first_slice_index += 1; + + media::H265NALU pps_nalu; + pps_nalu.data = active_pps_.data(); + pps_nalu.size = active_pps_.size(); + nalus.insert(nalus.begin() + first_slice_index, pps_nalu); + data_size += kNALUHeaderLength + pps_nalu.size; + first_slice_index += 1; + + // Update the configured VPSs/SPSs/PPSs in case VT referrence to the wrong + // parameter sets. + configured_vpss_[active_vps_id].assign( + active_vps_.data(), active_vps_.data() + active_vps_.size()); + configured_spss_[active_sps_id].assign( + active_sps_.data(), active_sps_.data() + active_sps_.size()); + configured_ppss_[active_pps_id].assign( + active_pps_.data(), active_pps_.data() + active_pps_.size()); } } @@ -2056,16 +2127,19 @@ bool VTVideoDecodeAccelerator::ProcessFrame(const Frame& frame) { // Request new pictures. picture_size_ = frame.image_size; - // TODO(https://crbug.com/1210994): Remove RGBAF16 support, and expose only - // PIXEL_FORMAT_NV12 and PIXEL_FORMAT_YUV420P10. - picture_format_ = PIXEL_FORMAT_RGBAF16; - if (base::FeatureList::IsEnabled(kMultiPlaneVideoToolboxSharedImages)) { - // TODO(https://crbug.com/1233228): The UV planes of P010 frames cannot - // be represented in the current gfx::BufferFormat. - if (config_.profile != VP9PROFILE_PROFILE2 && - config_.profile != HEVCPROFILE_MAIN10 && - config_.profile != HEVCPROFILE_REXT) - picture_format_ = PIXEL_FORMAT_NV12; + // ARGB is required to make alpha video has a non-transparent background + // when playing in PiP mode. + if (has_alpha_) { + buffer_format_ = gfx::BufferFormat::BGRA_8888; + picture_format_ = PIXEL_FORMAT_ARGB; + } else if (config_.profile == VP9PROFILE_PROFILE2 || + config_.profile == HEVCPROFILE_MAIN10 || + config_.profile == HEVCPROFILE_REXT) { + buffer_format_ = gfx::BufferFormat::P010; + picture_format_ = PIXEL_FORMAT_P016LE; + } else { + buffer_format_ = gfx::BufferFormat::YUV_420_BIPLANAR; + picture_format_ = PIXEL_FORMAT_NV12; } DVLOG(3) << "ProvidePictureBuffers(" << kNumPictureBuffers @@ -2093,61 +2167,46 @@ bool VTVideoDecodeAccelerator::SendFrame(const Frame& frame) { PictureInfo* picture_info = it->second.get(); DCHECK(picture_info->gl_images.empty()); - const gfx::BufferFormat buffer_format = - config_.profile == VP9PROFILE_PROFILE2 || - config_.profile == HEVCPROFILE_MAIN10 || - config_.profile == HEVCPROFILE_REXT - ? gfx::BufferFormat::P010 - : gfx::BufferFormat::YUV_420_BIPLANAR; - gfx::ColorSpace color_space = GetImageBufferColorSpace(frame.image); - + const gfx::ColorSpace color_space = GetImageBufferColorSpace(frame.image); std::vector<gfx::BufferPlane> planes; switch (picture_format_) { case PIXEL_FORMAT_NV12: - case PIXEL_FORMAT_YUV420P10: + case PIXEL_FORMAT_P016LE: planes.push_back(gfx::BufferPlane::Y); planes.push_back(gfx::BufferPlane::UV); break; - case PIXEL_FORMAT_RGBAF16: + case PIXEL_FORMAT_ARGB: planes.push_back(gfx::BufferPlane::DEFAULT); break; default: NOTREACHED(); break; } - for (size_t plane = 0; plane < planes.size(); ++plane) { const gfx::Size plane_size( CVPixelBufferGetWidthOfPlane(frame.image.get(), plane), CVPixelBufferGetHeightOfPlane(frame.image.get(), plane)); gfx::BufferFormat plane_buffer_format = - gpu::GetPlaneBufferFormat(planes[plane], buffer_format); - // TODO(https://crbug.com/1108909): BGRA is not an appropriate value for - // these parameters. + gpu::GetPlaneBufferFormat(planes[plane], buffer_format_); const viz::ResourceFormat viz_resource_format = - (picture_format_ == PIXEL_FORMAT_RGBAF16) - ? viz::ResourceFormat::RGBA_F16 - : viz::GetResourceFormat(plane_buffer_format); + viz::GetResourceFormat(plane_buffer_format); const GLenum gl_format = viz::GLDataFormat(viz_resource_format); scoped_refptr<gl::GLImageIOSurface> gl_image( - gl::GLImageIOSurface::Create(plane_size, gl_format)); + gl::GLImageIOSurface::Create(plane_size)); if (!gl_image->InitializeWithCVPixelBuffer( frame.image.get(), plane, gfx::GenericSharedMemoryId(g_cv_pixel_buffer_ids.GetNext()), - plane_buffer_format)) { + plane_buffer_format, color_space)) { NOTIFY_STATUS("Failed to initialize GLImageIOSurface", PLATFORM_FAILURE, SFT_PLATFORM_ERROR); } - gl_image->DisableInUseByWindowServer(); - gl_image->SetColorSpaceForYUVToRGBConversion(color_space); - gl_image->SetColorSpaceShallow(color_space); if (picture_info->uses_shared_images) { gpu::SharedImageStub* shared_image_stub = client_->GetSharedImageStub(); DCHECK(shared_image_stub); - const uint32_t shared_image_usage = - gpu::SHARED_IMAGE_USAGE_DISPLAY | gpu::SHARED_IMAGE_USAGE_SCANOUT; + const uint32_t shared_image_usage = gpu::SHARED_IMAGE_USAGE_DISPLAY_READ | + gpu::SHARED_IMAGE_USAGE_SCANOUT; gpu::Mailbox mailbox = gpu::Mailbox::GenerateForSharedImage(); gpu::GLTextureImageBackingHelper::InitializeGLTextureParams gl_params; @@ -2170,12 +2229,13 @@ bool VTVideoDecodeAccelerator::SendFrame(const Frame& frame) { } auto shared_image = std::make_unique<gpu::GLImageBacking>( - gl_image, mailbox, viz_resource_format, plane_size, color_space, - kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, shared_image_usage, - gl_params, gl_client_.is_passthrough); + gl_image, mailbox, + viz::SharedImageFormat::SinglePlane(viz_resource_format), plane_size, + color_space, kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, + shared_image_usage, gl_params, gl_client_.is_passthrough); const bool success = shared_image_stub->factory()->RegisterBacking( - std::move(shared_image), /*allow_legacy_mailbox=*/false); + std::move(shared_image)); if (!success) { DLOG(ERROR) << "Failed to register shared image"; NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); diff --git a/chromium/media/gpu/mac/vt_video_decode_accelerator_mac.h b/chromium/media/gpu/mac/vt_video_decode_accelerator_mac.h index 178f21f5549..ebee56c1fae 100644 --- a/chromium/media/gpu/mac/vt_video_decode_accelerator_mac.h +++ b/chromium/media/gpu/mac/vt_video_decode_accelerator_mac.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -265,6 +265,9 @@ class VTVideoDecodeAccelerator : public VideoDecodeAccelerator, // Format of the assigned picture buffers. VideoPixelFormat picture_format_ = PIXEL_FORMAT_UNKNOWN; + // Corresponding GpuMemoryBuffer format. + gfx::BufferFormat buffer_format_ = gfx::BufferFormat::YUV_420_BIPLANAR; + // Frames that have not yet been decoded, keyed by bitstream ID; maintains // ownership of Frame objects while they flow through VideoToolbox. base::flat_map<int32_t, std::unique_ptr<Frame>> pending_frames_; @@ -315,8 +318,13 @@ class VTVideoDecodeAccelerator : public VideoDecodeAccelerator, base::flat_map<int, std::vector<uint8_t>> seen_vps_; // VPS most recently activated by an IDR. std::vector<uint8_t> active_vps_; - // VPS the decoder is currently confgured with. - std::vector<uint8_t> configured_vps_; + + // VPSs the decoder is currently confgured with. + base::flat_map<int, std::vector<uint8_t>> configured_vpss_; + // SPSs the decoder is currently confgured with. + base::flat_map<int, std::vector<uint8_t>> configured_spss_; + // PPSs the decoder is currently confgured with. + base::flat_map<int, std::vector<uint8_t>> configured_ppss_; H265POC hevc_poc_; #endif // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER) @@ -330,6 +338,10 @@ class VTVideoDecodeAccelerator : public VideoDecodeAccelerator, bool waiting_for_idr_ = true; bool missing_idr_logged_ = false; + // currently only HEVC is supported, VideoToolbox doesn't + // support VP9 with alpha for now. + bool has_alpha_ = false; + // Used to accumulate the output picture count as a workaround to solve // the VT CRA/RASL bug uint64_t output_count_for_cra_rasl_workaround_ = 0; diff --git a/chromium/media/gpu/mac/vt_video_encode_accelerator_mac.cc b/chromium/media/gpu/mac/vt_video_encode_accelerator_mac.cc index 965e3986fb0..1020df4e969 100644 --- a/chromium/media/gpu/mac/vt_video_encode_accelerator_mac.cc +++ b/chromium/media/gpu/mac/vt_video_encode_accelerator_mac.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,11 +6,13 @@ #include <memory> +#include "base/containers/contains.h" #include "base/logging.h" #include "base/mac/foundation_util.h" #include "base/mac/mac_logging.h" #include "base/memory/shared_memory_mapping.h" #include "base/memory/unsafe_shared_memory_region.h" +#include "base/numerics/safe_conversions.h" #include "base/task/thread_pool.h" #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" @@ -60,19 +62,60 @@ static CFStringRef VideoCodecProfileToVTProfile(VideoCodecProfile profile) { return kVTProfileLevel_H264_Baseline_AutoLevel; } -} // namespace +base::ScopedCFTypeRef<CFArrayRef> CreateRateLimitArray(const Bitrate& bitrate) { + std::vector<CFNumberRef> limits; + switch (bitrate.mode()) { + case Bitrate::Mode::kConstant: { + // CBR should be enforces with granularity of a second. + float target_interval = 1.0; + int32_t target_bitrate = bitrate.target_bps() / kBitsPerByte; + + limits.push_back( + CFNumberCreate(nullptr, kCFNumberSInt32Type, &target_bitrate)); + limits.push_back( + CFNumberCreate(nullptr, kCFNumberFloat32Type, &target_interval)); + break; + } + case Bitrate::Mode::kVariable: { + // 5 seconds should be an okay interval for VBR to enforce the long-term + // limit. + float avg_interval = 5.0; + int32_t avg_bitrate = base::saturated_cast<int32_t>( + bitrate.target_bps() / kBitsPerByte * avg_interval); + + // And the peak bitrate is measured per-second in a way similar to CBR. + float peak_interval = 1.0; + int32_t peak_bitrate = bitrate.peak_bps() / kBitsPerByte; + limits.push_back( + CFNumberCreate(nullptr, kCFNumberSInt32Type, &peak_bitrate)); + limits.push_back( + CFNumberCreate(nullptr, kCFNumberFloat32Type, &peak_interval)); + limits.push_back( + CFNumberCreate(nullptr, kCFNumberSInt32Type, &avg_bitrate)); + limits.push_back( + CFNumberCreate(nullptr, kCFNumberFloat32Type, &avg_interval)); + break; + } -struct VTVideoEncodeAccelerator::InProgressFrameEncode { - InProgressFrameEncode() = delete; + default: + NOTREACHED(); + } - InProgressFrameEncode(base::TimeDelta rtp_timestamp, base::TimeTicks ref_time) - : timestamp(rtp_timestamp), reference_time(ref_time) {} + base::ScopedCFTypeRef<CFArrayRef> result(CFArrayCreate( + kCFAllocatorDefault, reinterpret_cast<const void**>(limits.data()), + limits.size(), &kCFTypeArrayCallBacks)); + for (auto* number : limits) + CFRelease(number); + return result; +} - InProgressFrameEncode(const InProgressFrameEncode&) = delete; - InProgressFrameEncode& operator=(const InProgressFrameEncode&) = delete; +} // namespace + +struct VTVideoEncodeAccelerator::InProgressFrameEncode { + InProgressFrameEncode(base::TimeDelta rtp_timestamp) + : timestamp(rtp_timestamp) {} const base::TimeDelta timestamp; - const base::TimeTicks reference_time; }; struct VTVideoEncodeAccelerator::EncodeOutput { @@ -162,26 +205,6 @@ VTVideoEncodeAccelerator::GetSupportedProfiles() { return profiles; } -VideoEncodeAccelerator::SupportedProfiles -VTVideoEncodeAccelerator::GetSupportedProfilesLight() { - DVLOG(3) << __func__; - DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_); - - SupportedProfiles profiles; - - SupportedProfile profile; - profile.max_framerate_numerator = kMaxFrameRateNumerator; - profile.max_framerate_denominator = kMaxFrameRateDenominator; - profile.rate_control_modes = VideoEncodeAccelerator::kConstantMode | - VideoEncodeAccelerator::kVariableMode; - profile.max_resolution = gfx::Size(kMaxResolutionWidth, kMaxResolutionHeight); - for (const auto& supported_profile : kSupportedProfiles) { - profile.profile = supported_profile; - profiles.push_back(profile); - } - return profiles; -} - bool VTVideoEncodeAccelerator::Initialize(const Config& config, Client* client, std::unique_ptr<MediaLog> media_log) { @@ -199,8 +222,7 @@ bool VTVideoEncodeAccelerator::Initialize(const Config& config, << VideoPixelFormatToString(config.input_format); return false; } - if (std::find(std::begin(kSupportedProfiles), std::end(kSupportedProfiles), - config.output_profile) == std::end(kSupportedProfiles)) { + if (!base::Contains(kSupportedProfiles, config.output_profile)) { MEDIA_LOG(ERROR, media_log.get()) << "Output profile not supported= " << GetProfileName(config.output_profile); return false; @@ -327,23 +349,23 @@ void VTVideoEncodeAccelerator::EncodeTask(scoped_refptr<VideoFrame> frame, DCHECK(compression_session_); DCHECK(frame); - // TODO(emircan): See if we can eliminate a copy here by using - // CVPixelBufferPool for the allocation of incoming VideoFrames. - base::ScopedCFTypeRef<CVPixelBufferRef> pixel_buffer = - WrapVideoFrameInCVPixelBuffer(*frame); + auto pixel_buffer = WrapVideoFrameInCVPixelBuffer(frame); + if (!pixel_buffer) { + DLOG(ERROR) << "WrapVideoFrameInCVPixelBuffer failed."; + NotifyError(kPlatformFailureError); + return; + } base::ScopedCFTypeRef<CFDictionaryRef> frame_props = video_toolbox::DictionaryWithKeyValue( kVTEncodeFrameOptionKey_ForceKeyFrame, force_keyframe ? kCFBooleanTrue : kCFBooleanFalse); - base::TimeTicks ref_time = - frame->metadata().reference_time.value_or(base::TimeTicks::Now()); auto timestamp_cm = CMTimeMake(frame->timestamp().InMicroseconds(), USEC_PER_SEC); // Wrap information we'll need after the frame is encoded in a heap object. // We'll get the pointer back from the VideoToolbox completion callback. std::unique_ptr<InProgressFrameEncode> request( - new InProgressFrameEncode(frame->timestamp(), ref_time)); + new InProgressFrameEncode(frame->timestamp())); if (bitrate_.mode() == Bitrate::Mode::kConstant) { // In CBR mode, we adjust bitrate before every encode based on past history @@ -414,7 +436,7 @@ void VTVideoEncodeAccelerator::RequestEncodingParametersChangeTask( bitrate_ = bitrate; } -void VTVideoEncodeAccelerator::SetAdjustedConstantBitrate(int32_t bitrate) { +void VTVideoEncodeAccelerator::SetAdjustedConstantBitrate(uint32_t bitrate) { DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); if (bitrate == encoder_set_bitrate_) @@ -424,11 +446,11 @@ void VTVideoEncodeAccelerator::SetAdjustedConstantBitrate(int32_t bitrate) { video_toolbox::SessionPropertySetter session_property_setter( compression_session_); [[maybe_unused]] bool rv = session_property_setter.Set( - kVTCompressionPropertyKey_AverageBitRate, encoder_set_bitrate_); + kVTCompressionPropertyKey_AverageBitRate, + base::saturated_cast<int32_t>(encoder_set_bitrate_)); rv &= session_property_setter.Set( kVTCompressionPropertyKey_DataRateLimits, - video_toolbox::ArrayWithIntegerAndFloat( - encoder_set_bitrate_ / kBitsPerByte, 1.0f)); + CreateRateLimitArray(Bitrate::ConstantBitrate(bitrate))); DLOG_IF(ERROR, !rv) << "Couldn't change bitrate parameters of encode session."; } @@ -442,10 +464,8 @@ void VTVideoEncodeAccelerator::SetVariableBitrate(const Bitrate& bitrate) { [[maybe_unused]] bool rv = session_property_setter.Set(kVTCompressionPropertyKey_AverageBitRate, static_cast<int32_t>(bitrate.target_bps())); - rv &= - session_property_setter.Set(kVTCompressionPropertyKey_DataRateLimits, - video_toolbox::ArrayWithIntegerAndFloat( - bitrate.peak_bps() / kBitsPerByte, 1.0f)); + rv &= session_property_setter.Set(kVTCompressionPropertyKey_DataRateLimits, + CreateRateLimitArray(bitrate)); DLOG_IF(ERROR, !rv) << "Couldn't change bitrate parameters of encode session."; } diff --git a/chromium/media/gpu/mac/vt_video_encode_accelerator_mac.h b/chromium/media/gpu/mac/vt_video_encode_accelerator_mac.h index 7c69134c108..b1fd86a0a7c 100644 --- a/chromium/media/gpu/mac/vt_video_encode_accelerator_mac.h +++ b/chromium/media/gpu/mac/vt_video_encode_accelerator_mac.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -37,8 +37,6 @@ class MEDIA_GPU_EXPORT VTVideoEncodeAccelerator // VideoEncodeAccelerator implementation. VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() override; - VideoEncodeAccelerator::SupportedProfiles GetSupportedProfilesLight() - override; bool Initialize(const Config& config, Client* client, @@ -72,7 +70,7 @@ class MEDIA_GPU_EXPORT VTVideoEncodeAccelerator void DestroyTask(); // Helper functions to set bitrate. - void SetAdjustedConstantBitrate(int32_t bitrate); + void SetAdjustedConstantBitrate(uint32_t bitrate); void SetVariableBitrate(const Bitrate& bitrate); // Helper function to notify the client of an error on |client_task_runner_|. @@ -127,8 +125,8 @@ class MEDIA_GPU_EXPORT VTVideoEncodeAccelerator // bitrate mode no adjustments are needed. // Bitrate adjuster used to fix VideoToolbox's inconsistent bitrate issues. webrtc::BitrateAdjuster bitrate_adjuster_; - int32_t target_bitrate_ = 0; // User for CBR only - int32_t encoder_set_bitrate_ = 0; // User for CBR only + uint32_t target_bitrate_ = 0; // User for CBR only + uint32_t encoder_set_bitrate_ = 0; // User for CBR only // If True, the encoder fails initialization if setting of session's property // kVTCompressionPropertyKey_MaxFrameDelayCount returns an error. diff --git a/chromium/media/gpu/macros.h b/chromium/media/gpu/macros.h index e758332eccc..9d30f09682e 100644 --- a/chromium/media/gpu/macros.h +++ b/chromium/media/gpu/macros.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/media_gpu_export.h b/chromium/media/gpu/media_gpu_export.h index b5b80aae5c1..8c364dc6ddd 100644 --- a/chromium/media/gpu/media_gpu_export.h +++ b/chromium/media/gpu/media_gpu_export.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/sandbox/BUILD.gn b/chromium/media/gpu/sandbox/BUILD.gn index d9a745c1ca4..437a0f3445b 100644 --- a/chromium/media/gpu/sandbox/BUILD.gn +++ b/chromium/media/gpu/sandbox/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium Authors. All rights reserved. +# Copyright 2021 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/chromium/media/gpu/sandbox/OWNERS b/chromium/media/gpu/sandbox/OWNERS index 70554b270ab..57df6dc7ec4 100644 --- a/chromium/media/gpu/sandbox/OWNERS +++ b/chromium/media/gpu/sandbox/OWNERS @@ -1,2 +1,2 @@ set noparent -file://sandbox/OWNERS +file://sandbox/linux/OWNERS diff --git a/chromium/media/gpu/sandbox/hardware_video_decoding_sandbox_hook_linux.cc b/chromium/media/gpu/sandbox/hardware_video_decoding_sandbox_hook_linux.cc index 793be9e963e..25e31b629d2 100644 --- a/chromium/media/gpu/sandbox/hardware_video_decoding_sandbox_hook_linux.cc +++ b/chromium/media/gpu/sandbox/hardware_video_decoding_sandbox_hook_linux.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -72,10 +72,16 @@ bool HardwareVideoDecodingPreSandboxHook( BrokerFilePermission::ReadOnlyRecursive(path + "/")); } } +#endif // BUILDFLAG(USE_V4L2_CODEC) - // TODO(b/195769334): for now, this is only needed for two use cases: the - // legacy VaapiVideoDecodeAccelerator and AMD. However, we'll likely need this - // unconditionally so that we can allocate dma-bufs. + // TODO(b/195769334): consider using the type of client to decide if we should + // allow access to the render node: + // + // - If the client is ARC++/ARCVM, the render node is only needed for two + // cases, the legacy VaapiVideoDecodeAccelerator and AMD. + // + // - If the client is a Chrome renderer process, the render node is needed on + // ChromeOS to allocate output buffers. for (int i = 128; i <= 137; ++i) { const std::string path = base::StringPrintf("/dev/dri/renderD%d", i); struct stat st; @@ -85,7 +91,6 @@ bool HardwareVideoDecodingPreSandboxHook( : BrokerFilePermission::ReadOnly(path)); } } -#endif // BUILDFLAG(USE_V4L2_CODEC) sandbox::policy::SandboxLinux::GetInstance()->StartBrokerProcess( command_set, permissions, sandbox::policy::SandboxLinux::PreSandboxHook(), diff --git a/chromium/media/gpu/sandbox/hardware_video_decoding_sandbox_hook_linux.h b/chromium/media/gpu/sandbox/hardware_video_decoding_sandbox_hook_linux.h index 332c02e4d1b..7b90e3d3be7 100644 --- a/chromium/media/gpu/sandbox/hardware_video_decoding_sandbox_hook_linux.h +++ b/chromium/media/gpu/sandbox/hardware_video_decoding_sandbox_hook_linux.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/test/BUILD.gn b/chromium/media/gpu/test/BUILD.gn index d0d079cffae..6c2eba6cbac 100644 --- a/chromium/media/gpu/test/BUILD.gn +++ b/chromium/media/gpu/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2018 The Chromium Authors. All rights reserved. +# Copyright 2018 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -71,7 +71,6 @@ source_set("test_helpers") { ] deps = [ "//media/gpu", - "//media/mojo/common:mojo_shared_buffer_video_frame", "//media/parsers", "//mojo/public/cpp/system", "//testing/gtest", diff --git a/chromium/media/gpu/v4l2/BUILD.gn b/chromium/media/gpu/v4l2/BUILD.gn index 80ebde854de..42285e35308 100644 --- a/chromium/media/gpu/v4l2/BUILD.gn +++ b/chromium/media/gpu/v4l2/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2019 The Chromium Authors. All rights reserved. +# Copyright 2019 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -13,13 +13,11 @@ import("//ui/gl/features.gni") assert(use_v4l2_codec) -if (use_v4lplugin) { - generate_stubs("libv4l2_stubs") { - extra_header = "v4l2_stub_header.fragment" - sigs = [ "v4l2.sig" ] - output_name = "v4l2_stubs" - deps = [ "//base" ] - } +generate_stubs("libv4l2_stubs") { + extra_header = "v4l2_stub_header.fragment" + sigs = [ "v4l2.sig" ] + output_name = "v4l2_stubs" + deps = [ "//base" ] } source_set("v4l2") { @@ -58,6 +56,8 @@ source_set("v4l2") { "v4l2_video_decoder_backend_stateful.h", "v4l2_video_decoder_backend_stateless.cc", "v4l2_video_decoder_backend_stateless.h", + "v4l2_video_decoder_delegate_av1.cc", + "v4l2_video_decoder_delegate_av1.h", "v4l2_video_decoder_delegate_h264.cc", "v4l2_video_decoder_delegate_h264.h", "v4l2_video_decoder_delegate_vp8.cc", @@ -100,6 +100,7 @@ source_set("v4l2") { public_deps = [ "//ui/gl" ] deps = [ + ":libv4l2_stubs", ":v4l2_status", "//base", "//gpu/ipc/common", @@ -114,10 +115,6 @@ source_set("v4l2") { "//ui/ozone", ] - if (use_v4lplugin) { - deps += [ ":libv4l2_stubs" ] - } - if (is_chromeos_ash) { sources += [ "v4l2_jpeg_encode_accelerator.cc", @@ -132,6 +129,11 @@ source_set("v4l2") { "//media/gpu:video_frame_mapper_common", ] } + + # TODO(b/243970152): update use_libgav1_parser flag + if (enable_libgav1_decoder || use_libgav1_parser) { + deps += [ "//third_party/libgav1:libgav1" ] + } } # The v4l2 status functionality is in its own source set so that it can be diff --git a/chromium/media/gpu/v4l2/aml_v4l2_device.cc b/chromium/media/gpu/v4l2/aml_v4l2_device.cc index 2d28017d393..b4cd4f4662d 100644 --- a/chromium/media/gpu/v4l2/aml_v4l2_device.cc +++ b/chromium/media/gpu/v4l2/aml_v4l2_device.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/aml_v4l2_device.h b/chromium/media/gpu/v4l2/aml_v4l2_device.h index 7893c2131b5..fe260385933 100644 --- a/chromium/media/gpu/v4l2/aml_v4l2_device.h +++ b/chromium/media/gpu/v4l2/aml_v4l2_device.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // diff --git a/chromium/media/gpu/v4l2/buffer_affinity_tracker.cc b/chromium/media/gpu/v4l2/buffer_affinity_tracker.cc index 7ada30e1960..5565fbba907 100644 --- a/chromium/media/gpu/v4l2/buffer_affinity_tracker.cc +++ b/chromium/media/gpu/v4l2/buffer_affinity_tracker.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/buffer_affinity_tracker.h b/chromium/media/gpu/v4l2/buffer_affinity_tracker.h index 5019518967e..c94bba29565 100644 --- a/chromium/media/gpu/v4l2/buffer_affinity_tracker.h +++ b/chromium/media/gpu/v4l2/buffer_affinity_tracker.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/generic_v4l2_device.cc b/chromium/media/gpu/v4l2/generic_v4l2_device.cc index 475548bd743..fa9a95b957b 100644 --- a/chromium/media/gpu/v4l2/generic_v4l2_device.cc +++ b/chromium/media/gpu/v4l2/generic_v4l2_device.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -15,9 +15,9 @@ #include <sys/ioctl.h> #include <sys/mman.h> -#include <algorithm> #include <memory> +#include "base/containers/contains.h" #include "base/files/scoped_file.h" #include "base/posix/eintr_wrapper.h" #include "base/strings/stringprintf.h" @@ -36,15 +36,13 @@ #include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/surface_factory_ozone.h" -#if BUILDFLAG(USE_LIBV4L2) // Auto-generated for dlopen libv4l2 libraries #include "media/gpu/v4l2/v4l2_stubs.h" #include "third_party/v4l-utils/lib/include/libv4l2.h" -using media_gpu_v4l2::kModuleV4l2; using media_gpu_v4l2::InitializeStubs; +using media_gpu_v4l2::kModuleV4l2; using media_gpu_v4l2::StubPathMap; -#endif namespace media { @@ -75,9 +73,7 @@ uint32_t V4L2PixFmtToDrmFormat(uint32_t format) { } // namespace GenericV4L2Device::GenericV4L2Device() { -#if BUILDFLAG(USE_LIBV4L2) use_libv4l2_ = false; -#endif } GenericV4L2Device::~GenericV4L2Device() { @@ -86,10 +82,10 @@ GenericV4L2Device::~GenericV4L2Device() { int GenericV4L2Device::Ioctl(int request, void* arg) { DCHECK(device_fd_.is_valid()); -#if BUILDFLAG(USE_LIBV4L2) + if (use_libv4l2_) return HANDLE_EINTR(v4l2_ioctl(device_fd_.get(), request, arg)); -#endif + return HANDLE_EINTR(ioctl(device_fd_.get(), request, arg)); } @@ -230,11 +226,8 @@ bool GenericV4L2Device::CanCreateEGLImageFrom(const Fourcc fourcc) const { #endif }; - return std::find( - kEGLImageDrmFmtsSupported, - kEGLImageDrmFmtsSupported + std::size(kEGLImageDrmFmtsSupported), - V4L2PixFmtToDrmFormat(fourcc.ToV4L2PixFmt())) != - kEGLImageDrmFmtsSupported + std::size(kEGLImageDrmFmtsSupported); + return base::Contains(kEGLImageDrmFmtsSupported, + V4L2PixFmtToDrmFormat(fourcc.ToV4L2PixFmt())); } EGLImageKHR GenericV4L2Device::CreateEGLImage( @@ -440,42 +433,34 @@ bool GenericV4L2Device::OpenDevicePath(const std::string& path, Type type) { if (!device_fd_.is_valid()) return false; -#if BUILDFLAG(USE_LIBV4L2) - if (type == Type::kEncoder && - HANDLE_EINTR(v4l2_fd_open(device_fd_.get(), V4L2_DISABLE_CONVERSION)) != - -1) { - DVLOGF(3) << "Using libv4l2 for " << path; - use_libv4l2_ = true; + if (V4L2Device::UseLibV4L2()) { + if (type == Type::kEncoder && + HANDLE_EINTR(v4l2_fd_open(device_fd_.get(), V4L2_DISABLE_CONVERSION)) != + -1) { + DVLOGF(3) << "Using libv4l2 for " << path; + use_libv4l2_ = true; + } } -#endif return true; } void GenericV4L2Device::CloseDevice() { DVLOGF(3); -#if BUILDFLAG(USE_LIBV4L2) if (use_libv4l2_ && device_fd_.is_valid()) v4l2_close(device_fd_.release()); -#endif device_fd_.reset(); } // static bool GenericV4L2Device::PostSandboxInitialization() { -#if BUILDFLAG(USE_LIBV4L2) - static const base::FilePath::CharType kV4l2Lib[] = -#if defined(ARCH_CPU_64_BITS) - FILE_PATH_LITERAL("/usr/lib64/libv4l2.so"); -#else - FILE_PATH_LITERAL("/usr/lib/libv4l2.so"); -#endif // defined(ARCH_CPU_64_BITS) - StubPathMap paths; - paths[kModuleV4l2].push_back(kV4l2Lib); - - return InitializeStubs(paths); -#else - return true; -#endif + if (V4L2Device::UseLibV4L2()) { + StubPathMap paths; + paths[kModuleV4l2].push_back(V4L2Device::kLibV4l2Path); + + return InitializeStubs(paths); + } else { + return true; + } } void GenericV4L2Device::EnumerateDevicesForType(Type type) { @@ -556,8 +541,7 @@ std::string GenericV4L2Device::GetDevicePathFor(Type type, uint32_t pixfmt) { const Devices& devices = GetDevicesForType(type); for (const auto& device : devices) { - if (std::find(device.second.begin(), device.second.end(), pixfmt) != - device.second.end()) + if (base::Contains(device.second, pixfmt)) return device.first; } diff --git a/chromium/media/gpu/v4l2/generic_v4l2_device.h b/chromium/media/gpu/v4l2/generic_v4l2_device.h index 09013a5cf12..63870260288 100644 --- a/chromium/media/gpu/v4l2/generic_v4l2_device.h +++ b/chromium/media/gpu/v4l2/generic_v4l2_device.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -120,10 +120,8 @@ class GenericV4L2Device : public V4L2Device { // interrupted. base::ScopedFD device_poll_interrupt_fd_; -#if BUILDFLAG(USE_LIBV4L2) // Use libv4l2 when operating |device_fd_|. bool use_libv4l2_; -#endif // Lazily initialize static data after sandbox is enabled. Return false on // init failure. diff --git a/chromium/media/gpu/v4l2/v4l2.sig b/chromium/media/gpu/v4l2/v4l2.sig index 4269fb48d59..32931df3720 100644 --- a/chromium/media/gpu/v4l2/v4l2.sig +++ b/chromium/media/gpu/v4l2/v4l2.sig @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_decode_surface.cc b/chromium/media/gpu/v4l2/v4l2_decode_surface.cc index e7bc6953a48..8fe97c361db 100644 --- a/chromium/media/gpu/v4l2/v4l2_decode_surface.cc +++ b/chromium/media/gpu/v4l2/v4l2_decode_surface.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_decode_surface.h b/chromium/media/gpu/v4l2/v4l2_decode_surface.h index 2f188a1eed1..e789e4f8d84 100644 --- a/chromium/media/gpu/v4l2/v4l2_decode_surface.h +++ b/chromium/media/gpu/v4l2/v4l2_decode_surface.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_decode_surface_handler.h b/chromium/media/gpu/v4l2/v4l2_decode_surface_handler.h index e49cd961039..8977fe8116c 100644 --- a/chromium/media/gpu/v4l2/v4l2_decode_surface_handler.h +++ b/chromium/media/gpu/v4l2/v4l2_decode_surface_handler.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_device.cc b/chromium/media/gpu/v4l2/v4l2_device.cc index d24013d2eb5..8e3c87009b4 100644 --- a/chromium/media/gpu/v4l2/v4l2_device.cc +++ b/chromium/media/gpu/v4l2/v4l2_device.cc @@ -1,13 +1,15 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "media/gpu/v4l2/v4l2_device.h" +#include <errno.h> #include <fcntl.h> -#include <poll.h> #include <linux/media.h> +#include <poll.h> #include <sys/ioctl.h> +#include <unistd.h> #include <algorithm> #include <set> @@ -130,6 +132,20 @@ void V4L2ProcessingTrace(const struct v4l2_buffer* v4l2_buffer, bool start) { } } +bool LibV4L2Exists() { +#if BUILDFLAG(USE_LIBV4L2) + return true; +#elif BUILDFLAG(IS_CHROMEOS_LACROS) + if (access(V4L2Device::kLibV4l2Path, F_OK) == 0) + return true; + PLOG_IF(FATAL, errno != ENOENT) + << "access() failed for a reason other than ENOENT"; + return false; +#else + return false; +#endif +} + } // namespace V4L2ExtCtrl::V4L2ExtCtrl(uint32_t id) { @@ -593,8 +609,10 @@ bool V4L2WritableBufferRef::DoQueue(V4L2RequestRef* request_ref, DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(buffer_data_); - if (request_ref && buffer_data_->queue_->SupportsRequests()) - request_ref->ApplyQueueBuffer(&(buffer_data_->v4l2_buffer_)); + if (request_ref && buffer_data_->queue_->SupportsRequests() && + !request_ref->ApplyQueueBuffer(&(buffer_data_->v4l2_buffer_))) { + return false; + } bool queued = buffer_data_->QueueBuffer(std::move(video_frame)); @@ -1012,7 +1030,8 @@ V4L2Queue::~V4L2Queue() { if (is_streaming_) { VQLOGF(1) << "Queue is still streaming, trying to stop it..."; - Streamoff(); + if (!Streamoff()) + VQLOGF(1) << "Failed to stop queue"; } DCHECK(queued_buffers_.empty()); @@ -1020,7 +1039,8 @@ V4L2Queue::~V4L2Queue() { if (!buffers_.empty()) { VQLOGF(1) << "Buffers are still allocated, trying to deallocate them..."; - DeallocateBuffers(); + if (!DeallocateBuffers()) + VQLOGF(1) << "Failed to deallocate queue buffers"; } std::move(destroy_cb_).Run(); @@ -1166,7 +1186,8 @@ size_t V4L2Queue::AllocateBuffers(size_t count, auto buffer = V4L2Buffer::Create(device_, type_, memory_, *format, i); if (!buffer) { - DeallocateBuffers(); + if (!DeallocateBuffers()) + VQLOGF(1) << "Failed to deallocate queue buffers"; return 0; } @@ -1963,6 +1984,12 @@ size_t V4L2Device::GetNumPlanesOfV4L2PixFmt(uint32_t pix_fmt) { return 1u; } +// static +bool V4L2Device::UseLibV4L2() { + static const bool use_libv4l2 = LibV4L2Exists(); + return use_libv4l2; +} + void V4L2Device::GetSupportedResolution(uint32_t pixelformat, gfx::Size* min_resolution, gfx::Size* max_resolution) { diff --git a/chromium/media/gpu/v4l2/v4l2_device.h b/chromium/media/gpu/v4l2/v4l2_device.h index 740667eb6e7..439414c69ee 100644 --- a/chromium/media/gpu/v4l2/v4l2_device.h +++ b/chromium/media/gpu/v4l2/v4l2_device.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -96,7 +96,7 @@ class MEDIA_GPU_EXPORT V4L2WritableBufferRef { // so this reference becomes invalid. // In case of error, false is returned and the buffer is returned to the free // list. - bool QueueMMap(V4L2RequestRef* request_ref = nullptr) &&; + [[nodiscard]] bool QueueMMap(V4L2RequestRef* request_ref = nullptr) &&; // Queue a USERPTR buffer, assigning |ptrs| as pointer for each plane. // The size of |ptrs| must be equal to the number of planes of this buffer. // When requests are supported, a |request_ref| can be passed along this @@ -105,8 +105,8 @@ class MEDIA_GPU_EXPORT V4L2WritableBufferRef { // so this reference becomes invalid. // In case of error, false is returned and the buffer is returned to the free // list. - bool QueueUserPtr(const std::vector<void*>& ptrs, - V4L2RequestRef* request_ref = nullptr) &&; + [[nodiscard]] bool QueueUserPtr(const std::vector<void*>& ptrs, + V4L2RequestRef* request_ref = nullptr) &&; // Queue a DMABUF buffer, assigning |fds| as file descriptors for each plane. // It is allowed the number of |fds| might be greater than the number of // planes of this buffer. It happens when the v4l2 pixel format is single @@ -117,8 +117,8 @@ class MEDIA_GPU_EXPORT V4L2WritableBufferRef { // so this reference becomes invalid. // In case of error, false is returned and the buffer is returned to the free // list. - bool QueueDMABuf(const std::vector<base::ScopedFD>& fds, - V4L2RequestRef* request_ref = nullptr) &&; + [[nodiscard]] bool QueueDMABuf(const std::vector<base::ScopedFD>& fds, + V4L2RequestRef* request_ref = nullptr) &&; // Queue a DMABUF buffer, assigning file descriptors of |planes| for planes. // It is allowed the number of |planes| might be greater than the number of // planes of this buffer. It happens when the v4l2 pixel format is single @@ -129,8 +129,9 @@ class MEDIA_GPU_EXPORT V4L2WritableBufferRef { // so this reference becomes invalid. // In case of error, false is returned and the buffer is returned to the free // list. - bool QueueDMABuf(const std::vector<gfx::NativePixmapPlane>& planes, - V4L2RequestRef* request_ref = nullptr) &&; + [[nodiscard]] bool QueueDMABuf( + const std::vector<gfx::NativePixmapPlane>& planes, + V4L2RequestRef* request_ref = nullptr) &&; // Queue a |video_frame| using its file descriptors as DMABUFs. The VideoFrame // must have been constructed from its file descriptors. // The particularity of this method is that a reference to |video_frame| is @@ -138,8 +139,8 @@ class MEDIA_GPU_EXPORT V4L2WritableBufferRef { // |V4L2ReadableBufferRef::GetVideoFrame()|. |video_frame| is thus guaranteed // to be alive until either all the |V4L2ReadableBufferRef| from the dequeued // buffer get out of scope, or |V4L2Queue::Streamoff()| is called. - bool QueueDMABuf(scoped_refptr<VideoFrame> video_frame, - V4L2RequestRef* request_ref = nullptr) &&; + [[nodiscard]] bool QueueDMABuf(scoped_refptr<VideoFrame> video_frame, + V4L2RequestRef* request_ref = nullptr) &&; // Returns the number of planes in this buffer. size_t PlanesCount() const; @@ -197,8 +198,8 @@ class MEDIA_GPU_EXPORT V4L2WritableBufferRef { // filled. // When requests are supported, a |request_ref| can be passed along this // the buffer to be submitted. - bool DoQueue(V4L2RequestRef* request_ref, - scoped_refptr<VideoFrame> video_frame) &&; + [[nodiscard]] bool DoQueue(V4L2RequestRef* request_ref, + scoped_refptr<VideoFrame> video_frame) &&; V4L2WritableBufferRef(const struct v4l2_buffer& v4l2_buffer, base::WeakPtr<V4L2Queue> queue); @@ -339,11 +340,11 @@ class MEDIA_GPU_EXPORT V4L2Queue // This pair is used because not all failures to get the format are // necessarily errors, so we need to way to let the use decide whether it // is one or not. - std::pair<absl::optional<struct v4l2_format>, int> GetFormat(); + [[nodiscard]] std::pair<absl::optional<struct v4l2_format>, int> GetFormat(); // Codec-specific method to get the visible rectangle of the queue, using the // VIDIOC_G_SELECTION ioctl if available, or VIDIOC_G_CROP as a fallback. - absl::optional<gfx::Rect> GetVisibleRect(); + [[nodiscard]] absl::optional<gfx::Rect> GetVisibleRect(); // Allocate |count| buffers for the current format of this queue, with a // specific |memory| allocation, and returns the number of buffers allocated @@ -367,27 +368,27 @@ class MEDIA_GPU_EXPORT V4L2Queue // Deallocate all buffers previously allocated by |AllocateBuffers|. Any // references to buffers previously allocated held by the client must be // released, or this call will fail. - bool DeallocateBuffers(); + [[nodiscard]] bool DeallocateBuffers(); // Returns the memory usage of v4l2 buffers owned by this V4L2Queue which are // mapped in user space memory. - size_t GetMemoryUsage() const; + [[nodiscard]] size_t GetMemoryUsage() const; // Returns |memory_|, memory type of last buffers allocated by this V4L2Queue. - v4l2_memory GetMemoryType() const; + [[nodiscard]] v4l2_memory GetMemoryType() const; // Return a reference to a free buffer for the caller to prepare and submit, // or nullopt if no buffer is currently free. // // If the caller discards the returned reference, the underlying buffer is // made available to clients again. - absl::optional<V4L2WritableBufferRef> GetFreeBuffer(); + [[nodiscard]] absl::optional<V4L2WritableBufferRef> GetFreeBuffer(); // Return the buffer at index |requested_buffer_id|, if it is available at // this time. // // If the buffer is currently in use or the provided index is invalid, // return |absl::nullopt|. - absl::optional<V4L2WritableBufferRef> GetFreeBuffer( + [[nodiscard]] absl::optional<V4L2WritableBufferRef> GetFreeBuffer( size_t requested_buffer_id); // Return a V4L2 buffer suitable for the passed VideoFrame. // @@ -404,7 +405,7 @@ class MEDIA_GPU_EXPORT V4L2Queue // since it will maximize performance in that case provided the number of // different VideoFrames passed to this method does not exceed the number of // V4L2 buffers allocated on the queue. - absl::optional<V4L2WritableBufferRef> GetFreeBufferForFrame( + [[nodiscard]] absl::optional<V4L2WritableBufferRef> GetFreeBufferForFrame( const VideoFrame& frame); // Attempt to dequeue a buffer, and return a reference to it if one was @@ -417,45 +418,46 @@ class MEDIA_GPU_EXPORT V4L2Queue // otherwise. // Dequeued buffers will not be reused by the driver until all references to // them are dropped. - std::pair<bool, V4L2ReadableBufferRef> DequeueBuffer(); + [[nodiscard]] std::pair<bool, V4L2ReadableBufferRef> DequeueBuffer(); // Returns true if this queue is currently streaming. - bool IsStreaming() const; + [[nodiscard]] bool IsStreaming() const; // If not currently streaming, starts streaming. Returns true if we started // streaming, or were already streaming, or false if we were not streaming // and an error occurred when attempting to start the stream. On failure, any // previously-queued buffers will be dequeued without processing and made // available to the client, while any buffers held by the client will remain // unchanged and their ownership will remain with the client. - bool Streamon(); + [[nodiscard]] bool Streamon(); // If currently streaming, stops streaming. Also make all queued buffers // available to the client again regardless of the streaming state. // If an error occurred while attempting to stop streaming, then false is // returned and queued buffers are left untouched since the V4L2 queue may // still be using them. - bool Streamoff(); + [[nodiscard]] bool Streamoff(); // Returns the number of buffers currently allocated for this queue. - size_t AllocatedBuffersCount() const; + [[nodiscard]] size_t AllocatedBuffersCount() const; // Returns the number of currently free buffers on this queue. - size_t FreeBuffersCount() const; + [[nodiscard]] size_t FreeBuffersCount() const; // Returns the number of buffers currently queued on this queue. - size_t QueuedBuffersCount() const; + [[nodiscard]] size_t QueuedBuffersCount() const; // Returns true if requests are supported by this queue. - bool SupportsRequests(); + [[nodiscard]] bool SupportsRequests(); // TODO (b/166275274) : Remove this once V4L2 properly supports modifiers. // Out of band method to configure V4L2 for modifier use. - absl::optional<struct v4l2_format> SetModifierFormat(uint64_t modifier, - const gfx::Size& size); + [[nodiscard]] absl::optional<struct v4l2_format> SetModifierFormat( + uint64_t modifier, + const gfx::Size& size); private: ~V4L2Queue(); // Called when clients request a buffer to be queued. - bool QueueBuffer(struct v4l2_buffer* v4l2_buffer, - scoped_refptr<VideoFrame> video_frame); + [[nodiscard]] bool QueueBuffer(struct v4l2_buffer* v4l2_buffer, + scoped_refptr<VideoFrame> video_frame); const enum v4l2_buf_type type_; enum v4l2_memory memory_ = V4L2_MEMORY_MMAP; @@ -539,7 +541,7 @@ class MEDIA_GPU_EXPORT V4L2RequestRef : public V4L2RequestRefBase { // Apply controls to the request. bool ApplyCtrls(struct v4l2_ext_controls* ctrls) const; // Apply buffer to the request. - bool ApplyQueueBuffer(struct v4l2_buffer* buffer) const; + [[nodiscard]] bool ApplyQueueBuffer(struct v4l2_buffer* buffer) const; // Submits the request to the driver. absl::optional<V4L2SubmittedRequestRef> Submit() &&; @@ -563,7 +565,7 @@ class MEDIA_GPU_EXPORT V4L2SubmittedRequestRef : public V4L2RequestRefBase { V4L2SubmittedRequestRef& operator=(const V4L2SubmittedRequestRef&) = delete; // Indicates if the request has completed. - bool IsCompleted(); + [[nodiscard]] bool IsCompleted(); private: friend class V4L2RequestRef; @@ -648,6 +650,17 @@ class MEDIA_GPU_EXPORT V4L2Device kJpegEncoder, }; + inline static constexpr char kLibV4l2Path[] = +#if defined(__aarch64__) + "/usr/lib64/libv4l2.so"; +#else + "/usr/lib/libv4l2.so"; +#endif + + // Returns true iff libv4l2 should be used to interact with the V4L2 driver. + // This method is thread-safe. + static bool UseLibV4L2(); + // Create and initialize an appropriate V4L2Device instance for the current // platform, or return nullptr if not available. static scoped_refptr<V4L2Device> Create(); @@ -655,7 +668,7 @@ class MEDIA_GPU_EXPORT V4L2Device // Open a V4L2 device of |type| for use with |v4l2_pixfmt|. // Return true on success. // The device will be closed in the destructor. - virtual bool Open(Type type, uint32_t v4l2_pixfmt) = 0; + [[nodiscard]] virtual bool Open(Type type, uint32_t v4l2_pixfmt) = 0; // Returns the driver name. std::string GetDriverName(); @@ -666,7 +679,7 @@ class MEDIA_GPU_EXPORT V4L2Device // Parameters and return value are the same as for the standard ioctl() system // call. - virtual int Ioctl(int request, void* arg) = 0; + [[nodiscard]] virtual int Ioctl(int request, void* arg) = 0; // This method sleeps until either: // - SetDevicePollInterrupt() is called (on another thread), @@ -779,11 +792,12 @@ class MEDIA_GPU_EXPORT V4L2Device // the caller's sequence if a buffer is ready to be dequeued and/or a V4L2 // event has been posted. |error_callback| will be posted to the client's // sequence if a polling error has occurred. - bool StartPolling(V4L2DevicePoller::EventCallback event_callback, - base::RepeatingClosure error_callback); + [[nodiscard]] bool StartPolling( + V4L2DevicePoller::EventCallback event_callback, + base::RepeatingClosure error_callback); // Stop polling this V4L2Device if polling was active. No new events will // be posted after this method has returned. - bool StopPolling(); + [[nodiscard]] bool StopPolling(); // Schedule a polling event if polling is enabled. This method is intended // to be called from V4L2Queue, clients should not need to call it directly. void SchedulePoll(); @@ -826,7 +840,7 @@ class MEDIA_GPU_EXPORT V4L2Device // Perform platform-specific initialization of the device instance. // Return true on success, false on error or if the particular implementation // is not available. - virtual bool Initialize() = 0; + [[nodiscard]] virtual bool Initialize() = 0; // Associates a v4l2_buf_type to its queue. base::flat_map<enum v4l2_buf_type, V4L2Queue*> queues_; diff --git a/chromium/media/gpu/v4l2/v4l2_device_poller.cc b/chromium/media/gpu/v4l2/v4l2_device_poller.cc index 8c5e0751eed..58fc5a5faea 100644 --- a/chromium/media/gpu/v4l2/v4l2_device_poller.cc +++ b/chromium/media/gpu/v4l2/v4l2_device_poller.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_device_poller.h b/chromium/media/gpu/v4l2/v4l2_device_poller.h index 9abe4416668..8469f9eb043 100644 --- a/chromium/media/gpu/v4l2/v4l2_device_poller.h +++ b/chromium/media/gpu/v4l2/v4l2_device_poller.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_device_unittest.cc b/chromium/media/gpu/v4l2/v4l2_device_unittest.cc index 71380430c77..2fd2b3c2867 100644 --- a/chromium/media/gpu/v4l2/v4l2_device_unittest.cc +++ b/chromium/media/gpu/v4l2/v4l2_device_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_framerate_control.cc b/chromium/media/gpu/v4l2/v4l2_framerate_control.cc index 8a8ed61bfc8..bc417961018 100644 --- a/chromium/media/gpu/v4l2/v4l2_framerate_control.cc +++ b/chromium/media/gpu/v4l2/v4l2_framerate_control.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_framerate_control.h b/chromium/media/gpu/v4l2/v4l2_framerate_control.h index b2346021a1f..a78667ff372 100644 --- a/chromium/media/gpu/v4l2/v4l2_framerate_control.h +++ b/chromium/media/gpu/v4l2/v4l2_framerate_control.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc b/chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc index b90b1c9a4ac..bbf7959e21a 100644 --- a/chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc +++ b/chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -152,13 +152,17 @@ void V4L2ImageProcessorBackend::Destroy() { backend_weak_this_factory_.InvalidateWeakPtrs(); if (input_queue_) { - input_queue_->Streamoff(); - input_queue_->DeallocateBuffers(); + if (!input_queue_->Streamoff()) + VLOGF(1) << "Failed to turn stream off"; + if (!input_queue_->DeallocateBuffers()) + VLOGF(1) << "Failed to deallocate buffers"; input_queue_ = nullptr; } if (output_queue_) { - output_queue_->Streamoff(); - output_queue_->DeallocateBuffers(); + if (!output_queue_->Streamoff()) + VLOGF(1) << "Failed to turn stream off"; + if (!output_queue_->DeallocateBuffers()) + VLOGF(1) << "Failed to deallocate buffers"; output_queue_ = nullptr; } @@ -205,7 +209,6 @@ v4l2_memory InputStorageTypeToV4L2Memory(VideoFrame::StorageType storage_type) { case VideoFrame::STORAGE_OWNED_MEMORY: case VideoFrame::STORAGE_UNOWNED_MEMORY: case VideoFrame::STORAGE_SHMEM: - case VideoFrame::STORAGE_MOJO_SHARED_BUFFER: return V4L2_MEMORY_USERPTR; case VideoFrame::STORAGE_DMABUFS: case VideoFrame::STORAGE_GPU_MEMORY_BUFFER: @@ -921,18 +924,41 @@ bool V4L2ImageProcessorBackend::EnqueueInputRecord( switch (input_memory_type_) { case V4L2_MEMORY_USERPTR: { + VideoFrame& frame = *job_record->input_frame; const size_t num_planes = V4L2Device::GetNumPlanesOfV4L2PixFmt( input_config_.fourcc.ToV4L2PixFmt()); std::vector<void*> user_ptrs(num_planes); + if (frame.storage_type() == VideoFrame::STORAGE_SHMEM) { + // TODO(b/243883312): This copies the video frame to a writable buffer + // since the USERPTR API requires writable permission. Remove this + // workaround once the unreasonable permission is fixed. + const size_t buffer_size = frame.shm_region()->GetSize(); + std::vector<uint8_t> writable_buffer(buffer_size); + std::memcpy(writable_buffer.data(), frame.data(0), buffer_size); + for (size_t i = 0; i < num_planes; ++i) { + const std::intptr_t plane_offset = + reinterpret_cast<std::intptr_t>(frame.data(i)) - + reinterpret_cast<std::intptr_t>(frame.data(0)); + user_ptrs[i] = writable_buffer.data() + plane_offset; + } + job_record->input_frame->AddDestructionObserver(base::BindOnce( + [](std::vector<uint8_t>) {}, std::move(writable_buffer))); + } else { + for (size_t i = 0; i < num_planes; ++i) + user_ptrs[i] = frame.writable_data(i); + } + for (size_t i = 0; i < num_planes; ++i) { int bytes_used = - VideoFrame::PlaneSize(job_record->input_frame->format(), i, - input_config_.size) + VideoFrame::PlaneSize(frame.format(), i, input_config_.size) .GetArea(); buffer.SetPlaneBytesUsed(i, bytes_used); - user_ptrs[i] = job_record->input_frame->data(i); } - std::move(buffer).QueueUserPtr(user_ptrs); + if (!std::move(buffer).QueueUserPtr(user_ptrs)) { + VPLOGF(1) << "Failed to queue a DMABUF buffer to input queue"; + NotifyError(); + return false; + } break; } case V4L2_MEMORY_DMABUF: { @@ -945,7 +971,12 @@ bool V4L2ImageProcessorBackend::EnqueueInputRecord( FillV4L2BufferByGpuMemoryBufferHandle( input_config_.fourcc, input_config_.size, *input_handle, &buffer); - std::move(buffer).QueueDMABuf(input_handle->native_pixmap_handle.planes); + if (!std::move(buffer).QueueDMABuf( + input_handle->native_pixmap_handle.planes)) { + VPLOGF(1) << "Failed to queue a DMABUF buffer to input queue"; + NotifyError(); + return false; + } break; } default: diff --git a/chromium/media/gpu/v4l2/v4l2_image_processor_backend.h b/chromium/media/gpu/v4l2/v4l2_image_processor_backend.h index b4fbaa911dd..b09d78dfb09 100644 --- a/chromium/media/gpu/v4l2/v4l2_image_processor_backend.h +++ b/chromium/media/gpu/v4l2/v4l2_image_processor_backend.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.cc b/chromium/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.cc index 6d4e96c3d81..cdf121279ef 100644 --- a/chromium/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.cc +++ b/chromium/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +10,7 @@ #include <sys/mman.h> #include <memory> +#include <tuple> #include <utility> #include "base/bind.h" @@ -666,9 +667,9 @@ bool V4L2JpegEncodeAccelerator::EncodedInstance::EnqueueInputRecord() { DCHECK(!input_record.at_device); // Copy image from user memory to MMAP memory. - uint8_t* src_y = job_record->input_frame->data(VideoFrame::kYPlane); - uint8_t* src_u = job_record->input_frame->data(VideoFrame::kUPlane); - uint8_t* src_v = job_record->input_frame->data(VideoFrame::kVPlane); + const uint8_t* src_y = job_record->input_frame->data(VideoFrame::kYPlane); + const uint8_t* src_u = job_record->input_frame->data(VideoFrame::kUPlane); + const uint8_t* src_v = job_record->input_frame->data(VideoFrame::kVPlane); size_t src_y_stride = job_record->input_frame->stride(VideoFrame::kYPlane); size_t src_u_stride = job_record->input_frame->stride(VideoFrame::kUPlane); size_t src_v_stride = job_record->input_frame->stride(VideoFrame::kVPlane); @@ -1193,7 +1194,7 @@ bool V4L2JpegEncodeAccelerator::EncodedInstanceDmaBuf::SetUpJpegParameters( // Driver may not have implemented V4L2_CID_JPEG_ACTIVE_MARKER. // Ignore any error and assume the driver implements the JPEG stream // the way we want it. - device_->Ioctl(VIDIOC_QUERY_EXT_CTRL, &queryctrl); + std::ignore = device_->Ioctl(VIDIOC_QUERY_EXT_CTRL, &queryctrl); // Ask for JPEG markers we want. Since not all may be implemented, // ask for the common subset of what we want and what is supported. @@ -1201,7 +1202,7 @@ bool V4L2JpegEncodeAccelerator::EncodedInstanceDmaBuf::SetUpJpegParameters( ctrl.value = queryctrl.maximum & (V4L2_JPEG_ACTIVE_MARKER_APP0 | V4L2_JPEG_ACTIVE_MARKER_DQT | V4L2_JPEG_ACTIVE_MARKER_DHT); - device_->Ioctl(VIDIOC_S_EXT_CTRLS, &ctrls); + std::ignore = device_->Ioctl(VIDIOC_S_EXT_CTRLS, &ctrls); break; default: diff --git a/chromium/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.h b/chromium/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.h index b31ef0e2021..a11a1792b73 100644 --- a/chromium/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.h +++ b/chromium/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.cc b/chromium/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.cc index 1ee2eba47d6..e8e1422889d 100644 --- a/chromium/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.cc +++ b/chromium/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -900,7 +900,7 @@ bool V4L2MjpegDecodeAccelerator::ConvertOutputImage( std::array<uint8_t*, VideoFrame::kMaxPlanes> dst_ptrs{}; std::array<int, VideoFrame::kMaxPlanes> dst_strides{}; for (size_t i = 0; i < dst_frame->layout().num_planes(); i++) { - dst_ptrs[i] = dst_frame->visible_data(i); + dst_ptrs[i] = dst_frame->GetWritableVisibleData(i); dst_strides[i] = base::checked_cast<int>(dst_frame->stride(i)); } diff --git a/chromium/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.h b/chromium/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.h index f13e5292065..f14368f6633 100644 --- a/chromium/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.h +++ b/chromium/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_slice_video_decode_accelerator.cc b/chromium/media/gpu/v4l2/v4l2_slice_video_decode_accelerator.cc index d788c3957dd..79d6be6b274 100644 --- a/chromium/media/gpu/v4l2/v4l2_slice_video_decode_accelerator.cc +++ b/chromium/media/gpu/v4l2/v4l2_slice_video_decode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -20,9 +20,11 @@ #include "base/callback.h" #include "base/callback_helpers.h" #include "base/command_line.h" +#include "base/containers/contains.h" #include "base/memory/ptr_util.h" #include "base/numerics/safe_conversions.h" #include "base/posix/eintr_wrapper.h" +#include "base/ranges/algorithm.h" #include "base/strings/stringprintf.h" #include "base/task/single_thread_task_runner.h" #include "base/threading/thread_task_runner_handle.h" @@ -788,7 +790,8 @@ void V4L2SliceVideoDecodeAccelerator::DestroyInputBuffers() { DCHECK(!input_queue_->IsStreaming()); - input_queue_->DeallocateBuffers(); + if (!input_queue_->DeallocateBuffers()) + VLOGF(1) << "Failed to deallocate V4L2 input buffers"; } void V4L2SliceVideoDecodeAccelerator::DismissPictures( @@ -1287,7 +1290,8 @@ bool V4L2SliceVideoDecodeAccelerator::DestroyOutputBuffers() { output_buffer_map_.clear(); - output_queue_->DeallocateBuffers(); + if (!output_queue_->DeallocateBuffers()) + VLOGF(1) << "Failed to deallocate V4L2 output buffers"; return true; } @@ -1571,11 +1575,8 @@ void V4L2SliceVideoDecodeAccelerator::ImportBufferForPictureTask( if (surface_set_change_pending_) return; - const auto iter = - std::find_if(output_buffer_map_.begin(), output_buffer_map_.end(), - [picture_buffer_id](const OutputRecord& output_record) { - return output_record.picture_id == picture_buffer_id; - }); + const auto iter = base::ranges::find(output_buffer_map_, picture_buffer_id, + &OutputRecord::picture_id); if (iter == output_buffer_map_.end()) { // It's possible that we've already posted a DismissPictureBuffer for this // picture, but it has not yet executed when this ImportBufferForPicture was @@ -2249,8 +2250,7 @@ bool V4L2SliceVideoDecodeAccelerator::IsSupportedProfile( for (const SupportedProfile& entry : profiles) supported_profiles_.push_back(entry.profile); } - return std::find(supported_profiles_.begin(), supported_profiles_.end(), - profile) != supported_profiles_.end(); + return base::Contains(supported_profiles_, profile); } size_t V4L2SliceVideoDecodeAccelerator::GetNumOfOutputRecordsAtDevice() const { diff --git a/chromium/media/gpu/v4l2/v4l2_slice_video_decode_accelerator.h b/chromium/media/gpu/v4l2/v4l2_slice_video_decode_accelerator.h index 6aad0f46292..142f92b97f7 100644 --- a/chromium/media/gpu/v4l2/v4l2_slice_video_decode_accelerator.h +++ b/chromium/media/gpu/v4l2/v4l2_slice_video_decode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_stateful_workaround.cc b/chromium/media/gpu/v4l2/v4l2_stateful_workaround.cc index cb52bc31795..7003bcccf22 100644 --- a/chromium/media/gpu/v4l2/v4l2_stateful_workaround.cc +++ b/chromium/media/gpu/v4l2/v4l2_stateful_workaround.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_stateful_workaround.h b/chromium/media/gpu/v4l2/v4l2_stateful_workaround.h index 619953c1d51..d5561272e46 100644 --- a/chromium/media/gpu/v4l2/v4l2_stateful_workaround.h +++ b/chromium/media/gpu/v4l2/v4l2_stateful_workaround.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_stateful_workaround_unittest.cc b/chromium/media/gpu/v4l2/v4l2_stateful_workaround_unittest.cc index 9a4dc99c5fd..86baab97eb3 100644 --- a/chromium/media/gpu/v4l2/v4l2_stateful_workaround_unittest.cc +++ b/chromium/media/gpu/v4l2/v4l2_stateful_workaround_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_status.h b/chromium/media/gpu/v4l2/v4l2_status.h index 3ce393f6e83..ed625bc07f8 100644 --- a/chromium/media/gpu/v4l2/v4l2_status.h +++ b/chromium/media/gpu/v4l2/v4l2_status.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -20,6 +20,7 @@ enum class V4L2StatusCodes : StatusCodeType { kFailedResourceAllocation = 7, kBadFormat = 8, kFailedToStartStreamQueue = 9, + kFailedToDestroyQueueBuffers = 10, }; struct V4L2StatusTraits { @@ -31,4 +32,4 @@ using V4L2Status = TypedStatus<V4L2StatusTraits>; } // namespace media -#endif // MEDIA_GPU_V4L2_V4L2_STATUS_H_
\ No newline at end of file +#endif // MEDIA_GPU_V4L2_V4L2_STATUS_H_ diff --git a/chromium/media/gpu/v4l2/v4l2_utils.cc b/chromium/media/gpu/v4l2/v4l2_utils.cc index ee4d1bd5090..4612a484450 100644 --- a/chromium/media/gpu/v4l2/v4l2_utils.cc +++ b/chromium/media/gpu/v4l2/v4l2_utils.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_utils.h b/chromium/media/gpu/v4l2/v4l2_utils.h index ac463995e2d..0ab6354b89f 100644 --- a/chromium/media/gpu/v4l2/v4l2_utils.h +++ b/chromium/media/gpu/v4l2/v4l2_utils.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_vda_helpers.cc b/chromium/media/gpu/v4l2/v4l2_vda_helpers.cc index f2561907703..baaca9c0ad3 100644 --- a/chromium/media/gpu/v4l2/v4l2_vda_helpers.cc +++ b/chromium/media/gpu/v4l2/v4l2_vda_helpers.cc @@ -1,10 +1,12 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "media/gpu/v4l2/v4l2_vda_helpers.h" #include "base/bind.h" +#include "base/containers/contains.h" +#include "base/ranges/algorithm.h" #include "media/base/color_plane_layout.h" #include "media/base/video_codecs.h" #include "media/gpu/chromeos/fourcc.h" @@ -24,9 +26,7 @@ absl::optional<Fourcc> FindImageProcessorInputFormat(V4L2Device* vda_device) { memset(&fmtdesc, 0, sizeof(fmtdesc)); fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; while (vda_device->Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0) { - if (std::find(processor_input_formats.begin(), - processor_input_formats.end(), - fmtdesc.pixelformat) != processor_input_formats.end()) { + if (base::Contains(processor_input_formats, fmtdesc.pixelformat)) { DVLOGF(3) << "Image processor input format=" << fmtdesc.description; return Fourcc::FromV4L2PixFmt(fmtdesc.pixelformat); } @@ -41,10 +41,8 @@ absl::optional<Fourcc> FindImageProcessorOutputFormat(V4L2Device* ip_device) { static constexpr uint32_t kPreferredFormats[] = {V4L2_PIX_FMT_NV12, V4L2_PIX_FMT_YVU420}; auto preferred_formats_first = [](uint32_t a, uint32_t b) -> bool { - auto* iter_a = std::find(std::begin(kPreferredFormats), - std::end(kPreferredFormats), a); - auto* iter_b = std::find(std::begin(kPreferredFormats), - std::end(kPreferredFormats), b); + auto* iter_a = base::ranges::find(kPreferredFormats, a); + auto* iter_b = base::ranges::find(kPreferredFormats, b); return iter_a < iter_b; }; diff --git a/chromium/media/gpu/v4l2/v4l2_vda_helpers.h b/chromium/media/gpu/v4l2/v4l2_vda_helpers.h index ebd07cf7e5b..ec11f2f5e73 100644 --- a/chromium/media/gpu/v4l2/v4l2_vda_helpers.h +++ b/chromium/media/gpu/v4l2/v4l2_vda_helpers.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decode_accelerator.cc b/chromium/media/gpu/v4l2/v4l2_video_decode_accelerator.cc index c54c7356dcb..05b87395fe7 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decode_accelerator.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -19,6 +19,7 @@ #include "base/command_line.h" #include "base/numerics/safe_conversions.h" #include "base/posix/eintr_wrapper.h" +#include "base/ranges/algorithm.h" #include "base/strings/stringprintf.h" #include "base/task/single_thread_task_runner.h" #include "base/threading/thread_task_runner_handle.h" @@ -633,11 +634,8 @@ void V4L2VideoDecodeAccelerator::ImportBufferForPictureTask( if (IsDestroyPending()) return; - const auto iter = - std::find_if(output_buffer_map_.begin(), output_buffer_map_.end(), - [picture_buffer_id](const OutputRecord& output_record) { - return output_record.picture_id == picture_buffer_id; - }); + const auto iter = base::ranges::find(output_buffer_map_, picture_buffer_id, + &OutputRecord::picture_id); if (iter == output_buffer_map_.end()) { // It's possible that we've already posted a DismissPictureBuffer for this // picture, but it has not yet executed when this ImportBufferForPicture was @@ -2502,7 +2500,10 @@ void V4L2VideoDecodeAccelerator::DestroyInputBuffers() { if (!input_queue_) return; - input_queue_->DeallocateBuffers(); + if (!input_queue_->DeallocateBuffers()) { + VLOGF(1) << "Failed deallocating V4L2 input buffers"; + NOTIFY_ERROR(PLATFORM_FAILURE); + } } bool V4L2VideoDecodeAccelerator::DestroyOutputBuffers() { diff --git a/chromium/media/gpu/v4l2/v4l2_video_decode_accelerator.h b/chromium/media/gpu/v4l2/v4l2_video_decode_accelerator.h index 163907129a0..0eb4a81db9f 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decode_accelerator.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder.cc index ac21ea7ce03..cb8f06faf69 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -42,7 +42,10 @@ constexpr int k1080pArea = 1920 * 1088; constexpr size_t kInputBufferMaxSizeFor1080p = 1024 * 1024; // Input bitstream buffer size for up to 4k streams. constexpr size_t kInputBufferMaxSizeFor4k = 4 * kInputBufferMaxSizeFor1080p; -constexpr size_t kNumInputBuffers = 8; +// Some H.264 test vectors (CAPCM*1_Sand_E.h264) need 16 reference frames. +// TODO(b/249325255): reduce this number to e.g. 8 or even less when it does not +// artificially limit the size of the CAPTURE (decoded video frames) queue. +constexpr size_t kNumInputBuffers = 17; // Input format V4L2 fourccs this class supports. constexpr uint32_t kSupportedInputFourccs[] = { @@ -50,11 +53,6 @@ constexpr uint32_t kSupportedInputFourccs[] = { V4L2_PIX_FMT_H264, V4L2_PIX_FMT_VP8, V4L2_PIX_FMT_VP9, }; -// Number of output buffers to use for each VD stage above what's required by -// the decoder (e.g. DPB size, in H264). We need limits::kMaxVideoFrames to -// fill up the GpuVideoDecode pipeline, and +1 for a frame in transit. -constexpr size_t kDpbOutputBufferExtraCount = limits::kMaxVideoFrames + 1; - } // namespace // static @@ -126,11 +124,13 @@ V4L2VideoDecoder::~V4L2VideoDecoder() { // Stop and Destroy device. StopStreamV4L2Queue(true); if (input_queue_) { - input_queue_->DeallocateBuffers(); + if (!input_queue_->DeallocateBuffers()) + VLOGF(1) << "Failed to deallocate V4L2 input buffers"; input_queue_ = nullptr; } if (output_queue_) { - output_queue_->DeallocateBuffers(); + if (!output_queue_->DeallocateBuffers()) + VLOGF(1) << "Failed to deallocate V4L2 output buffers"; output_queue_ = nullptr; } @@ -185,8 +185,16 @@ void V4L2VideoDecoder::Initialize(const VideoDecoderConfig& config, return; } - input_queue_->DeallocateBuffers(); - output_queue_->DeallocateBuffers(); + if (!input_queue_->DeallocateBuffers() || + !output_queue_->DeallocateBuffers()) { + VLOGF(1) << "Failed to deallocate V4L2 buffers"; + std::move(init_cb).Run( + DecoderStatus(DecoderStatus::Codes::kNotInitialized) + .AddCause( + V4L2Status(V4L2Status::Codes::kFailedToDestroyQueueBuffers))); + return; + } + input_queue_ = nullptr; output_queue_ = nullptr; @@ -624,10 +632,15 @@ bool V4L2VideoDecoder::StopStreamV4L2Queue(bool stop_input_queue) { weak_this_for_polling_ = weak_this_for_polling_factory_.GetWeakPtr(); // Streamoff input and output queue. - if (input_queue_ && stop_input_queue) - input_queue_->Streamoff(); - if (output_queue_) - output_queue_->Streamoff(); + if (input_queue_ && stop_input_queue && !input_queue_->Streamoff()) { + SetState(State::kError); + return false; + } + + if (output_queue_ && !output_queue_->Streamoff()) { + SetState(State::kError); + return false; + } if (backend_) backend_->OnStreamStopped(stop_input_queue); @@ -702,8 +715,9 @@ CroStatus V4L2VideoDecoder::ContinueChangeResolution( if (state_ != State::kFlushing) return CroStatus::Codes::kResetRequired; - DCHECK_GT(num_output_frames, 0u); - num_output_frames_ = num_output_frames + kDpbOutputBufferExtraCount; + DCHECK_GT(num_output_frames, + static_cast<size_t>(limits::kMaxVideoFrames + 1)); + num_output_frames_ = num_output_frames; // Stateful decoders require the input queue to keep running during resolution // changes, but stateless ones require it to be stopped. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder.h b/chromium/media/gpu/v4l2/v4l2_video_decoder.h index 14ccc06fe0e..ef7a6a431a8 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend.cc index a01b317e4a5..fafd1b347b6 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend.h b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend.h index d6d2973628e..28ffebaccf7 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc index 87d4f153df5..b18d655dc68 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc @@ -1,10 +1,10 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "media/gpu/v4l2/v4l2_video_decoder_backend_stateful.h" -#include <cstddef> +#include <cstddef> #include <memory> #include <tuple> #include <utility> @@ -16,6 +16,7 @@ #include "base/metrics/histogram_macros.h" #include "base/sequence_checker.h" #include "base/task/sequenced_task_runner.h" +#include "media/base/limits.h" #include "media/base/media_switches.h" #include "media/base/video_codecs.h" #include "media/gpu/chromeos/dmabuf_video_frame_pool.h" @@ -616,9 +617,10 @@ void V4L2StatefulVideoDecoderBackend::ChangeResolution() { } auto ctrl = device_->GetCtrl(V4L2_CID_MIN_BUFFERS_FOR_CAPTURE); - constexpr size_t DEFAULT_NUM_OUTPUT_BUFFERS = 7; + constexpr size_t kDefaultNumOutputBuffers = 7; + constexpr size_t kPicsInPipeline = limits::kMaxVideoFrames + 1; const size_t num_output_buffers = - ctrl ? ctrl->value : DEFAULT_NUM_OUTPUT_BUFFERS; + (ctrl ? ctrl->value : kDefaultNumOutputBuffers) + kPicsInPipeline; if (!ctrl) VLOGF(1) << "Using default minimum number of CAPTURE buffers"; @@ -741,8 +743,7 @@ bool V4L2StatefulVideoDecoderBackend::IsSupportedProfile( for (const auto& entry : profiles) supported_profiles_.push_back(entry.profile); } - return std::find(supported_profiles_.begin(), supported_profiles_.end(), - profile) != supported_profiles_.end(); + return base::Contains(supported_profiles_, profile); } bool V4L2StatefulVideoDecoderBackend::StopInputQueueOnResChange() const { diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.h b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.h index 19370d7abf6..bb0682b5adb 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateless.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateless.cc index ca3fd50962d..1905061c82a 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateless.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateless.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateless.h b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateless.h index 5ccd3034c37..59eeb7bb60c 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateless.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_backend_stateless.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_av1.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_av1.cc new file mode 100644 index 00000000000..fc619a98872 --- /dev/null +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_av1.cc @@ -0,0 +1,622 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/gpu/v4l2/v4l2_video_decoder_delegate_av1.h" + +#include <linux/media/av1-ctrls.h> + +#include "media/gpu/macros.h" +#include "media/gpu/v4l2/v4l2_decode_surface.h" +#include "media/gpu/v4l2/v4l2_decode_surface_handler.h" +#include "third_party/libgav1/src/src/obu_parser.h" + +namespace media { + +using DecodeStatus = AV1Decoder::AV1Accelerator::Status; + +class V4L2AV1Picture : public AV1Picture { + public: + V4L2AV1Picture(scoped_refptr<V4L2DecodeSurface> dec_surface) + : dec_surface_(std::move(dec_surface)) {} + + V4L2AV1Picture(const V4L2AV1Picture&) = delete; + V4L2AV1Picture& operator=(const V4L2AV1Picture&) = delete; + + const scoped_refptr<V4L2DecodeSurface>& dec_surface() const { + return dec_surface_; + } + + private: + ~V4L2AV1Picture() override = default; + + scoped_refptr<AV1Picture> CreateDuplicate() override { + return new V4L2AV1Picture(dec_surface_); + } + + scoped_refptr<V4L2DecodeSurface> dec_surface_; +}; + +namespace { +// TODO(stevecho): Remove this when AV1 uAPI RFC v3 change +// (crrev/c/3859126) lands. +#ifndef BIT +#define BIT(nr) (1U << (nr)) +#endif + +// Section 5.5. Sequence header OBU syntax in the AV1 spec. +// https://aomediacodec.github.io/av1-spec +void FillSequenceParams(v4l2_ctrl_av1_sequence& v4l2_seq_params, + const libgav1::ObuSequenceHeader& seq_header) { + if (seq_header.still_picture) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_STILL_PICTURE; + + if (seq_header.use_128x128_superblock) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_USE_128X128_SUPERBLOCK; + + if (seq_header.enable_filter_intra) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_FILTER_INTRA; + + if (seq_header.enable_intra_edge_filter) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_INTRA_EDGE_FILTER; + + if (seq_header.enable_interintra_compound) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_INTERINTRA_COMPOUND; + + if (seq_header.enable_masked_compound) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_MASKED_COMPOUND; + + if (seq_header.enable_warped_motion) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_WARPED_MOTION; + + if (seq_header.enable_dual_filter) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_DUAL_FILTER; + + if (seq_header.enable_order_hint) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_ORDER_HINT; + + if (seq_header.enable_jnt_comp) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_JNT_COMP; + + if (seq_header.enable_ref_frame_mvs) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_REF_FRAME_MVS; + + if (seq_header.enable_superres) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_SUPERRES; + + if (seq_header.enable_cdef) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_CDEF; + + if (seq_header.enable_restoration) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_ENABLE_RESTORATION; + + if (seq_header.color_config.is_monochrome) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_MONO_CHROME; + + if (seq_header.color_config.color_range) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_COLOR_RANGE; + + if (seq_header.color_config.subsampling_x) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_SUBSAMPLING_X; + + if (seq_header.color_config.subsampling_y) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_SUBSAMPLING_Y; + + if (seq_header.film_grain_params_present) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_FILM_GRAIN_PARAMS_PRESENT; + + if (seq_header.color_config.separate_uv_delta_q) + v4l2_seq_params.flags |= V4L2_AV1_SEQUENCE_FLAG_SEPARATE_UV_DELTA_Q; + + v4l2_seq_params.seq_profile = seq_header.profile; + v4l2_seq_params.order_hint_bits = seq_header.order_hint_bits; + v4l2_seq_params.bit_depth = seq_header.color_config.bitdepth; + v4l2_seq_params.max_frame_width_minus_1 = seq_header.max_frame_width - 1; + v4l2_seq_params.max_frame_height_minus_1 = seq_header.max_frame_height - 1; +} + +// Section 5.9.11. Loop filter params syntax. +// Note that |update_ref_delta| and |update_mode_delta| flags in the spec +// are not needed for V4L2 AV1 API. +void FillLoopFilterParams(v4l2_av1_loop_filter& v4l2_lf, + const libgav1::LoopFilter& lf) { + if (lf.delta_enabled) + v4l2_lf.flags |= V4L2_AV1_LOOP_FILTER_FLAG_DELTA_ENABLED; + + if (lf.delta_update) + v4l2_lf.flags |= V4L2_AV1_LOOP_FILTER_FLAG_DELTA_UPDATE; + + static_assert(std::size(decltype(v4l2_lf.level){}) == libgav1::kFrameLfCount, + "Invalid size of loop filter level (strength) array"); + for (size_t i = 0; i < libgav1::kFrameLfCount; i++) + v4l2_lf.level[i] = base::checked_cast<__u8>(lf.level[i]); + + v4l2_lf.sharpness = lf.sharpness; + + static_assert(std::size(decltype(v4l2_lf.ref_deltas){}) == + libgav1::kNumReferenceFrameTypes, + "Invalid size of ref deltas array"); + for (size_t i = 0; i < libgav1::kNumReferenceFrameTypes; i++) + v4l2_lf.ref_deltas[i] = lf.ref_deltas[i]; + + static_assert(std::size(decltype(v4l2_lf.mode_deltas){}) == + libgav1::kLoopFilterMaxModeDeltas, + "Invalid size of mode deltas array"); + for (size_t i = 0; i < libgav1::kLoopFilterMaxModeDeltas; i++) + v4l2_lf.mode_deltas[i] = lf.mode_deltas[i]; +} + +// Section 5.9.12. Quantization params syntax +void FillQuantizationParams(v4l2_av1_quantization& v4l2_quant, + const libgav1::QuantizerParameters& quant) { + if (quant.use_matrix) + v4l2_quant.flags |= V4L2_AV1_QUANTIZATION_FLAG_USING_QMATRIX; + + v4l2_quant.base_q_idx = quant.base_index; + + // Note that quant.delta_ac[0] is useless + // because it is always 0 according to libgav1. + v4l2_quant.delta_q_y_dc = quant.delta_dc[0]; + + v4l2_quant.delta_q_u_dc = quant.delta_dc[1]; + v4l2_quant.delta_q_u_ac = quant.delta_ac[1]; + + v4l2_quant.delta_q_v_dc = quant.delta_dc[2]; + v4l2_quant.delta_q_v_ac = quant.delta_ac[2]; + + if (!quant.use_matrix) + return; + + v4l2_quant.qm_y = base::checked_cast<uint8_t>(quant.matrix_level[0]); + v4l2_quant.qm_u = base::checked_cast<uint8_t>(quant.matrix_level[1]); + v4l2_quant.qm_v = base::checked_cast<uint8_t>(quant.matrix_level[2]); +} + +} // namespace + +// Section 5.9.14. Segmentation params syntax +void FillSegmentationParams(struct v4l2_av1_segmentation& v4l2_seg, + const libgav1::Segmentation& seg) { + if (seg.enabled) + v4l2_seg.flags |= V4L2_AV1_SEGMENTATION_FLAG_ENABLED; + + if (seg.update_map) + v4l2_seg.flags |= V4L2_AV1_SEGMENTATION_FLAG_UPDATE_MAP; + + if (seg.temporal_update) + v4l2_seg.flags |= V4L2_AV1_SEGMENTATION_FLAG_TEMPORAL_UPDATE; + + if (seg.update_data) + v4l2_seg.flags |= V4L2_AV1_SEGMENTATION_FLAG_UPDATE_DATA; + + if (seg.segment_id_pre_skip) + v4l2_seg.flags |= V4L2_AV1_SEGMENTATION_FLAG_SEG_ID_PRE_SKIP; + + static_assert( + std::size(decltype(v4l2_seg.feature_enabled){}) == libgav1::kMaxSegments, + "Invalid size of |feature_enabled| array in |v4l2_av1_segmentation| " + "struct"); + + static_assert( + std::size(decltype(v4l2_seg.feature_data){}) == libgav1::kMaxSegments && + std::extent<decltype(v4l2_seg.feature_data), 0>::value == + libgav1::kSegmentFeatureMax, + "Invalid size of |feature_data| array in |v4l2_av1_segmentation| struct"); + + for (size_t i = 0; i < libgav1::kMaxSegments; ++i) { + for (size_t j = 0; j < libgav1::kSegmentFeatureMax; ++j) { + v4l2_seg.feature_enabled[i] |= (seg.feature_enabled[i][j] << j); + v4l2_seg.feature_data[i][j] = seg.feature_data[i][j]; + } + } + + v4l2_seg.last_active_seg_id = seg.last_active_segment_id; +} + +// Section 5.9.15. Tile info syntax +void FillTileInfo(v4l2_av1_tile_info& v4l2_ti, const libgav1::TileInfo& ti) { + if (ti.uniform_spacing) + v4l2_ti.flags |= V4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACING; + + static_assert(std::size(decltype(v4l2_ti.mi_col_starts){}) == + (libgav1::kMaxTileColumns + 1), + "Size of |mi_col_starts| array in |v4l2_av1_tile_info| struct " + "does not match libgav1 expectation"); + + for (size_t i = 0; i < libgav1::kMaxTileColumns + 1; i++) { + v4l2_ti.mi_col_starts[i] = + base::checked_cast<uint32_t>(ti.tile_column_start[i]); + } + static_assert(std::size(decltype(v4l2_ti.mi_row_starts){}) == + (libgav1::kMaxTileRows + 1), + "Size of |mi_row_starts| array in |v4l2_av1_tile_info| struct " + "does not match libgav1 expectation"); + for (size_t i = 0; i < libgav1::kMaxTileRows + 1; i++) { + v4l2_ti.mi_row_starts[i] = + base::checked_cast<uint32_t>(ti.tile_row_start[i]); + } + + if (!ti.uniform_spacing) { + // Confirmed that |kMaxTileColumns| is enough size for + // |width_in_sbs_minus_1| and |kMaxTileRows| is enough size for + // |height_in_sbs_minus_1| + // https://b.corp.google.com/issues/187828854#comment19 + static_assert( + std::size(decltype(v4l2_ti.width_in_sbs_minus_1){}) == + libgav1::kMaxTileColumns, + "Size of |width_in_sbs_minus_1| array in |v4l2_av1_tile_info| struct " + "does not match libgav1 expectation"); + for (size_t i = 0; i < libgav1::kMaxTileColumns; i++) { + if (ti.tile_column_width_in_superblocks[i] >= 1) { + v4l2_ti.width_in_sbs_minus_1[i] = base::checked_cast<uint32_t>( + ti.tile_column_width_in_superblocks[i] - 1); + } + } + + static_assert( + std::size(decltype(v4l2_ti.height_in_sbs_minus_1){}) == + libgav1::kMaxTileRows, + "Size of |height_in_sbs_minus_1| array in |v4l2_av1_tile_info| struct " + "does not match libgav1 expectation"); + for (size_t i = 0; i < libgav1::kMaxTileRows; i++) { + if (ti.tile_row_height_in_superblocks[i] >= 1) { + v4l2_ti.height_in_sbs_minus_1[i] = base::checked_cast<uint32_t>( + ti.tile_row_height_in_superblocks[i] - 1); + } + } + } + + v4l2_ti.tile_size_bytes = ti.tile_size_bytes; + v4l2_ti.context_update_tile_id = ti.context_update_id; + v4l2_ti.tile_cols = ti.tile_columns; + v4l2_ti.tile_rows = ti.tile_rows; +} + +// Section 5.9.17. Quantizer index delta parameters syntax +void FillQuantizerIndexDeltaParams(struct v4l2_av1_quantization& v4l2_quant, + const libgav1::ObuSequenceHeader& seq_header, + const libgav1::ObuFrameHeader& frm_header) { + // |diff_uv_delta| in the spec doesn't exist in libgav1, + // because libgav1 infers it using the following logic. + const bool diff_uv_delta = (frm_header.quantizer.base_index != 0) && + (!seq_header.color_config.is_monochrome) && + (seq_header.color_config.separate_uv_delta_q); + if (diff_uv_delta) + v4l2_quant.flags |= V4L2_AV1_QUANTIZATION_FLAG_DIFF_UV_DELTA; + + if (frm_header.delta_q.present) + v4l2_quant.flags |= V4L2_AV1_QUANTIZATION_FLAG_DELTA_Q_PRESENT; + + // |scale| is used to store |delta_q_res| value. This is because libgav1 uses + // the same struct |Delta| both for quantizer index delta parameters and loop + // filter delta parameters. + v4l2_quant.delta_q_res = frm_header.delta_q.scale; +} + +// Section 5.9.18. Loop filter delta parameters syntax. +// Note that |delta_lf_res| in |v4l2_av1_loop_filter| corresponds to +// |delta_lf.scale| in the frame header defined in libgav1. +void FillLoopFilterDeltaParams(struct v4l2_av1_loop_filter& v4l2_lf, + const libgav1::Delta& delta_lf) { + if (delta_lf.present) + v4l2_lf.flags |= V4L2_AV1_LOOP_FILTER_FLAG_DELTA_LF_PRESENT; + + if (delta_lf.multi) + v4l2_lf.flags |= V4L2_AV1_LOOP_FILTER_FLAG_DELTA_LF_MULTI; + + v4l2_lf.delta_lf_res = delta_lf.scale; +} + +// Section 5.9.19. CDEF params syntax +void FillCdefParams(struct v4l2_av1_cdef& v4l2_cdef, + const libgav1::Cdef& cdef, + uint8_t color_bitdepth) { + // Damping value parsed in libgav1 is from the spec + (bitdepth - 8). + // All the strength values parsed in libgav1 are from the spec and left + // shifted by (bitdepth - 8). + CHECK_GE(color_bitdepth, 8u); + const uint8_t coeff_shift = color_bitdepth - 8u; + + v4l2_cdef.damping_minus_3 = + base::checked_cast<uint8_t>(cdef.damping - coeff_shift - 3u); + + v4l2_cdef.bits = cdef.bits; + + static_assert(std::size(decltype(v4l2_cdef.y_pri_strength){}) == + libgav1::kMaxCdefStrengths, + "Invalid size of cdef y_pri_strength strength"); + + static_assert(std::size(decltype(v4l2_cdef.y_sec_strength){}) == + libgav1::kMaxCdefStrengths, + "Invalid size of cdef y_sec_strength strength"); + + static_assert(std::size(decltype(v4l2_cdef.uv_pri_strength){}) == + libgav1::kMaxCdefStrengths, + "Invalid size of cdef uv_pri_strength strength"); + + static_assert(std::size(decltype(v4l2_cdef.uv_sec_strength){}) == + libgav1::kMaxCdefStrengths, + "Invalid size of cdef uv_sec_strength strength"); + + SafeArrayMemcpy(v4l2_cdef.y_pri_strength, cdef.y_primary_strength); + SafeArrayMemcpy(v4l2_cdef.y_sec_strength, cdef.y_secondary_strength); + SafeArrayMemcpy(v4l2_cdef.uv_pri_strength, cdef.uv_primary_strength); + SafeArrayMemcpy(v4l2_cdef.uv_sec_strength, cdef.uv_secondary_strength); +} + +// 5.9.20. Loop restoration params syntax +void FillLoopRestorationParams(v4l2_av1_loop_restoration& v4l2_lr, + const libgav1::LoopRestoration& lr) { + for (size_t i = 0; i < V4L2_AV1_NUM_PLANES_MAX; i++) { + switch (lr.type[i]) { + case libgav1::LoopRestorationType::kLoopRestorationTypeNone: + v4l2_lr.frame_restoration_type[i] = V4L2_AV1_FRAME_RESTORE_NONE; + break; + case libgav1::LoopRestorationType::kLoopRestorationTypeWiener: + v4l2_lr.frame_restoration_type[i] = V4L2_AV1_FRAME_RESTORE_WIENER; + break; + case libgav1::LoopRestorationType::kLoopRestorationTypeSgrProj: + v4l2_lr.frame_restoration_type[i] = V4L2_AV1_FRAME_RESTORE_SGRPROJ; + break; + case libgav1::LoopRestorationType::kLoopRestorationTypeSwitchable: + v4l2_lr.frame_restoration_type[i] = V4L2_AV1_FRAME_RESTORE_SWITCHABLE; + break; + default: + NOTREACHED() << "Invalid loop restoration type"; + } + + if (v4l2_lr.frame_restoration_type[i] != V4L2_AV1_FRAME_RESTORE_NONE) { + if (true) + v4l2_lr.flags |= V4L2_AV1_LOOP_RESTORATION_FLAG_USES_LR; + + if (i > 0) + v4l2_lr.flags |= V4L2_AV1_LOOP_RESTORATION_FLAG_USES_CHROMA_LR; + } + } + + const bool use_loop_restoration = + std::find_if(std::begin(lr.type), + std::begin(lr.type) + libgav1::kMaxPlanes, + [](const auto type) { + return type != libgav1::kLoopRestorationTypeNone; + }) != (lr.type + libgav1::kMaxPlanes); + + if (!use_loop_restoration) + return; + + DCHECK_GE(lr.unit_size_log2[0], lr.unit_size_log2[1]); + DCHECK_LE(lr.unit_size_log2[0] - lr.unit_size_log2[1], 1); + v4l2_lr.lr_unit_shift = lr.unit_size_log2[0] - 6; + v4l2_lr.lr_uv_shift = lr.unit_size_log2[0] - lr.unit_size_log2[1]; + + // AV1 spec (p.52) uses this formula with hard coded value 2. + // https://aomediacodec.github.io/av1-spec/#loop-restoration-params-syntax + v4l2_lr.loop_restoration_size[0] = + V4L2_AV1_RESTORATION_TILESIZE_MAX >> (2 - v4l2_lr.lr_unit_shift); + v4l2_lr.loop_restoration_size[1] = + v4l2_lr.loop_restoration_size[0] >> v4l2_lr.lr_uv_shift; + v4l2_lr.loop_restoration_size[2] = + v4l2_lr.loop_restoration_size[0] >> v4l2_lr.lr_uv_shift; +} + +V4L2VideoDecoderDelegateAV1::V4L2VideoDecoderDelegateAV1( + V4L2DecodeSurfaceHandler* surface_handler, + V4L2Device* device) + : surface_handler_(surface_handler), device_(device) { + VLOGF(1); + DCHECK(surface_handler_); + DCHECK(device_); +} + +V4L2VideoDecoderDelegateAV1::~V4L2VideoDecoderDelegateAV1() = default; + +scoped_refptr<AV1Picture> V4L2VideoDecoderDelegateAV1::CreateAV1Picture( + bool apply_grain) { + scoped_refptr<V4L2DecodeSurface> dec_surface = + surface_handler_->CreateSurface(); + if (!dec_surface) + return nullptr; + + return new V4L2AV1Picture(std::move(dec_surface)); +} + +DecodeStatus V4L2VideoDecoderDelegateAV1::SubmitDecode( + const AV1Picture& pic, + const libgav1::ObuSequenceHeader& sequence_header, + const AV1ReferenceFrameVector& ref_frames, + const libgav1::Vector<libgav1::TileBuffer>& tile_buffers, + base::span<const uint8_t> data) { + struct v4l2_ctrl_av1_sequence v4l2_seq_params = {}; + FillSequenceParams(v4l2_seq_params, sequence_header); + + const libgav1::ObuFrameHeader& frame_header = pic.frame_header; + + struct v4l2_av1_loop_filter v4l2_lf = {}; + FillLoopFilterParams(v4l2_lf, frame_header.loop_filter); + + FillLoopFilterDeltaParams(v4l2_lf, frame_header.delta_lf); + + struct v4l2_av1_quantization v4l2_quant = {}; + FillQuantizationParams(v4l2_quant, frame_header.quantizer); + + FillQuantizerIndexDeltaParams(v4l2_quant, sequence_header, frame_header); + + struct v4l2_av1_segmentation v4l2_seg = {}; + FillSegmentationParams(v4l2_seg, frame_header.segmentation); + + const auto color_bitdepth = sequence_header.color_config.bitdepth; + struct v4l2_av1_cdef v4l2_cdef = {}; + FillCdefParams(v4l2_cdef, frame_header.cdef, + base::strict_cast<int8_t>(color_bitdepth)); + + struct v4l2_av1_loop_restoration v4l2_lr = {}; + FillLoopRestorationParams(v4l2_lr, frame_header.loop_restoration); + + struct v4l2_av1_tile_info v4l2_ti = {}; + FillTileInfo(v4l2_ti, frame_header.tile_info); + + struct v4l2_ctrl_av1_frame v4l2_frame_params = {}; + if (frame_header.show_frame) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_SHOW_FRAME; + if (frame_header.showable_frame) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_SHOWABLE_FRAME; + if (frame_header.error_resilient_mode) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_ERROR_RESILIENT_MODE; + if (frame_header.enable_cdf_update == false) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_DISABLE_CDF_UPDATE; + if (frame_header.allow_screen_content_tools) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_ALLOW_SCREEN_CONTENT_TOOLS; + if (frame_header.force_integer_mv) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_FORCE_INTEGER_MV; + if (frame_header.allow_intrabc) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_ALLOW_INTRABC; + if (frame_header.use_superres) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_USE_SUPERRES; + if (frame_header.allow_high_precision_mv) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_ALLOW_HIGH_PRECISION_MV; + if (frame_header.is_motion_mode_switchable) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_IS_MOTION_MODE_SWITCHABLE; + if (frame_header.use_ref_frame_mvs) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_USE_REF_FRAME_MVS; + if (frame_header.enable_frame_end_update_cdf == false) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_DISABLE_FRAME_END_UPDATE_CDF; + if (frame_header.tile_info.uniform_spacing) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_UNIFORM_TILE_SPACING; + if (frame_header.allow_warped_motion) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_ALLOW_WARPED_MOTION; + if (frame_header.reference_mode_select) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_REFERENCE_SELECT; + if (frame_header.reduced_tx_set) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_REDUCED_TX_SET; + if (frame_header.skip_mode_frame[0] > 0) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_SKIP_MODE_ALLOWED; + if (frame_header.skip_mode_present) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_SKIP_MODE_PRESENT; + if (frame_header.frame_size_override_flag) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_FRAME_SIZE_OVERRIDE; + // libgav1 header doesn't have |buffer_removal_time_present_flag|. + if (frame_header.buffer_removal_time[0] > 0) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_BUFFER_REMOVAL_TIME_PRESENT; + if (frame_header.frame_refs_short_signaling) + v4l2_frame_params.flags |= V4L2_AV1_FRAME_FLAG_FRAME_REFS_SHORT_SIGNALING; + + switch (frame_header.frame_type) { + case libgav1::kFrameKey: + v4l2_frame_params.frame_type = V4L2_AV1_KEY_FRAME; + break; + case libgav1::kFrameInter: + v4l2_frame_params.frame_type = V4L2_AV1_INTER_FRAME; + break; + case libgav1::kFrameIntraOnly: + v4l2_frame_params.frame_type = V4L2_AV1_INTRA_ONLY_FRAME; + break; + case libgav1::kFrameSwitch: + v4l2_frame_params.frame_type = V4L2_AV1_SWITCH_FRAME; + break; + default: + NOTREACHED() << "Invalid frame type, " << frame_header.frame_type; + } + + v4l2_frame_params.order_hint = frame_header.order_hint; + v4l2_frame_params.superres_denom = frame_header.superres_scale_denominator; + v4l2_frame_params.upscaled_width = frame_header.upscaled_width; + + switch (frame_header.interpolation_filter) { + case libgav1::kInterpolationFilterEightTap: + v4l2_frame_params.interpolation_filter = + V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP; + break; + case libgav1::kInterpolationFilterEightTapSmooth: + v4l2_frame_params.interpolation_filter = + V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP_SMOOTH; + break; + case libgav1::kInterpolationFilterEightTapSharp: + v4l2_frame_params.interpolation_filter = + V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP_SHARP; + break; + case libgav1::kInterpolationFilterBilinear: + v4l2_frame_params.interpolation_filter = + V4L2_AV1_INTERPOLATION_FILTER_BILINEAR; + break; + case libgav1::kInterpolationFilterSwitchable: + v4l2_frame_params.interpolation_filter = + V4L2_AV1_INTERPOLATION_FILTER_SWITCHABLE; + break; + default: + NOTREACHED() << "Invalid interpolation filter, " + << frame_header.interpolation_filter; + } + + switch (frame_header.tx_mode) { + case libgav1::kTxModeOnly4x4: + v4l2_frame_params.tx_mode = V4L2_AV1_TX_MODE_ONLY_4X4; + break; + case libgav1::kTxModeLargest: + v4l2_frame_params.tx_mode = V4L2_AV1_TX_MODE_LARGEST; + break; + case libgav1::kTxModeSelect: + v4l2_frame_params.tx_mode = V4L2_AV1_TX_MODE_SELECT; + break; + default: + NOTREACHED() << "Invalid tx mode, " << frame_header.tx_mode; + } + + v4l2_frame_params.frame_width_minus_1 = frame_header.width - 1; + v4l2_frame_params.frame_height_minus_1 = frame_header.height - 1; + v4l2_frame_params.render_width_minus_1 = frame_header.render_width - 1; + v4l2_frame_params.render_height_minus_1 = frame_header.render_height - 1; + + v4l2_frame_params.current_frame_id = frame_header.current_frame_id; + v4l2_frame_params.primary_ref_frame = frame_header.primary_reference_frame; + SafeArrayMemcpy(v4l2_frame_params.buffer_removal_time, + frame_header.buffer_removal_time); + v4l2_frame_params.refresh_frame_flags = frame_header.refresh_frame_flags; + + // TODO(b/248602457): Enable code for |order_hints| setup + // after |ref_order_hint| maintenance is implemented. + + // These params looks duplicated with |ref_frame_idx|, but they are required + // and used when |frame_refs_short_signaling| is set according to the AV1 + // spec. https://aomediacodec.github.io/av1-spec/#uncompressed-header-syntax + v4l2_frame_params.last_frame_idx = + frame_header.reference_frame_index[libgav1::kReferenceFrameLast]; + v4l2_frame_params.gold_frame_idx = + frame_header.reference_frame_index[libgav1::kReferenceFrameGolden]; + + for (size_t i = 0; i < libgav1::kNumReferenceFrameTypes; ++i) { + const auto* v4l2_ref_pic = + static_cast<const V4L2AV1Picture*>(ref_frames[i].get()); + + v4l2_frame_params.reference_frame_ts[i] = + v4l2_ref_pic->dec_surface()->GetReferenceID(); + } + + static_assert(std::size(decltype(v4l2_frame_params.ref_frame_idx){}) == + libgav1::kNumInterReferenceFrameTypes, + "Invalid size of |ref_frame_idx| array"); + for (size_t i = 0; i < libgav1::kNumInterReferenceFrameTypes; i++) + v4l2_frame_params.ref_frame_idx[i] = + base::checked_cast<__u8>(frame_header.reference_frame_index[i]); + + v4l2_frame_params.skip_mode_frame[0] = + base::checked_cast<__u8>(frame_header.skip_mode_frame[0]); + v4l2_frame_params.skip_mode_frame[1] = + base::checked_cast<__u8>(frame_header.skip_mode_frame[1]); + + NOTIMPLEMENTED(); + + return DecodeStatus::kFail; +} + +bool V4L2VideoDecoderDelegateAV1::OutputPicture(const AV1Picture& pic) { + VLOGF(3); + const auto* v4l2_pic = static_cast<const V4L2AV1Picture*>(&pic); + + surface_handler_->SurfaceReady( + v4l2_pic->dec_surface(), v4l2_pic->bitstream_id(), + v4l2_pic->visible_rect(), v4l2_pic->get_colorspace()); + + return true; +} + +} // namespace media diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_av1.h b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_av1.h new file mode 100644 index 00000000000..43894385a57 --- /dev/null +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_av1.h @@ -0,0 +1,48 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MEDIA_GPU_V4L2_V4L2_VIDEO_DECODER_DELEGATE_AV1_H_ +#define MEDIA_GPU_V4L2_V4L2_VIDEO_DECODER_DELEGATE_AV1_H_ + +#include "media/gpu/av1_decoder.h" + +#ifndef V4L2_AV1_RESTORATION_TILESIZE_MAX +#define V4L2_AV1_RESTORATION_TILESIZE_MAX 256 +#endif + +namespace media { + +class V4L2DecodeSurfaceHandler; +class V4L2Device; + +class V4L2VideoDecoderDelegateAV1 : public AV1Decoder::AV1Accelerator { + public: + V4L2VideoDecoderDelegateAV1(V4L2DecodeSurfaceHandler* surface_handler, + V4L2Device* device); + + V4L2VideoDecoderDelegateAV1(const V4L2VideoDecoderDelegateAV1&) = delete; + V4L2VideoDecoderDelegateAV1& operator=(const V4L2VideoDecoderDelegateAV1&) = + delete; + + ~V4L2VideoDecoderDelegateAV1() override; + + // AV1Decoder::AV1Accelerator implementation. + scoped_refptr<AV1Picture> CreateAV1Picture(bool apply_grain) override; + + Status SubmitDecode(const AV1Picture& pic, + const libgav1::ObuSequenceHeader& sequence_header, + const AV1ReferenceFrameVector& ref_frames, + const libgav1::Vector<libgav1::TileBuffer>& tile_buffers, + base::span<const uint8_t> data) override; + + bool OutputPicture(const AV1Picture& pic) override; + + private: + V4L2DecodeSurfaceHandler* const surface_handler_; + V4L2Device* const device_; +}; + +} // namespace media + +#endif // MEDIA_GPU_V4L2_V4L2_VIDEO_DECODER_DELEGATE_AV1_H_ diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264.cc index 9f37ddcc7bf..a392c11ca95 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264.h b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264.h index 308ef7f36de..2309dcaf9dd 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264_legacy.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264_legacy.cc index 2957beeb8c5..bf8823d8958 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264_legacy.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264_legacy.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264_legacy.h b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264_legacy.h index 21483799727..802755e518d 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264_legacy.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_h264_legacy.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8.cc index 3523c83446f..52e888dac09 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8.h b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8.h index 77bc2b9c890..880e92636a3 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8_legacy.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8_legacy.cc index 674e31c57a9..c8dfebfff2b 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8_legacy.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8_legacy.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8_legacy.h b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8_legacy.h index 41867dd6746..dd623cd3e1d 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8_legacy.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp8_legacy.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9.cc index be3008d586b..6d5fa99d12e 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9.cc @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9.h b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9.h index f5725496dac..51540d412f3 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9.h @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9_legacy.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9_legacy.cc index 227eef09d18..a8d06890b7d 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9_legacy.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9_legacy.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9_legacy.h b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9_legacy.h index 6943ec590bb..7efe7bb86ab 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9_legacy.h +++ b/chromium/media/gpu/v4l2/v4l2_video_decoder_delegate_vp9_legacy.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/v4l2/v4l2_video_encode_accelerator.cc b/chromium/media/gpu/v4l2/v4l2_video_encode_accelerator.cc index 8b6f57bcab9..58c78cee265 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_encode_accelerator.cc +++ b/chromium/media/gpu/v4l2/v4l2_video_encode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -399,10 +399,10 @@ void V4L2VideoEncodeAccelerator::InitializeTask(const Config& config) { // Notify VideoEncoderInfo after initialization. VideoEncoderInfo encoder_info; encoder_info.implementation_name = "V4L2VideoEncodeAccelerator"; - encoder_info.has_trusted_rate_controller = true; - encoder_info.is_hardware_accelerated = true; - encoder_info.supports_native_handle = true; - encoder_info.supports_simulcast = false; + DCHECK(!encoder_info.has_trusted_rate_controller); + DCHECK(encoder_info.is_hardware_accelerated); + DCHECK(encoder_info.supports_native_handle); + DCHECK(!encoder_info.supports_simulcast); // V4L2VideoEncodeAccelerator doesn't support either temporal-SVC or // spatial-SVC. A single stream shall be output at the desired FPS. @@ -431,7 +431,7 @@ bool V4L2VideoEncodeAccelerator::CreateImageProcessor( VideoFrame::StorageType input_storage_type = native_input_mode_ ? VideoFrame::STORAGE_GPU_MEMORY_BUFFER - : VideoFrame::STORAGE_MOJO_SHARED_BUFFER; + : VideoFrame::STORAGE_SHMEM; auto input_config = VideoFrameLayoutToPortConfig( *ip_input_layout, input_visible_rect, {input_storage_type}); if (!input_config) { @@ -617,6 +617,14 @@ void V4L2VideoEncodeAccelerator::Flush(FlushCallback flush_callback) { void V4L2VideoEncodeAccelerator::FlushTask(FlushCallback flush_callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(encoder_sequence_checker_); + if (encoder_state_ == kInitialized) { + // Flush() is called before either Encode() or UseOutputBitstreamBuffer() is + // called. Just return as successful. + child_task_runner_->PostTask( + FROM_HERE, base::BindOnce(std::move(flush_callback), true)); + return; + } + if (flush_callback_ || encoder_state_ != kEncoding) { VLOGF(1) << "Flush failed: there is a pending flush, " << "or VideoEncodeAccelerator is not in kEncoding state"; @@ -776,7 +784,7 @@ void V4L2VideoEncodeAccelerator::EncodeTask(scoped_refptr<VideoFrame> frame, const bool is_expected_storage_type = native_input_mode_ ? frame->storage_type() == VideoFrame::STORAGE_GPU_MEMORY_BUFFER - : frame->IsMappable(); + : frame->storage_type() == VideoFrame::STORAGE_SHMEM; if (!is_expected_storage_type) { VLOGF(1) << "Unexpected storage: " << VideoFrame::StorageTypeToString(frame->storage_type()); @@ -793,6 +801,12 @@ void V4L2VideoEncodeAccelerator::EncodeTask(scoped_refptr<VideoFrame> frame, // not been called yet. if (input_buffer_map_.empty() && !CreateInputBuffers()) return; + + if (encoder_state_ == kInitialized) { + if (!StartDevicePoll()) + return; + encoder_state_ = kEncoding; + } } if (image_processor_) { @@ -1157,8 +1171,14 @@ void V4L2VideoEncodeAccelerator::Enqueue() { DCHECK(!output_queue_->IsStreaming() && !input_queue_->IsStreaming()); // When VIDIOC_STREAMON can be executed in OUTPUT queue, it is fine to call // STREAMON in CAPTURE queue. - output_queue_->Streamon(); - input_queue_->Streamon(); + if (!output_queue_->Streamon()) { + NOTIFY_ERROR(kPlatformFailureError); + return; + } + if (!input_queue_->Streamon()) { + NOTIFY_ERROR(kPlatformFailureError); + return; + } } } @@ -1368,14 +1388,44 @@ bool V4L2VideoEncodeAccelerator::EnqueueInputRecord( switch (input_buf.Memory()) { case V4L2_MEMORY_USERPTR: { - std::vector<void*> user_ptrs; - for (size_t i = 0; i < num_planes; ++i) - user_ptrs.push_back(frame->data(i)); - std::move(input_buf).QueueUserPtr(std::move(user_ptrs)); + if (frame->storage_type() != VideoFrame::STORAGE_SHMEM) { + VLOGF(1) << "VideoFrame doesn't have shared memory"; + NOTIFY_ERROR(kPlatformFailureError); + } + + // TODO(b/243883312): This copies the video frame to a writable buffer + // since the USERPTR API requires writable permission. Remove this + // workaround once the unreasonable permission is fixed. + const size_t buffer_size = frame->shm_region()->GetSize(); + std::vector<uint8_t> writable_buffer(buffer_size); + std::memcpy(writable_buffer.data(), frame->data(0), buffer_size); + std::vector<void*> user_ptrs(num_planes); + for (size_t i = 0; i < num_planes; ++i) { + const std::intptr_t plane_offset = + reinterpret_cast<std::intptr_t>(frame->data(i)) - + reinterpret_cast<std::intptr_t>(frame->data(0)); + user_ptrs[i] = writable_buffer.data() + plane_offset; + } + + if (!std::move(input_buf).QueueUserPtr(std::move(user_ptrs))) { + VPLOGF(1) << "Failed to queue a USRPTR buffer to input queue"; + NOTIFY_ERROR(kPlatformFailureError); + return false; + } + frame->AddDestructionObserver(base::BindOnce([](std::vector<uint8_t>) {}, + std::move(writable_buffer))); break; } case V4L2_MEMORY_DMABUF: { - std::move(input_buf).QueueDMABuf(gmb_handle.native_pixmap_handle.planes); + if (!std::move(input_buf).QueueDMABuf( + gmb_handle.native_pixmap_handle.planes)) { + VPLOGF(1) << "Failed queue a DMABUF buffer to input queue"; + return false; + } + // Keep |gmb_handle| alive as long as |frame| is alive so that fds passed + // to the driver are valid during encoding. + frame->AddDestructionObserver(base::BindOnce( + [](gfx::GpuMemoryBufferHandle) {}, std::move(gmb_handle))); break; } default: @@ -1384,11 +1434,6 @@ bool V4L2VideoEncodeAccelerator::EnqueueInputRecord( return false; } - // Keep |gmb_handle| alive as long as |frame| is alive so that fds passed - // to the driver are valid during encoding. - frame->AddDestructionObserver( - base::BindOnce([](gfx::GpuMemoryBufferHandle) {}, std::move(gmb_handle))); - InputRecord& input_record = input_buffer_map_[buffer_id]; input_record.frame = frame; input_record.ip_output_buffer_index = frame_info.ip_output_buffer_index; @@ -1969,7 +2014,9 @@ void V4L2VideoEncodeAccelerator::DestroyInputBuffers() { return; DCHECK(!input_queue_->IsStreaming()); - input_queue_->DeallocateBuffers(); + if (!input_queue_->DeallocateBuffers()) + VLOGF(1) << "Failed to deallocate V4L2 input buffers"; + input_buffer_map_.clear(); } @@ -1981,7 +2028,8 @@ void V4L2VideoEncodeAccelerator::DestroyOutputBuffers() { return; DCHECK(!output_queue_->IsStreaming()); - output_queue_->DeallocateBuffers(); + if (!output_queue_->DeallocateBuffers()) + VLOGF(1) << "Failed to deallocate V4L2 output buffers"; } } // namespace media diff --git a/chromium/media/gpu/v4l2/v4l2_video_encode_accelerator.h b/chromium/media/gpu/v4l2/v4l2_video_encode_accelerator.h index 686b3c29fbe..e3dfdf392ab 100644 --- a/chromium/media/gpu/v4l2/v4l2_video_encode_accelerator.h +++ b/chromium/media/gpu/v4l2/v4l2_video_encode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/BUILD.gn b/chromium/media/gpu/vaapi/BUILD.gn index 8fbc73ddac3..29aa09bb597 100644 --- a/chromium/media/gpu/vaapi/BUILD.gn +++ b/chromium/media/gpu/vaapi/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2018 The Chromium Authors. All rights reserved. +# Copyright 2018 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/av1_vaapi_video_decoder_delegate.cc b/chromium/media/gpu/vaapi/av1_vaapi_video_decoder_delegate.cc index 7c7214d5a1a..53e4d89e7f4 100644 --- a/chromium/media/gpu/vaapi/av1_vaapi_video_decoder_delegate.cc +++ b/chromium/media/gpu/vaapi/av1_vaapi_video_decoder_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -738,6 +738,7 @@ AV1VaapiVideoDecoderDelegate::~AV1VaapiVideoDecoderDelegate() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(!picture_params_); DCHECK(!crypto_params_); + DCHECK(!protected_params_); } scoped_refptr<AV1Picture> AV1VaapiVideoDecoderDelegate::CreateAV1Picture( @@ -852,22 +853,47 @@ DecodeStatus AV1VaapiVideoDecoderDelegate::SubmitDecode( // also be adjusted. // Create VASliceData buffer |encoded_data| every frame so that decoding can // be more asynchronous than reusing the buffer. - auto encoded_data = - vaapi_wrapper_->CreateVABuffer(VASliceDataBufferType, data.size_bytes()); - if (!encoded_data) - return DecodeStatus::kFail; + std::unique_ptr<ScopedVABuffer> encoded_data; std::vector<std::pair<VABufferID, VaapiWrapper::VABufferDescriptor>> buffers = {{picture_params_->id(), - {picture_params_->type(), picture_params_->size(), &pic_param}}, - {encoded_data->id(), - {encoded_data->type(), encoded_data->size(), data.data()}}}; - for (size_t i = 0; i < slice_params.size(); ++i) { - buffers.push_back({slice_params_va_buffers[i]->id(), - {slice_params_va_buffers[i]->type(), - slice_params_va_buffers[i]->size(), &slice_params[i]}}); - } + {picture_params_->type(), picture_params_->size(), &pic_param}}}; + buffers.reserve(3 + slice_params.size()); +#if BUILDFLAG(IS_CHROMEOS_ASH) + if (IsTranscrypted()) { + CHECK(decrypt_config); + CHECK_EQ(decrypt_config->subsamples().size(), 2u); + if (!protected_params_) { + protected_params_ = vaapi_wrapper_->CreateVABuffer( + VAProtectedSliceDataBufferType, decrypt_config->key_id().length()); + if (!protected_params_) + return DecodeStatus::kFail; + } + DCHECK_EQ(decrypt_config->key_id().length(), protected_params_->size()); + buffers.push_back({protected_params_->id(), + {protected_params_->type(), protected_params_->size(), + decrypt_config->key_id().data()}}); + encoded_data = vaapi_wrapper_->CreateVABuffer( + VASliceDataBufferType, + base::strict_cast<size_t>( + decrypt_config->subsamples()[0].cypher_bytes)); + if (!encoded_data) + return DecodeStatus::kFail; + buffers.push_back( + {encoded_data->id(), + {encoded_data->type(), encoded_data->size(), + data.data() + decrypt_config->subsamples()[0].clear_bytes}}); + } else { +#endif // BUILDFLAG(IS_CHROMEOS_ASH) + encoded_data = vaapi_wrapper_->CreateVABuffer(VASliceDataBufferType, + data.size_bytes()); + if (!encoded_data) + return DecodeStatus::kFail; + buffers.push_back( + {encoded_data->id(), + {encoded_data->type(), encoded_data->size(), data.data()}}); #if BUILDFLAG(IS_CHROMEOS_ASH) + } if (uses_crypto) { buffers.push_back( {crypto_params_->id(), @@ -875,6 +901,12 @@ DecodeStatus AV1VaapiVideoDecoderDelegate::SubmitDecode( } #endif // BUILDFLAG(IS_CHROMEOS_ASH) + for (size_t i = 0; i < slice_params.size(); ++i) { + buffers.push_back({slice_params_va_buffers[i]->id(), + {slice_params_va_buffers[i]->type(), + slice_params_va_buffers[i]->size(), &slice_params[i]}}); + } + const auto* vaapi_pic = static_cast<const VaapiAV1Picture*>(&pic); const bool success = vaapi_wrapper_->MapAndCopyAndExecute( vaapi_pic->reconstruct_va_surface()->id(), buffers); @@ -892,5 +924,6 @@ void AV1VaapiVideoDecoderDelegate::OnVAContextDestructionSoon() { // that will be destroyed soon. picture_params_.reset(); crypto_params_.reset(); + protected_params_.reset(); } } // namespace media diff --git a/chromium/media/gpu/vaapi/av1_vaapi_video_decoder_delegate.h b/chromium/media/gpu/vaapi/av1_vaapi_video_decoder_delegate.h index 31fd5a4f2f6..7468f5821ba 100644 --- a/chromium/media/gpu/vaapi/av1_vaapi_video_decoder_delegate.h +++ b/chromium/media/gpu/vaapi/av1_vaapi_video_decoder_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -44,6 +44,7 @@ class AV1VaapiVideoDecoderDelegate : public AV1Decoder::AV1Accelerator, private: std::unique_ptr<ScopedVABuffer> picture_params_; std::unique_ptr<ScopedVABuffer> crypto_params_; + std::unique_ptr<ScopedVABuffer> protected_params_; }; } // namespace media #endif // MEDIA_GPU_VAAPI_AV1_VAAPI_VIDEO_DECODER_DELEGATE_H_ diff --git a/chromium/media/gpu/vaapi/fuzzers/jpeg_decoder/BUILD.gn b/chromium/media/gpu/vaapi/fuzzers/jpeg_decoder/BUILD.gn index 37b7d6f0387..031785b1c16 100644 --- a/chromium/media/gpu/vaapi/fuzzers/jpeg_decoder/BUILD.gn +++ b/chromium/media/gpu/vaapi/fuzzers/jpeg_decoder/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2019 The Chromium Authors. All rights reserved. +# Copyright 2019 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/h264_vaapi_video_decoder_delegate.cc b/chromium/media/gpu/vaapi/h264_vaapi_video_decoder_delegate.cc index 5999fa5b38f..186a1808384 100644 --- a/chromium/media/gpu/vaapi/h264_vaapi_video_decoder_delegate.cc +++ b/chromium/media/gpu/vaapi/h264_vaapi_video_decoder_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/h264_vaapi_video_decoder_delegate.h b/chromium/media/gpu/vaapi/h264_vaapi_video_decoder_delegate.h index 191f609cada..1cad17eb26d 100644 --- a/chromium/media/gpu/vaapi/h264_vaapi_video_decoder_delegate.h +++ b/chromium/media/gpu/vaapi/h264_vaapi_video_decoder_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate.cc b/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate.cc index 904767443ab..d8871537603 100644 --- a/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate.cc +++ b/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate.h b/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate.h index c6f0badf8d3..55ad4bea8c0 100644 --- a/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate.h +++ b/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate_unittest.cc b/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate_unittest.cc index 93569661f1c..61928fce47a 100644 --- a/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate_unittest.cc +++ b/chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/h265_vaapi_video_decoder_delegate.cc b/chromium/media/gpu/vaapi/h265_vaapi_video_decoder_delegate.cc index ed283709f74..5819efb541b 100644 --- a/chromium/media/gpu/vaapi/h265_vaapi_video_decoder_delegate.cc +++ b/chromium/media/gpu/vaapi/h265_vaapi_video_decoder_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/h265_vaapi_video_decoder_delegate.h b/chromium/media/gpu/vaapi/h265_vaapi_video_decoder_delegate.h index 9c699998131..e33bad7fc87 100644 --- a/chromium/media/gpu/vaapi/h265_vaapi_video_decoder_delegate.h +++ b/chromium/media/gpu/vaapi/h265_vaapi_video_decoder_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/test_utils.cc b/chromium/media/gpu/vaapi/test_utils.cc index f578bae1071..0233870fcbe 100644 --- a/chromium/media/gpu/vaapi/test_utils.cc +++ b/chromium/media/gpu/vaapi/test_utils.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/test_utils.h b/chromium/media/gpu/vaapi/test_utils.h index c05be315a8d..e08a1ab54c3 100644 --- a/chromium/media/gpu/vaapi/test_utils.h +++ b/chromium/media/gpu/vaapi/test_utils.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/va.sigs b/chromium/media/gpu/vaapi/va.sigs index a735f310edd..f08976bef0e 100644 --- a/chromium/media/gpu/vaapi/va.sigs +++ b/chromium/media/gpu/vaapi/va.sigs @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/va_drm.sigs b/chromium/media/gpu/vaapi/va_drm.sigs index 093e36c8851..295921d1f18 100644 --- a/chromium/media/gpu/vaapi/va_drm.sigs +++ b/chromium/media/gpu/vaapi/va_drm.sigs @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/va_prot.sigs b/chromium/media/gpu/vaapi/va_prot.sigs index dd13dafef1a..183319bbd72 100644 --- a/chromium/media/gpu/vaapi/va_prot.sigs +++ b/chromium/media/gpu/vaapi/va_prot.sigs @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/va_surface.cc b/chromium/media/gpu/vaapi/va_surface.cc index 64d213c050f..c07ff15d8f5 100644 --- a/chromium/media/gpu/vaapi/va_surface.cc +++ b/chromium/media/gpu/vaapi/va_surface.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/va_surface.h b/chromium/media/gpu/vaapi/va_surface.h index 813fb725fd3..60c41b26e9f 100644 --- a/chromium/media/gpu/vaapi/va_surface.h +++ b/chromium/media/gpu/vaapi/va_surface.h @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // diff --git a/chromium/media/gpu/vaapi/va_x11.sigs b/chromium/media/gpu/vaapi/va_x11.sigs index d87356b5c20..748e11c2dbb 100644 --- a/chromium/media/gpu/vaapi/va_x11.sigs +++ b/chromium/media/gpu/vaapi/va_x11.sigs @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_common.cc b/chromium/media/gpu/vaapi/vaapi_common.cc index 92e42b6a99c..5cb6f08d76c 100644 --- a/chromium/media/gpu/vaapi/vaapi_common.cc +++ b/chromium/media/gpu/vaapi/vaapi_common.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_common.h b/chromium/media/gpu/vaapi/vaapi_common.h index 169eec95581..72a2fd66f79 100644 --- a/chromium/media/gpu/vaapi/vaapi_common.h +++ b/chromium/media/gpu/vaapi/vaapi_common.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MEDIA_GPU_VAAPI_VAAPI_COMMON_H_ diff --git a/chromium/media/gpu/vaapi/vaapi_dmabuf_video_frame_mapper.cc b/chromium/media/gpu/vaapi/vaapi_dmabuf_video_frame_mapper.cc index c838ec3a850..fecf199136b 100644 --- a/chromium/media/gpu/vaapi/vaapi_dmabuf_video_frame_mapper.cc +++ b/chromium/media/gpu/vaapi/vaapi_dmabuf_video_frame_mapper.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_dmabuf_video_frame_mapper.h b/chromium/media/gpu/vaapi/vaapi_dmabuf_video_frame_mapper.h index 4d31db21280..76c6742bd22 100644 --- a/chromium/media/gpu/vaapi/vaapi_dmabuf_video_frame_mapper.h +++ b/chromium/media/gpu/vaapi/vaapi_dmabuf_video_frame_mapper.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker.cc b/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker.cc index b49e8fc9a1d..296057a598b 100644 --- a/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker.cc +++ b/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker.h b/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker.h index 02387be35fe..16d98de9e7a 100644 --- a/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker.h +++ b/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker_unittest.cc b/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker_unittest.cc index 640c4d76900..47295cdbe0f 100644 --- a/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker_unittest.cc +++ b/chromium/media/gpu/vaapi/vaapi_image_decode_accelerator_worker_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_image_decoder.cc b/chromium/media/gpu/vaapi/vaapi_image_decoder.cc index 91b26f9ebd2..3b045ff3bbf 100644 --- a/chromium/media/gpu/vaapi/vaapi_image_decoder.cc +++ b/chromium/media/gpu/vaapi/vaapi_image_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_image_decoder.h b/chromium/media/gpu/vaapi/vaapi_image_decoder.h index 524f4a051ec..fcbb0e0561d 100644 --- a/chromium/media/gpu/vaapi/vaapi_image_decoder.h +++ b/chromium/media/gpu/vaapi/vaapi_image_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_image_decoder_test_common.cc b/chromium/media/gpu/vaapi/vaapi_image_decoder_test_common.cc index d34c9712253..960239e0dae 100644 --- a/chromium/media/gpu/vaapi/vaapi_image_decoder_test_common.cc +++ b/chromium/media/gpu/vaapi/vaapi_image_decoder_test_common.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_image_decoder_test_common.h b/chromium/media/gpu/vaapi/vaapi_image_decoder_test_common.h index 753bacb5941..31c1f37493a 100644 --- a/chromium/media/gpu/vaapi/vaapi_image_decoder_test_common.h +++ b/chromium/media/gpu/vaapi/vaapi_image_decoder_test_common.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_image_processor_backend.cc b/chromium/media/gpu/vaapi/vaapi_image_processor_backend.cc index 6c8cd3d38b5..030c0327f7b 100644 --- a/chromium/media/gpu/vaapi/vaapi_image_processor_backend.cc +++ b/chromium/media/gpu/vaapi/vaapi_image_processor_backend.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_image_processor_backend.h b/chromium/media/gpu/vaapi/vaapi_image_processor_backend.h index e2180506fef..a8f0decbdb5 100644 --- a/chromium/media/gpu/vaapi/vaapi_image_processor_backend.h +++ b/chromium/media/gpu/vaapi/vaapi_image_processor_backend.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_jpeg_decoder.cc b/chromium/media/gpu/vaapi/vaapi_jpeg_decoder.cc index 7c3e8e8b316..ea55c923df3 100644 --- a/chromium/media/gpu/vaapi/vaapi_jpeg_decoder.cc +++ b/chromium/media/gpu/vaapi/vaapi_jpeg_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_jpeg_decoder.h b/chromium/media/gpu/vaapi/vaapi_jpeg_decoder.h index 61ea4be387a..1ba5e96350c 100644 --- a/chromium/media/gpu/vaapi/vaapi_jpeg_decoder.h +++ b/chromium/media/gpu/vaapi/vaapi_jpeg_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_jpeg_decoder_unittest.cc b/chromium/media/gpu/vaapi/vaapi_jpeg_decoder_unittest.cc index 730dcb94b6f..2c76f0747c5 100644 --- a/chromium/media/gpu/vaapi/vaapi_jpeg_decoder_unittest.cc +++ b/chromium/media/gpu/vaapi/vaapi_jpeg_decoder_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.cc b/chromium/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.cc index 72993a3a017..563fc294f38 100644 --- a/chromium/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.cc +++ b/chromium/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.h b/chromium/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.h index ab8932c7df6..42777b85ee1 100644 --- a/chromium/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.h +++ b/chromium/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_jpeg_encoder.cc b/chromium/media/gpu/vaapi/vaapi_jpeg_encoder.cc index 90619a021a2..7226b21efa6 100644 --- a/chromium/media/gpu/vaapi/vaapi_jpeg_encoder.cc +++ b/chromium/media/gpu/vaapi/vaapi_jpeg_encoder.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_jpeg_encoder.h b/chromium/media/gpu/vaapi/vaapi_jpeg_encoder.h index a01fc7448b4..adfbb0ee1b6 100644 --- a/chromium/media/gpu/vaapi/vaapi_jpeg_encoder.h +++ b/chromium/media/gpu/vaapi/vaapi_jpeg_encoder.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_mjpeg_decode_accelerator.cc b/chromium/media/gpu/vaapi/vaapi_mjpeg_decode_accelerator.cc index e56098a8758..44769d5d06e 100644 --- a/chromium/media/gpu/vaapi/vaapi_mjpeg_decode_accelerator.cc +++ b/chromium/media/gpu/vaapi/vaapi_mjpeg_decode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_mjpeg_decode_accelerator.h b/chromium/media/gpu/vaapi/vaapi_mjpeg_decode_accelerator.h index 9d420769dde..d16821d98ac 100644 --- a/chromium/media/gpu/vaapi/vaapi_mjpeg_decode_accelerator.h +++ b/chromium/media/gpu/vaapi/vaapi_mjpeg_decode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture.cc b/chromium/media/gpu/vaapi/vaapi_picture.cc index c9d5d22e9cc..101226ab9e8 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture.cc +++ b/chromium/media/gpu/vaapi/vaapi_picture.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture.h b/chromium/media/gpu/vaapi/vaapi_picture.h index a599253cf04..fa74aa23177 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture.h +++ b/chromium/media/gpu/vaapi/vaapi_picture.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // diff --git a/chromium/media/gpu/vaapi/vaapi_picture_factory.cc b/chromium/media/gpu/vaapi/vaapi_picture_factory.cc index 62e3a429239..54825cd693a 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_factory.cc +++ b/chromium/media/gpu/vaapi/vaapi_picture_factory.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_factory.h b/chromium/media/gpu/vaapi/vaapi_picture_factory.h index 804bdcbdc22..169038d2334 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_factory.h +++ b/chromium/media/gpu/vaapi/vaapi_picture_factory.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap.cc b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap.cc index 941f24cc595..18c6c2234b0 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap.cc +++ b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap.h b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap.h index 71ced2dcf56..60e87754c56 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap.h +++ b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.cc b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.cc index 929c7492403..a21495d9567 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.cc +++ b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.h b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.h index d80bb4eb6c2..0d0d3eb052c 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.h +++ b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_egl.cc b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_egl.cc index 17d70682b06..f17221a38dd 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_egl.cc +++ b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_egl.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_egl.h b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_egl.h index 39c1e4369f7..234da305c58 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_egl.h +++ b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_egl.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.cc b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.cc index a53056a32c4..5437b2fa848 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.cc +++ b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.h b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.h index e75a5ccd1ab..aa67b10a996 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.h +++ b/chromium/media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_tfp.cc b/chromium/media/gpu/vaapi/vaapi_picture_tfp.cc index b23c42052bd..87c9b918e65 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_tfp.cc +++ b/chromium/media/gpu/vaapi/vaapi_picture_tfp.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_picture_tfp.h b/chromium/media/gpu/vaapi/vaapi_picture_tfp.h index 37d6e947a42..6d1ff0f0923 100644 --- a/chromium/media/gpu/vaapi/vaapi_picture_tfp.h +++ b/chromium/media/gpu/vaapi/vaapi_picture_tfp.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_status.h b/chromium/media/gpu/vaapi/vaapi_status.h index 73041944d61..2bc7abedcc0 100644 --- a/chromium/media/gpu/vaapi/vaapi_status.h +++ b/chromium/media/gpu/vaapi/vaapi_status.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_unittest.cc b/chromium/media/gpu/vaapi/vaapi_unittest.cc index 8658dc7749d..558f5108355 100644 --- a/chromium/media/gpu/vaapi/vaapi_unittest.cc +++ b/chromium/media/gpu/vaapi/vaapi_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_utils.cc b/chromium/media/gpu/vaapi/vaapi_utils.cc index 0e57649173b..1fe2a259114 100644 --- a/chromium/media/gpu/vaapi/vaapi_utils.cc +++ b/chromium/media/gpu/vaapi/vaapi_utils.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_utils.h b/chromium/media/gpu/vaapi/vaapi_utils.h index 1f0e5ac384e..c47564188b0 100644 --- a/chromium/media/gpu/vaapi/vaapi_utils.h +++ b/chromium/media/gpu/vaapi/vaapi_utils.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_utils_unittest.cc b/chromium/media/gpu/vaapi/vaapi_utils_unittest.cc index a06db699e14..71d5435f3bf 100644 --- a/chromium/media/gpu/vaapi/vaapi_utils_unittest.cc +++ b/chromium/media/gpu/vaapi/vaapi_utils_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator.cc b/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator.cc index bf791d813b4..37e3520f12f 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator.cc +++ b/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator.h b/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator.h index 3444ebf2d6c..82a4a49b3ed 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator.h +++ b/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // diff --git a/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator_unittest.cc b/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator_unittest.cc index 9f7c69007f5..2b0c061c0f5 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator_unittest.cc +++ b/chromium/media/gpu/vaapi/vaapi_video_decode_accelerator_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_video_decoder.cc b/chromium/media/gpu/vaapi/vaapi_video_decoder.cc index 551b8aa70b6..7ed209ad9b9 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_decoder.cc +++ b/chromium/media/gpu/vaapi/vaapi_video_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_video_decoder.h b/chromium/media/gpu/vaapi/vaapi_video_decoder.h index a3ecd231fbd..c76b2c5df2e 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_decoder.h +++ b/chromium/media/gpu/vaapi/vaapi_video_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_video_decoder_delegate.cc b/chromium/media/gpu/vaapi/vaapi_video_decoder_delegate.cc index 4e2dc91c33a..a4401587e9b 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_decoder_delegate.cc +++ b/chromium/media/gpu/vaapi/vaapi_video_decoder_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_video_decoder_delegate.h b/chromium/media/gpu/vaapi/vaapi_video_decoder_delegate.h index 075ccf28987..c4febb525f4 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_decoder_delegate.h +++ b/chromium/media/gpu/vaapi/vaapi_video_decoder_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator.cc b/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator.cc index c97d6952f1c..85903cfaebf 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator.cc +++ b/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,7 @@ #include <memory> #include <type_traits> #include <utility> +#include <variant> #include "base/bind.h" #include "base/bits.h" @@ -127,7 +128,7 @@ VaapiVideoEncodeAccelerator::VaapiVideoEncodeAccelerator() // The default value of VideoEncoderInfo of VaapiVideoEncodeAccelerator. encoder_info_.implementation_name = "VaapiVideoEncodeAccelerator"; - encoder_info_.has_trusted_rate_controller = true; + DCHECK(!encoder_info_.has_trusted_rate_controller); DCHECK(encoder_info_.is_hardware_accelerated); DCHECK(encoder_info_.supports_native_handle); DCHECK(!encoder_info_.supports_simulcast); @@ -570,6 +571,9 @@ bool VaapiVideoEncodeAccelerator::CreateSurfacesForGpuMemoryBufferEncoding( return false; } + if (spatial_layer_resolutions.empty()) + return false; + scoped_refptr<VASurface> source_surface; { TRACE_EVENT0("media,gpu", "VAVEA::ImportGpuMemoryBufferToVASurface"); @@ -593,30 +597,36 @@ bool VaapiVideoEncodeAccelerator::CreateSurfacesForGpuMemoryBufferEncoding( // Create input and reconstructed surfaces. TRACE_EVENT1("media,gpu", "VAVEA::ConstructSurfaces", "layers", spatial_layer_resolutions.size()); - input_surfaces->reserve(spatial_layer_resolutions.size()); - reconstructed_surfaces->reserve(spatial_layer_resolutions.size()); - for (const gfx::Size& encode_size : spatial_layer_resolutions) { - const bool engage_vpp = frame.visible_rect() != gfx::Rect(encode_size); + input_surfaces->resize(spatial_layer_resolutions.size()); + reconstructed_surfaces->resize(spatial_layer_resolutions.size()); + + // Process from uppermost layer, then use immediate upper layer as vpp source + // surface if applicable. + auto source_rect = frame.visible_rect(); + for (size_t i = spatial_layer_resolutions.size() - 1; i != std::variant_npos; + --i) { + const gfx::Size& encode_size = spatial_layer_resolutions[i]; + const bool engage_vpp = source_rect != gfx::Rect(encode_size); + // Crop and Scale input surface to a surface whose size is |encode_size|. // The size of a reconstructed surface is also |encode_size|. if (engage_vpp) { - auto blit_surface = ExecuteBlitSurface(*source_surface, - frame.visible_rect(), encode_size); - if (!blit_surface) - return false; - - input_surfaces->push_back(std::move(blit_surface)); + if (i + 1 < spatial_layer_resolutions.size()) { + source_surface = input_surfaces->at(i + 1); + source_rect = gfx::Rect(source_surface->size()); + } + input_surfaces->at(i) = + ExecuteBlitSurface(*source_surface, source_rect, encode_size); } else { - input_surfaces->emplace_back(source_surface); + input_surfaces->at(i) = source_surface; } - reconstructed_surfaces->emplace_back(CreateEncodeSurface(encode_size)); - if (!reconstructed_surfaces->back()) + reconstructed_surfaces->at(i) = CreateEncodeSurface(encode_size); + + if (!input_surfaces->at(i) || !reconstructed_surfaces->at(i)) return false; } - DCHECK(!base::Contains(*input_surfaces, nullptr)); - DCHECK(!base::Contains(*reconstructed_surfaces, nullptr)); return true; } diff --git a/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator.h b/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator.h index 13a062f2a27..30730c9cc52 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator.h +++ b/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator_unittest.cc b/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator_unittest.cc index e73e47997af..b45f172223f 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator_unittest.cc +++ b/chromium/media/gpu/vaapi/vaapi_video_encode_accelerator_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -126,14 +126,14 @@ MATCHER_P2(MatchesEncoderInfo, } } return arg.implementation_name == "VaapiVideoEncodeAccelerator" && - arg.supports_native_handle && arg.has_trusted_rate_controller && + arg.supports_native_handle && !arg.has_trusted_rate_controller && arg.is_hardware_accelerated && !arg.supports_simulcast; } class MockVideoEncodeAcceleratorClient : public VideoEncodeAccelerator::Client { public: MockVideoEncodeAcceleratorClient() = default; - virtual ~MockVideoEncodeAcceleratorClient() = default; + ~MockVideoEncodeAcceleratorClient() override = default; MOCK_METHOD3(RequireBitstreamBuffers, void(unsigned int, const gfx::Size&, size_t)); @@ -506,7 +506,7 @@ class VaapiVideoEncodeAcceleratorTest std::vector<gfx::Size> svc_resolutions = GetDefaultSVCResolutions(num_spatial_layers); // Create Surfaces. - for (size_t i = 0; i < num_spatial_layers; ++i) { + for (size_t i = num_spatial_layers - 1; i != std::variant_npos; --i) { if (i < num_spatial_layers - 1) { if (va_vpp_dest_surface_ids_[i] == VA_INVALID_ID) { EXPECT_CALL( @@ -529,10 +529,10 @@ class VaapiVideoEncodeAcceleratorTest return va_surfaces; })); } - absl::optional<gfx::Rect> default_rect = gfx::Rect(kDefaultEncodeSize); + absl::optional<gfx::Rect> src_rect = gfx::Rect(svc_resolutions[i + 1]); absl::optional<gfx::Rect> layer_rect = gfx::Rect(svc_resolutions[i]); EXPECT_CALL(*mock_vpp_vaapi_wrapper_, - DoBlitSurface(_, _, default_rect, layer_rect, + DoBlitSurface(_, _, src_rect, layer_rect, VideoRotation::VIDEO_ROTATION_0)) .WillOnce(Return(true)); } @@ -565,9 +565,6 @@ class VaapiVideoEncodeAcceleratorTest } } - for (size_t i = 0; i < num_spatial_layers; ++i) { - } - // Create CodedBuffers in creating EncodeJobs. constexpr VABufferID kCodedBufferIds[] = {123, 124, 125}; for (size_t i = 0; i < num_spatial_layers; ++i) { diff --git a/chromium/media/gpu/vaapi/vaapi_video_encoder_delegate.cc b/chromium/media/gpu/vaapi/vaapi_video_encoder_delegate.cc index 21e8ca9e82a..b01a7b15efd 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_encoder_delegate.cc +++ b/chromium/media/gpu/vaapi/vaapi_video_encoder_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_video_encoder_delegate.h b/chromium/media/gpu/vaapi/vaapi_video_encoder_delegate.h index 995347c55a5..1af498e4d87 100644 --- a/chromium/media/gpu/vaapi/vaapi_video_encoder_delegate.h +++ b/chromium/media/gpu/vaapi/vaapi_video_encoder_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_webp_decoder.cc b/chromium/media/gpu/vaapi/vaapi_webp_decoder.cc index afb71b35daa..48800522df5 100644 --- a/chromium/media/gpu/vaapi/vaapi_webp_decoder.cc +++ b/chromium/media/gpu/vaapi/vaapi_webp_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_webp_decoder.h b/chromium/media/gpu/vaapi/vaapi_webp_decoder.h index 35839e631e3..2a96492d8fe 100644 --- a/chromium/media/gpu/vaapi/vaapi_webp_decoder.h +++ b/chromium/media/gpu/vaapi/vaapi_webp_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_webp_decoder_unittest.cc b/chromium/media/gpu/vaapi/vaapi_webp_decoder_unittest.cc index 49342d29c97..3c11defedef 100644 --- a/chromium/media/gpu/vaapi/vaapi_webp_decoder_unittest.cc +++ b/chromium/media/gpu/vaapi/vaapi_webp_decoder_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vaapi_wrapper.cc b/chromium/media/gpu/vaapi/vaapi_wrapper.cc index dc1b731ea25..cc1c86fde9f 100644 --- a/chromium/media/gpu/vaapi/vaapi_wrapper.cc +++ b/chromium/media/gpu/vaapi/vaapi_wrapper.cc @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,7 +16,6 @@ #include <va/va_version.h> #include <xf86drm.h> -#include <algorithm> #include <string> #include <type_traits> #include <utility> @@ -35,6 +34,7 @@ #include "base/numerics/checked_math.h" #include "base/numerics/safe_conversions.h" #include "base/posix/eintr_wrapper.h" +#include "base/ranges/algorithm.h" #include "base/strings/pattern.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" @@ -622,10 +622,8 @@ bool IsVAProfileSupported(VAProfile va_profile) { #if BUILDFLAG(IS_CHROMEOS_ASH) va_profile == VAProfileProtected || #endif - std::find_if(profiles.begin(), profiles.end(), - [va_profile](const auto& entry) { - return entry.second == va_profile; - }) != profiles.end(); + base::Contains(profiles, va_profile, + &ProfileCodecMap::value_type::second); } bool IsBlockedDriver(VaapiWrapper::CodecMode mode, VAProfile va_profile) { @@ -1164,8 +1162,8 @@ const VASupportedProfiles::ProfileInfo* VASupportedProfiles::IsProfileSupported( VaapiWrapper::CodecMode mode, VAProfile va_profile, VAEntrypoint va_entrypoint) const { - auto iter = std::find_if( - supported_profiles_[mode].begin(), supported_profiles_[mode].end(), + auto iter = base::ranges::find_if( + supported_profiles_[mode], [va_profile, va_entrypoint](const ProfileInfo& profile) { return profile.va_profile == va_profile && (va_entrypoint == kVAEntrypointInvalid || @@ -1470,11 +1468,8 @@ const VASupportedImageFormats& VASupportedImageFormats::Get() { bool VASupportedImageFormats::IsImageFormatSupported( const VAImageFormat& va_image_format) const { - auto it = std::find_if(supported_formats_.begin(), supported_formats_.end(), - [&va_image_format](const VAImageFormat& format) { - return format.fourcc == va_image_format.fourcc; - }); - return it != supported_formats_.end(); + return base::Contains(supported_formats_, va_image_format.fourcc, + &VAImageFormat::fourcc); } const std::vector<VAImageFormat>& @@ -1552,10 +1547,9 @@ bool VASupportedImageFormats::InitSupportedImageFormats_Locked( // assume that IYUV/I420 is supported. However, it's not currently being // reported. See https://gitlab.freedesktop.org/mesa/mesa/commit/b0a44f10. // Remove this workaround once b/128340287 is resolved. - if (std::find_if(supported_formats_.cbegin(), supported_formats_.cend(), - [](const VAImageFormat& format) { - return format.fourcc == VA_FOURCC_I420; - }) == supported_formats_.cend()) { + if (!base::Contains(supported_formats_, + static_cast<unsigned int>(VA_FOURCC_I420), + &VAImageFormat::fourcc)) { VAImageFormat i420_format{}; i420_format.fourcc = VA_FOURCC_I420; supported_formats_.push_back(i420_format); diff --git a/chromium/media/gpu/vaapi/vaapi_wrapper.h b/chromium/media/gpu/vaapi/vaapi_wrapper.h index c59f9798f07..84c25547f5a 100644 --- a/chromium/media/gpu/vaapi/vaapi_wrapper.h +++ b/chromium/media/gpu/vaapi/vaapi_wrapper.h @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // diff --git a/chromium/media/gpu/vaapi/vaapi_wrapper_unittest.cc b/chromium/media/gpu/vaapi/vaapi_wrapper_unittest.cc index cded354e7e8..ff8caa3bcc6 100644 --- a/chromium/media/gpu/vaapi/vaapi_wrapper_unittest.cc +++ b/chromium/media/gpu/vaapi/vaapi_wrapper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vp8_vaapi_video_decoder_delegate.cc b/chromium/media/gpu/vaapi/vp8_vaapi_video_decoder_delegate.cc index e9433bedcf3..cac6d9af10d 100644 --- a/chromium/media/gpu/vaapi/vp8_vaapi_video_decoder_delegate.cc +++ b/chromium/media/gpu/vaapi/vp8_vaapi_video_decoder_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vp8_vaapi_video_decoder_delegate.h b/chromium/media/gpu/vaapi/vp8_vaapi_video_decoder_delegate.h index 644e8a9cf2a..af857d70460 100644 --- a/chromium/media/gpu/vaapi/vp8_vaapi_video_decoder_delegate.h +++ b/chromium/media/gpu/vaapi/vp8_vaapi_video_decoder_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vp8_vaapi_video_encoder_delegate.cc b/chromium/media/gpu/vaapi/vp8_vaapi_video_encoder_delegate.cc index 1b0de54c241..6edd9b0f026 100644 --- a/chromium/media/gpu/vaapi/vp8_vaapi_video_encoder_delegate.cc +++ b/chromium/media/gpu/vaapi/vp8_vaapi_video_encoder_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -32,12 +32,11 @@ constexpr uint8_t kMinQP = 4; // resolution (180p). constexpr uint8_t kMaxQP = 117; -// The upper limitation of the quantization parameter for the software rate -// controller. This is larger than |kMaxQP| because a driver might ignore the -// specified maximum quantization parameter when the driver determines the -// value, but it doesn't ignore the quantization parameter by the software rate -// controller. -constexpr uint8_t kMaxQPForSoftwareRateCtrl = 127; +// WebRTC's default qp values are 15 and 106 for screen sharing, respectively, +// Set smaller qp values for zero hertz tab sharing, which is triggered when qp +// values are consecutively less than or equal to 15. +constexpr uint8_t kScreenMinQP = 8; +constexpr uint8_t kScreenMaxQP = 106; // Convert Qindex, whose range is 0-127, to the quantizer parameter used in // libvpx vp8 rate control, whose range is 0-63. @@ -319,7 +318,11 @@ bool VP8VaapiVideoEncoderDelegate::Initialize( else initial_bitrate_allocation.SetBitrate(0, 0, config.bitrate.target_bps()); - current_params_.max_qp = kMaxQPForSoftwareRateCtrl; + if (config.content_type == + VideoEncodeAccelerator::Config::ContentType::kDisplay) { + current_params_.min_qp = kScreenMinQP; + current_params_.max_qp = kScreenMaxQP; + } // |rate_ctrl_| might be injected for tests. if (!rate_ctrl_) { diff --git a/chromium/media/gpu/vaapi/vp8_vaapi_video_encoder_delegate.h b/chromium/media/gpu/vaapi/vp8_vaapi_video_encoder_delegate.h index 732eebe8667..27ee737c5bd 100644 --- a/chromium/media/gpu/vaapi/vp8_vaapi_video_encoder_delegate.h +++ b/chromium/media/gpu/vaapi/vp8_vaapi_video_encoder_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vp9_vaapi_video_decoder_delegate.cc b/chromium/media/gpu/vaapi/vp9_vaapi_video_decoder_delegate.cc index a1ea410276f..f2c8bd269e3 100644 --- a/chromium/media/gpu/vaapi/vp9_vaapi_video_decoder_delegate.cc +++ b/chromium/media/gpu/vaapi/vp9_vaapi_video_decoder_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vp9_vaapi_video_decoder_delegate.h b/chromium/media/gpu/vaapi/vp9_vaapi_video_decoder_delegate.h index f3f81122243..0abe7312811 100644 --- a/chromium/media/gpu/vaapi/vp9_vaapi_video_decoder_delegate.h +++ b/chromium/media/gpu/vaapi/vp9_vaapi_video_decoder_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.cc b/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.cc index a58e65942ec..aa64ca838f2 100644 --- a/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.cc +++ b/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.h b/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.h index d135b0beea1..414c6cc538f 100644 --- a/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.h +++ b/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate_unittest.cc b/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate_unittest.cc index d966194387e..9a911e06057 100644 --- a/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate_unittest.cc +++ b/chromium/media/gpu/vaapi/vp9_vaapi_video_encoder_delegate_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/video_decode_accelerator_perf_tests.cc b/chromium/media/gpu/video_decode_accelerator_perf_tests.cc index 0d83e25237c..d0fcbd9e216 100644 --- a/chromium/media/gpu/video_decode_accelerator_perf_tests.cc +++ b/chromium/media/gpu/video_decode_accelerator_perf_tests.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -472,8 +472,8 @@ int main(int argc, char** argv) { bool use_legacy = false; bool use_vd_vda = false; bool linear_output = false; - std::vector<base::Feature> disabled_features; - std::vector<base::Feature> enabled_features; + std::vector<base::test::FeatureRef> disabled_features; + std::vector<base::test::FeatureRef> enabled_features; #if defined(ARCH_CPU_ARM_FAMILY) enabled_features.push_back(media::kPreferLibYuvImageProcessor); diff --git a/chromium/media/gpu/video_decode_accelerator_tests.cc b/chromium/media/gpu/video_decode_accelerator_tests.cc index e1fadd70895..712b82306ca 100644 --- a/chromium/media/gpu/video_decode_accelerator_tests.cc +++ b/chromium/media/gpu/video_decode_accelerator_tests.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -544,8 +544,8 @@ int main(int argc, char** argv) { bool use_legacy = false; bool use_vd_vda = false; bool linear_output = false; - std::vector<base::Feature> disabled_features; - std::vector<base::Feature> enabled_features; + std::vector<base::test::FeatureRef> disabled_features; + std::vector<base::test::FeatureRef> enabled_features; #if defined(ARCH_CPU_ARM_FAMILY) enabled_features.push_back(media::kPreferLibYuvImageProcessor); diff --git a/chromium/media/gpu/video_encode_accelerator_perf_tests.cc b/chromium/media/gpu/video_encode_accelerator_perf_tests.cc index 7275b26d6ce..2ed2028ce05 100644 --- a/chromium/media/gpu/video_encode_accelerator_perf_tests.cc +++ b/chromium/media/gpu/video_encode_accelerator_perf_tests.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -791,7 +791,7 @@ int main(int argc, char** argv) { media::Bitrate::Mode bitrate_mode = media::Bitrate::Mode::kConstant; bool reverse = false; absl::optional<uint32_t> encode_bitrate; - std::vector<base::Feature> disabled_features; + std::vector<base::test::FeatureRef> disabled_features; // Parse command line arguments. base::FilePath::StringType output_folder = media::test::kDefaultOutputFolder; diff --git a/chromium/media/gpu/video_encode_accelerator_tests.cc b/chromium/media/gpu/video_encode_accelerator_tests.cc index 6208f2821c5..2b48c653f20 100644 --- a/chromium/media/gpu/video_encode_accelerator_tests.cc +++ b/chromium/media/gpu/video_encode_accelerator_tests.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -871,7 +871,7 @@ int main(int argc, char** argv) { media::test::FrameOutputConfig frame_output_config; base::FilePath output_folder = base::FilePath(base::FilePath::kCurrentDirectory); - std::vector<base::Feature> disabled_features; + std::vector<base::test::FeatureRef> disabled_features; // Parse command line arguments. bool enable_bitstream_validator = true; diff --git a/chromium/media/gpu/video_frame_mapper.h b/chromium/media/gpu/video_frame_mapper.h index cc8f9564090..ad257152092 100644 --- a/chromium/media/gpu/video_frame_mapper.h +++ b/chromium/media/gpu/video_frame_mapper.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/video_frame_mapper_factory.cc b/chromium/media/gpu/video_frame_mapper_factory.cc index 28b10541fa2..27c98d0baae 100644 --- a/chromium/media/gpu/video_frame_mapper_factory.cc +++ b/chromium/media/gpu/video_frame_mapper_factory.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/video_frame_mapper_factory.h b/chromium/media/gpu/video_frame_mapper_factory.h index ba1fc28bc7c..657a5e94667 100644 --- a/chromium/media/gpu/video_frame_mapper_factory.h +++ b/chromium/media/gpu/video_frame_mapper_factory.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/video_rate_control.cc b/chromium/media/gpu/video_rate_control.cc index 90ce36256ad..e56b62e8a86 100644 --- a/chromium/media/gpu/video_rate_control.cc +++ b/chromium/media/gpu/video_rate_control.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/video_rate_control.h b/chromium/media/gpu/video_rate_control.h index c5666505d61..88da1ff72ed 100644 --- a/chromium/media/gpu/video_rate_control.h +++ b/chromium/media/gpu/video_rate_control.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp8_decoder.cc b/chromium/media/gpu/vp8_decoder.cc index c499357fbc2..d91a16fe47e 100644 --- a/chromium/media/gpu/vp8_decoder.cc +++ b/chromium/media/gpu/vp8_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp8_decoder.h b/chromium/media/gpu/vp8_decoder.h index a1acdcbd9d3..09ef7d64a04 100644 --- a/chromium/media/gpu/vp8_decoder.h +++ b/chromium/media/gpu/vp8_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp8_decoder_unittest.cc b/chromium/media/gpu/vp8_decoder_unittest.cc index 25ebc0f80ce..1cab3ab7b9d 100644 --- a/chromium/media/gpu/vp8_decoder_unittest.cc +++ b/chromium/media/gpu/vp8_decoder_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp8_picture.cc b/chromium/media/gpu/vp8_picture.cc index 366ad8354dd..3e7159921ed 100644 --- a/chromium/media/gpu/vp8_picture.cc +++ b/chromium/media/gpu/vp8_picture.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp8_picture.h b/chromium/media/gpu/vp8_picture.h index cb30ef8ca8b..84865c8d263 100644 --- a/chromium/media/gpu/vp8_picture.h +++ b/chromium/media/gpu/vp8_picture.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp8_reference_frame_vector.cc b/chromium/media/gpu/vp8_reference_frame_vector.cc index 1012a1350c1..d1ca7864604 100644 --- a/chromium/media/gpu/vp8_reference_frame_vector.cc +++ b/chromium/media/gpu/vp8_reference_frame_vector.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp8_reference_frame_vector.h b/chromium/media/gpu/vp8_reference_frame_vector.h index 8e0e2e8a0e0..8eaa18937da 100644 --- a/chromium/media/gpu/vp8_reference_frame_vector.h +++ b/chromium/media/gpu/vp8_reference_frame_vector.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp9_decoder.cc b/chromium/media/gpu/vp9_decoder.cc index fbac517457b..ca87587c32d 100644 --- a/chromium/media/gpu/vp9_decoder.cc +++ b/chromium/media/gpu/vp9_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp9_decoder.h b/chromium/media/gpu/vp9_decoder.h index cc0c6f61e18..e76472c8178 100644 --- a/chromium/media/gpu/vp9_decoder.h +++ b/chromium/media/gpu/vp9_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp9_picture.cc b/chromium/media/gpu/vp9_picture.cc index 477443d661b..7a32a2b3d00 100644 --- a/chromium/media/gpu/vp9_picture.cc +++ b/chromium/media/gpu/vp9_picture.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp9_picture.h b/chromium/media/gpu/vp9_picture.h index 1ce652dca19..8937400e582 100644 --- a/chromium/media/gpu/vp9_picture.h +++ b/chromium/media/gpu/vp9_picture.h @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp9_reference_frame_vector.cc b/chromium/media/gpu/vp9_reference_frame_vector.cc index f4541bf53bd..9481cbbb4e0 100644 --- a/chromium/media/gpu/vp9_reference_frame_vector.cc +++ b/chromium/media/gpu/vp9_reference_frame_vector.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp9_reference_frame_vector.h b/chromium/media/gpu/vp9_reference_frame_vector.h index 0d18d15430d..b0807cfd75d 100644 --- a/chromium/media/gpu/vp9_reference_frame_vector.h +++ b/chromium/media/gpu/vp9_reference_frame_vector.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp9_svc_layers.cc b/chromium/media/gpu/vp9_svc_layers.cc index 919531c018d..6b2774c4cb6 100644 --- a/chromium/media/gpu/vp9_svc_layers.cc +++ b/chromium/media/gpu/vp9_svc_layers.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp9_svc_layers.h b/chromium/media/gpu/vp9_svc_layers.h index 47d87bc3c4f..a5709c1b571 100644 --- a/chromium/media/gpu/vp9_svc_layers.h +++ b/chromium/media/gpu/vp9_svc_layers.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/vp9_svc_layers_unittest.cc b/chromium/media/gpu/vp9_svc_layers_unittest.cc index b4aa85e6ceb..254d658a22b 100644 --- a/chromium/media/gpu/vp9_svc_layers_unittest.cc +++ b/chromium/media/gpu/vp9_svc_layers_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/av1_guids.h b/chromium/media/gpu/windows/av1_guids.h index 9f0d9232ffa..404cab7d0f9 100644 --- a/chromium/media/gpu/windows/av1_guids.h +++ b/chromium/media/gpu/windows/av1_guids.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_av1_accelerator.cc b/chromium/media/gpu/windows/d3d11_av1_accelerator.cc index 6493c3de286..3d1b65b552d 100644 --- a/chromium/media/gpu/windows/d3d11_av1_accelerator.cc +++ b/chromium/media/gpu/windows/d3d11_av1_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -560,12 +560,19 @@ void D3D11AV1Accelerator::FillPicParams( pp->film_grain.ar_coeffs_cb[i] = fg.auto_regression_coeff_u[i] + 128; pp->film_grain.ar_coeffs_cr[i] = fg.auto_regression_coeff_v[i] + 128; } - pp->film_grain.cb_mult = fg.u_multiplier; - pp->film_grain.cb_luma_mult = fg.u_luma_multiplier; - pp->film_grain.cb_offset = fg.u_offset; - pp->film_grain.cr_mult = fg.v_multiplier; - pp->film_grain.cr_luma_mult = fg.v_luma_multiplier; - pp->film_grain.cr_offset = fg.v_offset; + // libgav1 will provide the multipliers by subtracting 128 and the offsets + // by subtracting 256. Restore values as DXVA spec requires values without + // subtraction. + if (fg.num_u_points > 0) { + pp->film_grain.cb_mult = fg.u_multiplier + 128; + pp->film_grain.cb_luma_mult = fg.u_luma_multiplier + 128; + pp->film_grain.cb_offset = fg.u_offset + 256; + } + if (fg.num_v_points > 0) { + pp->film_grain.cr_mult = fg.v_multiplier + 128; + pp->film_grain.cr_luma_mult = fg.v_luma_multiplier + 128; + pp->film_grain.cr_offset = fg.v_offset + 256; + } } // StatusReportFeedbackNumber "should not be equal to 0"... but it crashes :| diff --git a/chromium/media/gpu/windows/d3d11_av1_accelerator.h b/chromium/media/gpu/windows/d3d11_av1_accelerator.h index a8fbe9205cf..df8b9847496 100644 --- a/chromium/media/gpu/windows/d3d11_av1_accelerator.h +++ b/chromium/media/gpu/windows/d3d11_av1_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_com_defs.h b/chromium/media/gpu/windows/d3d11_com_defs.h index 97735df0003..cc7fd85b5b2 100644 --- a/chromium/media/gpu/windows/d3d11_com_defs.h +++ b/chromium/media/gpu/windows/d3d11_com_defs.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_copying_texture_wrapper.cc b/chromium/media/gpu/windows/d3d11_copying_texture_wrapper.cc index 95a7084e745..15162d016d2 100644 --- a/chromium/media/gpu/windows/d3d11_copying_texture_wrapper.cc +++ b/chromium/media/gpu/windows/d3d11_copying_texture_wrapper.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -77,18 +77,7 @@ D3D11Status CopyingTexture2DWrapper::ProcessTexture( *previous_input_color_space_ != input_color_space) { previous_input_color_space_ = input_color_space; - // The VideoProcessor doesn't support tone mapping of HLG content, so treat - // treat it as gamma 2.2 since HLG is designed to look okay that way. - auto adjusted_color_space = input_color_space; - if (input_color_space.GetTransferID() == gfx::ColorSpace::TransferID::HLG && - !copy_color_space.IsHDR()) { - adjusted_color_space = gfx::ColorSpace( - input_color_space.GetPrimaryID(), - gfx::ColorSpace::TransferID::GAMMA22, input_color_space.GetMatrixID(), - input_color_space.GetRangeID()); - } - - video_processor_->SetStreamColorSpace(adjusted_color_space); + video_processor_->SetStreamColorSpace(input_color_space); video_processor_->SetOutputColorSpace(copy_color_space); } diff --git a/chromium/media/gpu/windows/d3d11_copying_texture_wrapper.h b/chromium/media/gpu/windows/d3d11_copying_texture_wrapper.h index 95c5ebeee0b..47a5f21be78 100644 --- a/chromium/media/gpu/windows/d3d11_copying_texture_wrapper.h +++ b/chromium/media/gpu/windows/d3d11_copying_texture_wrapper.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_copying_texture_wrapper_unittest.cc b/chromium/media/gpu/windows/d3d11_copying_texture_wrapper_unittest.cc index db1a84af106..687cc0200ff 100644 --- a/chromium/media/gpu/windows/d3d11_copying_texture_wrapper_unittest.cc +++ b/chromium/media/gpu/windows/d3d11_copying_texture_wrapper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_decoder_configurator.cc b/chromium/media/gpu/windows/d3d11_decoder_configurator.cc index a88e8a371b4..8b43e325e54 100644 --- a/chromium/media/gpu/windows/d3d11_decoder_configurator.cc +++ b/chromium/media/gpu/windows/d3d11_decoder_configurator.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_decoder_configurator.h b/chromium/media/gpu/windows/d3d11_decoder_configurator.h index 7814bf535da..04a3b2327dc 100644 --- a/chromium/media/gpu/windows/d3d11_decoder_configurator.h +++ b/chromium/media/gpu/windows/d3d11_decoder_configurator.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_decoder_configurator_unittest.cc b/chromium/media/gpu/windows/d3d11_decoder_configurator_unittest.cc index a75f6e123d9..ee790be215c 100644 --- a/chromium/media/gpu/windows/d3d11_decoder_configurator_unittest.cc +++ b/chromium/media/gpu/windows/d3d11_decoder_configurator_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_h264_accelerator.cc b/chromium/media/gpu/windows/d3d11_h264_accelerator.cc index 48e827bee83..4f3f901444c 100644 --- a/chromium/media/gpu/windows/d3d11_h264_accelerator.cc +++ b/chromium/media/gpu/windows/d3d11_h264_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -21,7 +21,6 @@ #include "ui/gfx/color_space.h" #include "ui/gl/gl_bindings.h" #include "ui/gl/gl_context.h" -#include "ui/gl/gl_image_dxgi.h" #include "ui/gl/gl_surface_egl.h" #include "ui/gl/scoped_binders.h" diff --git a/chromium/media/gpu/windows/d3d11_h264_accelerator.h b/chromium/media/gpu/windows/d3d11_h264_accelerator.h index d9d9d6dc35b..8bf45046e1a 100644 --- a/chromium/media/gpu/windows/d3d11_h264_accelerator.h +++ b/chromium/media/gpu/windows/d3d11_h264_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_h265_accelerator.cc b/chromium/media/gpu/windows/d3d11_h265_accelerator.cc index d0ba1214ec9..ad15bf5216a 100644 --- a/chromium/media/gpu/windows/d3d11_h265_accelerator.cc +++ b/chromium/media/gpu/windows/d3d11_h265_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -23,7 +23,6 @@ #include "ui/gfx/color_space.h" #include "ui/gl/gl_bindings.h" #include "ui/gl/gl_context.h" -#include "ui/gl/gl_image_dxgi.h" #include "ui/gl/gl_surface_egl.h" #include "ui/gl/scoped_binders.h" @@ -407,12 +406,12 @@ void D3D11H265Accelerator::PicParamsFromSliceHeader( // IDR_W_RADL and IDR_N_LP NALUs do not contain st_rps in slice header. // Otherwise if short_term_ref_pic_set_sps_flag is 1, host decoder // shall set ucNumDeltaPocsOfRefRpsIdx to 0. - if (slice_hdr->short_term_ref_pic_set_sps_flag || !slice_hdr->st_rps_bits) { + if (slice_hdr->short_term_ref_pic_set_sps_flag) { pic_param->main.ucNumDeltaPocsOfRefRpsIdx = 0; pic_param->main.wNumBitsForShortTermRPSInSlice = 0; } else { pic_param->main.ucNumDeltaPocsOfRefRpsIdx = - slice_hdr->GetStRefPicSet(sps).num_delta_pocs; + slice_hdr->st_ref_pic_set.rps_idx_num_delta_pocs; pic_param->main.wNumBitsForShortTermRPSInSlice = slice_hdr->st_rps_bits; } pic_param->main.IrapPicFlag = slice_hdr->irap_pic; diff --git a/chromium/media/gpu/windows/d3d11_h265_accelerator.h b/chromium/media/gpu/windows/d3d11_h265_accelerator.h index f094b9c6a05..cf7924a530d 100644 --- a/chromium/media/gpu/windows/d3d11_h265_accelerator.h +++ b/chromium/media/gpu/windows/d3d11_h265_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_picture_buffer.cc b/chromium/media/gpu/windows/d3d11_picture_buffer.cc index 4e22aa5b602..e0929db67b8 100644 --- a/chromium/media/gpu/windows/d3d11_picture_buffer.cc +++ b/chromium/media/gpu/windows/d3d11_picture_buffer.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_picture_buffer.h b/chromium/media/gpu/windows/d3d11_picture_buffer.h index e63b92316e5..266840f8866 100644 --- a/chromium/media/gpu/windows/d3d11_picture_buffer.h +++ b/chromium/media/gpu/windows/d3d11_picture_buffer.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_picture_buffer_unittest.cc b/chromium/media/gpu/windows/d3d11_picture_buffer_unittest.cc index 546dee28ca3..8366b49127a 100644 --- a/chromium/media/gpu/windows/d3d11_picture_buffer_unittest.cc +++ b/chromium/media/gpu/windows/d3d11_picture_buffer_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_status.h b/chromium/media/gpu/windows/d3d11_status.h index 1642050216f..f2c76496e79 100644 --- a/chromium/media/gpu/windows/d3d11_status.h +++ b/chromium/media/gpu/windows/d3d11_status.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_texture_selector.cc b/chromium/media/gpu/windows/d3d11_texture_selector.cc index 7c9d135f580..cd12c5c8eec 100644 --- a/chromium/media/gpu/windows/d3d11_texture_selector.cc +++ b/chromium/media/gpu/windows/d3d11_texture_selector.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -122,23 +122,10 @@ std::unique_ptr<TextureSelector> TextureSelector::Create( output_dxgi_format = DXGI_FORMAT_B8G8R8A8_UNORM; output_pixel_format = PIXEL_FORMAT_ARGB; - if (input_color_space.GetTransferID() == - gfx::ColorSpace::TransferID::HLG) { - // VideoProcessor do good HLG tone mappping between different gpu - // vendors if we change input transfer from hlg to Gamma2.2 (Windows - // does not support DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020 - // well, see: https://crbug.com/1144260#c6) and output color space - // to sRGB. - output_color_space = gfx::ColorSpace::CreateSRGB(); - } else { - // VideoProcessor do poor PQ tone mapping between different - // gpu vendors, no matter if - // D3D11_VIDEO_PROCESSOR_FEATURE_CAPS_METADATA_HDR10 feature caps is - // supported or not. but gfx::ColorTransform indeed handle PQ content - // well, so reset colorspace to use gfx do tone mapping and the result - // is pretty good indeed. - output_color_space.reset(); - } + // Gfx::ColorTransform now can handle both PQ/HLG content well for + // all gpu vendors and also has a better performance when compared with + // video processor, reset colorspace to use gfx do tone mapping. + output_color_space.reset(); MEDIA_LOG(INFO, media_log) << "D3D11VideoDecoder: Selected ARGB"; } else if (!needs_texture_copy || supports_fmt(DXGI_FORMAT_P010)) { diff --git a/chromium/media/gpu/windows/d3d11_texture_selector.h b/chromium/media/gpu/windows/d3d11_texture_selector.h index 4e16e450fdc..18d1a7fd346 100644 --- a/chromium/media/gpu/windows/d3d11_texture_selector.h +++ b/chromium/media/gpu/windows/d3d11_texture_selector.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_texture_selector_unittest.cc b/chromium/media/gpu/windows/d3d11_texture_selector_unittest.cc index 0b25774bd70..c7055215846 100644 --- a/chromium/media/gpu/windows/d3d11_texture_selector_unittest.cc +++ b/chromium/media/gpu/windows/d3d11_texture_selector_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -25,7 +25,7 @@ class D3D11TextureSelectorUnittest : public ::testing::Test { class MockFormatSupportChecker : public FormatSupportChecker { public: MockFormatSupportChecker() : FormatSupportChecker(nullptr) {} - ~MockFormatSupportChecker() = default; + ~MockFormatSupportChecker() override = default; bool Initialize() override { return true; } MOCK_CONST_METHOD1(CheckOutputFormatSupport, bool(DXGI_FORMAT)); diff --git a/chromium/media/gpu/windows/d3d11_texture_wrapper.cc b/chromium/media/gpu/windows/d3d11_texture_wrapper.cc index fa6989ecf37..263fdd3b756 100644 --- a/chromium/media/gpu/windows/d3d11_texture_wrapper.cc +++ b/chromium/media/gpu/windows/d3d11_texture_wrapper.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -215,7 +215,7 @@ DefaultTexture2DWrapper::GpuResources::GpuResources( // decode, and allow webgl/canvas access. constexpr uint32_t usage = gpu::SHARED_IMAGE_USAGE_VIDEO_DECODE | gpu::SHARED_IMAGE_USAGE_GLES2 | - gpu::SHARED_IMAGE_USAGE_RASTER | gpu::SHARED_IMAGE_USAGE_DISPLAY | + gpu::SHARED_IMAGE_USAGE_RASTER | gpu::SHARED_IMAGE_USAGE_DISPLAY_READ | gpu::SHARED_IMAGE_USAGE_SCANOUT; scoped_refptr<gpu::DXGISharedHandleState> dxgi_shared_handle_state; diff --git a/chromium/media/gpu/windows/d3d11_texture_wrapper.h b/chromium/media/gpu/windows/d3d11_texture_wrapper.h index 12d442741de..1e0fde475c3 100644 --- a/chromium/media/gpu/windows/d3d11_texture_wrapper.h +++ b/chromium/media/gpu/windows/d3d11_texture_wrapper.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -24,7 +24,6 @@ #include "ui/gfx/hdr_metadata.h" #include "ui/gl/gl_bindings.h" #include "ui/gl/gl_context.h" -#include "ui/gl/gl_image_dxgi.h" #include "ui/gl/gl_surface_egl.h" #include "ui/gl/scoped_binders.h" diff --git a/chromium/media/gpu/windows/d3d11_texture_wrapper_unittest.cc b/chromium/media/gpu/windows/d3d11_texture_wrapper_unittest.cc index 4a7cfb19f98..0774789f8a6 100644 --- a/chromium/media/gpu/windows/d3d11_texture_wrapper_unittest.cc +++ b/chromium/media/gpu/windows/d3d11_texture_wrapper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_context_wrapper.cc b/chromium/media/gpu/windows/d3d11_video_context_wrapper.cc index f1073892fa7..45d89fa5982 100644 --- a/chromium/media/gpu/windows/d3d11_video_context_wrapper.cc +++ b/chromium/media/gpu/windows/d3d11_video_context_wrapper.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_context_wrapper.h b/chromium/media/gpu/windows/d3d11_video_context_wrapper.h index cbdd6b4e80c..30beeb950a9 100644 --- a/chromium/media/gpu/windows/d3d11_video_context_wrapper.h +++ b/chromium/media/gpu/windows/d3d11_video_context_wrapper.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_decoder.cc b/chromium/media/gpu/windows/d3d11_video_decoder.cc index 485515a8111..72a1b6fbf90 100644 --- a/chromium/media/gpu/windows/d3d11_video_decoder.cc +++ b/chromium/media/gpu/windows/d3d11_video_decoder.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -94,7 +94,7 @@ std::unique_ptr<VideoDecoder> D3D11VideoDecoder::Create( base::RepeatingCallback<gpu::CommandBufferStub*()> get_stub_cb, D3D11VideoDecoder::GetD3D11DeviceCB get_d3d11_device_cb, SupportedConfigs supported_configs, - bool is_hdr_supported) { + bool system_hdr_enabled) { // We create |impl_| on the wrong thread, but we never use it here. // Note that the output callback will hop to our thread, post the video // frame, and along with a callback that will hop back to the impl thread @@ -111,7 +111,7 @@ std::unique_ptr<VideoDecoder> D3D11VideoDecoder::Create( base::SequenceBound<D3D11VideoDecoderImpl>( gpu_task_runner, std::move(cloned_media_log), get_helper_cb), get_helper_cb, std::move(get_d3d11_device_cb), - std::move(supported_configs), is_hdr_supported)); + std::move(supported_configs), system_hdr_enabled)); } D3D11VideoDecoder::D3D11VideoDecoder( @@ -123,7 +123,7 @@ D3D11VideoDecoder::D3D11VideoDecoder( base::RepeatingCallback<scoped_refptr<CommandBufferHelper>()> get_helper_cb, GetD3D11DeviceCB get_d3d11_device_cb, SupportedConfigs supported_configs, - bool is_hdr_supported) + bool system_hdr_enabled) : media_log_(std::move(media_log)), impl_(std::move(impl)), gpu_task_runner_(std::move(gpu_task_runner)), @@ -134,7 +134,7 @@ D3D11VideoDecoder::D3D11VideoDecoder( get_d3d11_device_cb_(std::move(get_d3d11_device_cb)), get_helper_cb_(std::move(get_helper_cb)), supported_configs_(std::move(supported_configs)), - is_hdr_supported_(is_hdr_supported) { + system_hdr_enabled_(system_hdr_enabled) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(media_log_); } @@ -256,8 +256,8 @@ D3D11Status::Or<ComD3D11VideoDecoder> D3D11VideoDecoder::CreateD3D11Decoder() { texture_selector_ = TextureSelector::Create( gpu_preferences_, gpu_workarounds_, decoder_configurator_->TextureFormat(), - is_hdr_supported_ ? TextureSelector::HDRMode::kSDROrHDR - : TextureSelector::HDRMode::kSDROnly, + system_hdr_enabled_ ? TextureSelector::HDRMode::kSDROrHDR + : TextureSelector::HDRMode::kSDROnly, &format_checker, video_device_, device_context_, media_log_.get(), config_.color_space_info().ToGfxColorSpace(), use_shared_handle); if (!texture_selector_) @@ -812,7 +812,10 @@ void D3D11VideoDecoder::CreatePictureBuffers() { // order of these calls is important, and we must set the display metadata // if we set the stream metadata, else it can crash on some AMD cards. if (display_metadata) { - if (config_.hdr_metadata() || + // If system hdr is not enabled, don't set metadata can help us avoid + // video processor's tone mapping (if gpu vendor is intel), since we + // always want to use gfx::ColorTransform do PQ tone-mapping. + if ((config_.hdr_metadata() && system_hdr_enabled_) || gpu_workarounds_.use_empty_video_hdr_metadata) { // It's okay if this has an empty-initialized metadata. picture_buffers_[i]->texture_wrapper()->SetStreamHDRMetadata( diff --git a/chromium/media/gpu/windows/d3d11_video_decoder.h b/chromium/media/gpu/windows/d3d11_video_decoder.h index f7749719570..60aedc519fe 100644 --- a/chromium/media/gpu/windows/d3d11_video_decoder.h +++ b/chromium/media/gpu/windows/d3d11_video_decoder.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -68,7 +68,7 @@ class MEDIA_GPU_EXPORT D3D11VideoDecoder : public VideoDecoder, base::RepeatingCallback<gpu::CommandBufferStub*()> get_stub_cb, GetD3D11DeviceCB get_d3d11_device_cb, SupportedConfigs supported_configs, - bool is_hdr_supported); + bool system_hdr_enabled); D3D11VideoDecoder(const D3D11VideoDecoder&) = delete; D3D11VideoDecoder& operator=(const D3D11VideoDecoder&) = delete; @@ -125,7 +125,7 @@ class MEDIA_GPU_EXPORT D3D11VideoDecoder : public VideoDecoder, get_helper_cb, GetD3D11DeviceCB get_d3d11_device_cb, SupportedConfigs supported_configs, - bool is_hdr_supported); + bool system_hdr_enabled); // Receive |buffer|, that is now unused by the client. void ReceivePictureBufferFromClient(scoped_refptr<D3D11PictureBuffer> buffer); @@ -308,7 +308,7 @@ class MEDIA_GPU_EXPORT D3D11VideoDecoder : public VideoDecoder, SupportedConfigs supported_configs_; // Should we assume that we're outputting to an HDR display? - bool is_hdr_supported_ = false; + bool system_hdr_enabled_ = false; // Should we use multiple single textures for the decoder output (true) or one // texture with multiple array slices (false)? diff --git a/chromium/media/gpu/windows/d3d11_video_decoder_client.h b/chromium/media/gpu/windows/d3d11_video_decoder_client.h index efd0d711d4a..aeeb694b0fb 100644 --- a/chromium/media/gpu/windows/d3d11_video_decoder_client.h +++ b/chromium/media/gpu/windows/d3d11_video_decoder_client.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_decoder_impl.cc b/chromium/media/gpu/windows/d3d11_video_decoder_impl.cc index 719e7b516fe..954a4404ccf 100644 --- a/chromium/media/gpu/windows/d3d11_video_decoder_impl.cc +++ b/chromium/media/gpu/windows/d3d11_video_decoder_impl.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_decoder_impl.h b/chromium/media/gpu/windows/d3d11_video_decoder_impl.h index 61320d864cc..53b71395162 100644 --- a/chromium/media/gpu/windows/d3d11_video_decoder_impl.h +++ b/chromium/media/gpu/windows/d3d11_video_decoder_impl.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_decoder_unittest.cc b/chromium/media/gpu/windows/d3d11_video_decoder_unittest.cc index 897ec022ddd..4a50aa78827 100644 --- a/chromium/media/gpu/windows/d3d11_video_decoder_unittest.cc +++ b/chromium/media/gpu/windows/d3d11_video_decoder_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -204,7 +204,7 @@ class D3D11VideoDecoderTest : public ::testing::Test { gpu_task_runner_, std::make_unique<NullMediaLog>(), gpu_preferences_, gpu_workarounds_, std::move(impl), base::RepeatingCallback<scoped_refptr<CommandBufferHelper>()>(), - get_device_cb, *supported_configs, is_hdr_supported_)); + get_device_cb, *supported_configs, system_hdr_enabled_)); } void InitializeDecoder(const VideoDecoderConfig& config, bool expectSuccess) { @@ -250,8 +250,8 @@ class D3D11VideoDecoderTest : public ::testing::Test { Microsoft::WRL::ComPtr<DXGIDeviceMock> mock_dxgi_device_; Microsoft::WRL::ComPtr<DXGIAdapterMock> mock_dxgi_adapter_; - // Used by CreateDecoder() to tell D3D11VideoDecoder about HDR support. - bool is_hdr_supported_ = true; + // Used by CreateDecoder() to tell D3D11VideoDecoder about if HDR is enabled. + bool system_hdr_enabled_ = true; DXGI_ADAPTER_DESC mock_adapter_desc_; diff --git a/chromium/media/gpu/windows/d3d11_video_device_format_support.cc b/chromium/media/gpu/windows/d3d11_video_device_format_support.cc index 7436f418f9d..f35411baaa4 100644 --- a/chromium/media/gpu/windows/d3d11_video_device_format_support.cc +++ b/chromium/media/gpu/windows/d3d11_video_device_format_support.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_device_format_support.h b/chromium/media/gpu/windows/d3d11_video_device_format_support.h index 8472044c358..ab752f0d7b8 100644 --- a/chromium/media/gpu/windows/d3d11_video_device_format_support.h +++ b/chromium/media/gpu/windows/d3d11_video_device_format_support.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_device_format_support_unittest.cc b/chromium/media/gpu/windows/d3d11_video_device_format_support_unittest.cc index 6c03b082f69..2f5b7b9d0b9 100644 --- a/chromium/media/gpu/windows/d3d11_video_device_format_support_unittest.cc +++ b/chromium/media/gpu/windows/d3d11_video_device_format_support_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_processor_proxy.cc b/chromium/media/gpu/windows/d3d11_video_processor_proxy.cc index deb7182dd7b..3d8c07318df 100644 --- a/chromium/media/gpu/windows/d3d11_video_processor_proxy.cc +++ b/chromium/media/gpu/windows/d3d11_video_processor_proxy.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_processor_proxy.h b/chromium/media/gpu/windows/d3d11_video_processor_proxy.h index 8bd0d360e9c..b4fe2fb2818 100644 --- a/chromium/media/gpu/windows/d3d11_video_processor_proxy.h +++ b/chromium/media/gpu/windows/d3d11_video_processor_proxy.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_video_processor_proxy_unittest.cc b/chromium/media/gpu/windows/d3d11_video_processor_proxy_unittest.cc index 1ddc97ca178..50e71223a38 100644 --- a/chromium/media/gpu/windows/d3d11_video_processor_proxy_unittest.cc +++ b/chromium/media/gpu/windows/d3d11_video_processor_proxy_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_vp9_accelerator.cc b/chromium/media/gpu/windows/d3d11_vp9_accelerator.cc index 5de9677ca47..2054e2418ff 100644 --- a/chromium/media/gpu/windows/d3d11_vp9_accelerator.cc +++ b/chromium/media/gpu/windows/d3d11_vp9_accelerator.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_vp9_accelerator.h b/chromium/media/gpu/windows/d3d11_vp9_accelerator.h index 4dd398502c7..d5498c5f18f 100644 --- a/chromium/media/gpu/windows/d3d11_vp9_accelerator.h +++ b/chromium/media/gpu/windows/d3d11_vp9_accelerator.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_vp9_picture.cc b/chromium/media/gpu/windows/d3d11_vp9_picture.cc index 913fefec589..997e07f96cb 100644 --- a/chromium/media/gpu/windows/d3d11_vp9_picture.cc +++ b/chromium/media/gpu/windows/d3d11_vp9_picture.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/d3d11_vp9_picture.h b/chromium/media/gpu/windows/d3d11_vp9_picture.h index 02b50c5d7bb..2caeca464d7 100644 --- a/chromium/media/gpu/windows/d3d11_vp9_picture.h +++ b/chromium/media/gpu/windows/d3d11_vp9_picture.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/dxva_picture_buffer_win.cc b/chromium/media/gpu/windows/dxva_picture_buffer_win.cc index fa4837b645f..726bd6a136c 100644 --- a/chromium/media/gpu/windows/dxva_picture_buffer_win.cc +++ b/chromium/media/gpu/windows/dxva_picture_buffer_win.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/dxva_picture_buffer_win.h b/chromium/media/gpu/windows/dxva_picture_buffer_win.h index 1fbb8494813..e3c5783f699 100644 --- a/chromium/media/gpu/windows/dxva_picture_buffer_win.h +++ b/chromium/media/gpu/windows/dxva_picture_buffer_win.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/dxva_video_decode_accelerator_win.cc b/chromium/media/gpu/windows/dxva_video_decode_accelerator_win.cc index 3c85ccad3ab..7b71280afe5 100644 --- a/chromium/media/gpu/windows/dxva_video_decode_accelerator_win.cc +++ b/chromium/media/gpu/windows/dxva_video_decode_accelerator_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -3235,7 +3235,7 @@ DXVAVideoDecodeAccelerator::GetSharedImagesFromPictureBuffer( // to decode, and allow webgl/canvas access. constexpr uint32_t shared_image_usage = gpu::SHARED_IMAGE_USAGE_VIDEO_DECODE | gpu::SHARED_IMAGE_USAGE_GLES2 | - gpu::SHARED_IMAGE_USAGE_RASTER | gpu::SHARED_IMAGE_USAGE_DISPLAY | + gpu::SHARED_IMAGE_USAGE_RASTER | gpu::SHARED_IMAGE_USAGE_DISPLAY_READ | gpu::SHARED_IMAGE_USAGE_SCANOUT; // Create a shared image @@ -3274,8 +3274,8 @@ DXVAVideoDecodeAccelerator::GetSharedImagesFromPictureBuffer( gpu::SharedImageStub* shared_image_stub = client_->GetSharedImageStub(); DCHECK(shared_image_stub); - const bool success = shared_image_stub->factory()->RegisterBacking( - std::move(shared_image), /* legacy_mailbox */ true); + const bool success = + shared_image_stub->factory()->RegisterBacking(std::move(shared_image)); if (!success) { RETURN_AND_NOTIFY_ON_FAILURE(false, "Failed to register shared image", PLATFORM_FAILURE, {}); diff --git a/chromium/media/gpu/windows/dxva_video_decode_accelerator_win.h b/chromium/media/gpu/windows/dxva_video_decode_accelerator_win.h index 8ca4d60b155..04f03a441ac 100644 --- a/chromium/media/gpu/windows/dxva_video_decode_accelerator_win.h +++ b/chromium/media/gpu/windows/dxva_video_decode_accelerator_win.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/init_guid.cc b/chromium/media/gpu/windows/init_guid.cc index 51e49af265f..ed8fd5e41f3 100644 --- a/chromium/media/gpu/windows/init_guid.cc +++ b/chromium/media/gpu/windows/init_guid.cc @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/media_foundation_video_encode_accelerator_win.cc b/chromium/media/gpu/windows/media_foundation_video_encode_accelerator_win.cc index 3b424904e2e..fab1ff9def5 100644 --- a/chromium/media/gpu/windows/media_foundation_video_encode_accelerator_win.cc +++ b/chromium/media/gpu/windows/media_foundation_video_encode_accelerator_win.cc @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -79,6 +79,12 @@ constexpr const wchar_t* const kMediaFoundationVideoEncoderDLLs[] = { L"mfplat.dll", }; +static const CLSID kIntelAV1HybridEncoderCLSID = { + 0x62c053ce, + 0x5357, + 0x4794, + {0x8c, 0x5a, 0xfb, 0xef, 0xfe, 0xff, 0xb8, 0x2d}}; + eAVEncH264VProfile GetH264VProfile(VideoCodecProfile profile, bool is_constrained_h264) { switch (profile) { @@ -115,6 +121,8 @@ bool IsSvcSupported(IMFActivate* activate) { // More info: https://crbug.com/1253748 return false; #else + // crbug.com/1350257 + TRACE_EVENT0("catan_investigation", "IsSvcSupported"); Microsoft::WRL::ComPtr<IMFTransform> encoder; Microsoft::WRL::ComPtr<ICodecAPI> codec_api; HRESULT hr = activate->ActivateObject(IID_PPV_ARGS(&encoder)); @@ -229,6 +237,33 @@ uint32_t EnumerateHardwareEncoders(VideoCodec codec, return count; } +// Per +// https://learn.microsoft.com/en-us/windows/win32/medfound/handling-stream-changes, +// encoders should only accept an input type that matches the currently +// configured output type. If we want to change the frame rate, a +// stream restart flow is needed, which in turn generates a key-frame on the +// stream restart. This is not friendly for WebRTC encoding, which adjusts the +// encoding frame rate frequently. +// To mitigate this, we only configure the frame rate during HMFT +// initialization. On subsequent frame rate update request, if new frame rate is +// larger than currently configured frame rate and bitrate is kept unchanged, +// this implies average encoded frame size should decrease proportionally. Since +// we don't actually configure the new frame rate into HMFT(to avoid stream +// restart), we emulate this average frame size decrease by proportionally +// decreasing the target/peak bitrate(which does not require stream restart). +// This is similar for frame rate update request that is lower than currently +// configured, by increasing bitrate to emulate average frame size increase. +// See https://crbug.com/1295815 for more details. +uint32_t AdjustBitrateToFrameRate(uint32_t bitrate, + uint32_t configured_framerate, + uint32_t requested_framerate) { + if (requested_framerate == 0u) { + return 0u; + } + + return bitrate * configured_framerate / requested_framerate; +} + } // namespace class MediaFoundationVideoEncodeAccelerator::EncodeOutput { @@ -282,8 +317,6 @@ MediaFoundationVideoEncodeAccelerator::MediaFoundationVideoEncodeAccelerator( CHROME_LUID luid) : compatible_with_win7_( gpu_preferences.enable_media_foundation_vea_on_windows7), - disable_dynamic_framerate_update_( - gpu_workarounds.disable_dynamic_video_encode_framerate_update), frame_rate_(kMaxFrameRateNumerator / kMaxFrameRateDenominator), bitrate_(Bitrate::ConstantBitrate(kDefaultTargetBitrate)), input_required_(false), @@ -314,26 +347,7 @@ MediaFoundationVideoEncodeAccelerator::GetSupportedProfiles() { SupportedProfiles profiles; for (auto codec : {VideoCodec::kH264, VideoCodec::kVP9, VideoCodec::kAV1}) { - auto codec_profiles = GetSupportedProfilesForCodec(codec, true); - profiles.insert(profiles.end(), codec_profiles.begin(), - codec_profiles.end()); - } - - ReleaseEncoderResources(); - return profiles; -} - -VideoEncodeAccelerator::SupportedProfiles -MediaFoundationVideoEncodeAccelerator::GetSupportedProfilesLight() { - TRACE_EVENT0( - "gpu,startup", - "MediaFoundationVideoEncodeAccelerator::GetSupportedProfilesLight"); - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - - SupportedProfiles profiles; - - for (auto codec : {VideoCodec::kH264, VideoCodec::kVP9, VideoCodec::kAV1}) { - auto codec_profiles = GetSupportedProfilesForCodec(codec, false); + auto codec_profiles = GetSupportedProfilesForCodec(codec); profiles.insert(profiles.end(), codec_profiles.begin(), codec_profiles.end()); } @@ -344,8 +358,7 @@ MediaFoundationVideoEncodeAccelerator::GetSupportedProfilesLight() { VideoEncodeAccelerator::SupportedProfiles MediaFoundationVideoEncodeAccelerator::GetSupportedProfilesForCodec( - VideoCodec codec, - bool populate_svc_info) { + VideoCodec codec) { SupportedProfiles profiles; if ((codec == VideoCodec::kVP9 && !base::FeatureList::IsEnabled(kMediaFoundationVP9Encoding)) || @@ -367,10 +380,8 @@ MediaFoundationVideoEncodeAccelerator::GetSupportedProfilesForCodec( if (pp_activate) { for (UINT32 i = 0; i < encoder_count; i++) { if (pp_activate[i]) { - if (populate_svc_info && !svc_supported && - IsSvcSupported(pp_activate[i])) { + if (!svc_supported && IsSvcSupported(pp_activate[i])) svc_supported = true; - } // Release the enumerated instances if any. // According to Windows Dev Center, @@ -460,7 +471,7 @@ bool MediaFoundationVideoEncodeAccelerator::Initialize( std::make_unique<base::WeakPtrFactory<Client>>(client); main_client_ = main_client_weak_factory_->GetWeakPtr(); input_visible_size_ = config.input_visible_size; - if (config.initial_framerate.has_value()) + if (config.initial_framerate.has_value() && config.initial_framerate.value()) frame_rate_ = config.initial_framerate.value(); else frame_rate_ = kMaxFrameRateNumerator / kMaxFrameRateDenominator; @@ -558,7 +569,7 @@ void MediaFoundationVideoEncodeAccelerator::EncoderInitializeTask( VideoEncoderInfo encoder_info; encoder_info.implementation_name = "MediaFoundationVideoEncodeAccelerator"; - encoder_info.has_trusted_rate_controller = true; + encoder_info.has_trusted_rate_controller = false; DCHECK(encoder_info.is_hardware_accelerated); DCHECK(encoder_info.supports_native_handle); DCHECK(!encoder_info.supports_simulcast); @@ -682,52 +693,52 @@ bool MediaFoundationVideoEncodeAccelerator::ActivateAsyncEncoder( // Try to create the encoder with priority according to merit value. HRESULT hr = E_FAIL; for (UINT32 i = 0; i < encoder_count; i++) { - if (FAILED(hr)) { - DCHECK(!encoder_); - DCHECK(!activate_); - hr = pp_activate[i]->ActivateObject(IID_PPV_ARGS(&encoder_)); - if (encoder_.Get() != nullptr) { - DCHECK(SUCCEEDED(hr)); - auto vendor = GetDriverVendor(pp_activate[i]); - - // Skip NVIDIA GPU due to https://crbug.com/1088650 for constrained - // baseline profile H.264 encoding, and go to the next instance - // according to merit value. - if (codec_ == VideoCodec::kH264 && is_constrained_h264) { - // Get the vendor id. - base::win::ScopedCoMem<WCHAR> vendor_id; - UINT32 id_length; - pp_activate[i]->GetAllocatedString( - MFT_ENUM_HARDWARE_VENDOR_ID_Attribute, &vendor_id, &id_length); - if (!_wcsnicmp(vendor_id, L"VEN_10DE", id_length)) { - DLOG(WARNING) - << "Skipped NVIDIA GPU due to https://crbug.com/1088650"; - pp_activate[i]->ShutdownObject(); - encoder_.Reset(); - hr = E_FAIL; - continue; - } - } + auto vendor = GetDriverVendor(pp_activate[i]); + // Skip flawky Intel hybrid AV1 encoder. + if (codec_ == VideoCodec::kAV1 && vendor == DriverVendor::kIntel) { + // Get the CLSID GUID of the HMFT. + GUID mft_guid = {0}; + pp_activate[i]->GetGUID(MFT_TRANSFORM_CLSID_Attribute, &mft_guid); + if (mft_guid == kIntelAV1HybridEncoderCLSID) { + DLOG(WARNING) << "Skipped Intel hybrid AV1 encoder MFT."; + continue; + } + } - activate_ = pp_activate[i]; - vendor_ = vendor; - pp_activate[i] = nullptr; + // Skip NVIDIA GPU due to https://crbug.com/1088650 for constrained + // baseline profile H.264 encoding, and go to the next instance according + // to merit value. + if (codec_ == VideoCodec::kH264 && is_constrained_h264 && + vendor == DriverVendor::kNvidia) { + DLOG(WARNING) << "Skipped NVIDIA GPU due to https://crbug.com/1088650"; + continue; + } - // Print the friendly name. - base::win::ScopedCoMem<WCHAR> friendly_name; - UINT32 name_length; - activate_->GetAllocatedString(MFT_FRIENDLY_NAME_Attribute, - &friendly_name, &name_length); - DVLOG(3) << "Selected asynchronous hardware encoder's friendly name: " - << friendly_name; - } else { - DCHECK(FAILED(hr)); + DCHECK(!encoder_); + DCHECK(!activate_); + hr = pp_activate[i]->ActivateObject(IID_PPV_ARGS(&encoder_)); + if (encoder_.Get() != nullptr) { + DCHECK(SUCCEEDED(hr)); + activate_ = pp_activate[i]; + vendor_ = vendor; + pp_activate[i] = nullptr; + + // Print the friendly name. + base::win::ScopedCoMem<WCHAR> friendly_name; + UINT32 name_length; + activate_->GetAllocatedString(MFT_FRIENDLY_NAME_Attribute, &friendly_name, + &name_length); + DVLOG(3) << "Selected asynchronous hardware encoder's friendly name: " + << friendly_name; + // Encoder is successfully activated. + break; + } else { + DCHECK(FAILED(hr)); - // The component that calls ActivateObject is - // responsible for calling ShutdownObject, - // https://docs.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfactivate-shutdownobject. - pp_activate[i]->ShutdownObject(); - } + // The component that calls ActivateObject is + // responsible for calling ShutdownObject, + // https://docs.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfactivate-shutdownobject. + pp_activate[i]->ShutdownObject(); } } @@ -803,11 +814,15 @@ bool MediaFoundationVideoEncodeAccelerator::InitializeInputOutputParameters( hr = imf_output_media_type_->SetGUID(MF_MT_SUBTYPE, VideoCodecToMFSubtype(codec_)); RETURN_ON_HR_FAILURE(hr, "Couldn't set video format", false); - hr = imf_output_media_type_->SetUINT32(MF_MT_AVG_BITRATE, - bitrate_.target_bps()); + + hr = imf_output_media_type_->SetUINT32( + MF_MT_AVG_BITRATE, AdjustBitrateToFrameRate(bitrate_.target_bps(), + frame_rate_, frame_rate_)); RETURN_ON_HR_FAILURE(hr, "Couldn't set bitrate", false); + configured_frame_rate_ = frame_rate_; + hr = MFSetAttributeRatio(imf_output_media_type_.Get(), MF_MT_FRAME_RATE, - frame_rate_, 1); + configured_frame_rate_, 1); RETURN_ON_HR_FAILURE(hr, "Couldn't set frame rate", false); hr = MFSetAttributeSize(imf_output_media_type_.Get(), MF_MT_FRAME_SIZE, input_visible_size_.width(), @@ -837,7 +852,7 @@ bool MediaFoundationVideoEncodeAccelerator::InitializeInputOutputParameters( hr = imf_input_media_type_->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12); RETURN_ON_HR_FAILURE(hr, "Couldn't set video format", false); hr = MFSetAttributeRatio(imf_input_media_type_.Get(), MF_MT_FRAME_RATE, - frame_rate_, 1); + configured_frame_rate_, 1); RETURN_ON_HR_FAILURE(hr, "Couldn't set frame rate", false); hr = MFSetAttributeSize(imf_input_media_type_.Get(), MF_MT_FRAME_SIZE, input_visible_size_.width(), @@ -891,14 +906,16 @@ bool MediaFoundationVideoEncodeAccelerator::SetEncoderModes() { } } - var.ulVal = bitrate_.target_bps(); + var.ulVal = AdjustBitrateToFrameRate(bitrate_.target_bps(), + configured_frame_rate_, frame_rate_); hr = codec_api_->SetValue(&CODECAPI_AVEncCommonMeanBitRate, &var); if (!compatible_with_win7_) { RETURN_ON_HR_FAILURE(hr, "Couldn't set bitrate", false); } if (bitrate_.mode() == Bitrate::Mode::kVariable) { - var.ulVal = bitrate_.peak_bps(); + var.ulVal = AdjustBitrateToFrameRate(bitrate_.peak_bps(), + configured_frame_rate_, frame_rate_); hr = codec_api_->SetValue(&CODECAPI_AVEncCommonMaxBitRate, &var); if (!compatible_with_win7_) { RETURN_ON_HR_FAILURE(hr, "Couldn't set bitrate", false); @@ -1468,78 +1485,21 @@ void MediaFoundationVideoEncodeAccelerator::RequestEncodingParametersChangeTask( framerate = base::clamp(framerate, 1u, uint32_t{kMaxFrameRateNumerator}); - if (frame_rate_ != framerate) { - // When dynamic framerate update is disabled, fallback from current encoder. - if (disable_dynamic_framerate_update_) { - DLOG(ERROR) << "Dynamic encode framerate update disabled."; - NotifyError(kPlatformFailureError); - } - HRESULT hr = MFSetAttributeRatio(imf_output_media_type_.Get(), - MF_MT_FRAME_RATE, framerate, 1); - RETURN_ON_HR_FAILURE(hr, "Couldn't set frame rate for output type", ); - - imf_output_media_type_->SetUINT32(MF_MT_AVG_BITRATE, bitrate.target_bps()); - RETURN_ON_HR_FAILURE(hr, "Couldn't set average bitrate for output type", ); - - hr = MFSetAttributeRatio(imf_input_media_type_.Get(), MF_MT_FRAME_RATE, - framerate, 1); - RETURN_ON_HR_FAILURE(hr, "Couldn't set frame rate for input type", ); - - // Some HMFTs will reject output type change with MF_E_INVALIDTYPE due - // to temporary mismatch between output/input media types, so we always - // clear the input/output media types before reconfiguring them - // dynamically. - hr = encoder_->ProcessMessage(MFT_MESSAGE_COMMAND_DRAIN, 0); - RETURN_ON_HR_FAILURE( - hr, "Couldn't process message MFT_MESSAGE_COMMAND_DRAIN", ); - - DrainPendingOutputs(); - - hr = encoder_->ProcessMessage(MFT_MESSAGE_NOTIFY_END_OF_STREAM, 0); - RETURN_ON_HR_FAILURE( - hr, "Couldn't process message MFT_MESSAGE_NOTIFY_END_OF_STREAM", ); - - hr = encoder_->ProcessMessage(MFT_MESSAGE_NOTIFY_END_STREAMING, 0); - RETURN_ON_HR_FAILURE( - hr, "Couldn't process message MFT_MESSAGE_NOTIFY_END_STREAMING", ); - - hr = encoder_->SetInputType(input_stream_id_, nullptr, 0); - RETURN_ON_HR_FAILURE(hr, "Couldn't clear input media type.", ); - - hr = encoder_->SetOutputType(output_stream_id_, nullptr, 0); - RETURN_ON_HR_FAILURE(hr, "Couldn't clear ouput media type.", ); - - hr = encoder_->SetOutputType(output_stream_id_, - imf_output_media_type_.Get(), 0); - RETURN_ON_HR_FAILURE(hr, "Couldn't set output media type", ); - - hr = encoder_->SetInputType(input_stream_id_, imf_input_media_type_.Get(), - 0); - RETURN_ON_HR_FAILURE(hr, "Couldn't set input media type", ); - - hr = encoder_->ProcessMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, 0); - RETURN_ON_HR_FAILURE( - hr, "Couldn't process message MFT_MESSAGE_NOTIFY_BEGIN_STREAMING", ); - - hr = encoder_->ProcessMessage(MFT_MESSAGE_NOTIFY_START_OF_STREAM, 0); - RETURN_ON_HR_FAILURE( - hr, "Couldn't process message MFT_MESSAGE_NOTIFY_START_OF_STREAM", ); - - frame_rate_ = framerate; - } - - if (bitrate_ != bitrate) { + if (bitrate_ != bitrate || frame_rate_ != framerate) { bitrate_ = bitrate; + frame_rate_ = framerate; VARIANT var; var.vt = VT_UI4; - var.ulVal = bitrate.target_bps(); + var.ulVal = AdjustBitrateToFrameRate(bitrate.target_bps(), + configured_frame_rate_, framerate); HRESULT hr = codec_api_->SetValue(&CODECAPI_AVEncCommonMeanBitRate, &var); if (!compatible_with_win7_) { RETURN_ON_HR_FAILURE(hr, "Couldn't update mean bitrate", ); } if (bitrate.mode() == Bitrate::Mode::kVariable) { - var.ulVal = bitrate.peak_bps(); + var.ulVal = AdjustBitrateToFrameRate(bitrate.peak_bps(), + configured_frame_rate_, framerate); hr = codec_api_->SetValue(&CODECAPI_AVEncCommonMaxBitRate, &var); if (!compatible_with_win7_) { RETURN_ON_HR_FAILURE(hr, "Couldn't set max bitrate", ); @@ -1739,22 +1699,4 @@ HRESULT MediaFoundationVideoEncodeAccelerator::PerformD3DScaling( return hr; } -void MediaFoundationVideoEncodeAccelerator::DrainPendingOutputs() { - Microsoft::WRL::ComPtr<IMFMediaEvent> media_event; - - while ((SUCCEEDED( - event_generator_->GetEvent(MF_EVENT_FLAG_NO_WAIT, &media_event)))) { - MediaEventType event_type; - HRESULT hr = media_event->GetType(&event_type); - if (FAILED(hr)) { - DLOG(ERROR) << "Failed to get the type of media event."; - continue; - } - - if (event_type == METransformHaveOutput) { - ProcessOutput(); - } - } -} - } // namespace media diff --git a/chromium/media/gpu/windows/media_foundation_video_encode_accelerator_win.h b/chromium/media/gpu/windows/media_foundation_video_encode_accelerator_win.h index be7dd3ac671..c95c815e1d9 100644 --- a/chromium/media/gpu/windows/media_foundation_video_encode_accelerator_win.h +++ b/chromium/media/gpu/windows/media_foundation_video_encode_accelerator_win.h @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -52,8 +52,6 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator // VideoEncodeAccelerator implementation. VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() override; - VideoEncodeAccelerator::SupportedProfiles GetSupportedProfilesLight() - override; bool Initialize(const Config& config, Client* client, std::unique_ptr<MediaLog> media_log) override; @@ -82,8 +80,7 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator // Get supported profiles for specific codec. VideoEncodeAccelerator::SupportedProfiles GetSupportedProfilesForCodec( - VideoCodec codec, - bool populate_svc_info); + VideoCodec codec); // Activates the asynchronous encoder instance |encoder_| according to codec // merit. @@ -126,9 +123,6 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator // Checks for and copies encoded output on |encoder_thread_task_runner_|. void ProcessOutput(); - // Drains pending output samples on |encoder_thread_task_runner_|. - void DrainPendingOutputs(); - // Tries to deliver the input frame to the encoder. bool TryToDeliverInputFrame(scoped_refptr<VideoFrame> frame, bool force_keyframe); @@ -161,7 +155,6 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator HRESULT PerformD3DScaling(ID3D11Texture2D* input_texture); const bool compatible_with_win7_; - const bool disable_dynamic_framerate_update_; // Bitstream buffers ready to be used to return encoded output as a FIFO. base::circular_deque<std::unique_ptr<BitstreamBufferRef>> @@ -180,6 +173,9 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator gfx::Size input_visible_size_; size_t bitstream_buffer_size_; uint32_t frame_rate_; + // For recording configured frame rate as we don't dynamically change it. + // The default value here will be overridden during initialization. + uint32_t configured_frame_rate_ = 30; Bitrate bitrate_; bool low_latency_mode_; int num_temporal_layers_ = 1; diff --git a/chromium/media/gpu/windows/mf_audio_encoder.cc b/chromium/media/gpu/windows/mf_audio_encoder.cc index bd39b655768..049cef50193 100644 --- a/chromium/media/gpu/windows/mf_audio_encoder.cc +++ b/chromium/media/gpu/windows/mf_audio_encoder.cc @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,9 +12,11 @@ #include <string.h> #include <wmcodecdsp.h> #include <wrl/client.h> + #include <utility> #include "base/bind.h" +#include "base/containers/contains.h" #include "base/logging.h" #include "base/memory/weak_ptr.h" #include "base/task/single_thread_task_runner.h" @@ -78,8 +80,7 @@ EncoderStatus::Codes ValidateInputOptions(const AudioEncoder::Options& options, if (options.codec != AudioCodec::kAAC) return EncoderStatus::Codes::kEncoderUnsupportedCodec; - if (std::find(kSupportedSampleRates.begin(), kSupportedSampleRates.end(), - options.sample_rate) == kSupportedSampleRates.end()) { + if (!base::Contains(kSupportedSampleRates, options.sample_rate)) { return EncoderStatus::Codes::kEncoderUnsupportedConfig; } @@ -102,8 +103,7 @@ EncoderStatus::Codes ValidateInputOptions(const AudioEncoder::Options& options, } *bitrate = options.bitrate.value_or(kDefaultBitrate); - if (std::find(kSupportedBitrates.begin(), kSupportedBitrates.end(), - *bitrate) == kSupportedBitrates.end()) { + if (!base::Contains(kSupportedBitrates, *bitrate)) { return EncoderStatus::Codes::kEncoderUnsupportedConfig; } @@ -470,9 +470,9 @@ void MFAudioEncoder::Initialize(const Options& options, } channel_count_ = options_.channels; - audio_params_ = - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, - options_.sample_rate, kSamplesPerFrame); + audio_params_ = AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + {channel_layout, channel_count_}, + options_.sample_rate, kSamplesPerFrame); input_timestamp_tracker_ = std::make_unique<AudioTimestampHelper>(options_.sample_rate); output_timestamp_tracker_ = diff --git a/chromium/media/gpu/windows/mf_audio_encoder.h b/chromium/media/gpu/windows/mf_audio_encoder.h index f7f3e9c17ed..c257f31e3ae 100644 --- a/chromium/media/gpu/windows/mf_audio_encoder.h +++ b/chromium/media/gpu/windows/mf_audio_encoder.h @@ -1,4 +1,4 @@ -// Copyright 2022 The Chromium Authors. All rights reserved. +// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/output_with_release_mailbox_cb.h b/chromium/media/gpu/windows/output_with_release_mailbox_cb.h index 9fcfcb509e2..feb4c396933 100644 --- a/chromium/media/gpu/windows/output_with_release_mailbox_cb.h +++ b/chromium/media/gpu/windows/output_with_release_mailbox_cb.h @@ -1,4 +1,4 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. +// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/supported_profile_helpers.cc b/chromium/media/gpu/windows/supported_profile_helpers.cc index 47cbb84d13f..a95e4b778e5 100644 --- a/chromium/media/gpu/windows/supported_profile_helpers.cc +++ b/chromium/media/gpu/windows/supported_profile_helpers.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/supported_profile_helpers.h b/chromium/media/gpu/windows/supported_profile_helpers.h index e99379be3f0..2dd3f019f38 100644 --- a/chromium/media/gpu/windows/supported_profile_helpers.h +++ b/chromium/media/gpu/windows/supported_profile_helpers.h @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/media/gpu/windows/supported_profile_helpers_unittest.cc b/chromium/media/gpu/windows/supported_profile_helpers_unittest.cc index 87adc2cdcbb..e127d6785ff 100644 --- a/chromium/media/gpu/windows/supported_profile_helpers_unittest.cc +++ b/chromium/media/gpu/windows/supported_profile_helpers_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. +// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -332,19 +332,8 @@ TEST_F(SupportedResolutionResolverTest, AV1ProfileProSupports8k) { #if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER) TEST_F(SupportedResolutionResolverTest, H265Supports8kIfEnabled) { DONT_RUN_ON_WIN_7(); - EnableDecoders({D3D11_DECODER_PROFILE_HEVC_VLD_MAIN}); - base::test::ScopedFeatureList scoped_feature_list; - - // Test the supported resolutions before enabling the feature: - const auto no_feature_resolutions = GetSupportedD3D11VideoDecoderResolutions( - mock_d3d11_device_, gpu_workarounds_); - // Should only have the three h264 default resolutions. - ASSERT_EQ(3u, no_feature_resolutions.size()); - - // enable the feature and try again SetMaxResolution(D3D11_DECODER_PROFILE_HEVC_VLD_MAIN, kSquare8k); - scoped_feature_list.InitAndEnableFeature(kPlatformHEVCDecoderSupport); const auto resolutions_for_feature = GetSupportedD3D11VideoDecoderResolutions( mock_d3d11_device_, gpu_workarounds_); ASSERT_EQ(4u, resolutions_for_feature.size()); |