Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Unified Diff: media/gpu/vaapi_wrapper.cc

Issue 2668813002: Remove LazyInstance usage from media/ (Closed)
Patch Set: Comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/gpu/vaapi_wrapper.cc
diff --git a/media/gpu/vaapi_wrapper.cc b/media/gpu/vaapi_wrapper.cc
index dcec8b971480adef3841710a07c5ac1c528f1d76..5564806116d2fcb6c3e9e78aedfddabfe6dbf725 100644
--- a/media/gpu/vaapi_wrapper.cc
+++ b/media/gpu/vaapi_wrapper.cc
@@ -95,6 +95,16 @@ uint32_t BufferFormatToVARTFormat(gfx::BufferFormat fmt) {
}
}
+VADisplayState* GetDisplayState() {
+ static VADisplayState* display_state = new VADisplayState();
+ return display_state;
+}
+
+LazyProfileInfos* GetProfileInfos() {
+ static LazyProfileInfos* profile_infos = new LazyProfileInfos();
+ return profile_infos;
+}
+
} // namespace
#endif
@@ -104,12 +114,6 @@ namespace media {
// and not taken from HW documentation.
const int kMaxEncoderFramerate = 30;
-base::LazyInstance<VaapiWrapper::VADisplayState>
- VaapiWrapper::va_display_state_ = LAZY_INSTANCE_INITIALIZER;
-
-base::LazyInstance<VaapiWrapper::LazyProfileInfos>
- VaapiWrapper::profile_infos_ = LAZY_INSTANCE_INITIALIZER;
-
// Config attributes common for both encode and decode.
static const VAConfigAttrib kCommonVAConfigAttribs[] = {
{VAConfigAttribRTFormat, VA_RT_FORMAT_YUV420},
@@ -177,7 +181,7 @@ VaapiWrapper::VaapiWrapper()
va_vpp_config_id_(VA_INVALID_ID),
va_vpp_context_id_(VA_INVALID_ID),
va_vpp_buffer_id_(VA_INVALID_ID) {
- va_lock_ = va_display_state_.Get().va_lock();
+ va_lock_ = GetDisplayState()->va_lock();
Mark Mentovai 2017/01/31 22:16:00 For consistency, you can deal with this in the ini
}
VaapiWrapper::~VaapiWrapper() {
@@ -193,7 +197,7 @@ scoped_refptr<VaapiWrapper> VaapiWrapper::Create(
CodecMode mode,
VAProfile va_profile,
const base::Closure& report_error_to_uma_cb) {
- if (!profile_infos_.Get().IsProfileSupported(mode, va_profile)) {
+ if (!GetProfileInfos()->IsProfileSupported(mode, va_profile)) {
DVLOG(1) << "Unsupported va_profile: " << va_profile;
return nullptr;
}
@@ -223,7 +227,7 @@ VideoEncodeAccelerator::SupportedProfiles
VaapiWrapper::GetSupportedEncodeProfiles() {
VideoEncodeAccelerator::SupportedProfiles profiles;
std::vector<ProfileInfo> encode_profile_infos =
- profile_infos_.Get().GetSupportedProfileInfosForCodecMode(kEncode);
+ GetProfileInfos()->GetSupportedProfileInfosForCodecMode(kEncode);
for (size_t i = 0; i < arraysize(kProfileMap); ++i) {
VAProfile va_profile = ProfileToVAProfile(kProfileMap[i].profile, kEncode);
@@ -249,7 +253,7 @@ VideoDecodeAccelerator::SupportedProfiles
VaapiWrapper::GetSupportedDecodeProfiles() {
VideoDecodeAccelerator::SupportedProfiles profiles;
std::vector<ProfileInfo> decode_profile_infos =
- profile_infos_.Get().GetSupportedProfileInfosForCodecMode(kDecode);
+ GetProfileInfos()->GetSupportedProfileInfosForCodecMode(kDecode);
for (size_t i = 0; i < arraysize(kProfileMap); ++i) {
VAProfile va_profile = ProfileToVAProfile(kProfileMap[i].profile, kDecode);
@@ -271,8 +275,7 @@ VaapiWrapper::GetSupportedDecodeProfiles() {
// static
bool VaapiWrapper::IsJpegDecodeSupported() {
- return profile_infos_.Get().IsProfileSupported(kDecode,
- VAProfileJPEGBaseline);
+ return GetProfileInfos()->IsProfileSupported(kDecode, VAProfileJPEGBaseline);
}
void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() {
@@ -298,14 +301,14 @@ VAProfile VaapiWrapper::ProfileToVAProfile(VideoCodecProfile profile,
break;
}
}
- if (!profile_infos_.Get().IsProfileSupported(mode, va_profile) &&
+ if (!GetProfileInfos()->IsProfileSupported(mode, va_profile) &&
va_profile == VAProfileH264Baseline) {
// crbug.com/345569: ProfileIDToVideoCodecProfile() currently strips
// the information whether the profile is constrained or not, so we have no
// way to know here. Try for baseline first, but if it is not supported,
// try constrained baseline and hope this is what it actually is
// (which in practice is true for a great majority of cases).
- if (profile_infos_.Get().IsProfileSupported(
+ if (GetProfileInfos()->IsProfileSupported(
mode, VAProfileH264ConstrainedBaseline)) {
va_profile = VAProfileH264ConstrainedBaseline;
DVLOG(1) << "Fall back to constrained baseline profile.";
@@ -364,17 +367,10 @@ bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) {
report_error_to_uma_cb_ = report_error_to_uma_cb;
base::AutoLock auto_lock(*va_lock_);
-
- VADisplayState* va_display_state = &va_display_state_.Get();
- if (!va_display_state) {
- LOG(ERROR) << "Failed to allocate VA display state";
+ if (!GetDisplayState()->Initialize())
return false;
- }
- if (!va_display_state->Initialize())
- return false;
-
- va_display_ = va_display_state->va_display();
+ va_display_ = GetDisplayState()->va_display();
return true;
}
@@ -520,12 +516,9 @@ void VaapiWrapper::Deinitialize() {
VA_LOG_ON_ERROR(va_res, "vaDestroyConfig failed");
}
- VADisplayState* va_display_state = &va_display_state_.Get();
- if (va_display_state) {
- VAStatus va_res = VA_STATUS_SUCCESS;
- va_display_state->Deinitialize(&va_res);
- VA_LOG_ON_ERROR(va_res, "vaTerminate failed");
- }
+ VAStatus va_res = VA_STATUS_SUCCESS;
+ GetDisplayState()->Deinitialize(&va_res);
+ VA_LOG_ON_ERROR(va_res, "vaTerminate failed");
va_config_id_ = VA_INVALID_ID;
va_display_ = NULL;
@@ -1146,7 +1139,7 @@ void VaapiWrapper::PreSandboxInitialization() {
base::FilePath::FromUTF8Unsafe(kDriRenderNode0Path),
base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE);
if (drm_file.IsValid())
- va_display_state_.Get().SetDrmFd(drm_file.GetPlatformFile());
+ GetDisplayState()->SetDrmFd(drm_file.GetPlatformFile());
#endif
}

Powered by Google App Engine
This is Rietveld 408576698