1From 5b94ed32a369c19d7069d1d1e897ca151cd27606 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Fri, 9 Sep 2022 16:06:58 +0800
4Subject: [PATCH 15/17] media: Enable HEVC by default for V4L2VDA
5
6Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
7---
8 media/base/media_switches.cc                          | 2 +-
9 media/gpu/v4l2/v4l2_device.cc                         | 9 +++++++++
10 media/gpu/v4l2/v4l2_vda_helpers.cc                    | 1 +
11 media/gpu/v4l2/v4l2_video_decode_accelerator.cc       | 2 +-
12 media/gpu/v4l2/v4l2_video_decoder.cc                  | 3 ++-
13 media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc | 1 +
14 media/media_options.gni                               | 2 +-
15 7 files changed, 16 insertions(+), 4 deletions(-)
16
17diff --git a/media/base/media_switches.cc b/media/base/media_switches.cc
18index 74b2379ff..880d284c7 100644
19--- a/media/base/media_switches.cc
20+++ b/media/base/media_switches.cc
21@@ -275,7 +275,7 @@ const base::Feature kPictureInPicture{"PictureInPicture",
22 #if BUILDFLAG(ENABLE_PLATFORM_HEVC)
23 // Enables HEVC hardware accelerated decoding.
24 const base::Feature kPlatformHEVCDecoderSupport{
25-    "PlatformHEVCDecoderSupport", base::FEATURE_DISABLED_BY_DEFAULT};
26+    "PlatformHEVCDecoderSupport", base::FEATURE_ENABLED_BY_DEFAULT};
27 #endif  // BUILDFLAG(ENABLE_PLATFORM_HEVC)
28
29 // Only decode preload=metadata elements upon visibility.
30diff --git a/media/gpu/v4l2/v4l2_device.cc b/media/gpu/v4l2/v4l2_device.cc
31index 3669f7176..ab227a954 100644
32--- a/media/gpu/v4l2/v4l2_device.cc
33+++ b/media/gpu/v4l2/v4l2_device.cc
34@@ -1567,6 +1567,8 @@ uint32_t V4L2Device::VideoCodecProfileToV4L2PixFmt(VideoCodecProfile profile,
35
36   if (profile >= H264PROFILE_MIN && profile <= H264PROFILE_MAX) {
37     return V4L2_PIX_FMT_H264;
38+  } else if (profile >= HEVCPROFILE_MIN && profile <= HEVCPROFILE_MAX) {
39+    return V4L2_PIX_FMT_HEVC;
40   } else if (profile >= VP8PROFILE_MIN && profile <= VP8PROFILE_MAX) {
41     return V4L2_PIX_FMT_VP8;
42   } else if (profile >= VP9PROFILE_MIN && profile <= VP9PROFILE_MAX) {
43@@ -1730,6 +1732,13 @@ std::vector<VideoCodecProfile> V4L2Device::V4L2PixFmtToVideoCodecProfiles(
44           H264PROFILE_HIGH,
45       };
46       break;
47+    case V4L2_PIX_FMT_HEVC:
48+      profiles = {
49+          HEVCPROFILE_MAIN,
50+          HEVCPROFILE_MAIN10,
51+          HEVCPROFILE_MAIN_STILL_PICTURE,
52+      };
53+      break;
54     case V4L2_PIX_FMT_VP8:
55       profiles = {VP8PROFILE_ANY};
56       break;
57diff --git a/media/gpu/v4l2/v4l2_vda_helpers.cc b/media/gpu/v4l2/v4l2_vda_helpers.cc
58index f25619077..e2cb051c5 100644
59--- a/media/gpu/v4l2/v4l2_vda_helpers.cc
60+++ b/media/gpu/v4l2/v4l2_vda_helpers.cc
61@@ -151,6 +151,7 @@ InputBufferFragmentSplitter::CreateFromProfile(
62     case VideoCodec::kH264:
63       return std::make_unique<
64           v4l2_vda_helpers::H264InputBufferFragmentSplitter>();
65+    case VideoCodec::kHEVC:
66     case VideoCodec::kVP8:
67     case VideoCodec::kVP9:
68       // VP8/VP9 don't need any frame splitting, use the default implementation.
69diff --git a/media/gpu/v4l2/v4l2_video_decode_accelerator.cc b/media/gpu/v4l2/v4l2_video_decode_accelerator.cc
70index c54c7356d..c1db336de 100644
71--- a/media/gpu/v4l2/v4l2_video_decode_accelerator.cc
72+++ b/media/gpu/v4l2/v4l2_video_decode_accelerator.cc
73@@ -86,7 +86,7 @@ bool IsVp9KSVCStream(uint32_t input_format_fourcc,
74
75 // static
76 const uint32_t V4L2VideoDecodeAccelerator::supported_input_fourccs_[] = {
77-    V4L2_PIX_FMT_H264, V4L2_PIX_FMT_VP8, V4L2_PIX_FMT_VP9,
78+    V4L2_PIX_FMT_H264, V4L2_PIX_FMT_HEVC, V4L2_PIX_FMT_VP8, V4L2_PIX_FMT_VP9,
79 };
80
81 // static
82diff --git a/media/gpu/v4l2/v4l2_video_decoder.cc b/media/gpu/v4l2/v4l2_video_decoder.cc
83index d7cda20b4..8d8487cfa 100644
84--- a/media/gpu/v4l2/v4l2_video_decoder.cc
85+++ b/media/gpu/v4l2/v4l2_video_decoder.cc
86@@ -52,7 +52,8 @@ constexpr uint32_t kSupportedInputFourccs[] = {
87 #if !BUILDFLAG(USE_LINUX_V4L2)
88     V4L2_PIX_FMT_H264_SLICE, V4L2_PIX_FMT_VP8_FRAME, V4L2_PIX_FMT_VP9_FRAME,
89 #endif
90-    V4L2_PIX_FMT_H264,       V4L2_PIX_FMT_VP8,       V4L2_PIX_FMT_VP9,
91+    V4L2_PIX_FMT_H264,      V4L2_PIX_FMT_HEVC,
92+    V4L2_PIX_FMT_VP8,       V4L2_PIX_FMT_VP9,
93 };
94
95 // Number of output buffers to use for each VD stage above what's required by
96diff --git a/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc b/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc
97index 87d4f153d..6ab11da86 100644
98--- a/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc
99+++ b/media/gpu/v4l2/v4l2_video_decoder_backend_stateful.cc
100@@ -731,6 +731,7 @@ bool V4L2StatefulVideoDecoderBackend::IsSupportedProfile(
101   if (supported_profiles_.empty()) {
102     constexpr uint32_t kSupportedInputFourccs[] = {
103         V4L2_PIX_FMT_H264,
104+        V4L2_PIX_FMT_HEVC,
105         V4L2_PIX_FMT_VP8,
106         V4L2_PIX_FMT_VP9,
107     };
108diff --git a/media/media_options.gni b/media/media_options.gni
109index 3349dda85..92d8c84ca 100644
110--- a/media/media_options.gni
111+++ b/media/media_options.gni
112@@ -99,7 +99,7 @@ declare_args() {
113   enable_hevc_parser_and_hw_decoder =
114       proprietary_codecs &&
115       (use_fuzzing_engine || use_chromeos_protected_media || is_win || is_mac ||
116-       is_android)
117+       is_android || is_linux)
118 }
119
120 # Use another declare_args() to allow dependence on
121--
1222.20.1
123
124