Commit 0581a105 authored by Alexandre Courbot's avatar Alexandre Courbot Committed by Commit Bot

media/gpu/v4l2: pass Fourcc to Create(GL|EGL)Image

Use the Fourcc class instead of uin32_t with the GL/EGL image creation
methods. This simplifies their logic a bit.

BUG=None
TEST=Video plays properly on Hana and Kevin non-VD.

Change-Id: I50ae21d1ce34d3dba4c08bb59887d5f208b41a28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1982348Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728443}
parent b26da86f
...@@ -195,7 +195,7 @@ std::vector<base::ScopedFD> GenericV4L2Device::GetDmabufsForV4L2Buffer( ...@@ -195,7 +195,7 @@ std::vector<base::ScopedFD> GenericV4L2Device::GetDmabufsForV4L2Buffer(
return dmabuf_fds; return dmabuf_fds;
} }
bool GenericV4L2Device::CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) { bool GenericV4L2Device::CanCreateEGLImageFrom(const Fourcc fourcc) {
static uint32_t kEGLImageDrmFmtsSupported[] = { static uint32_t kEGLImageDrmFmtsSupported[] = {
DRM_FORMAT_ARGB8888, DRM_FORMAT_ARGB8888,
#if defined(ARCH_CPU_ARM_FAMILY) #if defined(ARCH_CPU_ARM_FAMILY)
...@@ -207,7 +207,7 @@ bool GenericV4L2Device::CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) { ...@@ -207,7 +207,7 @@ bool GenericV4L2Device::CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) {
return std::find( return std::find(
kEGLImageDrmFmtsSupported, kEGLImageDrmFmtsSupported,
kEGLImageDrmFmtsSupported + base::size(kEGLImageDrmFmtsSupported), kEGLImageDrmFmtsSupported + base::size(kEGLImageDrmFmtsSupported),
V4L2PixFmtToDrmFormat(v4l2_pixfmt)) != V4L2PixFmtToDrmFormat(fourcc.ToV4L2PixFmt())) !=
kEGLImageDrmFmtsSupported + base::size(kEGLImageDrmFmtsSupported); kEGLImageDrmFmtsSupported + base::size(kEGLImageDrmFmtsSupported);
} }
...@@ -217,20 +217,16 @@ EGLImageKHR GenericV4L2Device::CreateEGLImage( ...@@ -217,20 +217,16 @@ EGLImageKHR GenericV4L2Device::CreateEGLImage(
GLuint texture_id, GLuint texture_id,
const gfx::Size& size, const gfx::Size& size,
unsigned int buffer_index, unsigned int buffer_index,
uint32_t v4l2_pixfmt, const Fourcc fourcc,
std::vector<base::ScopedFD>&& dmabuf_fds) { std::vector<base::ScopedFD>&& dmabuf_fds) {
DVLOGF(3); DVLOGF(3);
if (!CanCreateEGLImageFrom(v4l2_pixfmt)) {
if (!CanCreateEGLImageFrom(fourcc)) {
VLOGF(1) << "Unsupported V4L2 pixel format"; VLOGF(1) << "Unsupported V4L2 pixel format";
return EGL_NO_IMAGE_KHR; return EGL_NO_IMAGE_KHR;
} }
const auto vf_format_fourcc = Fourcc::FromV4L2PixFmt(v4l2_pixfmt); const VideoPixelFormat vf_format = fourcc.ToVideoPixelFormat();
if (!vf_format_fourcc) {
VLOGF(1) << "Unrecognized pixel format " << FourccToString(v4l2_pixfmt);
return EGL_NO_IMAGE_KHR;
}
const VideoPixelFormat vf_format = vf_format_fourcc->ToVideoPixelFormat();
// Number of components, as opposed to the number of V4L2 planes, which is // Number of components, as opposed to the number of V4L2 planes, which is
// just a buffer count. // just a buffer count.
size_t num_planes = VideoFrame::NumPlanes(vf_format); size_t num_planes = VideoFrame::NumPlanes(vf_format);
...@@ -248,7 +244,7 @@ EGLImageKHR GenericV4L2Device::CreateEGLImage( ...@@ -248,7 +244,7 @@ EGLImageKHR GenericV4L2Device::CreateEGLImage(
attrs.push_back(EGL_HEIGHT); attrs.push_back(EGL_HEIGHT);
attrs.push_back(size.height()); attrs.push_back(size.height());
attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT); attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT);
attrs.push_back(V4L2PixFmtToDrmFormat(v4l2_pixfmt)); attrs.push_back(V4L2PixFmtToDrmFormat(fourcc.ToV4L2PixFmt()));
// For existing formats, if we have less buffers (V4L2 planes) than // For existing formats, if we have less buffers (V4L2 planes) than
// components (planes), the remaining planes are stored in the last // components (planes), the remaining planes are stored in the last
...@@ -290,16 +286,12 @@ EGLImageKHR GenericV4L2Device::CreateEGLImage( ...@@ -290,16 +286,12 @@ EGLImageKHR GenericV4L2Device::CreateEGLImage(
scoped_refptr<gl::GLImage> GenericV4L2Device::CreateGLImage( scoped_refptr<gl::GLImage> GenericV4L2Device::CreateGLImage(
const gfx::Size& size, const gfx::Size& size,
uint32_t fourcc, const Fourcc fourcc,
std::vector<base::ScopedFD>&& dmabuf_fds) { std::vector<base::ScopedFD>&& dmabuf_fds) {
DVLOGF(3); DVLOGF(3);
DCHECK(CanCreateEGLImageFrom(fourcc)); DCHECK(CanCreateEGLImageFrom(fourcc));
const auto vf_format_fourcc = Fourcc::FromV4L2PixFmt(fourcc);
if (!vf_format_fourcc) { const VideoPixelFormat vf_format = fourcc.ToVideoPixelFormat();
VLOGF(1) << "Unrecognized pixel format " << FourccToString(fourcc);
return nullptr;
}
const VideoPixelFormat vf_format = vf_format_fourcc->ToVideoPixelFormat();
size_t num_planes = VideoFrame::NumPlanes(vf_format); size_t num_planes = VideoFrame::NumPlanes(vf_format);
DCHECK_LE(num_planes, 3u); DCHECK_LE(num_planes, 3u);
DCHECK_LE(dmabuf_fds.size(), num_planes); DCHECK_LE(dmabuf_fds.size(), num_planes);
...@@ -344,7 +336,7 @@ scoped_refptr<gl::GLImage> GenericV4L2Device::CreateGLImage( ...@@ -344,7 +336,7 @@ scoped_refptr<gl::GLImage> GenericV4L2Device::CreateGLImage(
} }
gfx::BufferFormat buffer_format = gfx::BufferFormat::BGRA_8888; gfx::BufferFormat buffer_format = gfx::BufferFormat::BGRA_8888;
switch (fourcc) { switch (fourcc.ToV4L2PixFmt()) {
case DRM_FORMAT_ARGB8888: case DRM_FORMAT_ARGB8888:
buffer_format = gfx::BufferFormat::BGRA_8888; buffer_format = gfx::BufferFormat::BGRA_8888;
break; break;
......
...@@ -43,18 +43,18 @@ class GenericV4L2Device : public V4L2Device { ...@@ -43,18 +43,18 @@ class GenericV4L2Device : public V4L2Device {
size_t num_planes, size_t num_planes,
enum v4l2_buf_type buf_type) override; enum v4l2_buf_type buf_type) override;
bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) override; bool CanCreateEGLImageFrom(const Fourcc fourcc) override;
EGLImageKHR CreateEGLImage(EGLDisplay egl_display, EGLImageKHR CreateEGLImage(EGLDisplay egl_display,
EGLContext egl_context, EGLContext egl_context,
GLuint texture_id, GLuint texture_id,
const gfx::Size& size, const gfx::Size& size,
unsigned int buffer_index, unsigned int buffer_index,
uint32_t v4l2_pixfmt, const Fourcc fourcc,
std::vector<base::ScopedFD>&& dmabuf_fds) override; std::vector<base::ScopedFD>&& dmabuf_fds) override;
scoped_refptr<gl::GLImage> CreateGLImage( scoped_refptr<gl::GLImage> CreateGLImage(
const gfx::Size& size, const gfx::Size& size,
uint32_t fourcc, const Fourcc fourcc,
std::vector<base::ScopedFD>&& dmabuf_fds) override; std::vector<base::ScopedFD>&& dmabuf_fds) override;
EGLBoolean DestroyEGLImage(EGLDisplay egl_display, EGLBoolean DestroyEGLImage(EGLDisplay egl_display,
......
...@@ -216,8 +216,8 @@ std::vector<base::ScopedFD> TegraV4L2Device::GetDmabufsForV4L2Buffer( ...@@ -216,8 +216,8 @@ std::vector<base::ScopedFD> TegraV4L2Device::GetDmabufsForV4L2Buffer(
return dmabuf_fds; return dmabuf_fds;
} }
bool TegraV4L2Device::CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) { bool TegraV4L2Device::CanCreateEGLImageFrom(const Fourcc fourcc) {
return v4l2_pixfmt == V4L2_PIX_FMT_NV12M; return fourcc.ToV4L2PixFmt() == V4L2_PIX_FMT_NV12M;
} }
EGLImageKHR TegraV4L2Device::CreateEGLImage( EGLImageKHR TegraV4L2Device::CreateEGLImage(
...@@ -226,10 +226,11 @@ EGLImageKHR TegraV4L2Device::CreateEGLImage( ...@@ -226,10 +226,11 @@ EGLImageKHR TegraV4L2Device::CreateEGLImage(
GLuint texture_id, GLuint texture_id,
const gfx::Size& /* size */, const gfx::Size& /* size */,
unsigned int buffer_index, unsigned int buffer_index,
uint32_t v4l2_pixfmt, const Fourcc fourcc,
std::vector<base::ScopedFD>&& /* dmabuf_fds */) { std::vector<base::ScopedFD>&& /* dmabuf_fds */) {
DVLOGF(3); DVLOGF(3);
if (!CanCreateEGLImageFrom(v4l2_pixfmt)) {
if (!CanCreateEGLImageFrom(fourcc)) {
LOG(ERROR) << "Unsupported V4L2 pixel format"; LOG(ERROR) << "Unsupported V4L2 pixel format";
return EGL_NO_IMAGE_KHR; return EGL_NO_IMAGE_KHR;
} }
...@@ -251,7 +252,7 @@ EGLImageKHR TegraV4L2Device::CreateEGLImage( ...@@ -251,7 +252,7 @@ EGLImageKHR TegraV4L2Device::CreateEGLImage(
} }
scoped_refptr<gl::GLImage> TegraV4L2Device::CreateGLImage( scoped_refptr<gl::GLImage> TegraV4L2Device::CreateGLImage(
const gfx::Size& size, const gfx::Size& size,
uint32_t fourcc, const Fourcc fourcc,
std::vector<base::ScopedFD>&& dmabuf_fds) { std::vector<base::ScopedFD>&& dmabuf_fds) {
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
......
...@@ -43,17 +43,17 @@ class TegraV4L2Device : public V4L2Device { ...@@ -43,17 +43,17 @@ class TegraV4L2Device : public V4L2Device {
int index, int index,
size_t num_planes, size_t num_planes,
enum v4l2_buf_type buf_type) override; enum v4l2_buf_type buf_type) override;
bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) override; bool CanCreateEGLImageFrom(const Fourcc fourcc) override;
EGLImageKHR CreateEGLImage(EGLDisplay egl_display, EGLImageKHR CreateEGLImage(EGLDisplay egl_display,
EGLContext egl_context, EGLContext egl_context,
GLuint texture_id, GLuint texture_id,
const gfx::Size& size, const gfx::Size& size,
unsigned int buffer_index, unsigned int buffer_index,
uint32_t v4l2_pixfmt, const Fourcc fourcc,
std::vector<base::ScopedFD>&& dmabuf_fds) override; std::vector<base::ScopedFD>&& dmabuf_fds) override;
scoped_refptr<gl::GLImage> CreateGLImage( scoped_refptr<gl::GLImage> CreateGLImage(
const gfx::Size& size, const gfx::Size& size,
uint32_t fourcc, const Fourcc fourcc,
std::vector<base::ScopedFD>&& dmabuf_fds) override; std::vector<base::ScopedFD>&& dmabuf_fds) override;
EGLBoolean DestroyEGLImage(EGLDisplay egl_display, EGLBoolean DestroyEGLImage(EGLDisplay egl_display,
EGLImageKHR egl_image) override; EGLImageKHR egl_image) override;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "media/base/video_decoder_config.h" #include "media/base/video_decoder_config.h"
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "media/base/video_frame_layout.h" #include "media/base/video_frame_layout.h"
#include "media/gpu/chromeos/fourcc.h"
#include "media/gpu/media_gpu_export.h" #include "media/gpu/media_gpu_export.h"
#include "media/gpu/v4l2/v4l2_device_poller.h" #include "media/gpu/v4l2/v4l2_device_poller.h"
#include "media/video/video_decode_accelerator.h" #include "media/video/video_decode_accelerator.h"
...@@ -593,7 +594,7 @@ class MEDIA_GPU_EXPORT V4L2Device ...@@ -593,7 +594,7 @@ class MEDIA_GPU_EXPORT V4L2Device
// Return true if the given V4L2 pixfmt can be used in CreateEGLImage() // Return true if the given V4L2 pixfmt can be used in CreateEGLImage()
// for the current platform. // for the current platform.
virtual bool CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) = 0; virtual bool CanCreateEGLImageFrom(const Fourcc fourcc) = 0;
// Create an EGLImage from provided |dmabuf_fds| and bind |texture_id| to it. // Create an EGLImage from provided |dmabuf_fds| and bind |texture_id| to it.
// Some implementations may also require the V4L2 |buffer_index| of the buffer // Some implementations may also require the V4L2 |buffer_index| of the buffer
...@@ -608,7 +609,7 @@ class MEDIA_GPU_EXPORT V4L2Device ...@@ -608,7 +609,7 @@ class MEDIA_GPU_EXPORT V4L2Device
GLuint texture_id, GLuint texture_id,
const gfx::Size& size, const gfx::Size& size,
unsigned int buffer_index, unsigned int buffer_index,
uint32_t v4l2_pixfmt, const Fourcc fourcc,
std::vector<base::ScopedFD>&& dmabuf_fds) = 0; std::vector<base::ScopedFD>&& dmabuf_fds) = 0;
// Create a GLImage from provided |dmabuf_fds|. // Create a GLImage from provided |dmabuf_fds|.
...@@ -618,7 +619,7 @@ class MEDIA_GPU_EXPORT V4L2Device ...@@ -618,7 +619,7 @@ class MEDIA_GPU_EXPORT V4L2Device
// Return the newly created GLImage. // Return the newly created GLImage.
virtual scoped_refptr<gl::GLImage> CreateGLImage( virtual scoped_refptr<gl::GLImage> CreateGLImage(
const gfx::Size& size, const gfx::Size& size,
uint32_t fourcc, const Fourcc fourcc,
std::vector<base::ScopedFD>&& dmabuf_fds) = 0; std::vector<base::ScopedFD>&& dmabuf_fds) = 0;
// Destroys the EGLImageKHR. // Destroys the EGLImageKHR.
......
...@@ -495,8 +495,9 @@ bool V4L2SliceVideoDecodeAccelerator::SetupFormats() { ...@@ -495,8 +495,9 @@ bool V4L2SliceVideoDecodeAccelerator::SetupFormats() {
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
output_format_fourcc_ = base::nullopt; output_format_fourcc_ = base::nullopt;
while (device_->Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0) { while (device_->Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0) {
if (device_->CanCreateEGLImageFrom(fmtdesc.pixelformat)) { auto fourcc = Fourcc::FromV4L2PixFmt(fmtdesc.pixelformat);
output_format_fourcc_ = Fourcc::FromV4L2PixFmt(fmtdesc.pixelformat); if (fourcc && device_->CanCreateEGLImageFrom(*fourcc)) {
output_format_fourcc_ = fourcc;
break; break;
} }
++fmtdesc.index; ++fmtdesc.index;
...@@ -1471,8 +1472,8 @@ void V4L2SliceVideoDecodeAccelerator::CreateGLImageFor( ...@@ -1471,8 +1472,8 @@ void V4L2SliceVideoDecodeAccelerator::CreateGLImageFor(
return; return;
} }
scoped_refptr<gl::GLImage> gl_image = gl_image_device_->CreateGLImage( scoped_refptr<gl::GLImage> gl_image =
size, fourcc.ToV4L2PixFmt(), std::move(dmabuf_fds)); gl_image_device_->CreateGLImage(size, fourcc, std::move(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;
......
...@@ -53,9 +53,10 @@ base::Optional<Fourcc> FindImageProcessorOutputFormat(V4L2Device* ip_device) { ...@@ -53,9 +53,10 @@ base::Optional<Fourcc> FindImageProcessorOutputFormat(V4L2Device* ip_device) {
preferred_formats_first); preferred_formats_first);
for (uint32_t processor_output_format : processor_output_formats) { for (uint32_t processor_output_format : processor_output_formats) {
if (ip_device->CanCreateEGLImageFrom(processor_output_format)) { auto fourcc = Fourcc::FromV4L2PixFmt(processor_output_format);
if (fourcc && ip_device->CanCreateEGLImageFrom(*fourcc)) {
DVLOGF(3) << "Image processor output format=" << processor_output_format; DVLOGF(3) << "Image processor output format=" << processor_output_format;
return Fourcc::FromV4L2PixFmt(processor_output_format); return fourcc;
} }
} }
......
...@@ -484,7 +484,7 @@ void V4L2VideoDecodeAccelerator::CreateEGLImageFor( ...@@ -484,7 +484,7 @@ void V4L2VideoDecodeAccelerator::CreateEGLImageFor(
EGLImageKHR egl_image = egl_image_device_->CreateEGLImage( EGLImageKHR egl_image = egl_image_device_->CreateEGLImage(
egl_display_, gl_context->GetHandle(), texture_id, size, buffer_index, egl_display_, gl_context->GetHandle(), texture_id, size, buffer_index,
fourcc.ToV4L2PixFmt(), std::move(dmabuf_fds)); fourcc, std::move(dmabuf_fds));
if (egl_image == EGL_NO_IMAGE_KHR) { if (egl_image == EGL_NO_IMAGE_KHR) {
VLOGF(1) << "could not create EGLImageKHR," VLOGF(1) << "could not create EGLImageKHR,"
<< " index=" << buffer_index << " texture_id=" << texture_id; << " index=" << buffer_index << " texture_id=" << texture_id;
...@@ -2325,8 +2325,9 @@ bool V4L2VideoDecodeAccelerator::SetupFormats() { ...@@ -2325,8 +2325,9 @@ bool V4L2VideoDecodeAccelerator::SetupFormats() {
memset(&fmtdesc, 0, sizeof(fmtdesc)); memset(&fmtdesc, 0, sizeof(fmtdesc));
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
while (device_->Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0) { while (device_->Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0) {
if (device_->CanCreateEGLImageFrom(fmtdesc.pixelformat)) { auto fourcc = Fourcc::FromV4L2PixFmt(fmtdesc.pixelformat);
output_format_fourcc_ = Fourcc::FromV4L2PixFmt(fmtdesc.pixelformat); if (fourcc && device_->CanCreateEGLImageFrom(*fourcc)) {
output_format_fourcc_ = *fourcc;
break; break;
} }
++fmtdesc.index; ++fmtdesc.index;
......
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