Commit 22bb62f9 authored by Alexandre Courbot's avatar Alexandre Courbot Committed by Commit Bot

media/gpu/v4l2svda: add GL-related members

As we are about to introduce image processor support in the v4l2svda, a
few members describing the output frame's format may now refer to the
GL-capable device instead of the decoder.

Add these members and use them where appropriate - since IP support is
still lacking, for now they will always hold the same values as their
decoder's counterpart.

The V4L2VDA does something similar, albeit for EGL.

Bug: b:132589320
Test: vdaunittest and vdatests pass on Minnie.

Change-Id: I66ac72edeb0de279b30e486d54bd198dcf36a9e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1730733Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarChih-Yu Huang <akahuang@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683916}
parent 42ec4bf0
...@@ -155,6 +155,8 @@ V4L2SliceVideoDecodeAccelerator::V4L2SliceVideoDecodeAccelerator( ...@@ -155,6 +155,8 @@ V4L2SliceVideoDecodeAccelerator::V4L2SliceVideoDecodeAccelerator(
egl_display_(egl_display), egl_display_(egl_display),
bind_image_cb_(bind_image_cb), bind_image_cb_(bind_image_cb),
make_context_current_cb_(make_context_current_cb), make_context_current_cb_(make_context_current_cb),
gl_image_format_fourcc_(0),
gl_image_planes_count_(0),
weak_this_factory_(this) { weak_this_factory_(this) {
weak_this_ = weak_this_factory_.GetWeakPtr(); weak_this_ = weak_this_factory_.GetWeakPtr();
} }
...@@ -455,6 +457,9 @@ bool V4L2SliceVideoDecodeAccelerator::SetupFormats() { ...@@ -455,6 +457,9 @@ bool V4L2SliceVideoDecodeAccelerator::SetupFormats() {
if (output_format_fourcc_ == 0) { if (output_format_fourcc_ == 0) {
VLOGF(1) << "Could not find a usable output format"; VLOGF(1) << "Could not find a usable output format";
return false; return false;
} else {
gl_image_format_fourcc_ = output_format_fourcc_;
gl_image_device_ = device_;
} }
// Only set fourcc for output; resolution, etc., will come from the // Only set fourcc for output; resolution, etc., will come from the
...@@ -468,6 +473,7 @@ bool V4L2SliceVideoDecodeAccelerator::SetupFormats() { ...@@ -468,6 +473,7 @@ bool V4L2SliceVideoDecodeAccelerator::SetupFormats() {
DCHECK_EQ(V4L2Device::GetNumPlanesOfV4L2PixFmt(output_format_fourcc_), static_cast<size_t>(format.fmt.pix_mp.num_planes)); DCHECK_EQ(V4L2Device::GetNumPlanesOfV4L2PixFmt(output_format_fourcc_), static_cast<size_t>(format.fmt.pix_mp.num_planes));
output_planes_count_ = format.fmt.pix_mp.num_planes; output_planes_count_ = format.fmt.pix_mp.num_planes;
gl_image_planes_count_ = output_planes_count_;
return true; return true;
} }
...@@ -542,6 +548,8 @@ bool V4L2SliceVideoDecodeAccelerator::CreateOutputBuffers() { ...@@ -542,6 +548,8 @@ bool V4L2SliceVideoDecodeAccelerator::CreateOutputBuffers() {
DCHECK_EQ(coded_size_.width() % 16, 0); DCHECK_EQ(coded_size_.width() % 16, 0);
DCHECK_EQ(coded_size_.height() % 16, 0); DCHECK_EQ(coded_size_.height() % 16, 0);
gl_image_size_ = coded_size_;
if (!gfx::Rect(coded_size_).Contains(gfx::Rect(pic_size))) { if (!gfx::Rect(coded_size_).Contains(gfx::Rect(pic_size))) {
VLOGF(1) << "Got invalid adjusted coded size: " << coded_size_.ToString(); VLOGF(1) << "Got invalid adjusted coded size: " << coded_size_.ToString();
return false; return false;
...@@ -552,7 +560,7 @@ bool V4L2SliceVideoDecodeAccelerator::CreateOutputBuffers() { ...@@ -552,7 +560,7 @@ bool V4L2SliceVideoDecodeAccelerator::CreateOutputBuffers() {
<< ", coded size=" << coded_size_.ToString(); << ", coded size=" << coded_size_.ToString();
VideoPixelFormat pixel_format = VideoPixelFormat pixel_format =
V4L2Device::V4L2PixFmtToVideoPixelFormat(output_format_fourcc_); V4L2Device::V4L2PixFmtToVideoPixelFormat(gl_image_format_fourcc_);
child_task_runner_->PostTask( child_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
...@@ -1281,6 +1289,8 @@ void V4L2SliceVideoDecodeAccelerator::AssignPictureBuffersTask( ...@@ -1281,6 +1289,8 @@ void V4L2SliceVideoDecodeAccelerator::AssignPictureBuffersTask(
} }
} }
gl_image_size_ = coded_size_;
const v4l2_memory memory = const v4l2_memory memory =
(output_mode_ == Config::OutputMode::ALLOCATE ? V4L2_MEMORY_MMAP (output_mode_ == Config::OutputMode::ALLOCATE ? V4L2_MEMORY_MMAP
: V4L2_MEMORY_DMABUF); : V4L2_MEMORY_DMABUF);
...@@ -1326,8 +1336,8 @@ void V4L2SliceVideoDecodeAccelerator::AssignPictureBuffersTask( ...@@ -1326,8 +1336,8 @@ void V4L2SliceVideoDecodeAccelerator::AssignPictureBuffersTask(
if (output_mode_ == Config::OutputMode::ALLOCATE) { if (output_mode_ == Config::OutputMode::ALLOCATE) {
std::vector<base::ScopedFD> passed_dmabuf_fds = std::vector<base::ScopedFD> passed_dmabuf_fds =
device_->GetDmabufsForV4L2Buffer(i, output_planes_count_, gl_image_device_->GetDmabufsForV4L2Buffer(
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); i, gl_image_planes_count_, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
if (passed_dmabuf_fds.empty()) { if (passed_dmabuf_fds.empty()) {
NOTIFY_ERROR(PLATFORM_FAILURE); NOTIFY_ERROR(PLATFORM_FAILURE);
return; return;
...@@ -1377,18 +1387,19 @@ void V4L2SliceVideoDecodeAccelerator::CreateGLImageFor( ...@@ -1377,18 +1387,19 @@ void V4L2SliceVideoDecodeAccelerator::CreateGLImageFor(
} }
scoped_refptr<gl::GLImage> gl_image = scoped_refptr<gl::GLImage> gl_image =
device_->CreateGLImage(size, fourcc, passed_dmabuf_fds); gl_image_device_->CreateGLImage(size, fourcc, passed_dmabuf_fds);
if (!gl_image) { if (!gl_image) {
VLOGF(1) << "Could not create GLImage," VLOGF(1) << "Could not create GLImage,"
<< " index=" << buffer_index << " texture_id=" << texture_id; << " index=" << buffer_index << " texture_id=" << texture_id;
NOTIFY_ERROR(PLATFORM_FAILURE); NOTIFY_ERROR(PLATFORM_FAILURE);
return; return;
} }
gl::ScopedTextureBinder bind_restore(device_->GetTextureTarget(), texture_id); gl::ScopedTextureBinder bind_restore(gl_image_device_->GetTextureTarget(),
bool ret = gl_image->BindTexImage(device_->GetTextureTarget()); texture_id);
bool ret = gl_image->BindTexImage(gl_image_device_->GetTextureTarget());
DCHECK(ret); DCHECK(ret);
bind_image_cb_.Run(client_texture_id, device_->GetTextureTarget(), gl_image, bind_image_cb_.Run(client_texture_id, gl_image_device_->GetTextureTarget(),
true); gl_image, true);
decoder_thread_task_runner_->PostTask( decoder_thread_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&V4L2SliceVideoDecodeAccelerator::AssignDmaBufs, base::BindOnce(&V4L2SliceVideoDecodeAccelerator::AssignDmaBufs,
...@@ -1452,7 +1463,7 @@ void V4L2SliceVideoDecodeAccelerator::ImportBufferForPicture( ...@@ -1452,7 +1463,7 @@ void V4L2SliceVideoDecodeAccelerator::ImportBufferForPicture(
for (auto& plane : gpu_memory_buffer_handle.native_pixmap_handle.planes) { for (auto& plane : gpu_memory_buffer_handle.native_pixmap_handle.planes) {
dmabuf_fds.push_back(std::move(plane.fd)); dmabuf_fds.push_back(std::move(plane.fd));
} }
for (size_t i = dmabuf_fds.size() - 1; i >= output_planes_count_; i--) { for (size_t i = dmabuf_fds.size() - 1; i >= gl_image_planes_count_; i--) {
if (gpu_memory_buffer_handle.native_pixmap_handle.planes[i].offset == 0) { if (gpu_memory_buffer_handle.native_pixmap_handle.planes[i].offset == 0) {
VLOGF(1) << "The dmabuf fd points to a new buffer, "; VLOGF(1) << "The dmabuf fd points to a new buffer, ";
NOTIFY_ERROR(INVALID_ARGUMENT); NOTIFY_ERROR(INVALID_ARGUMENT);
...@@ -1471,7 +1482,7 @@ void V4L2SliceVideoDecodeAccelerator::ImportBufferForPicture( ...@@ -1471,7 +1482,7 @@ void V4L2SliceVideoDecodeAccelerator::ImportBufferForPicture(
} }
if (pixel_format != if (pixel_format !=
V4L2Device::V4L2PixFmtToVideoPixelFormat(output_format_fourcc_)) { V4L2Device::V4L2PixFmtToVideoPixelFormat(gl_image_format_fourcc_)) {
VLOGF(1) << "Unsupported import format: " VLOGF(1) << "Unsupported import format: "
<< VideoPixelFormatToString(pixel_format); << VideoPixelFormatToString(pixel_format);
NOTIFY_ERROR(INVALID_ARGUMENT); NOTIFY_ERROR(INVALID_ARGUMENT);
...@@ -1523,10 +1534,11 @@ void V4L2SliceVideoDecodeAccelerator::ImportBufferForPictureTask( ...@@ -1523,10 +1534,11 @@ void V4L2SliceVideoDecodeAccelerator::ImportBufferForPictureTask(
base::BindOnce(&V4L2SliceVideoDecodeAccelerator::CreateGLImageFor, base::BindOnce(&V4L2SliceVideoDecodeAccelerator::CreateGLImageFor,
weak_this_, index, picture_buffer_id, weak_this_, index, picture_buffer_id,
std::move(passed_dmabuf_fds), iter->client_texture_id, std::move(passed_dmabuf_fds), iter->client_texture_id,
iter->texture_id, coded_size_, output_format_fourcc_)); iter->texture_id, gl_image_size_,
gl_image_format_fourcc_));
} else { } else {
// No need for a GLImage, start using this buffer now. // No need for a GLImage, start using this buffer now.
DCHECK_EQ(output_planes_count_, passed_dmabuf_fds.size()); DCHECK_EQ(gl_image_planes_count_, passed_dmabuf_fds.size());
iter->dmabuf_fds = std::move(passed_dmabuf_fds); iter->dmabuf_fds = std::move(passed_dmabuf_fds);
// Buffer is now ready to be used. // Buffer is now ready to be used.
......
...@@ -452,6 +452,15 @@ class MEDIA_GPU_EXPORT V4L2SliceVideoDecodeAccelerator ...@@ -452,6 +452,15 @@ class MEDIA_GPU_EXPORT V4L2SliceVideoDecodeAccelerator
// Callback to set the correct gl context. // Callback to set the correct gl context.
MakeGLContextCurrentCallback make_context_current_cb_; MakeGLContextCurrentCallback make_context_current_cb_;
// The V4L2Device GLImage is created from.
scoped_refptr<V4L2Device> gl_image_device_;
// The format of GLImage.
uint32_t gl_image_format_fourcc_;
// The logical dimensions of GLImage buffer in pixels.
gfx::Size gl_image_size_;
// Number of planes for GLImage.
size_t gl_image_planes_count_;
// The WeakPtrFactory for |weak_this_|. // The WeakPtrFactory for |weak_this_|.
base::WeakPtrFactory<V4L2SliceVideoDecodeAccelerator> weak_this_factory_; base::WeakPtrFactory<V4L2SliceVideoDecodeAccelerator> weak_this_factory_;
......
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