Index: media/gpu/vaapi_wrapper.cc |
diff --git a/content/common/gpu/media/vaapi_wrapper.cc b/media/gpu/vaapi_wrapper.cc |
similarity index 87% |
rename from content/common/gpu/media/vaapi_wrapper.cc |
rename to media/gpu/vaapi_wrapper.cc |
index ab4e176e4ec0e869448e192728bcce4a80257d46..c40f8bcf3cee9e8751dbd8c48856f78cca255db2 100644 |
--- a/content/common/gpu/media/vaapi_wrapper.cc |
+++ b/media/gpu/vaapi_wrapper.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "content/common/gpu/media/vaapi_wrapper.h" |
+#include "media/gpu/vaapi_wrapper.h" |
#include <dlfcn.h> |
#include <string.h> |
@@ -14,11 +14,14 @@ |
#include "base/numerics/safe_conversions.h" |
#include "base/sys_info.h" |
#include "build/build_config.h" |
+ |
// Auto-generated for dlopen libva libraries |
-#include "content/common/gpu/media/va_stubs.h" |
-#include "content/common/gpu/media/vaapi_picture.h" |
+#include "media/gpu/va_stubs.h" |
+ |
+#include "media/gpu/vaapi_picture.h" |
#include "third_party/libyuv/include/libyuv.h" |
#include "ui/gl/gl_bindings.h" |
+ |
#if defined(USE_X11) |
#include "ui/gfx/x/x11_types.h" |
#elif defined(USE_OZONE) |
@@ -28,34 +31,33 @@ |
#include "ui/ozone/public/surface_factory_ozone.h" |
#endif // USE_X11 |
-using content_common_gpu_media::kModuleVa; |
+using media_gpu::kModuleVa; |
#if defined(USE_X11) |
-using content_common_gpu_media::kModuleVa_x11; |
+using media_gpu::kModuleVa_x11; |
#elif defined(USE_OZONE) |
-using content_common_gpu_media::kModuleVa_drm; |
+using media_gpu::kModuleVa_drm; |
#endif // USE_X11 |
-using content_common_gpu_media::InitializeStubs; |
-using content_common_gpu_media::StubPathMap; |
- |
-#define LOG_VA_ERROR_AND_REPORT(va_error, err_msg) \ |
- do { \ |
- LOG(ERROR) << err_msg \ |
- << " VA error: " << vaErrorStr(va_error); \ |
- report_error_to_uma_cb_.Run(); \ |
+using media_gpu::InitializeStubs; |
+using media_gpu::StubPathMap; |
+ |
+#define LOG_VA_ERROR_AND_REPORT(va_error, err_msg) \ |
+ do { \ |
+ LOG(ERROR) << err_msg << " VA error: " << vaErrorStr(va_error); \ |
+ report_error_to_uma_cb_.Run(); \ |
} while (0) |
-#define VA_LOG_ON_ERROR(va_error, err_msg) \ |
- do { \ |
- if ((va_error) != VA_STATUS_SUCCESS) \ |
- LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ |
+#define VA_LOG_ON_ERROR(va_error, err_msg) \ |
+ do { \ |
+ if ((va_error) != VA_STATUS_SUCCESS) \ |
+ LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ |
} while (0) |
-#define VA_SUCCESS_OR_RETURN(va_error, err_msg, ret) \ |
- do { \ |
- if ((va_error) != VA_STATUS_SUCCESS) { \ |
- LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ |
- return (ret); \ |
- } \ |
+#define VA_SUCCESS_OR_RETURN(va_error, err_msg, ret) \ |
+ do { \ |
+ if ((va_error) != VA_STATUS_SUCCESS) { \ |
+ LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ |
+ return (ret); \ |
+ } \ |
} while (0) |
#if defined(USE_OZONE) |
@@ -88,7 +90,7 @@ uint32_t BufferFormatToVARTFormat(gfx::BufferFormat fmt) { |
} // namespace |
#endif |
-namespace content { |
+namespace media { |
// Maximum framerate of encoded profile. This value is an arbitary limit |
// and not taken from HW documentation. |
@@ -134,13 +136,11 @@ static std::vector<VAConfigAttrib> GetRequiredAttribs( |
VaapiWrapper::CodecMode mode) { |
std::vector<VAConfigAttrib> required_attribs; |
required_attribs.insert( |
- required_attribs.end(), |
- kCommonVAConfigAttribs, |
+ required_attribs.end(), kCommonVAConfigAttribs, |
kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs)); |
if (mode == VaapiWrapper::kEncode) { |
required_attribs.insert( |
- required_attribs.end(), |
- kEncodeVAConfigAttribs, |
+ required_attribs.end(), kEncodeVAConfigAttribs, |
kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs)); |
} |
return required_attribs; |
@@ -270,7 +270,7 @@ bool VaapiWrapper::IsJpegDecodeSupported() { |
void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { |
base::AutoLock auto_lock(*va_lock_); |
VADisplayAttribute item = {VADisplayAttribRenderMode, |
- 1, // At least support '_LOCAL_OVERLAY'. |
+ 1, // At least support '_LOCAL_OVERLAY'. |
-1, // The maximum possible support 'ALL'. |
VA_RENDER_MODE_LOCAL_GPU, |
VA_DISPLAY_ATTRIB_SETTABLE}; |
@@ -281,8 +281,8 @@ void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { |
} |
// static |
-VAProfile VaapiWrapper::ProfileToVAProfile( |
- media::VideoCodecProfile profile, CodecMode mode) { |
+VAProfile VaapiWrapper::ProfileToVAProfile(media::VideoCodecProfile profile, |
+ CodecMode mode) { |
VAProfile va_profile = VAProfileNone; |
for (size_t i = 0; i < arraysize(kProfileMap); ++i) { |
if (kProfileMap[i].profile == profile) { |
@@ -298,7 +298,7 @@ VAProfile VaapiWrapper::ProfileToVAProfile( |
// 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( |
- mode, VAProfileH264ConstrainedBaseline)) { |
+ mode, VAProfileH264ConstrainedBaseline)) { |
va_profile = VAProfileH264ConstrainedBaseline; |
DVLOG(1) << "Fall back to constrained baseline profile."; |
} |
@@ -315,7 +315,7 @@ VaapiWrapper::GetSupportedProfileInfosForCodecModeInternal(CodecMode mode) { |
std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); |
VAEntrypoint entrypoint = |
- (mode == kEncode ? VAEntrypointEncSlice: VAEntrypointVLD); |
+ (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); |
base::AutoLock auto_lock(*va_lock_); |
for (const auto& va_profile : va_profiles) { |
@@ -324,9 +324,7 @@ VaapiWrapper::GetSupportedProfileInfosForCodecModeInternal(CodecMode mode) { |
if (!AreAttribsSupported_Locked(va_profile, entrypoint, required_attribs)) |
continue; |
ProfileInfo profile_info; |
- if (!GetMaxResolution_Locked(va_profile, |
- entrypoint, |
- required_attribs, |
+ if (!GetMaxResolution_Locked(va_profile, entrypoint, required_attribs, |
&profile_info.max_resolution)) { |
LOG(ERROR) << "GetMaxResolution failed for va_profile " << va_profile |
<< " and entrypoint " << entrypoint; |
@@ -380,8 +378,8 @@ bool VaapiWrapper::GetSupportedVaProfiles(std::vector<VAProfile>* profiles) { |
base::checked_cast<size_t>(max_profiles)); |
int num_supported_profiles; |
- VAStatus va_res = vaQueryConfigProfiles( |
- va_display_, &supported_profiles[0], &num_supported_profiles); |
+ VAStatus va_res = vaQueryConfigProfiles(va_display_, &supported_profiles[0], |
+ &num_supported_profiles); |
VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigProfiles failed", false); |
if (num_supported_profiles < 0 || num_supported_profiles > max_profiles) { |
LOG(ERROR) << "vaQueryConfigProfiles returned: " << num_supported_profiles; |
@@ -402,8 +400,7 @@ bool VaapiWrapper::IsEntrypointSupported_Locked(VAProfile va_profile, |
base::checked_cast<size_t>(max_entrypoints)); |
int num_supported_entrypoints; |
- VAStatus va_res = vaQueryConfigEntrypoints(va_display_, |
- va_profile, |
+ VAStatus va_res = vaQueryConfigEntrypoints(va_display_, va_profile, |
&supported_entrypoints[0], |
&num_supported_entrypoints); |
VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigEntrypoints failed", false); |
@@ -414,8 +411,7 @@ bool VaapiWrapper::IsEntrypointSupported_Locked(VAProfile va_profile, |
return false; |
} |
- if (std::find(supported_entrypoints.begin(), |
- supported_entrypoints.end(), |
+ if (std::find(supported_entrypoints.begin(), supported_entrypoints.end(), |
entrypoint) == supported_entrypoints.end()) { |
DVLOG(1) << "Unsupported entrypoint"; |
return false; |
@@ -433,8 +429,8 @@ bool VaapiWrapper::AreAttribsSupported_Locked( |
for (size_t i = 0; i < required_attribs.size(); ++i) |
attribs[i].value = 0; |
- VAStatus va_res = vaGetConfigAttributes( |
- va_display_, va_profile, entrypoint, &attribs[0], attribs.size()); |
+ VAStatus va_res = vaGetConfigAttributes(va_display_, va_profile, entrypoint, |
+ &attribs[0], attribs.size()); |
VA_SUCCESS_OR_RETURN(va_res, "vaGetConfigAttributes failed", false); |
for (size_t i = 0; i < required_attribs.size(); ++i) { |
@@ -456,21 +452,17 @@ bool VaapiWrapper::GetMaxResolution_Locked( |
gfx::Size* resolution) { |
va_lock_->AssertAcquired(); |
VAConfigID va_config_id; |
- VAStatus va_res = vaCreateConfig( |
- va_display_, |
- va_profile, |
- entrypoint, |
- &required_attribs[0], |
- required_attribs.size(), |
- &va_config_id); |
+ VAStatus va_res = |
+ vaCreateConfig(va_display_, va_profile, entrypoint, &required_attribs[0], |
+ required_attribs.size(), &va_config_id); |
VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); |
// Calls vaQuerySurfaceAttributes twice. The first time is to get the number |
// of attributes to prepare the space and the second time is to get all |
// attributes. |
unsigned int num_attribs; |
- va_res = vaQuerySurfaceAttributes( |
- va_display_, va_config_id, nullptr, &num_attribs); |
+ va_res = vaQuerySurfaceAttributes(va_display_, va_config_id, nullptr, |
+ &num_attribs); |
VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false); |
if (!num_attribs) |
return false; |
@@ -478,8 +470,8 @@ bool VaapiWrapper::GetMaxResolution_Locked( |
std::vector<VASurfaceAttrib> attrib_list( |
base::checked_cast<size_t>(num_attribs)); |
- va_res = vaQuerySurfaceAttributes( |
- va_display_, va_config_id, &attrib_list[0], &num_attribs); |
+ va_res = vaQuerySurfaceAttributes(va_display_, va_config_id, &attrib_list[0], |
+ &num_attribs); |
VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false); |
resolution->SetSize(0, 0); |
@@ -501,15 +493,12 @@ bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) { |
TryToSetVADisplayAttributeToLocalGPU(); |
VAEntrypoint entrypoint = |
- (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); |
+ (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); |
std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); |
base::AutoLock auto_lock(*va_lock_); |
- VAStatus va_res = vaCreateConfig(va_display_, |
- va_profile, |
- entrypoint, |
- &required_attribs[0], |
- required_attribs.size(), |
- &va_config_id_); |
+ VAStatus va_res = |
+ vaCreateConfig(va_display_, va_profile, entrypoint, &required_attribs[0], |
+ required_attribs.size(), &va_config_id_); |
VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); |
return true; |
@@ -558,10 +547,9 @@ bool VaapiWrapper::CreateSurfaces(unsigned int va_format, |
} |
// And create a context associated with them. |
- va_res = vaCreateContext(va_display_, va_config_id_, |
- size.width(), size.height(), VA_PROGRESSIVE, |
- &va_surface_ids_[0], va_surface_ids_.size(), |
- &va_context_id_); |
+ va_res = vaCreateContext(va_display_, va_config_id_, size.width(), |
+ size.height(), VA_PROGRESSIVE, &va_surface_ids_[0], |
+ va_surface_ids_.size(), &va_context_id_); |
VA_LOG_ON_ERROR(va_res, "vaCreateContext failed"); |
if (va_res != VA_STATUS_SUCCESS) { |
@@ -576,7 +564,7 @@ bool VaapiWrapper::CreateSurfaces(unsigned int va_format, |
void VaapiWrapper::DestroySurfaces() { |
base::AutoLock auto_lock(*va_lock_); |
- DVLOG(2) << "Destroying " << va_surface_ids_.size() << " surfaces"; |
+ DVLOG(2) << "Destroying " << va_surface_ids_.size() << " surfaces"; |
if (va_context_id_ != VA_INVALID_ID) { |
VAStatus va_res = vaDestroyContext(va_display_, va_context_id_); |
@@ -711,9 +699,8 @@ bool VaapiWrapper::SubmitBuffer(VABufferType va_buffer_type, |
base::AutoLock auto_lock(*va_lock_); |
VABufferID buffer_id; |
- VAStatus va_res = vaCreateBuffer(va_display_, va_context_id_, |
- va_buffer_type, size, |
- 1, buffer, &buffer_id); |
+ VAStatus va_res = vaCreateBuffer(va_display_, va_context_id_, va_buffer_type, |
+ size, 1, buffer, &buffer_id); |
VA_SUCCESS_OR_RETURN(va_res, "Failed to create a VA buffer", false); |
switch (va_buffer_type) { |
@@ -738,13 +725,9 @@ bool VaapiWrapper::SubmitVAEncMiscParamBuffer( |
base::AutoLock auto_lock(*va_lock_); |
VABufferID buffer_id; |
- VAStatus va_res = vaCreateBuffer(va_display_, |
- va_context_id_, |
- VAEncMiscParameterBufferType, |
- sizeof(VAEncMiscParameterBuffer) + size, |
- 1, |
- NULL, |
- &buffer_id); |
+ VAStatus va_res = vaCreateBuffer( |
+ va_display_, va_context_id_, VAEncMiscParameterBufferType, |
+ sizeof(VAEncMiscParameterBuffer) + size, 1, NULL, &buffer_id); |
VA_SUCCESS_OR_RETURN(va_res, "Failed to create a VA buffer", false); |
void* data_ptr = NULL; |
@@ -787,13 +770,9 @@ void VaapiWrapper::DestroyPendingBuffers() { |
bool VaapiWrapper::CreateCodedBuffer(size_t size, VABufferID* buffer_id) { |
base::AutoLock auto_lock(*va_lock_); |
- VAStatus va_res = vaCreateBuffer(va_display_, |
- va_context_id_, |
- VAEncCodedBufferType, |
- size, |
- 1, |
- NULL, |
- buffer_id); |
+ VAStatus va_res = |
+ vaCreateBuffer(va_display_, va_context_id_, VAEncCodedBufferType, size, 1, |
+ NULL, buffer_id); |
VA_SUCCESS_OR_RETURN(va_res, "Failed to create a coded buffer", false); |
const auto is_new_entry = coded_buffers_.insert(*buffer_id).second; |
@@ -805,8 +784,7 @@ void VaapiWrapper::DestroyCodedBuffers() { |
base::AutoLock auto_lock(*va_lock_); |
for (std::set<VABufferID>::const_iterator iter = coded_buffers_.begin(); |
- iter != coded_buffers_.end(); |
- ++iter) { |
+ iter != coded_buffers_.end(); ++iter) { |
VAStatus va_res = vaDestroyBuffer(va_display_, *iter); |
VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); |
} |
@@ -822,24 +800,20 @@ bool VaapiWrapper::Execute(VASurfaceID va_surface_id) { |
DVLOG(4) << "Target VA surface " << va_surface_id; |
// Get ready to execute for given surface. |
- VAStatus va_res = vaBeginPicture(va_display_, va_context_id_, |
- va_surface_id); |
+ VAStatus va_res = vaBeginPicture(va_display_, va_context_id_, va_surface_id); |
VA_SUCCESS_OR_RETURN(va_res, "vaBeginPicture failed", false); |
if (pending_va_bufs_.size() > 0) { |
// Commit parameter and slice buffers. |
- va_res = vaRenderPicture(va_display_, |
- va_context_id_, |
- &pending_va_bufs_[0], |
+ va_res = vaRenderPicture(va_display_, va_context_id_, &pending_va_bufs_[0], |
pending_va_bufs_.size()); |
VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for va_bufs failed", false); |
} |
if (pending_slice_bufs_.size() > 0) { |
- va_res = vaRenderPicture(va_display_, |
- va_context_id_, |
- &pending_slice_bufs_[0], |
- pending_slice_bufs_.size()); |
+ va_res = |
+ vaRenderPicture(va_display_, va_context_id_, &pending_slice_bufs_[0], |
+ pending_slice_bufs_.size()); |
VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for slices failed", false); |
} |
@@ -867,12 +841,9 @@ bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); |
// Put the data into an X Pixmap. |
- va_res = vaPutSurface(va_display_, |
- va_surface_id, |
- x_pixmap, |
- 0, 0, dest_size.width(), dest_size.height(), |
- 0, 0, dest_size.width(), dest_size.height(), |
- NULL, 0, 0); |
+ va_res = vaPutSurface(va_display_, va_surface_id, x_pixmap, 0, 0, |
+ dest_size.width(), dest_size.height(), 0, 0, |
+ dest_size.width(), dest_size.height(), NULL, 0, 0); |
VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false); |
return true; |
} |
@@ -1010,8 +981,8 @@ bool VaapiWrapper::DownloadAndDestroyCodedBuffer(VABufferID buffer_id, |
VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); |
VACodedBufferSegment* buffer_segment = NULL; |
- va_res = vaMapBuffer( |
- va_display_, buffer_id, reinterpret_cast<void**>(&buffer_segment)); |
+ va_res = vaMapBuffer(va_display_, buffer_id, |
+ reinterpret_cast<void**>(&buffer_segment)); |
VA_SUCCESS_OR_RETURN(va_res, "vaMapBuffer failed", false); |
DCHECK(target_ptr); |
@@ -1184,8 +1155,7 @@ VaapiWrapper::LazyProfileInfos::LazyProfileInfos() { |
} |
} |
-VaapiWrapper::LazyProfileInfos::~LazyProfileInfos() { |
-} |
+VaapiWrapper::LazyProfileInfos::~LazyProfileInfos() {} |
std::vector<VaapiWrapper::ProfileInfo> |
VaapiWrapper::LazyProfileInfos::GetSupportedProfileInfosForCodecMode( |
@@ -1193,8 +1163,8 @@ VaapiWrapper::LazyProfileInfos::GetSupportedProfileInfosForCodecMode( |
return supported_profiles_[mode]; |
} |
-bool VaapiWrapper::LazyProfileInfos::IsProfileSupported( |
- CodecMode mode, VAProfile va_profile) { |
+bool VaapiWrapper::LazyProfileInfos::IsProfileSupported(CodecMode mode, |
+ VAProfile va_profile) { |
for (const auto& profile : supported_profiles_[mode]) { |
if (profile.va_profile == va_profile) |
return true; |
@@ -1268,7 +1238,7 @@ void VaapiWrapper::VADisplayState::SetDrmFd(base::PlatformFile fd) { |
bool VaapiWrapper::VADisplayState::VAAPIVersionLessThan(int major, int minor) { |
return (major_version_ < major) || |
- (major_version_ == major && minor_version_ < minor); |
+ (major_version_ == major && minor_version_ < minor); |
} |
-} // namespace content |
+} // namespace media |