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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
30 * @short_description: Support library for video operations
34 * This library contains some helper functions and includes the
35 * videosink and videofilter base classes.
40 static GstVideoFormat gst_video_format_from_rgb32_masks (int red_mask,
41 int green_mask, int blue_mask);
42 static GstVideoFormat gst_video_format_from_rgba32_masks (int red_mask,
43 int green_mask, int blue_mask, int alpha_mask);
44 static GstVideoFormat gst_video_format_from_rgb24_masks (int red_mask,
45 int green_mask, int blue_mask);
46 static GstVideoFormat gst_video_format_from_rgb16_masks (int red_mask,
47 int green_mask, int blue_mask);
51 * gst_video_frame_rate:
52 * @pad: pointer to a #GstPad
54 * A convenience function to retrieve a GValue holding the framerate
55 * from the caps on a pad.
57 * The pad needs to have negotiated caps containing a framerate property.
59 * Returns: NULL if the pad has no configured caps or the configured caps
60 * do not contain a framerate.
64 gst_video_frame_rate (GstPad * pad)
69 const GstCaps *caps = NULL;
70 GstStructure *structure;
73 caps = GST_PAD_CAPS (pad);
75 g_warning ("gstvideo: failed to get caps of pad %s:%s",
76 GST_DEBUG_PAD_NAME (pad));
80 structure = gst_caps_get_structure (caps, 0);
81 if ((fps = gst_structure_get_value (structure, "framerate")) == NULL) {
82 g_warning ("gstvideo: failed to get framerate property of pad %s:%s",
83 GST_DEBUG_PAD_NAME (pad));
86 if (!GST_VALUE_HOLDS_FRACTION (fps)) {
88 ("gstvideo: framerate property of pad %s:%s is not of type Fraction",
89 GST_DEBUG_PAD_NAME (pad));
93 fps_string = gst_value_serialize (fps);
94 GST_DEBUG ("Framerate request on pad %s:%s: %s",
95 GST_DEBUG_PAD_NAME (pad), fps_string);
102 * gst_video_get_size:
103 * @pad: pointer to a #GstPad
104 * @width: pointer to integer to hold pixel width of the video frames (output)
105 * @height: pointer to integer to hold pixel height of the video frames (output)
107 * Inspect the caps of the provided pad and retrieve the width and height of
108 * the video frames it is configured for.
110 * The pad needs to have negotiated caps containing width and height properties.
112 * Returns: TRUE if the width and height could be retrieved.
116 gst_video_get_size (GstPad * pad, gint * width, gint * height)
118 const GstCaps *caps = NULL;
119 GstStructure *structure;
122 g_return_val_if_fail (pad != NULL, FALSE);
123 g_return_val_if_fail (width != NULL, FALSE);
124 g_return_val_if_fail (height != NULL, FALSE);
126 caps = GST_PAD_CAPS (pad);
129 g_warning ("gstvideo: failed to get caps of pad %s:%s",
130 GST_DEBUG_PAD_NAME (pad));
134 structure = gst_caps_get_structure (caps, 0);
135 ret = gst_structure_get_int (structure, "width", width);
136 ret &= gst_structure_get_int (structure, "height", height);
139 g_warning ("gstvideo: failed to get size properties on pad %s:%s",
140 GST_DEBUG_PAD_NAME (pad));
144 GST_DEBUG ("size request on pad %s:%s: %dx%d",
145 GST_DEBUG_PAD_NAME (pad), width ? *width : -1, height ? *height : -1);
151 * gst_video_calculate_display_ratio:
152 * @dar_n: Numerator of the calculated display_ratio
153 * @dar_d: Denominator of the calculated display_ratio
154 * @video_width: Width of the video frame in pixels
155 * @video_height: Height of the video frame in pixels
156 * @video_par_n: Numerator of the pixel aspect ratio of the input video.
157 * @video_par_d: Denominator of the pixel aspect ratio of the input video.
158 * @display_par_n: Numerator of the pixel aspect ratio of the display device
159 * @display_par_d: Denominator of the pixel aspect ratio of the display device
161 * Given the Pixel Aspect Ratio and size of an input video frame, and the
162 * pixel aspect ratio of the intended display device, calculates the actual
163 * display ratio the video will be rendered with.
165 * Returns: A boolean indicating success and a calculated Display Ratio in the
166 * dar_n and dar_d parameters.
167 * The return value is FALSE in the case of integer overflow or other error.
172 gst_video_calculate_display_ratio (guint * dar_n, guint * dar_d,
173 guint video_width, guint video_height,
174 guint video_par_n, guint video_par_d,
175 guint display_par_n, guint display_par_d)
180 g_return_val_if_fail (dar_n != NULL, FALSE);
181 g_return_val_if_fail (dar_d != NULL, FALSE);
183 /* Calculate (video_width * video_par_n * display_par_d) /
184 * (video_height * video_par_d * display_par_n) */
185 if (!gst_util_fraction_multiply (video_width, video_height, video_par_n,
186 video_par_d, &tmp_n, &tmp_d))
189 if (!gst_util_fraction_multiply (tmp_n, tmp_d, display_par_d, display_par_n,
193 g_return_val_if_fail (num > 0, FALSE);
194 g_return_val_if_fail (den > 0, FALSE);
205 * gst_video_format_parse_caps_interlaced:
206 * @caps: the fixed #GstCaps to parse
207 * @interlaced: whether @caps represents interlaced video or not, may be NULL (output)
209 * Extracts whether the caps represents interlaced content or not and places it
214 * Returns: TRUE if @caps was parsed correctly.
217 gst_video_format_parse_caps_interlaced (GstCaps * caps, gboolean * interlaced)
219 GstStructure *structure;
221 if (!gst_caps_is_fixed (caps))
224 structure = gst_caps_get_structure (caps, 0);
227 if (!gst_structure_get_boolean (structure, "interlaced", interlaced))
235 * gst_video_parse_caps_color_matrix:
236 * @caps: the fixed #GstCaps to parse
238 * Extracts the color matrix used by the caps. Possible values are
239 * "sdtv" for the standard definition color matrix (as specified in
240 * Rec. ITU-R BT.470-6) or "hdtv" for the high definition color
241 * matrix (as specified in Rec. ITU-R BT.709)
245 * Returns: a color matrix string, or NULL if no color matrix could be
249 gst_video_parse_caps_color_matrix (GstCaps * caps)
251 GstStructure *structure;
254 if (!gst_caps_is_fixed (caps))
257 structure = gst_caps_get_structure (caps, 0);
259 s = gst_structure_get_string (structure, "color-matrix");
263 if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
271 * gst_video_parse_caps_chroma_site:
272 * @caps: the fixed #GstCaps to parse
274 * Extracts the chroma site used by the caps. Possible values are
275 * "mpeg2" for MPEG-2 style chroma siting (co-sited horizontally,
276 * halfway-sited vertically), "jpeg" for JPEG and Theora style
277 * chroma siting (halfway-sited both horizontally and vertically).
278 * Other chroma site values are possible, but uncommon.
280 * When no chroma site is specified in the caps, it should be assumed
285 * Returns: a chroma site string, or NULL if no chroma site could be
289 gst_video_parse_caps_chroma_site (GstCaps * caps)
291 GstStructure *structure;
294 if (!gst_caps_is_fixed (caps))
297 structure = gst_caps_get_structure (caps, 0);
299 s = gst_structure_get_string (structure, "chroma-site");
303 if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
311 * gst_video_format_parse_caps:
312 * @caps: the #GstCaps to parse
313 * @format: the #GstVideoFormat of the video represented by @caps (output)
314 * @width: the width of the video represented by @caps, may be NULL (output)
315 * @height: the height of the video represented by @caps, may be NULL (output)
317 * Determines the #GstVideoFormat of @caps and places it in the location
318 * pointed to by @format. Extracts the size of the video and places it
319 * in the location pointed to by @width and @height. If @caps does not
320 * represent one of the raw video formats listed in #GstVideoFormat, the
321 * function will fail and return FALSE.
325 * Returns: TRUE if @caps was parsed correctly.
328 gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format,
329 int *width, int *height)
331 GstStructure *structure;
334 if (!gst_caps_is_fixed (caps))
337 structure = gst_caps_get_structure (caps, 0);
340 if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
343 ok &= gst_structure_get_fourcc (structure, "format", &fourcc);
345 *format = gst_video_format_from_fourcc (fourcc);
346 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
349 } else if (gst_structure_has_name (structure, "video/x-raw-rgb")) {
359 ok &= gst_structure_get_int (structure, "depth", &depth);
360 ok &= gst_structure_get_int (structure, "bpp", &bpp);
363 ok &= gst_structure_get_int (structure, "endianness", &endianness);
364 ok &= gst_structure_get_int (structure, "red_mask", &red_mask);
365 ok &= gst_structure_get_int (structure, "green_mask", &green_mask);
366 ok &= gst_structure_get_int (structure, "blue_mask", &blue_mask);
368 have_alpha = gst_structure_get_int (structure, "alpha_mask", &alpha_mask);
370 if (depth == 30 && bpp == 32 && endianness == G_BIG_ENDIAN) {
371 *format = GST_VIDEO_FORMAT_r210;
372 } else if (depth == 24 && bpp == 32 && endianness == G_BIG_ENDIAN) {
373 *format = gst_video_format_from_rgb32_masks (red_mask, green_mask,
375 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
378 } else if (depth == 32 && bpp == 32 && endianness == G_BIG_ENDIAN &&
380 *format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
381 blue_mask, alpha_mask);
382 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
385 } else if (depth == 24 && bpp == 24 && endianness == G_BIG_ENDIAN) {
386 *format = gst_video_format_from_rgb24_masks (red_mask, green_mask,
388 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
391 } else if ((depth == 15 || depth == 16) && bpp == 16 &&
392 endianness == G_BYTE_ORDER) {
393 *format = gst_video_format_from_rgb16_masks (red_mask, green_mask,
395 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
398 } else if (depth == 8 && bpp == 8) {
399 *format = GST_VIDEO_FORMAT_RGB8_PALETTED;
400 } else if (depth == 64 && bpp == 64) {
401 *format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
402 blue_mask, alpha_mask);
403 if (*format == GST_VIDEO_FORMAT_ARGB) {
404 *format = GST_VIDEO_FORMAT_ARGB64;
406 *format = GST_VIDEO_FORMAT_UNKNOWN;
412 } else if (gst_structure_has_name (structure, "video/x-raw-gray")) {
417 ok &= gst_structure_get_int (structure, "depth", &depth);
418 ok &= gst_structure_get_int (structure, "bpp", &bpp);
421 ok &= gst_structure_get_int (structure, "endianness", &endianness);
423 if (depth == 8 && bpp == 8) {
424 *format = GST_VIDEO_FORMAT_GRAY8;
425 } else if (depth == 16 && bpp == 16 && endianness == G_BIG_ENDIAN) {
426 *format = GST_VIDEO_FORMAT_GRAY16_BE;
427 } else if (depth == 16 && bpp == 16 && endianness == G_LITTLE_ENDIAN) {
428 *format = GST_VIDEO_FORMAT_GRAY16_LE;
438 ok &= gst_structure_get_int (structure, "width", width);
442 ok &= gst_structure_get_int (structure, "height", height);
450 * gst_video_parse_caps_framerate:
451 * @caps: pointer to a #GstCaps instance
452 * @fps_n: pointer to integer to hold numerator of frame rate (output)
453 * @fps_d: pointer to integer to hold denominator of frame rate (output)
455 * Extracts the frame rate from @caps and places the values in the locations
456 * pointed to by @fps_n and @fps_d. Returns TRUE if the values could be
457 * parsed correctly, FALSE if not.
459 * This function can be used with #GstCaps that have any media type; it
460 * is not limited to formats handled by #GstVideoFormat.
464 * Returns: TRUE if @caps was parsed correctly.
467 gst_video_parse_caps_framerate (GstCaps * caps, int *fps_n, int *fps_d)
469 GstStructure *structure;
471 if (!gst_caps_is_fixed (caps))
474 structure = gst_caps_get_structure (caps, 0);
476 return gst_structure_get_fraction (structure, "framerate", fps_n, fps_d);
480 * gst_video_parse_caps_pixel_aspect_ratio:
481 * @caps: pointer to a #GstCaps instance
482 * @par_n: pointer to numerator of pixel aspect ratio (output)
483 * @par_d: pointer to denominator of pixel aspect ratio (output)
485 * Extracts the pixel aspect ratio from @caps and places the values in
486 * the locations pointed to by @par_n and @par_d. Returns TRUE if the
487 * values could be parsed correctly, FALSE if not.
489 * This function can be used with #GstCaps that have any media type; it
490 * is not limited to formats handled by #GstVideoFormat.
494 * Returns: TRUE if @caps was parsed correctly.
497 gst_video_parse_caps_pixel_aspect_ratio (GstCaps * caps, int *par_n, int *par_d)
499 GstStructure *structure;
501 if (!gst_caps_is_fixed (caps))
504 structure = gst_caps_get_structure (caps, 0);
506 if (!gst_structure_get_fraction (structure, "pixel-aspect-ratio",
515 * gst_video_format_new_caps_interlaced:
516 * @format: the #GstVideoFormat describing the raw video format
517 * @width: width of video
518 * @height: height of video
519 * @framerate_n: numerator of frame rate
520 * @framerate_d: denominator of frame rate
521 * @par_n: numerator of pixel aspect ratio
522 * @par_d: denominator of pixel aspect ratio
523 * @interlaced: #TRUE if the format is interlaced
525 * Creates a new #GstCaps object based on the parameters provided.
529 * Returns: a new #GstCaps object, or NULL if there was an error
532 gst_video_format_new_caps_interlaced (GstVideoFormat format,
533 int width, int height, int framerate_n, int framerate_d, int par_n,
534 int par_d, gboolean interlaced)
539 gst_video_format_new_caps (format, width, height, framerate_n,
540 framerate_d, par_n, par_d);
541 if (interlaced && (res != NULL))
542 gst_caps_set_simple (res, "interlaced", G_TYPE_BOOLEAN, TRUE, NULL);
548 gst_video_format_new_caps_raw (GstVideoFormat format)
550 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
552 if (gst_video_format_is_yuv (format)) {
553 return gst_caps_new_simple ("video/x-raw-yuv",
554 "format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format), NULL);
556 if (gst_video_format_is_rgb (format)) {
565 unsigned int mask = 0;
568 case GST_VIDEO_FORMAT_RGBx:
569 case GST_VIDEO_FORMAT_BGRx:
570 case GST_VIDEO_FORMAT_xRGB:
571 case GST_VIDEO_FORMAT_xBGR:
576 case GST_VIDEO_FORMAT_RGBA:
577 case GST_VIDEO_FORMAT_BGRA:
578 case GST_VIDEO_FORMAT_ARGB:
579 case GST_VIDEO_FORMAT_ABGR:
584 case GST_VIDEO_FORMAT_RGB:
585 case GST_VIDEO_FORMAT_BGR:
590 case GST_VIDEO_FORMAT_RGB16:
591 case GST_VIDEO_FORMAT_BGR16:
596 case GST_VIDEO_FORMAT_RGB15:
597 case GST_VIDEO_FORMAT_BGR15:
602 case GST_VIDEO_FORMAT_RGB8_PALETTED:
607 case GST_VIDEO_FORMAT_ARGB64:
612 case GST_VIDEO_FORMAT_r210:
620 if (bpp == 32 && depth == 30) {
621 red_mask = 0x3ff00000;
622 green_mask = 0x000ffc00;
623 blue_mask = 0x000003ff;
625 } else if (bpp == 32 || bpp == 24 || bpp == 64) {
632 mask >> (8 * gst_video_format_get_component_offset (format, 0, 0, 0));
634 mask >> (8 * gst_video_format_get_component_offset (format, 1, 0, 0));
636 mask >> (8 * gst_video_format_get_component_offset (format, 2, 0, 0));
637 } else if (bpp == 16) {
639 case GST_VIDEO_FORMAT_RGB16:
640 red_mask = GST_VIDEO_COMP1_MASK_16_INT;
641 green_mask = GST_VIDEO_COMP2_MASK_16_INT;
642 blue_mask = GST_VIDEO_COMP3_MASK_16_INT;
644 case GST_VIDEO_FORMAT_BGR16:
645 red_mask = GST_VIDEO_COMP3_MASK_16_INT;
646 green_mask = GST_VIDEO_COMP2_MASK_16_INT;
647 blue_mask = GST_VIDEO_COMP1_MASK_16_INT;
650 case GST_VIDEO_FORMAT_RGB15:
651 red_mask = GST_VIDEO_COMP1_MASK_15_INT;
652 green_mask = GST_VIDEO_COMP2_MASK_15_INT;
653 blue_mask = GST_VIDEO_COMP3_MASK_15_INT;
655 case GST_VIDEO_FORMAT_BGR15:
656 red_mask = GST_VIDEO_COMP3_MASK_15_INT;
657 green_mask = GST_VIDEO_COMP2_MASK_15_INT;
658 blue_mask = GST_VIDEO_COMP1_MASK_15_INT;
663 } else if (bpp != 8) {
667 caps = gst_caps_new_simple ("video/x-raw-rgb",
668 "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth, NULL);
671 gst_caps_set_simple (caps,
672 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
673 "red_mask", G_TYPE_INT, red_mask,
674 "green_mask", G_TYPE_INT, green_mask,
675 "blue_mask", G_TYPE_INT, blue_mask, NULL);
680 mask >> (8 * gst_video_format_get_component_offset (format, 3, 0, 0));
681 gst_caps_set_simple (caps, "alpha_mask", G_TYPE_INT, alpha_mask, NULL);
686 if (gst_video_format_is_gray (format)) {
693 case GST_VIDEO_FORMAT_GRAY8:
695 endianness = G_BIG_ENDIAN;
697 case GST_VIDEO_FORMAT_GRAY16_BE:
699 endianness = G_BIG_ENDIAN;
701 case GST_VIDEO_FORMAT_GRAY16_LE:
703 endianness = G_LITTLE_ENDIAN;
711 caps = gst_caps_new_simple ("video/x-raw-gray",
712 "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth, NULL);
714 caps = gst_caps_new_simple ("video/x-raw-gray",
715 "bpp", G_TYPE_INT, bpp,
716 "depth", G_TYPE_INT, depth,
717 "endianness", G_TYPE_INT, G_BIG_ENDIAN, NULL);
727 * gst_video_format_new_template_caps:
728 * @format: the #GstVideoFormat describing the raw video format
730 * Creates a new #GstCaps object based on the parameters provided.
731 * Size, frame rate, and pixel aspect ratio are set to the full
736 * Returns: a new #GstCaps object, or NULL if there was an error
739 gst_video_format_new_template_caps (GstVideoFormat format)
742 GstStructure *structure;
744 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
746 caps = gst_video_format_new_caps_raw (format);
748 GValue value = { 0 };
751 structure = gst_caps_get_structure (caps, 0);
753 gst_structure_set (structure,
754 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
755 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
756 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1,
757 "pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
759 g_value_init (&value, GST_TYPE_LIST);
760 g_value_init (&v, G_TYPE_BOOLEAN);
761 g_value_set_boolean (&v, TRUE);
762 gst_value_list_append_value (&value, &v);
763 g_value_set_boolean (&v, FALSE);
764 gst_value_list_append_value (&value, &v);
766 gst_structure_set_value (structure, "interlaced", &value);
768 g_value_reset (&value);
776 * gst_video_format_new_caps:
777 * @format: the #GstVideoFormat describing the raw video format
778 * @width: width of video
779 * @height: height of video
780 * @framerate_n: numerator of frame rate
781 * @framerate_d: denominator of frame rate
782 * @par_n: numerator of pixel aspect ratio
783 * @par_d: denominator of pixel aspect ratio
785 * Creates a new #GstCaps object based on the parameters provided.
789 * Returns: a new #GstCaps object, or NULL if there was an error
792 gst_video_format_new_caps (GstVideoFormat format, int width,
793 int height, int framerate_n, int framerate_d, int par_n, int par_d)
796 GstStructure *structure;
798 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
799 g_return_val_if_fail (width > 0 && height > 0, NULL);
801 caps = gst_video_format_new_caps_raw (format);
803 structure = gst_caps_get_structure (caps, 0);
805 gst_structure_set (structure,
806 "width", G_TYPE_INT, width,
807 "height", G_TYPE_INT, height,
808 "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
809 "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
817 * gst_video_format_from_fourcc:
818 * @fourcc: a FOURCC value representing raw YUV video
820 * Converts a FOURCC value into the corresponding #GstVideoFormat.
821 * If the FOURCC cannot be represented by #GstVideoFormat,
822 * #GST_VIDEO_FORMAT_UNKNOWN is returned.
826 * Returns: the #GstVideoFormat describing the FOURCC value
829 gst_video_format_from_fourcc (guint32 fourcc)
832 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
833 return GST_VIDEO_FORMAT_I420;
834 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
835 return GST_VIDEO_FORMAT_YV12;
836 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
837 return GST_VIDEO_FORMAT_YUY2;
838 case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'):
839 return GST_VIDEO_FORMAT_YVYU;
840 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
841 return GST_VIDEO_FORMAT_UYVY;
842 case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
843 return GST_VIDEO_FORMAT_AYUV;
844 case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
845 return GST_VIDEO_FORMAT_Y41B;
846 case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
847 return GST_VIDEO_FORMAT_Y42B;
848 case GST_MAKE_FOURCC ('Y', '4', '4', '4'):
849 return GST_VIDEO_FORMAT_Y444;
850 case GST_MAKE_FOURCC ('v', '2', '1', '0'):
851 return GST_VIDEO_FORMAT_v210;
852 case GST_MAKE_FOURCC ('v', '2', '1', '6'):
853 return GST_VIDEO_FORMAT_v216;
854 case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
855 return GST_VIDEO_FORMAT_NV12;
856 case GST_MAKE_FOURCC ('N', 'V', '2', '1'):
857 return GST_VIDEO_FORMAT_NV21;
858 case GST_MAKE_FOURCC ('v', '3', '0', '8'):
859 return GST_VIDEO_FORMAT_v308;
860 case GST_MAKE_FOURCC ('Y', '8', '0', '0'):
861 case GST_MAKE_FOURCC ('Y', '8', ' ', ' '):
862 case GST_MAKE_FOURCC ('G', 'R', 'E', 'Y'):
863 return GST_VIDEO_FORMAT_Y800;
864 case GST_MAKE_FOURCC ('Y', '1', '6', ' '):
865 return GST_VIDEO_FORMAT_Y16;
866 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'P'):
867 return GST_VIDEO_FORMAT_UYVP;
868 case GST_MAKE_FOURCC ('A', '4', '2', '0'):
869 return GST_VIDEO_FORMAT_A420;
870 case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
871 return GST_VIDEO_FORMAT_YUV9;
872 case GST_MAKE_FOURCC ('Y', 'V', 'U', '9'):
873 return GST_VIDEO_FORMAT_YVU9;
874 case GST_MAKE_FOURCC ('I', 'Y', 'U', '1'):
875 return GST_VIDEO_FORMAT_IYU1;
876 case GST_MAKE_FOURCC ('A', 'Y', '6', '4'):
877 return GST_VIDEO_FORMAT_AYUV64;
879 return GST_VIDEO_FORMAT_UNKNOWN;
884 * gst_video_format_to_fourcc:
885 * @format: a #GstVideoFormat video format
887 * Converts a #GstVideoFormat value into the corresponding FOURCC. Only
888 * a few YUV formats have corresponding FOURCC values. If @format has
889 * no corresponding FOURCC value, 0 is returned.
893 * Returns: the FOURCC corresponding to @format
896 gst_video_format_to_fourcc (GstVideoFormat format)
898 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
901 case GST_VIDEO_FORMAT_I420:
902 return GST_MAKE_FOURCC ('I', '4', '2', '0');
903 case GST_VIDEO_FORMAT_YV12:
904 return GST_MAKE_FOURCC ('Y', 'V', '1', '2');
905 case GST_VIDEO_FORMAT_YUY2:
906 return GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
907 case GST_VIDEO_FORMAT_YVYU:
908 return GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U');
909 case GST_VIDEO_FORMAT_UYVY:
910 return GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
911 case GST_VIDEO_FORMAT_AYUV:
912 return GST_MAKE_FOURCC ('A', 'Y', 'U', 'V');
913 case GST_VIDEO_FORMAT_Y41B:
914 return GST_MAKE_FOURCC ('Y', '4', '1', 'B');
915 case GST_VIDEO_FORMAT_Y42B:
916 return GST_MAKE_FOURCC ('Y', '4', '2', 'B');
917 case GST_VIDEO_FORMAT_Y444:
918 return GST_MAKE_FOURCC ('Y', '4', '4', '4');
919 case GST_VIDEO_FORMAT_v210:
920 return GST_MAKE_FOURCC ('v', '2', '1', '0');
921 case GST_VIDEO_FORMAT_v216:
922 return GST_MAKE_FOURCC ('v', '2', '1', '6');
923 case GST_VIDEO_FORMAT_NV12:
924 return GST_MAKE_FOURCC ('N', 'V', '1', '2');
925 case GST_VIDEO_FORMAT_NV21:
926 return GST_MAKE_FOURCC ('N', 'V', '2', '1');
927 case GST_VIDEO_FORMAT_v308:
928 return GST_MAKE_FOURCC ('v', '3', '0', '8');
929 case GST_VIDEO_FORMAT_Y800:
930 return GST_MAKE_FOURCC ('Y', '8', '0', '0');
931 case GST_VIDEO_FORMAT_Y16:
932 return GST_MAKE_FOURCC ('Y', '1', '6', ' ');
933 case GST_VIDEO_FORMAT_UYVP:
934 return GST_MAKE_FOURCC ('U', 'Y', 'V', 'P');
935 case GST_VIDEO_FORMAT_A420:
936 return GST_MAKE_FOURCC ('A', '4', '2', '0');
937 case GST_VIDEO_FORMAT_YUV9:
938 return GST_MAKE_FOURCC ('Y', 'U', 'V', '9');
939 case GST_VIDEO_FORMAT_YVU9:
940 return GST_MAKE_FOURCC ('Y', 'V', 'U', '9');
941 case GST_VIDEO_FORMAT_IYU1:
942 return GST_MAKE_FOURCC ('I', 'Y', 'U', '1');
943 case GST_VIDEO_FORMAT_AYUV64:
944 return GST_MAKE_FOURCC ('A', 'Y', '6', '4');
951 * gst_video_format_from_rgb32_masks:
952 * @red_mask: red bit mask
953 * @green_mask: green bit mask
954 * @blue_mask: blue bit mask
956 * Converts red, green, blue bit masks into the corresponding
961 * Returns: the #GstVideoFormat corresponding to the bit masks
963 static GstVideoFormat
964 gst_video_format_from_rgb32_masks (int red_mask, int green_mask, int blue_mask)
966 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
967 blue_mask == 0x0000ff00) {
968 return GST_VIDEO_FORMAT_RGBx;
970 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
971 blue_mask == 0xff000000) {
972 return GST_VIDEO_FORMAT_BGRx;
974 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
975 blue_mask == 0x000000ff) {
976 return GST_VIDEO_FORMAT_xRGB;
978 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
979 blue_mask == 0x00ff0000) {
980 return GST_VIDEO_FORMAT_xBGR;
983 return GST_VIDEO_FORMAT_UNKNOWN;
986 static GstVideoFormat
987 gst_video_format_from_rgba32_masks (int red_mask, int green_mask,
988 int blue_mask, int alpha_mask)
990 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
991 blue_mask == 0x0000ff00 && alpha_mask == 0x000000ff) {
992 return GST_VIDEO_FORMAT_RGBA;
994 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
995 blue_mask == 0xff000000 && alpha_mask == 0x000000ff) {
996 return GST_VIDEO_FORMAT_BGRA;
998 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
999 blue_mask == 0x000000ff && alpha_mask == 0xff000000) {
1000 return GST_VIDEO_FORMAT_ARGB;
1002 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
1003 blue_mask == 0x00ff0000 && alpha_mask == 0xff000000) {
1004 return GST_VIDEO_FORMAT_ABGR;
1007 return GST_VIDEO_FORMAT_UNKNOWN;
1010 static GstVideoFormat
1011 gst_video_format_from_rgb24_masks (int red_mask, int green_mask, int blue_mask)
1013 if (red_mask == 0xff0000 && green_mask == 0x00ff00 && blue_mask == 0x0000ff) {
1014 return GST_VIDEO_FORMAT_RGB;
1016 if (red_mask == 0x0000ff && green_mask == 0x00ff00 && blue_mask == 0xff0000) {
1017 return GST_VIDEO_FORMAT_BGR;
1020 return GST_VIDEO_FORMAT_UNKNOWN;
1023 static GstVideoFormat
1024 gst_video_format_from_rgb16_masks (int red_mask, int green_mask, int blue_mask)
1026 if (red_mask == GST_VIDEO_COMP1_MASK_16_INT
1027 && green_mask == GST_VIDEO_COMP2_MASK_16_INT
1028 && blue_mask == GST_VIDEO_COMP3_MASK_16_INT) {
1029 return GST_VIDEO_FORMAT_RGB16;
1031 if (red_mask == GST_VIDEO_COMP3_MASK_16_INT
1032 && green_mask == GST_VIDEO_COMP2_MASK_16_INT
1033 && blue_mask == GST_VIDEO_COMP1_MASK_16_INT) {
1034 return GST_VIDEO_FORMAT_BGR16;
1036 if (red_mask == GST_VIDEO_COMP1_MASK_15_INT
1037 && green_mask == GST_VIDEO_COMP2_MASK_15_INT
1038 && blue_mask == GST_VIDEO_COMP3_MASK_15_INT) {
1039 return GST_VIDEO_FORMAT_RGB15;
1041 if (red_mask == GST_VIDEO_COMP3_MASK_15_INT
1042 && green_mask == GST_VIDEO_COMP2_MASK_15_INT
1043 && blue_mask == GST_VIDEO_COMP1_MASK_15_INT) {
1044 return GST_VIDEO_FORMAT_BGR15;
1047 return GST_VIDEO_FORMAT_UNKNOWN;
1051 * gst_video_format_is_rgb:
1052 * @format: a #GstVideoFormat
1054 * Determine whether the video format is an RGB format.
1058 * Returns: TRUE if @format represents RGB video
1061 gst_video_format_is_rgb (GstVideoFormat format)
1064 case GST_VIDEO_FORMAT_I420:
1065 case GST_VIDEO_FORMAT_YV12:
1066 case GST_VIDEO_FORMAT_YUY2:
1067 case GST_VIDEO_FORMAT_YVYU:
1068 case GST_VIDEO_FORMAT_UYVY:
1069 case GST_VIDEO_FORMAT_AYUV:
1070 case GST_VIDEO_FORMAT_Y41B:
1071 case GST_VIDEO_FORMAT_Y42B:
1072 case GST_VIDEO_FORMAT_Y444:
1073 case GST_VIDEO_FORMAT_v210:
1074 case GST_VIDEO_FORMAT_v216:
1075 case GST_VIDEO_FORMAT_NV12:
1076 case GST_VIDEO_FORMAT_NV21:
1077 case GST_VIDEO_FORMAT_v308:
1078 case GST_VIDEO_FORMAT_UYVP:
1079 case GST_VIDEO_FORMAT_A420:
1080 case GST_VIDEO_FORMAT_YUV9:
1081 case GST_VIDEO_FORMAT_YVU9:
1082 case GST_VIDEO_FORMAT_IYU1:
1083 case GST_VIDEO_FORMAT_AYUV64:
1085 case GST_VIDEO_FORMAT_RGBx:
1086 case GST_VIDEO_FORMAT_BGRx:
1087 case GST_VIDEO_FORMAT_xRGB:
1088 case GST_VIDEO_FORMAT_xBGR:
1089 case GST_VIDEO_FORMAT_RGBA:
1090 case GST_VIDEO_FORMAT_BGRA:
1091 case GST_VIDEO_FORMAT_ARGB:
1092 case GST_VIDEO_FORMAT_ABGR:
1093 case GST_VIDEO_FORMAT_RGB:
1094 case GST_VIDEO_FORMAT_BGR:
1095 case GST_VIDEO_FORMAT_RGB16:
1096 case GST_VIDEO_FORMAT_BGR16:
1097 case GST_VIDEO_FORMAT_RGB15:
1098 case GST_VIDEO_FORMAT_BGR15:
1099 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1100 case GST_VIDEO_FORMAT_ARGB64:
1101 case GST_VIDEO_FORMAT_r210:
1109 * gst_video_format_is_yuv:
1110 * @format: a #GstVideoFormat
1112 * Determine whether the video format is a YUV format.
1116 * Returns: TRUE if @format represents YUV video
1119 gst_video_format_is_yuv (GstVideoFormat format)
1122 case GST_VIDEO_FORMAT_I420:
1123 case GST_VIDEO_FORMAT_YV12:
1124 case GST_VIDEO_FORMAT_YUY2:
1125 case GST_VIDEO_FORMAT_YVYU:
1126 case GST_VIDEO_FORMAT_UYVY:
1127 case GST_VIDEO_FORMAT_AYUV:
1128 case GST_VIDEO_FORMAT_Y41B:
1129 case GST_VIDEO_FORMAT_Y42B:
1130 case GST_VIDEO_FORMAT_Y444:
1131 case GST_VIDEO_FORMAT_v210:
1132 case GST_VIDEO_FORMAT_v216:
1133 case GST_VIDEO_FORMAT_NV12:
1134 case GST_VIDEO_FORMAT_NV21:
1135 case GST_VIDEO_FORMAT_v308:
1136 case GST_VIDEO_FORMAT_Y800:
1137 case GST_VIDEO_FORMAT_Y16:
1138 case GST_VIDEO_FORMAT_UYVP:
1139 case GST_VIDEO_FORMAT_A420:
1140 case GST_VIDEO_FORMAT_YUV9:
1141 case GST_VIDEO_FORMAT_YVU9:
1142 case GST_VIDEO_FORMAT_IYU1:
1143 case GST_VIDEO_FORMAT_AYUV64:
1145 case GST_VIDEO_FORMAT_RGBx:
1146 case GST_VIDEO_FORMAT_BGRx:
1147 case GST_VIDEO_FORMAT_xRGB:
1148 case GST_VIDEO_FORMAT_xBGR:
1149 case GST_VIDEO_FORMAT_RGBA:
1150 case GST_VIDEO_FORMAT_BGRA:
1151 case GST_VIDEO_FORMAT_ARGB:
1152 case GST_VIDEO_FORMAT_ABGR:
1153 case GST_VIDEO_FORMAT_RGB:
1154 case GST_VIDEO_FORMAT_BGR:
1155 case GST_VIDEO_FORMAT_RGB16:
1156 case GST_VIDEO_FORMAT_BGR16:
1157 case GST_VIDEO_FORMAT_RGB15:
1158 case GST_VIDEO_FORMAT_BGR15:
1159 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1160 case GST_VIDEO_FORMAT_ARGB64:
1161 case GST_VIDEO_FORMAT_r210:
1169 * gst_video_format_is_gray:
1170 * @format: a #GstVideoFormat
1172 * Determine whether the video format is a grayscale format.
1176 * Returns: TRUE if @format represents grayscale video
1179 gst_video_format_is_gray (GstVideoFormat format)
1182 case GST_VIDEO_FORMAT_GRAY8:
1183 case GST_VIDEO_FORMAT_GRAY16_BE:
1184 case GST_VIDEO_FORMAT_GRAY16_LE:
1185 case GST_VIDEO_FORMAT_Y800:
1186 case GST_VIDEO_FORMAT_Y16:
1194 * gst_video_format_has_alpha:
1195 * @format: a #GstVideoFormat
1197 * Returns TRUE or FALSE depending on if the video format provides an
1202 * Returns: TRUE if @format has an alpha channel
1205 gst_video_format_has_alpha (GstVideoFormat format)
1208 case GST_VIDEO_FORMAT_I420:
1209 case GST_VIDEO_FORMAT_YV12:
1210 case GST_VIDEO_FORMAT_YUY2:
1211 case GST_VIDEO_FORMAT_YVYU:
1212 case GST_VIDEO_FORMAT_UYVY:
1213 case GST_VIDEO_FORMAT_Y41B:
1214 case GST_VIDEO_FORMAT_Y42B:
1215 case GST_VIDEO_FORMAT_Y444:
1216 case GST_VIDEO_FORMAT_v210:
1217 case GST_VIDEO_FORMAT_v216:
1218 case GST_VIDEO_FORMAT_NV12:
1219 case GST_VIDEO_FORMAT_NV21:
1220 case GST_VIDEO_FORMAT_v308:
1221 case GST_VIDEO_FORMAT_Y800:
1222 case GST_VIDEO_FORMAT_Y16:
1223 case GST_VIDEO_FORMAT_UYVP:
1224 case GST_VIDEO_FORMAT_YUV9:
1225 case GST_VIDEO_FORMAT_YVU9:
1226 case GST_VIDEO_FORMAT_IYU1:
1228 case GST_VIDEO_FORMAT_AYUV:
1229 case GST_VIDEO_FORMAT_RGBA:
1230 case GST_VIDEO_FORMAT_BGRA:
1231 case GST_VIDEO_FORMAT_ARGB:
1232 case GST_VIDEO_FORMAT_ABGR:
1233 case GST_VIDEO_FORMAT_A420:
1234 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1235 case GST_VIDEO_FORMAT_ARGB64:
1236 case GST_VIDEO_FORMAT_AYUV64:
1238 case GST_VIDEO_FORMAT_RGBx:
1239 case GST_VIDEO_FORMAT_BGRx:
1240 case GST_VIDEO_FORMAT_xRGB:
1241 case GST_VIDEO_FORMAT_xBGR:
1242 case GST_VIDEO_FORMAT_RGB:
1243 case GST_VIDEO_FORMAT_BGR:
1244 case GST_VIDEO_FORMAT_RGB16:
1245 case GST_VIDEO_FORMAT_BGR16:
1246 case GST_VIDEO_FORMAT_RGB15:
1247 case GST_VIDEO_FORMAT_BGR15:
1248 case GST_VIDEO_FORMAT_r210:
1256 * gst_video_format_get_component_depth:
1257 * @format: a #GstVideoFormat
1259 * Returns the number of bits used to encode an individual pixel of
1260 * a given component. Typically this is 8, although higher and lower
1261 * values are possible for some formats.
1265 * Returns: depth of component
1268 gst_video_format_get_component_depth (GstVideoFormat format, int component)
1270 if (component == 3 && !gst_video_format_has_alpha (format))
1274 case GST_VIDEO_FORMAT_RGB16:
1275 case GST_VIDEO_FORMAT_BGR16:
1279 case GST_VIDEO_FORMAT_RGB15:
1280 case GST_VIDEO_FORMAT_BGR15:
1282 case GST_VIDEO_FORMAT_I420:
1283 case GST_VIDEO_FORMAT_YV12:
1284 case GST_VIDEO_FORMAT_YUY2:
1285 case GST_VIDEO_FORMAT_YVYU:
1286 case GST_VIDEO_FORMAT_UYVY:
1287 case GST_VIDEO_FORMAT_Y41B:
1288 case GST_VIDEO_FORMAT_Y42B:
1289 case GST_VIDEO_FORMAT_Y444:
1290 case GST_VIDEO_FORMAT_NV12:
1291 case GST_VIDEO_FORMAT_NV21:
1292 case GST_VIDEO_FORMAT_v308:
1293 case GST_VIDEO_FORMAT_Y800:
1294 case GST_VIDEO_FORMAT_YUV9:
1295 case GST_VIDEO_FORMAT_YVU9:
1296 case GST_VIDEO_FORMAT_IYU1:
1297 case GST_VIDEO_FORMAT_AYUV:
1298 case GST_VIDEO_FORMAT_RGBA:
1299 case GST_VIDEO_FORMAT_BGRA:
1300 case GST_VIDEO_FORMAT_ARGB:
1301 case GST_VIDEO_FORMAT_ABGR:
1302 case GST_VIDEO_FORMAT_A420:
1303 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1304 case GST_VIDEO_FORMAT_RGBx:
1305 case GST_VIDEO_FORMAT_BGRx:
1306 case GST_VIDEO_FORMAT_xRGB:
1307 case GST_VIDEO_FORMAT_xBGR:
1308 case GST_VIDEO_FORMAT_RGB:
1309 case GST_VIDEO_FORMAT_BGR:
1312 case GST_VIDEO_FORMAT_v210:
1313 case GST_VIDEO_FORMAT_UYVP:
1314 case GST_VIDEO_FORMAT_r210:
1316 case GST_VIDEO_FORMAT_Y16:
1317 case GST_VIDEO_FORMAT_v216:
1318 case GST_VIDEO_FORMAT_ARGB64:
1319 case GST_VIDEO_FORMAT_AYUV64:
1326 * gst_video_format_get_row_stride:
1327 * @format: a #GstVideoFormat
1328 * @component: the component index
1329 * @width: the width of video
1331 * Calculates the row stride (number of bytes from one row of pixels to
1332 * the next) for the video component with an index of @component. For
1333 * YUV video, Y, U, and V have component indices of 0, 1, and 2,
1334 * respectively. For RGB video, R, G, and B have component indicies of
1335 * 0, 1, and 2, respectively. Alpha channels, if present, have a component
1336 * index of 3. The @width parameter always represents the width of the
1337 * video, not the component.
1341 * Returns: row stride of component @component
1344 gst_video_format_get_row_stride (GstVideoFormat format, int component,
1347 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1348 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1349 g_return_val_if_fail (width > 0, 0);
1352 case GST_VIDEO_FORMAT_I420:
1353 case GST_VIDEO_FORMAT_YV12:
1354 if (component == 0) {
1355 return GST_ROUND_UP_4 (width);
1357 return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
1359 case GST_VIDEO_FORMAT_YUY2:
1360 case GST_VIDEO_FORMAT_YVYU:
1361 case GST_VIDEO_FORMAT_UYVY:
1362 return GST_ROUND_UP_4 (width * 2);
1363 case GST_VIDEO_FORMAT_AYUV:
1364 case GST_VIDEO_FORMAT_RGBx:
1365 case GST_VIDEO_FORMAT_BGRx:
1366 case GST_VIDEO_FORMAT_xRGB:
1367 case GST_VIDEO_FORMAT_xBGR:
1368 case GST_VIDEO_FORMAT_RGBA:
1369 case GST_VIDEO_FORMAT_BGRA:
1370 case GST_VIDEO_FORMAT_ARGB:
1371 case GST_VIDEO_FORMAT_ABGR:
1372 case GST_VIDEO_FORMAT_r210:
1374 case GST_VIDEO_FORMAT_RGB16:
1375 case GST_VIDEO_FORMAT_BGR16:
1376 case GST_VIDEO_FORMAT_RGB15:
1377 case GST_VIDEO_FORMAT_BGR15:
1378 return GST_ROUND_UP_4 (width * 2);
1379 case GST_VIDEO_FORMAT_RGB:
1380 case GST_VIDEO_FORMAT_BGR:
1381 case GST_VIDEO_FORMAT_v308:
1382 return GST_ROUND_UP_4 (width * 3);
1383 case GST_VIDEO_FORMAT_Y41B:
1384 if (component == 0) {
1385 return GST_ROUND_UP_4 (width);
1387 return GST_ROUND_UP_16 (width) / 4;
1389 case GST_VIDEO_FORMAT_Y42B:
1390 if (component == 0) {
1391 return GST_ROUND_UP_4 (width);
1393 return GST_ROUND_UP_8 (width) / 2;
1395 case GST_VIDEO_FORMAT_Y444:
1396 return GST_ROUND_UP_4 (width);
1397 case GST_VIDEO_FORMAT_v210:
1398 return ((width + 47) / 48) * 128;
1399 case GST_VIDEO_FORMAT_v216:
1400 return GST_ROUND_UP_8 (width * 4);
1401 case GST_VIDEO_FORMAT_NV12:
1402 case GST_VIDEO_FORMAT_NV21:
1403 return GST_ROUND_UP_4 (width);
1404 case GST_VIDEO_FORMAT_GRAY8:
1405 case GST_VIDEO_FORMAT_Y800:
1406 return GST_ROUND_UP_4 (width);
1407 case GST_VIDEO_FORMAT_GRAY16_BE:
1408 case GST_VIDEO_FORMAT_GRAY16_LE:
1409 case GST_VIDEO_FORMAT_Y16:
1410 return GST_ROUND_UP_4 (width * 2);
1411 case GST_VIDEO_FORMAT_UYVP:
1412 return GST_ROUND_UP_4 ((width * 2 * 5 + 3) / 4);
1413 case GST_VIDEO_FORMAT_A420:
1414 if (component == 0 || component == 3) {
1415 return GST_ROUND_UP_4 (width);
1417 return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
1419 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1420 return GST_ROUND_UP_4 (width);
1421 case GST_VIDEO_FORMAT_YUV9:
1422 case GST_VIDEO_FORMAT_YVU9:
1423 if (component == 0) {
1424 return GST_ROUND_UP_4 (width);
1426 return GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4);
1428 case GST_VIDEO_FORMAT_IYU1:
1429 return GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) +
1430 GST_ROUND_UP_4 (width) / 2);
1431 case GST_VIDEO_FORMAT_ARGB64:
1432 case GST_VIDEO_FORMAT_AYUV64:
1440 * gst_video_format_get_pixel_stride:
1441 * @format: a #GstVideoFormat
1442 * @component: the component index
1444 * Calculates the pixel stride (number of bytes from one pixel to the
1445 * pixel to its immediate left) for the video component with an index
1446 * of @component. See @gst_video_format_get_row_stride for a description
1447 * of the component index.
1451 * Returns: pixel stride of component @component
1454 gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
1456 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1457 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1460 case GST_VIDEO_FORMAT_I420:
1461 case GST_VIDEO_FORMAT_YV12:
1462 case GST_VIDEO_FORMAT_Y41B:
1463 case GST_VIDEO_FORMAT_Y42B:
1464 case GST_VIDEO_FORMAT_Y444:
1465 case GST_VIDEO_FORMAT_A420:
1466 case GST_VIDEO_FORMAT_YUV9:
1467 case GST_VIDEO_FORMAT_YVU9:
1469 case GST_VIDEO_FORMAT_YUY2:
1470 case GST_VIDEO_FORMAT_YVYU:
1471 case GST_VIDEO_FORMAT_UYVY:
1472 if (component == 0) {
1477 case GST_VIDEO_FORMAT_IYU1:
1478 /* doesn't make much sense for IYU1 because it's 1 or 3
1479 * for luma depending on position */
1481 case GST_VIDEO_FORMAT_AYUV:
1482 case GST_VIDEO_FORMAT_RGBx:
1483 case GST_VIDEO_FORMAT_BGRx:
1484 case GST_VIDEO_FORMAT_xRGB:
1485 case GST_VIDEO_FORMAT_xBGR:
1486 case GST_VIDEO_FORMAT_RGBA:
1487 case GST_VIDEO_FORMAT_BGRA:
1488 case GST_VIDEO_FORMAT_ARGB:
1489 case GST_VIDEO_FORMAT_ABGR:
1490 case GST_VIDEO_FORMAT_r210:
1492 case GST_VIDEO_FORMAT_RGB16:
1493 case GST_VIDEO_FORMAT_BGR16:
1494 case GST_VIDEO_FORMAT_RGB15:
1495 case GST_VIDEO_FORMAT_BGR15:
1497 case GST_VIDEO_FORMAT_RGB:
1498 case GST_VIDEO_FORMAT_BGR:
1499 case GST_VIDEO_FORMAT_v308:
1501 case GST_VIDEO_FORMAT_v210:
1502 /* v210 is packed at the bit level, so pixel stride doesn't make sense */
1504 case GST_VIDEO_FORMAT_v216:
1505 if (component == 0) {
1510 case GST_VIDEO_FORMAT_NV12:
1511 case GST_VIDEO_FORMAT_NV21:
1512 if (component == 0) {
1517 case GST_VIDEO_FORMAT_GRAY8:
1518 case GST_VIDEO_FORMAT_Y800:
1520 case GST_VIDEO_FORMAT_GRAY16_BE:
1521 case GST_VIDEO_FORMAT_GRAY16_LE:
1522 case GST_VIDEO_FORMAT_Y16:
1524 case GST_VIDEO_FORMAT_UYVP:
1525 /* UYVP is packed at the bit level, so pixel stride doesn't make sense */
1527 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1529 case GST_VIDEO_FORMAT_ARGB64:
1530 case GST_VIDEO_FORMAT_AYUV64:
1538 * gst_video_format_get_component_width:
1539 * @format: a #GstVideoFormat
1540 * @component: the component index
1541 * @width: the width of video
1543 * Calculates the width of the component. See
1544 * @gst_video_format_get_row_stride for a description
1545 * of the component index.
1549 * Returns: width of component @component
1552 gst_video_format_get_component_width (GstVideoFormat format,
1553 int component, int width)
1555 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1556 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1557 g_return_val_if_fail (width > 0, 0);
1560 case GST_VIDEO_FORMAT_I420:
1561 case GST_VIDEO_FORMAT_YV12:
1562 case GST_VIDEO_FORMAT_YUY2:
1563 case GST_VIDEO_FORMAT_YVYU:
1564 case GST_VIDEO_FORMAT_UYVY:
1565 case GST_VIDEO_FORMAT_Y42B:
1566 case GST_VIDEO_FORMAT_v210:
1567 case GST_VIDEO_FORMAT_v216:
1568 case GST_VIDEO_FORMAT_NV12:
1569 case GST_VIDEO_FORMAT_NV21:
1570 case GST_VIDEO_FORMAT_UYVP:
1571 if (component == 0) {
1574 return GST_ROUND_UP_2 (width) / 2;
1576 case GST_VIDEO_FORMAT_Y41B:
1577 case GST_VIDEO_FORMAT_YUV9:
1578 case GST_VIDEO_FORMAT_YVU9:
1579 case GST_VIDEO_FORMAT_IYU1:
1580 if (component == 0) {
1583 return GST_ROUND_UP_4 (width) / 4;
1585 case GST_VIDEO_FORMAT_AYUV:
1586 case GST_VIDEO_FORMAT_RGBx:
1587 case GST_VIDEO_FORMAT_BGRx:
1588 case GST_VIDEO_FORMAT_xRGB:
1589 case GST_VIDEO_FORMAT_xBGR:
1590 case GST_VIDEO_FORMAT_RGBA:
1591 case GST_VIDEO_FORMAT_BGRA:
1592 case GST_VIDEO_FORMAT_ARGB:
1593 case GST_VIDEO_FORMAT_ABGR:
1594 case GST_VIDEO_FORMAT_RGB:
1595 case GST_VIDEO_FORMAT_BGR:
1596 case GST_VIDEO_FORMAT_RGB16:
1597 case GST_VIDEO_FORMAT_BGR16:
1598 case GST_VIDEO_FORMAT_RGB15:
1599 case GST_VIDEO_FORMAT_BGR15:
1600 case GST_VIDEO_FORMAT_Y444:
1601 case GST_VIDEO_FORMAT_v308:
1602 case GST_VIDEO_FORMAT_GRAY8:
1603 case GST_VIDEO_FORMAT_GRAY16_BE:
1604 case GST_VIDEO_FORMAT_GRAY16_LE:
1605 case GST_VIDEO_FORMAT_Y800:
1606 case GST_VIDEO_FORMAT_Y16:
1607 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1608 case GST_VIDEO_FORMAT_ARGB64:
1609 case GST_VIDEO_FORMAT_AYUV64:
1610 case GST_VIDEO_FORMAT_r210:
1612 case GST_VIDEO_FORMAT_A420:
1613 if (component == 0 || component == 3) {
1616 return GST_ROUND_UP_2 (width) / 2;
1624 * gst_video_format_get_component_height:
1625 * @format: a #GstVideoFormat
1626 * @component: the component index
1627 * @height: the height of video
1629 * Calculates the height of the component. See
1630 * @gst_video_format_get_row_stride for a description
1631 * of the component index.
1635 * Returns: height of component @component
1638 gst_video_format_get_component_height (GstVideoFormat format,
1639 int component, int height)
1641 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1642 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1643 g_return_val_if_fail (height > 0, 0);
1646 case GST_VIDEO_FORMAT_I420:
1647 case GST_VIDEO_FORMAT_YV12:
1648 case GST_VIDEO_FORMAT_NV12:
1649 case GST_VIDEO_FORMAT_NV21:
1650 if (component == 0) {
1653 return GST_ROUND_UP_2 (height) / 2;
1655 case GST_VIDEO_FORMAT_Y41B:
1656 case GST_VIDEO_FORMAT_Y42B:
1657 case GST_VIDEO_FORMAT_YUY2:
1658 case GST_VIDEO_FORMAT_YVYU:
1659 case GST_VIDEO_FORMAT_UYVY:
1660 case GST_VIDEO_FORMAT_AYUV:
1661 case GST_VIDEO_FORMAT_RGBx:
1662 case GST_VIDEO_FORMAT_BGRx:
1663 case GST_VIDEO_FORMAT_xRGB:
1664 case GST_VIDEO_FORMAT_xBGR:
1665 case GST_VIDEO_FORMAT_RGBA:
1666 case GST_VIDEO_FORMAT_BGRA:
1667 case GST_VIDEO_FORMAT_ARGB:
1668 case GST_VIDEO_FORMAT_ABGR:
1669 case GST_VIDEO_FORMAT_RGB:
1670 case GST_VIDEO_FORMAT_BGR:
1671 case GST_VIDEO_FORMAT_RGB16:
1672 case GST_VIDEO_FORMAT_BGR16:
1673 case GST_VIDEO_FORMAT_RGB15:
1674 case GST_VIDEO_FORMAT_BGR15:
1675 case GST_VIDEO_FORMAT_Y444:
1676 case GST_VIDEO_FORMAT_v210:
1677 case GST_VIDEO_FORMAT_v216:
1678 case GST_VIDEO_FORMAT_v308:
1679 case GST_VIDEO_FORMAT_GRAY8:
1680 case GST_VIDEO_FORMAT_GRAY16_BE:
1681 case GST_VIDEO_FORMAT_GRAY16_LE:
1682 case GST_VIDEO_FORMAT_Y800:
1683 case GST_VIDEO_FORMAT_Y16:
1684 case GST_VIDEO_FORMAT_UYVP:
1685 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1686 case GST_VIDEO_FORMAT_IYU1:
1687 case GST_VIDEO_FORMAT_ARGB64:
1688 case GST_VIDEO_FORMAT_AYUV64:
1689 case GST_VIDEO_FORMAT_r210:
1691 case GST_VIDEO_FORMAT_A420:
1692 if (component == 0 || component == 3) {
1695 return GST_ROUND_UP_2 (height) / 2;
1697 case GST_VIDEO_FORMAT_YUV9:
1698 case GST_VIDEO_FORMAT_YVU9:
1699 if (component == 0) {
1702 return GST_ROUND_UP_4 (height) / 4;
1710 * gst_video_format_get_component_offset:
1711 * @format: a #GstVideoFormat
1712 * @component: the component index
1713 * @width: the width of video
1714 * @height: the height of video
1716 * Calculates the offset (in bytes) of the first pixel of the component
1717 * with index @component. For packed formats, this will typically be a
1718 * small integer (0, 1, 2, 3). For planar formats, this will be a
1719 * (relatively) large offset to the beginning of the second or third
1720 * component planes. See @gst_video_format_get_row_stride for a description
1721 * of the component index.
1725 * Returns: offset of component @component
1728 gst_video_format_get_component_offset (GstVideoFormat format,
1729 int component, int width, int height)
1731 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1732 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1733 g_return_val_if_fail ((!gst_video_format_is_yuv (format)) || (width > 0
1737 case GST_VIDEO_FORMAT_I420:
1741 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1742 if (component == 2) {
1743 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1744 GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1745 (GST_ROUND_UP_2 (height) / 2);
1748 case GST_VIDEO_FORMAT_YV12: /* same as I420, but components 1+2 swapped */
1752 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1753 if (component == 1) {
1754 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1755 GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1756 (GST_ROUND_UP_2 (height) / 2);
1759 case GST_VIDEO_FORMAT_YUY2:
1767 case GST_VIDEO_FORMAT_YVYU:
1775 case GST_VIDEO_FORMAT_UYVY:
1783 case GST_VIDEO_FORMAT_AYUV:
1793 case GST_VIDEO_FORMAT_RGBx:
1794 case GST_VIDEO_FORMAT_RGBA:
1804 case GST_VIDEO_FORMAT_BGRx:
1805 case GST_VIDEO_FORMAT_BGRA:
1815 case GST_VIDEO_FORMAT_xRGB:
1816 case GST_VIDEO_FORMAT_ARGB:
1826 case GST_VIDEO_FORMAT_xBGR:
1827 case GST_VIDEO_FORMAT_ABGR:
1837 case GST_VIDEO_FORMAT_RGB:
1838 case GST_VIDEO_FORMAT_v308:
1846 case GST_VIDEO_FORMAT_BGR:
1854 case GST_VIDEO_FORMAT_Y41B:
1858 return GST_ROUND_UP_4 (width) * height;
1860 return (GST_ROUND_UP_4 (width) +
1861 (GST_ROUND_UP_16 (width) / 4)) * height;
1863 case GST_VIDEO_FORMAT_Y42B:
1867 return GST_ROUND_UP_4 (width) * height;
1869 return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_8 (width) / 2)) * height;
1871 case GST_VIDEO_FORMAT_Y444:
1872 return GST_ROUND_UP_4 (width) * height * component;
1873 case GST_VIDEO_FORMAT_v210:
1874 case GST_VIDEO_FORMAT_r210:
1875 /* v210 is bit-packed, so this doesn't make sense */
1877 case GST_VIDEO_FORMAT_v216:
1885 case GST_VIDEO_FORMAT_NV12:
1889 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1891 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) + 1;
1892 case GST_VIDEO_FORMAT_NV21:
1896 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) + 1;
1898 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1899 case GST_VIDEO_FORMAT_GRAY8:
1900 case GST_VIDEO_FORMAT_GRAY16_BE:
1901 case GST_VIDEO_FORMAT_GRAY16_LE:
1902 case GST_VIDEO_FORMAT_Y800:
1903 case GST_VIDEO_FORMAT_Y16:
1905 case GST_VIDEO_FORMAT_UYVP:
1906 /* UYVP is bit-packed, so this doesn't make sense */
1908 case GST_VIDEO_FORMAT_A420:
1912 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1913 if (component == 2) {
1914 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1915 GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1916 (GST_ROUND_UP_2 (height) / 2);
1918 if (component == 3) {
1919 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1920 2 * GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1921 (GST_ROUND_UP_2 (height) / 2);
1923 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1925 case GST_VIDEO_FORMAT_YUV9:
1929 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1930 if (component == 2) {
1931 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1932 GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4) *
1933 (GST_ROUND_UP_4 (height) / 4);
1936 case GST_VIDEO_FORMAT_YVU9:
1939 if (component == 1) {
1940 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1941 GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4) *
1942 (GST_ROUND_UP_4 (height) / 4);
1945 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1947 case GST_VIDEO_FORMAT_IYU1:
1954 case GST_VIDEO_FORMAT_ARGB64:
1955 case GST_VIDEO_FORMAT_AYUV64:
1971 * gst_video_format_get_size:
1972 * @format: a #GstVideoFormat
1973 * @width: the width of video
1974 * @height: the height of video
1976 * Calculates the total number of bytes in the raw video format. This
1977 * number should be used when allocating a buffer for raw video.
1981 * Returns: size (in bytes) of raw video format
1984 gst_video_format_get_size (GstVideoFormat format, int width, int height)
1988 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1989 g_return_val_if_fail (width > 0 && height > 0, 0);
1992 case GST_VIDEO_FORMAT_I420:
1993 case GST_VIDEO_FORMAT_YV12:
1994 size = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1995 size += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1996 (GST_ROUND_UP_2 (height) / 2) * 2;
1998 case GST_VIDEO_FORMAT_IYU1:
1999 return GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) +
2000 GST_ROUND_UP_4 (width) / 2) * height;
2001 case GST_VIDEO_FORMAT_YUY2:
2002 case GST_VIDEO_FORMAT_YVYU:
2003 case GST_VIDEO_FORMAT_UYVY:
2004 return GST_ROUND_UP_4 (width * 2) * height;
2005 case GST_VIDEO_FORMAT_AYUV:
2006 case GST_VIDEO_FORMAT_RGBx:
2007 case GST_VIDEO_FORMAT_BGRx:
2008 case GST_VIDEO_FORMAT_xRGB:
2009 case GST_VIDEO_FORMAT_xBGR:
2010 case GST_VIDEO_FORMAT_RGBA:
2011 case GST_VIDEO_FORMAT_BGRA:
2012 case GST_VIDEO_FORMAT_ARGB:
2013 case GST_VIDEO_FORMAT_ABGR:
2014 case GST_VIDEO_FORMAT_r210:
2015 return width * 4 * height;
2016 case GST_VIDEO_FORMAT_RGB16:
2017 case GST_VIDEO_FORMAT_BGR16:
2018 case GST_VIDEO_FORMAT_RGB15:
2019 case GST_VIDEO_FORMAT_BGR15:
2020 return GST_ROUND_UP_4 (width * 2) * height;
2021 case GST_VIDEO_FORMAT_RGB:
2022 case GST_VIDEO_FORMAT_BGR:
2023 case GST_VIDEO_FORMAT_v308:
2024 return GST_ROUND_UP_4 (width * 3) * height;
2025 case GST_VIDEO_FORMAT_Y41B:
2026 /* simplification of ROUNDUP4(w)*h + 2*((ROUNDUP16(w)/4)*h */
2027 return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_16 (width) / 2)) * height;
2028 case GST_VIDEO_FORMAT_Y42B:
2029 /* simplification of ROUNDUP4(w)*h + 2*(ROUNDUP8(w)/2)*h */
2030 return (GST_ROUND_UP_4 (width) + GST_ROUND_UP_8 (width)) * height;
2031 case GST_VIDEO_FORMAT_Y444:
2032 return GST_ROUND_UP_4 (width) * height * 3;
2033 case GST_VIDEO_FORMAT_v210:
2034 return ((width + 47) / 48) * 128 * height;
2035 case GST_VIDEO_FORMAT_v216:
2036 return GST_ROUND_UP_8 (width * 4) * height;
2037 case GST_VIDEO_FORMAT_NV12:
2038 case GST_VIDEO_FORMAT_NV21:
2039 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) * 3 / 2;
2040 case GST_VIDEO_FORMAT_GRAY8:
2041 case GST_VIDEO_FORMAT_Y800:
2042 case GST_VIDEO_FORMAT_RGB8_PALETTED:
2043 return GST_ROUND_UP_4 (width) * height;
2044 case GST_VIDEO_FORMAT_GRAY16_BE:
2045 case GST_VIDEO_FORMAT_GRAY16_LE:
2046 case GST_VIDEO_FORMAT_Y16:
2047 return GST_ROUND_UP_4 (width * 2) * height;
2048 case GST_VIDEO_FORMAT_UYVP:
2049 return GST_ROUND_UP_4 ((width * 2 * 5 + 3) / 4) * height;
2050 case GST_VIDEO_FORMAT_A420:
2051 size = 2 * GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
2052 size += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
2053 (GST_ROUND_UP_2 (height) / 2) * 2;
2055 case GST_VIDEO_FORMAT_YUV9:
2056 case GST_VIDEO_FORMAT_YVU9:
2057 size = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
2058 size += GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4) *
2059 (GST_ROUND_UP_4 (height) / 4) * 2;
2061 case GST_VIDEO_FORMAT_ARGB64:
2062 case GST_VIDEO_FORMAT_AYUV64:
2063 return width * 8 * height;
2070 * gst_video_format_convert:
2071 * @format: a #GstVideoFormat
2072 * @width: the width of video
2073 * @height: the height of video
2074 * @fps_n: frame rate numerator
2075 * @fps_d: frame rate denominator
2076 * @src_format: #GstFormat of the @src_value
2077 * @src_value: value to convert
2078 * @dest_format: #GstFormat of the @dest_value
2079 * @dest_value: pointer to destination value
2081 * Converts among various #GstFormat types. This function handles
2082 * GST_FORMAT_BYTES, GST_FORMAT_TIME, and GST_FORMAT_DEFAULT. For
2083 * raw video, GST_FORMAT_DEFAULT corresponds to video frames. This
2084 * function can be to handle pad queries of the type GST_QUERY_CONVERT.
2088 * Returns: TRUE if the conversion was successful.
2091 gst_video_format_convert (GstVideoFormat format, int width, int height,
2092 int fps_n, int fps_d,
2093 GstFormat src_format, gint64 src_value,
2094 GstFormat dest_format, gint64 * dest_value)
2096 gboolean ret = FALSE;
2099 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
2100 g_return_val_if_fail (width > 0 && height > 0, 0);
2102 size = gst_video_format_get_size (format, width, height);
2104 GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
2105 src_value, gst_format_get_name (src_format),
2106 gst_format_get_name (dest_format));
2108 if (src_format == dest_format) {
2109 *dest_value = src_value;
2114 if (src_value == -1) {
2120 /* bytes to frames */
2121 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_DEFAULT) {
2123 *dest_value = gst_util_uint64_scale_int (src_value, 1, size);
2125 GST_ERROR ("blocksize is 0");
2132 /* frames to bytes */
2133 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_BYTES) {
2134 *dest_value = gst_util_uint64_scale_int (src_value, size, 1);
2139 /* time to frames */
2140 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_DEFAULT) {
2142 *dest_value = gst_util_uint64_scale (src_value,
2143 fps_n, GST_SECOND * fps_d);
2145 GST_ERROR ("framerate denominator is 0");
2152 /* frames to time */
2153 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_TIME) {
2155 *dest_value = gst_util_uint64_scale (src_value,
2156 GST_SECOND * fps_d, fps_n);
2158 GST_ERROR ("framerate numerator is 0");
2166 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
2168 *dest_value = gst_util_uint64_scale (src_value,
2169 fps_n * size, GST_SECOND * fps_d);
2171 GST_ERROR ("framerate denominator is 0");
2179 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_TIME) {
2180 if (fps_n != 0 && size != 0) {
2181 *dest_value = gst_util_uint64_scale (src_value,
2182 GST_SECOND * fps_d, fps_n * size);
2184 GST_ERROR ("framerate denominator and/or blocksize is 0");
2192 GST_DEBUG ("ret=%d result %" G_GINT64_FORMAT, ret, *dest_value);
2197 #define GST_VIDEO_EVENT_STILL_STATE_NAME "GstEventStillFrame"
2200 * gst_video_event_new_still_frame:
2201 * @in_still: boolean value for the still-frame state of the event.
2203 * Creates a new Still Frame event. If @in_still is %TRUE, then the event
2204 * represents the start of a still frame sequence. If it is %FALSE, then
2205 * the event ends a still frame sequence.
2207 * To parse an event created by gst_video_event_new_still_frame() use
2208 * gst_video_event_parse_still_frame().
2210 * Returns: The new GstEvent
2214 gst_video_event_new_still_frame (gboolean in_still)
2216 GstEvent *still_event;
2219 s = gst_structure_new (GST_VIDEO_EVENT_STILL_STATE_NAME,
2220 "still-state", G_TYPE_BOOLEAN, in_still, NULL);
2221 still_event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
2227 * gst_video_event_parse_still_frame:
2228 * @event: A #GstEvent to parse
2229 * @in_still: A boolean to receive the still-frame status from the event, or NULL
2231 * Parse a #GstEvent, identify if it is a Still Frame event, and
2232 * return the still-frame state from the event if it is.
2233 * If the event represents the start of a still frame, the in_still
2234 * variable will be set to TRUE, otherwise FALSE. It is OK to pass NULL for the
2235 * in_still variable order to just check whether the event is a valid still-frame
2238 * Create a still frame event using gst_video_event_new_still_frame()
2240 * Returns: %TRUE if the event is a valid still-frame event. %FALSE if not
2244 gst_video_event_parse_still_frame (GstEvent * event, gboolean * in_still)
2246 const GstStructure *s;
2247 gboolean ev_still_state;
2249 g_return_val_if_fail (event != NULL, FALSE);
2251 if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_DOWNSTREAM)
2252 return FALSE; /* Not a still frame event */
2254 s = gst_event_get_structure (event);
2256 || !gst_structure_has_name (s, GST_VIDEO_EVENT_STILL_STATE_NAME))
2257 return FALSE; /* Not a still frame event */
2258 if (!gst_structure_get_boolean (s, "still-state", &ev_still_state))
2259 return FALSE; /* Not a still frame event */
2261 *in_still = ev_still_state;
2266 * gst_video_parse_caps_palette:
2267 * @caps: #GstCaps to parse
2269 * Returns the palette data from the caps as a #GstBuffer. For
2270 * #GST_VIDEO_FORMAT_RGB8_PALETTED this is containing 256 #guint32
2271 * values, each containing ARGB colors in native endianness.
2273 * Returns: a #GstBuffer containing the palette data. Unref after usage.
2277 gst_video_parse_caps_palette (GstCaps * caps)
2283 if (!gst_caps_is_fixed (caps))
2286 s = gst_caps_get_structure (caps, 0);
2288 p_v = gst_structure_get_value (s, "palette_data");
2289 if (!p_v || !GST_VALUE_HOLDS_BUFFER (p_v))
2292 p = gst_buffer_ref (gst_value_get_buffer (p_v));