From fa1f042d1d9564a699e715b796de7279e9eda94f Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 25 Jan 2022 14:04:13 -0500 Subject: [PATCH] video: Add an helper to extrapolate strides 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: --- .../gst-libs/gst/video/video-format.c | 38 ++++++++++++++++++++++ .../gst-libs/gst/video/video-format.h | 4 +++ 2 files changed, 42 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 b90d534..dae117d 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 @@ -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; 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 8ce34c6..c67659d 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 @@ -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 -- 2.7.4