video: Add a helper to get the tile size information
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 12 Apr 2022 16:14:03 +0000 (12:14 -0400)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 2 May 2022 19:10:43 +0000 (19:10 +0000)
Since the addition of tiling format with subsampled tile size
(NV12_16L32S), getting the tile width/height shifts and tile
size have become more complex. Add a helper to extract and
scale this information for the selected plane and format.

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

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

index 286051f..e033d38 100644 (file)
@@ -7895,3 +7895,62 @@ gst_video_make_raw_caps_with_features (const GstVideoFormat formats[],
 
   return caps;
 }
+
+static void
+scale_tile_shifts (const GstVideoFormatInfo * finfo, gint plane, guint * ws,
+    guint * hs)
+{
+  gint comp[GST_VIDEO_MAX_COMPONENTS];
+  gint i;
+
+  gst_video_format_info_component (finfo, plane, comp);
+
+  /* scale the tile size according to the subsampling */
+  *ws -= finfo->w_sub[comp[0]];
+  *hs -= finfo->h_sub[comp[0]];
+
+  /* for each additional component in the same plane, double the tile width,
+   * this should provide the appropriate tile size when the tile size varies
+   * base on the subsampling. */
+  for (i = 1; i < GST_VIDEO_MAX_COMPONENTS && comp[i] >= 0; i++)
+    *ws += 1;
+}
+
+/**
+ * gst_video_format_info_get_tile_sizes:
+ * @finfo: #GstVideoFormatInfo
+ * @plane: The plane to read the tile sizes for.
+ * @out_ws: (nullable): Set to the scaled tile width shift
+ * @out_hs: (nullable): Set to the scaled tile height shift
+ *
+ * This function will read the width and height tile dimension shifts from
+ * @info and scale it according to the tiling type and @plane. The results
+ * will written into @out_hs and @out_ws. It also computes the size of a tile
+ * in bytes.
+ *
+ * Returns: The size of a tile in bytes.
+ *
+ * Since: 1.22
+ */
+guint
+gst_video_format_info_get_tile_sizes (const GstVideoFormatInfo * finfo,
+    guint plane, guint * out_ws, guint * out_hs)
+{
+  guint ws, hs;
+
+  g_return_val_if_fail (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo), 0);
+
+  ws = GST_VIDEO_FORMAT_INFO_TILE_WS (finfo);
+  hs = GST_VIDEO_FORMAT_INFO_TILE_HS (finfo);
+
+  if (GST_VIDEO_FORMAT_INFO_HAS_SUBTILES (finfo))
+    scale_tile_shifts (finfo, plane, &ws, &hs);
+
+  if (out_ws)
+    *out_ws = ws;
+
+  if (out_hs)
+    *out_hs = hs;
+
+  return 1 << (ws + hs);
+}
index 9a0f18c..da78552 100644 (file)
@@ -861,6 +861,13 @@ GST_VIDEO_API
 GstCaps * gst_video_make_raw_caps_with_features (const GstVideoFormat formats[], guint len,
                                                  GstCapsFeatures * features);
 
+GST_VIDEO_API
+guint     gst_video_format_info_get_tile_sizes  (const GstVideoFormatInfo * finfo,
+                                                 guint plane,
+                                                 guint * out_ws, guint * out_hs);
+
+
+
 G_END_DECLS
 
 #endif /* __GST_VIDEO_FORMAT_H__ */