1From e42483f06ae602945631ff8fc6bd370590f8e015 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Mon, 13 Feb 2023 15:50:20 +0800
4Subject: [PATCH 17/18] media: Support AV1 in V4L2 VDA
5
6Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
7---
8 media/gpu/v4l2/v4l2_device.cc                         | 9 +++++++++
9 media/gpu/v4l2/v4l2_vda_helpers.cc                    | 3 +++
10 media/gpu/v4l2/v4l2_video_decode_accelerator.cc       | 2 +-
11 media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc | 1 +
12 4 files changed, 14 insertions(+), 1 deletion(-)
13
14diff --git a/media/gpu/v4l2/v4l2_device.cc b/media/gpu/v4l2/v4l2_device.cc
15index fc719957d..18d5d1a4c 100644
16--- a/media/gpu/v4l2/v4l2_device.cc
17+++ b/media/gpu/v4l2/v4l2_device.cc
18@@ -1584,6 +1584,8 @@ uint32_t V4L2Device::VideoCodecProfileToV4L2PixFmt(VideoCodecProfile profile,
19     return V4L2_PIX_FMT_VP8;
20   } else if (profile >= VP9PROFILE_MIN && profile <= VP9PROFILE_MAX) {
21     return V4L2_PIX_FMT_VP9;
22+  } else if (profile >= AV1PROFILE_MIN && profile <= AV1PROFILE_MAX) {
23+    return V4L2_PIX_FMT_AV1;
24   } else {
25     DVLOGF(1) << "Unsupported profile: " << GetProfileName(profile);
26     return 0;
27@@ -1812,6 +1814,13 @@ std::vector<VideoCodecProfile> V4L2Device::V4L2PixFmtToVideoCodecProfiles(
28     case V4L2_PIX_FMT_VP9:
29       profiles = {VP9PROFILE_PROFILE0};
30       break;
31+    case V4L2_PIX_FMT_AV1:
32+      profiles = {
33+          AV1PROFILE_PROFILE_MAIN,
34+          AV1PROFILE_PROFILE_HIGH,
35+          AV1PROFILE_PROFILE_PRO,
36+      };
37+      break;
38     default:
39       VLOGF(1) << "Unhandled pixelformat " << FourccToString(pix_fmt);
40       return {};
41diff --git a/media/gpu/v4l2/v4l2_vda_helpers.cc b/media/gpu/v4l2/v4l2_vda_helpers.cc
42index 1fda578eb..1233b1355 100644
43--- a/media/gpu/v4l2/v4l2_vda_helpers.cc
44+++ b/media/gpu/v4l2/v4l2_vda_helpers.cc
45@@ -162,6 +162,9 @@ InputBufferFragmentSplitter::CreateFromProfile(
46     case VideoCodec::kVP9:
47       // VP8/VP9 don't need any frame splitting, use the default implementation.
48       return std::make_unique<v4l2_vda_helpers::InputBufferFragmentSplitter>();
49+    case VideoCodec::kAV1:
50+      // Depends on downstream frame splitting, use the default implementation.
51+      return std::make_unique<v4l2_vda_helpers::InputBufferFragmentSplitter>();
52     default:
53       LOG(ERROR) << "Unhandled profile: " << profile;
54       return nullptr;
55diff --git a/media/gpu/v4l2/v4l2_video_decode_accelerator.cc b/media/gpu/v4l2/v4l2_video_decode_accelerator.cc
56index 539908bf4..d67fdbaad 100644
57--- a/media/gpu/v4l2/v4l2_video_decode_accelerator.cc
58+++ b/media/gpu/v4l2/v4l2_video_decode_accelerator.cc
59@@ -86,7 +86,7 @@ bool IsVp9KSVCStream(uint32_t input_format_fourcc,
60
61 // static
62 const uint32_t V4L2VideoDecodeAccelerator::supported_input_fourccs_[] = {
63-    V4L2_PIX_FMT_H264, V4L2_PIX_FMT_HEVC, V4L2_PIX_FMT_VP8, V4L2_PIX_FMT_VP9,
64+    V4L2_PIX_FMT_H264, V4L2_PIX_FMT_HEVC, V4L2_PIX_FMT_VP8, V4L2_PIX_FMT_VP9, V4L2_PIX_FMT_AV1,
65 };
66
67 // static
68diff --git a/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc b/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc
69index 22b99e4d2..9d5fa1f91 100644
70--- a/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc
71+++ b/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc
72@@ -776,6 +776,7 @@ bool V4L2StatefulVideoDecoderBackend::IsSupportedProfile(
73 #endif  // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
74       V4L2_PIX_FMT_VP8,
75       V4L2_PIX_FMT_VP9,
76+      V4L2_PIX_FMT_AV1,
77     };
78     scoped_refptr<V4L2Device> device = V4L2Device::Create();
79     VideoDecodeAccelerator::SupportedProfiles profiles =
80--
812.20.1
82
83