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.
29 #include "video-info.h"
30 #include "video-tile.h"
32 #ifndef GST_DISABLE_GST_DEBUG
33 #define GST_CAT_DEFAULT ensure_debug_category()
34 static GstDebugCategory *
35 ensure_debug_category (void)
37 static gsize cat_gonce = 0;
39 if (g_once_init_enter (&cat_gonce)) {
42 cat_done = (gsize) _gst_debug_category_new ("video-info", 0,
43 "video-info structure");
45 g_once_init_leave (&cat_gonce, cat_done);
48 return (GstDebugCategory *) cat_gonce;
51 #define ensure_debug_category() /* NOOP */
52 #endif /* GST_DISABLE_GST_DEBUG */
55 * gst_video_info_copy:
56 * @info: a #GstVideoInfo
58 * Copy a GstVideoInfo structure.
60 * Returns: a new #GstVideoInfo. free with gst_video_info_free.
65 gst_video_info_copy (const GstVideoInfo * info)
67 return g_slice_dup (GstVideoInfo, info);
71 * gst_video_info_free:
72 * @info: a #GstVideoInfo
74 * Free a GstVideoInfo structure previously allocated with gst_video_info_new()
75 * or gst_video_info_copy().
80 gst_video_info_free (GstVideoInfo * info)
82 g_slice_free (GstVideoInfo, info);
85 G_DEFINE_BOXED_TYPE (GstVideoInfo, gst_video_info,
86 (GBoxedCopyFunc) gst_video_info_copy, (GBoxedFreeFunc) gst_video_info_free);
91 * Allocate a new #GstVideoInfo that is also initialized with
92 * gst_video_info_init().
94 * Returns: a new #GstVideoInfo. free with gst_video_info_free().
99 gst_video_info_new (void)
103 info = g_slice_new (GstVideoInfo);
104 gst_video_info_init (info);
109 static gboolean fill_planes (GstVideoInfo * info);
112 * gst_video_info_init:
113 * @info: a #GstVideoInfo
115 * Initialize @info with default values.
118 gst_video_info_init (GstVideoInfo * info)
120 g_return_if_fail (info != NULL);
122 memset (info, 0, sizeof (GstVideoInfo));
124 info->finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_UNKNOWN);
127 /* arrange for sensible defaults, e.g. if turned into caps */
132 GST_VIDEO_INFO_MULTIVIEW_MODE (info) = GST_VIDEO_MULTIVIEW_MODE_NONE;
133 GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
134 GST_VIDEO_INFO_FIELD_ORDER (info) = GST_VIDEO_FIELD_ORDER_UNKNOWN;
137 #define MAKE_COLORIMETRY(r,m,t,p) { \
138 GST_VIDEO_COLOR_RANGE ##r, GST_VIDEO_COLOR_MATRIX_ ##m, \
139 GST_VIDEO_TRANSFER_ ##t, GST_VIDEO_COLOR_PRIMARIES_ ##p }
141 #define DEFAULT_YUV_SD 0
142 #define DEFAULT_YUV_HD 1
143 #define DEFAULT_RGB 2
144 #define DEFAULT_GRAY 3
145 #define DEFAULT_UNKNOWN 4
146 #define DEFAULT_YUV_UHD 5
148 static const GstVideoColorimetry default_color[] = {
149 MAKE_COLORIMETRY (_16_235, BT601, BT709, SMPTE170M),
150 MAKE_COLORIMETRY (_16_235, BT709, BT709, BT709),
151 MAKE_COLORIMETRY (_0_255, RGB, SRGB, BT709),
152 MAKE_COLORIMETRY (_0_255, BT601, UNKNOWN, UNKNOWN),
153 MAKE_COLORIMETRY (_UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN),
154 MAKE_COLORIMETRY (_16_235, BT2020, BT2020_12, BT2020),
158 set_default_colorimetry (GstVideoInfo * info)
160 const GstVideoFormatInfo *finfo = info->finfo;
162 if (GST_VIDEO_FORMAT_INFO_IS_YUV (finfo)) {
163 if (info->height >= 2160) {
164 info->chroma_site = GST_VIDEO_CHROMA_SITE_H_COSITED;
165 info->colorimetry = default_color[DEFAULT_YUV_UHD];
166 } else if (info->height > 576) {
167 info->chroma_site = GST_VIDEO_CHROMA_SITE_H_COSITED;
168 info->colorimetry = default_color[DEFAULT_YUV_HD];
170 info->chroma_site = GST_VIDEO_CHROMA_SITE_NONE;
171 info->colorimetry = default_color[DEFAULT_YUV_SD];
173 } else if (GST_VIDEO_FORMAT_INFO_IS_GRAY (finfo)) {
174 info->colorimetry = default_color[DEFAULT_GRAY];
175 } else if (GST_VIDEO_FORMAT_INFO_IS_RGB (finfo)) {
176 info->colorimetry = default_color[DEFAULT_RGB];
178 info->colorimetry = default_color[DEFAULT_UNKNOWN];
183 validate_colorimetry (GstVideoInfo * info)
185 const GstVideoFormatInfo *finfo = info->finfo;
187 if (!GST_VIDEO_FORMAT_INFO_IS_RGB (finfo) &&
188 info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_RGB) {
190 ("color matrix RGB is only supported with RGB format, %s is not",
195 if (GST_VIDEO_FORMAT_INFO_IS_YUV (finfo) &&
196 info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_UNKNOWN) {
197 GST_WARNING ("Need to specify a color matrix when using YUV format (%s)",
206 gst_video_info_set_format_common (GstVideoInfo * info, GstVideoFormat format,
207 guint width, guint height)
209 g_return_val_if_fail (info != NULL, FALSE);
210 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, FALSE);
212 if (width > G_MAXINT || height > G_MAXINT)
215 gst_video_info_init (info);
217 info->finfo = gst_video_format_get_info (format);
219 info->height = height;
222 set_default_colorimetry (info);
228 * gst_video_info_set_format:
229 * @info: a #GstVideoInfo
230 * @format: the format
234 * Set the default info for a video frame of @format and @width and @height.
236 * Note: This initializes @info first, no values are preserved. This function
237 * does not set the offsets correctly for interlaced vertically
238 * subsampled formats.
240 * Returns: %FALSE if the returned video info is invalid, e.g. because the
241 * size of a frame can't be represented as a 32 bit integer (Since: 1.12)
244 gst_video_info_set_format (GstVideoInfo * info, GstVideoFormat format,
245 guint width, guint height)
247 if (!gst_video_info_set_format_common (info, format, width, height))
250 return fill_planes (info);
254 * gst_video_info_set_interlaced_format:
255 * @info: a #GstVideoInfo
256 * @format: the format
257 * @mode: a #GstVideoInterlaceMode
261 * Same as #gst_video_info_set_format but also allowing to set the interlaced
264 * Returns: %FALSE if the returned video info is invalid, e.g. because the
265 * size of a frame can't be represented as a 32 bit integer.
270 gst_video_info_set_interlaced_format (GstVideoInfo * info,
271 GstVideoFormat format, GstVideoInterlaceMode mode, guint width,
274 if (!gst_video_info_set_format_common (info, format, width, height))
277 GST_VIDEO_INFO_INTERLACE_MODE (info) = mode;
278 return fill_planes (info);
281 static const gchar *interlace_mode[] = {
290 * gst_video_interlace_mode_to_string:
291 * @mode: a #GstVideoInterlaceMode
293 * Convert @mode to its string representation.
295 * Returns: @mode as a string or NULL if @mode in invalid.
300 gst_video_interlace_mode_to_string (GstVideoInterlaceMode mode)
302 if (((guint) mode) >= G_N_ELEMENTS (interlace_mode))
305 return interlace_mode[mode];
309 * gst_video_interlace_mode_from_string:
312 * Convert @mode to a #GstVideoInterlaceMode
314 * Returns: the #GstVideoInterlaceMode of @mode or
315 * #GST_VIDEO_INTERLACE_MODE_PROGRESSIVE when @mode is not a valid
316 * string representation for a #GstVideoInterlaceMode.
320 GstVideoInterlaceMode
321 gst_video_interlace_mode_from_string (const gchar * mode)
324 for (i = 0; i < G_N_ELEMENTS (interlace_mode); i++) {
325 if (g_str_equal (interlace_mode[i], mode))
328 return GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
331 static const gchar *field_order[] = {
338 * gst_video_field_order_to_string:
339 * @order: a #GstVideoFieldOrder
341 * Convert @order to its string representation.
343 * Returns: @order as a string or NULL if @order in invalid.
348 gst_video_field_order_to_string (GstVideoFieldOrder order)
350 if (((guint) order) >= G_N_ELEMENTS (field_order))
353 return field_order[order];
357 * gst_video_field_order_from_string:
358 * @order: a field order
360 * Convert @order to a #GstVideoFieldOrder
362 * Returns: the #GstVideoFieldOrder of @order or
363 * #GST_VIDEO_FIELD_ORDER_UNKNOWN when @order is not a valid
364 * string representation for a #GstVideoFieldOrder.
369 gst_video_field_order_from_string (const gchar * order)
372 for (i = 0; i < G_N_ELEMENTS (field_order); i++) {
373 if (g_str_equal (field_order[i], order))
376 return GST_VIDEO_FIELD_ORDER_UNKNOWN;
380 * gst_video_info_from_caps:
381 * @info: a #GstVideoInfo
384 * Parse @caps and update @info.
386 * Returns: TRUE if @caps could be parsed
389 gst_video_info_from_caps (GstVideoInfo * info, const GstCaps * caps)
391 GstStructure *structure;
393 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
394 gint width = 0, height = 0;
397 guint multiview_flags;
399 g_return_val_if_fail (info != NULL, FALSE);
400 g_return_val_if_fail (caps != NULL, FALSE);
401 g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
403 GST_DEBUG ("parsing caps %" GST_PTR_FORMAT, caps);
405 structure = gst_caps_get_structure (caps, 0);
407 if (gst_structure_has_name (structure, "video/x-raw")) {
408 if (!(s = gst_structure_get_string (structure, "format")))
411 format = gst_video_format_from_string (s);
412 if (format == GST_VIDEO_FORMAT_UNKNOWN)
415 } else if (g_str_has_prefix (gst_structure_get_name (structure), "video/") ||
416 g_str_has_prefix (gst_structure_get_name (structure), "image/")) {
417 format = GST_VIDEO_FORMAT_ENCODED;
422 /* width and height are mandatory, except for non-raw-formats */
423 if (!gst_structure_get_int (structure, "width", &width) &&
424 format != GST_VIDEO_FORMAT_ENCODED)
426 if (!gst_structure_get_int (structure, "height", &height) &&
427 format != GST_VIDEO_FORMAT_ENCODED)
430 gst_video_info_init (info);
432 info->finfo = gst_video_format_get_info (format);
434 info->height = height;
436 if (gst_structure_get_fraction (structure, "framerate", &fps_n, &fps_d)) {
438 /* variable framerate */
439 info->flags |= GST_VIDEO_FLAG_VARIABLE_FPS;
440 /* see if we have a max-framerate */
441 gst_structure_get_fraction (structure, "max-framerate", &fps_n, &fps_d);
446 /* unspecified is variable framerate */
451 if (gst_structure_get_fraction (structure, "pixel-aspect-ratio",
460 if ((s = gst_structure_get_string (structure, "interlace-mode")))
461 info->interlace_mode = gst_video_interlace_mode_from_string (s);
463 info->interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
465 /* Interlaced feature is mandatory for raw alternate streams */
466 if (info->interlace_mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE &&
467 format != GST_VIDEO_FORMAT_ENCODED) {
470 f = gst_caps_get_features (caps, 0);
472 || !gst_caps_features_contains (f, GST_CAPS_FEATURE_FORMAT_INTERLACED))
473 goto alternate_no_feature;
476 if (GST_VIDEO_INFO_IS_INTERLACED (info) &&
477 (s = gst_structure_get_string (structure, "field-order"))) {
478 GST_VIDEO_INFO_FIELD_ORDER (info) = gst_video_field_order_from_string (s);
480 GST_VIDEO_INFO_FIELD_ORDER (info) = GST_VIDEO_FIELD_ORDER_UNKNOWN;
484 if ((s = gst_structure_get_string (structure, "multiview-mode")))
485 GST_VIDEO_INFO_MULTIVIEW_MODE (info) =
486 gst_video_multiview_mode_from_caps_string (s);
488 GST_VIDEO_INFO_MULTIVIEW_MODE (info) = GST_VIDEO_MULTIVIEW_MODE_NONE;
490 if (gst_structure_get_flagset (structure, "multiview-flags",
491 &multiview_flags, NULL))
492 GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) = multiview_flags;
494 if (!gst_structure_get_int (structure, "views", &info->views))
497 /* At one point, I tried normalising the half-aspect flag here,
498 * but it behaves weird for GstVideoInfo operations other than
499 * directly converting to/from caps - sometimes causing the
500 * PAR to be doubled/halved too many times */
503 if ((s = gst_structure_get_string (structure, "chroma-site")))
504 info->chroma_site = gst_video_chroma_from_string (s);
506 info->chroma_site = GST_VIDEO_CHROMA_SITE_UNKNOWN;
508 if ((s = gst_structure_get_string (structure, "colorimetry"))) {
509 if (!gst_video_colorimetry_from_string (&info->colorimetry, s)) {
510 GST_WARNING ("unparsable colorimetry, using default");
511 set_default_colorimetry (info);
512 } else if (!validate_colorimetry (info)) {
513 GST_WARNING ("invalid colorimetry, using default");
514 set_default_colorimetry (info);
516 /* force RGB matrix for RGB formats */
517 if (GST_VIDEO_FORMAT_INFO_IS_RGB (info->finfo) &&
518 info->colorimetry.matrix != GST_VIDEO_COLOR_MATRIX_RGB) {
519 GST_WARNING ("invalid matrix %d for RGB format, using RGB",
520 info->colorimetry.matrix);
521 info->colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB;
525 GST_DEBUG ("no colorimetry, using default");
526 set_default_colorimetry (info);
529 if (!fill_planes (info))
537 GST_ERROR ("wrong name '%s', expected video/ or image/",
538 gst_structure_get_name (structure));
543 GST_ERROR ("no format given");
548 GST_ERROR ("unknown format '%s' given", s);
553 GST_ERROR ("no width property given");
558 GST_ERROR ("no height property given");
561 alternate_no_feature:
564 ("caps has 'interlace-mode=alternate' but doesn't have the Interlaced feature");
570 * gst_video_info_is_equal:
571 * @info: a #GstVideoInfo
572 * @other: a #GstVideoInfo
574 * Compares two #GstVideoInfo and returns whether they are equal or not
576 * Returns: %TRUE if @info and @other are equal, else %FALSE.
579 gst_video_info_is_equal (const GstVideoInfo * info, const GstVideoInfo * other)
583 if (GST_VIDEO_INFO_FORMAT (info) != GST_VIDEO_INFO_FORMAT (other))
585 if (GST_VIDEO_INFO_INTERLACE_MODE (info) !=
586 GST_VIDEO_INFO_INTERLACE_MODE (other))
588 if (GST_VIDEO_INFO_FLAGS (info) != GST_VIDEO_INFO_FLAGS (other))
590 if (GST_VIDEO_INFO_WIDTH (info) != GST_VIDEO_INFO_WIDTH (other))
592 if (GST_VIDEO_INFO_HEIGHT (info) != GST_VIDEO_INFO_HEIGHT (other))
594 if (GST_VIDEO_INFO_SIZE (info) != GST_VIDEO_INFO_SIZE (other))
596 if (GST_VIDEO_INFO_PAR_N (info) != GST_VIDEO_INFO_PAR_N (other))
598 if (GST_VIDEO_INFO_PAR_D (info) != GST_VIDEO_INFO_PAR_D (other))
600 if (GST_VIDEO_INFO_FPS_N (info) != GST_VIDEO_INFO_FPS_N (other))
602 if (GST_VIDEO_INFO_FPS_D (info) != GST_VIDEO_INFO_FPS_D (other))
604 if (!gst_video_colorimetry_is_equal (&GST_VIDEO_INFO_COLORIMETRY (info),
605 &GST_VIDEO_INFO_COLORIMETRY (other)))
607 if (GST_VIDEO_INFO_CHROMA_SITE (info) != GST_VIDEO_INFO_CHROMA_SITE (other))
609 if (GST_VIDEO_INFO_MULTIVIEW_MODE (info) !=
610 GST_VIDEO_INFO_MULTIVIEW_MODE (other))
612 if (GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) !=
613 GST_VIDEO_INFO_MULTIVIEW_FLAGS (other))
615 if (GST_VIDEO_INFO_VIEWS (info) != GST_VIDEO_INFO_VIEWS (other))
618 for (i = 0; i < info->finfo->n_planes; i++) {
619 if (info->stride[i] != other->stride[i])
621 if (info->offset[i] != other->offset[i])
629 * gst_video_info_to_caps:
630 * @info: a #GstVideoInfo
632 * Convert the values of @info into a #GstCaps.
634 * Returns: a new #GstCaps containing the info of @info.
637 gst_video_info_to_caps (GstVideoInfo * info)
643 GstVideoColorimetry colorimetry;
645 g_return_val_if_fail (info != NULL, NULL);
646 g_return_val_if_fail (info->finfo != NULL, NULL);
647 g_return_val_if_fail (info->finfo->format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
649 format = gst_video_format_to_string (info->finfo->format);
650 g_return_val_if_fail (format != NULL, NULL);
652 caps = gst_caps_new_simple ("video/x-raw",
653 "format", G_TYPE_STRING, format,
654 "width", G_TYPE_INT, info->width,
655 "height", G_TYPE_INT, info->height, NULL);
660 gst_caps_set_simple (caps, "interlace-mode", G_TYPE_STRING,
661 gst_video_interlace_mode_to_string (info->interlace_mode), NULL);
663 if ((info->interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED ||
664 info->interlace_mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE) &&
665 GST_VIDEO_INFO_FIELD_ORDER (info) != GST_VIDEO_FIELD_ORDER_UNKNOWN) {
666 gst_caps_set_simple (caps, "field-order", G_TYPE_STRING,
667 gst_video_field_order_to_string (GST_VIDEO_INFO_FIELD_ORDER (info)),
671 if (info->interlace_mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE) {
672 /* 'alternate' mode must always be accompanied by interlaced caps feature.
674 GstCapsFeatures *features;
676 features = gst_caps_features_new (GST_CAPS_FEATURE_FORMAT_INTERLACED, NULL);
677 gst_caps_set_features (caps, 0, features);
680 if (GST_VIDEO_INFO_MULTIVIEW_MODE (info) != GST_VIDEO_MULTIVIEW_MODE_NONE) {
681 const gchar *caps_str = NULL;
683 /* If the half-aspect flag is set, applying it into the PAR of the
684 * resulting caps now seems safe, and helps with automatic behaviour
685 * in elements that aren't explicitly multiview aware */
686 if (GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) &
687 GST_VIDEO_MULTIVIEW_FLAGS_HALF_ASPECT) {
688 GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) &=
689 ~GST_VIDEO_MULTIVIEW_FLAGS_HALF_ASPECT;
690 switch (GST_VIDEO_INFO_MULTIVIEW_MODE (info)) {
691 case GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE:
692 case GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE_QUINCUNX:
693 case GST_VIDEO_MULTIVIEW_MODE_COLUMN_INTERLEAVED:
694 case GST_VIDEO_MULTIVIEW_MODE_CHECKERBOARD:
695 par_n *= 2; /* double the width / half the height */
697 case GST_VIDEO_MULTIVIEW_MODE_ROW_INTERLEAVED:
698 case GST_VIDEO_MULTIVIEW_MODE_TOP_BOTTOM:
699 par_d *= 2; /* half the width / double the height */
707 gst_video_multiview_mode_to_caps_string (GST_VIDEO_INFO_MULTIVIEW_MODE
709 if (caps_str != NULL) {
710 gst_caps_set_simple (caps, "multiview-mode", G_TYPE_STRING,
711 caps_str, "multiview-flags", GST_TYPE_VIDEO_MULTIVIEW_FLAGSET,
712 GST_VIDEO_INFO_MULTIVIEW_FLAGS (info), GST_FLAG_SET_MASK_EXACT, NULL);
716 gst_caps_set_simple (caps, "pixel-aspect-ratio",
717 GST_TYPE_FRACTION, par_n, par_d, NULL);
719 if (info->chroma_site != GST_VIDEO_CHROMA_SITE_UNKNOWN)
720 gst_caps_set_simple (caps, "chroma-site", G_TYPE_STRING,
721 gst_video_chroma_to_string (info->chroma_site), NULL);
723 /* make sure we set the RGB matrix for RGB formats */
724 colorimetry = info->colorimetry;
725 if (GST_VIDEO_FORMAT_INFO_IS_RGB (info->finfo) &&
726 colorimetry.matrix != GST_VIDEO_COLOR_MATRIX_RGB) {
727 GST_WARNING ("invalid matrix %d for RGB format, using RGB",
729 colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB;
731 if ((color = gst_video_colorimetry_to_string (&colorimetry))) {
732 gst_caps_set_simple (caps, "colorimetry", G_TYPE_STRING, color, NULL);
737 gst_caps_set_simple (caps, "views", G_TYPE_INT, info->views, NULL);
739 if (info->flags & GST_VIDEO_FLAG_VARIABLE_FPS && info->fps_n != 0) {
740 /* variable fps with a max-framerate */
741 gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, 0, 1,
742 "max-framerate", GST_TYPE_FRACTION, info->fps_n, info->fps_d, NULL);
744 /* no variable fps or no max-framerate */
745 gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION,
746 info->fps_n, info->fps_d, NULL);
753 fill_planes (GstVideoInfo * info)
755 gsize width, height, cr_h;
758 width = (gsize) info->width;
759 height = (gsize) GST_VIDEO_INFO_FIELD_HEIGHT (info);
761 /* Sanity check the resulting frame size for overflows */
762 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
763 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
764 bpp = GST_ROUND_UP_8 (bpp) / 8;
765 if (bpp > 0 && GST_ROUND_UP_128 ((guint64) width) * ((guint64) height) >=
767 GST_ERROR ("Frame size %ux%u would overflow", info->width, info->height);
771 switch (info->finfo->format) {
772 case GST_VIDEO_FORMAT_YUY2:
773 case GST_VIDEO_FORMAT_YVYU:
774 case GST_VIDEO_FORMAT_UYVY:
775 case GST_VIDEO_FORMAT_VYUY:
776 info->stride[0] = GST_ROUND_UP_4 (width * 2);
778 info->size = info->stride[0] * height;
780 case GST_VIDEO_FORMAT_AYUV:
781 case GST_VIDEO_FORMAT_RGBx:
782 case GST_VIDEO_FORMAT_RGBA:
783 case GST_VIDEO_FORMAT_BGRx:
784 case GST_VIDEO_FORMAT_BGRA:
785 case GST_VIDEO_FORMAT_SR32:
786 case GST_VIDEO_FORMAT_xRGB:
787 case GST_VIDEO_FORMAT_ARGB:
788 case GST_VIDEO_FORMAT_xBGR:
789 case GST_VIDEO_FORMAT_ABGR:
790 case GST_VIDEO_FORMAT_r210:
791 case GST_VIDEO_FORMAT_Y410:
792 case GST_VIDEO_FORMAT_VUYA:
793 case GST_VIDEO_FORMAT_BGR10A2_LE:
794 info->stride[0] = width * 4;
796 info->size = info->stride[0] * height;
798 case GST_VIDEO_FORMAT_RGB16:
799 case GST_VIDEO_FORMAT_BGR16:
800 case GST_VIDEO_FORMAT_RGB15:
801 case GST_VIDEO_FORMAT_BGR15:
802 info->stride[0] = GST_ROUND_UP_4 (width * 2);
804 info->size = info->stride[0] * height;
806 case GST_VIDEO_FORMAT_RGB:
807 case GST_VIDEO_FORMAT_BGR:
808 case GST_VIDEO_FORMAT_v308:
809 case GST_VIDEO_FORMAT_IYU2:
810 info->stride[0] = GST_ROUND_UP_4 (width * 3);
812 info->size = info->stride[0] * height;
814 case GST_VIDEO_FORMAT_v210:
815 info->stride[0] = ((width + 47) / 48) * 128;
817 info->size = info->stride[0] * height;
819 case GST_VIDEO_FORMAT_v216:
820 case GST_VIDEO_FORMAT_Y210:
821 info->stride[0] = GST_ROUND_UP_8 (width * 4);
823 info->size = info->stride[0] * height;
825 case GST_VIDEO_FORMAT_GRAY8:
826 info->stride[0] = GST_ROUND_UP_4 (width);
828 info->size = info->stride[0] * height;
830 case GST_VIDEO_FORMAT_GRAY16_BE:
831 case GST_VIDEO_FORMAT_GRAY16_LE:
832 case GST_VIDEO_FORMAT_INVZ:
833 info->stride[0] = GST_ROUND_UP_4 (width * 2);
835 info->size = info->stride[0] * height;
837 case GST_VIDEO_FORMAT_UYVP:
838 info->stride[0] = GST_ROUND_UP_4 ((width * 2 * 5 + 3) / 4);
840 info->size = info->stride[0] * height;
842 case GST_VIDEO_FORMAT_RGB8P:
843 info->stride[0] = GST_ROUND_UP_4 (width);
846 info->offset[1] = info->stride[0] * height;
847 info->size = info->offset[1] + (4 * 256);
849 case GST_VIDEO_FORMAT_IYU1:
850 info->stride[0] = GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) +
851 GST_ROUND_UP_4 (width) / 2);
853 info->size = info->stride[0] * height;
855 case GST_VIDEO_FORMAT_ARGB64:
856 case GST_VIDEO_FORMAT_AYUV64:
857 info->stride[0] = width * 8;
859 info->size = info->stride[0] * height;
861 case GST_VIDEO_FORMAT_I420:
862 case GST_VIDEO_FORMAT_S420:
863 case GST_VIDEO_FORMAT_YV12: /* same as I420, but plane 1+2 swapped */
864 #ifdef TIZEN_PROFILE_TV
865 case GST_VIDEO_FORMAT_STV0:
866 case GST_VIDEO_FORMAT_STV1:
868 info->stride[0] = GST_ROUND_UP_4 (width);
869 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
870 info->stride[2] = info->stride[1];
872 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
873 cr_h = GST_ROUND_UP_2 (height) / 2;
874 if (GST_VIDEO_INFO_IS_INTERLACED (info))
875 cr_h = GST_ROUND_UP_2 (cr_h);
876 info->offset[2] = info->offset[1] + info->stride[1] * cr_h;
877 info->size = info->offset[2] + info->stride[2] * cr_h;
879 case GST_VIDEO_FORMAT_Y41B:
880 info->stride[0] = GST_ROUND_UP_4 (width);
881 info->stride[1] = GST_ROUND_UP_16 (width) / 4;
882 info->stride[2] = info->stride[1];
884 info->offset[1] = info->stride[0] * height;
885 info->offset[2] = info->offset[1] + info->stride[1] * height;
886 /* simplification of ROUNDUP4(w)*h + 2*((ROUNDUP16(w)/4)*h */
887 info->size = (info->stride[0] + (GST_ROUND_UP_16 (width) / 2)) * height;
889 case GST_VIDEO_FORMAT_Y42B:
890 info->stride[0] = GST_ROUND_UP_4 (width);
891 info->stride[1] = GST_ROUND_UP_8 (width) / 2;
892 info->stride[2] = info->stride[1];
894 info->offset[1] = info->stride[0] * height;
895 info->offset[2] = info->offset[1] + info->stride[1] * height;
896 /* simplification of ROUNDUP4(w)*h + 2*(ROUNDUP8(w)/2)*h */
897 info->size = (info->stride[0] + GST_ROUND_UP_8 (width)) * height;
899 case GST_VIDEO_FORMAT_Y444:
900 case GST_VIDEO_FORMAT_GBR:
901 info->stride[0] = GST_ROUND_UP_4 (width);
902 info->stride[1] = info->stride[0];
903 info->stride[2] = info->stride[0];
905 info->offset[1] = info->stride[0] * height;
906 info->offset[2] = info->offset[1] * 2;
907 info->size = info->stride[0] * height * 3;
909 case GST_VIDEO_FORMAT_GBRA:
910 info->stride[0] = GST_ROUND_UP_4 (width);
911 info->stride[1] = info->stride[0];
912 info->stride[2] = info->stride[0];
913 info->stride[3] = info->stride[0];
915 info->offset[1] = info->stride[0] * height;
916 info->offset[2] = info->offset[1] * 2;
917 info->offset[3] = info->offset[1] * 3;
918 info->size = info->stride[0] * height * 4;
920 case GST_VIDEO_FORMAT_NV12:
921 #ifdef TIZEN_FEATURE_VIDEO_MODIFICATION
922 case GST_VIDEO_FORMAT_SN12:
923 case GST_VIDEO_FORMAT_ST12:
924 case GST_VIDEO_FORMAT_SN21:
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 #ifdef TIZEN_FEATURE_VIDEO_MODIFICATION
932 info->size = info->stride[0] * GST_ROUND_UP_2 (height) * 3 / 2;
934 cr_h = GST_ROUND_UP_2 (height) / 2;
935 if (GST_VIDEO_INFO_IS_INTERLACED (info))
936 cr_h = GST_ROUND_UP_2 (cr_h);
937 info->size = info->offset[1] + info->stride[0] * cr_h;
940 case GST_VIDEO_FORMAT_NV16:
941 case GST_VIDEO_FORMAT_NV61:
942 info->stride[0] = GST_ROUND_UP_4 (width);
943 info->stride[1] = info->stride[0];
945 info->offset[1] = info->stride[0] * height;
946 info->size = info->stride[0] * height * 2;
948 case GST_VIDEO_FORMAT_NV24:
949 info->stride[0] = GST_ROUND_UP_4 (width);
950 info->stride[1] = GST_ROUND_UP_4 (width * 2);
952 info->offset[1] = info->stride[0] * height;
953 info->size = info->stride[0] * height + info->stride[1] * height;
955 case GST_VIDEO_FORMAT_A420:
956 info->stride[0] = GST_ROUND_UP_4 (width);
957 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
958 info->stride[2] = info->stride[1];
959 info->stride[3] = info->stride[0];
961 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
962 cr_h = GST_ROUND_UP_2 (height) / 2;
963 if (GST_VIDEO_INFO_IS_INTERLACED (info))
964 cr_h = GST_ROUND_UP_2 (cr_h);
965 info->offset[2] = info->offset[1] + info->stride[1] * cr_h;
966 info->offset[3] = info->offset[2] + info->stride[2] * cr_h;
967 info->size = info->offset[3] + info->stride[0] * GST_ROUND_UP_2 (height);
969 case GST_VIDEO_FORMAT_YUV9:
970 case GST_VIDEO_FORMAT_YVU9:
971 info->stride[0] = GST_ROUND_UP_4 (width);
972 info->stride[1] = GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4);
973 info->stride[2] = info->stride[1];
975 info->offset[1] = info->stride[0] * height;
976 cr_h = GST_ROUND_UP_4 (height) / 4;
977 if (GST_VIDEO_INFO_IS_INTERLACED (info))
978 cr_h = GST_ROUND_UP_2 (cr_h);
979 info->offset[2] = info->offset[1] + info->stride[1] * cr_h;
980 info->size = info->offset[2] + info->stride[2] * cr_h;
982 case GST_VIDEO_FORMAT_I420_10LE:
983 case GST_VIDEO_FORMAT_I420_10BE:
984 case GST_VIDEO_FORMAT_I420_12LE:
985 case GST_VIDEO_FORMAT_I420_12BE:
986 info->stride[0] = GST_ROUND_UP_4 (width * 2);
987 info->stride[1] = GST_ROUND_UP_4 (width);
988 info->stride[2] = info->stride[1];
990 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
991 cr_h = GST_ROUND_UP_2 (height) / 2;
992 if (GST_VIDEO_INFO_IS_INTERLACED (info))
993 cr_h = GST_ROUND_UP_2 (cr_h);
994 info->offset[2] = info->offset[1] + info->stride[1] * cr_h;
995 info->size = info->offset[2] + info->stride[2] * cr_h;
997 case GST_VIDEO_FORMAT_I422_10LE:
998 case GST_VIDEO_FORMAT_I422_10BE:
999 case GST_VIDEO_FORMAT_I422_12LE:
1000 case GST_VIDEO_FORMAT_I422_12BE:
1001 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1002 info->stride[1] = GST_ROUND_UP_4 (width);
1003 info->stride[2] = info->stride[1];
1004 info->offset[0] = 0;
1005 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1006 info->offset[2] = info->offset[1] +
1007 info->stride[1] * GST_ROUND_UP_2 (height);
1008 info->size = info->offset[2] + info->stride[2] * GST_ROUND_UP_2 (height);
1010 case GST_VIDEO_FORMAT_Y444_10LE:
1011 case GST_VIDEO_FORMAT_Y444_10BE:
1012 case GST_VIDEO_FORMAT_Y444_12LE:
1013 case GST_VIDEO_FORMAT_Y444_12BE:
1014 case GST_VIDEO_FORMAT_GBR_10LE:
1015 case GST_VIDEO_FORMAT_GBR_10BE:
1016 case GST_VIDEO_FORMAT_GBR_12LE:
1017 case GST_VIDEO_FORMAT_GBR_12BE:
1018 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1019 info->stride[1] = info->stride[0];
1020 info->stride[2] = info->stride[0];
1021 info->offset[0] = 0;
1022 info->offset[1] = info->stride[0] * height;
1023 info->offset[2] = info->offset[1] * 2;
1024 info->size = info->stride[0] * height * 3;
1026 case GST_VIDEO_FORMAT_GBRA_10LE:
1027 case GST_VIDEO_FORMAT_GBRA_10BE:
1028 case GST_VIDEO_FORMAT_GBRA_12LE:
1029 case GST_VIDEO_FORMAT_GBRA_12BE:
1030 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1031 info->stride[1] = info->stride[0];
1032 info->stride[2] = info->stride[0];
1033 info->stride[3] = info->stride[0];
1034 info->offset[0] = 0;
1035 info->offset[1] = info->stride[0] * height;
1036 info->offset[2] = info->offset[1] * 2;
1037 info->offset[3] = info->offset[1] * 3;
1038 info->size = info->stride[0] * height * 4;
1040 case GST_VIDEO_FORMAT_NV12_64Z32:
1042 GST_VIDEO_TILE_MAKE_STRIDE (GST_ROUND_UP_128 (width) / 64,
1043 GST_ROUND_UP_32 (height) / 32);
1045 GST_VIDEO_TILE_MAKE_STRIDE (GST_ROUND_UP_128 (width) / 64,
1046 GST_ROUND_UP_64 (height) / 64);
1047 info->offset[0] = 0;
1048 info->offset[1] = GST_ROUND_UP_128 (width) * GST_ROUND_UP_32 (height);
1049 info->size = info->offset[1] +
1050 GST_ROUND_UP_128 (width) * GST_ROUND_UP_64 (height) / 2;
1052 case GST_VIDEO_FORMAT_A420_10LE:
1053 case GST_VIDEO_FORMAT_A420_10BE:
1054 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1055 info->stride[1] = GST_ROUND_UP_4 (width);
1056 info->stride[2] = info->stride[1];
1057 info->stride[3] = info->stride[0];
1058 info->offset[0] = 0;
1059 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1060 cr_h = GST_ROUND_UP_2 (height) / 2;
1061 if (GST_VIDEO_INFO_IS_INTERLACED (info))
1062 cr_h = GST_ROUND_UP_2 (cr_h);
1063 info->offset[2] = info->offset[1] + info->stride[1] * cr_h;
1064 info->offset[3] = info->offset[2] + info->stride[2] * cr_h;
1065 info->size = info->offset[3] + info->stride[0] * GST_ROUND_UP_2 (height);
1067 case GST_VIDEO_FORMAT_A422_10LE:
1068 case GST_VIDEO_FORMAT_A422_10BE:
1069 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1070 info->stride[1] = GST_ROUND_UP_4 (width);
1071 info->stride[2] = info->stride[1];
1072 info->stride[3] = info->stride[0];
1073 info->offset[0] = 0;
1074 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1075 info->offset[2] = info->offset[1] +
1076 info->stride[1] * GST_ROUND_UP_2 (height);
1078 info->offset[2] + info->stride[2] * GST_ROUND_UP_2 (height);
1079 info->size = info->offset[3] + info->stride[0] * GST_ROUND_UP_2 (height);
1081 case GST_VIDEO_FORMAT_A444_10LE:
1082 case GST_VIDEO_FORMAT_A444_10BE:
1083 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1084 info->stride[1] = info->stride[0];
1085 info->stride[2] = info->stride[0];
1086 info->stride[3] = info->stride[0];
1087 info->offset[0] = 0;
1088 info->offset[1] = info->stride[0] * height;
1089 info->offset[2] = info->offset[1] * 2;
1090 info->offset[3] = info->offset[1] * 3;
1091 info->size = info->stride[0] * height * 4;
1093 case GST_VIDEO_FORMAT_P010_10LE:
1094 case GST_VIDEO_FORMAT_P010_10BE:
1095 info->stride[0] = GST_ROUND_UP_4 (width * 2);
1096 info->stride[1] = info->stride[0];
1097 info->offset[0] = 0;
1098 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1099 cr_h = GST_ROUND_UP_2 (height) / 2;
1100 info->size = info->offset[1] + info->stride[0] * cr_h;
1102 case GST_VIDEO_FORMAT_GRAY10_LE32:
1103 info->stride[0] = (width + 2) / 3 * 4;
1104 info->offset[0] = 0;
1105 info->size = info->stride[0] * GST_ROUND_UP_2 (height);
1107 case GST_VIDEO_FORMAT_NV12_10LE32:
1108 info->stride[0] = (width + 2) / 3 * 4;
1109 info->stride[1] = info->stride[0];
1110 info->offset[0] = 0;
1111 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1112 cr_h = GST_ROUND_UP_2 (height) / 2;
1113 if (GST_VIDEO_INFO_IS_INTERLACED (info))
1114 cr_h = GST_ROUND_UP_2 (cr_h);
1115 info->size = info->offset[1] + info->stride[0] * cr_h;
1117 case GST_VIDEO_FORMAT_NV16_10LE32:
1118 info->stride[0] = (width + 2) / 3 * 4;
1119 info->stride[1] = info->stride[0];
1120 info->offset[0] = 0;
1121 info->offset[1] = info->stride[0] * height;
1122 info->size = info->stride[0] * height * 2;
1124 case GST_VIDEO_FORMAT_NV12_10LE40:
1125 info->stride[0] = ((width * 5 >> 2) + 4) / 5 * 5;
1126 info->stride[1] = info->stride[0];
1127 info->offset[0] = 0;
1128 info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
1129 cr_h = GST_ROUND_UP_2 (height) / 2;
1130 if (GST_VIDEO_INFO_IS_INTERLACED (info))
1131 cr_h = GST_ROUND_UP_2 (cr_h);
1132 info->size = info->offset[1] + info->stride[0] * cr_h;
1135 case GST_VIDEO_FORMAT_ENCODED:
1137 case GST_VIDEO_FORMAT_UNKNOWN:
1138 #ifdef TIZEN_FEATURE_VIDEO_MODIFICATION
1141 GST_ERROR ("invalid format");
1142 g_warning ("invalid format");
1150 * gst_video_info_convert:
1151 * @info: a #GstVideoInfo
1152 * @src_format: #GstFormat of the @src_value
1153 * @src_value: value to convert
1154 * @dest_format: #GstFormat of the @dest_value
1155 * @dest_value: (out): pointer to destination value
1157 * Converts among various #GstFormat types. This function handles
1158 * GST_FORMAT_BYTES, GST_FORMAT_TIME, and GST_FORMAT_DEFAULT. For
1159 * raw video, GST_FORMAT_DEFAULT corresponds to video frames. This
1160 * function can be used to handle pad queries of the type GST_QUERY_CONVERT.
1162 * Returns: TRUE if the conversion was successful.
1165 gst_video_info_convert (GstVideoInfo * info,
1166 GstFormat src_format, gint64 src_value,
1167 GstFormat dest_format, gint64 * dest_value)
1169 gboolean ret = FALSE;
1173 g_return_val_if_fail (info != NULL, 0);
1174 g_return_val_if_fail (info->finfo != NULL, 0);
1175 g_return_val_if_fail (info->finfo->format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1176 g_return_val_if_fail (info->size > 0, 0);
1179 fps_n = info->fps_n;
1180 fps_d = info->fps_d;
1182 GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
1183 src_value, gst_format_get_name (src_format),
1184 gst_format_get_name (dest_format));
1186 if (src_format == dest_format) {
1187 *dest_value = src_value;
1192 if (src_value == -1) {
1198 /* bytes to frames */
1199 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_DEFAULT) {
1201 *dest_value = gst_util_uint64_scale (src_value, 1, size);
1203 GST_ERROR ("blocksize is 0");
1210 /* frames to bytes */
1211 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_BYTES) {
1212 *dest_value = gst_util_uint64_scale (src_value, size, 1);
1217 /* time to frames */
1218 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_DEFAULT) {
1220 *dest_value = gst_util_uint64_scale (src_value,
1221 fps_n, GST_SECOND * fps_d);
1223 GST_ERROR ("framerate denominator is 0");
1230 /* frames to time */
1231 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_TIME) {
1233 *dest_value = gst_util_uint64_scale (src_value,
1234 GST_SECOND * fps_d, fps_n);
1236 GST_ERROR ("framerate numerator is 0");
1244 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
1246 *dest_value = gst_util_uint64_scale (src_value,
1247 fps_n * size, GST_SECOND * fps_d);
1249 GST_ERROR ("framerate denominator is 0");
1257 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_TIME) {
1258 if (fps_n != 0 && size != 0) {
1259 *dest_value = gst_util_uint64_scale (src_value,
1260 GST_SECOND * fps_d, fps_n * size);
1262 GST_ERROR ("framerate denominator and/or blocksize is 0");
1270 GST_DEBUG ("ret=%d result %" G_GINT64_FORMAT, ret, *dest_value);
1276 * gst_video_info_align:
1277 * @info: a #GstVideoInfo
1278 * @align: alignment parameters
1280 * Adjust the offset and stride fields in @info so that the padding and
1281 * stride alignment in @align is respected.
1283 * Extra padding will be added to the right side when stride alignment padding
1284 * is required and @align will be updated with the new padding values.
1286 * Returns: %FALSE if alignment could not be applied, e.g. because the
1287 * size of a frame can't be represented as a 32 bit integer (Since: 1.12)
1290 gst_video_info_align (GstVideoInfo * info, GstVideoAlignment * align)
1292 const GstVideoFormatInfo *vinfo = info->finfo;
1294 gint padded_width, padded_height;
1298 width = GST_VIDEO_INFO_WIDTH (info);
1299 height = GST_VIDEO_INFO_HEIGHT (info);
1301 GST_LOG ("padding %u-%ux%u-%u", align->padding_top,
1302 align->padding_left, align->padding_right, align->padding_bottom);
1304 n_planes = GST_VIDEO_INFO_N_PLANES (info);
1306 if (GST_VIDEO_FORMAT_INFO_HAS_PALETTE (vinfo))
1309 /* first make sure the left padding does not cause alignment problems later */
1311 GST_LOG ("left padding %u", align->padding_left);
1313 for (i = 0; i < n_planes; i++) {
1316 /* this is the amout of pixels to add as left padding */
1317 hedge = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (vinfo, i, align->padding_left);
1318 hedge *= GST_VIDEO_FORMAT_INFO_PSTRIDE (vinfo, i);
1320 GST_LOG ("plane %d, padding %d, alignment %u", i, hedge,
1321 align->stride_align[i]);
1322 aligned &= (hedge & align->stride_align[i]) == 0;
1327 GST_LOG ("unaligned padding, increasing padding");
1328 /* increase padded_width */
1329 align->padding_left += align->padding_left & ~(align->padding_left - 1);
1332 /* add the padding */
1333 padded_width = width + align->padding_left + align->padding_right;
1334 padded_height = height + align->padding_top + align->padding_bottom;
1337 GST_LOG ("padded dimension %u-%u", padded_width, padded_height);
1339 info->width = padded_width;
1340 info->height = padded_height;
1342 if (!fill_planes (info))
1345 /* check alignment */
1347 for (i = 0; i < n_planes; i++) {
1348 GST_LOG ("plane %d, stride %d, alignment %u", i, info->stride[i],
1349 align->stride_align[i]);
1350 aligned &= (info->stride[i] & align->stride_align[i]) == 0;
1355 GST_LOG ("unaligned strides, increasing dimension");
1356 /* increase padded_width */
1357 padded_width += padded_width & ~(padded_width - 1);
1360 align->padding_right = padded_width - width - align->padding_left;
1362 info->width = width;
1363 info->height = height;
1365 for (i = 0; i < n_planes; i++) {
1366 gint vedge, hedge, comp;
1368 /* Find the component for this plane, FIXME, we assume the plane number and
1369 * component number is the same for now, for scaling the dimensions this is
1370 * currently true for all formats but it might not be when adding new
1371 * formats. We might need to add a plane subsamling in the format info to
1372 * make this more generic or maybe use a plane -> component mapping. */
1376 GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (vinfo, comp, align->padding_left);
1378 GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (vinfo, comp, align->padding_top);
1380 GST_DEBUG ("plane %d: comp: %d, hedge %d vedge %d align %d stride %d", i,
1381 comp, hedge, vedge, align->stride_align[i], info->stride[i]);
1383 info->offset[i] += (vedge * info->stride[i]) +
1384 (hedge * GST_VIDEO_FORMAT_INFO_PSTRIDE (vinfo, comp));