From 6c9c8d3b84f3e0786b543b334a3dbae16d7becf1 Mon Sep 17 00:00:00 2001 From: Alexander David Frick Date: Fri, 10 Jun 2022 03:59:01 -0700 Subject: [PATCH] Update vaapi_wrapper.cc --- media/gpu/vaapi/vaapi_wrapper.cc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/media/gpu/vaapi/vaapi_wrapper.cc b/media/gpu/vaapi/vaapi_wrapper.cc index db37b824..290c03aa 100644 --- a/media/gpu/vaapi/vaapi_wrapper.cc +++ b/media/gpu/vaapi/vaapi_wrapper.cc @@ -42,6 +42,7 @@ #include "build/build_config.h" #include "build/chromeos_buildflags.h" #include "media/base/media_switches.h" +#include "media/base/video_codecs.h" #include "media/base/video_frame.h" #include "media/base/video_types.h" #include "media/gpu/macros.h" @@ -481,6 +482,17 @@ bool IsVAProfileSupported(VAProfile va_profile) { }) != profiles.end(); } +bool IsImplementedVbr(VideoCodecProfile codec_profile) { + switch (codec_profile) { + case H264PROFILE_BASELINE: + case H264PROFILE_MAIN: + case H264PROFILE_HIGH: + return true; + default: + return false; + } +} + bool IsBlockedDriver(VaapiWrapper::CodecMode mode, VAProfile va_profile) { if (!IsModeEncoding(mode)) { return va_profile == VAProfileAV1Profile0 && @@ -1524,12 +1536,7 @@ std::vector VaapiWrapper::GetSupportedScalabilityModes( } if (media_profile >= H264PROFILE_MIN && media_profile <= H264PROFILE_MAX) { - // TODO(b/199487660): Enable H.264 temporal layer encoding on AMD once their - // drivers support them. - VAImplementation implementation = VaapiWrapper::GetImplementationType(); - if (base::FeatureList::IsEnabled(kVaapiH264TemporalLayerHWEncoding) && - (implementation == VAImplementation::kIntelI965 || - implementation == VAImplementation::kIntelIHD)) { + if (base::FeatureList::IsEnabled(kVaapiH264TemporalLayerHWEncoding)) { scalability_modes.push_back(SVCScalabilityMode::kL1T2); scalability_modes.push_back(SVCScalabilityMode::kL1T3); } @@ -1561,8 +1568,15 @@ VaapiWrapper::GetSupportedEncodeProfiles() { constexpr int kMaxEncoderFramerate = 30; profile.max_framerate_numerator = kMaxEncoderFramerate; profile.max_framerate_denominator = 1; - // TODO(b/193680666): remove hard-coding when VBR is supported profile.rate_control_modes = media::VideoEncodeAccelerator::kConstantMode; + // This code assumes that the resolutions are the same between CBR and VBR. + // This is checked in a test in vaapi_unittest.cc: VbrAndCbrResolutionsMatch + if (IsImplementedVbr(media_profile) && + VASupportedProfiles::Get().IsProfileSupported(kEncodeVariableBitrate, + va_profile)) { + profile.rate_control_modes |= + media::VideoEncodeAccelerator::kVariableMode; + } profile.scalability_modes = GetSupportedScalabilityModes(media_profile, va_profile); profiles.push_back(profile);