video: Add an helper to extrapolate strides
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 25 Jan 2022 19:04:13 +0000 (14:04 -0500)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sun, 20 Feb 2022 22:32:55 +0000 (22:32 +0000)
Many of the legacy APIs, specifically in the Linux Kernel, have a
single stride for the pictures. In this context, it is common
to extrapolate the other strides based on the selected pixel
format. Such function have been copy pasted from video4linux2
plugin into wayland, kms and v4l2codecs plugins.

This patch implements a generalized from of that function and
make it available to everyone through the video library.

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

subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c
subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h

index b90d534..dae117d 100644 (file)
@@ -7565,6 +7565,44 @@ gst_video_format_info_component (const GstVideoFormatInfo * info, guint plane,
     components[c] = -1;
 }
 
+/**
+ * gst_video_format_info_extrapolate_stride:
+ * @info: #GstVideoFormatInfo
+ * @plane: a plane number
+ * @stride: The fist plane stride
+ *
+ * Extrapolate @plane stride from the first stride of an image. This helper is
+ * useful to support legacy API were only one stride is supported.
+ *
+ * Returns: The extrapolated stride for @plane
+ *
+ * Since: 1.22
+ */
+gint
+gst_video_format_info_extrapolate_stride (const GstVideoFormatInfo * finfo,
+    gint plane, gint stride)
+{
+  gint estride;
+  gint comp[GST_VIDEO_MAX_COMPONENTS];
+  gint i;
+
+  /* there is nothing to extrapolate on first plane */
+  if (plane == 0)
+    return stride;
+
+  gst_video_format_info_component (finfo, plane, comp);
+
+  /* For now, all planar formats have a single component on first plane, but
+   * if there was a planar format with more, we'd have to make a ratio of the
+   * number of component on the first plane against the number of component on
+   * the current plane. */
+  estride = 0;
+  for (i = 0; comp[i] >= 0; i++)
+    estride += GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, comp[i], stride);
+
+  return estride;
+}
+
 struct RawVideoFormats
 {
   GstVideoFormat *formats;
index 8ce34c6..c67659d 100644 (file)
@@ -711,6 +711,10 @@ struct _GstVideoFormatInfo {
 GST_VIDEO_API
 void gst_video_format_info_component                  (const GstVideoFormatInfo *info, guint plane, gint components[GST_VIDEO_MAX_COMPONENTS]);
 
+GST_VIDEO_API
+gint gst_video_format_info_extrapolate_stride        (const GstVideoFormatInfo * finfo,
+                                                      gint plane, gint stride);
+
 /* format properties */
 
 GST_VIDEO_API