Commit dbb57509 authored by Sharif Elcott's avatar Sharif Elcott Committed by Commit Bot

Change Vaapi::SubmitBuffer() to accept a const buffer.

Previously we were casting away const at call sites because vaCreateBuffer
accepts a non-const buffer. However its documentation says that the data
will be copied out, and the implementation does so as well.
We can avoid this by mapping server-side memory via vaMapBuffer and copying
it ourselves, as VaapiWrapper::SubmitVAEncMiscParamBuffer does.

Bug: 844303
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I4d66d0d6ee5e672d22a5dbe4073244515fa1b14d
Reviewed-on: https://chromium-review.googlesource.com/1080495
Commit-Queue: Sharif Elcott <selcott@chromium.org>
Reviewed-by: default avatarPawel Osciak <posciak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564878}
parent 1d29c5f5
......@@ -282,10 +282,7 @@ bool VaapiH264Accelerator::SubmitSlice(const H264PPS* pps,
sizeof(slice_param), &slice_param))
return false;
// Can't help it, blame libva...
void* non_const_ptr = const_cast<uint8_t*>(data);
return vaapi_wrapper_->SubmitBuffer(VASliceDataBufferType, size,
non_const_ptr);
return vaapi_wrapper_->SubmitBuffer(VASliceDataBufferType, size, data);
}
bool VaapiH264Accelerator::SubmitDecode(const scoped_refptr<H264Picture>& pic) {
......
......@@ -382,11 +382,8 @@ void VaapiVideoEncodeAccelerator::SubmitVAEncMiscParamBuffer(
void VaapiVideoEncodeAccelerator::SubmitH264BitstreamBuffer(
scoped_refptr<H264BitstreamBuffer> buffer) {
DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread());
// TODO(crbug.com/844303): use vaMapBuffer in VaapiWrapper::SubmitBuffer()
// instead to avoid this.
void* non_const_ptr = const_cast<uint8_t*>(buffer->data());
if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderDataBufferType,
buffer->BytesInBuffer(), non_const_ptr)) {
buffer->BytesInBuffer(), buffer->data())) {
NOTIFY_ERROR(kPlatformFailureError, "Failed submitting a bitstream buffer");
}
}
......
......@@ -216,9 +216,8 @@ bool VaapiVP8Accelerator::SubmitDecode(
&slice_param))
return false;
void* non_const_ptr = const_cast<uint8_t*>(frame_hdr->data);
if (!vaapi_wrapper_->SubmitBuffer(VASliceDataBufferType,
frame_hdr->frame_size, non_const_ptr))
frame_hdr->frame_size, frame_hdr->data))
return false;
return vaapi_dec_->DecodeVASurface(pic->AsVaapiVP8Picture()->va_surface());
......
......@@ -154,9 +154,8 @@ bool VaapiVP9Accelerator::SubmitDecode(
sizeof(slice_param), &slice_param))
return false;
void* non_const_ptr = const_cast<uint8_t*>(frame_hdr->data);
if (!vaapi_wrapper_->SubmitBuffer(VASliceDataBufferType,
frame_hdr->frame_size, non_const_ptr))
frame_hdr->frame_size, frame_hdr->data))
return false;
return vaapi_dec_->DecodeVASurface(pic->AsVaapiVP9Picture()->va_surface());
......
......@@ -909,14 +909,30 @@ scoped_refptr<VASurface> VaapiWrapper::CreateVASurfaceForPixmap(
bool VaapiWrapper::SubmitBuffer(VABufferType va_buffer_type,
size_t size,
void* buffer) {
const void* buffer) {
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);
size, 1, nullptr, &buffer_id);
VA_SUCCESS_OR_RETURN(va_res, "Failed to create a VA buffer", false);
void* va_buffer_data = nullptr;
va_res = vaMapBuffer(va_display_, buffer_id, &va_buffer_data);
VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed");
if (va_res != VA_STATUS_SUCCESS) {
vaDestroyBuffer(va_display_, buffer_id);
return false;
}
DCHECK(va_buffer_data);
// TODO(selcott): Investigate potentially faster alternatives to memcpy here
// such as libyuv::CopyX and family.
memcpy(va_buffer_data, buffer, size);
va_res = vaUnmapBuffer(va_display_, buffer_id);
VA_LOG_ON_ERROR(va_res, "vaUnmapBuffer failed");
switch (va_buffer_type) {
case VASliceParameterBufferType:
case VASliceDataBufferType:
......
......@@ -122,7 +122,9 @@ class MEDIA_GPU_EXPORT VaapiWrapper
// Data submitted via this method awaits in the HW codec until
// ExecuteAndDestroyPendingBuffers() is called to execute or
// DestroyPendingBuffers() is used to cancel a pending job.
bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer);
bool SubmitBuffer(VABufferType va_buffer_type,
size_t size,
const void* buffer);
// Submit a VAEncMiscParameterBuffer of given |misc_param_type|, copying its
// data from |buffer| of size |size|, into HW codec. The data in |buffer| is
......
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