From ef56c0c20a6f94bfc4b9f2d5880a16933835283b Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Sun, 10 Dec 2023 21:00:42 +0800 Subject: [PATCH] hwdec_drmprime: try and declare support for weird forked ffmpeg formats As a result of the work I did the explicitly check for formats supported by the vo in the f_autoconvert logic, I introduced a regression in the handling of the rpi4_8 and rpi4_10 formats. These require special handling because they only exist in the rpi forks and not upstream ffmpeg, which means they don't have stable pix fmt values that we can use directly. Previously, we simply didn't declare them as supported, which was ok, as nothing was really enforcing the list of supported formats, but that has changed. As we still can't simply use the pix fmts, I had to do a slightly ridiculous dance to look them up by name, and if they exist, then register them as supported. Good times. --- video/out/hwdec/hwdec_drmprime.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/video/out/hwdec/hwdec_drmprime.c b/video/out/hwdec/hwdec_drmprime.c index f7c6250cb6..a5f9c664fb 100644 --- a/video/out/hwdec/hwdec_drmprime.c +++ b/video/out/hwdec/hwdec_drmprime.c @@ -23,6 +23,7 @@ #include #include +#include #include #include "config.h" @@ -64,6 +65,18 @@ const static dmabuf_interop_init interop_inits[] = { NULL }; +/** + * Due to the fact that Raspberry Pi support only exists in forked ffmpegs and + * also requires custom pixel formats, we need some way to work with those formats + * without introducing any build time dependencies. We do this by looking up the + * pixel formats by name. As rpi is an important target platform for this hwdec + * we don't really have the luxury of ignoring these forks. + */ +const static char *forked_pix_fmt_names[] = { + "rpi4_8", + "rpi4_10", +}; + static int init(struct ra_hwdec *hw) { struct priv_owner *p = hw->priv; @@ -119,6 +132,14 @@ static int init(struct ra_hwdec *hw) MP_TARRAY_APPEND(p, p->formats, num_formats, IMGFMT_NV12); MP_TARRAY_APPEND(p, p->formats, num_formats, IMGFMT_420P); MP_TARRAY_APPEND(p, p->formats, num_formats, pixfmt2imgfmt(AV_PIX_FMT_NV16)); + + for (int i = 0; i < MP_ARRAY_SIZE(forked_pix_fmt_names); i++) { + enum AVPixelFormat fmt = av_get_pix_fmt(forked_pix_fmt_names[i]); + if (fmt != AV_PIX_FMT_NONE) { + MP_TARRAY_APPEND(p, p->formats, num_formats, pixfmt2imgfmt(fmt)); + } + } + MP_TARRAY_APPEND(p, p->formats, num_formats, 0); // terminate it p->hwctx.hw_imgfmt = IMGFMT_DRMPRIME;