Commit a5e4fd56 authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

VaapiWrapper: homogenize logging macros and add success-logging

This CL modifies the VAAPI error-check and log macros to accept
just the name of the function, adding itself the "failed" suffix,
or prints out the function name if successful. This allows for
quick following up of the VA function interactions.  Callsites
are adapted. Same thing applies to VA_LOG_ON_ERROR() calls.

A singleton LOG_VA_ERROR_AND_REPORT+return is corrected to
VA_SUCCESS_OR_RETURN

I also took the chance to make VADisplayState::Deinitialize()
to return the VAStatus ISO filling an argument var.

Change-Id: Idcc24f3c09b79bc3f971ae8c3827aa07082261d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1967217
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726684}
parent 79cb81b6
...@@ -78,24 +78,26 @@ using media_gpu_vaapi::IsVa_x11Initialized; ...@@ -78,24 +78,26 @@ using media_gpu_vaapi::IsVa_x11Initialized;
using media_gpu_vaapi::IsVa_drmInitialized; using media_gpu_vaapi::IsVa_drmInitialized;
using media_gpu_vaapi::StubPathMap; using media_gpu_vaapi::StubPathMap;
#define LOG_VA_ERROR_AND_REPORT(va_error, err_msg) \ #define LOG_VA_ERROR_AND_REPORT(va_error, name) \
do { \ do { \
LOG(ERROR) << err_msg << " VA error: " << vaErrorStr(va_error); \ LOG(ERROR) << name << " failed, VA error: " << vaErrorStr(va_error); \
report_error_to_uma_cb_.Run(); \ report_error_to_uma_cb_.Run(); \
} while (0) } while (0)
#define VA_LOG_ON_ERROR(va_error, err_msg) \ #define VA_LOG_ON_ERROR(va_error, name) \
do { \ do { \
if ((va_error) != VA_STATUS_SUCCESS) \ if ((va_error) != VA_STATUS_SUCCESS) \
LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ LOG_VA_ERROR_AND_REPORT(va_error, name); \
} while (0) } while (0)
#define VA_SUCCESS_OR_RETURN(va_error, err_msg, ret) \ #define VA_SUCCESS_OR_RETURN(va_error, name, ret) \
do { \ do { \
if ((va_error) != VA_STATUS_SUCCESS) { \ if ((va_error) != VA_STATUS_SUCCESS) { \
LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ LOG_VA_ERROR_AND_REPORT(va_error, name); \
return (ret); \ return (ret); \
} \ } else { \
VLOG(1) << name; \
} \
} while (0) } while (0)
namespace { namespace {
...@@ -287,7 +289,7 @@ class VADisplayState { ...@@ -287,7 +289,7 @@ class VADisplayState {
static void PreSandboxInitialization(); static void PreSandboxInitialization();
bool Initialize(); bool Initialize();
void Deinitialize(VAStatus* status); VAStatus Deinitialize();
base::Lock* va_lock() { return &va_lock_; } base::Lock* va_lock() { return &va_lock_; }
VADisplay va_display() const { return va_display_; } VADisplay va_display() const { return va_display_; }
...@@ -442,11 +444,12 @@ bool VADisplayState::InitializeOnce() { ...@@ -442,11 +444,12 @@ bool VADisplayState::InitializeOnce() {
return true; return true;
} }
void VADisplayState::Deinitialize(VAStatus* status) { VAStatus VADisplayState::Deinitialize() {
base::AutoLock auto_lock(va_lock_); base::AutoLock auto_lock(va_lock_);
VAStatus va_res = VA_STATUS_SUCCESS;
if (--refcount_ > 0) if (--refcount_ > 0)
return; return va_res;
// Must check if vaInitialize completed successfully, to work around a bug in // Must check if vaInitialize completed successfully, to work around a bug in
// libva. The bug was fixed upstream: // libva. The bug was fixed upstream:
...@@ -454,10 +457,11 @@ void VADisplayState::Deinitialize(VAStatus* status) { ...@@ -454,10 +457,11 @@ void VADisplayState::Deinitialize(VAStatus* status) {
// TODO(mgiuca): Remove this check, and the |va_initialized_| variable, once // TODO(mgiuca): Remove this check, and the |va_initialized_| variable, once
// the fix has rolled out sufficiently. // the fix has rolled out sufficiently.
if (va_initialized_ && va_display_) if (va_initialized_ && va_display_)
*status = vaTerminate(va_display_); va_res = vaTerminate(va_display_);
va_initialized_ = false; va_initialized_ = false;
va_display_ = nullptr; va_display_ = nullptr;
va_vendor_string_ = ""; va_vendor_string_ = "";
return va_res;
} }
static VAEntrypoint GetVaEntryPoint(VaapiWrapper::CodecMode mode, static VAEntrypoint GetVaEntryPoint(VaapiWrapper::CodecMode mode,
...@@ -652,9 +656,8 @@ VASupportedProfiles::VASupportedProfiles() ...@@ -652,9 +656,8 @@ VASupportedProfiles::VASupportedProfiles()
static_cast<VaapiWrapper::CodecMode>(i)); static_cast<VaapiWrapper::CodecMode>(i));
} }
VAStatus va_res = VA_STATUS_SUCCESS; const VAStatus va_res = display_state->Deinitialize();
display_state->Deinitialize(&va_res); VA_LOG_ON_ERROR(va_res, "vaTerminate");
VA_LOG_ON_ERROR(va_res, "VADisplayState::Deinitialize failed");
{ {
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
...@@ -710,7 +713,7 @@ bool VASupportedProfiles::GetSupportedVAProfiles( ...@@ -710,7 +713,7 @@ bool VASupportedProfiles::GetSupportedVAProfiles(
int num_supported_profiles; int num_supported_profiles;
VAStatus va_res = vaQueryConfigProfiles(va_display_, &supported_profiles[0], VAStatus va_res = vaQueryConfigProfiles(va_display_, &supported_profiles[0],
&num_supported_profiles); &num_supported_profiles);
VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigProfiles failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigProfiles", false);
if (num_supported_profiles < 0 || num_supported_profiles > max_profiles) { if (num_supported_profiles < 0 || num_supported_profiles > max_profiles) {
LOG(ERROR) << "vaQueryConfigProfiles returned: " << num_supported_profiles; LOG(ERROR) << "vaQueryConfigProfiles returned: " << num_supported_profiles;
return false; return false;
...@@ -734,7 +737,7 @@ bool VASupportedProfiles::IsEntrypointSupported_Locked( ...@@ -734,7 +737,7 @@ bool VASupportedProfiles::IsEntrypointSupported_Locked(
VAStatus va_res = vaQueryConfigEntrypoints(va_display_, va_profile, VAStatus va_res = vaQueryConfigEntrypoints(va_display_, va_profile,
&supported_entrypoints[0], &supported_entrypoints[0],
&num_supported_entrypoints); &num_supported_entrypoints);
VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigEntrypoints failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigEntrypoints", false);
if (num_supported_entrypoints < 0 || if (num_supported_entrypoints < 0 ||
num_supported_entrypoints > max_entrypoints) { num_supported_entrypoints > max_entrypoints) {
LOG(ERROR) << "vaQueryConfigEntrypoints returned: " LOG(ERROR) << "vaQueryConfigEntrypoints returned: "
...@@ -757,7 +760,7 @@ bool VASupportedProfiles::AreAttribsSupported_Locked( ...@@ -757,7 +760,7 @@ bool VASupportedProfiles::AreAttribsSupported_Locked(
VAStatus va_res = vaGetConfigAttributes(va_display_, va_profile, entrypoint, VAStatus va_res = vaGetConfigAttributes(va_display_, va_profile, entrypoint,
&attribs[0], attribs.size()); &attribs[0], attribs.size());
VA_SUCCESS_OR_RETURN(va_res, "vaGetConfigAttributes failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaGetConfigAttributes", false);
for (size_t i = 0; i < required_attribs.size(); ++i) { for (size_t i = 0; i < required_attribs.size(); ++i) {
if (attribs[i].type != required_attribs[i].type || if (attribs[i].type != required_attribs[i].type ||
...@@ -781,7 +784,7 @@ bool VASupportedProfiles::FillProfileInfo_Locked( ...@@ -781,7 +784,7 @@ bool VASupportedProfiles::FillProfileInfo_Locked(
VAStatus va_res = VAStatus va_res =
vaCreateConfig(va_display_, va_profile, entrypoint, &required_attribs[0], vaCreateConfig(va_display_, va_profile, entrypoint, &required_attribs[0],
required_attribs.size(), &va_config_id); required_attribs.size(), &va_config_id);
VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig", false);
base::ScopedClosureRunner vaconfig_destroyer(base::BindOnce( base::ScopedClosureRunner vaconfig_destroyer(base::BindOnce(
[](VADisplay display, VAConfigID id) { [](VADisplay display, VAConfigID id) {
if (id != VA_INVALID_ID) { if (id != VA_INVALID_ID) {
...@@ -799,7 +802,7 @@ bool VASupportedProfiles::FillProfileInfo_Locked( ...@@ -799,7 +802,7 @@ bool VASupportedProfiles::FillProfileInfo_Locked(
unsigned int num_attribs; unsigned int num_attribs;
va_res = vaQuerySurfaceAttributes(va_display_, va_config_id, nullptr, va_res = vaQuerySurfaceAttributes(va_display_, va_config_id, nullptr,
&num_attribs); &num_attribs);
VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes", false);
if (!num_attribs) if (!num_attribs)
return false; return false;
...@@ -808,7 +811,7 @@ bool VASupportedProfiles::FillProfileInfo_Locked( ...@@ -808,7 +811,7 @@ bool VASupportedProfiles::FillProfileInfo_Locked(
va_res = vaQuerySurfaceAttributes(va_display_, va_config_id, &attrib_list[0], va_res = vaQuerySurfaceAttributes(va_display_, va_config_id, &attrib_list[0],
&num_attribs); &num_attribs);
VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes", false);
profile_info->va_profile = va_profile; profile_info->va_profile = va_profile;
profile_info->min_resolution = gfx::Size(); profile_info->min_resolution = gfx::Size();
...@@ -844,7 +847,7 @@ bool VASupportedProfiles::FillProfileInfo_Locked( ...@@ -844,7 +847,7 @@ bool VASupportedProfiles::FillProfileInfo_Locked(
// supported RT formats. // supported RT formats.
va_res = vaCreateConfig(va_display_, va_profile, entrypoint, nullptr, 0, va_res = vaCreateConfig(va_display_, va_profile, entrypoint, nullptr, 0,
&va_config_id); &va_config_id);
VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig", false);
base::ScopedClosureRunner vaconfig_no_attribs_destroyer(base::BindOnce( base::ScopedClosureRunner vaconfig_no_attribs_destroyer(base::BindOnce(
[](VADisplay display, VAConfigID id) { [](VADisplay display, VAConfigID id) {
if (id != VA_INVALID_ID) { if (id != VA_INVALID_ID) {
...@@ -867,7 +870,7 @@ bool VASupportedProfiles::FillProfileInfo_Locked( ...@@ -867,7 +870,7 @@ bool VASupportedProfiles::FillProfileInfo_Locked(
va_res = vaQueryConfigAttributes(va_display_, va_config_id, &va_profile, va_res = vaQueryConfigAttributes(va_display_, va_config_id, &va_profile,
&entrypoint, config_attributes.data(), &entrypoint, config_attributes.data(),
&num_config_attributes); &num_config_attributes);
VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigAttributes failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigAttributes", false);
for (int i = 0; i < num_config_attributes; i++) { for (int i = 0; i < num_config_attributes; i++) {
const VAConfigAttrib& attrib = config_attributes[i]; const VAConfigAttrib& attrib = config_attributes[i];
if (attrib.type != VAConfigAttribRTFormat) if (attrib.type != VAConfigAttribRTFormat)
...@@ -1009,9 +1012,8 @@ VASupportedImageFormats::VASupportedImageFormats() ...@@ -1009,9 +1012,8 @@ VASupportedImageFormats::VASupportedImageFormats()
LOG(ERROR) << "Failed to get supported image formats"; LOG(ERROR) << "Failed to get supported image formats";
} }
VAStatus va_res = VA_STATUS_SUCCESS; const VAStatus va_res = display_state->Deinitialize();
display_state->Deinitialize(&va_res); VA_LOG_ON_ERROR(va_res, "vaTerminate");
VA_LOG_ON_ERROR(va_res, "VADisplayState::Deinitialize failed");
} }
bool VASupportedImageFormats::InitSupportedImageFormats_Locked() { bool VASupportedImageFormats::InitSupportedImageFormats_Locked() {
...@@ -1029,7 +1031,7 @@ bool VASupportedImageFormats::InitSupportedImageFormats_Locked() { ...@@ -1029,7 +1031,7 @@ bool VASupportedImageFormats::InitSupportedImageFormats_Locked() {
int num_image_formats; int num_image_formats;
const VAStatus va_res = vaQueryImageFormats( const VAStatus va_res = vaQueryImageFormats(
va_display_, supported_formats_.data(), &num_image_formats); va_display_, supported_formats_.data(), &num_image_formats);
VA_SUCCESS_OR_RETURN(va_res, "vaQueryImageFormats failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaQueryImageFormats", false);
if (num_image_formats < 0 || num_image_formats > max_image_formats) { if (num_image_formats < 0 || num_image_formats > max_image_formats) {
LOG(ERROR) << "vaQueryImageFormats returned: " << num_image_formats; LOG(ERROR) << "vaQueryImageFormats returned: " << num_image_formats;
supported_formats_.clear(); supported_formats_.clear();
...@@ -1421,7 +1423,7 @@ bool VaapiWrapper::CreateContext(const gfx::Size& size) { ...@@ -1421,7 +1423,7 @@ bool VaapiWrapper::CreateContext(const gfx::Size& size) {
va_display_, va_config_id_, picture_size.width(), picture_size.height(), va_display_, va_config_id_, picture_size.width(), picture_size.height(),
flag, empty_va_surfaces_ids_pointer, empty_va_surfaces_ids_size, flag, empty_va_surfaces_ids_pointer, empty_va_surfaces_ids_size,
&va_context_id_); &va_context_id_);
VA_LOG_ON_ERROR(va_res, "vaCreateContext failed"); VA_LOG_ON_ERROR(va_res, "vaCreateContext");
return va_res == VA_STATUS_SUCCESS; return va_res == VA_STATUS_SUCCESS;
} }
...@@ -1490,7 +1492,7 @@ scoped_refptr<VASurface> VaapiWrapper::CreateVASurfaceForPixmap( ...@@ -1490,7 +1492,7 @@ scoped_refptr<VASurface> VaapiWrapper::CreateVASurfaceForPixmap(
va_display_, va_format, base::checked_cast<unsigned int>(size.width()), va_display_, va_format, base::checked_cast<unsigned int>(size.width()),
base::checked_cast<unsigned int>(size.height()), &va_surface_id, 1, base::checked_cast<unsigned int>(size.height()), &va_surface_id, 1,
&va_attribs[0], va_attribs.size()); &va_attribs[0], va_attribs.size());
VA_SUCCESS_OR_RETURN(va_res, "Failed to create unowned VASurface", nullptr); VA_SUCCESS_OR_RETURN(va_res, "vaCreateSurfaces (import mode)", nullptr);
} }
// VASurface shares an ownership of the buffer referred by the passed file // VASurface shares an ownership of the buffer referred by the passed file
...@@ -1511,13 +1513,13 @@ VaapiWrapper::ExportVASurfaceAsNativePixmapDmaBuf( ...@@ -1511,13 +1513,13 @@ VaapiWrapper::ExportVASurfaceAsNativePixmapDmaBuf(
{ {
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
VAStatus va_res = vaSyncSurface(va_display_, scoped_va_surface.id()); VAStatus va_res = vaSyncSurface(va_display_, scoped_va_surface.id());
VA_SUCCESS_OR_RETURN(va_res, "Cannot sync VASurface", nullptr); VA_SUCCESS_OR_RETURN(va_res, "vaSyncSurface", nullptr);
va_res = vaExportSurfaceHandle( va_res = vaExportSurfaceHandle(
va_display_, scoped_va_surface.id(), va_display_, scoped_va_surface.id(),
VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2, VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
VA_EXPORT_SURFACE_READ_ONLY | VA_EXPORT_SURFACE_SEPARATE_LAYERS, VA_EXPORT_SURFACE_READ_ONLY | VA_EXPORT_SURFACE_SEPARATE_LAYERS,
&descriptor); &descriptor);
VA_SUCCESS_OR_RETURN(va_res, "Failed to export VASurface", nullptr); VA_SUCCESS_OR_RETURN(va_res, "vaExportSurfaceHandle", nullptr);
} }
// We only support one bo containing all the planes. The fd should be owned by // We only support one bo containing all the planes. The fd should be owned by
...@@ -1607,7 +1609,7 @@ bool VaapiWrapper::SyncSurface(VASurfaceID va_surface_id) { ...@@ -1607,7 +1609,7 @@ bool VaapiWrapper::SyncSurface(VASurfaceID va_surface_id) {
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); VA_SUCCESS_OR_RETURN(va_res, "vaSyncSurface", false);
return true; return true;
} }
...@@ -1623,7 +1625,7 @@ bool VaapiWrapper::SubmitBuffer(VABufferType va_buffer_type, ...@@ -1623,7 +1625,7 @@ bool VaapiWrapper::SubmitBuffer(VABufferType va_buffer_type,
VABufferID buffer_id; VABufferID buffer_id;
VAStatus va_res = vaCreateBuffer(va_display_, va_context_id_, va_buffer_type, VAStatus va_res = vaCreateBuffer(va_display_, va_context_id_, va_buffer_type,
size, 1, nullptr, &buffer_id); size, 1, nullptr, &buffer_id);
VA_SUCCESS_OR_RETURN(va_res, "Failed to create a VA buffer", false); VA_SUCCESS_OR_RETURN(va_res, "vaCreateBuffer", false);
ScopedVABufferMapping mapping( ScopedVABufferMapping mapping(
va_lock_, va_display_, buffer_id, va_lock_, va_display_, buffer_id,
...@@ -1660,7 +1662,7 @@ bool VaapiWrapper::SubmitVAEncMiscParamBuffer( ...@@ -1660,7 +1662,7 @@ bool VaapiWrapper::SubmitVAEncMiscParamBuffer(
VAStatus va_res = vaCreateBuffer( VAStatus va_res = vaCreateBuffer(
va_display_, va_context_id_, VAEncMiscParameterBufferType, va_display_, va_context_id_, VAEncMiscParameterBufferType,
sizeof(VAEncMiscParameterBuffer) + size, 1, NULL, &buffer_id); sizeof(VAEncMiscParameterBuffer) + size, 1, NULL, &buffer_id);
VA_SUCCESS_OR_RETURN(va_res, "Failed to create a VA buffer", false); VA_SUCCESS_OR_RETURN(va_res, "vaCreateBuffer", false);
ScopedVABufferMapping mapping( ScopedVABufferMapping mapping(
va_lock_, va_display_, buffer_id, va_lock_, va_display_, buffer_id,
...@@ -1687,12 +1689,12 @@ void VaapiWrapper::DestroyPendingBuffers_Locked() { ...@@ -1687,12 +1689,12 @@ void VaapiWrapper::DestroyPendingBuffers_Locked() {
va_lock_->AssertAcquired(); va_lock_->AssertAcquired();
for (const auto& pending_va_buf : pending_va_bufs_) { for (const auto& pending_va_buf : pending_va_bufs_) {
VAStatus va_res = vaDestroyBuffer(va_display_, pending_va_buf); VAStatus va_res = vaDestroyBuffer(va_display_, pending_va_buf);
VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer");
} }
for (const auto& pending_slice_buf : pending_slice_bufs_) { for (const auto& pending_slice_buf : pending_slice_bufs_) {
VAStatus va_res = vaDestroyBuffer(va_display_, pending_slice_buf); VAStatus va_res = vaDestroyBuffer(va_display_, pending_slice_buf);
VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer");
} }
pending_va_bufs_.clear(); pending_va_bufs_.clear();
...@@ -1713,7 +1715,7 @@ bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id, ...@@ -1713,7 +1715,7 @@ bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); VA_SUCCESS_OR_RETURN(va_res, "vaSyncSurface", false);
// Put the data into an X Pixmap. // Put the data into an X Pixmap.
va_res = vaPutSurface(va_display_, va_res = vaPutSurface(va_display_,
...@@ -1722,7 +1724,7 @@ bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id, ...@@ -1722,7 +1724,7 @@ bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
0, 0, dest_size.width(), dest_size.height(), 0, 0, dest_size.width(), dest_size.height(),
0, 0, dest_size.width(), dest_size.height(), 0, 0, dest_size.width(), dest_size.height(),
NULL, 0, 0); NULL, 0, 0);
VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false); VA_SUCCESS_OR_RETURN(va_res, "vaPutSurface", false);
return true; return true;
} }
#endif // USE_X11 #endif // USE_X11
...@@ -1736,7 +1738,7 @@ std::unique_ptr<ScopedVAImage> VaapiWrapper::CreateVaImage( ...@@ -1736,7 +1738,7 @@ std::unique_ptr<ScopedVAImage> VaapiWrapper::CreateVaImage(
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", nullptr); VA_SUCCESS_OR_RETURN(va_res, "vaSyncSurface", nullptr);
scoped_image = std::make_unique<ScopedVAImage>(va_lock_, va_display_, scoped_image = std::make_unique<ScopedVAImage>(va_lock_, va_display_,
va_surface_id, format, size); va_surface_id, format, size);
...@@ -1764,7 +1766,7 @@ bool VaapiWrapper::UploadVideoFrameToSurface(const VideoFrame& frame, ...@@ -1764,7 +1766,7 @@ bool VaapiWrapper::UploadVideoFrameToSurface(const VideoFrame& frame,
va_res = vaCreateImage(va_display_, &image_format, size.width(), va_res = vaCreateImage(va_display_, &image_format, size.width(),
size.height(), &image); size.height(), &image);
VA_SUCCESS_OR_RETURN(va_res, "vaCreateImage failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaCreateImage", false);
} }
base::ScopedClosureRunner vaimage_deleter( base::ScopedClosureRunner vaimage_deleter(
base::Bind(&DestroyVAImage, va_display_, image)); base::Bind(&DestroyVAImage, va_display_, image));
...@@ -1816,7 +1818,7 @@ bool VaapiWrapper::UploadVideoFrameToSurface(const VideoFrame& frame, ...@@ -1816,7 +1818,7 @@ bool VaapiWrapper::UploadVideoFrameToSurface(const VideoFrame& frame,
va_res = vaPutImage(va_display_, va_surface_id, image.image_id, 0, 0, va_res = vaPutImage(va_display_, va_surface_id, image.image_id, 0, 0,
size.width(), size.height(), 0, 0, size.width(), size.width(), size.height(), 0, 0, size.width(),
size.height()); size.height());
VA_SUCCESS_OR_RETURN(va_res, "vaPutImage failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaPutImage", false);
} }
return ret == 0; return ret == 0;
} }
...@@ -1828,7 +1830,7 @@ bool VaapiWrapper::CreateVABuffer(size_t size, VABufferID* buffer_id) { ...@@ -1828,7 +1830,7 @@ bool VaapiWrapper::CreateVABuffer(size_t size, VABufferID* buffer_id) {
VAStatus va_res = VAStatus va_res =
vaCreateBuffer(va_display_, va_context_id_, VAEncCodedBufferType, size, 1, vaCreateBuffer(va_display_, va_context_id_, VAEncCodedBufferType, size, 1,
NULL, buffer_id); NULL, buffer_id);
VA_SUCCESS_OR_RETURN(va_res, "Failed to create a coded buffer", false); VA_SUCCESS_OR_RETURN(va_res, "vaCreateBuffer", false);
const auto is_new_entry = va_buffers_.insert(*buffer_id).second; const auto is_new_entry = va_buffers_.insert(*buffer_id).second;
DCHECK(is_new_entry); DCHECK(is_new_entry);
...@@ -1846,7 +1848,7 @@ bool VaapiWrapper::DownloadFromVABuffer(VABufferID buffer_id, ...@@ -1846,7 +1848,7 @@ bool VaapiWrapper::DownloadFromVABuffer(VABufferID buffer_id,
TRACE_EVENT0("media,gpu", "VaapiWrapper::DownloadFromVABufferLocked"); TRACE_EVENT0("media,gpu", "VaapiWrapper::DownloadFromVABufferLocked");
VAStatus va_res = vaSyncSurface(va_display_, sync_surface_id); VAStatus va_res = vaSyncSurface(va_display_, sync_surface_id);
VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); VA_SUCCESS_OR_RETURN(va_res, "vaSyncSurface", false);
ScopedVABufferMapping mapping(va_lock_, va_display_, buffer_id); ScopedVABufferMapping mapping(va_lock_, va_display_, buffer_id);
if (!mapping.IsValid()) if (!mapping.IsValid())
...@@ -1896,10 +1898,7 @@ bool VaapiWrapper::GetVAEncMaxNumOfRefFrames(VideoCodecProfile profile, ...@@ -1896,10 +1898,7 @@ bool VaapiWrapper::GetVAEncMaxNumOfRefFrames(VideoCodecProfile profile,
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
VAStatus va_res = VAStatus va_res =
vaGetConfigAttributes(va_display_, va_profile, entrypoint, &attrib, 1); vaGetConfigAttributes(va_display_, va_profile, entrypoint, &attrib, 1);
if (va_res) { VA_SUCCESS_OR_RETURN(va_res, "vaGetConfigAttributes", false);
LOG_VA_ERROR_AND_REPORT(va_res, "vaGetConfigAttributes failed");
return false;
}
*max_ref_frames = attrib.value; *max_ref_frames = attrib.value;
return true; return true;
...@@ -1908,7 +1907,7 @@ bool VaapiWrapper::GetVAEncMaxNumOfRefFrames(VideoCodecProfile profile, ...@@ -1908,7 +1907,7 @@ bool VaapiWrapper::GetVAEncMaxNumOfRefFrames(VideoCodecProfile profile,
void VaapiWrapper::DestroyVABuffer(VABufferID buffer_id) { void VaapiWrapper::DestroyVABuffer(VABufferID buffer_id) {
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
VAStatus va_res = vaDestroyBuffer(va_display_, buffer_id); VAStatus va_res = vaDestroyBuffer(va_display_, buffer_id);
VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer");
const auto was_found = va_buffers_.erase(buffer_id); const auto was_found = va_buffers_.erase(buffer_id);
DCHECK(was_found); DCHECK(was_found);
} }
...@@ -1918,7 +1917,7 @@ void VaapiWrapper::DestroyVABuffers() { ...@@ -1918,7 +1917,7 @@ void VaapiWrapper::DestroyVABuffers() {
for (auto it = va_buffers_.begin(); it != va_buffers_.end(); ++it) { for (auto it = va_buffers_.begin(); it != va_buffers_.end(); ++it) {
VAStatus va_res = vaDestroyBuffer(va_display_, *it); VAStatus va_res = vaDestroyBuffer(va_display_, *it);
VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer");
} }
va_buffers_.clear(); va_buffers_.clear();
...@@ -1937,7 +1936,7 @@ bool VaapiWrapper::BlitSurface(const scoped_refptr<VASurface>& va_surface_src, ...@@ -1937,7 +1936,7 @@ bool VaapiWrapper::BlitSurface(const scoped_refptr<VASurface>& va_surface_src,
VAStatus va_res = vaCreateBuffer( VAStatus va_res = vaCreateBuffer(
va_display_, va_context_id_, VAProcPipelineParameterBufferType, va_display_, va_context_id_, VAProcPipelineParameterBufferType,
sizeof(VAProcPipelineParameterBuffer), 1, nullptr, &buffer_id); sizeof(VAProcPipelineParameterBuffer), 1, nullptr, &buffer_id);
VA_SUCCESS_OR_RETURN(va_res, "Couldn't create buffer", false); VA_SUCCESS_OR_RETURN(va_res, "vaCreateBuffer", false);
DCHECK_NE(buffer_id, VA_INVALID_ID); DCHECK_NE(buffer_id, VA_INVALID_ID);
va_buffers_.emplace(buffer_id); va_buffers_.emplace(buffer_id);
} }
...@@ -1976,19 +1975,19 @@ bool VaapiWrapper::BlitSurface(const scoped_refptr<VASurface>& va_surface_src, ...@@ -1976,19 +1975,19 @@ bool VaapiWrapper::BlitSurface(const scoped_refptr<VASurface>& va_surface_src,
pipeline_param->output_color_standard = VAProcColorStandardNone; pipeline_param->output_color_standard = VAProcColorStandardNone;
pipeline_param->filter_flags = VA_FILTER_SCALING_DEFAULT; pipeline_param->filter_flags = VA_FILTER_SCALING_DEFAULT;
VA_SUCCESS_OR_RETURN(mapping.Unmap(), "Couldn't unmap vpp buffer", false); VA_SUCCESS_OR_RETURN(mapping.Unmap(), "Vpp Buffer unmapping", false);
} }
VA_SUCCESS_OR_RETURN( VA_SUCCESS_OR_RETURN(
vaBeginPicture(va_display_, va_context_id_, va_surface_dest->id()), vaBeginPicture(va_display_, va_context_id_, va_surface_dest->id()),
"Couldn't begin picture", false); "vaBeginPicture", false);
VA_SUCCESS_OR_RETURN( VA_SUCCESS_OR_RETURN(
vaRenderPicture(va_display_, va_context_id_, &buffer_id, 1), vaRenderPicture(va_display_, va_context_id_, &buffer_id, 1),
"Couldn't render picture", false); "vaRenderPicture", false);
VA_SUCCESS_OR_RETURN(vaEndPicture(va_display_, va_context_id_), VA_SUCCESS_OR_RETURN(vaEndPicture(va_display_, va_context_id_),
"Couldn't end picture", false); "vaEndPicture", false);
return true; return true;
} }
...@@ -2066,7 +2065,7 @@ bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) { ...@@ -2066,7 +2065,7 @@ bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) {
vaCreateConfig(va_display_, va_profile, entrypoint, vaCreateConfig(va_display_, va_profile, entrypoint,
required_attribs.empty() ? nullptr : &required_attribs[0], required_attribs.empty() ? nullptr : &required_attribs[0],
required_attribs.size(), &va_config_id_); required_attribs.size(), &va_config_id_);
VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig", false);
return true; return true;
} }
...@@ -2075,15 +2074,14 @@ void VaapiWrapper::Deinitialize() { ...@@ -2075,15 +2074,14 @@ void VaapiWrapper::Deinitialize() {
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
if (va_config_id_ != VA_INVALID_ID) { if (va_config_id_ != VA_INVALID_ID) {
VAStatus va_res = vaDestroyConfig(va_display_, va_config_id_); VAStatus va_res = vaDestroyConfig(va_display_, va_config_id_);
VA_LOG_ON_ERROR(va_res, "vaDestroyConfig failed"); VA_LOG_ON_ERROR(va_res, "vaDestroyConfig");
} }
va_config_id_ = VA_INVALID_ID; va_config_id_ = VA_INVALID_ID;
va_display_ = nullptr; va_display_ = nullptr;
} }
VAStatus va_res = VA_STATUS_SUCCESS; const VAStatus va_res = VADisplayState::Get()->Deinitialize();
VADisplayState::Get()->Deinitialize(&va_res); VA_LOG_ON_ERROR(va_res, "vaTerminate");
VA_LOG_ON_ERROR(va_res, "vaTerminate failed");
} }
bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) { bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) {
...@@ -2106,7 +2104,7 @@ void VaapiWrapper::DestroyContext() { ...@@ -2106,7 +2104,7 @@ void VaapiWrapper::DestroyContext() {
if (va_context_id_ != VA_INVALID_ID) { if (va_context_id_ != VA_INVALID_ID) {
const VAStatus va_res = vaDestroyContext(va_display_, va_context_id_); const VAStatus va_res = vaDestroyContext(va_display_, va_context_id_);
VA_LOG_ON_ERROR(va_res, "vaDestroyContext failed"); VA_LOG_ON_ERROR(va_res, "vaDestroyContext");
} }
va_context_id_ = VA_INVALID_ID; va_context_id_ = VA_INVALID_ID;
...@@ -2118,7 +2116,7 @@ bool VaapiWrapper::CreateSurfaces(unsigned int va_format, ...@@ -2118,7 +2116,7 @@ bool VaapiWrapper::CreateSurfaces(unsigned int va_format,
size_t num_surfaces, size_t num_surfaces,
std::vector<VASurfaceID>* va_surfaces) { std::vector<VASurfaceID>* va_surfaces) {
DVLOG(2) << "Creating " << num_surfaces << " " << size.ToString() DVLOG(2) << "Creating " << num_surfaces << " " << size.ToString()
<< " surfaces "; << " surfaces";
DCHECK_NE(va_format, kInvalidVaRtFormat); DCHECK_NE(va_format, kInvalidVaRtFormat);
DCHECK(va_surfaces->empty()); DCHECK(va_surfaces->empty());
...@@ -2150,7 +2148,7 @@ bool VaapiWrapper::CreateSurfaces(unsigned int va_format, ...@@ -2150,7 +2148,7 @@ bool VaapiWrapper::CreateSurfaces(unsigned int va_format,
base::checked_cast<unsigned int>(size.height()), va_surfaces->data(), base::checked_cast<unsigned int>(size.height()), va_surfaces->data(),
num_surfaces, &attribute, 1u); num_surfaces, &attribute, 1u);
} }
VA_LOG_ON_ERROR(va_res, "vaCreateSurfaces failed"); VA_LOG_ON_ERROR(va_res, "vaCreateSurfaces (allocate mode)");
return va_res == VA_STATUS_SUCCESS; return va_res == VA_STATUS_SUCCESS;
} }
...@@ -2174,7 +2172,7 @@ std::unique_ptr<ScopedVASurface> VaapiWrapper::CreateScopedVASurface( ...@@ -2174,7 +2172,7 @@ std::unique_ptr<ScopedVASurface> VaapiWrapper::CreateScopedVASurface(
va_display_, va_rt_format, base::checked_cast<unsigned int>(size.width()), va_display_, va_rt_format, base::checked_cast<unsigned int>(size.width()),
base::checked_cast<unsigned int>(size.height()), &va_surface_id, 1u, NULL, base::checked_cast<unsigned int>(size.height()), &va_surface_id, 1u, NULL,
0); 0);
VA_SUCCESS_OR_RETURN(va_res, "vaCreateSurfaces failed", nullptr); VA_SUCCESS_OR_RETURN(va_res, "vaCreateSurfaces (allocate mode)", nullptr);
DCHECK_NE(VA_INVALID_ID, va_surface_id) DCHECK_NE(VA_INVALID_ID, va_surface_id)
<< "Invalid VA surface id after vaCreateSurfaces"; << "Invalid VA surface id after vaCreateSurfaces";
...@@ -2200,7 +2198,7 @@ void VaapiWrapper::DestroySurfaces(std::vector<VASurfaceID> va_surfaces) { ...@@ -2200,7 +2198,7 @@ void VaapiWrapper::DestroySurfaces(std::vector<VASurfaceID> va_surfaces) {
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
const VAStatus va_res = const VAStatus va_res =
vaDestroySurfaces(va_display_, va_surfaces.data(), va_surfaces.size()); vaDestroySurfaces(va_display_, va_surfaces.data(), va_surfaces.size());
VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces failed"); VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces");
} }
void VaapiWrapper::DestroySurface(VASurfaceID va_surface_id) { void VaapiWrapper::DestroySurface(VASurfaceID va_surface_id) {
...@@ -2208,7 +2206,7 @@ void VaapiWrapper::DestroySurface(VASurfaceID va_surface_id) { ...@@ -2208,7 +2206,7 @@ void VaapiWrapper::DestroySurface(VASurfaceID va_surface_id) {
return; return;
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
const VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_id, 1); const VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_id, 1);
VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces on surface failed"); VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces");
} }
bool VaapiWrapper::Execute(VASurfaceID va_surface_id) { bool VaapiWrapper::Execute(VASurfaceID va_surface_id) {
...@@ -2227,26 +2225,28 @@ bool VaapiWrapper::Execute_Locked(VASurfaceID va_surface_id) { ...@@ -2227,26 +2225,28 @@ bool VaapiWrapper::Execute_Locked(VASurfaceID va_surface_id) {
// Get ready to execute for given surface. // 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); VA_SUCCESS_OR_RETURN(va_res, "vaBeginPicture", false);
if (pending_va_bufs_.size() > 0) { if (pending_va_bufs_.size() > 0) {
// Commit parameter and slice buffers. // 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()); pending_va_bufs_.size());
VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for va_bufs failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for |pending_va_bufs_|",
false);
} }
if (pending_slice_bufs_.size() > 0) { if (pending_slice_bufs_.size() > 0) {
va_res = va_res =
vaRenderPicture(va_display_, va_context_id_, &pending_slice_bufs_[0], vaRenderPicture(va_display_, va_context_id_, &pending_slice_bufs_[0],
pending_slice_bufs_.size()); pending_slice_bufs_.size());
VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for slices failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for |pending_slice_bufs_|",
false);
} }
// Instruct HW codec to start processing committed buffers. // Instruct HW codec to start processing committed buffers.
// Does not block and the job is not finished after this returns. // Does not block and the job is not finished after this returns.
va_res = vaEndPicture(va_display_, va_context_id_); va_res = vaEndPicture(va_display_, va_context_id_);
VA_SUCCESS_OR_RETURN(va_res, "vaEndPicture failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaEndPicture", false);
return true; return true;
} }
...@@ -2285,7 +2285,7 @@ bool VaapiWrapper::IsLowPowerEncSupported(VAProfile va_profile) const { ...@@ -2285,7 +2285,7 @@ bool VaapiWrapper::IsLowPowerEncSupported(VAProfile va_profile) const {
VAStatus va_res = VAStatus va_res =
vaGetConfigAttributes(va_display_, va_profile, kLowPowerEncEntryPoint, vaGetConfigAttributes(va_display_, va_profile, kLowPowerEncEntryPoint,
&attribs[0], attribs.size()); &attribs[0], attribs.size());
VA_SUCCESS_OR_RETURN(va_res, "vaGetConfigAttributes failed", false); VA_SUCCESS_OR_RETURN(va_res, "vaGetConfigAttributes", false);
for (size_t i = 0; i < required_attribs.size(); ++i) { for (size_t i = 0; i < required_attribs.size(); ++i) {
if (attribs[i].type != required_attribs[i].type || if (attribs[i].type != required_attribs[i].type ||
......
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