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

Unified Diff: content/common/gpu/media/vaapi_wrapper.cc

Issue 490233002: VaapiVideoAccelerator: make Vaapi accelerator work with ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More VaapiPictureProviderDrm cleanup Created 6 years, 2 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: 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..7a18c09301ee41abd45eb5a89726dfdfd204c86b 100644
--- a/content/common/gpu/media/vaapi_wrapper.cc
+++ b/content/common/gpu/media/vaapi_wrapper.cc
@@ -13,15 +13,25 @@
// Auto-generated for dlopen libva libraries
#include "content/common/gpu/media/va_stubs.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"
+#else
+#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
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 \
@@ -102,9 +112,10 @@ static VAProfile ProfileToVAProfile(
return va_profile;
}
-VASurface::VASurface(VASurfaceID va_surface_id, const ReleaseCB& release_cb)
- : va_surface_id_(va_surface_id),
- release_cb_(release_cb) {
+VASurface::VASurface(VASurfaceID va_surface_id,
+ const gfx::Size& size,
+ const ReleaseCB& release_cb)
+ : va_surface_id_(va_surface_id), size_(size), release_cb_(release_cb) {
DCHECK(!release_cb_.is_null());
}
@@ -115,28 +126,49 @@ 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_vpp_config_(VA_INVALID_ID),
+ va_vpp_context_(VA_INVALID_ID),
+ va_vpp_buffer_(VA_INVALID_ID) {
}
VaapiWrapper::~VaapiWrapper() {
DestroyPendingBuffers();
DestroyCodedBuffers();
DestroySurfaces();
+ DeinitializeVpp();
Deinitialize();
}
-scoped_ptr<VaapiWrapper> VaapiWrapper::Create(
+scoped_refptr<VaapiWrapper> VaapiWrapper::Create(
CodecMode mode,
media::VideoCodecProfile profile,
- Display* x_display,
const base::Closure& report_error_to_uma_cb) {
- scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
+ static bool vaapi_functions_initialized = PostSandboxInitialization();
+ scoped_refptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
+
+ if (!vaapi_functions_initialized) {
+ DVLOG(1) << "Failed to initialize VAAPI libs";
+ vaapi_wrapper = NULL;
+ return vaapi_wrapper;
+ }
+
+ 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();
+
+ va_display = vaGetDisplayDRM(factory->GetDrmFd());
+#endif // USE_X11
- if (!vaapi_wrapper->Initialize(
- mode, profile, x_display, report_error_to_uma_cb))
- vaapi_wrapper.reset();
+ if (!va_display ||
+ !vaapi_wrapper->Initialize(
+ va_display, mode, profile, report_error_to_uma_cb))
+ vaapi_wrapper = NULL;
- return vaapi_wrapper.Pass();
+ return vaapi_wrapper;
}
void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() {
@@ -151,21 +183,15 @@ void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() {
DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default.";
}
-bool VaapiWrapper::Initialize(CodecMode mode,
+bool VaapiWrapper::Initialize(VADisplay va_display,
+ 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;
- }
-
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;
@@ -198,7 +224,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;
}
@@ -296,7 +322,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_);
@@ -355,6 +381,32 @@ void VaapiWrapper::DestroySurfaces() {
va_context_id_ = VA_INVALID_ID;
}
+bool VaapiWrapper::CreateOutputSurface(unsigned int va_format,
+ const gfx::Size& size,
+ VASurfaceAttrib* va_attribs,
+ size_t num_va_attribs,
+ VASurfaceID* va_surface) {
+ base::AutoLock auto_lock(va_lock_);
+
+ VAStatus va_res = vaCreateSurfaces(va_display_,
+ va_format,
+ size.width(),
+ size.height(),
+ va_surface,
+ 1,
+ va_attribs,
+ num_va_attribs);
+ VA_SUCCESS_OR_RETURN(va_res, "Failed to create output VASurface", false);
+ return true;
+}
+
+void VaapiWrapper::DestroyOutputSurface(VASurfaceID va_surface) {
+ base::AutoLock auto_lock(va_lock_);
+
+ VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface, 1);
+ VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces on output surface failed");
+}
+
bool VaapiWrapper::SubmitBuffer(VABufferType va_buffer_type,
size_t size,
void* buffer) {
@@ -506,25 +558,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) {
@@ -665,10 +698,164 @@ bool VaapiWrapper::DownloadAndDestroyCodedBuffer(VABufferID buffer_id,
return buffer_segment == NULL;
}
+bool VaapiWrapper::PutSurfaceIntoSurface(VASurfaceID va_surface_id_src,
+ const gfx::Size& src_size,
+ VASurfaceID va_surface_id_dest,
+ const gfx::Size& dest_size) {
+ VAProcPipelineParameterBuffer* pipeline_param;
+ VARectangle input_region, output_region;
Pawel Osciak 2014/10/26 13:06:47 Please define variables as late as possible. Here
llandwerlin-old 2014/10/29 13:52:48 Acknowledged.
+
+ // If the source size is changed, we need to reconfigure the VPP
+ // pipeline.
+ if (src_size != vpp_picture_size_) {
+ DeinitializeVpp();
+ if (!InitializeVpp(dest_size))
+ return false;
+ }
+
+ base::AutoLock auto_lock(va_lock_);
Pawel Osciak 2014/10/26 13:06:47 You need the lock for the duration of the entire m
llandwerlin-old 2014/10/29 13:52:48 Acknowledged.
+
+ VA_SUCCESS_OR_RETURN(vaSyncSurface(va_display_, va_surface_id_src),
Pawel Osciak 2014/10/26 13:06:47 I think we could move this even lower to give it m
llandwerlin-old 2014/10/29 13:52:48 That's true, since it's all coming from the GPU, w
+ "Failed syncing surface",
+ false);
+
+ VA_SUCCESS_OR_RETURN(
+ vaMapBuffer(va_display_, va_vpp_buffer_, (void**)&pipeline_param),
Pawel Osciak 2014/10/26 13:06:47 Please no c-style casts. reinterpret_cast.
llandwerlin-old 2014/10/29 13:52:48 Acknowledged.
+ "Couldn't map vpp buffer",
+ false);
+
+ memset(pipeline_param, 0, sizeof *pipeline_param);
+
+ input_region.x = input_region.y = 0;
+ input_region.width = src_size.width();
+ input_region.height = src_size.height();
+ pipeline_param->surface_region = &input_region;
+ pipeline_param->surface = va_surface_id_src;
+ pipeline_param->surface_color_standard = VAProcColorStandardNone;
+
+ output_region.x = output_region.y = 0;
+ output_region.width = dest_size.width();
+ output_region.height = dest_size.height();
+ pipeline_param->output_region = &output_region;
+ pipeline_param->output_background_color = 0xff000000;
+ pipeline_param->output_color_standard = VAProcColorStandardNone;
+
+ VA_SUCCESS_OR_RETURN(vaUnmapBuffer(va_display_, va_vpp_buffer_),
+ "Couldn't unmap vpp buffer",
+ false);
+
+ VA_SUCCESS_OR_RETURN(
+ vaBeginPicture(va_display_, va_vpp_context_, va_surface_id_dest),
+ "Couldn't begin picture",
+ false);
+
+ VA_SUCCESS_OR_RETURN(
+ vaRenderPicture(va_display_, va_vpp_context_, &va_vpp_buffer_, 1),
+ "Couldn't render picture",
+ false);
+
+ VA_SUCCESS_OR_RETURN(vaEndPicture(va_display_, va_vpp_context_),
+ "Couldn't end picture",
+ false);
+
+ return true;
+}
+
+bool VaapiWrapper::InitializeVpp(const gfx::Size& size) {
+ base::AutoLock auto_lock(va_lock_);
+
+ VA_SUCCESS_OR_RETURN(vaCreateConfig(va_display_,
+ VAProfileNone,
+ VAEntrypointVideoProc,
+ NULL,
+ 0,
+ &va_vpp_config_),
+ "Couldn't create config",
+ false);
+
+ VA_SUCCESS_OR_RETURN(vaCreateContext(va_display_,
+ va_vpp_config_,
+ size.width(),
+ size.height(),
+ 0,
+ NULL,
+ 0,
+ &va_vpp_context_),
+ "Couldn't create context",
+ false);
+
+ VA_SUCCESS_OR_RETURN(vaCreateBuffer(va_display_,
+ va_vpp_context_,
+ VAProcPipelineParameterBufferType,
+ sizeof(VAProcPipelineParameterBuffer),
+ 1,
+ NULL,
+ &va_vpp_buffer_),
+ "Couldn't create buffer",
+ false);
+
+ vpp_picture_size_ = size;
+
+ return true;
+}
+
+void VaapiWrapper::DeinitializeVpp() {
+ base::AutoLock auto_lock(va_lock_);
+
+ if (va_vpp_buffer_ != VA_INVALID_ID) {
+ vaDestroyBuffer(va_display_, va_vpp_buffer_);
+ va_vpp_buffer_ = VA_INVALID_ID;
+ }
+ if (va_vpp_context_ != VA_INVALID_ID) {
+ vaDestroyContext(va_display_, va_vpp_context_);
+ va_vpp_context_ = VA_INVALID_ID;
+ }
+ if (va_vpp_config_ != VA_INVALID_ID) {
+ vaDestroyConfig(va_display_, va_vpp_config_);
+ va_vpp_config_ = VA_INVALID_ID;
+ }
+}
+
+#if defined(USE_X11)
+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;
+}
+#endif // USE_X11
+
// 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);
}

Powered by Google App Engine
This is Rietveld 408576698