From 9a2344c2e5fc37c77d7b3211e499c86bc7864de3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 20 Aug 2012 10:50:59 +0200 Subject: [PATCH] video: expose gst_video_info_align Expose the gst_video_info_align function that adds padding and does stride alignment on a GstVideoInfo. Move this previously private function to video-info.co Move the definition of the alignment structure to video.h where it can be picked up by both the bufferpool and the video-info. --- gst-libs/gst/video/gstvideopool.c | 91 ------------------------------- gst-libs/gst/video/gstvideopool.h | 25 --------- gst-libs/gst/video/video-info.c | 81 +++++++++++++++++++++++++++ gst-libs/gst/video/video-info.h | 5 ++ gst-libs/gst/video/video.c | 21 +++++++ gst-libs/gst/video/video.h | 27 +++++++++ 6 files changed, 134 insertions(+), 116 deletions(-) diff --git a/gst-libs/gst/video/gstvideopool.c b/gst-libs/gst/video/gstvideopool.c index 45d6fa6169..c5a7881f54 100644 --- a/gst-libs/gst/video/gstvideopool.c +++ b/gst-libs/gst/video/gstvideopool.c @@ -20,27 +20,6 @@ #include "gst/video/gstvideometa.h" #include "gst/video/gstvideopool.h" -/** - * gst_video_alignment_reset: - * @align: a #GstVideoAlignment - * - * Set @align to its default values with no padding and no alignment. - */ -void -gst_video_alignment_reset (GstVideoAlignment * align) -{ - gint i; - - g_return_if_fail (align != NULL); - - align->padding_top = 0; - align->padding_bottom = 0; - align->padding_left = 0; - align->padding_right = 0; - for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) - align->stride_align[i] = 0; -} - /** * gst_buffer_pool_config_set_video_alignment: * @config: a #GstStructure @@ -95,76 +74,6 @@ gst_buffer_pool_config_get_video_alignment (GstStructure * config, "stride-align3", G_TYPE_UINT, &align->stride_align[3], NULL); } -static void -gst_video_info_align (GstVideoInfo * info, GstVideoAlignment * align) -{ - const GstVideoFormatInfo *vinfo = info->finfo; - gint width, height; - gint padded_width, padded_height; - gint i, n_planes; - gboolean aligned; - - width = GST_VIDEO_INFO_WIDTH (info); - height = GST_VIDEO_INFO_HEIGHT (info); - - GST_LOG ("padding %u-%ux%u-%u", align->padding_top, - align->padding_left, align->padding_right, align->padding_bottom); - - /* add the padding */ - padded_width = width + align->padding_left + align->padding_right; - padded_height = height + align->padding_top + align->padding_bottom; - - n_planes = GST_VIDEO_INFO_N_PLANES (info); - do { - GST_LOG ("padded dimension %u-%u", padded_width, padded_height); - - gst_video_info_set_format (info, GST_VIDEO_INFO_FORMAT (info), - padded_width, padded_height); - - /* check alignment */ - aligned = TRUE; - for (i = 0; i < n_planes; i++) { - GST_LOG ("plane %d, stride %d, alignment %u", i, info->stride[i], - align->stride_align[i]); - aligned &= (info->stride[i] & align->stride_align[i]) == 0; - } - if (aligned) - break; - - GST_LOG ("unaligned strides, increasing dimension"); - /* increase padded_width */ - padded_width += padded_width & ~(padded_width - 1); - } while (!aligned); - - info->width = width; - info->height = height; - - if (GST_VIDEO_FORMAT_INFO_HAS_PALETTE (vinfo)) - n_planes--; - - for (i = 0; i < n_planes; i++) { - gint vedge, hedge, comp; - - /* Find the component for this plane, FIXME, we assume the plane number and - * component number is the same for now, for scaling the dimensions this is - * currently true for all formats but it might not be when adding new - * formats. We might need to add a plane subsamling in the format info to - * make this more generic or maybe use a plane -> component mapping. */ - comp = i; - - hedge = - GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (vinfo, comp, align->padding_left); - vedge = - GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (vinfo, comp, align->padding_top); - - GST_DEBUG ("plane %d: comp: %d, hedge %d vedge %d align %d stride %d", i, - comp, hedge, vedge, align->stride_align[i], info->stride[i]); - - info->offset[i] += (vedge * info->stride[i]) + - (hedge * GST_VIDEO_FORMAT_INFO_PSTRIDE (vinfo, comp)); - } -} - /* bufferpool */ struct _GstVideoBufferPoolPrivate { diff --git a/gst-libs/gst/video/gstvideopool.h b/gst-libs/gst/video/gstvideopool.h index 1c057f1a0d..c1b3e1e9ed 100644 --- a/gst-libs/gst/video/gstvideopool.h +++ b/gst-libs/gst/video/gstvideopool.h @@ -45,31 +45,6 @@ G_BEGIN_DECLS */ #define GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT "GstBufferPoolOptionVideoAlignment" -typedef struct _GstVideoAlignment GstVideoAlignment; - -/** - * GstVideoAlignment: - * @padding_left: extra pixels on the left side - * @padding_right: extra pixels on the right side - * @padding_top: extra pixels on the top - * @padding_bottom: extra pixels on the bottom - * @stride_align: array with extra alignment requirements for the strides - * - * Extra alignment paramters for the memory of video buffers. This - * structure is usually used to configure the bufferpool if it supports the - * #GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT. - */ -struct _GstVideoAlignment -{ - guint padding_top; - guint padding_bottom; - guint padding_left; - guint padding_right; - guint stride_align[GST_VIDEO_MAX_PLANES]; -}; - -void gst_video_alignment_reset (GstVideoAlignment *align); - /* setting a bufferpool config */ void gst_buffer_pool_config_set_video_alignment (GstStructure *config, GstVideoAlignment *align); gboolean gst_buffer_pool_config_get_video_alignment (GstStructure *config, GstVideoAlignment *align); diff --git a/gst-libs/gst/video/video-info.c b/gst-libs/gst/video/video-info.c index 56cc5f9d9c..6378a4ba4d 100644 --- a/gst-libs/gst/video/video-info.c +++ b/gst-libs/gst/video/video-info.c @@ -665,3 +665,84 @@ done: return ret; } + +/** + * gst_video_info_align: + * @info: a #GstVideoInfo + * @align: alignment parameters + * + * Adjust the offset and stride fields in @info so that the padding and + * stride alignment in @align is respected. + * + * Extra padding will be added to the right side when stride alignment padding + * is required. + */ +void +gst_video_info_align (GstVideoInfo * info, GstVideoAlignment * align) +{ + const GstVideoFormatInfo *vinfo = info->finfo; + gint width, height; + gint padded_width, padded_height; + gint i, n_planes; + gboolean aligned; + + width = GST_VIDEO_INFO_WIDTH (info); + height = GST_VIDEO_INFO_HEIGHT (info); + + GST_LOG ("padding %u-%ux%u-%u", align->padding_top, + align->padding_left, align->padding_right, align->padding_bottom); + + /* add the padding */ + padded_width = width + align->padding_left + align->padding_right; + padded_height = height + align->padding_top + align->padding_bottom; + + n_planes = GST_VIDEO_INFO_N_PLANES (info); + do { + GST_LOG ("padded dimension %u-%u", padded_width, padded_height); + + gst_video_info_set_format (info, GST_VIDEO_INFO_FORMAT (info), + padded_width, padded_height); + + /* check alignment */ + aligned = TRUE; + for (i = 0; i < n_planes; i++) { + GST_LOG ("plane %d, stride %d, alignment %u", i, info->stride[i], + align->stride_align[i]); + aligned &= (info->stride[i] & align->stride_align[i]) == 0; + } + if (aligned) + break; + + GST_LOG ("unaligned strides, increasing dimension"); + /* increase padded_width */ + padded_width += padded_width & ~(padded_width - 1); + } while (!aligned); + + info->width = width; + info->height = height; + + if (GST_VIDEO_FORMAT_INFO_HAS_PALETTE (vinfo)) + n_planes--; + + for (i = 0; i < n_planes; i++) { + gint vedge, hedge, comp; + + /* Find the component for this plane, FIXME, we assume the plane number and + * component number is the same for now, for scaling the dimensions this is + * currently true for all formats but it might not be when adding new + * formats. We might need to add a plane subsamling in the format info to + * make this more generic or maybe use a plane -> component mapping. */ + comp = i; + + hedge = + GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (vinfo, comp, align->padding_left); + vedge = + GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (vinfo, comp, align->padding_top); + + GST_DEBUG ("plane %d: comp: %d, hedge %d vedge %d align %d stride %d", i, + comp, hedge, vedge, align->stride_align[i], info->stride[i]); + + info->offset[i] += (vedge * info->stride[i]) + + (hedge * GST_VIDEO_FORMAT_INFO_PSTRIDE (vinfo, comp)); + } +} diff --git a/gst-libs/gst/video/video-info.h b/gst-libs/gst/video/video-info.h index b4b3e42439..ff821d836e 100644 --- a/gst-libs/gst/video/video-info.h +++ b/gst-libs/gst/video/video-info.h @@ -177,6 +177,11 @@ gboolean gst_video_info_convert (GstVideoInfo *info, gboolean gst_video_info_is_equal (const GstVideoInfo *info, const GstVideoInfo *other); +#include + +void gst_video_info_align (GstVideoInfo * info, GstVideoAlignment * align); + + G_END_DECLS #endif /* __GST_VIDEO_INFO_H__ */ diff --git a/gst-libs/gst/video/video.c b/gst-libs/gst/video/video.c index 6b2c7d7858..56da373cb3 100644 --- a/gst-libs/gst/video/video.c +++ b/gst-libs/gst/video/video.c @@ -97,3 +97,24 @@ error_overflow: return FALSE; } } + +/** + * gst_video_alignment_reset: + * @align: a #GstVideoAlignment + * + * Set @align to its default values with no padding and no alignment. + */ +void +gst_video_alignment_reset (GstVideoAlignment * align) +{ + gint i; + + g_return_if_fail (align != NULL); + + align->padding_top = 0; + align->padding_bottom = 0; + align->padding_left = 0; + align->padding_right = 0; + for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) + align->stride_align[i] = 0; +} diff --git a/gst-libs/gst/video/video.h b/gst-libs/gst/video/video.h index 4068fc4b7c..cafa58c6fb 100644 --- a/gst-libs/gst/video/video.h +++ b/gst-libs/gst/video/video.h @@ -21,6 +21,9 @@ #define __GST_VIDEO_H__ #include + +typedef struct _GstVideoAlignment GstVideoAlignment; + #include #include #include @@ -30,6 +33,30 @@ G_BEGIN_DECLS +/** + * GstVideoAlignment: + * @padding_left: extra pixels on the left side + * @padding_right: extra pixels on the right side + * @padding_top: extra pixels on the top + * @padding_bottom: extra pixels on the bottom + * @stride_align: array with extra alignment requirements for the strides + * + * Extra alignment paramters for the memory of video buffers. This + * structure is usually used to configure the bufferpool if it supports the + * #GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT. + */ +struct _GstVideoAlignment +{ + guint padding_top; + guint padding_bottom; + guint padding_left; + guint padding_right; + guint stride_align[GST_VIDEO_MAX_PLANES]; +}; + +void gst_video_alignment_reset (GstVideoAlignment *align); + + /* some helper functions */ gboolean gst_video_calculate_display_ratio (guint * dar_n, guint * dar_d,