HYL_OK3568_LINUX/buildroot/package/qt5/qt5webengine-chromium/0004-Add-support-for-V4L2VDA-on-Linux.patch
2025-05-10 21:49:39 +08:00

471 lines
16 KiB
Diff

From be3074eaa6255f8579e6830f22d78a405207e4c2 Mon Sep 17 00:00:00 2001
From: Maksim Sisov <msisov@igalia.com>
Date: Wed, 31 Jul 2019 09:56:24 +0300
Subject: [PATCH 04/14] Add support for V4L2VDA on Linux
This patch enables hardware assisted video decoding via the
Chromium V4L2VDA. Including changes when Linux is used. In
order to use this, use_linux_v4l2_only flag should be set
to true.
Signed-off-by: Ryo Kodama <ryo.kodama.vz@renesas.com>
fixup! avoid building not declared formats
"FRAME", "_SLICE", "V4L2_PIX_FMT_VP9" are not defined in mainline
Linux headers. This patch avoids building these formats.
Signed-off-by: Ryo Kodama <ryo.kodama.vz@renesas.com>
fixup! add V4L2_PIX_FMT_VP9 support back again as it is now
included in mainline Linux kernel. This allows VP9 codec
to work with upstream kernel and v4l2 vda. Tested on db820c
with Venus v4l2 driver.
Signed-off-by: Peter Griffin <peter.griffin@linaro.org>
Signed-off-by: Stanimir Varbanov <stanimir.varbanov@linaro.org>
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
.../gpu_mjpeg_decode_accelerator_factory.cc | 3 +-
chromium/media/gpu/BUILD.gn | 1 +
chromium/media/gpu/args.gni | 4 ++
.../gpu_video_decode_accelerator_factory.cc | 8 +++
.../gpu_video_decode_accelerator_factory.h | 2 +
chromium/media/gpu/v4l2/BUILD.gn | 39 +++++-----
.../media/gpu/v4l2/generic_v4l2_device.cc | 4 ++
chromium/media/gpu/v4l2/v4l2_device.cc | 72 +++++++++++++++++++
chromium/media/gpu/v4l2/v4l2_video_decoder.cc | 7 ++
9 files changed, 122 insertions(+), 18 deletions(-)
diff --git a/chromium/components/chromeos_camera/gpu_mjpeg_decode_accelerator_factory.cc b/chromium/components/chromeos_camera/gpu_mjpeg_decode_accelerator_factory.cc
index 6f319e889..4f8f0b7d0 100644
--- a/chromium/components/chromeos_camera/gpu_mjpeg_decode_accelerator_factory.cc
+++ b/chromium/components/chromeos_camera/gpu_mjpeg_decode_accelerator_factory.cc
@@ -13,7 +13,8 @@
#include "media/base/media_switches.h"
#include "media/gpu/buildflags.h"
-#if BUILDFLAG(USE_V4L2_CODEC) && defined(ARCH_CPU_ARM_FAMILY)
+#if BUILDFLAG(USE_V4L2_CODEC) && defined(ARCH_CPU_ARM_FAMILY) && \
+ !BUILDFLAG(USE_LINUX_V4L2)
#define USE_V4L2_MJPEG_DECODE_ACCELERATOR
#endif
diff --git a/chromium/media/gpu/BUILD.gn b/chromium/media/gpu/BUILD.gn
index b1a84b1ad..1edccb7ab 100644
--- a/chromium/media/gpu/BUILD.gn
+++ b/chromium/media/gpu/BUILD.gn
@@ -18,6 +18,7 @@ buildflag_header("buildflags") {
"USE_VAAPI=$use_vaapi",
"USE_V4L2_CODEC=$use_v4l2_codec",
"USE_LIBV4L2=$use_v4lplugin",
+ "USE_LINUX_V4L2=$use_linux_v4l2_only",
]
}
diff --git a/chromium/media/gpu/args.gni b/chromium/media/gpu/args.gni
index 2a87b9980..7e905aebb 100644
--- a/chromium/media/gpu/args.gni
+++ b/chromium/media/gpu/args.gni
@@ -10,6 +10,10 @@ declare_args() {
# platforms which have v4l2 hardware encoder / decoder.
use_v4l2_codec = false
+ # Indicates that only definitions available in the mainline linux kernel
+ # will be used.
+ use_linux_v4l2_only = false
+
# Indicates if Video4Linux2 AML encoder is used. This is used for AML
# platforms which have v4l2 hardware encoder
use_v4l2_codec_aml = false
diff --git a/chromium/media/gpu/gpu_video_decode_accelerator_factory.cc b/chromium/media/gpu/gpu_video_decode_accelerator_factory.cc
index a24ee0fe3..b085ebbbe 100644
--- a/chromium/media/gpu/gpu_video_decode_accelerator_factory.cc
+++ b/chromium/media/gpu/gpu_video_decode_accelerator_factory.cc
@@ -26,7 +26,9 @@
#endif
#if BUILDFLAG(USE_V4L2_CODEC)
#include "media/gpu/v4l2/v4l2_device.h"
+#if !BUILDFLAG(USE_LINUX_V4L2)
#include "media/gpu/v4l2/v4l2_slice_video_decode_accelerator.h"
+#endif
#include "media/gpu/v4l2/v4l2_video_decode_accelerator.h"
#include "ui/gl/gl_surface_egl.h"
#endif
@@ -63,10 +65,12 @@ gpu::VideoDecodeAcceleratorCapabilities GetDecoderCapabilitiesInternal(
vda_profiles = V4L2VideoDecodeAccelerator::GetSupportedProfiles();
GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(
vda_profiles, &capabilities.supported_profiles);
+#if !BUILDFLAG(USE_LINUX_V4L2)
vda_profiles = V4L2SliceVideoDecodeAccelerator::GetSupportedProfiles();
GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(
vda_profiles, &capabilities.supported_profiles);
#endif
+#endif
#if BUILDFLAG(USE_VAAPI)
vda_profiles = VaapiVideoDecodeAccelerator::GetSupportedProfiles(workarounds);
GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(
@@ -147,8 +151,10 @@ GpuVideoDecodeAcceleratorFactory::CreateVDA(
#endif
#if BUILDFLAG(USE_V4L2_CODEC)
&GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA,
+#if !BUILDFLAG(USE_LINUX_V4L2)
&GpuVideoDecodeAcceleratorFactory::CreateV4L2SVDA,
#endif
+#endif
#if defined(OS_MAC)
&GpuVideoDecodeAcceleratorFactory::CreateVTVDA,
#endif
@@ -196,6 +202,7 @@ GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA(
return decoder;
}
+#if !BUILDFLAG(USE_LINUX_V4L2)
std::unique_ptr<VideoDecodeAccelerator>
GpuVideoDecodeAcceleratorFactory::CreateV4L2SVDA(
const gpu::GpuDriverBugWorkarounds& workarounds,
@@ -211,6 +218,7 @@ GpuVideoDecodeAcceleratorFactory::CreateV4L2SVDA(
return decoder;
}
#endif
+#endif
#if BUILDFLAG(USE_VAAPI)
std::unique_ptr<VideoDecodeAccelerator>
diff --git a/chromium/media/gpu/gpu_video_decode_accelerator_factory.h b/chromium/media/gpu/gpu_video_decode_accelerator_factory.h
index b2721b7d1..613906486 100644
--- a/chromium/media/gpu/gpu_video_decode_accelerator_factory.h
+++ b/chromium/media/gpu/gpu_video_decode_accelerator_factory.h
@@ -92,11 +92,13 @@ class MEDIA_GPU_EXPORT GpuVideoDecodeAcceleratorFactory {
const gpu::GpuDriverBugWorkarounds& workarounds,
const gpu::GpuPreferences& gpu_preferences,
MediaLog* media_log) const;
+#if !BUILDFLAG(USE_LINUX_V4L2)
std::unique_ptr<VideoDecodeAccelerator> CreateV4L2SVDA(
const gpu::GpuDriverBugWorkarounds& workarounds,
const gpu::GpuPreferences& gpu_preferences,
MediaLog* media_log) const;
#endif
+#endif
#if BUILDFLAG(USE_VAAPI)
std::unique_ptr<VideoDecodeAccelerator> CreateVaapiVDA(
const gpu::GpuDriverBugWorkarounds& workarounds,
diff --git a/chromium/media/gpu/v4l2/BUILD.gn b/chromium/media/gpu/v4l2/BUILD.gn
index 9a999e43a..9cf40f5c5 100644
--- a/chromium/media/gpu/v4l2/BUILD.gn
+++ b/chromium/media/gpu/v4l2/BUILD.gn
@@ -27,21 +27,12 @@ source_set("v4l2") {
"buffer_affinity_tracker.h",
"generic_v4l2_device.cc",
"generic_v4l2_device.h",
- "v4l2_decode_surface.cc",
- "v4l2_decode_surface.h",
- "v4l2_decode_surface_handler.h",
"v4l2_device.cc",
"v4l2_device.h",
"v4l2_device_poller.cc",
"v4l2_device_poller.h",
- "v4l2_h264_accelerator.cc",
- "v4l2_h264_accelerator.h",
- "v4l2_h264_accelerator_legacy.cc",
- "v4l2_h264_accelerator_legacy.h",
"v4l2_image_processor_backend.cc",
"v4l2_image_processor_backend.h",
- "v4l2_slice_video_decode_accelerator.cc",
- "v4l2_slice_video_decode_accelerator.h",
"v4l2_stateful_workaround.cc",
"v4l2_stateful_workaround.h",
"v4l2_vda_helpers.cc",
@@ -54,18 +45,32 @@ source_set("v4l2") {
"v4l2_video_decoder_backend.h",
"v4l2_video_decoder_backend_stateful.cc",
"v4l2_video_decoder_backend_stateful.h",
- "v4l2_video_decoder_backend_stateless.cc",
- "v4l2_video_decoder_backend_stateless.h",
"v4l2_video_encode_accelerator.cc",
"v4l2_video_encode_accelerator.h",
- "v4l2_vp8_accelerator.cc",
- "v4l2_vp8_accelerator.h",
- "v4l2_vp8_accelerator_legacy.cc",
- "v4l2_vp8_accelerator_legacy.h",
- "v4l2_vp9_accelerator_legacy.cc",
- "v4l2_vp9_accelerator_legacy.h",
]
+ if (!use_linux_v4l2_only) {
+ sources += [
+ "v4l2_decode_surface.cc",
+ "v4l2_decode_surface.h",
+ "v4l2_decode_surface_handler.h",
+ "v4l2_h264_accelerator.cc",
+ "v4l2_h264_accelerator.h",
+ "v4l2_h264_accelerator_legacy.cc",
+ "v4l2_h264_accelerator_legacy.h",
+ "v4l2_slice_video_decode_accelerator.cc",
+ "v4l2_slice_video_decode_accelerator.h",
+ "v4l2_video_decoder_backend_stateless.cc",
+ "v4l2_video_decoder_backend_stateless.h",
+ "v4l2_vp8_accelerator.cc",
+ "v4l2_vp8_accelerator.h",
+ "v4l2_vp8_accelerator_legacy.cc",
+ "v4l2_vp8_accelerator_legacy.h",
+ "v4l2_vp9_accelerator_legacy.cc",
+ "v4l2_vp9_accelerator_legacy.h",
+ ]
+ }
+
libs = [
"EGL",
"GLESv2",
diff --git a/chromium/media/gpu/v4l2/generic_v4l2_device.cc b/chromium/media/gpu/v4l2/generic_v4l2_device.cc
index 6742dc14c..f0f103458 100644
--- a/chromium/media/gpu/v4l2/generic_v4l2_device.cc
+++ b/chromium/media/gpu/v4l2/generic_v4l2_device.cc
@@ -415,7 +415,11 @@ bool GenericV4L2Device::OpenDevicePath(const std::string& path, Type type) {
return false;
#if BUILDFLAG(USE_LIBV4L2)
+#if BUILDFLAG(USE_LINUX_V4L2)
+ if (
+#else
if (type == Type::kEncoder &&
+#endif
HANDLE_EINTR(v4l2_fd_open(device_fd_.get(), V4L2_DISABLE_CONVERSION)) !=
-1) {
DVLOGF(3) << "Using libv4l2 for " << path;
diff --git a/chromium/media/gpu/v4l2/v4l2_device.cc b/chromium/media/gpu/v4l2/v4l2_device.cc
index 9dd1c87aa..f9cc4fbb4 100644
--- a/chromium/media/gpu/v4l2/v4l2_device.cc
+++ b/chromium/media/gpu/v4l2/v4l2_device.cc
@@ -784,7 +784,9 @@ void V4L2WritableBufferRef::SetConfigStore(uint32_t config_store) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(buffer_data_);
+#if !BUILDFLAG(USE_LINUX_V4L2)
buffer_data_->v4l2_buffer_.config_store = config_store;
+#endif
}
V4L2ReadableBuffer::V4L2ReadableBuffer(const struct v4l2_buffer& v4l2_buffer,
@@ -927,10 +929,12 @@ V4L2Queue::V4L2Queue(scoped_refptr<V4L2Device> dev,
return;
}
+#if !BUILDFLAG(USE_LINUX_V4L2)
if (reqbufs.capabilities & V4L2_BUF_CAP_SUPPORTS_REQUESTS) {
supports_requests_ = true;
DVLOGF(4) << "Queue supports request API.";
}
+#endif
}
V4L2Queue::~V4L2Queue() {
@@ -1465,6 +1469,23 @@ scoped_refptr<V4L2Device> V4L2Device::Create() {
// static
uint32_t V4L2Device::VideoCodecProfileToV4L2PixFmt(VideoCodecProfile profile,
bool slice_based) {
+#if BUILDFLAG(USE_LINUX_V4L2)
+ if (slice_based) {
+ LOG(ERROR) << "Slice not supported";
+ return 0;
+ }
+
+ if (profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX) {
+ return V4L2_PIX_FMT_H264;
+ } else if (profile >= VP8PROFILE_MIN && profile <= VP8PROFILE_MAX) {
+ return V4L2_PIX_FMT_VP8;
+ } else if (profile >= VP9PROFILE_MIN && profile <= VP9PROFILE_MAX) {
+ return V4L2_PIX_FMT_VP9;
+ } else {
+ LOG(ERROR) << "Unknown profile: " << GetProfileName(profile);
+ return 0;
+ }
+#else
if (profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX) {
if (slice_based)
return V4L2_PIX_FMT_H264_SLICE;
@@ -1484,8 +1505,10 @@ uint32_t V4L2Device::VideoCodecProfileToV4L2PixFmt(VideoCodecProfile profile,
LOG(ERROR) << "Unknown profile: " << GetProfileName(profile);
return 0;
}
+#endif
}
+#if !BUILDFLAG(USE_LINUX_V4L2)
// static
VideoCodecProfile V4L2Device::V4L2ProfileToVideoCodecProfile(VideoCodec codec,
uint32_t profile) {
@@ -1534,10 +1557,12 @@ VideoCodecProfile V4L2Device::V4L2ProfileToVideoCodecProfile(VideoCodec codec,
VLOGF(2) << "Unknown profile: " << profile;
return VIDEO_CODEC_PROFILE_UNKNOWN;
}
+#endif
std::vector<VideoCodecProfile> V4L2Device::V4L2PixFmtToVideoCodecProfiles(
uint32_t pix_fmt,
bool is_encoder) {
+#if !BUILDFLAG(USE_LINUX_V4L2)
auto get_supported_profiles = [this](
VideoCodec codec,
std::vector<VideoCodecProfile>* profiles) {
@@ -1608,6 +1633,27 @@ std::vector<VideoCodecProfile> V4L2Device::V4L2PixFmtToVideoCodecProfiles(
VLOGF(1) << "Unhandled pixelformat " << FourccToString(pix_fmt);
return {};
}
+#else
+ std::vector<VideoCodecProfile> profiles;
+ switch (pix_fmt) {
+ case V4L2_PIX_FMT_H264:
+ profiles = {
+ H264PROFILE_BASELINE,
+ H264PROFILE_MAIN,
+ H264PROFILE_HIGH,
+ };
+ break;
+ case V4L2_PIX_FMT_VP8:
+ profiles = {VP8PROFILE_ANY};
+ break;
+ case V4L2_PIX_FMT_VP9:
+ profiles = {VP9PROFILE_PROFILE0};
+ break;
+ default:
+ VLOGF(1) << "Unhandled pixelformat " << FourccToString(pix_fmt);
+ return {};
+ }
+#endif
// Erase duplicated profiles.
std::sort(profiles.begin(), profiles.end());
@@ -1632,6 +1678,12 @@ uint32_t V4L2Device::V4L2PixFmtToDrmFormat(uint32_t format) {
case V4L2_PIX_FMT_RGB32:
return DRM_FORMAT_ARGB8888;
+#if !BUILDFLAG(USE_LINUX_V4L2)
+ case V4L2_PIX_FMT_MT21C:
+ case V4L2_PIX_FMT_MT21:
+ return DRM_FORMAT_MT21;
+#endif
+
default:
DVLOGF(1) << "Unrecognized format " << FourccToString(format);
return 0;
@@ -2311,10 +2363,14 @@ bool V4L2Request::ApplyCtrls(struct v4l2_ext_controls* ctrls) {
return false;
}
+#if !BUILDFLAG(USE_LINUX_V4L2)
ctrls->which = V4L2_CTRL_WHICH_REQUEST_VAL;
ctrls->request_fd = request_fd_.get();
return true;
+#else
+ return false;
+#endif
}
bool V4L2Request::ApplyQueueBuffer(struct v4l2_buffer* buffer) {
@@ -2326,10 +2382,14 @@ bool V4L2Request::ApplyQueueBuffer(struct v4l2_buffer* buffer) {
return false;
}
+#if !BUILDFLAG(USE_LINUX_V4L2)
buffer->flags |= V4L2_BUF_FLAG_REQUEST_FD;
buffer->request_fd = request_fd_.get();
return true;
+#else
+ return false;
+#endif
}
bool V4L2Request::Submit() {
@@ -2340,7 +2400,11 @@ bool V4L2Request::Submit() {
return false;
}
+#if !BUILDFLAG(USE_LINUX_V4L2)
return HANDLE_EINTR(ioctl(request_fd_.get(), MEDIA_REQUEST_IOC_QUEUE)) == 0;
+#else
+ return false;
+#endif
}
bool V4L2Request::IsCompleted() {
@@ -2383,6 +2447,7 @@ bool V4L2Request::Reset() {
return false;
}
+#if !BUILDFLAG(USE_LINUX_V4L2)
// Reinit the request to make sure we can use it for a new submission.
if (HANDLE_EINTR(ioctl(request_fd_.get(), MEDIA_REQUEST_IOC_REINIT)) < 0) {
VPLOGF(1) << "Failed to reinit request.";
@@ -2390,6 +2455,9 @@ bool V4L2Request::Reset() {
}
return true;
+#else
+ return false;
+#endif
}
V4L2RequestRefBase::V4L2RequestRefBase(V4L2RequestRefBase&& req_base) {
@@ -2464,6 +2532,7 @@ V4L2RequestsQueue::~V4L2RequestsQueue() {
base::Optional<base::ScopedFD> V4L2RequestsQueue::CreateRequestFD() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+#if !BUILDFLAG(USE_LINUX_V4L2)
int request_fd;
int ret = HANDLE_EINTR(
ioctl(media_fd_.get(), MEDIA_IOC_REQUEST_ALLOC, &request_fd));
@@ -2473,6 +2542,9 @@ base::Optional<base::ScopedFD> V4L2RequestsQueue::CreateRequestFD() {
}
return base::ScopedFD(request_fd);
+#else
+ return base::nullopt;
+#endif
}
base::Optional<V4L2RequestRef> V4L2RequestsQueue::GetFreeRequest() {
diff --git a/chromium/media/gpu/v4l2/v4l2_video_decoder.cc b/chromium/media/gpu/v4l2/v4l2_video_decoder.cc
index c0963ed40..5b3dd3af2 100644
--- a/chromium/media/gpu/v4l2/v4l2_video_decoder.cc
+++ b/chromium/media/gpu/v4l2/v4l2_video_decoder.cc
@@ -19,7 +19,10 @@
#include "media/gpu/gpu_video_decode_accelerator_helpers.h"
#include "media/gpu/macros.h"
#include "media/gpu/v4l2/v4l2_video_decoder_backend_stateful.h"
+
+#if !BUILDFLAG(USE_LINUX_V4L2)
#include "media/gpu/v4l2/v4l2_video_decoder_backend_stateless.h"
+#endif
namespace media {
@@ -35,7 +38,9 @@ constexpr size_t kNumInputBuffers = 16;
// Input format V4L2 fourccs this class supports.
constexpr uint32_t kSupportedInputFourccs[] = {
+#if !BUILDFLAG(USE_LINUX_V4L2)
V4L2_PIX_FMT_H264_SLICE, V4L2_PIX_FMT_VP8_FRAME, V4L2_PIX_FMT_VP9_FRAME,
+#endif
V4L2_PIX_FMT_H264, V4L2_PIX_FMT_VP8, V4L2_PIX_FMT_VP9,
};
@@ -204,10 +209,12 @@ void V4L2VideoDecoder::Initialize(const VideoDecoderConfig& config,
backend_ = std::make_unique<V4L2StatefulVideoDecoderBackend>(
this, device_, profile, decoder_task_runner_);
input_format_fourcc = input_format_fourcc_stateful;
+#if !BUILDFLAG(USE_LINUX_V4L2)
} else if (input_format_fourcc_stateless) {
backend_ = std::make_unique<V4L2StatelessVideoDecoderBackend>(
this, device_, profile, decoder_task_runner_);
input_format_fourcc = input_format_fourcc_stateless;
+#endif
} else {
VLOGF(1) << "No backend capable of taking this profile.";
std::move(init_cb).Run(StatusCode::kV4l2FailedResourceAllocation);
--
2.20.1