Skip to content

Commit

Permalink
Avoid crash on startup if VAAPI cannot be initialized.
Browse files Browse the repository at this point in the history
The call to vaTerminate crashes if vaInitialize failed. Therefore,
remember whether vaInitialize succeeded, and do not call vaTerminate if
it failed.

BUG=425732

Review URL: https://codereview.chromium.org/784273002

Cr-Commit-Position: refs/heads/master@{#307848}
  • Loading branch information
mgiuca authored and Commit bot committed Dec 11, 2014
1 parent 6a2b78c commit c8ff24b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions content/common/gpu/media/vaapi_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ VASurface::~VASurface() {
VaapiWrapper::VaapiWrapper()
: va_display_(NULL),
va_config_id_(VA_INVALID_ID),
va_context_id_(VA_INVALID_ID) {
va_context_id_(VA_INVALID_ID),
va_initialized_(false) {
}

VaapiWrapper::~VaapiWrapper() {
Expand Down Expand Up @@ -231,6 +232,7 @@ bool VaapiWrapper::VaInitialize(Display* x_display,

VAStatus va_res = vaInitialize(va_display_, &major_version_, &minor_version_);
VA_SUCCESS_OR_RETURN(va_res, "vaInitialize failed", false);
va_initialized_ = true;
DVLOG(1) << "VAAPI version: " << major_version_ << "." << minor_version_;

if (VAAPIVersionLessThan(0, 34)) {
Expand Down Expand Up @@ -361,13 +363,19 @@ void VaapiWrapper::Deinitialize() {
VA_LOG_ON_ERROR(va_res, "vaDestroyConfig failed");
}

if (va_display_) {
// Must check if vaInitialize completed successfully, to work around a bug in
// libva. The bug was fixed upstream:
// http://lists.freedesktop.org/archives/libva/2013-July/001807.html
// TODO(mgiuca): Remove this check, and the |va_initialized_| variable, once
// the fix has rolled out sufficiently.
if (va_initialized_ && va_display_) {
VAStatus va_res = vaTerminate(va_display_);
VA_LOG_ON_ERROR(va_res, "vaTerminate failed");
}

va_config_id_ = VA_INVALID_ID;
va_display_ = NULL;
va_initialized_ = false;
}

bool VaapiWrapper::VAAPIVersionLessThan(int major, int minor) {
Expand Down
2 changes: 2 additions & 0 deletions content/common/gpu/media/vaapi_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ class CONTENT_EXPORT VaapiWrapper {
// Created for the current set of va_surface_ids_ in CreateSurfaces() and
// valid until DestroySurfaces().
VAContextID va_context_id_;
// True if vaInitialize has been called successfully.
bool va_initialized_;

// Data queued up for HW codec, to be committed on next execution.
std::vector<VABufferID> pending_slice_bufs_;
Expand Down

0 comments on commit c8ff24b

Please sign in to comment.