[vlc-commits] [Git][videolan/vlc][master] 8 commits: drm: move display.c to own directory

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Thu Mar 10 20:30:00 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
a4e68066 by Rémi Denis-Courmont at 2022-03-10T20:16:34+00:00
drm: move display.c to own directory

- - - - -
c44bf904 by Rémi Denis-Courmont at 2022-03-10T20:16:34+00:00
drm: inline trivial function

- - - - -
3b55b7ef by Rémi Denis-Courmont at 2022-03-10T20:16:34+00:00
drm: remove --kms-vlc-chroma

We don't need two ways to force the pixel format, and DRM formats are
more specific (include RGB masks) than VLC's, so stick to those.

- - - - -
8494807e by Rémi Denis-Courmont at 2022-03-10T20:16:34+00:00
drm: do not keep VLC FourCC

This is only used during activation.

- - - - -
9be09307 by Rémi Denis-Courmont at 2022-03-10T20:16:34+00:00
drm: add helpers to map FourCC

This provides all known mappings between VLC and DRM pixel formats.

- - - - -
15be060c by Rémi Denis-Courmont at 2022-03-10T20:16:34+00:00
drm: check & match the RGB masks

Do not assume that the DRM format matches the display source.

- - - - -
f3d03705 by Rémi Denis-Courmont at 2022-03-10T20:16:34+00:00
drm: use vlc_fourcc_drm()

- - - - -
98374a84 by Rémi Denis-Courmont at 2022-03-10T20:16:34+00:00
drm: remove unused structure member

- - - - -


4 changed files:

- modules/video_output/Makefile.am
- modules/video_output/drm_display.c → modules/video_output/drm/display.c
- + modules/video_output/drm/fourcc.c
- + modules/video_output/drm/vlc_drm.h


Changes:

=====================================
modules/video_output/Makefile.am
=====================================
@@ -318,7 +318,10 @@ libkms_plugin_la_SOURCES = video_output/kms.c
 libkms_plugin_la_CFLAGS = $(AM_CFLAGS) $(KMS_CFLAGS)
 libkms_plugin_la_LIBADD = $(KMS_LIBS)
 
-libdrm_display_plugin_la_SOURCES = video_output/drm_display.c
+libdrm_display_plugin_la_SOURCES = \
+	video_output/drm/vlc_drm.h \
+	video_output/drm/fourcc.c \
+	video_output/drm/display.c
 libdrm_display_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(KMS_CFLAGS)
 libdrm_display_plugin_la_LIBADD = $(KMS_LIBS)
 if HAVE_KMS


=====================================
modules/video_output/drm_display.c → modules/video_output/drm/display.c
=====================================
@@ -45,6 +45,7 @@
 #include <vlc_picture_pool.h>
 #include <vlc_fs.h>
 #include <vlc_vout_window.h>
+#include "vlc_drm.h"
 
 #include <assert.h>
 
@@ -52,9 +53,6 @@
  * Local prototypes
  *****************************************************************************/
 
-#define VLC_CHROMA_TEXT "Image format used by VLC"
-#define VLC_CHROMA_LONGTEXT "Chroma fourcc request to VLC for output format"
-
 #define DRM_CHROMA_TEXT "Image format used by DRM"
 #define DRM_CHROMA_LONGTEXT "Chroma fourcc override for DRM framebuffer format selection"
 
@@ -86,7 +84,6 @@ typedef struct vout_display_sys_t {
 
     bool            forced_drm_fourcc;
     uint32_t        drm_fourcc;
-    vlc_fourcc_t    vlc_fourcc;
 
 /*
  * modeset information
@@ -217,7 +214,6 @@ err_destroy:
  * listed in order of preference.
  *
  * fourccmatching::drm DRM fourcc code from drm_fourcc.h
- * fourccmatching::vlc VLC fourcc code from vlc_fourcc.h under title 'Chromas'
  * fourccmatching::plane_id from which plane this DRM fourcc was found
  * fourccmatching::present if this mode was available in HW
  * fourccmatching::isYUV as name suggest..
@@ -225,21 +221,20 @@ err_destroy:
 static struct
 {
     uint32_t     drm;
-    vlc_fourcc_t vlc;
     uint32_t     plane_id;
     bool         present;
     bool         isYUV;
 } fourccmatching[] = {
-    { .drm = DRM_FORMAT_XRGB8888, .vlc = VLC_CODEC_RGB32, .isYUV = false },
-    { .drm = DRM_FORMAT_RGB565, .vlc = VLC_CODEC_RGB16, .isYUV = false },
+    { .drm = DRM_FORMAT_XRGB8888, .isYUV = false },
+    { .drm = DRM_FORMAT_RGB565, .isYUV = false },
 #if defined DRM_FORMAT_P010
-    { .drm = DRM_FORMAT_P010, .vlc = VLC_CODEC_P010, .isYUV = true },
+    { .drm = DRM_FORMAT_P010, .isYUV = true },
 #endif
-    { .drm = DRM_FORMAT_NV12, .vlc = VLC_CODEC_NV12, .isYUV = true },
-    { .drm = DRM_FORMAT_YUYV, .vlc = VLC_CODEC_YUYV, .isYUV = true },
-    { .drm = DRM_FORMAT_YVYU, .vlc = VLC_CODEC_YVYU, .isYUV = true },
-    { .drm = DRM_FORMAT_UYVY, .vlc = VLC_CODEC_UYVY, .isYUV = true },
-    { .drm = DRM_FORMAT_VYUY, .vlc = VLC_CODEC_VYUY, .isYUV = true },
+    { .drm = DRM_FORMAT_NV12, .isYUV = true },
+    { .drm = DRM_FORMAT_YUYV, .isYUV = true },
+    { .drm = DRM_FORMAT_YVYU, .isYUV = true },
+    { .drm = DRM_FORMAT_UYVY, .isYUV = true },
+    { .drm = DRM_FORMAT_VYUY, .isYUV = true },
 };
 
 
@@ -262,8 +257,7 @@ static void CheckFourCCList(uint32_t drmfourcc, uint32_t plane_id)
     }
 }
 
-
-static bool ChromaNegotiation(vout_display_t *vd)
+static vlc_fourcc_t ChromaNegotiation(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
     vout_window_t *wnd = vd->cfg->window;
@@ -281,7 +275,7 @@ static bool ChromaNegotiation(vout_display_t *vd)
 
     drmModeRes *resources = drmModeGetResources(drm_fd);
     if (resources == NULL)
-        return false;
+        return 0;
 
     int crtc_index = -1;
     for (int crtc_id=0; crtc_id < resources->count_crtcs; ++crtc_id)
@@ -356,33 +350,37 @@ static bool ChromaNegotiation(vout_display_t *vd)
             } else {
                 msg_Err(vd, "Couldn't get list of DRM formats");
                 drmModeFreePlaneResources(plane_res);
-                return false;
+                return 0;
             }
         }
         drmModeFreePlaneResources(plane_res);
     }
 
+    vlc_fourcc_t fourcc = vd->source->i_chroma;
+
     if (sys->forced_drm_fourcc) {
         for (c = i = 0; c < ARRAY_SIZE(fourccmatching); c++) {
             if (fourccmatching[c].drm == sys->drm_fourcc) {
-                sys->vlc_fourcc = fourccmatching[c].vlc;
+                fourcc = vlc_fourcc_drm(sys->drm_fourcc);
                 break;
             }
         }
         if (sys->plane_id == 0) {
             msg_Err(vd, "Forced DRM fourcc (%.4s) not available in kernel.",
                     (char*)&sys->drm_fourcc);
-            return false;
+            return 0;
         }
-        return true;
+        return fourcc;
     }
 
     /*
      * favor yuv format according to YUVFormat flag.
      * check for exact match first, then YUVFormat and then !YUVFormat
      */
+    uint_fast32_t drm_fourcc = vlc_drm_format(vd->source);
+
     for (c = i = 0; c < ARRAY_SIZE(fourccmatching); c++) {
-        if (fourccmatching[c].vlc == sys->vlc_fourcc) {
+        if (fourccmatching[c].drm == drm_fourcc) {
             if (!sys->forced_drm_fourcc && fourccmatching[c].present) {
                 sys->drm_fourcc = fourccmatching[c].drm;
                 sys->plane_id = fourccmatching[c].plane_id;
@@ -390,14 +388,14 @@ static bool ChromaNegotiation(vout_display_t *vd)
 
             if (!sys->drm_fourcc) {
                 msg_Err(vd, "Forced VLC fourcc (%.4s) not matching anything available in kernel, please set manually",
-                        (char*)&sys->vlc_fourcc);
-                return false;
+                        (char*)&fourcc);
+                return 0;
             }
-            return true;
+            return fourcc;
         }
     }
 
-    YUVFormat = vlc_fourcc_IsYUV(sys->vlc_fourcc);
+    YUVFormat = vlc_fourcc_IsYUV(fourcc);
     for (c = i = 0; c < ARRAY_SIZE(fourccmatching); c++) {
         if (fourccmatching[c].isYUV == YUVFormat
                 && fourccmatching[c].present) {
@@ -406,8 +404,7 @@ static bool ChromaNegotiation(vout_display_t *vd)
                 sys->plane_id = fourccmatching[c].plane_id;
              }
 
-            sys->vlc_fourcc = fourccmatching[c].vlc;
-            return true;
+            return vlc_fourcc_drm(fourccmatching[c].drm);
         }
     }
 
@@ -419,12 +416,11 @@ static bool ChromaNegotiation(vout_display_t *vd)
                 sys->plane_id = fourccmatching[c].plane_id;
              }
 
