From 8fcfc44c15b7420698beada8446f4469c1ed0ee8 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 12 Apr 2022 12:14:03 -0400 Subject: [PATCH] video: Add a helper to get the tile size information 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: --- .../gst-libs/gst/video/video-format.c | 59 ++++++++++++++++++++++ .../gst-libs/gst/video/video-format.h | 7 +++ 2 files changed, 66 insertions(+) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c b/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c index 286051f..e033d38 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c @@ -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); +} diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h b/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h index 9a0f18c..da78552 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h @@ -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__ */ -- 2.7.4