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,8 +335,11 @@ bool ClearNV12Padding(const VAImage& image,
return true;
}
// Map of the supported VaProfiles indexed by media's VideoCodecProfile.
const std::map<VideoCodecProfile, VAProfile> kMediaToVAProfileMap = {
// Can't statically initialize the profile map:
// https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables
using ProfileCodecMap = std::map<VideoCodecProfile, VAProfile>;
const ProfileCodecMap& GetProfileCodecMap() {
static const base::NoDestructor<ProfileCodecMap> kMediaToVAProfileMap({
// VAProfileH264Baseline is deprecated in <va/va.h> since libva 2.0.0.
{H264PROFILE_BASELINE, VAProfileH264ConstrainedBaseline},
{H264PROFILE_MAIN, VAProfileH264Main},
......@@ -350,24 +353,28 @@ const std::map<VideoCodecProfile, VAProfile> kMediaToVAProfileMap = {
{VP9PROFILE_PROFILE2, VAProfileVP9Profile2},
// VaapiWrapper does not support Profile 3.
//{VP9PROFILE_PROFILE3, VAProfileVP9Profile3},
};
});
return *kMediaToVAProfileMap;
}
// Maps a VideoCodecProfile |profile| to a VAProfile, or VAProfileNone.
VAProfile ProfileToVAProfile(VideoCodecProfile profile,
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 kMediaToVAProfileMap.at(profile);
return maybe_profile->second;
}
// Returns true if |va_profile| is present in kMediaToVAProfileMap.
bool IsVAProfileSupported(VAProfile va_profile) {
// VAProfileJPEGBaseline is always recognized but is not a video codec per se.
const auto& profiles = GetProfileCodecMap();
return va_profile == VAProfileJPEGBaseline ||
std::find_if(kMediaToVAProfileMap.begin(), kMediaToVAProfileMap.end(),
std::find_if(profiles.begin(), profiles.end(),
[va_profile](const auto& entry) {
return entry.second == va_profile;
}) != kMediaToVAProfileMap.end();
}) != profiles.end();
}
bool IsBlockedDriver(VaapiWrapper::CodecMode mode, VAProfile va_profile) {
......@@ -1255,11 +1262,10 @@ VideoEncodeAccelerator::SupportedProfiles
VaapiWrapper::GetSupportedEncodeProfiles() {
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 VAProfile va_profile = ProfileToVAProfile(media_profile, kEncode);
if (va_profile == VAProfileNone)
continue;
const VAProfile va_profile = media_to_va_profile_map_entry.second;
DCHECK(va_profile != VAProfileNone);
const VASupportedProfiles::ProfileInfo* profile_info =
VASupportedProfiles::Get().IsProfileSupported(kEncode, va_profile);
......@@ -1289,18 +1295,16 @@ VaapiWrapper::GetSupportedDecodeProfiles(
const gpu::GpuDriverBugWorkarounds& workarounds) {
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 VAProfile va_profile = media_to_va_profile_map_entry.second;
DCHECK(va_profile != VAProfileNone);
if (media_profile == VP8PROFILE_ANY &&
workarounds.disable_accelerated_vp8_decode) {
continue;
}
const VAProfile va_profile = ProfileToVAProfile(media_profile, kDecode);
if (va_profile == VAProfileNone)
continue;
const VASupportedProfiles::ProfileInfo* profile_info =
VASupportedProfiles::Get().IsProfileSupported(kDecode, va_profile);
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