2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Library <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * Copyright (C) 2007 David A. Schleef <ds@schleef.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
24 * @title: GstVideoInfo
25 * @short_description: Structures and enumerations to describe raw images
35 #include "video-info.h"
36 #include "video-tile.h"
38 #ifndef GST_DISABLE_GST_DEBUG
39 #define GST_CAT_DEFAULT ensure_debug_category()
40 static GstDebugCategory *
41 ensure_debug_category (void)
43 static gsize cat_gonce = 0;
45 if (g_once_init_enter (&cat_gonce)) {
48 cat_done = (gsize) _gst_debug_category_new ("video-info", 0,
49 "video-info structure");
51 g_once_init_leave (&cat_gonce, cat_done);
54 return (GstDebugCategory *) cat_gonce;
57 #define ensure_debug_category() /* NOOP */
58 #endif /* GST_DISABLE_GST_DEBUG */
61 * gst_video_info_copy:
62 * @info: a #GstVideoInfo
64 * Copy a GstVideoInfo structure.
66 * Returns: a new #GstVideoInfo. free with gst_video_info_free.
71 gst_video_info_copy (const GstVideoInfo * info)
73 return g_slice_dup (GstVideoInfo, info);
77 * gst_video_info_free:
78 * @info: a #GstVideoInfo
80 * Free a GstVideoInfo structure previously allocated with gst_video_info_new()
81 * or gst_video_info_copy().
86 gst_video_info_free (GstVideoInfo * info)
88 g_slice_free (GstVideoInfo, info);
91 G_DEFINE_BOXED_TYPE (GstVideoInfo, gst_video_info,
92 (GBoxedCopyFunc) gst_video_info_copy, (GBoxedFreeFunc) gst_video_info_free);
97 * Allocate a new #GstVideoInfo that is also initialized with
98 * gst_video_info_init().
100 * Returns: a new #GstVideoInfo. free with gst_video_info_free().
105 gst_video_info_new (void)
109 info = g_slice_new (GstVideoInfo);
110 gst_video_info_init (info);
115 static gboolean fill_planes (GstVideoInfo * info,
116 gsize plane_size[GST_VIDEO_MAX_PLANES]);
119 * gst_video_info_init:
120 * @info: a #GstVideoInfo
122 * Initialize @info with default values.
125 gst_video_info_init (GstVideoInfo * info)
127 g_return_if_fail (info != NULL);
129 memset (info, 0, sizeof (GstVideoInfo));
131 info->finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_UNKNOWN);
134 /* arrange for sensible defaults, e.g. if turned into caps */
139 GST_VIDEO_INFO_MULTIVIEW_MODE (info) = GST_VIDEO_MULTIVIEW_MODE_NONE;
140 GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
141 GST_VIDEO_INFO_FIELD_ORDER (info) = GST_VIDEO_FIELD_ORDER_UNKNOWN;
144 #define MAKE_COLORIMETRY(r,m,t,p) { \
145 GST_VIDEO_COLOR_RANGE ##r, GST_VIDEO_COLOR_MATRIX_ ##m, \
146 GST_VIDEO_TRANSFER_ ##t, GST_VIDEO_COLOR_PRIMARIES_ ##p }
148 #define DEFAULT_YUV_SD 0
149 #define DEFAULT_YUV_HD 1
150 #define DEFAULT_RGB 2
151 #define DEFAULT_GRAY 3
152 #define DEFAULT_UNKNOWN 4
153 #define DEFAULT_YUV_UHD 5
155 static const GstVideoColorimetry default_color[] = {
156 MAKE_COLORIMETRY (_16_235, BT601, BT601, SMPTE170M),
157 MAKE_COLORIMETRY (_16_235, BT709, BT709, BT709),
158 MAKE_COLORIMETRY (_0_255, RGB, SRGB, BT709),
159 MAKE_COLORIMETRY (_0_255, BT601, UNKNOWN, UNKNOWN),
160 MAKE_COLORIMETRY (_UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN),
161 MAKE_COLORIMETRY (_16_235, BT2020, BT2020_12, BT2020),
165 set_default_colorimetry (GstVideoInfo * info)
167 const GstVideoFormatInfo *finfo = info->finfo;
169 if (GST_VIDEO_FORMAT_INFO_IS_YUV (finfo)) {
170 if (info->height >= 2160) {
171 info->chroma_site = GST_VIDEO_CHROMA_SITE_H_COSITED;
172 info->colorimetry = default_color[DEFAULT_YUV_UHD];
173 } else if (info->height > 576) {
174 info->chroma_site = GST_VIDEO_CHROMA_SITE_H_COSITED;
175 info->colorimetry = default_color[DEFAULT_YUV_HD];
177 info->chroma_site = GST_VIDEO_CHROMA_SITE_NONE;
178 info->colorimetry = default_color[DEFAULT_YUV_SD];
180 } else if (GST_VIDEO_FORMAT_INFO_IS_GRAY (finfo)) {
181 info->colorimetry = default_color[DEFAULT_GRAY];
182 } else if (GST_VIDEO_FORMAT_INFO_IS_RGB (finfo)) {
183 info->colorimetry = default_color[DEFAULT_RGB];
185 info->colorimetry = default_color[DEFAULT_UNKNOWN];
190 validate_colorimetry (GstVideoInfo * info)
192 const GstVideoFormatInfo *finfo = info->finfo;
194 if (!GST_VIDEO_FORMAT_INFO_IS_RGB (finfo) &&
195 info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_RGB) {
197 ("color matrix RGB is only supported with RGB format, %s is not",
202 if (GST_VIDEO_FORMAT_INFO_IS_YUV (finfo) &&
203 info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_UNKNOWN) {
204 GST_WARNING ("Need to specify a color matrix when using YUV format (%s)",
213 gst_video_info_set_format_common (GstVideoInfo * info, GstVideoFormat format,
214 guint width, guint height)
216 g_return_val_if_fail (info != NULL, FALSE);
217 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, FALSE);
219 if (width > G_MAXINT || height > G_MAXINT)
222 gst_video_info_init (info);
224 info->finfo = gst_video_format_get_info (format);
226 info->height = height;
229 set_default_colorimetry (info);
235 * gst_video_info_set_format:
236 * @info: a #GstVideoInfo
237 * @format: the format
241 * Set the default info for a video frame of @format and @width and @height.
243 * Note: This initializes @info first, no values are preserved. This function
244 * does not set the offsets correctly for interlaced vertically
245 * subsampled formats.
247 * Returns: %FALSE if the returned video info is invalid, e.g. because the
248 * size of a frame can't be represented as a 32 bit integer (Since: 1.12)
251 gst_video_info_set_format (GstVideoInfo * info, GstVideoFormat format,
252 guint width, guint height)
254 if (!gst_video_info_set_format_common (info, format, width, height))
257 return fill_planes (info, NULL);
261 * gst_video_info_set_interlaced_format:
262 * @info: a #GstVideoInfo
263 * @format: the format
264 * @mode: a #GstVideoInterlaceMode
268 * Same as #gst_video_info_set_format but also allowing to set the interlaced
271 * Returns: %FALSE if the returned video info is invalid, e.g. because the
272 * size of a frame can't be represented as a 32 bit integer.
277 gst_video_info_set_interlaced_format (GstVideoInfo * info,
278 GstVideoFormat format, GstVideoInterlaceMode mode, guint width,
281 if (!gst_video_info_set_format_common (info, format, width, height))
284 GST_VIDEO_INFO_INTERLACE_MODE (info) = mode;
285 return fill_planes (info, NULL);
288 static const gchar *interlace_mode[] = {
297 * gst_video_interlace_mode_to_string:
298 * @mode: a #GstVideoInterlaceMode
300 * Convert @mode to its string representation.
302 * Returns: @mode as a string or NULL if @mode in invalid.
307 gst_video_interlace_mode_to_string (GstVideoInterlaceMode mode)
309 if (((guint) mode) >= G_N_ELEMENTS (interlace_mode))
312 return interlace_mode[mode];
316 * gst_video_interlace_mode_from_string:
319 * Convert @mode to a #GstVideoInterlaceMode
321 * Returns: the #GstVideoInterlaceMode of @mode or
322 * #GST_VIDEO_INTERLACE_MODE_PROGRESSIVE when @mode is not a valid
323 * string representation for a #GstVideoInterlaceMode.
327 GstVideoInterlaceMode
328 gst_video_interlace_mode_from_string (const gchar * mode)
331 for (i = 0; i < G_N_ELEMENTS (interlace_mode); i++) {
332 if (g_str_equal (interlace_mode[i], mode))
335 return GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
338 static const gchar *field_order[] = {
345 * gst_video_field_order_to_string:
346 * @order: a #GstVideoFieldOrder
348 * Convert @order to its string representation.
350 * Returns: @order as a string or NULL if @order in invalid.
355 gst_video_field_order_to_string (GstVideoFieldOrder order)
357 if (((guint) order) >= G_N_ELEMENTS (field_order))
360 return field_order[order];
364 * gst_video_field_order_from_string:
365 * @order: a field order
367 * Convert @order to a #GstVideoFieldOrder
369 * Returns: the #GstVideoFieldOrder of @order or
370 * #GST_VIDEO_FIELD_ORDER_UNKNOWN when @order is not a valid
371 * string representation for a #GstVideoFieldOrder.
376 gst_video_field_order_from_string (const gchar * order)
379 for (i = 0; i < G_N_ELEMENTS (field_order); i++) {
380 if (g_str_equal (field_order[i], order))
383 return GST_VIDEO_FIELD_ORDER_UNKNOWN;
387 * gst_video_info_from_caps:
388 * @info: a #GstVideoInfo
391 * Parse @caps and update @info.
393 * Returns: TRUE if @caps could be parsed
396 gst_video_info_from_caps (GstVideoInfo * info, const GstCaps * caps)
398 GstStructure *structure;
400 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
401 gint width = 0, height = 0;
404 guint multiview_flags;
406 g_return_val_if_fail (info != NULL, FALSE);
407 g_return_val_if_fail (caps != NULL, FALSE);
408 g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
410 GST_DEBUG ("parsing caps %" GST_PTR_FORMAT, caps);
412 structure = gst_caps_get_structure (caps, 0);
414 if (gst_structure_has_name (structure, "video/x-raw")) {
415 if (!(s = gst_structure_get_string (structure, "format")))
418 format = gst_video_format_from_string (s);
419 if (format == GST_VIDEO_FORMAT_UNKNOWN)
422 } else if (g_str_has_prefix (gst_structure_get_name (structure), "video/") ||
423 g_str_has_prefix (gst_structure_get_name (structure), "image/")) {
424 format = GST_VIDEO_FORMAT_ENCODED;
429 /* width and height are mandatory, except for non-raw-formats */
430 if (!gst_structure_get_int (structure, "width", &width) &&
431 format != GST_VIDEO_FORMAT_ENCODED)
433 if (!gst_structure_get_int (structure, "height", &height) &&
434 format != GST_VIDEO_FORMAT_ENCODED)
437 gst_video_info_init (info);
439 info->finfo = gst_video_format_get_info (format);
441 info->height = height;
443 if (gst_structure_get_fraction (structure, "framerate", &fps_n, &fps_d)) {
445 /* variable framerate */
446 info->flags |= GST_VIDEO_FLAG_VARIABLE_FPS;
447 /* see if we have a max-framerate */
448 gst_structure_get_fraction (structure, "max-framerate", &fps_n, &fps_d);
453 /* unspecified is variable framerate */
458 if (gst_structure_get_fraction (structure, "pixel-aspect-ratio",
467 if ((s = gst_structure_get_string (structure, "interlace-mode")))
468 info->interlace_mode = gst_video_interlace_mode_from_string (s);
470 info->interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
472 /* Interlaced feature is mandatory for raw alternate streams */
473 if (info->interlace_mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE &&
474 format != GST_VIDEO_FORMAT_ENCODED) {
477 f = gst_caps_get_features (caps, 0);
479 || !gst_caps_features_contains (f, GST_CAPS_FEATURE_FORMAT_INTERLACED))
480 goto alternate_no_feature;
483 if (GST_VIDEO_INFO_IS_INTERLACED (info) &&
484 (s = gst_structure_get_string (structure, "field-order"))) {
485 GST_VIDEO_INFO_FIELD_ORDER (info) = gst_video_field_order_from_string (s);
487 GST_VIDEO_INFO_FIELD_ORDER (info) = GST_VIDEO_FIELD_ORDER_UNKNOWN;
491 if ((s = gst_structure_get_string (structure, "multiview-mode")))
492 GST_VIDEO_INFO_MULTIVIEW_MODE (info) =
493 gst_video_multiview_mode_from_caps_string (s);
495 GST_VIDEO_INFO_MULTIVIEW_MODE (info) = GST_VIDEO_MULTIVIEW_MODE_NONE;
497 if (gst_structure_get_flagset (structure, "multiview-flags",
498 &multiview_flags, NULL))
499 GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) = multiview_flags;
501 if (!gst_structure_get_int (structure, "views", &info->views))
504 /* At one point, I tried normalising the half-aspect flag here,
505 * but it behaves weird for GstVideoInfo operations other than
506 * directly converting to/from caps - sometimes causing the
507 * PAR to be doubled/halved too many times */
510 if ((s = gst_structure_get_string (structure, "chroma-site")))
511 info->chroma_site = gst_video_chroma_from_string (s);
513 info->chroma_site = GST_VIDEO_CHROMA_SITE_UNKNOWN;
515 if ((s = gst_structure_get_string (structure, "colorimetry"))) {
516 if (!gst_video_colorimetry_from_string (&info->colorimetry, s)) {
517 GST_WARNING ("unparsable colorimetry, using default");
518 set_default_colorimetry (info);
519 } else if (!validate_colorimetry (info)) {
520 GST_WARNING ("invalid colorimetry, using default");
521 set_default_colorimetry (info);
523 /* force RGB matrix for RGB formats */
524 if (GST_VIDEO_FORMAT_INFO_IS_RGB (info->finfo) &&
525 info->colorimetry.matrix != GST_VIDEO_COLOR_MATRIX_RGB) {
526 GST_WARNING ("invalid matrix %d for RGB format, using RGB",
527 info->colorimetry.matrix);
528 info->colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB;
532 GST_DEBUG ("no colorimetry, using default");
533 set_default_colorimetry (info);
536 if (!fill_planes (info, NULL))
544 GST_ERROR ("wrong name '%s', expected video/ or image/",
545 gst_structure_get_name (structure));
550 GST_ERROR ("no format given");
555 GST_ERROR ("unknown format '%s' given", s);
560 GST_ERROR ("no width property given");
565 GST_ERROR ("no height property given");
568 alternate_no_feature:
571 ("caps has 'interlace-mode=alternate' but doesn't have the Interlaced feature");
577 * gst_video_info_is_equal:
578 * @info: a #GstVideoInfo
579 * @other: a #GstVideoInfo
581 * Compares two #GstVideoInfo and returns whether they are equal or not
583 * Returns: %TRUE if @info and @other are equal, else %FALSE.
586 gst_video_info_is_equal (const GstVideoInfo * info, const GstVideoInfo * other)
590 if (GST_VIDEO_INFO_FORMAT (info) != GST_VIDEO_INFO_FORMAT (other))
592 if (GST_VIDEO_INFO_INTERLACE_MODE (info) !=
593 GST_VIDEO_INFO_INTERLACE_MODE (other))
595 if (GST_VIDEO_INFO_FLAGS (info) != GST_VIDEO_INFO_FLAGS (other))
597 if (GST_VIDEO_INFO_WIDTH (info) != GST_VIDEO_INFO_WIDTH (other))
599 if (GST_VIDEO_INFO_HEIGHT (info) != GST_VIDEO_INFO_HEIGHT (other))
601 if (GST_VIDEO_INFO_SIZE (info) != GST_VIDEO_INFO_SIZE (other))
603 if (GST_VIDEO_INFO_PAR_N (info) != GST_VIDEO_INFO_PAR_N (other))
605 if (GST_VIDEO_INFO_PAR_D (info) != GST_VIDEO_INFO_PAR_D (other))
607 if (GST_VIDEO_INFO_FPS_N (info) != GST_VIDEO_INFO_FPS_N (other))
609 if (GST_VIDEO_INFO_FPS_D (info) != GST_VIDEO_INFO_FPS_D (other))
611 if (!gst_video_colorimetry_is_equal (&GST_VIDEO_INFO_COLORIMETRY (info),
612 &GST_VIDEO_INFO_COLORIMETRY (other)))
614 if (GST_VIDEO_INFO_CHROMA_SITE (info) != GST_VIDEO_INFO_CHROMA_SITE (other))
616 if (GST_VIDEO_INFO_MULTIVIEW_MODE (info) !=
617 GST_VIDEO_INFO_MULTIVIEW_MODE (other))
619 if (GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) !=
620 GST_VIDEO_INFO_MULTIVIEW_FLAGS (other))
622 if (GST_VIDEO_INFO_VIEWS (info) != GST_VIDEO_INFO_VIEWS (other))
625 for (i = 0; i < info->finfo->n_planes; i++) {
626 if (info->stride[i] != other->stride[i])
628 if (info->offset[i] != other->offset[i])
636 * gst_video_info_to_caps:
637 * @info: a #GstVideoInfo
639 * Convert the values of @info into a #GstCaps.
641 * Returns: a new #GstCaps containing the info of @info.
644 gst_video_info_to_caps (GstVideoInfo * info)
650 GstVideoColorimetry colorimetry;
652 g_return_val_if_fail (info != NULL, NULL);
653 g_return_val_if_fail (info->finfo != NULL, NULL);
654 g_return_val_if_fail (info->finfo->format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
656 format = gst_video_format_to_string (info->finfo->format);
657 g_return_val_if_fail (format != NULL, NULL);
659 caps = gst_caps_new_simple ("video/x-raw",
660 "format", G_TYPE_STRING, format,
661 "width", G_TYPE_INT, info->width,
662 "height", G_TYPE_INT, info->height, NULL);
667 gst_caps_set_simple (caps, "interlace-mode", G_TYPE_STRING,
668 gst_video_interlace_mode_to_string (info->interlace_mode), NULL);
670 if ((info->interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED ||
671 info->interlace_mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE) &&
672 GST_VIDEO_INFO_FIELD_ORDER (info) != GST_VIDEO_FIELD_ORDER_UNKNOWN) {
673 gst_caps_set_simple (caps, "field-order", G_TYPE_STRING,
674 gst_video_field_order_to_string (GST_VIDEO_INFO_FIELD_ORDER (info)),
678 if (info->interlace_mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE) {
679 /* 'alternate' mode must always be accompanied by interlaced caps feature.
681 GstCapsFeatures *features;
683 features = gst_caps_features_new (GST_CAPS_FEATURE_FORMAT_INTERLACED, NULL);
684 gst_caps_set_features (caps, 0, features);
687 if (GST_VIDEO_INFO_MULTIVIEW_MODE (info) != GST_VIDEO_MULTIVIEW_MODE_NONE) {
688 const gchar *caps_str = NULL;
690 /* If the half-aspect flag is set, applying it into the PAR of the
691 * resulting caps now seems safe, and helps with automatic behaviour
692 * in elements that aren't explicitly multiview aware */
693 if (GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) &
694 GST_VIDEO_MULTIVIEW_FLAGS_HALF_ASPECT) {
695 GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) &=
696 ~GST_VIDEO_MULTIVIEW_FLAGS_HALF_ASPECT;
697 switch (GST_VIDEO_INFO_MULTIVIEW_MODE (info)) {
698 case GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE:
699 case GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE_QUINCUNX:
700 case GST_VIDEO_MULTIVIEW_MODE_COLUMN_INTERLEAVED:
701 case GST_VIDEO_MULTIVIEW_MODE_CHECKERBOARD:
702 par_n *= 2; /* double the width / half the height */
704 case GST_VIDEO_MULTIVIEW_MODE_ROW_INTERLEAVED:
705 case GST_VIDEO_MULTIVIEW_MODE_TOP_BOTTOM:
706 par_d *= 2; /* half the width / double the height */
714 gst_video_multiview_mode_to_caps_string (GST_VIDEO_INFO_MULTIVIEW_MODE
716 if (caps_str != NULL) {
717 gst_caps_set_simple (caps, "multiview-mode", G_TYPE_STRING,
718 caps_str, "multiview-flags", GST_TYPE_VIDEO_MULTIVIEW_FLAGSET,
719 GST_VIDEO_INFO_MULTIVIEW_FLAGS (info), GST_FLAG_SET_MASK_EXACT, NULL);
723 gst_caps_set_simple (caps, "pixel-aspect-ratio",
724 GST_TYPE_FRACTION, par_n, par_d, NULL);
726 if (info->chroma_site != GST_VIDEO_CHROMA_SITE_UNKNOWN)
727 gst_caps_set_simple (caps, "chroma-site", G_TYPE_STRING,
728 gst_video_chroma_to_string (info->chroma_site), NULL);
730 /* make sure we set the RGB matrix for RGB formats */
731 colorimetry = info->colorimetry;
732 if (GST_VIDEO_FORMAT_INFO_IS_RGB (info->finfo) &&
733 colorimetry.matrix != GST_VIDEO_COLOR_MATRIX_RGB) {
734 GST_WARNING ("invalid matrix %d for RGB format, using RGB",
736 colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB;
738 if ((color = gst_video_colorimetry_to_string (&colorimetry))) {
739 gst_caps_set_simple (caps, "colorimetry", G_TYPE_STRING, color, NULL);
744 gst_caps_set_simple (caps, "views", G_TYPE_INT, info->views, NULL);
746 if (info->flags & GST_VIDEO_FLAG_VARIABLE_FPS && info->fps_n != 0) {
747 /* variable fps with a max-framerate */
748 gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, 0, 1,
749 "max-framerate", GST_TYPE_FRACTION, info->fps_n, info->fps_d, NULL);
751 /* no variable fps or no max-framerate */
752 gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION,
753 info->fps_n, info->fps_d, NULL);
760 fill_planes (GstVideoInfo * info, gsize plane_size[GST_VIDEO_MAX_PLANES])
762 gsize width, height, cr_h;
765 width = (gsize) info->width;
766 height = (gsize) GST_VIDEO_INFO_FIELD_HEIGHT (info);
768 /* Sanity check the resulting frame size for overflows */
769 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
770 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
771 bpp = GST_ROUND_UP_8 (bpp) / 8;
772 if (bpp > 0 && GST_ROUND_UP_128 ((guint64) width) * ((guint64) height) >=
774 GST_ERROR ("Frame size %ux%u would overflow", info->width, info->height);
778 switch (info->finfo->format) {
779 case GST_VIDEO_FORMAT_YUY2:
780 case GST_VIDEO_FORMAT_YVYU:
781 case GST_VIDEO_FORMAT_UYVY:
782 case GST_VIDEO_FORMAT_VYUY:
783 info->stride[0] = GST_ROUND_UP_4 (width * 2);
785 info->size = info->stride[0] * height;
787 case GST_VIDEO_FORMAT_AYUV:
788 case GST_VIDEO_FORMAT_RGBx:
789 case GST_VIDEO_FORMAT_RGBA:
790 case GST_VIDEO_FORMAT_BGRx:
791 case GST_VIDEO_FORMAT_BGRA:
792 case GST_VIDEO_FORMAT_xRGB:
793 case GST_VIDEO_FORMAT_ARGB:
794 case GST_VIDEO_FORMAT_xBGR:
795 case GST_VIDEO_FORMAT_ABGR:
796 case GST_VIDEO_FORMAT_r210:
797 case GST_VIDEO_FORMAT_Y410:
798 case GST_VIDEO_FORMAT_VUYA:
799 case GST_VIDEO_FORMAT_BGR10A2_LE:
800 case GST_VIDEO_FORMAT_RGB10A2_LE:
801 info->stride[0] = width * 4;
803 info->size = info->stride[0] * height;
805 case GST_VIDEO_FORMAT_RGB16:
806 case GST_VIDEO_FORMAT_BGR16:
807 case GST_VIDEO_FORMAT_RGB15:
808 case GST_VIDEO_FORMAT_BGR15:
809 info->stride[0] = GST_ROUND_UP_4 (width * 2);
811 info->size = info->stride[0] * height;
813 case GST_VIDEO_FORMAT_RGB:
814 case GST_VIDEO_FORMAT_BGR:
815 case GST_VIDEO_FORMAT_v308:
816 case GST_VIDEO_FORMAT_IYU2:
817 info->stride[0] = GST_ROUND_UP_4 (width * 3);
819 info->size = info->stride[0] * height;
821 case GST_VIDEO_FORMAT_v210:
822 info->stride[0] = ((width + 47) / 48) * 128;
824 info->size = info->stride[0] * height;
826 case GST_VIDEO_FORMAT_v216:
827 case GST_VIDEO_FORMAT_Y210:
828 case GST_VIDEO_FORMAT_Y212_BE:
829 case GST_VIDEO_FORMAT_Y212_LE:
830 info->stride[0] = GST_ROUND_UP_8 (width * 4);
832 info->size = info->stride[0] * height;
834 case GST_VIDEO_FORMAT_GRAY8:
835 info->stride[0] = GST_ROUND_UP_4 (width);
837 info->size = info->stride[0] * height;
839 case GST_VIDEO_FORMAT_GRAY16_BE:
840 case GST_VIDEO_FORMAT_GRAY16_LE:
841 info->stride[0] = GST_ROUND_UP_4 (width * 2);
843 info->size = info->stride[0] * height;
845 case GST_VIDEO_FORMAT_UYVP:
846 info->stride[0] = GST_ROUND_UP_4 ((width * 2 * 5 + 3) / 4);
848 info->size = info->stride[0] * height;
850 case GST_VIDEO_FORMAT_RGB8P:
851 info->stride[0] = GST_ROUND_UP_4 (width);
854 info->offset[1] = info->stride[0] * height;
855 info->size = info->offset[1] + (4 * 256);
857 case GST_VIDEO_FORMAT_IYU1:
858 info->stride[0] = GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) +
859 GST_ROUND_UP_4 (width) / 2);
861 info->size = info->stride[0] * height;
863 case GST_VIDEO_FORMAT_ARGB64:
864 case GST_VIDEO_FORMAT_AYUV64:
865 case GST_VIDEO_FORMAT_Y412_BE:
866 case GST_VIDEO_FORMAT_Y412_LE:
867 info->stride[0] = width * 8;
869 info->size = info->stride[0] * height;
871 case GST_VIDEO_FORMAT_I420:
872 case GST_VIDEO_FORMAT_YV12: /* same as I420, but plane 1+2 swapped */
873 info->stride[0] = GST_ROUND_UP_4 (width);
874 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
875 info->stride[2] = info->stride[1];
877 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
878 cr_h = GST_ROUND_UP_2 (height) / 2;
879 if (GST_VIDEO_INFO_IS_INTERLACED (info))
880 cr_h = GST_ROUND_UP_2 (cr_h);
881 info->offset[2] = info->offset[1] + info->stride[1] * cr_h;
882 info->size = info->offset[2] + info->stride[2] * cr_h;
884 case GST_VIDEO_FORMAT_Y41B:
885 info->stride[0] = GST_ROUND_UP_4 (width);
886 info->stride[1] = GST_ROUND_UP_16 (width) / 4;
887 info->stride[2] = info->stride[1];
889 info->offset[1] = info->stride[0] * height;
890 info->offset[2] = info->offset[1] + info->stride[1] * height;
891 /* simplification of ROUNDUP4(w)*h + 2*((ROUNDUP16(w)/4)*h */
892 info->size = (info->stride[0] + (GST_ROUND_UP_16 (width) / 2)) * height;
894 case GST_VIDEO_FORMAT_Y42B:
895 info->stride[0] = GST_ROUND_UP_4 (width);
896 info->stride[1] = GST_ROUND_UP_8 (width) / 2;
897 info->stride[2] = info->stride[1];
899 info->offset[1] = info->stride[0] * height;
900 info->offset[2] = info->offset[1] + info->stride[1] * height;
901 /* simplification of ROUNDUP4(w)*h + 2*(ROUNDUP8(w)/2)*h */
902 info->size = (info->stride[0] + GST_ROUND_UP_8 (width)) * height;
904 case GST_VIDEO_FORMAT_Y444:
905 case GST_VIDEO_FORMAT_GBR:
906 info->stride[0] = GST_ROUND_UP_4 (width);
907 info->stride[1] = info->stride[0];
908 info->stride[2] = info->stride[0];
910 info->offset[1] = info->stride[0] * height;
911 info->offset[2] = info->offset[1] * 2;
912 info->size = info->stride[0] * height * 3;
914 case GST_VIDEO_FORMAT_GBRA:
915 info->stride[0] = GST_ROUND_UP_4 (width);
916 info->stride[1] = info->stride[0];
917 info->stride[2] = info->stride[0];
918 info->stride[3] = info->stride[0];
920 info->offset[1] = info->stride[0] * height;
921 info->offset[2] = info->offset[1] * 2;
922 info->offset[3] = info->offset[1] * 3;
923 info->size = info->stride[0] * height * 4;
925 case GST_VIDEO_FORMAT_NV12:
926 case GST_VIDEO_FORMAT_NV21:
927 info->stride[0] = GST_ROUND_UP_4 (width);
928 info->stride[1] = info->stride[0];
930 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
931 cr_h = GST_ROUND_UP_2 (height) / 2;
932 if (GST_VIDEO_INFO_IS_INTERLACED (info))
933 cr_h = GST_ROUND_UP_2 (cr_h);
934 info->size = info->offset[1] + info->stride[0] * cr_h;
936 case GST_VIDEO_FORMAT_NV16:
937 case GST_VIDEO_FORMAT_NV61:
938 info->stride[0] = GST_ROUND_UP_4 (width);
939 info->stride[1] = info->stride[0];
941 info->offset[1] = info->stride[0] * height;
942 info->size = info->stride[0] * height * 2;
944 case GST_VIDEO_FORMAT_NV24:
945 info->stride[0] = GST_ROUND_UP_4 (width);
946 info->stride[1] = GST_ROUND_UP_4 (width * 2);
948 info->offset[1] = info->stride[0] * height;
949 info->size = info->stride[0] * height + info->stride[1] * height;
951 case GST_VIDEO_FORMAT_A420:
952 info->stride[0] = GST_ROUND_UP_4 (width);
953 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
954 info->stride[2] = info->stride[1];
955 info->stride[3] = info->stride[0];
957 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
958 cr_h = GST_ROUND_UP_2 (height) / 2;
959 if (GST_VIDEO_INFO_IS_INTERLACED (info))
960 cr_h = GST_ROUND_UP_2 (cr_h);
961 info->offset[2] = info->offset[1] + info->stride[1] * cr_h;
962 info->offset[3] = info->offset[2] + info->stride[2] * cr_h;
963 info->size = info->offset[3] + info->stride[0] * GST_ROUND_UP_2 (height);
965 case GST_VIDEO_FORMAT_YUV9:
966 case GST_VIDEO_FORMAT_YVU9:
967 info->stride[0] = GST_ROUND_UP_4 (width);
968 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4);
969 info->stride[2] = info->stride[1];
971 info->offset[1] = info->stride[0] * height;
972 cr_h = GST_ROUND_UP_4 (height) / 4;
973 if (GST_VIDEO_INFO_IS_INTERLACED (info))
974 cr_h = GST_ROUND_UP_2 (cr_h);
975 info->offset[2] = info->offset[1] + info->stride[1] * cr_h;
976 info->size = info->offset[2] + info->stride[2] * cr_h;
978 case GST_VIDEO_FORMAT_I420_10LE:
979 case GST_VIDEO_FORMAT_I420_10BE:
980 case GST_VIDEO_FORMAT_I420_12LE:
981 case GST_VIDEO_FORMAT_I420_12BE:
982 info->stride[0] = GST_ROUND_UP_4 (width * 2);
983 info->stride[1] = GST_ROUND_UP_4 (width);
984 info->stride[2] = info->stride[1];
986 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
987 cr_h = GST_ROUND_UP_2 (height) / 2;
988 if (GST_VIDEO_INFO_IS_INTERLACED (info))
989 cr_h = GST_ROUND_UP_2 (cr_h);
990 info->offset[2] = info->offset[1] + info->stride[1] * cr_h;
991 info->size = info->offset[2] + info->stride[2] * cr_h;
993 case GST_VIDEO_FORMAT_I422_10LE:
994 case GST_VIDEO_FORMAT_I422_10BE:
995 case GST_VIDEO_FORMAT_I422_12LE:
996 case GST_VIDEO_FORMAT_I422_12BE:
997 info->stride[0] = GST_ROUND_UP_4 (width * 2);
998 info->stride[1] = GST_ROUND_UP_4 (width);
999 info->stride[2] = info->stride[1];
1000 info->offset[0] = 0;
1001 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1002 info->offset[2] = info->offset[1] +
1003 info->stride[1] * GST_ROUND_UP_2 (height);
1004 info->size = info->offset[2] + info->stride[2] * GST_ROUND_UP_2 (height);
1006 case GST_VIDEO_FORMAT_Y444_10LE:
1007 case GST_VIDEO_FORMAT_Y444_10BE:
1008 case GST_VIDEO_FORMAT_Y444_12LE:
1009 case GST_VIDEO_FORMAT_Y444_12BE:
1010 case GST_VIDEO_FORMAT_GBR_10LE:
1011 case GST_VIDEO_FORMAT_GBR_10BE:
1012 case GST_VIDEO_FORMAT_GBR_12LE:
1013 case GST_VIDEO_FORMAT_GBR_12BE:
1014 case GST_VIDEO_FORMAT_Y444_16LE:
1015 case GST_VIDEO_FORMAT_Y444_16BE:
1016 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1017 info->stride[1] = info->stride[0];
1018 info->stride[2] = info->stride[0];
1019 info->offset[0] = 0;
1020 info->offset[1] = info->stride[0] * height;
1021 info->offset[2] = info->offset[1] * 2;
1022 info->size = info->stride[0] * height * 3;
1024 case GST_VIDEO_FORMAT_GBRA_10LE:
1025 case GST_VIDEO_FORMAT_GBRA_10BE:
1026 case GST_VIDEO_FORMAT_GBRA_12LE:
1027 case GST_VIDEO_FORMAT_GBRA_12BE:
1028 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1029 info->stride[1] = info->stride[0];
1030 info->stride[2] = info->stride[0];
1031 info->stride[3] = info->stride[0];
1032 info->offset[0] = 0;
1033 info->offset[1] = info->stride[0] * height;
1034 info->offset[2] = info->offset[1] * 2;
1035 info->offset[3] = info->offset[1] * 3;
1036 info->size = info->stride[0] * height * 4;
1038 case GST_VIDEO_FORMAT_NV12_64Z32:
1040 GST_VIDEO_TILE_MAKE_STRIDE (GST_ROUND_UP_128 (width) / 64,
1041 GST_ROUND_UP_32 (height) / 32);
1043 GST_VIDEO_TILE_MAKE_STRIDE (GST_ROUND_UP_128 (width) / 64,
1044 GST_ROUND_UP_64 (height) / 64);
1045 info->offset[0] = 0;
1046 info->offset[1] = GST_ROUND_UP_128 (width) * GST_ROUND_UP_32 (height);
1047 info->size = info->offset[1] +
1048 GST_ROUND_UP_128 (width) * GST_ROUND_UP_64 (height) / 2;
1050 case GST_VIDEO_FORMAT_A420_10LE:
1051 case GST_VIDEO_FORMAT_A420_10BE:
1052 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1053 info->stride[1] = GST_ROUND_UP_4 (width);
1054 info->stride[2] = info->stride[1];
1055 info->stride[3] = info->stride[0];
1056 info->offset[0] = 0;
1057 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1058 cr_h = GST_ROUND_UP_2 (height) / 2;
1059 if (GST_VIDEO_INFO_IS_INTERLACED (info))
1060 cr_h = GST_ROUND_UP_2 (cr_h);
1061 info->offset[2] = info->offset[1] + info->stride[1] * cr_h;
1062 info->offset[3] = info->offset[2] + info->stride[2] * cr_h;
1063 info->size = info->offset[3] + info->stride[0] * GST_ROUND_UP_2 (height);
1065 case GST_VIDEO_FORMAT_A422_10LE:
1066 case GST_VIDEO_FORMAT_A422_10BE:
1067 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1068 info->stride[1] = GST_ROUND_UP_4 (width);
1069 info->stride[2] = info->stride[1];
1070 info->stride[3] = info->stride[0];
1071 info->offset[0] = 0;
1072 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1073 info->offset[2] = info->offset[1] +
1074 info->stride[1] * GST_ROUND_UP_2 (height);
1076 info->offset[2] + info->stride[2] * GST_ROUND_UP_2 (height);
1077 info->size = info->offset[3] + info->stride[0] * GST_ROUND_UP_2 (height);
1079 case GST_VIDEO_FORMAT_A444_10LE:
1080 case GST_VIDEO_FORMAT_A444_10BE:
1081 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1082 info->stride[1] = info->stride[0];
1083 info->stride[2] = info->stride[0];
1084 info->stride[3] = info->stride[0];
1085 info->offset[0] = 0;
1086 info->offset[1] = info->stride[0] * height;
1087 info->offset[2] = info->offset[1] * 2;
1088 info->offset[3] = info->offset[1] * 3;
1089 info->size = info->stride[0] * height * 4;
1091 case GST_VIDEO_FORMAT_P010_10LE:
1092 case GST_VIDEO_FORMAT_P010_10BE:
1093 case GST_VIDEO_FORMAT_P016_LE:
1094 case GST_VIDEO_FORMAT_P016_BE:
1095 case GST_VIDEO_FORMAT_P012_LE:
1096 case GST_VIDEO_FORMAT_P012_BE:
1097 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1098 info->stride[1] = info->stride[0];
1099 info->offset[0] = 0;
1100 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1101 cr_h = GST_ROUND_UP_2 (height) / 2;
1102 info->size = info->offset[1] + info->stride[0] * cr_h;
1104 case GST_VIDEO_FORMAT_GRAY10_LE32:
1105 info->stride[0] = (width + 2) / 3 * 4;
1106 info->offset[0] = 0;
1107 info->size = info->stride[0] * GST_ROUND_UP_2 (height);
1109 case GST_VIDEO_FORMAT_NV12_10LE32:
1110 info->stride[0] = (width + 2) / 3 * 4;
1111 info->stride[1] = info->stride[0];
1112 info->offset[0] = 0;
1113 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1114 cr_h = GST_ROUND_UP_2 (height) / 2;
1115 if (GST_VIDEO_INFO_IS_INTERLACED (info))
1116 cr_h = GST_ROUND_UP_2 (cr_h);
1117 info->size = info->offset[1] + info->stride[0] * cr_h;
1119 case GST_VIDEO_FORMAT_NV16_10LE32:
1120 info->stride[0] = (width + 2) / 3 * 4;
1121 info->stride[1] = info->stride[0];
1122 info->offset[0] = 0;
1123 info->offset[1] = info->stride[0] * height;
1124 info->size = info->stride[0] * height * 2;
1126 case GST_VIDEO_FORMAT_NV12_10LE40:
1127 info->stride[0] = ((width * 5 >> 2) + 4) / 5 * 5;
1128 info->stride[1] = info->stride[0];
1129 info->offset[0] = 0;
1130 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1131 cr_h = GST_ROUND_UP_2 (height) / 2;
1132 if (GST_VIDEO_INFO_IS_INTERLACED (info))
1133 cr_h = GST_ROUND_UP_2 (cr_h);
1134 info->size = info->offset[1] + info->stride[0] * cr_h;
1137 case GST_VIDEO_FORMAT_ENCODED:
1139 case GST_VIDEO_FORMAT_UNKNOWN:
1140 GST_ERROR ("invalid format");
1141 g_warning ("invalid format");
1147 for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
1148 if (i < GST_VIDEO_INFO_N_PLANES (info)) {
1149 gint comps[GST_VIDEO_MAX_COMPONENTS];
1152 /* Convert plane index to component index */
1153 gst_video_format_info_component (info->finfo, i, comps);
1155 GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info->finfo, comps[0],
1156 GST_VIDEO_INFO_FIELD_HEIGHT (info));
1157 plane_size[i] = plane_height * GST_VIDEO_INFO_PLANE_STRIDE (info, i);
1168 * gst_video_info_convert:
1169 * @info: a #GstVideoInfo
1170 * @src_format: #GstFormat of the @src_value
1171 * @src_value: value to convert
1172 * @dest_format: #GstFormat of the @dest_value
1173 * @dest_value: (out): pointer to destination value
1175 * Converts among various #GstFormat types. This function handles
1176 * GST_FORMAT_BYTES, GST_FORMAT_TIME, and GST_FORMAT_DEFAULT. For
1177 * raw video, GST_FORMAT_DEFAULT corresponds to video frames. This
1178 * function can be used to handle pad queries of the type GST_QUERY_CONVERT.
1180 * Returns: TRUE if the conversion was successful.
1183 gst_video_info_convert (GstVideoInfo * info,
1184 GstFormat src_format, gint64 src_value,
1185 GstFormat dest_format, gint64 * dest_value)
1187 gboolean ret = FALSE;
1191 g_return_val_if_fail (info != NULL, 0);
1192 g_return_val_if_fail (info->finfo != NULL, 0);
1193 g_return_val_if_fail (info->finfo->format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1194 g_return_val_if_fail (info->size > 0, 0);
1197 fps_n = info->fps_n;
1198 fps_d = info->fps_d;
1200 GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
1201 src_value, gst_format_get_name (src_format),
1202 gst_format_get_name (dest_format));
1204 if (src_format == dest_format) {
1205 *dest_value = src_value;
1210 if (src_value == -1) {
1216 /* bytes to frames */
1217 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_DEFAULT) {
1219 *dest_value = gst_util_uint64_scale (src_value, 1, size);
1221 GST_ERROR ("blocksize is 0");
1228 /* frames to bytes */
1229 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_BYTES) {
1230 *dest_value = gst_util_uint64_scale (src_value, size, 1);
1235 /* time to frames */
1236 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_DEFAULT) {
1238 *dest_value = gst_util_uint64_scale (src_value,
1239 fps_n, GST_SECOND * fps_d);
1241 GST_ERROR ("framerate denominator is 0");
1248 /* frames to time */
1249 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_TIME) {
1251 *dest_value = gst_util_uint64_scale (src_value,
1252 GST_SECOND * fps_d, fps_n);
1254 GST_ERROR ("framerate numerator is 0");
1262 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
1264 *dest_value = gst_util_uint64_scale (src_value,
1265 fps_n * size, GST_SECOND * fps_d);
1267 GST_ERROR ("framerate denominator is 0");
1275 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_TIME) {
1276 if (fps_n != 0 && size != 0) {
1277 *dest_value = gst_util_uint64_scale (src_value,
1278 GST_SECOND * fps_d, fps_n * size);
1280 GST_ERROR ("framerate denominator and/or blocksize is 0");
1288 GST_DEBUG ("ret=%d result %" G_GINT64_FORMAT, ret, *dest_value);
1294 * gst_video_info_align_full:
1295 * @info: a #GstVideoInfo
1296 * @align: alignment parameters
1297 * @plane_size: (out) (allow-none): array used to store the plane sizes
1299 * This variant of gst_video_info_align() provides the updated size, in bytes,
1300 * of each video plane after the alignment, including all horizontal and vertical
1303 * In case of GST_VIDEO_INTERLACE_MODE_ALTERNATE info, the returned sizes are the
1304 * ones used to hold a single field, not the full frame.
1306 * Returns: %FALSE if alignment could not be applied, e.g. because the
1307 * size of a frame can't be represented as a 32 bit integer
1312 gst_video_info_align_full (GstVideoInfo * info, GstVideoAlignment * align,
1313 gsize plane_size[GST_VIDEO_MAX_PLANES])
1315 const GstVideoFormatInfo *vinfo = info->finfo;
1317 gint padded_width, padded_height;
1321 width = GST_VIDEO_INFO_WIDTH (info);
1322 height = GST_VIDEO_INFO_HEIGHT (info);
1324 GST_LOG ("padding %u-%ux%u-%u", align->padding_top,
1325 align->padding_left, align->padding_right, align->padding_bottom);
1327 n_planes = GST_VIDEO_INFO_N_PLANES (info);
1329 if (GST_VIDEO_FORMAT_INFO_HAS_PALETTE (vinfo))
1332 /* first make sure the left padding does not cause alignment problems later */
1334 GST_LOG ("left padding %u", align->padding_left);
1336 for (i = 0; i < n_planes; i++) {
1339 /* this is the amount of pixels to add as left padding */
1340 hedge = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (vinfo, i, align->padding_left);
1341 hedge *= GST_VIDEO_FORMAT_INFO_PSTRIDE (vinfo, i);
1343 GST_LOG ("plane %d, padding %d, alignment %u", i, hedge,
1344 align->stride_align[i]);
1345 aligned &= (hedge & align->stride_align[i]) == 0;
1350 GST_LOG ("unaligned padding, increasing padding");
1351 /* increase padded_width */
1352 align->padding_left += align->padding_left & ~(align->padding_left - 1);
1355 /* add the padding */
1356 padded_width = width + align->padding_left + align->padding_right;
1357 padded_height = height + align->padding_top + align->padding_bottom;
1360 GST_LOG ("padded dimension %u-%u", padded_width, padded_height);
1362 info->width = padded_width;
1363 info->height = padded_height;
1365 if (!fill_planes (info, plane_size))
1368 /* check alignment */
1370 for (i = 0; i < n_planes; i++) {
1371 GST_LOG ("plane %d, stride %d, alignment %u", i, info->stride[i],
1372 align->stride_align[i]);
1373 aligned &= (info->stride[i] & align->stride_align[i]) == 0;
1378 GST_LOG ("unaligned strides, increasing dimension");
1379 /* increase padded_width */
1380 padded_width += padded_width & ~(padded_width - 1);
1383 align->padding_right = padded_width - width - align->padding_left;
1385 info->width = width;
1386 info->height = height;
1388 for (i = 0; i < n_planes; i++) {
1389 gint vedge, hedge, comp;
1391 /* Find the component for this plane, FIXME, we assume the plane number and
1392 * component number is the same for now, for scaling the dimensions this is
1393 * currently true for all formats but it might not be when adding new
1394 * formats. We might need to add a plane subsamling in the format info to
1395 * make this more generic or maybe use a plane -> component mapping. */
1399 GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (vinfo, comp, align->padding_left);
1401 GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (vinfo, comp, align->padding_top);
1403 GST_DEBUG ("plane %d: comp: %d, hedge %d vedge %d align %d stride %d", i,
1404 comp, hedge, vedge, align->stride_align[i], info->stride[i]);
1406 info->offset[i] += (vedge * info->stride[i]) +
1407 (hedge * GST_VIDEO_FORMAT_INFO_PSTRIDE (vinfo, comp));
1414 * gst_video_info_align:
1415 * @info: a #GstVideoInfo
1416 * @align: alignment parameters
1418 * Adjust the offset and stride fields in @info so that the padding and
1419 * stride alignment in @align is respected.
1421 * Extra padding will be added to the right side when stride alignment padding
1422 * is required and @align will be updated with the new padding values.
1424 * Returns: %FALSE if alignment could not be applied, e.g. because the
1425 * size of a frame can't be represented as a 32 bit integer (Since: 1.12)
1428 gst_video_info_align (GstVideoInfo * info, GstVideoAlignment * align)
1430 return gst_video_info_align_full (info, align, NULL);