mirror of
https://github.com/nxp-imx/meta-imx.git
synced 2025-07-19 18:39:09 +02:00

- support on i.MX 8 series platform. - 8MM/8MP/8MQ support h264/hevc/vp8/vp9 hardware decoding. - 8QM/8QXP support h264/hevc/vp8 hardware decoding. - support seek, playrate change and resolution change. - support video acceleration for online media platform such as Youtube, bilibili. Signed-off-by: Hou Qi <qi.hou@nxp.com>
321 lines
12 KiB
Diff
321 lines
12 KiB
Diff
From fdc95ddfab945de74fe6b0b196df9a6394013243 Mon Sep 17 00:00:00 2001
|
|
From: Hou Qi <qi.hou@nxp.com>
|
|
Date: Fri, 2 Sep 2022 13:18:34 +0800
|
|
Subject: [PATCH 03/17] V4L2VDA: Add macro use_linux_v4l2
|
|
|
|
Upstream-Status: Inappropriate [NXP specific]
|
|
---
|
|
.../gpu_mjpeg_decode_accelerator_factory.cc | 3 +-
|
|
media/gpu/BUILD.gn | 1 +
|
|
media/gpu/args.gni | 4 +++
|
|
.../gpu_video_decode_accelerator_factory.cc | 8 ++++++
|
|
.../gpu_video_decode_accelerator_factory.h | 2 ++
|
|
media/gpu/v4l2/BUILD.gn | 22 +++++++++------
|
|
media/gpu/v4l2/generic_v4l2_device.cc | 4 +++
|
|
media/gpu/v4l2/v4l2_device.cc | 28 +++++++++++++++++++
|
|
media/gpu/v4l2/v4l2_video_decoder.cc | 6 ++++
|
|
9 files changed, 69 insertions(+), 9 deletions(-)
|
|
|
|
diff --git a/components/chromeos_camera/gpu_mjpeg_decode_accelerator_factory.cc b/components/chromeos_camera/gpu_mjpeg_decode_accelerator_factory.cc
|
|
index 3772b8ef048a2..dece6b77f6a23 100644
|
|
--- a/components/chromeos_camera/gpu_mjpeg_decode_accelerator_factory.cc
|
|
+++ b/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/media/gpu/BUILD.gn b/media/gpu/BUILD.gn
|
|
index 78d151fa630d2..101e2e4f9411e 100644
|
|
--- a/media/gpu/BUILD.gn
|
|
+++ b/media/gpu/BUILD.gn
|
|
@@ -20,6 +20,7 @@ buildflag_header("buildflags") {
|
|
"USE_VAAPI_IMAGE_CODECS=$use_vaapi_image_codecs",
|
|
"USE_V4L2_CODEC=$use_v4l2_codec",
|
|
"USE_LIBV4L2=$use_v4lplugin",
|
|
+ "USE_LINUX_V4L2=$use_linux_v4l2_only",
|
|
"USE_VAAPI_X11=$use_vaapi_x11",
|
|
]
|
|
}
|
|
diff --git a/media/gpu/args.gni b/media/gpu/args.gni
|
|
index bb2ff0797e031..da20cff798728 100644
|
|
--- a/media/gpu/args.gni
|
|
+++ b/media/gpu/args.gni
|
|
@@ -21,6 +21,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/media/gpu/gpu_video_decode_accelerator_factory.cc b/media/gpu/gpu_video_decode_accelerator_factory.cc
|
|
index 6687b11865f07..9514786384aa7 100644
|
|
--- a/media/gpu/gpu_video_decode_accelerator_factory.cc
|
|
+++ b/media/gpu/gpu_video_decode_accelerator_factory.cc
|
|
@@ -29,7 +29,9 @@
|
|
#include "ui/gl/gl_implementation.h"
|
|
#elif 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
|
|
@@ -64,10 +66,12 @@ gpu::VideoDecodeAcceleratorCapabilities GetDecoderCapabilitiesInternal(
|
|
GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(
|
|
V4L2VideoDecodeAccelerator::GetSupportedProfiles(),
|
|
&capabilities.supported_profiles);
|
|
+#if !BUILDFLAG(USE_LINUX_V4L2)
|
|
GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(
|
|
V4L2SliceVideoDecodeAccelerator::GetSupportedProfiles(),
|
|
&capabilities.supported_profiles);
|
|
#endif
|
|
+#endif
|
|
#elif BUILDFLAG(IS_MAC)
|
|
capabilities.supported_profiles =
|
|
VTVideoDecodeAccelerator::GetSupportedProfiles(workarounds);
|
|
@@ -146,8 +150,10 @@ GpuVideoDecodeAcceleratorFactory::CreateVDA(
|
|
&GpuVideoDecodeAcceleratorFactory::CreateVaapiVDA,
|
|
#elif BUILDFLAG(USE_V4L2_CODEC)
|
|
&GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA,
|
|
+#if !BUILDFLAG(USE_LINUX_V4L2)
|
|
&GpuVideoDecodeAcceleratorFactory::CreateV4L2SliceVDA,
|
|
#endif
|
|
+#endif
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
|
&GpuVideoDecodeAcceleratorFactory::CreateVTVDA,
|
|
@@ -207,6 +213,7 @@ GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA(
|
|
return decoder;
|
|
}
|
|
|
|
+#if !BUILDFLAG(USE_LINUX_V4L2)
|
|
std::unique_ptr<VideoDecodeAccelerator>
|
|
GpuVideoDecodeAcceleratorFactory::CreateV4L2SliceVDA(
|
|
const gpu::GpuDriverBugWorkarounds& /*workarounds*/,
|
|
@@ -222,6 +229,7 @@ GpuVideoDecodeAcceleratorFactory::CreateV4L2SliceVDA(
|
|
return decoder;
|
|
}
|
|
#endif
|
|
+#endif
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
|
std::unique_ptr<VideoDecodeAccelerator>
|
|
diff --git a/media/gpu/gpu_video_decode_accelerator_factory.h b/media/gpu/gpu_video_decode_accelerator_factory.h
|
|
index b2e1390c5f02d..5a714eb801d04 100644
|
|
--- a/media/gpu/gpu_video_decode_accelerator_factory.h
|
|
+++ b/media/gpu/gpu_video_decode_accelerator_factory.h
|
|
@@ -104,11 +104,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> CreateV4L2SliceVDA(
|
|
const gpu::GpuDriverBugWorkarounds& workarounds,
|
|
const gpu::GpuPreferences& gpu_preferences,
|
|
MediaLog* media_log) const;
|
|
#endif
|
|
+#endif
|
|
#if BUILDFLAG(IS_MAC)
|
|
std::unique_ptr<VideoDecodeAccelerator> CreateVTVDA(
|
|
const gpu::GpuDriverBugWorkarounds& workarounds,
|
|
diff --git a/media/gpu/v4l2/BUILD.gn b/media/gpu/v4l2/BUILD.gn
|
|
index 65e5f58d1efef..ebd0a4ad64646 100644
|
|
--- a/media/gpu/v4l2/BUILD.gn
|
|
+++ b/media/gpu/v4l2/BUILD.gn
|
|
@@ -28,9 +28,6 @@ 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",
|
|
@@ -39,8 +36,6 @@ source_set("v4l2") {
|
|
"v4l2_framerate_control.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_status.h",
|
|
@@ -56,8 +51,19 @@ source_set("v4l2") {
|
|
"v4l2_video_decoder_backend.h",
|
|
"v4l2_video_decoder_backend_stateful.cc",
|
|
"v4l2_video_decoder_backend_stateful.h",
|
|
+ "v4l2_video_encode_accelerator.cc",
|
|
+ "v4l2_video_encode_accelerator.h",
|
|
+ ]
|
|
+
|
|
+ if (!use_linux_v4l2_only) {
|
|
+ sources += [
|
|
+ "v4l2_decode_surface.cc",
|
|
+ "v4l2_decode_surface.h",
|
|
+ "v4l2_decode_surface_handler.h",
|
|
"v4l2_video_decoder_backend_stateless.cc",
|
|
"v4l2_video_decoder_backend_stateless.h",
|
|
+ "v4l2_slice_video_decode_accelerator.cc",
|
|
+ "v4l2_slice_video_decode_accelerator.h",
|
|
"v4l2_video_decoder_delegate_h264.cc",
|
|
"v4l2_video_decoder_delegate_h264.h",
|
|
"v4l2_video_decoder_delegate_h264_legacy.cc",
|
|
@@ -72,9 +78,9 @@ source_set("v4l2") {
|
|
"v4l2_video_decoder_delegate_vp9_chromium.h",
|
|
"v4l2_video_decoder_delegate_vp9_legacy.cc",
|
|
"v4l2_video_decoder_delegate_vp9_legacy.h",
|
|
- "v4l2_video_encode_accelerator.cc",
|
|
- "v4l2_video_encode_accelerator.h",
|
|
- ]
|
|
+ ]
|
|
+ }
|
|
+
|
|
|
|
libs = [
|
|
"EGL",
|
|
diff --git a/media/gpu/v4l2/generic_v4l2_device.cc b/media/gpu/v4l2/generic_v4l2_device.cc
|
|
index c1fccf3e2e813..319357922c901 100644
|
|
--- a/media/gpu/v4l2/generic_v4l2_device.cc
|
|
+++ b/media/gpu/v4l2/generic_v4l2_device.cc
|
|
@@ -440,7 +440,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/media/gpu/v4l2/v4l2_device.cc b/media/gpu/v4l2/v4l2_device.cc
|
|
index de2800fdab395..722ddbd68cb2b 100644
|
|
--- a/media/gpu/v4l2/v4l2_device.cc
|
|
+++ b/media/gpu/v4l2/v4l2_device.cc
|
|
@@ -853,7 +853,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,
|
|
@@ -1539,6 +1541,25 @@ std::string V4L2Device::GetDriverName() {
|
|
// static
|
|
uint32_t V4L2Device::VideoCodecProfileToV4L2PixFmt(VideoCodecProfile profile,
|
|
bool slice_based) {
|
|
+#if BUILDFLAG(USE_LINUX_V4L2)
|
|
+ if (slice_based) {
|
|
+ LOG(ERROR) << "Unsupported slice";
|
|
+ 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 if (profile == HEVCPROFILE_MAIN) {
|
|
+ return V4L2_PIX_FMT_HEVC;
|
|
+ } else {
|
|
+ DVLOGF(1) << "Unsupported profile: " << GetProfileName(profile);
|
|
+ return 0;
|
|
+ }
|
|
+#else
|
|
if (profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX) {
|
|
if (slice_based)
|
|
return V4L2_PIX_FMT_H264_SLICE;
|
|
@@ -1558,6 +1579,7 @@ uint32_t V4L2Device::VideoCodecProfileToV4L2PixFmt(VideoCodecProfile profile,
|
|
DVLOGF(1) << "Unsupported profile: " << GetProfileName(profile);
|
|
return 0;
|
|
}
|
|
+#endif
|
|
}
|
|
|
|
namespace {
|
|
@@ -1652,7 +1674,9 @@ std::vector<VideoCodecProfile> V4L2Device::V4L2PixFmtToVideoCodecProfiles(
|
|
std::vector<VideoCodecProfile> profiles;
|
|
switch (pix_fmt) {
|
|
case V4L2_PIX_FMT_H264:
|
|
+#if !BUILDFLAG(USE_LINUX_V4L2)
|
|
case V4L2_PIX_FMT_H264_SLICE:
|
|
+#endif
|
|
if (!get_supported_profiles(VideoCodec::kH264, &profiles)) {
|
|
DLOG(WARNING) << "Driver doesn't support QUERY H264 profiles, "
|
|
<< "use default values, Base, Main, High";
|
|
@@ -1664,11 +1688,15 @@ std::vector<VideoCodecProfile> V4L2Device::V4L2PixFmtToVideoCodecProfiles(
|
|
}
|
|
break;
|
|
case V4L2_PIX_FMT_VP8:
|
|
+#if !BUILDFLAG(USE_LINUX_V4L2)
|
|
case V4L2_PIX_FMT_VP8_FRAME:
|
|
+#endif
|
|
profiles = {VP8PROFILE_ANY};
|
|
break;
|
|
case V4L2_PIX_FMT_VP9:
|
|
+#if !BUILDFLAG(USE_LINUX_V4L2)
|
|
case V4L2_PIX_FMT_VP9_FRAME:
|
|
+#endif
|
|
if (!get_supported_profiles(VideoCodec::kVP9, &profiles)) {
|
|
DLOG(WARNING) << "Driver doesn't support QUERY VP9 profiles, "
|
|
<< "use default values, Profile0";
|
|
diff --git a/media/gpu/v4l2/v4l2_video_decoder.cc b/media/gpu/v4l2/v4l2_video_decoder.cc
|
|
index 057b28663b15b..691908a3ba8ed 100644
|
|
--- a/media/gpu/v4l2/v4l2_video_decoder.cc
|
|
+++ b/media/gpu/v4l2/v4l2_video_decoder.cc
|
|
@@ -28,7 +28,9 @@
|
|
#include "media/gpu/macros.h"
|
|
#include "media/gpu/v4l2/v4l2_status.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 {
|
|
|
|
@@ -46,7 +48,9 @@ constexpr size_t kNumInputBuffers = 8;
|
|
|
|
// 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,
|
|
};
|
|
|
|
@@ -320,6 +324,7 @@ V4L2Status V4L2VideoDecoder::InitializeBackend() {
|
|
<< " and fourcc: " << FourccToString(input_format_fourcc);
|
|
backend_ = std::make_unique<V4L2StatefulVideoDecoderBackend>(
|
|
this, device_, profile_, color_space_, decoder_task_runner_);
|
|
+#if !BUILDFLAG(USE_LINUX_V4L2)
|
|
} else {
|
|
DCHECK_EQ(preferred_api_and_format.first, kStateless);
|
|
VLOGF(1) << "Using a stateless API for profile: "
|
|
@@ -327,6 +332,7 @@ V4L2Status V4L2VideoDecoder::InitializeBackend() {
|
|
<< " and fourcc: " << FourccToString(input_format_fourcc);
|
|
backend_ = std::make_unique<V4L2StatelessVideoDecoderBackend>(
|
|
this, device_, profile_, color_space_, decoder_task_runner_);
|
|
+#endif
|
|
}
|
|
|
|
if (!backend_->Initialize()) {
|
|
--
|
|
2.17.1
|
|
|