Commit e3728b23 authored by Ted Meyer's avatar Ted Meyer Committed by Commit Bot

Remove the static std::map initializer

Replace the static initializer with helper functions, so that we don't
have to modify testing/scripts/check_static_initializers.py when
building by default on linux.

Bug: 1066176
Change-Id: I1beb107cab47b5d7ece7b10ce5e41b8a407e080f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2425446
Commit-Queue: Ted Meyer <tmathmeyer@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810092}
parent f24b26ad
...@@ -335,39 +335,46 @@ bool ClearNV12Padding(const VAImage& image, ...@@ -335,39 +335,46 @@ bool ClearNV12Padding(const VAImage& image,
return true; return true;
} }
// Map of the supported VaProfiles indexed by media's VideoCodecProfile. // Can't statically initialize the profile map:
const std::map<VideoCodecProfile, VAProfile> kMediaToVAProfileMap = { // https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables
// VAProfileH264Baseline is deprecated in <va/va.h> since libva 2.0.0. using ProfileCodecMap = std::map<VideoCodecProfile, VAProfile>;
{H264PROFILE_BASELINE, VAProfileH264ConstrainedBaseline}, const ProfileCodecMap& GetProfileCodecMap() {
{H264PROFILE_MAIN, VAProfileH264Main}, static const base::NoDestructor<ProfileCodecMap> kMediaToVAProfileMap({
// TODO(posciak): See if we can/want to support other variants of // VAProfileH264Baseline is deprecated in <va/va.h> since libva 2.0.0.
// H264PROFILE_HIGH*. {H264PROFILE_BASELINE, VAProfileH264ConstrainedBaseline},
{H264PROFILE_HIGH, VAProfileH264High}, {H264PROFILE_MAIN, VAProfileH264Main},
{VP8PROFILE_ANY, VAProfileVP8Version0_3}, // TODO(posciak): See if we can/want to support other variants of
{VP9PROFILE_PROFILE0, VAProfileVP9Profile0}, // H264PROFILE_HIGH*.
// VaapiWrapper does not support VP9 Profile 1, see b/153680337. {H264PROFILE_HIGH, VAProfileH264High},
// {VP9PROFILE_PROFILE1, VAProfileVP9Profile1}, {VP8PROFILE_ANY, VAProfileVP8Version0_3},
{VP9PROFILE_PROFILE2, VAProfileVP9Profile2}, {VP9PROFILE_PROFILE0, VAProfileVP9Profile0},
// VaapiWrapper does not support Profile 3. // VaapiWrapper does not support VP9 Profile 1, see b/153680337.
//{VP9PROFILE_PROFILE3, VAProfileVP9Profile3}, // {VP9PROFILE_PROFILE1, VAProfileVP9Profile1},
}; {VP9PROFILE_PROFILE2, VAProfileVP9Profile2},
// VaapiWrapper does not support Profile 3.
//{VP9PROFILE_PROFILE3, VAProfileVP9Profile3},
});
return *kMediaToVAProfileMap;
}
// Maps a VideoCodecProfile |profile| to a VAProfile, or VAProfileNone. // Maps a VideoCodecProfile |profile| to a VAProfile, or VAProfileNone.
VAProfile ProfileToVAProfile(VideoCodecProfile profile, VAProfile ProfileToVAProfile(VideoCodecProfile profile,
VaapiWrapper::CodecMode mode) { VaapiWrapper::CodecMode mode) {
if (!base::Contains(kMediaToVAProfileMap, profile)) const auto& profiles = GetProfileCodecMap();
const auto& maybe_profile = profiles.find(profile);
if (maybe_profile == profiles.end())
return VAProfileNone; return VAProfileNone;
return kMediaToVAProfileMap.at(profile); return maybe_profile->second;
} }
// Returns true if |va_profile| is present in kMediaToVAProfileMap.
bool IsVAProfileSupported(VAProfile va_profile) { bool IsVAProfileSupported(VAProfile va_profile) {
// VAProfileJPEGBaseline is always recognized but is not a video codec per se. // VAProfileJPEGBaseline is always recognized but is not a video codec per se.
const auto& profiles = GetProfileCodecMap();
return va_profile == VAProfileJPEGBaseline || return va_profile == VAProfileJPEGBaseline ||
std::find_if(kMediaToVAProfileMap.begin(), kMediaToVAProfileMap.end(), std::find_if(profiles.begin(), profiles.end(),
[va_profile](const auto& entry) { [va_profile](const auto& entry) {
return entry.second == va_profile; return entry.second == va_profile;
}) != kMediaToVAProfileMap.end(); }) != profiles.end();
} }
bool IsBlockedDriver(VaapiWrapper::CodecMode mode, VAProfile va_profile) { bool IsBlockedDriver(VaapiWrapper::CodecMode mode, VAProfile va_profile) {
...@@ -1255,11 +1262,10 @@ VideoEncodeAccelerator::SupportedProfiles ...@@ -1255,11 +1262,10 @@ VideoEncodeAccelerator::SupportedProfiles
VaapiWrapper::GetSupportedEncodeProfiles() { VaapiWrapper::GetSupportedEncodeProfiles() {
VideoEncodeAccelerator::SupportedProfiles profiles; VideoEncodeAccelerator::SupportedProfiles profiles;
for (const auto& media_to_va_profile_map_entry : kMediaToVAProfileMap) { for (const auto& media_to_va_profile_map_entry : GetProfileCodecMap()) {
const VideoCodecProfile media_profile = media_to_va_profile_map_entry.first; const VideoCodecProfile media_profile = media_to_va_profile_map_entry.first;
const VAProfile va_profile = ProfileToVAProfile(media_profile, kEncode); const VAProfile va_profile = media_to_va_profile_map_entry.second;
if (va_profile == VAProfileNone) DCHECK(va_profile != VAProfileNone);
continue;
const VASupportedProfiles::ProfileInfo* profile_info = const VASupportedProfiles::ProfileInfo* profile_info =
VASupportedProfiles::Get().IsProfileSupported(kEncode, va_profile); VASupportedProfiles::Get().IsProfileSupported(kEncode, va_profile);
...@@ -1289,18 +1295,16 @@ VaapiWrapper::GetSupportedDecodeProfiles( ...@@ -1289,18 +1295,16 @@ VaapiWrapper::GetSupportedDecodeProfiles(
const gpu::GpuDriverBugWorkarounds& workarounds) { const gpu::GpuDriverBugWorkarounds& workarounds) {
VideoDecodeAccelerator::SupportedProfiles profiles; VideoDecodeAccelerator::SupportedProfiles profiles;
for (const auto& media_to_va_profile_map_entry : kMediaToVAProfileMap) { for (const auto& media_to_va_profile_map_entry : GetProfileCodecMap()) {
const VideoCodecProfile media_profile = media_to_va_profile_map_entry.first; const VideoCodecProfile media_profile = media_to_va_profile_map_entry.first;
const VAProfile va_profile = media_to_va_profile_map_entry.second;
DCHECK(va_profile != VAProfileNone);
if (media_profile == VP8PROFILE_ANY && if (media_profile == VP8PROFILE_ANY &&
workarounds.disable_accelerated_vp8_decode) { workarounds.disable_accelerated_vp8_decode) {
continue; continue;
} }
const VAProfile va_profile = ProfileToVAProfile(media_profile, kDecode);
if (va_profile == VAProfileNone)
continue;
const VASupportedProfiles::ProfileInfo* profile_info = const VASupportedProfiles::ProfileInfo* profile_info =
VASupportedProfiles::Get().IsProfileSupported(kDecode, va_profile); VASupportedProfiles::Get().IsProfileSupported(kDecode, va_profile);
if (!profile_info) if (!profile_info)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment