v4l2codecs: format: Add V4L2_PIX_FMT_NC12
authorRobert Mader <robert.mader@collabora.com>
Fri, 8 Nov 2024 11:38:09 +0000 (12:38 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 19 Dec 2024 20:55:59 +0000 (20:55 +0000)
Which is used by the Raspberry Pi 4 and 5 for 8-bit HEVC. Adding it
here in order to show-case how the V4L2<->DRM translation is
supposed to work.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7355>

subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2format.c

index 55ad6c198ce6153d953aec51172a62eb40d90bb9..382a0bd8077741e382cd960b5598480940a54ce6 100644 (file)
 #define GST_CAT_DEFAULT gstv4l2codecs_debug
 GST_DEBUG_CATEGORY_EXTERN (gstv4l2codecs_debug);
 
+#ifndef V4L2_PIX_FMT_NC12
+#define V4L2_PIX_FMT_NC12 v4l2_fourcc('N', 'C', '1', '2')       /* Y/CbCr 4:2:0 (128b cols) */
+#endif
+
 typedef struct
 {
   guint32 v4l2_pix_fmt;
@@ -45,6 +49,7 @@ static const GstV4l2FormatDesc gst_v4l2_descriptions[] = {
   {V4L2_PIX_FMT_SUNXI_TILED_NV12, GST_VIDEO_FORMAT_NV12_32L32,      DRM_FORMAT_INVALID, DRM_FORMAT_MOD_INVALID, 0},
   {V4L2_PIX_FMT_YUV420M,          GST_VIDEO_FORMAT_I420,            DRM_FORMAT_INVALID, DRM_FORMAT_MOD_INVALID, 0},
   {V4L2_PIX_FMT_YUYV,             GST_VIDEO_FORMAT_YUY2,            DRM_FORMAT_INVALID, DRM_FORMAT_MOD_INVALID, 0},
+  {V4L2_PIX_FMT_NC12,             GST_VIDEO_FORMAT_UNKNOWN,         DRM_FORMAT_NV12,    DRM_FORMAT_MOD_BROADCOM_SAND128, 2},
 };
 /* *INDENT-ON* */
 #define GST_V4L2_FORMAT_DESC_COUNT (G_N_ELEMENTS (gst_v4l2_descriptions))
@@ -193,6 +198,14 @@ gst_v4l2_format_to_dma_drm_info (struct v4l2_format *fmt,
     n_planes = 1;
   }
 
+  if (drm_fourcc == DRM_FORMAT_NV12
+      && drm_mod == DRM_FORMAT_MOD_BROADCOM_SAND128) {
+    out_drm_info->vinfo.offset[1] = pix_mp->height * 128;
+    out_drm_info->vinfo.stride[0] = pix_mp->plane_fmt[0].bytesperline;
+    out_drm_info->vinfo.stride[1] = pix_mp->plane_fmt[0].bytesperline;
+    return TRUE;
+  }
+
   /*
    * When single allocation formats are used for planar formats we need to
    * extrapolate the per-plane stride. Do this check once to prevent