vo_drm: add support for YUYV format

As the first aligned format this required a fix to reconfig().

Adding the other component-swapped formats in this group would be trivial
but I checked the DRM database [1] and no driver exists that supports
one of those but not YUYV and this is quite fringe as-is, so I opted not to.

[1] <https://drmdb.emersion.fr/formats>
This commit is contained in:
sfan5 2024-03-11 20:46:00 +01:00
parent bc8038cffd
commit aa75a0e9d2
4 changed files with 29 additions and 15 deletions

View File

@ -627,17 +627,20 @@ Available video output drivers are:
lower resolution (the video when handled by the hwdec will be on the
drmprime-video plane and at full 4K resolution)
``--drm-format=<xrgb8888|xrgb2101010>``
``--drm-format=<xrgb8888|xbgr8888|xrgb2101010|xbgr2101010|yuyv>``
Select the DRM format to use (default: xrgb8888). This allows you to
choose the bit depth of the DRM mode. xrgb8888 is your usual 24 bit per
pixel/8 bits per channel packed RGB format with 8 bits of padding.
xrgb2101010 is a packed 30 bits per pixel/10 bits per channel packed RGB
format with 2 bits of padding.
choose the bit depth and color type of the DRM mode.
xrgb8888 is your usual 24bpp packed RGB format with 8 bits of padding.
xrgb2101010 is a 30bpp packed RGB format with 2 bits of padding.
yuyv is a 32bpp packed YUV 4:2:2 format. No planar formats are currently
supported.
There are cases when xrgb2101010 will work with the ``drm`` VO, but not
with the ``drm`` backend for the ``gpu`` VO. This is because with the
``gpu`` VO, in addition to requiring support in your DRM driver,
requires support for xrgb2101010 in your EGL driver
requires support for xrgb2101010 in your EGL driver.
yuyv only ever works with the ``drm`` VO.
``--drm-draw-surface-size=<[WxH]>``
Sets the size of the surface used on the draw plane. The surface will

View File

@ -95,7 +95,8 @@ const struct m_sub_options drm_conf = {
{"xrgb8888", DRM_OPTS_FORMAT_XRGB8888},
{"xrgb2101010", DRM_OPTS_FORMAT_XRGB2101010},
{"xbgr8888", DRM_OPTS_FORMAT_XBGR8888},
{"xbgr2101010", DRM_OPTS_FORMAT_XBGR2101010})},
{"xbgr2101010", DRM_OPTS_FORMAT_XBGR2101010},
{"yuyv", DRM_OPTS_FORMAT_YUYV})},
{"drm-draw-surface-size", OPT_SIZE_BOX(draw_surface_size)},
{"drm-vrr-enabled", OPT_CHOICE(vrr_enabled,
{"no", 0}, {"yes", 1}, {"auto", -1})},
@ -106,6 +107,7 @@ const struct m_sub_options drm_conf = {
.drm_atomic = 1,
.draw_plane = DRM_OPTS_PRIMARY_PLANE,
.drmprime_video_plane = DRM_OPTS_OVERLAY_PLANE,
.drm_format = DRM_OPTS_FORMAT_XRGB8888,
},
.size = sizeof(struct drm_opts),
};

View File

@ -23,10 +23,13 @@
#include <xf86drmMode.h>
#include "vo.h"
#define DRM_OPTS_FORMAT_XRGB8888 0
#define DRM_OPTS_FORMAT_XRGB2101010 1
#define DRM_OPTS_FORMAT_XBGR8888 2
#define DRM_OPTS_FORMAT_XBGR2101010 3
enum {
DRM_OPTS_FORMAT_XRGB8888,
DRM_OPTS_FORMAT_XRGB2101010,
DRM_OPTS_FORMAT_XBGR8888,
DRM_OPTS_FORMAT_XBGR2101010,
DRM_OPTS_FORMAT_YUYV,
};
struct framebuffer {
int fd;

View File

@ -43,6 +43,7 @@
pixfmt2imgfmt(MP_SELECT_LE_BE(AV_PIX_FMT_X2RGB10LE, AV_PIX_FMT_X2RGB10BE))
#define IMGFMT_XBGR2101010 \
pixfmt2imgfmt(MP_SELECT_LE_BE(AV_PIX_FMT_X2BGR10LE, AV_PIX_FMT_X2BGR10BE))
#define IMGFMT_YUYV pixfmt2imgfmt(AV_PIX_FMT_YUYV422)
#define BYTES_PER_PIXEL 4
#define BITS_PER_PIXEL 32
@ -131,6 +132,10 @@ static struct framebuffer *setup_framebuffer(struct vo *vo)
p->drm_format = DRM_FORMAT_XBGR8888;
p->imgfmt = IMGFMT_XBGR8888;
break;
case DRM_OPTS_FORMAT_YUYV:
p->drm_format = DRM_FORMAT_YUYV;
p->imgfmt = IMGFMT_YUYV;
break;
default:
if (drm->opts->drm_format != DRM_OPTS_FORMAT_XRGB8888) {
MP_VERBOSE(vo, "Requested format not supported by VO, "
@ -187,14 +192,15 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
vo->dheight = drm->fb->height;
vo_get_src_dst_rects(vo, &p->src, &p->dst, &p->osd);
int w = p->dst.x1 - p->dst.x0;
int h = p->dst.y1 - p->dst.y0;
struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(p->imgfmt);
p->dst.x0 = MP_ALIGN_DOWN(p->dst.x0, fmt.align_x);
p->dst.y0 = MP_ALIGN_DOWN(p->dst.y0, fmt.align_y);
p->sws->src = *params;
p->sws->dst = (struct mp_image_params) {
.imgfmt = p->imgfmt,
.w = w,
.h = h,
.w = mp_rect_w(p->dst),
.h = mp_rect_h(p->dst),
.p_w = 1,
.p_h = 1,
};