From c7a8e715786f7a76443775015d5a554012382d45 Mon Sep 17 00:00:00 2001 From: EmperorPenguin18 <60635017+EmperorPenguin18@users.noreply.github.com> Date: Thu, 19 Jan 2023 19:25:15 -0500 Subject: [PATCH] hwdec_drmprime: support rpi4_8 and rpi4_10 formats HEVC hardware decode with drm wasn't working on the RPi 4. Mpv would report the image format (rpi4_8 for 8-bit and rpi4_10 for 10-bit) wasn't supported. The change to hwdec_drmprime.c identifies these two formats as NV12 because it functions exactly the same. The change to dmabuf_interop_gl.c adds support for P030 which rpi4_10 uses. These changes were tested on a Pi 4 with this fork of ffmpeg: https://github.com/jc-kynesim/rpi-ffmpeg. Signed-off-by: EmperorPenguin18 <60635017+EmperorPenguin18@users.noreply.github.com> --- video/out/hwdec/dmabuf_interop_gl.c | 3 +++ video/out/hwdec/hwdec_drmprime.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/video/out/hwdec/dmabuf_interop_gl.c b/video/out/hwdec/dmabuf_interop_gl.c index cd62e960ca..4bca008e58 100644 --- a/video/out/hwdec/dmabuf_interop_gl.c +++ b/video/out/hwdec/dmabuf_interop_gl.c @@ -185,6 +185,9 @@ static bool vaapi_gl_map(struct ra_hwdec_mapper *mapper, format[2] = DRM_FORMAT_R8; break; case DRM_FORMAT_P010: +#ifdef DRM_FORMAT_P030 /* Format added in a newer libdrm version than minimum */ + case DRM_FORMAT_P030: +#endif format[0] = DRM_FORMAT_R16; format[1] = DRM_FORMAT_GR1616; break; diff --git a/video/out/hwdec/hwdec_drmprime.c b/video/out/hwdec/hwdec_drmprime.c index 52ac54e30d..8a7c503757 100644 --- a/video/out/hwdec/hwdec_drmprime.c +++ b/video/out/hwdec/hwdec_drmprime.c @@ -167,7 +167,17 @@ static int mapper_init(struct ra_hwdec_mapper *mapper) struct dmabuf_interop_priv *p = mapper->priv; mapper->dst_params = mapper->src_params; - mapper->dst_params.imgfmt = mapper->src_params.hw_subfmt; + + /* + * rpi4_8 and rpi4_10 function identically to NV12. These two pixel + * formats however are not defined in upstream ffmpeg so a string + * comparison is used to identify them instead of a mpv IMGFMT. + */ + const char* fmt_name = mp_imgfmt_to_name(mapper->src_params.hw_subfmt); + if (strcmp(fmt_name, "rpi4_8") == 0 || strcmp(fmt_name, "rpi4_10") == 0) + mapper->dst_params.imgfmt = IMGFMT_NV12; + else + mapper->dst_params.imgfmt = mapper->src_params.hw_subfmt; mapper->dst_params.hw_subfmt = 0; struct ra_imgfmt_desc desc = {0};