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 a video format or does not contain height and width, the
321 * function will fail and return FALSE. If @caps does not represent a raw
322 * video format listed in #GstVideoFormat, but still contains video caps,
323 * this function will return TRUE and set @format to #GST_VIDEO_FORMAT_UNKNOWN.
327 * Returns: TRUE if @caps was parsed correctly.
330 gst_video_format_parse_caps (const GstCaps * caps, GstVideoFormat * format,
331 int *width, int *height)
333 GstStructure *structure;
336 if (!gst_caps_is_fixed (caps))
339 structure = gst_caps_get_structure (caps, 0);
342 if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
345 ok &= gst_structure_get_fourcc (structure, "format", &fourcc);
347 *format = gst_video_format_from_fourcc (fourcc);
348 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
351 } else if (gst_structure_has_name (structure, "video/x-raw-rgb")) {
361 ok &= gst_structure_get_int (structure, "depth", &depth);
362 ok &= gst_structure_get_int (structure, "bpp", &bpp);
365 ok &= gst_structure_get_int (structure, "endianness", &endianness);
366 ok &= gst_structure_get_int (structure, "red_mask", &red_mask);
367 ok &= gst_structure_get_int (structure, "green_mask", &green_mask);
368 ok &= gst_structure_get_int (structure, "blue_mask", &blue_mask);
370 have_alpha = gst_structure_get_int (structure, "alpha_mask", &alpha_mask);
372 if (depth == 30 && bpp == 32 && endianness == G_BIG_ENDIAN) {
373 *format = GST_VIDEO_FORMAT_r210;
374 } else if (depth == 24 && bpp == 32 && endianness == G_BIG_ENDIAN) {
375 *format = gst_video_format_from_rgb32_masks (red_mask, green_mask,
377 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
380 } else if (depth == 32 && bpp == 32 && endianness == G_BIG_ENDIAN &&
382 *format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
383 blue_mask, alpha_mask);
384 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
387 } else if (depth == 24 && bpp == 24 && endianness == G_BIG_ENDIAN) {
388 *format = gst_video_format_from_rgb24_masks (red_mask, green_mask,
390 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
393 } else if ((depth == 15 || depth == 16) && bpp == 16 &&
394 endianness == G_BYTE_ORDER) {
395 *format = gst_video_format_from_rgb16_masks (red_mask, green_mask,
397 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
400 } else if (depth == 8 && bpp == 8) {
401 *format = GST_VIDEO_FORMAT_RGB8_PALETTED;
402 } else if (depth == 64 && bpp == 64) {
403 *format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
404 blue_mask, alpha_mask);
405 if (*format == GST_VIDEO_FORMAT_ARGB) {
406 *format = GST_VIDEO_FORMAT_ARGB64;
408 *format = GST_VIDEO_FORMAT_UNKNOWN;
414 } else if (gst_structure_has_name (structure, "video/x-raw-gray")) {
419 ok &= gst_structure_get_int (structure, "depth", &depth);
420 ok &= gst_structure_get_int (structure, "bpp", &bpp);
423 ok &= gst_structure_get_int (structure, "endianness", &endianness);
425 if (depth == 8 && bpp == 8) {
426 *format = GST_VIDEO_FORMAT_GRAY8;
427 } else if (depth == 16 && bpp == 16 && endianness == G_BIG_ENDIAN) {
428 *format = GST_VIDEO_FORMAT_GRAY16_BE;
429 } else if (depth == 16 && bpp == 16 && endianness == G_LITTLE_ENDIAN) {
430 *format = GST_VIDEO_FORMAT_GRAY16_LE;
434 } else if (g_str_has_prefix (gst_structure_get_name (structure), "video/")) {
435 *format = GST_VIDEO_FORMAT_UNKNOWN;
442 ok &= gst_structure_get_int (structure, "width", width);
446 ok &= gst_structure_get_int (structure, "height", height);
454 * gst_video_parse_caps_framerate:
455 * @caps: pointer to a #GstCaps instance
456 * @fps_n: pointer to integer to hold numerator of frame rate (output)
457 * @fps_d: pointer to integer to hold denominator of frame rate (output)
459 * Extracts the frame rate from @caps and places the values in the locations
460 * pointed to by @fps_n and @fps_d. Returns TRUE if the values could be
461 * parsed correctly, FALSE if not.
463 * This function can be used with #GstCaps that have any media type; it
464 * is not limited to formats handled by #GstVideoFormat.
468 * Returns: TRUE if @caps was parsed correctly.
471 gst_video_parse_caps_framerate (GstCaps * caps, int *fps_n, int *fps_d)
473 GstStructure *structure;
475 if (!gst_caps_is_fixed (caps))
478 structure = gst_caps_get_structure (caps, 0);
480 return gst_structure_get_fraction (structure, "framerate", fps_n, fps_d);
484 * gst_video_parse_caps_pixel_aspect_ratio:
485 * @caps: pointer to a #GstCaps instance
486 * @par_n: pointer to numerator of pixel aspect ratio (output)
487 * @par_d: pointer to denominator of pixel aspect ratio (output)
489 * Extracts the pixel aspect ratio from @caps and places the values in
490 * the locations pointed to by @par_n and @par_d. Returns TRUE if the
491 * values could be parsed correctly, FALSE if not.
493 * This function can be used with #GstCaps that have any media type; it
494 * is not limited to formats handled by #GstVideoFormat.
498 * Returns: TRUE if @caps was parsed correctly.
501 gst_video_parse_caps_pixel_aspect_ratio (GstCaps * caps, int *par_n, int *par_d)
503 GstStructure *structure;
505 if (!gst_caps_is_fixed (caps))
508 structure = gst_caps_get_structure (caps, 0);
510 if (!gst_structure_get_fraction (structure, "pixel-aspect-ratio",
519 * gst_video_format_new_caps_interlaced:
520 * @format: the #GstVideoFormat describing the raw video format
521 * @width: width of video
522 * @height: height of video
523 * @framerate_n: numerator of frame rate
524 * @framerate_d: denominator of frame rate
525 * @par_n: numerator of pixel aspect ratio
526 * @par_d: denominator of pixel aspect ratio
527 * @interlaced: #TRUE if the format is interlaced
529 * Creates a new #GstCaps object based on the parameters provided.
533 * Returns: a new #GstCaps object, or NULL if there was an error
536 gst_video_format_new_caps_interlaced (GstVideoFormat format,
537 int width, int height, int framerate_n, int framerate_d, int par_n,
538 int par_d, gboolean interlaced)
543 gst_video_format_new_caps (format, width, height, framerate_n,
544 framerate_d, par_n, par_d);
545 if (interlaced && (res != NULL))
546 gst_caps_set_simple (res, "interlaced", G_TYPE_BOOLEAN, TRUE, NULL);
552 gst_video_format_new_caps_raw (GstVideoFormat format)
554 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
556 if (gst_video_format_is_yuv (format)) {
557 return gst_caps_new_simple ("video/x-raw-yuv",
558 "format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format), NULL);
560 if (gst_video_format_is_rgb (format)) {
569 unsigned int mask = 0;
572 case GST_VIDEO_FORMAT_RGBx:
573 case GST_VIDEO_FORMAT_BGRx:
574 case GST_VIDEO_FORMAT_xRGB:
575 case GST_VIDEO_FORMAT_xBGR:
580 case GST_VIDEO_FORMAT_RGBA:
581 case GST_VIDEO_FORMAT_BGRA:
582 case GST_VIDEO_FORMAT_ARGB:
583 case GST_VIDEO_FORMAT_ABGR:
588 case GST_VIDEO_FORMAT_RGB:
589 case GST_VIDEO_FORMAT_BGR:
594 case GST_VIDEO_FORMAT_RGB16:
595 case GST_VIDEO_FORMAT_BGR16:
600 case GST_VIDEO_FORMAT_RGB15:
601 case GST_VIDEO_FORMAT_BGR15:
606 case GST_VIDEO_FORMAT_RGB8_PALETTED:
611 case GST_VIDEO_FORMAT_ARGB64:
616 case GST_VIDEO_FORMAT_r210:
624 if (bpp == 32 && depth == 30) {
625 red_mask = 0x3ff00000;
626 green_mask = 0x000ffc00;
627 blue_mask = 0x000003ff;
629 } else if (bpp == 32 || bpp == 24 || bpp == 64) {
636 mask >> (8 * gst_video_format_get_component_offset (format, 0, 0, 0));
638 mask >> (8 * gst_video_format_get_component_offset (format, 1, 0, 0));
640 mask >> (8 * gst_video_format_get_component_offset (format, 2, 0, 0));
641 } else if (bpp == 16) {
643 case GST_VIDEO_FORMAT_RGB16:
644 red_mask = GST_VIDEO_COMP1_MASK_16_INT;
645 green_mask = GST_VIDEO_COMP2_MASK_16_INT;
646 blue_mask = GST_VIDEO_COMP3_MASK_16_INT;
648 case GST_VIDEO_FORMAT_BGR16:
649 red_mask = GST_VIDEO_COMP3_MASK_16_INT;
650 green_mask = GST_VIDEO_COMP2_MASK_16_INT;
651 blue_mask = GST_VIDEO_COMP1_MASK_16_INT;
654 case GST_VIDEO_FORMAT_RGB15:
655 red_mask = GST_VIDEO_COMP1_MASK_15_INT;
656 green_mask = GST_VIDEO_COMP2_MASK_15_INT;
657 blue_mask = GST_VIDEO_COMP3_MASK_15_INT;
659 case GST_VIDEO_FORMAT_BGR15:
660 red_mask = GST_VIDEO_COMP3_MASK_15_INT;
661 green_mask = GST_VIDEO_COMP2_MASK_15_INT;
662 blue_mask = GST_VIDEO_COMP1_MASK_15_INT;
665 g_assert_not_reached ();
667 } else if (bpp != 8) {
668 g_assert_not_reached ();
671 caps = gst_caps_new_simple ("video/x-raw-rgb",
672 "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth, NULL);
675 gst_caps_set_simple (caps,
676 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
677 "red_mask", G_TYPE_INT, red_mask,
678 "green_mask", G_TYPE_INT, green_mask,
679 "blue_mask", G_TYPE_INT, blue_mask, NULL);
684 mask >> (8 * gst_video_format_get_component_offset (format, 3, 0, 0));
685 gst_caps_set_simple (caps, "alpha_mask", G_TYPE_INT, alpha_mask, NULL);
690 if (gst_video_format_is_gray (format)) {
697 case GST_VIDEO_FORMAT_GRAY8:
699 endianness = G_BIG_ENDIAN;
701 case GST_VIDEO_FORMAT_GRAY16_BE:
703 endianness = G_BIG_ENDIAN;
705 case GST_VIDEO_FORMAT_GRAY16_LE:
707 endianness = G_LITTLE_ENDIAN;
715 caps = gst_caps_new_simple ("video/x-raw-gray",
716 "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth, NULL);
718 caps = gst_caps_new_simple ("video/x-raw-gray",
719 "bpp", G_TYPE_INT, bpp,
720 "depth", G_TYPE_INT, depth,
721 "endianness", G_TYPE_INT, endianness, NULL);
731 * gst_video_format_new_template_caps:
732 * @format: the #GstVideoFormat describing the raw video format
734 * Creates a new #GstCaps object based on the parameters provided.
735 * Size, frame rate, and pixel aspect ratio are set to the full
740 * Returns: a new #GstCaps object, or NULL if there was an error
743 gst_video_format_new_template_caps (GstVideoFormat format)
746 GstStructure *structure;
748 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
750 caps = gst_video_format_new_caps_raw (format);
752 GValue value = { 0 };
755 structure = gst_caps_get_structure (caps, 0);
757 gst_structure_set (structure,
758 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
759 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
760 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1,
761 "pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
763 g_value_init (&value, GST_TYPE_LIST);
764 g_value_init (&v, G_TYPE_BOOLEAN);
765 g_value_set_boolean (&v, TRUE);
766 gst_value_list_append_value (&value, &v);
767 g_value_set_boolean (&v, FALSE);
768 gst_value_list_append_value (&value, &v);
771 gst_structure_take_value (structure, "interlaced", &value);
778 * gst_video_format_new_caps:
779 * @format: the #GstVideoFormat describing the raw video format
780 * @width: width of video
781 * @height: height of video
782 * @framerate_n: numerator of frame rate
783 * @framerate_d: denominator of frame rate
784 * @par_n: numerator of pixel aspect ratio
785 * @par_d: denominator of pixel aspect ratio
787 * Creates a new #GstCaps object based on the parameters provided.
791 * Returns: a new #GstCaps object, or NULL if there was an error
794 gst_video_format_new_caps (GstVideoFormat format, int width,
795 int height, int framerate_n, int framerate_d, int par_n, int par_d)
798 GstStructure *structure;
800 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
801 g_return_val_if_fail (width > 0 && height > 0, NULL);
803 caps = gst_video_format_new_caps_raw (format);
805 structure = gst_caps_get_structure (caps, 0);
807 gst_structure_set (structure,
808 "width", G_TYPE_INT, width,
809 "height", G_TYPE_INT, height,
810 "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
811 "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
819 * gst_video_format_from_fourcc:
820 * @fourcc: a FOURCC value representing raw YUV video
822 * Converts a FOURCC value into the corresponding #GstVideoFormat.
823 * If the FOURCC cannot be represented by #GstVideoFormat,
824 * #GST_VIDEO_FORMAT_UNKNOWN is returned.
828 * Returns: the #GstVideoFormat describing the FOURCC value
831 gst_video_format_from_fourcc (guint32 fourcc)
834 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
835 return GST_VIDEO_FORMAT_I420;
836 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
837 return GST_VIDEO_FORMAT_YV12;
838 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
839 return GST_VIDEO_FORMAT_YUY2;
840 case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'):
841 return GST_VIDEO_FORMAT_YVYU;
842 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
843 return GST_VIDEO_FORMAT_UYVY;
844 case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
845 return GST_VIDEO_FORMAT_AYUV;
846 case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
847 return GST_VIDEO_FORMAT_Y41B;
848 case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
849 return GST_VIDEO_FORMAT_Y42B;
850 case GST_MAKE_FOURCC ('Y', '4', '4', '4'):
851 return GST_VIDEO_FORMAT_Y444;
852 case GST_MAKE_FOURCC ('v', '2', '1', '0'):
853 return GST_VIDEO_FORMAT_v210;
854 case GST_MAKE_FOURCC ('v', '2', '1', '6'):
855 return GST_VIDEO_FORMAT_v216;
856 case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
857 return GST_VIDEO_FORMAT_NV12;
858 case GST_MAKE_FOURCC ('N', 'V', '2', '1'):
859 return GST_VIDEO_FORMAT_NV21;
860 case GST_MAKE_FOURCC ('v', '3', '0', '8'):
861 return GST_VIDEO_FORMAT_v308;
862 case GST_MAKE_FOURCC ('Y', '8', '0', '0'):
863 case GST_MAKE_FOURCC ('Y', '8', ' ', ' '):
864 case GST_MAKE_FOURCC ('G', 'R', 'E', 'Y'):
865 return GST_VIDEO_FORMAT_Y800;
866 case GST_MAKE_FOURCC ('Y', '1', '6', ' '):
867 return GST_VIDEO_FORMAT_Y16;
868 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'P'):
869 return GST_VIDEO_FORMAT_UYVP;
870 case GST_MAKE_FOURCC ('A', '4', '2', '0'):
871 return GST_VIDEO_FORMAT_A420;
872 case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
873 return GST_VIDEO_FORMAT_YUV9;
874 case GST_MAKE_FOURCC ('Y', 'V', 'U', '9'):
875 return GST_VIDEO_FORMAT_YVU9;
876 case GST_MAKE_FOURCC ('I', 'Y', 'U', '1'):
877 return GST_VIDEO_FORMAT_IYU1;
878 case GST_MAKE_FOURCC ('A', 'Y', '6', '4'):
879 return GST_VIDEO_FORMAT_AYUV64;
881 return GST_VIDEO_FORMAT_UNKNOWN;
886 * gst_video_format_to_fourcc:
887 * @format: a #GstVideoFormat video format
889 * Converts a #GstVideoFormat value into the corresponding FOURCC. Only
890 * a few YUV formats have corresponding FOURCC values. If @format has
891 * no corresponding FOURCC value, 0 is returned.
895 * Returns: the FOURCC corresponding to @format
898 gst_video_format_to_fourcc (GstVideoFormat format)
900 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
903 case GST_VIDEO_FORMAT_I420:
904 return GST_MAKE_FOURCC ('I', '4', '2', '0');
905 case GST_VIDEO_FORMAT_YV12:
906 return GST_MAKE_FOURCC ('Y', 'V', '1', '2');
907 case GST_VIDEO_FORMAT_YUY2:
908 return GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
909 case GST_VIDEO_FORMAT_YVYU:
910 return GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U');
911 case GST_VIDEO_FORMAT_UYVY:
912 return GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
913 case GST_VIDEO_FORMAT_AYUV:
914 return GST_MAKE_FOURCC ('A', 'Y', 'U', 'V');
915 case GST_VIDEO_FORMAT_Y41B:
916 return GST_MAKE_FOURCC ('Y', '4', '1', 'B');
917 case GST_VIDEO_FORMAT_Y42B:
918 return GST_MAKE_FOURCC ('Y', '4', '2', 'B');
919 case GST_VIDEO_FORMAT_Y444:
920 return GST_MAKE_FOURCC ('Y', '4', '4', '4');
921 case GST_VIDEO_FORMAT_v210:
922 return GST_MAKE_FOURCC ('v', '2', '1', '0');
923 case GST_VIDEO_FORMAT_v216:
924 return GST_MAKE_FOURCC ('v', '2', '1', '6');
925 case GST_VIDEO_FORMAT_NV12:
926 return GST_MAKE_FOURCC ('N', 'V', '1', '2');
927 case GST_VIDEO_FORMAT_NV21:
928 return GST_MAKE_FOURCC ('N', 'V', '2', '1');
929 case GST_VIDEO_FORMAT_v308:
930 return GST_MAKE_FOURCC ('v', '3', '0', '8');
931 case GST_VIDEO_FORMAT_Y800:
932 return GST_MAKE_FOURCC ('Y', '8', '0', '0');
933 case GST_VIDEO_FORMAT_Y16:
934 return GST_MAKE_FOURCC ('Y', '1', '6', ' ');
935 case GST_VIDEO_FORMAT_UYVP:
936 return GST_MAKE_FOURCC ('U', 'Y', 'V', 'P');
937 case GST_VIDEO_FORMAT_A420:
938 return GST_MAKE_FOURCC ('A', '4', '2', '0');
939 case GST_VIDEO_FORMAT_YUV9:
940 return GST_MAKE_FOURCC ('Y', 'U', 'V', '9');
941 case GST_VIDEO_FORMAT_YVU9:
942 return GST_MAKE_FOURCC ('Y', 'V', 'U', '9');
943 case GST_VIDEO_FORMAT_IYU1:
944 return GST_MAKE_FOURCC ('I', 'Y', 'U', '1');
945 case GST_VIDEO_FORMAT_AYUV64:
946 return GST_MAKE_FOURCC ('A', 'Y', '6', '4');
953 * gst_video_format_from_rgb32_masks:
954 * @red_mask: red bit mask
955 * @green_mask: green bit mask
956 * @blue_mask: blue bit mask
958 * Converts red, green, blue bit masks into the corresponding
963 * Returns: the #GstVideoFormat corresponding to the bit masks
965 static GstVideoFormat
966 gst_video_format_from_rgb32_masks (int red_mask, int green_mask, int blue_mask)
968 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
969 blue_mask == 0x0000ff00) {
970 return GST_VIDEO_FORMAT_RGBx;
972 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
973 blue_mask == 0xff000000) {
974 return GST_VIDEO_FORMAT_BGRx;
976 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
977 blue_mask == 0x000000ff) {
978 return GST_VIDEO_FORMAT_xRGB;
980 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
981 blue_mask == 0x00ff0000) {
982 return GST_VIDEO_FORMAT_xBGR;
985 return GST_VIDEO_FORMAT_UNKNOWN;
988 static GstVideoFormat
989 gst_video_format_from_rgba32_masks (int red_mask, int green_mask,
990 int blue_mask, int alpha_mask)
992 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
993 blue_mask == 0x0000ff00 && alpha_mask == 0x000000ff) {
994 return GST_VIDEO_FORMAT_RGBA;
996 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
997 blue_mask == 0xff000000 && alpha_mask == 0x000000ff) {
998 return GST_VIDEO_FORMAT_BGRA;
1000 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
1001 blue_mask == 0x000000ff && alpha_mask == 0xff000000) {
1002 return GST_VIDEO_FORMAT_ARGB;
1004 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
1005 blue_mask == 0x00ff0000 && alpha_mask == 0xff000000) {
1006 return GST_VIDEO_FORMAT_ABGR;
1009 return GST_VIDEO_FORMAT_UNKNOWN;
1012 static GstVideoFormat
1013 gst_video_format_from_rgb24_masks (int red_mask, int green_mask, int blue_mask)
1015 if (red_mask == 0xff0000 && green_mask == 0x00ff00 && blue_mask == 0x0000ff) {
1016 return GST_VIDEO_FORMAT_RGB;
1018 if (red_mask == 0x0000ff && green_mask == 0x00ff00 && blue_mask == 0xff0000) {
1019 return GST_VIDEO_FORMAT_BGR;
1022 return GST_VIDEO_FORMAT_UNKNOWN;
1025 static GstVideoFormat
1026 gst_video_format_from_rgb16_masks (int red_mask, int green_mask, int blue_mask)
1028 if (red_mask == GST_VIDEO_COMP1_MASK_16_INT
1029 && green_mask == GST_VIDEO_COMP2_MASK_16_INT
1030 && blue_mask == GST_VIDEO_COMP3_MASK_16_INT) {
1031 return GST_VIDEO_FORMAT_RGB16;
1033 if (red_mask == GST_VIDEO_COMP3_MASK_16_INT
1034 && green_mask == GST_VIDEO_COMP2_MASK_16_INT
1035 && blue_mask == GST_VIDEO_COMP1_MASK_16_INT) {
1036 return GST_VIDEO_FORMAT_BGR16;
1038 if (red_mask == GST_VIDEO_COMP1_MASK_15_INT
1039 && green_mask == GST_VIDEO_COMP2_MASK_15_INT
1040 && blue_mask == GST_VIDEO_COMP3_MASK_15_INT) {
1041 return GST_VIDEO_FORMAT_RGB15;
1043 if (red_mask == GST_VIDEO_COMP3_MASK_15_INT
1044 && green_mask == GST_VIDEO_COMP2_MASK_15_INT
1045 && blue_mask == GST_VIDEO_COMP1_MASK_15_INT) {
1046 return GST_VIDEO_FORMAT_BGR15;
1049 return GST_VIDEO_FORMAT_UNKNOWN;
1053 * gst_video_format_is_rgb:
1054 * @format: a #GstVideoFormat
1056 * Determine whether the video format is an RGB format.
1060 * Returns: TRUE if @format represents RGB video
1063 gst_video_format_is_rgb (GstVideoFormat format)
1066 case GST_VIDEO_FORMAT_I420:
1067 case GST_VIDEO_FORMAT_YV12:
1068 case GST_VIDEO_FORMAT_YUY2:
1069 case GST_VIDEO_FORMAT_YVYU:
1070 case GST_VIDEO_FORMAT_UYVY:
1071 case GST_VIDEO_FORMAT_AYUV:
1072 case GST_VIDEO_FORMAT_Y41B:
1073 case GST_VIDEO_FORMAT_Y42B:
1074 case GST_VIDEO_FORMAT_Y444:
1075 case GST_VIDEO_FORMAT_v210:
1076 case GST_VIDEO_FORMAT_v216:
1077 case GST_VIDEO_FORMAT_NV12:
1078 case GST_VIDEO_FORMAT_NV21:
1079 case GST_VIDEO_FORMAT_v308:
1080 case GST_VIDEO_FORMAT_UYVP:
1081 case GST_VIDEO_FORMAT_A420:
1082 case GST_VIDEO_FORMAT_YUV9:
1083 case GST_VIDEO_FORMAT_YVU9:
1084 case GST_VIDEO_FORMAT_IYU1:
1085 case GST_VIDEO_FORMAT_AYUV64:
1087 case GST_VIDEO_FORMAT_RGBx:
1088 case GST_VIDEO_FORMAT_BGRx:
1089 case GST_VIDEO_FORMAT_xRGB:
1090 case GST_VIDEO_FORMAT_xBGR:
1091 case GST_VIDEO_FORMAT_RGBA:
1092 case GST_VIDEO_FORMAT_BGRA:
1093 case GST_VIDEO_FORMAT_ARGB:
1094 case GST_VIDEO_FORMAT_ABGR:
1095 case GST_VIDEO_FORMAT_RGB:
1096 case GST_VIDEO_FORMAT_BGR:
1097 case GST_VIDEO_FORMAT_RGB16:
1098 case GST_VIDEO_FORMAT_BGR16:
1099 case GST_VIDEO_FORMAT_RGB15:
1100 case GST_VIDEO_FORMAT_BGR15:
1101 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1102 case GST_VIDEO_FORMAT_ARGB64:
1103 case GST_VIDEO_FORMAT_r210:
1111 * gst_video_format_is_yuv:
1112 * @format: a #GstVideoFormat
1114 * Determine whether the video format is a YUV format.
1118 * Returns: TRUE if @format represents YUV video
1121 gst_video_format_is_yuv (GstVideoFormat format)
1124 case GST_VIDEO_FORMAT_I420:
1125 case GST_VIDEO_FORMAT_YV12:
1126 case GST_VIDEO_FORMAT_YUY2:
1127 case GST_VIDEO_FORMAT_YVYU:
1128 case GST_VIDEO_FORMAT_UYVY:
1129 case GST_VIDEO_FORMAT_AYUV:
1130 case GST_VIDEO_FORMAT_Y41B:
1131 case GST_VIDEO_FORMAT_Y42B:
1132 case GST_VIDEO_FORMAT_Y444:
1133 case GST_VIDEO_FORMAT_v210:
1134 case GST_VIDEO_FORMAT_v216:
1135 case GST_VIDEO_FORMAT_NV12:
1136 case GST_VIDEO_FORMAT_NV21:
1137 case GST_VIDEO_FORMAT_v308:
1138 case GST_VIDEO_FORMAT_Y800:
1139 case GST_VIDEO_FORMAT_Y16:
1140 case GST_VIDEO_FORMAT_UYVP:
1141 case GST_VIDEO_FORMAT_A420:
1142 case GST_VIDEO_FORMAT_YUV9:
1143 case GST_VIDEO_FORMAT_YVU9:
1144 case GST_VIDEO_FORMAT_IYU1:
1145 case GST_VIDEO_FORMAT_AYUV64:
1147 case GST_VIDEO_FORMAT_RGBx:
1148 case GST_VIDEO_FORMAT_BGRx:
1149 case GST_VIDEO_FORMAT_xRGB:
1150 case GST_VIDEO_FORMAT_xBGR:
1151 case GST_VIDEO_FORMAT_RGBA:
1152 case GST_VIDEO_FORMAT_BGRA:
1153 case GST_VIDEO_FORMAT_ARGB:
1154 case GST_VIDEO_FORMAT_ABGR:
1155 case GST_VIDEO_FORMAT_RGB:
1156 case GST_VIDEO_FORMAT_BGR:
1157 case GST_VIDEO_FORMAT_RGB16:
1158 case GST_VIDEO_FORMAT_BGR16:
1159 case GST_VIDEO_FORMAT_RGB15:
1160 case GST_VIDEO_FORMAT_BGR15:
1161 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1162 case GST_VIDEO_FORMAT_ARGB64:
1163 case GST_VIDEO_FORMAT_r210:
1171 * gst_video_format_is_gray:
1172 * @format: a #GstVideoFormat
1174 * Determine whether the video format is a grayscale format.
1178 * Returns: TRUE if @format represents grayscale video
1181 gst_video_format_is_gray (GstVideoFormat format)
1184 case GST_VIDEO_FORMAT_GRAY8:
1185 case GST_VIDEO_FORMAT_GRAY16_BE:
1186 case GST_VIDEO_FORMAT_GRAY16_LE:
1187 case GST_VIDEO_FORMAT_Y800:
1188 case GST_VIDEO_FORMAT_Y16:
1196 * gst_video_format_has_alpha:
1197 * @format: a #GstVideoFormat
1199 * Returns TRUE or FALSE depending on if the video format provides an
1204 * Returns: TRUE if @format has an alpha channel
1207 gst_video_format_has_alpha (GstVideoFormat format)
1210 case GST_VIDEO_FORMAT_I420:
1211 case GST_VIDEO_FORMAT_YV12:
1212 case GST_VIDEO_FORMAT_YUY2:
1213 case GST_VIDEO_FORMAT_YVYU:
1214 case GST_VIDEO_FORMAT_UYVY:
1215 case GST_VIDEO_FORMAT_Y41B:
1216 case GST_VIDEO_FORMAT_Y42B:
1217 case GST_VIDEO_FORMAT_Y444:
1218 case GST_VIDEO_FORMAT_v210:
1219 case GST_VIDEO_FORMAT_v216:
1220 case GST_VIDEO_FORMAT_NV12:
1221 case GST_VIDEO_FORMAT_NV21:
1222 case GST_VIDEO_FORMAT_v308:
1223 case GST_VIDEO_FORMAT_Y800:
1224 case GST_VIDEO_FORMAT_Y16:
1225 case GST_VIDEO_FORMAT_UYVP:
1226 case GST_VIDEO_FORMAT_YUV9:
1227 case GST_VIDEO_FORMAT_YVU9:
1228 case GST_VIDEO_FORMAT_IYU1:
1230 case GST_VIDEO_FORMAT_AYUV:
1231 case GST_VIDEO_FORMAT_RGBA:
1232 case GST_VIDEO_FORMAT_BGRA:
1233 case GST_VIDEO_FORMAT_ARGB:
1234 case GST_VIDEO_FORMAT_ABGR:
1235 case GST_VIDEO_FORMAT_A420:
1236 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1237 case GST_VIDEO_FORMAT_ARGB64:
1238 case GST_VIDEO_FORMAT_AYUV64:
1240 case GST_VIDEO_FORMAT_RGBx:
1241 case GST_VIDEO_FORMAT_BGRx:
1242 case GST_VIDEO_FORMAT_xRGB:
1243 case GST_VIDEO_FORMAT_xBGR:
1244 case GST_VIDEO_FORMAT_RGB:
1245 case GST_VIDEO_FORMAT_BGR:
1246 case GST_VIDEO_FORMAT_RGB16:
1247 case GST_VIDEO_FORMAT_BGR16:
1248 case GST_VIDEO_FORMAT_RGB15:
1249 case GST_VIDEO_FORMAT_BGR15:
1250 case GST_VIDEO_FORMAT_r210:
1258 * gst_video_format_get_component_depth:
1259 * @format: a #GstVideoFormat
1260 * @component: the video component (e.g. 0 for 'R' in RGB)
1262 * Returns the number of bits used to encode an individual pixel of
1263 * a given @component. Typically this is 8, although higher and lower
1264 * values are possible for some formats.
1268 * Returns: depth of component
1271 gst_video_format_get_component_depth (GstVideoFormat format, int component)
1273 if (component == 3 && !gst_video_format_has_alpha (format))
1277 case GST_VIDEO_FORMAT_RGB16:
1278 case GST_VIDEO_FORMAT_BGR16:
1282 case GST_VIDEO_FORMAT_RGB15:
1283 case GST_VIDEO_FORMAT_BGR15:
1285 case GST_VIDEO_FORMAT_I420:
1286 case GST_VIDEO_FORMAT_YV12:
1287 case GST_VIDEO_FORMAT_YUY2:
1288 case GST_VIDEO_FORMAT_YVYU:
1289 case GST_VIDEO_FORMAT_UYVY:
1290 case GST_VIDEO_FORMAT_Y41B:
1291 case GST_VIDEO_FORMAT_Y42B:
1292 case GST_VIDEO_FORMAT_Y444:
1293 case GST_VIDEO_FORMAT_NV12:
1294 case GST_VIDEO_FORMAT_NV21:
1295 case GST_VIDEO_FORMAT_v308:
1296 case GST_VIDEO_FORMAT_Y800:
1297 case GST_VIDEO_FORMAT_YUV9:
1298 case GST_VIDEO_FORMAT_YVU9:
1299 case GST_VIDEO_FORMAT_IYU1:
1300 case GST_VIDEO_FORMAT_AYUV:
1301 case GST_VIDEO_FORMAT_RGBA:
1302 case GST_VIDEO_FORMAT_BGRA:
1303 case GST_VIDEO_FORMAT_ARGB:
1304 case GST_VIDEO_FORMAT_ABGR:
1305 case GST_VIDEO_FORMAT_A420:
1306 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1307 case GST_VIDEO_FORMAT_RGBx:
1308 case GST_VIDEO_FORMAT_BGRx:
1309 case GST_VIDEO_FORMAT_xRGB:
1310 case GST_VIDEO_FORMAT_xBGR:
1311 case GST_VIDEO_FORMAT_RGB:
1312 case GST_VIDEO_FORMAT_BGR:
1315 case GST_VIDEO_FORMAT_v210:
1316 case GST_VIDEO_FORMAT_UYVP:
1317 case GST_VIDEO_FORMAT_r210:
1319 case GST_VIDEO_FORMAT_Y16:
1320 case GST_VIDEO_FORMAT_v216:
1321 case GST_VIDEO_FORMAT_ARGB64:
1322 case GST_VIDEO_FORMAT_AYUV64:
1329 * gst_video_format_get_row_stride:
1330 * @format: a #GstVideoFormat
1331 * @component: the component index
1332 * @width: the width of video
1334 * Calculates the row stride (number of bytes from one row of pixels to
1335 * the next) for the video component with an index of @component. For
1336 * YUV video, Y, U, and V have component indices of 0, 1, and 2,
1337 * respectively. For RGB video, R, G, and B have component indicies of
1338 * 0, 1, and 2, respectively. Alpha channels, if present, have a component
1339 * index of 3. The @width parameter always represents the width of the
1340 * video, not the component.
1344 * Returns: row stride of component @component
1347 gst_video_format_get_row_stride (GstVideoFormat format, int component,
1350 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1351 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1352 g_return_val_if_fail (width > 0, 0);
1355 case GST_VIDEO_FORMAT_I420:
1356 case GST_VIDEO_FORMAT_YV12:
1357 if (component == 0) {
1358 return GST_ROUND_UP_4 (width);
1360 return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
1362 case GST_VIDEO_FORMAT_YUY2:
1363 case GST_VIDEO_FORMAT_YVYU:
1364 case GST_VIDEO_FORMAT_UYVY:
1365 return GST_ROUND_UP_4 (width * 2);
1366 case GST_VIDEO_FORMAT_AYUV:
1367 case GST_VIDEO_FORMAT_RGBx:
1368 case GST_VIDEO_FORMAT_BGRx:
1369 case GST_VIDEO_FORMAT_xRGB:
1370 case GST_VIDEO_FORMAT_xBGR:
1371 case GST_VIDEO_FORMAT_RGBA:
1372 case GST_VIDEO_FORMAT_BGRA:
1373 case GST_VIDEO_FORMAT_ARGB:
1374 case GST_VIDEO_FORMAT_ABGR:
1375 case GST_VIDEO_FORMAT_r210:
1377 case GST_VIDEO_FORMAT_RGB16:
1378 case GST_VIDEO_FORMAT_BGR16:
1379 case GST_VIDEO_FORMAT_RGB15:
1380 case GST_VIDEO_FORMAT_BGR15:
1381 return GST_ROUND_UP_4 (width * 2);
1382 case GST_VIDEO_FORMAT_RGB:
1383 case GST_VIDEO_FORMAT_BGR:
1384 case GST_VIDEO_FORMAT_v308:
1385 return GST_ROUND_UP_4 (width * 3);
1386 case GST_VIDEO_FORMAT_Y41B:
1387 if (component == 0) {
1388 return GST_ROUND_UP_4 (width);
1390 return GST_ROUND_UP_16 (width) / 4;
1392 case GST_VIDEO_FORMAT_Y42B:
1393 if (component == 0) {
1394 return GST_ROUND_UP_4 (width);
1396 return GST_ROUND_UP_8 (width) / 2;
1398 case GST_VIDEO_FORMAT_Y444:
1399 return GST_ROUND_UP_4 (width);
1400 case GST_VIDEO_FORMAT_v210:
1401 return ((width + 47) / 48) * 128;
1402 case GST_VIDEO_FORMAT_v216:
1403 return GST_ROUND_UP_8 (width * 4);
1404 case GST_VIDEO_FORMAT_NV12:
1405 case GST_VIDEO_FORMAT_NV21:
1406 return GST_ROUND_UP_4 (width);
1407 case GST_VIDEO_FORMAT_GRAY8:
1408 case GST_VIDEO_FORMAT_Y800:
1409 return GST_ROUND_UP_4 (width);
1410 case GST_VIDEO_FORMAT_GRAY16_BE:
1411 case GST_VIDEO_FORMAT_GRAY16_LE:
1412 case GST_VIDEO_FORMAT_Y16:
1413 return GST_ROUND_UP_4 (width * 2);
1414 case GST_VIDEO_FORMAT_UYVP:
1415 return GST_ROUND_UP_4 ((width * 2 * 5 + 3) / 4);
1416 case GST_VIDEO_FORMAT_A420:
1417 if (component == 0 || component == 3) {
1418 return GST_ROUND_UP_4 (width);
1420 return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
1422 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1423 return GST_ROUND_UP_4 (width);
1424 case GST_VIDEO_FORMAT_YUV9:
1425 case GST_VIDEO_FORMAT_YVU9:
1426 if (component == 0) {
1427 return GST_ROUND_UP_4 (width);
1429 return GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4);
1431 case GST_VIDEO_FORMAT_IYU1:
1432 return GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) +
1433 GST_ROUND_UP_4 (width) / 2);
1434 case GST_VIDEO_FORMAT_ARGB64:
1435 case GST_VIDEO_FORMAT_AYUV64:
1443 * gst_video_format_get_pixel_stride:
1444 * @format: a #GstVideoFormat
1445 * @component: the component index
1447 * Calculates the pixel stride (number of bytes from one pixel to the
1448 * pixel to its immediate left) for the video component with an index
1449 * of @component. See @gst_video_format_get_row_stride for a description
1450 * of the component index.
1454 * Returns: pixel stride of component @component
1457 gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
1459 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1460 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1463 case GST_VIDEO_FORMAT_I420:
1464 case GST_VIDEO_FORMAT_YV12:
1465 case GST_VIDEO_FORMAT_Y41B:
1466 case GST_VIDEO_FORMAT_Y42B:
1467 case GST_VIDEO_FORMAT_Y444:
1468 case GST_VIDEO_FORMAT_A420:
1469 case GST_VIDEO_FORMAT_YUV9:
1470 case GST_VIDEO_FORMAT_YVU9:
1472 case GST_VIDEO_FORMAT_YUY2:
1473 case GST_VIDEO_FORMAT_YVYU:
1474 case GST_VIDEO_FORMAT_UYVY:
1475 if (component == 0) {
1480 case GST_VIDEO_FORMAT_IYU1:
1481 /* doesn't make much sense for IYU1 because it's 1 or 3
1482 * for luma depending on position */
1484 case GST_VIDEO_FORMAT_AYUV:
1485 case GST_VIDEO_FORMAT_RGBx:
1486 case GST_VIDEO_FORMAT_BGRx:
1487 case GST_VIDEO_FORMAT_xRGB:
1488 case GST_VIDEO_FORMAT_xBGR:
1489 case GST_VIDEO_FORMAT_RGBA:
1490 case GST_VIDEO_FORMAT_BGRA:
1491 case GST_VIDEO_FORMAT_ARGB:
1492 case GST_VIDEO_FORMAT_ABGR:
1493 case GST_VIDEO_FORMAT_r210:
1495 case GST_VIDEO_FORMAT_RGB16:
1496 case GST_VIDEO_FORMAT_BGR16:
1497 case GST_VIDEO_FORMAT_RGB15:
1498 case GST_VIDEO_FORMAT_BGR15:
1500 case GST_VIDEO_FORMAT_RGB:
1501 case GST_VIDEO_FORMAT_BGR:
1502 case GST_VIDEO_FORMAT_v308:
1504 case GST_VIDEO_FORMAT_v210:
1505 /* v210 is packed at the bit level, so pixel stride doesn't make sense */
1507 case GST_VIDEO_FORMAT_v216:
1508 if (component == 0) {
1513 case GST_VIDEO_FORMAT_NV12:
1514 case GST_VIDEO_FORMAT_NV21:
1515 if (component == 0) {
1520 case GST_VIDEO_FORMAT_GRAY8:
1521 case GST_VIDEO_FORMAT_Y800:
1523 case GST_VIDEO_FORMAT_GRAY16_BE:
1524 case GST_VIDEO_FORMAT_GRAY16_LE:
1525 case GST_VIDEO_FORMAT_Y16:
1527 case GST_VIDEO_FORMAT_UYVP:
1528 /* UYVP is packed at the bit level, so pixel stride doesn't make sense */
1530 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1532 case GST_VIDEO_FORMAT_ARGB64:
1533 case GST_VIDEO_FORMAT_AYUV64:
1541 * gst_video_format_get_component_width:
1542 * @format: a #GstVideoFormat
1543 * @component: the component index
1544 * @width: the width of video
1546 * Calculates the width of the component. See
1547 * @gst_video_format_get_row_stride for a description
1548 * of the component index.
1552 * Returns: width of component @component
1555 gst_video_format_get_component_width (GstVideoFormat format,
1556 int component, int width)
1558 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1559 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1560 g_return_val_if_fail (width > 0, 0);
1563 case GST_VIDEO_FORMAT_I420:
1564 case GST_VIDEO_FORMAT_YV12:
1565 case GST_VIDEO_FORMAT_YUY2:
1566 case GST_VIDEO_FORMAT_YVYU:
1567 case GST_VIDEO_FORMAT_UYVY:
1568 case GST_VIDEO_FORMAT_Y42B:
1569 case GST_VIDEO_FORMAT_v210:
1570 case GST_VIDEO_FORMAT_v216:
1571 case GST_VIDEO_FORMAT_NV12:
1572 case GST_VIDEO_FORMAT_NV21:
1573 case GST_VIDEO_FORMAT_UYVP:
1574 if (component == 0) {
1577 return GST_ROUND_UP_2 (width) / 2;
1579 case GST_VIDEO_FORMAT_Y41B:
1580 case GST_VIDEO_FORMAT_YUV9:
1581 case GST_VIDEO_FORMAT_YVU9:
1582 case GST_VIDEO_FORMAT_IYU1:
1583 if (component == 0) {
1586 return GST_ROUND_UP_4 (width) / 4;
1588 case GST_VIDEO_FORMAT_AYUV:
1589 case GST_VIDEO_FORMAT_RGBx:
1590 case GST_VIDEO_FORMAT_BGRx:
1591 case GST_VIDEO_FORMAT_xRGB:
1592 case GST_VIDEO_FORMAT_xBGR:
1593 case GST_VIDEO_FORMAT_RGBA:
1594 case GST_VIDEO_FORMAT_BGRA:
1595 case GST_VIDEO_FORMAT_ARGB:
1596 case GST_VIDEO_FORMAT_ABGR:
1597 case GST_VIDEO_FORMAT_RGB:
1598 case GST_VIDEO_FORMAT_BGR:
1599 case GST_VIDEO_FORMAT_RGB16:
1600 case GST_VIDEO_FORMAT_BGR16:
1601 case GST_VIDEO_FORMAT_RGB15:
1602 case GST_VIDEO_FORMAT_BGR15:
1603 case GST_VIDEO_FORMAT_Y444:
1604 case GST_VIDEO_FORMAT_v308:
1605 case GST_VIDEO_FORMAT_GRAY8:
1606 case GST_VIDEO_FORMAT_GRAY16_BE:
1607 case GST_VIDEO_FORMAT_GRAY16_LE:
1608 case GST_VIDEO_FORMAT_Y800:
1609 case GST_VIDEO_FORMAT_Y16:
1610 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1611 case GST_VIDEO_FORMAT_ARGB64:
1612 case GST_VIDEO_FORMAT_AYUV64:
1613 case GST_VIDEO_FORMAT_r210:
1615 case GST_VIDEO_FORMAT_A420:
1616 if (component == 0 || component == 3) {
1619 return GST_ROUND_UP_2 (width) / 2;
1627 * gst_video_format_get_component_height:
1628 * @format: a #GstVideoFormat
1629 * @component: the component index
1630 * @height: the height of video
1632 * Calculates the height of the component. See
1633 * @gst_video_format_get_row_stride for a description
1634 * of the component index.
1638 * Returns: height of component @component
1641 gst_video_format_get_component_height (GstVideoFormat format,
1642 int component, int height)
1644 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1645 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1646 g_return_val_if_fail (height > 0, 0);
1649 case GST_VIDEO_FORMAT_I420:
1650 case GST_VIDEO_FORMAT_YV12:
1651 case GST_VIDEO_FORMAT_NV12:
1652 case GST_VIDEO_FORMAT_NV21:
1653 if (component == 0) {
1656 return GST_ROUND_UP_2 (height) / 2;
1658 case GST_VIDEO_FORMAT_Y41B:
1659 case GST_VIDEO_FORMAT_Y42B:
1660 case GST_VIDEO_FORMAT_YUY2:
1661 case GST_VIDEO_FORMAT_YVYU:
1662 case GST_VIDEO_FORMAT_UYVY:
1663 case GST_VIDEO_FORMAT_AYUV:
1664 case GST_VIDEO_FORMAT_RGBx:
1665 case GST_VIDEO_FORMAT_BGRx:
1666 case GST_VIDEO_FORMAT_xRGB:
1667 case GST_VIDEO_FORMAT_xBGR:
1668 case GST_VIDEO_FORMAT_RGBA:
1669 case GST_VIDEO_FORMAT_BGRA:
1670 case GST_VIDEO_FORMAT_ARGB:
1671 case GST_VIDEO_FORMAT_ABGR:
1672 case GST_VIDEO_FORMAT_RGB:
1673 case GST_VIDEO_FORMAT_BGR:
1674 case GST_VIDEO_FORMAT_RGB16:
1675 case GST_VIDEO_FORMAT_BGR16:
1676 case GST_VIDEO_FORMAT_RGB15:
1677 case GST_VIDEO_FORMAT_BGR15:
1678 case GST_VIDEO_FORMAT_Y444:
1679 case GST_VIDEO_FORMAT_v210:
1680 case GST_VIDEO_FORMAT_v216:
1681 case GST_VIDEO_FORMAT_v308:
1682 case GST_VIDEO_FORMAT_GRAY8:
1683 case GST_VIDEO_FORMAT_GRAY16_BE:
1684 case GST_VIDEO_FORMAT_GRAY16_LE:
1685 case GST_VIDEO_FORMAT_Y800:
1686 case GST_VIDEO_FORMAT_Y16:
1687 case GST_VIDEO_FORMAT_UYVP:
1688 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1689 case GST_VIDEO_FORMAT_IYU1:
1690 case GST_VIDEO_FORMAT_ARGB64:
1691 case GST_VIDEO_FORMAT_AYUV64:
1692 case GST_VIDEO_FORMAT_r210:
1694 case GST_VIDEO_FORMAT_A420:
1695 if (component == 0 || component == 3) {
1698 return GST_ROUND_UP_2 (height) / 2;
1700 case GST_VIDEO_FORMAT_YUV9:
1701 case GST_VIDEO_FORMAT_YVU9:
1702 if (component == 0) {
1705 return GST_ROUND_UP_4 (height) / 4;
1713 * gst_video_format_get_component_offset:
1714 * @format: a #GstVideoFormat
1715 * @component: the component index
1716 * @width: the width of video
1717 * @height: the height of video
1719 * Calculates the offset (in bytes) of the first pixel of the component
1720 * with index @component. For packed formats, this will typically be a
1721 * small integer (0, 1, 2, 3). For planar formats, this will be a
1722 * (relatively) large offset to the beginning of the second or third
1723 * component planes. See @gst_video_format_get_row_stride for a description
1724 * of the component index.
1728 * Returns: offset of component @component
1731 gst_video_format_get_component_offset (GstVideoFormat format,
1732 int component, int width, int height)
1734 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1735 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1736 g_return_val_if_fail ((!gst_video_format_is_yuv (format)) || (width > 0
1740 case GST_VIDEO_FORMAT_I420:
1744 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1745 if (component == 2) {
1746 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1747 GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1748 (GST_ROUND_UP_2 (height) / 2);
1751 case GST_VIDEO_FORMAT_YV12: /* same as I420, but components 1+2 swapped */
1755 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1756 if (component == 1) {
1757 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1758 GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1759 (GST_ROUND_UP_2 (height) / 2);
1762 case GST_VIDEO_FORMAT_YUY2:
1770 case GST_VIDEO_FORMAT_YVYU:
1778 case GST_VIDEO_FORMAT_UYVY:
1786 case GST_VIDEO_FORMAT_AYUV:
1796 case GST_VIDEO_FORMAT_RGBx:
1797 case GST_VIDEO_FORMAT_RGBA:
1807 case GST_VIDEO_FORMAT_BGRx:
1808 case GST_VIDEO_FORMAT_BGRA:
1818 case GST_VIDEO_FORMAT_xRGB:
1819 case GST_VIDEO_FORMAT_ARGB:
1829 case GST_VIDEO_FORMAT_xBGR:
1830 case GST_VIDEO_FORMAT_ABGR:
1840 case GST_VIDEO_FORMAT_RGB:
1841 case GST_VIDEO_FORMAT_v308:
1849 case GST_VIDEO_FORMAT_BGR:
1857 case GST_VIDEO_FORMAT_Y41B:
1861 return GST_ROUND_UP_4 (width) * height;
1863 return (GST_ROUND_UP_4 (width) +
1864 (GST_ROUND_UP_16 (width) / 4)) * height;
1866 case GST_VIDEO_FORMAT_Y42B:
1870 return GST_ROUND_UP_4 (width) * height;
1872 return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_8 (width) / 2)) * height;
1874 case GST_VIDEO_FORMAT_Y444:
1875 return GST_ROUND_UP_4 (width) * height * component;
1876 case GST_VIDEO_FORMAT_v210:
1877 case GST_VIDEO_FORMAT_r210:
1878 /* v210 is bit-packed, so this doesn't make sense */
1880 case GST_VIDEO_FORMAT_v216:
1888 case GST_VIDEO_FORMAT_NV12:
1892 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1894 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) + 1;
1896 case GST_VIDEO_FORMAT_NV21:
1900 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) + 1;
1902 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1904 case GST_VIDEO_FORMAT_GRAY8:
1905 case GST_VIDEO_FORMAT_GRAY16_BE:
1906 case GST_VIDEO_FORMAT_GRAY16_LE:
1907 case GST_VIDEO_FORMAT_Y800:
1908 case GST_VIDEO_FORMAT_Y16:
1910 case GST_VIDEO_FORMAT_UYVP:
1911 /* UYVP is bit-packed, so this doesn't make sense */
1913 case GST_VIDEO_FORMAT_A420:
1917 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1918 if (component == 2) {
1919 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1920 GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1921 (GST_ROUND_UP_2 (height) / 2);
1923 if (component == 3) {
1924 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1925 2 * GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1926 (GST_ROUND_UP_2 (height) / 2);
1929 case GST_VIDEO_FORMAT_RGB8_PALETTED:
1931 case GST_VIDEO_FORMAT_YUV9:
1935 return GST_ROUND_UP_4 (width) * height;
1936 if (component == 2) {
1937 return GST_ROUND_UP_4 (width) * height +
1938 GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4) *
1939 (GST_ROUND_UP_4 (height) / 4);
1942 case GST_VIDEO_FORMAT_YVU9:
1945 if (component == 1) {
1946 return GST_ROUND_UP_4 (width) * height +
1947 GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4) *
1948 (GST_ROUND_UP_4 (height) / 4);
1951 return GST_ROUND_UP_4 (width) * height;
1953 case GST_VIDEO_FORMAT_IYU1:
1961 case GST_VIDEO_FORMAT_ARGB64:
1962 case GST_VIDEO_FORMAT_AYUV64:
1975 GST_WARNING ("unhandled format %d or component %d", format, component);
1980 * gst_video_format_get_size:
1981 * @format: a #GstVideoFormat
1982 * @width: the width of video
1983 * @height: the height of video
1985 * Calculates the total number of bytes in the raw video format. This
1986 * number should be used when allocating a buffer for raw video.
1990 * Returns: size (in bytes) of raw video format
1993 gst_video_format_get_size (GstVideoFormat format, int width, int height)
1997 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1998 g_return_val_if_fail (width > 0 && height > 0, 0);
2001 case GST_VIDEO_FORMAT_I420:
2002 case GST_VIDEO_FORMAT_YV12:
2003 size = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
2004 size += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
2005 (GST_ROUND_UP_2 (height) / 2) * 2;
2007 case GST_VIDEO_FORMAT_IYU1:
2008 return GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) +
2009 GST_ROUND_UP_4 (width) / 2) * height;
2010 case GST_VIDEO_FORMAT_YUY2:
2011 case GST_VIDEO_FORMAT_YVYU:
2012 case GST_VIDEO_FORMAT_UYVY:
2013 return GST_ROUND_UP_4 (width * 2) * height;
2014 case GST_VIDEO_FORMAT_AYUV:
2015 case GST_VIDEO_FORMAT_RGBx:
2016 case GST_VIDEO_FORMAT_BGRx:
2017 case GST_VIDEO_FORMAT_xRGB:
2018 case GST_VIDEO_FORMAT_xBGR:
2019 case GST_VIDEO_FORMAT_RGBA:
2020 case GST_VIDEO_FORMAT_BGRA:
2021 case GST_VIDEO_FORMAT_ARGB:
2022 case GST_VIDEO_FORMAT_ABGR:
2023 case GST_VIDEO_FORMAT_r210:
2024 return width * 4 * height;
2025 case GST_VIDEO_FORMAT_RGB16:
2026 case GST_VIDEO_FORMAT_BGR16:
2027 case GST_VIDEO_FORMAT_RGB15:
2028 case GST_VIDEO_FORMAT_BGR15:
2029 return GST_ROUND_UP_4 (width * 2) * height;
2030 case GST_VIDEO_FORMAT_RGB:
2031 case GST_VIDEO_FORMAT_BGR:
2032 case GST_VIDEO_FORMAT_v308:
2033 return GST_ROUND_UP_4 (width * 3) * height;
2034 case GST_VIDEO_FORMAT_Y41B:
2035 /* simplification of ROUNDUP4(w)*h + 2*((ROUNDUP16(w)/4)*h */
2036 return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_16 (width) / 2)) * height;
2037 case GST_VIDEO_FORMAT_Y42B:
2038 /* simplification of ROUNDUP4(w)*h + 2*(ROUNDUP8(w)/2)*h */
2039 return (GST_ROUND_UP_4 (width) + GST_ROUND_UP_8 (width)) * height;
2040 case GST_VIDEO_FORMAT_Y444:
2041 return GST_ROUND_UP_4 (width) * height * 3;
2042 case GST_VIDEO_FORMAT_v210:
2043 return ((width + 47) / 48) * 128 * height;
2044 case GST_VIDEO_FORMAT_v216:
2045 return GST_ROUND_UP_8 (width * 4) * height;
2046 case GST_VIDEO_FORMAT_NV12:
2047 case GST_VIDEO_FORMAT_NV21:
2048 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) * 3 / 2;
2049 case GST_VIDEO_FORMAT_GRAY8:
2050 case GST_VIDEO_FORMAT_Y800:
2051 case GST_VIDEO_FORMAT_RGB8_PALETTED:
2052 return GST_ROUND_UP_4 (width) * height;
2053 case GST_VIDEO_FORMAT_GRAY16_BE:
2054 case GST_VIDEO_FORMAT_GRAY16_LE:
2055 case GST_VIDEO_FORMAT_Y16:
2056 return GST_ROUND_UP_4 (width * 2) * height;
2057 case GST_VIDEO_FORMAT_UYVP:
2058 return GST_ROUND_UP_4 ((width * 2 * 5 + 3) / 4) * height;
2059 case GST_VIDEO_FORMAT_A420:
2060 size = 2 * GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
2061 size += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
2062 (GST_ROUND_UP_2 (height) / 2) * 2;
2064 case GST_VIDEO_FORMAT_YUV9:
2065 case GST_VIDEO_FORMAT_YVU9:
2066 size = GST_ROUND_UP_4 (width) * height;
2067 size += GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4) *
2068 (GST_ROUND_UP_4 (height) / 4) * 2;
2070 case GST_VIDEO_FORMAT_ARGB64:
2071 case GST_VIDEO_FORMAT_AYUV64:
2072 return width * 8 * height;
2079 * gst_video_get_size_from_caps:
2080 * @caps: a pointer to #GstCaps
2081 * @size: a pointer to a gint that will be assigned the size (in bytes) of a video frame with the given caps
2083 * Calculates the total number of bytes in the raw video format for the given
2084 * caps. This number should be used when allocating a buffer for raw video.
2088 * Returns: %TRUE if the size could be calculated from the caps
2091 gst_video_get_size_from_caps (const GstCaps * caps, gint * size)
2093 GstVideoFormat format = 0;
2094 gint width = 0, height = 0;
2096 g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
2097 g_return_val_if_fail (size != NULL, FALSE);
2099 if (gst_video_format_parse_caps (caps, &format, &width, &height) == FALSE) {
2100 GST_WARNING ("Could not parse caps: %" GST_PTR_FORMAT, caps);
2104 *size = gst_video_format_get_size (format, width, height);
2109 * gst_video_format_convert:
2110 * @format: a #GstVideoFormat
2111 * @width: the width of video
2112 * @height: the height of video
2113 * @fps_n: frame rate numerator
2114 * @fps_d: frame rate denominator
2115 * @src_format: #GstFormat of the @src_value
2116 * @src_value: value to convert
2117 * @dest_format: #GstFormat of the @dest_value
2118 * @dest_value: pointer to destination value
2120 * Converts among various #GstFormat types. This function handles
2121 * GST_FORMAT_BYTES, GST_FORMAT_TIME, and GST_FORMAT_DEFAULT. For
2122 * raw video, GST_FORMAT_DEFAULT corresponds to video frames. This
2123 * function can be to handle pad queries of the type GST_QUERY_CONVERT.
2127 * Returns: TRUE if the conversion was successful.
2130 gst_video_format_convert (GstVideoFormat format, int width, int height,
2131 int fps_n, int fps_d,
2132 GstFormat src_format, gint64 src_value,
2133 GstFormat dest_format, gint64 * dest_value)
2135 gboolean ret = FALSE;
2138 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
2139 g_return_val_if_fail (width > 0 && height > 0, 0);
2141 size = gst_video_format_get_size (format, width, height);
2143 GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
2144 src_value, gst_format_get_name (src_format),
2145 gst_format_get_name (dest_format));
2147 if (src_format == dest_format) {
2148 *dest_value = src_value;
2153 if (src_value == -1) {
2159 /* bytes to frames */
2160 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_DEFAULT) {
2162 *dest_value = gst_util_uint64_scale_int (src_value, 1, size);
2164 GST_ERROR ("blocksize is 0");
2171 /* frames to bytes */
2172 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_BYTES) {
2173 *dest_value = gst_util_uint64_scale_int (src_value, size, 1);
2178 /* time to frames */
2179 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_DEFAULT) {
2181 *dest_value = gst_util_uint64_scale (src_value,
2182 fps_n, GST_SECOND * fps_d);
2184 GST_ERROR ("framerate denominator is 0");
2191 /* frames to time */
2192 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_TIME) {
2194 *dest_value = gst_util_uint64_scale (src_value,
2195 GST_SECOND * fps_d, fps_n);
2197 GST_ERROR ("framerate numerator is 0");
2205 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
2207 *dest_value = gst_util_uint64_scale (src_value,
2208 fps_n * size, GST_SECOND * fps_d);
2210 GST_ERROR ("framerate denominator is 0");
2218 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_TIME) {
2219 if (fps_n != 0 && size != 0) {
2220 *dest_value = gst_util_uint64_scale (src_value,
2221 GST_SECOND * fps_d, fps_n * size);
2223 GST_ERROR ("framerate denominator and/or blocksize is 0");
2231 GST_DEBUG ("ret=%d result %" G_GINT64_FORMAT, ret, *dest_value);
2236 #define GST_VIDEO_EVENT_STILL_STATE_NAME "GstEventStillFrame"
2239 * gst_video_event_new_still_frame:
2240 * @in_still: boolean value for the still-frame state of the event.
2242 * Creates a new Still Frame event. If @in_still is %TRUE, then the event
2243 * represents the start of a still frame sequence. If it is %FALSE, then
2244 * the event ends a still frame sequence.
2246 * To parse an event created by gst_video_event_new_still_frame() use
2247 * gst_video_event_parse_still_frame().
2249 * Returns: The new GstEvent
2253 gst_video_event_new_still_frame (gboolean in_still)
2255 GstEvent *still_event;
2258 s = gst_structure_new (GST_VIDEO_EVENT_STILL_STATE_NAME,
2259 "still-state", G_TYPE_BOOLEAN, in_still, NULL);
2260 still_event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
2266 * gst_video_event_parse_still_frame:
2267 * @event: A #GstEvent to parse
2268 * @in_still: A boolean to receive the still-frame status from the event, or NULL
2270 * Parse a #GstEvent, identify if it is a Still Frame event, and
2271 * return the still-frame state from the event if it is.
2272 * If the event represents the start of a still frame, the in_still
2273 * variable will be set to TRUE, otherwise FALSE. It is OK to pass NULL for the
2274 * in_still variable order to just check whether the event is a valid still-frame
2277 * Create a still frame event using gst_video_event_new_still_frame()
2279 * Returns: %TRUE if the event is a valid still-frame event. %FALSE if not
2283 gst_video_event_parse_still_frame (GstEvent * event, gboolean * in_still)
2285 const GstStructure *s;
2286 gboolean ev_still_state;
2288 g_return_val_if_fail (event != NULL, FALSE);
2290 if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_DOWNSTREAM)
2291 return FALSE; /* Not a still frame event */
2293 s = gst_event_get_structure (event);
2295 || !gst_structure_has_name (s, GST_VIDEO_EVENT_STILL_STATE_NAME))
2296 return FALSE; /* Not a still frame event */
2297 if (!gst_structure_get_boolean (s, "still-state", &ev_still_state))
2298 return FALSE; /* Not a still frame event */
2300 *in_still = ev_still_state;
2305 * gst_video_parse_caps_palette:
2306 * @caps: #GstCaps to parse
2308 * Returns the palette data from the caps as a #GstBuffer. For
2309 * #GST_VIDEO_FORMAT_RGB8_PALETTED this is containing 256 #guint32
2310 * values, each containing ARGB colors in native endianness.
2312 * Returns: a #GstBuffer containing the palette data. Unref after usage.
2316 gst_video_parse_caps_palette (GstCaps * caps)
2322 if (!gst_caps_is_fixed (caps))
2325 s = gst_caps_get_structure (caps, 0);
2327 p_v = gst_structure_get_value (s, "palette_data");
2328 if (!p_v || !GST_VALUE_HOLDS_BUFFER (p_v))
2331 p = gst_buffer_ref (gst_value_get_buffer (p_v));
2336 #define GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME "GstForceKeyUnit"
2339 * gst_video_event_new_downstream_force_key_unit:
2340 * @timestamp: the timestamp of the buffer that starts a new key unit
2341 * @stream_time: the stream_time of the buffer that starts a new key unit
2342 * @running_time: the running_time of the buffer that starts a new key unit
2343 * @all_headers: %TRUE to produce headers when starting a new key unit
2344 * @count: integer that can be used to number key units
2346 * Creates a new downstream force key unit event. A downstream force key unit
2347 * event can be sent down the pipeline to request downstream elements to produce
2348 * a key unit. A downstream force key unit event must also be sent when handling
2349 * an upstream force key unit event to notify downstream that the latter has been
2352 * To parse an event created by gst_video_event_new_downstream_force_key_unit() use
2353 * gst_video_event_parse_downstream_force_key_unit().
2355 * Returns: The new GstEvent
2359 gst_video_event_new_downstream_force_key_unit (GstClockTime timestamp,
2360 GstClockTime stream_time, GstClockTime running_time, gboolean all_headers,
2363 GstEvent *force_key_unit_event;
2366 s = gst_structure_new (GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME,
2367 "timestamp", G_TYPE_UINT64, timestamp,
2368 "stream-time", G_TYPE_UINT64, stream_time,
2369 "running-time", G_TYPE_UINT64, running_time,
2370 "all-headers", G_TYPE_BOOLEAN, all_headers,
2371 "count", G_TYPE_UINT, count, NULL);
2372 force_key_unit_event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
2374 return force_key_unit_event;
2378 * gst_video_event_new_upstream_force_key_unit:
2379 * @running_time: the running_time at which a new key unit should be produced
2380 * @all_headers: %TRUE to produce headers when starting a new key unit
2381 * @count: integer that can be used to number key units
2383 * Creates a new upstream force key unit event. An upstream force key unit event
2384 * can be sent to request upstream elements to produce a key unit.
2386 * @running_time can be set to request a new key unit at a specific
2387 * running_time. If set to GST_CLOCK_TIME_NONE, upstream elements will produce a
2388 * new key unit as soon as possible.
2390 * To parse an event created by gst_video_event_new_downstream_force_key_unit() use
2391 * gst_video_event_parse_downstream_force_key_unit().
2393 * Returns: The new GstEvent
2397 gst_video_event_new_upstream_force_key_unit (GstClockTime running_time,
2398 gboolean all_headers, guint count)
2400 GstEvent *force_key_unit_event;
2403 s = gst_structure_new (GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME,
2404 "running-time", GST_TYPE_CLOCK_TIME, running_time,
2405 "all-headers", G_TYPE_BOOLEAN, all_headers,
2406 "count", G_TYPE_UINT, count, NULL);
2407 force_key_unit_event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM, s);
2409 return force_key_unit_event;
2413 * gst_video_event_is_force_key_unit:
2414 * @event: A #GstEvent to check
2416 * Checks if an event is a force key unit event. Returns true for both upstream
2417 * and downstream force key unit events.
2419 * Returns: %TRUE if the event is a valid force key unit event
2423 gst_video_event_is_force_key_unit (GstEvent * event)
2425 const GstStructure *s;
2427 g_return_val_if_fail (event != NULL, FALSE);
2429 if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_DOWNSTREAM &&
2430 GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_UPSTREAM)
2431 return FALSE; /* Not a force key unit event */
2433 s = gst_event_get_structure (event);
2435 || !gst_structure_has_name (s, GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME))
2442 * gst_video_event_parse_downstream_force_key_unit:
2443 * @event: A #GstEvent to parse
2444 * @timestamp: (out): A pointer to the timestamp in the event
2445 * @stream_time: (out): A pointer to the stream-time in the event
2446 * @running_time: (out): A pointer to the running-time in the event
2447 * @all_headers: (out): A pointer to the all_headers flag in the event
2448 * @count: (out): A pointer to the count field of the event
2450 * Get timestamp, stream-time, running-time, all-headers and count in the force
2451 * key unit event. See gst_video_event_new_downstream_force_key_unit() for a
2452 * full description of the downstream force key unit event.
2454 * Returns: %TRUE if the event is a valid downstream force key unit event.
2458 gst_video_event_parse_downstream_force_key_unit (GstEvent * event,
2459 GstClockTime * timestamp, GstClockTime * stream_time,
2460 GstClockTime * running_time, gboolean * all_headers, guint * count)
2462 const GstStructure *s;
2463 GstClockTime ev_timestamp, ev_stream_time, ev_running_time;
2464 gboolean ev_all_headers;
2467 g_return_val_if_fail (event != NULL, FALSE);
2469 if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_DOWNSTREAM)
2470 return FALSE; /* Not a force key unit event */
2472 s = gst_event_get_structure (event);
2474 || !gst_structure_has_name (s, GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME))
2477 if (!gst_structure_get_clock_time (s, "timestamp", &ev_timestamp))
2478 return FALSE; /* Not a force key unit event */
2479 if (!gst_structure_get_clock_time (s, "stream-time", &ev_stream_time))
2480 return FALSE; /* Not a force key unit event */
2481 if (!gst_structure_get_clock_time (s, "running-time", &ev_running_time))
2482 return FALSE; /* Not a force key unit event */
2483 if (!gst_structure_get_boolean (s, "all-headers", &ev_all_headers))
2484 return FALSE; /* Not a force key unit event */
2485 if (!gst_structure_get_uint (s, "count", &ev_count))
2486 return FALSE; /* Not a force key unit event */
2489 *timestamp = ev_timestamp;
2492 *stream_time = ev_stream_time;
2495 *running_time = ev_running_time;
2498 *all_headers = ev_all_headers;
2507 * gst_video_event_parse_upstream_force_key_unit:
2508 * @event: A #GstEvent to parse
2509 * @running_time: (out): A pointer to the running_time in the event
2510 * @all_headers: (out): A pointer to the all_headers flag in the event
2511 * @count: (out): A pointer to the count field in the event
2513 * Get running-time, all-headers and count in the force key unit event. See
2514 * gst_video_event_new_upstream_force_key_unit() for a full description of the
2515 * upstream force key unit event.
2517 * Create an upstream force key unit event using gst_video_event_new_upstream_force_key_unit()
2519 * Returns: %TRUE if the event is a valid upstream force-key-unit event. %FALSE if not
2523 gst_video_event_parse_upstream_force_key_unit (GstEvent * event,
2524 GstClockTime * running_time, gboolean * all_headers, guint * count)
2526 const GstStructure *s;
2527 GstClockTime ev_running_time;
2528 gboolean ev_all_headers;
2531 g_return_val_if_fail (event != NULL, FALSE);
2533 if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_UPSTREAM)
2534 return FALSE; /* Not a force key unit event */
2536 s = gst_event_get_structure (event);
2538 || !gst_structure_has_name (s, GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME))
2541 if (!gst_structure_get_clock_time (s, "running-time", &ev_running_time))
2542 return FALSE; /* Not a force key unit event */
2543 if (!gst_structure_get_boolean (s, "all-headers", &ev_all_headers))
2544 return FALSE; /* Not a force key unit event */
2545 if (!gst_structure_get_uint (s, "count", &ev_count))
2546 return FALSE; /* Not a force key unit event */
2549 *running_time = ev_running_time;
2552 *all_headers = ev_all_headers;