-            sys->vlc_fourcc = fourccmatching[c].vlc;
-            return true;
+            return vlc_fourcc_drm(fourccmatching[c].drm);
         }
     }
 
-    return false;
+    return 0;
 }
 
 static void CustomDestroyPicture(vout_display_t *vd)
@@ -433,19 +429,6 @@ static void CustomDestroyPicture(vout_display_t *vd)
         DestroyFB(vd, c);
 }
 
-static int OpenDisplay(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (!ChromaNegotiation(vd))
-        return VLC_EGENERIC;
-
-    msg_Dbg(vd, "Using VLC chroma '%.4s', DRM chroma '%.4s'",
-            (char*)&sys->vlc_fourcc, (char*)&sys->drm_fourcc);
-    return VLC_SUCCESS;
-}
-
-
 static int Control(vout_display_t *vd, int query)
 {
     (void) vd;
@@ -528,7 +511,6 @@ static int Open(vout_display_t *vd,
                 video_format_t *fmtp, vlc_video_context *context)
 {
     vout_display_sys_t *sys;
-    vlc_fourcc_t local_vlc_chroma;
     uint32_t local_drm_chroma;
     video_format_t fmt = {};
     char *chroma;
@@ -543,25 +525,6 @@ static int Open(vout_display_t *vd,
     if (!sys)
         return VLC_ENOMEM;
 
-    chroma = var_InheritString(vd, "kms-vlc-chroma");
-    if (chroma) {
-        local_vlc_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma);
-
-        if (local_vlc_chroma) {
-            sys->vlc_fourcc = local_vlc_chroma;
-            msg_Dbg(vd, "Forcing VLC to use chroma '%4s'", chroma);
-         } else {
-            sys->vlc_fourcc = vd->source->i_chroma;
-            msg_Dbg(vd, "Chroma %4s invalid, using default", chroma);
-         }
-
-        free(chroma);
-        chroma = NULL;
-    } else {
-        sys->vlc_fourcc = vd->source->i_chroma;
-        msg_Dbg(vd, "Chroma not defined, using default");
-    }
-
     chroma = var_InheritString(vd, "kms-drm-chroma");
     if (chroma) {
         local_drm_chroma = VLC_FOURCC(chroma[0], chroma[1], chroma[2],
@@ -579,11 +542,15 @@ static int Open(vout_display_t *vd,
         chroma = NULL;
     }
 
-    if (OpenDisplay(vd) != VLC_SUCCESS) {
+    vlc_fourcc_t fourcc = ChromaNegotiation(vd);
+    if (!fourcc) {
         Close(vd);
         return VLC_EGENERIC;
     }
 
+    msg_Dbg(vd, "Using VLC chroma '%.4s', DRM chroma '%.4s'",
+            (char*)&fourcc, (char*)&sys->drm_fourcc);
+
     video_format_ApplyRotation(&fmt, vd->fmt);
 
     sys->width  = fmt.i_visible_width;
@@ -601,7 +568,7 @@ static int Open(vout_display_t *vd,
     picture_resource_t rsc = { 0 };
     fmt.i_width = fmt.i_visible_width  = sys->width;
     fmt.i_height = fmt.i_visible_height = sys->height;
-    fmt.i_chroma = sys->vlc_fourcc;
+    fmt.i_chroma = fourcc;
 
     sys->picture = picture_NewFromResource(&fmt, &rsc);
 
@@ -633,7 +600,7 @@ vlc_module_begin ()
     add_shortcut("drm", "kms_drm", "kms")
     set_subcategory(SUBCAT_VIDEO_VOUT)
 
-    add_string( "kms-vlc-chroma", NULL, VLC_CHROMA_TEXT, VLC_CHROMA_LONGTEXT)
+    add_obsolete_string("kms-vlc-chroma") /* since 4.0.0 */
     add_string( "kms-drm-chroma", NULL, DRM_CHROMA_TEXT, DRM_CHROMA_LONGTEXT)
     set_description("Direct rendering management video output")
     set_callback_display(Open, 30)


=====================================
modules/video_output/drm/fourcc.c
=====================================
@@ -0,0 +1,248 @@
+/**
+ * @file fourcc.c
+ * @brief DRM FourCC's
+ */
+/*****************************************************************************
+ * Copyright © 2022 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdint.h>
+#include <drm_fourcc.h>
+#include <vlc_common.h>
+#include <vlc_es.h>
+#include "vlc_drm.h"
+
+/*
+ For reference, the last time these tables were updated, the following DRM
+ pixel formats had no equivalents in VLC, and there are no urges to add them:
+   DRM_FORMAT_XRGB16161616F
+   DRM_FORMAT_XBGR16161616F
+   DRM_FORMAT_ARGB16161616F
+   DRM_FORMAT_ABGR16161616F
+   DRM_FORMAT_ARGB4444
+   DRM_FORMAT_ABGR4444
+   DRM_FORMAT_RGBA4444
+   DRM_FORMAT_BGRA4444
+   DRM_FORMAT_ARGB1555
+   DRM_FORMAT_ABGR1555
+   DRM_FORMAT_RGBA5551
+   DRM_FORMAT_BGRA5551
+   DRM_FORMAT_RGBA8888 (VLC_CODEC_ABGR, not defined)
+   DRM_FORMAT_XRGB2101010
+   DRM_FORMAT_XBGR2101010
+   DRM_FORMAT_RGBX1010102
+   DRM_FORMAT_BGRX1010102
+   DRM_FORMAT_ARGB2101010
+   DRM_FORMAT_RGBA1010102
+   DRM_FORMAT_BGRA1010102
+   DRM_FORMAT_AXBXGXRX106106106106
+   DRM_FORMAT_XYUV8888
+   DRM_FORMAT_VUY888 (VLC_CODEC_V308, not a pixel format)
+   DRM_FORMAT_Y210 (*not* the same as VLC_CODEC_Y210)
+   DRM_FORMAT_Y212
+   DRM_FORMAT_Y216
+   DRM_FORMAT_Y410 (*not* the same as VLC_CODEC_Y410)
+   DRM_FORMAT_Y412
+   DRM_FORMAT_Y416
+   DRM_FORMAT_XVYU2101010
+   DRM_FORMAT_XVYU12_16161616
+   DRM_FORMAT_XVYU16161616
+   DRM_FORMAT_P210
+   DRM_FORMAT_P010 (*not* the same as VLC_CODEC_P010, MSB instead of LSB)
+   DRM_FORMAT_P012
+   DRM_FORMAT_Q410 (*not* the same as VLC_CODEC_I444_10L, MSB)
+   DRM_FORMAT_Q401
+   DRM_FORMAT_YVU411
+   DRM_FORMAT_YVU422
+   DRM_FORMAT_YVU444
+
+ These DRM formats are semiplanar RGB/A:
+   DRM_FORMAT_XRGB8888_A8
+   DRM_FORMAT_XBGR8888_A8
+   DRM_FORMAT_RGBX8888_A8
+   DRM_FORMAT_BGRX8888_A8
+   DRM_FORMAT_RGB888_A8
+   DRM_FORMAT_BGR888_A8
+   DRM_FORMAT_RGB565_A8
+   DRM_FORMAT_BGR565_A8
+
+ These DRM formats are used for planes within a multiplanar buffer:
+   DRM_FORMAT_C8
+   DRM_FORMAT_R8
+   DRM_FORMAT_R16
+   DRM_FORMAT_RG88
+   DRM_FORMAT_GR88
+   DRM_FORMAT_RG1616
+   DRM_FORMAT_GR1616
+
+ These DRM formats are not usable linearly, meaning they can only be used for
+ tiled opaque buffers. VLC cannot define them as non-opaque formats:
+   DRM_FORMAT_VUY101010
+   DRM_FORMAT_Y0L0
+   DRM_FORMAT_X0L0
+   DRM_FORMAT_Y0L2
+   DRM_FORMAT_X0L2
+   DRM_FORMAT_YUV420_8BIT
+   DRM_FORMAT_YUV420_10BIT
+   DRM_FORMAT_NV15
+
+ */
+
+/* RGB (no alpha) formats.
+ * For historical reasons, VLC uses same FourCC with different masks. */
+static const struct {
+    uint32_t drm_fourcc;
+    vlc_fourcc_t vlc_fourcc;
+    uint32_t red; /**< Little endian red mask */
+    uint32_t green; /**< Little endian green mask */
+    uint32_t blue; /**< Little endian blue mask */
+} rgb_fourcc_list[] = {
+    /* 8-bit RGB */
+    { DRM_FORMAT_RGB332,   VLC_CODEC_RGB8, 0xD0, 0x16, 0x03 },
+    { DRM_FORMAT_BGR233,   VLC_CODEC_RGB8, 0x07, 0x28, 0xC0 },
+#ifdef WORDS_BIGENDIAN
+    /* 16-bit-padded 12-bit RGB */
+    { DRM_FORMAT_XRGB4444, VLC_CODEC_RGB12, 0x000F, 0xF000, 0x0F00 },
+    { DRM_FORMAT_XBGR4444, VLC_CODEC_RGB12, 0x0F00, 0xF000, 0x000F },
+    { DRM_FORMAT_RGBX4444, VLC_CODEC_RGB12, 0x00F0, 0x000F, 0xF000 },
+    { DRM_FORMAT_BGRX4444, VLC_CODEC_RGB12, 0xF000, 0x000F, 0x00F0 },
+    /* 24-bit RGB */
+    { DRM_FORMAT_RGB888,   VLC_CODEC_RGB24, 0x0000FF, 0x00FF00, 0xFF0000 },
+    { DRM_FORMAT_BGR888,   VLC_CODEC_RGB24, 0xFF0000, 0x00FF00, 0x0000FF },
+    /* 32-bit-padded 24-bit RGB */
+    { DRM_FORMAT_XRGB8888, VLC_CODEC_RGB32,
+                                          0x0000FF00, 0x00FF0000, 0xFF000000 },
+    { DRM_FORMAT_XBGR8888, VLC_CODEC_RGB32,
+                                          0xFF000000, 0x00FF0000, 0x0000FF00 },
+    { DRM_FORMAT_RGBX8888, VLC_CODEC_RGB32,
+                                          0x000000FF, 0x0000FF00, 0x00FF0000 },
+    { DRM_FORMAT_BGRX8888, VLC_CODEC_RGB32,
+                                          0x00FF0000, 0x0000FF00, 0x000000FF },
+#else
+    /* 16-bit-padded 12-bit RGB */
+    { DRM_FORMAT_XRGB4444, VLC_CODEC_RGB12, 0x0F00, 0x00F0, 0x000F },
+    { DRM_FORMAT_XBGR4444, VLC_CODEC_RGB12, 0x000F, 0x00F0, 0x0F00 },
+    { DRM_FORMAT_RGBX4444, VLC_CODEC_RGB12, 0xF000, 0x0F00, 0x00F0 },
+    { DRM_FORMAT_BGRX4444, VLC_CODEC_RGB12, 0x00F0, 0x0F00, 0xF000 },
+    /* 16-bit-padded 15-bit RGB */
+    { DRM_FORMAT_XRGB1555, VLC_CODEC_RGB15, 0x7C00, 0x03E0, 0x001F },
+    { DRM_FORMAT_XBGR1555, VLC_CODEC_RGB15, 0x001F, 0x03E0, 0x7C00 },
+    { DRM_FORMAT_RGBX5551, VLC_CODEC_RGB15, 0xF800, 0x07C0, 0x003E },
+    { DRM_FORMAT_BGRX5551, VLC_CODEC_RGB15, 0x003E, 0x07C0, 0xF800 },
+    /* 16-bit RGB */
+    { DRM_FORMAT_RGB565,   VLC_CODEC_RGB16, 0xF800, 0x07E0, 0x001F },
+    { DRM_FORMAT_BGR565,   VLC_CODEC_RGB16, 0x001F, 0x07E0, 0xF800 },
+    /* 24-bit RGB */
+    { DRM_FORMAT_RGB888,   VLC_CODEC_RGB24, 0xFF0000, 0x00FF00, 0x0000FF },
+    { DRM_FORMAT_BGR888,   VLC_CODEC_RGB24, 0x0000FF, 0x00FF00, 0xFF0000 },
+    /* 32-bit-padded 24-bit RGB */
+    { DRM_FORMAT_XRGB8888, VLC_CODEC_RGB32,
+                                          0x00FF0000, 0x0000FF00, 0x000000FF },
+    { DRM_FORMAT_XBGR8888, VLC_CODEC_RGB32,
+                                          0x000000FF, 0x0000FF00, 0x00FF0000 },
+    { DRM_FORMAT_RGBX8888, VLC_CODEC_RGB32,
+                                          0xFF000000, 0x00FF0000, 0x0000FF00 },
+    { DRM_FORMAT_BGRX8888, VLC_CODEC_RGB32,
+                                          0x0000FF00, 0x00FF0000, 0xFF000000 },
+#endif
+};
+
+static const struct {
+    uint32_t drm_fourcc;
+    vlc_fourcc_t vlc_fourcc;
+} fourcc_list[] = {
+    /* Beware: DRM uses little endian while VLC uses big endian */
+    /* RGBA formats */
+    { DRM_FORMAT_ARGB8888, VLC_CODEC_BGRA },
+    { DRM_FORMAT_ABGR8888, VLC_CODEC_RGBA },
+    { DRM_FORMAT_BGRA8888, VLC_CODEC_ARGB },
+#ifndef WORDS_BIGENDIAN
+    { DRM_FORMAT_ABGR2101010, VLC_CODEC_RGBA10 },
+#endif
+
+    /* Packed YUV formats */
+    /* DRM uses big-endian for YUY2, otherwise little endian. */
+    { DRM_FORMAT_YUYV,     VLC_CODEC_YUYV },
+    { DRM_FORMAT_YVYU,     VLC_CODEC_YVYU },
+    { DRM_FORMAT_UYVY,     VLC_CODEC_UYVY },
+    { DRM_FORMAT_VYUY,     VLC_CODEC_VYUY },
+
+    /* Packed YUVA */
+    { DRM_FORMAT_AYUV,     VLC_CODEC_VUYA },
+
+    /* Semiplanar YUV */
+    { DRM_FORMAT_NV12,     VLC_CODEC_NV12 },
+    { DRM_FORMAT_NV21,     VLC_CODEC_NV21 },
+    { DRM_FORMAT_NV16,     VLC_CODEC_NV16 },
+    { DRM_FORMAT_NV61,     VLC_CODEC_NV61 },
+    { DRM_FORMAT_NV24,     VLC_CODEC_NV24 },
+    { DRM_FORMAT_NV42,     VLC_CODEC_NV42 },
+#ifndef WORDS_BIGENDIAN
+    { DRM_FORMAT_P016,     VLC_CODEC_P016 },
+#endif
+
+    /* Planar YUV */
+    { DRM_FORMAT_YUV410,   VLC_CODEC_I410 },
+    { DRM_FORMAT_YVU410,   VLC_CODEC_YV9 },
+    { DRM_FORMAT_YUV411,   VLC_CODEC_I411 },
+    { DRM_FORMAT_YUV420,   VLC_CODEC_I420 },
+    { DRM_FORMAT_YVU420,   VLC_CODEC_YV12 },
+    { DRM_FORMAT_YUV422,   VLC_CODEC_I422 },
+    { DRM_FORMAT_YUV444,   VLC_CODEC_I444 },
+};
+
+uint_fast32_t vlc_drm_fourcc(vlc_fourcc_t vlc_fourcc)
+{
+    for (size_t i = 0; i < ARRAY_SIZE(fourcc_list); i++)
+        if (fourcc_list[i].vlc_fourcc == vlc_fourcc)
+            return fourcc_list[i].drm_fourcc;
+
+    return DRM_FORMAT_INVALID;
+}
+
+uint_fast32_t vlc_drm_format(const video_format_t *restrict fmt)
+{
+    uint_fast32_t drm_fourcc = vlc_drm_fourcc(fmt->i_chroma);
+    if (drm_fourcc != DRM_FORMAT_INVALID)
+        return drm_fourcc;
+
+    for (size_t i = 0; i < ARRAY_SIZE(rgb_fourcc_list); i++)
+        if (rgb_fourcc_list[i].vlc_fourcc == fmt->i_chroma
+         && rgb_fourcc_list[i].red == fmt->i_rmask
+         && rgb_fourcc_list[i].red == fmt->i_gmask
+         && rgb_fourcc_list[i].red == fmt->i_bmask)
+            return rgb_fourcc_list[i].drm_fourcc;
+
+    return DRM_FORMAT_INVALID;
+}
+
+vlc_fourcc_t vlc_fourcc_drm(uint_fast32_t drm_fourcc)
+{
+    for (size_t i = 0; i < ARRAY_SIZE(fourcc_list); i++)
+        if (fourcc_list[i].drm_fourcc == drm_fourcc)
+            return fourcc_list[i].vlc_fourcc;
+
+    for (size_t i = 0; i < ARRAY_SIZE(rgb_fourcc_list); i++)
+        if (rgb_fourcc_list[i].drm_fourcc == drm_fourcc)
+            return rgb_fourcc_list[i].vlc_fourcc;
+
+    return 0;
+}


=====================================
modules/video_output/drm/vlc_drm.h
=====================================
@@ -0,0 +1,60 @@
+/**
+ * @file vlc_drm.h
+ */
+/*****************************************************************************
+ * Copyright © 2022 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdint.h>
+#include <vlc_common.h>
+
+struct video_format_t;
+
+/**
+ * Converts a VLC pixel format to DRM.
+ *
+ * \param vlc_fourcc VLC video format FourCC
+ * \return the corresponding DRM pixel format FourCC or
+ *         DRM_FORMAT_INVALID if not found.
+ * \warning This function cannot handle RGB formats. Use vlc_drm_format().
+ */
+uint_fast32_t vlc_drm_fourcc(vlc_fourcc_t vlc_fourcc);
+
+/**
+ * Converts a VLC video format to DRM.
+ *
+ * This returns the DRM pixel format FourCC for the supplied VLC video format.
+ * Unlike vlc_drm_fourcc(), this function can handle RGB formats, but it
+ * requires a complete VLC format structure.
+ *
+ * \param fmt VLC video format
+ * \return the corresponding DRM pixel format FourCC or
+ *         DRM_FORMAT_INVALID if not found.
+ */
+uint_fast32_t vlc_drm_format(const struct video_format_t *fmt);
+
+/**
+ * Converts a DRM pixel format to VLC.
+ *
+ * \param drm_fourcc DRM pixel format identifier
+ * \return the corresponding VLC pixel format, or 0 if not found.
+ */
+vlc_fourcc_t vlc_fourcc_drm(uint_fast32_t drm_fourcc);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/10c1255662e3729ab65f3abc9c34234b3038acf8...98374a84f40a31cace228e5f4331973365de89b9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/10c1255662e3729ab65f3abc9c34234b3038acf8...98374a84f40a31cace228e5f4331973365de89b9
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list