| Index: content/common/gpu/media/vaapi_wrapper.cc
|
| diff --git a/content/common/gpu/media/vaapi_wrapper.cc b/content/common/gpu/media/vaapi_wrapper.cc
|
| index 5e93b994db02dcf52301327e0c285b82a148e001..7aea8dccda5b85c474748141393daa90486952bf 100644
|
| --- a/content/common/gpu/media/vaapi_wrapper.cc
|
| +++ b/content/common/gpu/media/vaapi_wrapper.cc
|
| @@ -13,15 +13,27 @@
|
| // Auto-generated for dlopen libva libraries
|
| #include "content/common/gpu/media/va_stubs.h"
|
| #include "third_party/libyuv/include/libyuv.h"
|
| +#if defined(USE_X11)
|
| +#include "third_party/libva/va/va_x11.h"
|
| +#include "ui/gfx/x/x11_types.h"
|
| +#else
|
| +#include <gbm.h>
|
| +#include "third_party/libva/va/drm/va_drm.h"
|
| +#include "third_party/libva/va/va_drmcommon.h"
|
| +#include "ui/ozone/public/ozone_platform.h"
|
| +#include "ui/ozone/public/surface_factory_ozone.h"
|
| +#endif // USE_X11
|
| +#include "ui/gl/gl_bindings.h"
|
|
|
| using content_common_gpu_media::kModuleVa;
|
| +#if defined(USE_X11)
|
| +using content_common_gpu_media::kModuleVa_x11;
|
| +#else
|
| +using content_common_gpu_media::kModuleVa_drm;
|
| +#endif // USE_X11
|
| using content_common_gpu_media::InitializeStubs;
|
| using content_common_gpu_media::StubPathMap;
|
|
|
| -// libva-x11 depends on libva, so dlopen libva-x11 is enough
|
| -static const base::FilePath::CharType kVaLib[] =
|
| - FILE_PATH_LITERAL("libva-x11.so.1");
|
| -
|
| #define LOG_VA_ERROR_AND_REPORT(va_error, err_msg) \
|
| do { \
|
| DVLOG(1) << err_msg \
|
| @@ -113,9 +125,7 @@ VASurface::~VASurface() {
|
| }
|
|
|
| VaapiWrapper::VaapiWrapper()
|
| - : va_display_(NULL),
|
| - va_config_id_(VA_INVALID_ID),
|
| - va_context_id_(VA_INVALID_ID) {
|
| + : va_config_id_(VA_INVALID_ID), va_context_id_(VA_INVALID_ID) {
|
| }
|
|
|
| VaapiWrapper::~VaapiWrapper() {
|
| @@ -128,12 +138,31 @@ VaapiWrapper::~VaapiWrapper() {
|
| scoped_ptr<VaapiWrapper> VaapiWrapper::Create(
|
| CodecMode mode,
|
| media::VideoCodecProfile profile,
|
| - Display* x_display,
|
| const base::Closure& report_error_to_uma_cb) {
|
| + static bool vaapi_functions_initialized = PostSandboxInitialization();
|
| scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
|
|
|
| - if (!vaapi_wrapper->Initialize(
|
| - mode, profile, x_display, report_error_to_uma_cb))
|
| + if (!vaapi_functions_initialized) {
|
| + DVLOG(1) << "Failed to initialize VAAPI libs";
|
| + return vaapi_wrapper.Pass();
|
| + }
|
| +
|
| + VADisplay va_display = NULL;
|
| +#if defined(USE_X11)
|
| + va_display = vaGetDisplay(gfx::GetXDisplay());
|
| +#else
|
| + ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance();
|
| + ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone();
|
| + gbm_device* device =
|
| + reinterpret_cast<gbm_device*>(factory->GetNativeDisplay());
|
| +
|
| + va_display = vaGetDisplayDRM(gbm_device_get_fd(device));
|
| +#endif // USE_X11
|
| +
|
| + if (!va_display || !vaapi_wrapper->Initialize(va_display,
|
| + mode,
|
| + profile,
|
| + report_error_to_uma_cb))
|
| vaapi_wrapper.reset();
|
|
|
| return vaapi_wrapper.Pass();
|
| @@ -151,27 +180,23 @@ void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() {
|
| DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default.";
|
| }
|
|
|
| -bool VaapiWrapper::Initialize(CodecMode mode,
|
| - media::VideoCodecProfile profile,
|
| - Display* x_display,
|
| - const base::Closure& report_error_to_uma_cb) {
|
| - static bool vaapi_functions_initialized = PostSandboxInitialization();
|
| - if (!vaapi_functions_initialized) {
|
| - DVLOG(1) << "Failed to initialize VAAPI libs";
|
| - return false;
|
| - }
|
| -
|
| +bool VaapiWrapper::Initialize(
|
| + VADisplay va_display,
|
| + CodecMode mode,
|
| + media::VideoCodecProfile profile,
|
| + const base::Closure& report_error_to_uma_cb) {
|
| report_error_to_uma_cb_ = report_error_to_uma_cb;
|
|
|
| base::AutoLock auto_lock(va_lock_);
|
|
|
| - va_display_ = vaGetDisplay(x_display);
|
| + va_display_ = va_display;
|
| if (!vaDisplayIsValid(va_display_)) {
|
| DVLOG(1) << "Could not get a valid VA display";
|
| return false;
|
| }
|
|
|
| - VAStatus va_res = vaInitialize(va_display_, &major_version_, &minor_version_);
|
| + VAStatus va_res =
|
| + vaInitialize(va_display_, &major_version_, &minor_version_);
|
| VA_SUCCESS_OR_RETURN(va_res, "vaInitialize failed", false);
|
| DVLOG(1) << "VAAPI version: " << major_version_ << "." << minor_version_;
|
|
|
| @@ -198,7 +223,7 @@ bool VaapiWrapper::Initialize(CodecMode mode,
|
|
|
| VAProfile va_profile = ProfileToVAProfile(profile, supported_profiles);
|
| if (va_profile == VAProfileNone) {
|
| - DVLOG(1) << "Unsupported profile";
|
| + DVLOG(1) << "Unsupported profile : " << profile;
|
| return false;
|
| }
|
|
|
| @@ -247,8 +272,11 @@ bool VaapiWrapper::Initialize(CodecMode mode,
|
| for (size_t i = 0; i < required_attribs.size(); ++i)
|
| attribs[i].value = 0;
|
|
|
| - va_res = vaGetConfigAttributes(
|
| - va_display_, va_profile, entrypoint, &attribs[0], attribs.size());
|
| + 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) {
|
| @@ -296,7 +324,7 @@ bool VaapiWrapper::VAAPIVersionLessThan(int major, int minor) {
|
| (major_version_ == major && minor_version_ < minor);
|
| }
|
|
|
| -bool VaapiWrapper::CreateSurfaces(gfx::Size size,
|
| +bool VaapiWrapper::CreateSurfaces(const gfx::Size& size,
|
| size_t num_surfaces,
|
| std::vector<VASurfaceID>* va_surfaces) {
|
| base::AutoLock auto_lock(va_lock_);
|
| @@ -309,11 +337,12 @@ bool VaapiWrapper::CreateSurfaces(gfx::Size size,
|
| // Allocate surfaces in driver.
|
| VAStatus va_res = vaCreateSurfaces(va_display_,
|
| VA_RT_FORMAT_YUV420,
|
| - size.width(), size.height(),
|
| + size.width(),
|
| + size.height(),
|
| &va_surface_ids_[0],
|
| va_surface_ids_.size(),
|
| - NULL, 0);
|
| -
|
| + NULL,
|
| + 0);
|
| VA_LOG_ON_ERROR(va_res, "vaCreateSurfaces failed");
|
| if (va_res != VA_STATUS_SUCCESS) {
|
| va_surface_ids_.clear();
|
| @@ -321,9 +350,13 @@ bool VaapiWrapper::CreateSurfaces(gfx::Size size,
|
| }
|
|
|
| // 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_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");
|
| @@ -346,8 +379,8 @@ void VaapiWrapper::DestroySurfaces() {
|
| }
|
|
|
| if (!va_surface_ids_.empty()) {
|
| - VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_ids_[0],
|
| - va_surface_ids_.size());
|
| + VAStatus va_res = vaDestroySurfaces(
|
| + va_display_, &va_surface_ids_[0], va_surface_ids_.size());
|
| VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces failed");
|
| }
|
|
|
| @@ -361,9 +394,13 @@ 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) {
|
| @@ -422,12 +459,14 @@ void VaapiWrapper::DestroyPendingBuffers() {
|
| base::AutoLock auto_lock(va_lock_);
|
|
|
| for (size_t i = 0; i < pending_va_bufs_.size(); ++i) {
|
| - VAStatus va_res = vaDestroyBuffer(va_display_, pending_va_bufs_[i]);
|
| + VAStatus va_res =
|
| + vaDestroyBuffer(va_display_, pending_va_bufs_[i]);
|
| VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed");
|
| }
|
|
|
| for (size_t i = 0; i < pending_slice_bufs_.size(); ++i) {
|
| - VAStatus va_res = vaDestroyBuffer(va_display_, pending_slice_bufs_[i]);
|
| + VAStatus va_res =
|
| + vaDestroyBuffer(va_display_, pending_slice_bufs_[i]);
|
| VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed");
|
| }
|
|
|
| @@ -471,8 +510,8 @@ 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) {
|
| @@ -506,25 +545,6 @@ bool VaapiWrapper::ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id) {
|
| return result;
|
| }
|
|
|
| -bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
|
| - Pixmap x_pixmap,
|
| - gfx::Size dest_size) {
|
| - base::AutoLock auto_lock(va_lock_);
|
| -
|
| - VAStatus va_res = vaSyncSurface(va_display_, 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_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false);
|
| - return true;
|
| -}
|
| -
|
| bool VaapiWrapper::GetVaImageForTesting(VASurfaceID va_surface_id,
|
| VAImage* image,
|
| void** mem) {
|
| @@ -572,7 +592,8 @@ bool VaapiWrapper::UploadVideoFrameToSurface(
|
| base::AutoLock auto_lock(va_lock_);
|
|
|
| VAImage image;
|
| - VAStatus va_res = vaDeriveImage(va_display_, va_surface_id, &image);
|
| + VAStatus va_res =
|
| + vaDeriveImage(va_display_, va_surface_id, &image);
|
| VA_SUCCESS_OR_RETURN(va_res, "vaDeriveImage failed", false);
|
| base::ScopedClosureRunner vaimage_deleter(
|
| base::Bind(&DestroyVAImage, va_display_, image));
|
| @@ -626,8 +647,9 @@ 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);
|
|
|
| @@ -665,10 +687,22 @@ bool VaapiWrapper::DownloadAndDestroyCodedBuffer(VABufferID buffer_id,
|
| return buffer_segment == NULL;
|
| }
|
|
|
| +VADisplay VaapiWrapper::GetDisplay() {
|
| + return va_display_;
|
| +}
|
| +
|
| +
|
| // static
|
| bool VaapiWrapper::PostSandboxInitialization() {
|
| StubPathMap paths;
|
| - paths[kModuleVa].push_back(kVaLib);
|
| +
|
| + paths[kModuleVa].push_back("libva.so.1");
|
| +
|
| +#if defined(USE_X11)
|
| + paths[kModuleVa_x11].push_back("libva-x11.so.1");
|
| +#else
|
| + paths[kModuleVa_drm].push_back("libva-drm.so.1");
|
| +#endif
|
|
|
| return InitializeStubs(paths);
|
| }
|
|
|