Commit 8587b26e authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/vaapi: Remove implicit VAContext and VABuffer allocation on creating VPP VaapiWrapper

VAContext of VaapiWrapper for VPP and VABuffer for BlitSurface are created on
creating (i.e. VaapiWrapper::Create()). On the other hand, VAContext of
VaapiWrapper for other use cases (e.g. video encoding) is created by
VaapiWrapper::CreateContext() or VaapiWrapper::CreateContextAndSurfaces().

This leads a problem that VaapiWrapper for VPP cannot create surfaces because
Context is already created upon calling VaapiWrapper::CreateContextAndSurfaces().

This CL removes the implicit context and buffer allocation on the creation.
Therefore, a creator of VaapiWrapper for VPP has to call CreateContext() or
CreateContextAndSurfaces() if the client wants the VaapiWrapper to create
va surfaces.

Note that an allocation of a buffer for BlitSurface is moved to
VaapiWrapper::BlitSurface(), which is still implicit.

Bug: 1009297, 1005205, 982201
Test: https://appr.tc/?debug=loopback&vsc=vp8&video=maxWidth=640,maxHeight=360,minWidth=640,minHeight=360&debug=loopback
Test: tast run video.EncodeAccelH264* video.DecodeAccel* camera.*
Change-Id: Ida5c4bfa58127674d4e048fedf9749516d89cd98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863056
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707701}
parent 82b7a604
...@@ -135,6 +135,12 @@ std::unique_ptr<VaapiImageProcessor> VaapiImageProcessor::Create( ...@@ -135,6 +135,12 @@ std::unique_ptr<VaapiImageProcessor> VaapiImageProcessor::Create(
return nullptr; return nullptr;
} }
// Size is irrelevant for a VPP context.
if (!vaapi_wrapper->CreateContext(gfx::Size())) {
VLOGF(1) << "Failed to create context for VPP";
return nullptr;
}
// We should restrict the acceptable PortConfig for input and output both to // We should restrict the acceptable PortConfig for input and output both to
// the one returned by GetPlatformVideoFrameLayout(). However, // the one returned by GetPlatformVideoFrameLayout(). However,
// ImageProcessorFactory interface doesn't provide information about what // ImageProcessorFactory interface doesn't provide information about what
......
...@@ -456,6 +456,12 @@ VaapiJpegEncodeAccelerator::Initialize( ...@@ -456,6 +456,12 @@ VaapiJpegEncodeAccelerator::Initialize(
return PLATFORM_FAILURE; return PLATFORM_FAILURE;
} }
// Size is irrelevant for a VPP context.
if (!vpp_vaapi_wrapper->CreateContext(gfx::Size())) {
VLOGF(1) << "Failed to create context for VPP";
return PLATFORM_FAILURE;
}
encoder_task_runner_ = encoder_task_runner_ =
base::CreateSingleThreadTaskRunner({base::ThreadPool(), base::MayBlock(), base::CreateSingleThreadTaskRunner({base::ThreadPool(), base::MayBlock(),
base::TaskPriority::USER_BLOCKING}); base::TaskPriority::USER_BLOCKING});
......
...@@ -163,6 +163,12 @@ bool VaapiMjpegDecodeAccelerator::Initialize( ...@@ -163,6 +163,12 @@ bool VaapiMjpegDecodeAccelerator::Initialize(
return false; return false;
} }
// Size is irrelevant for a VPP context.
if (!vpp_vaapi_wrapper_->CreateContext(gfx::Size())) {
VLOGF(1) << "Failed to create context for VPP";
return false;
}
gpu_memory_buffer_support_ = std::make_unique<gpu::GpuMemoryBufferSupport>(); gpu_memory_buffer_support_ = std::make_unique<gpu::GpuMemoryBufferSupport>();
if (!decoder_thread_.Start()) { if (!decoder_thread_.Start()) {
......
...@@ -645,10 +645,14 @@ void VaapiVideoDecodeAccelerator::AssignPictureBuffers( ...@@ -645,10 +645,14 @@ void VaapiVideoDecodeAccelerator::AssignPictureBuffers(
vpp_vaapi_wrapper_ = VaapiWrapper::Create( vpp_vaapi_wrapper_ = VaapiWrapper::Create(
VaapiWrapper::kVideoProcess, VAProfileNone, VaapiWrapper::kVideoProcess, VAProfileNone,
base::BindRepeating(&ReportToUMA, VAAPI_VPP_ERROR)); base::BindRepeating(&ReportToUMA, VAAPI_VPP_ERROR));
if (!vpp_vaapi_wrapper_) { RETURN_AND_NOTIFY_ON_FAILURE(vpp_vaapi_wrapper_,
VLOGF(1) << "Failed initializing VppVaapiWrapper"; "Failed to initialize VppVaapiWrapper",
NotifyError(PLATFORM_FAILURE); PLATFORM_FAILURE, );
}
// Size is irrelevant for a VPP context.
RETURN_AND_NOTIFY_ON_FAILURE(vpp_vaapi_wrapper_->CreateContext(gfx::Size()),
"Failed to create Context",
PLATFORM_FAILURE, );
} }
for (size_t i = 0; i < buffers.size(); ++i) { for (size_t i = 0; i < buffers.size(); ++i) {
......
...@@ -1412,6 +1412,8 @@ bool VaapiWrapper::CreateContext(const gfx::Size& size) { ...@@ -1412,6 +1412,8 @@ bool VaapiWrapper::CreateContext(const gfx::Size& size) {
// (non-null) IDs until the signature gets updated. // (non-null) IDs until the signature gets updated.
constexpr VASurfaceID* empty_va_surfaces_ids_pointer = nullptr; constexpr VASurfaceID* empty_va_surfaces_ids_pointer = nullptr;
constexpr size_t empty_va_surfaces_ids_size = 0u; constexpr size_t empty_va_surfaces_ids_size = 0u;
// TODO(hiroh): VA_PROGRESSIVE might not ought to be set in VPP case. Think
// about removing it if something wrong happens or it turns out to be wrong.
const VAStatus va_res = const VAStatus va_res =
vaCreateContext(va_display_, va_config_id_, size.width(), size.height(), vaCreateContext(va_display_, va_config_id_, size.width(), size.height(),
VA_PROGRESSIVE, empty_va_surfaces_ids_pointer, VA_PROGRESSIVE, empty_va_surfaces_ids_pointer,
...@@ -1923,6 +1925,19 @@ bool VaapiWrapper::BlitSurface( ...@@ -1923,6 +1925,19 @@ bool VaapiWrapper::BlitSurface(
const scoped_refptr<VASurface>& va_surface_src, const scoped_refptr<VASurface>& va_surface_src,
const scoped_refptr<VASurface>& va_surface_dest) { const scoped_refptr<VASurface>& va_surface_dest) {
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
if (va_buffers_.empty()) {
DCHECK_NE(VA_INVALID_ID, va_context_id_);
// Create a buffer for VPP if it has not been created.
VABufferID buffer_id;
VAStatus va_res = vaCreateBuffer(
va_display_, va_context_id_, VAProcPipelineParameterBufferType,
sizeof(VAProcPipelineParameterBuffer), 1, nullptr, &buffer_id);
VA_SUCCESS_OR_RETURN(va_res, "Couldn't create buffer", false);
DCHECK_NE(buffer_id, VA_INVALID_ID);
va_buffers_.emplace(buffer_id);
}
DCHECK_EQ(va_buffers_.size(), 1u); DCHECK_EQ(va_buffers_.size(), 1u);
VABufferID buffer_id = *va_buffers_.begin(); VABufferID buffer_id = *va_buffers_.begin();
{ {
...@@ -2043,25 +2058,6 @@ bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) { ...@@ -2043,25 +2058,6 @@ bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) {
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 failed", false);
if (mode != kVideoProcess)
return true;
// Creates context and buffer here in the case of kVideoProcess.
constexpr size_t kIrrelevantWidth = 0;
constexpr size_t kIrrelevantHeight = 0;
va_res = vaCreateContext(va_display_, va_config_id_, kIrrelevantWidth,
kIrrelevantHeight, 0, NULL, 0, &va_context_id_);
VA_SUCCESS_OR_RETURN(va_res, "Couldn't create context", false);
VABufferID buffer_id;
va_res = vaCreateBuffer(
va_display_, va_context_id_, VAProcPipelineParameterBufferType,
sizeof(VAProcPipelineParameterBuffer), 1, NULL, &buffer_id);
VA_SUCCESS_OR_RETURN(va_res, "Couldn't create buffer", false);
DCHECK_NE(buffer_id, VA_INVALID_ID);
va_buffers_.emplace(buffer_id);
return true; return true;
} }
......
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