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.
This commit is contained in:
parent
f56e1222da
commit
9a2344c2e5
@ -20,27 +20,6 @@
|
|||||||
#include "gst/video/gstvideometa.h"
|
#include "gst/video/gstvideometa.h"
|
||||||
#include "gst/video/gstvideopool.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:
|
* gst_buffer_pool_config_set_video_alignment:
|
||||||
* @config: a #GstStructure
|
* @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);
|
"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 */
|
/* bufferpool */
|
||||||
struct _GstVideoBufferPoolPrivate
|
struct _GstVideoBufferPoolPrivate
|
||||||
{
|
{
|
||||||
|
@ -45,31 +45,6 @@ G_BEGIN_DECLS
|
|||||||
*/
|
*/
|
||||||
#define GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT "GstBufferPoolOptionVideoAlignment"
|
#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 */
|
/* setting a bufferpool config */
|
||||||
void gst_buffer_pool_config_set_video_alignment (GstStructure *config, GstVideoAlignment *align);
|
void gst_buffer_pool_config_set_video_alignment (GstStructure *config, GstVideoAlignment *align);
|
||||||
gboolean gst_buffer_pool_config_get_video_alignment (GstStructure *config, GstVideoAlignment *align);
|
gboolean gst_buffer_pool_config_get_video_alignment (GstStructure *config, GstVideoAlignment *align);
|
||||||
|
@ -665,3 +665,84 @@ done:
|
|||||||
|
|
||||||
return ret;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -177,6 +177,11 @@ gboolean gst_video_info_convert (GstVideoInfo *info,
|
|||||||
gboolean gst_video_info_is_equal (const GstVideoInfo *info,
|
gboolean gst_video_info_is_equal (const GstVideoInfo *info,
|
||||||
const GstVideoInfo *other);
|
const GstVideoInfo *other);
|
||||||
|
|
||||||
|
#include <gst/video/video.h>
|
||||||
|
|
||||||
|
void gst_video_info_align (GstVideoInfo * info, GstVideoAlignment * align);
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_VIDEO_INFO_H__ */
|
#endif /* __GST_VIDEO_INFO_H__ */
|
||||||
|
@ -97,3 +97,24 @@ error_overflow:
|
|||||||
return FALSE;
|
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;
|
||||||
|
}
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
#define __GST_VIDEO_H__
|
#define __GST_VIDEO_H__
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
typedef struct _GstVideoAlignment GstVideoAlignment;
|
||||||
|
|
||||||
#include <gst/video/video-event.h>
|
#include <gst/video/video-event.h>
|
||||||
#include <gst/video/video-format.h>
|
#include <gst/video/video-format.h>
|
||||||
#include <gst/video/video-color.h>
|
#include <gst/video/video-color.h>
|
||||||
@ -30,6 +33,30 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
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 */
|
/* some helper functions */
|
||||||
gboolean gst_video_calculate_display_ratio (guint * dar_n,
|
gboolean gst_video_calculate_display_ratio (guint * dar_n,
|
||||||
guint * dar_d,
|
guint * dar_d,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user