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);
361 ok &= gst_structure_get_int (structure, "endianness", &endianness);
362 ok &= gst_structure_get_int (structure, "red_mask", &red_mask);
363 ok &= gst_structure_get_int (structure, "green_mask", &green_mask);
364 ok &= gst_structure_get_int (structure, "blue_mask", &blue_mask);
365 have_alpha = gst_structure_get_int (structure, "alpha_mask", &alpha_mask);
367 if (depth == 24 && bpp == 32 && endianness == G_BIG_ENDIAN) {
368 *format = gst_video_format_from_rgb32_masks (red_mask, green_mask,
370 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
373 } else if (depth == 32 && bpp == 32 && endianness == G_BIG_ENDIAN &&
375 *format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
376 blue_mask, alpha_mask);
377 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
380 } else if (depth == 24 && bpp == 24 && endianness == G_BIG_ENDIAN) {
381 *format = gst_video_format_from_rgb24_masks (red_mask, green_mask,
383 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
386 } else if ((depth == 15 || depth == 16) && bpp == 16 &&
387 endianness == G_BYTE_ORDER) {
388 *format = gst_video_format_from_rgb16_masks (red_mask, green_mask,
390 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
396 } else if (gst_structure_has_name (structure, "video/x-raw-gray")) {
401 ok &= gst_structure_get_int (structure, "depth", &depth);
402 ok &= gst_structure_get_int (structure, "bpp", &bpp);
405 ok &= gst_structure_get_int (structure, "endianness", &endianness);
407 if (depth == 8 && bpp == 8) {
408 *format = GST_VIDEO_FORMAT_GRAY8;
409 } else if (depth == 16 && bpp == 16 && endianness == G_BIG_ENDIAN) {
410 *format = GST_VIDEO_FORMAT_GRAY16_BE;
411 } else if (depth == 16 && bpp == 16 && endianness == G_LITTLE_ENDIAN) {
412 *format = GST_VIDEO_FORMAT_GRAY16_LE;
422 ok &= gst_structure_get_int (structure, "width", width);
426 ok &= gst_structure_get_int (structure, "height", height);
434 * gst_video_parse_caps_framerate:
435 * @caps: pointer to a #GstCaps instance
436 * @fps_n: pointer to integer to hold numerator of frame rate (output)
437 * @fps_d: pointer to integer to hold denominator of frame rate (output)
439 * Extracts the frame rate from @caps and places the values in the locations
440 * pointed to by @fps_n and @fps_d. Returns TRUE if the values could be
441 * parsed correctly, FALSE if not.
443 * This function can be used with #GstCaps that have any media type; it
444 * is not limited to formats handled by #GstVideoFormat.
448 * Returns: TRUE if @caps was parsed correctly.
451 gst_video_parse_caps_framerate (GstCaps * caps, int *fps_n, int *fps_d)
453 GstStructure *structure;
455 if (!gst_caps_is_fixed (caps))
458 structure = gst_caps_get_structure (caps, 0);
460 return gst_structure_get_fraction (structure, "framerate", fps_n, fps_d);
464 * gst_video_parse_caps_pixel_aspect_ratio:
465 * @caps: pointer to a #GstCaps instance
466 * @par_n: pointer to numerator of pixel aspect ratio (output)
467 * @par_d: pointer to denominator of pixel aspect ratio (output)
469 * Extracts the pixel aspect ratio from @caps and places the values in
470 * the locations pointed to by @par_n and @par_d. Returns TRUE if the
471 * values could be parsed correctly, FALSE if not.
473 * This function can be used with #GstCaps that have any media type; it
474 * is not limited to formats handled by #GstVideoFormat.
478 * Returns: TRUE if @caps was parsed correctly.
481 gst_video_parse_caps_pixel_aspect_ratio (GstCaps * caps, int *par_n, int *par_d)
483 GstStructure *structure;
485 if (!gst_caps_is_fixed (caps))
488 structure = gst_caps_get_structure (caps, 0);
490 if (!gst_structure_get_fraction (structure, "pixel-aspect-ratio",
499 * gst_video_format_new_caps_interlaced:
500 * @format: the #GstVideoFormat describing the raw video format
501 * @width: width of video
502 * @height: height of video
503 * @framerate_n: numerator of frame rate
504 * @framerate_d: denominator of frame rate
505 * @par_n: numerator of pixel aspect ratio
506 * @par_d: denominator of pixel aspect ratio
507 * @interlaced: #TRUE if the format is interlaced
509 * Creates a new #GstCaps object based on the parameters provided.
513 * Returns: a new #GstCaps object, or NULL if there was an error
516 gst_video_format_new_caps_interlaced (GstVideoFormat format,
517 int width, int height, int framerate_n, int framerate_d, int par_n,
518 int par_d, gboolean interlaced)
523 gst_video_format_new_caps (format, width, height, framerate_n,
524 framerate_d, par_n, par_d);
525 if (interlaced && (res != NULL))
526 gst_caps_set_simple (res, "interlaced", G_TYPE_BOOLEAN, TRUE, NULL);
532 * gst_video_format_new_caps:
533 * @format: the #GstVideoFormat describing the raw video format
534 * @width: width of video
535 * @height: height of video
536 * @framerate_n: numerator of frame rate
537 * @framerate_d: denominator of frame rate
538 * @par_n: numerator of pixel aspect ratio
539 * @par_d: denominator of pixel aspect ratio
541 * Creates a new #GstCaps object based on the parameters provided.
545 * Returns: a new #GstCaps object, or NULL if there was an error
548 gst_video_format_new_caps (GstVideoFormat format, int width,
549 int height, int framerate_n, int framerate_d, int par_n, int par_d)
551 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
552 g_return_val_if_fail (width > 0 && height > 0, NULL);
554 if (gst_video_format_is_yuv (format)) {
555 return gst_caps_new_simple ("video/x-raw-yuv",
556 "format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format),
557 "width", G_TYPE_INT, width,
558 "height", G_TYPE_INT, height,
559 "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
560 "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
562 if (gst_video_format_is_rgb (format)) {
571 unsigned int mask = 0;
574 case GST_VIDEO_FORMAT_RGBx:
575 case GST_VIDEO_FORMAT_BGRx:
576 case GST_VIDEO_FORMAT_xRGB:
577 case GST_VIDEO_FORMAT_xBGR:
582 case GST_VIDEO_FORMAT_RGBA:
583 case GST_VIDEO_FORMAT_BGRA:
584 case GST_VIDEO_FORMAT_ARGB:
585 case GST_VIDEO_FORMAT_ABGR:
590 case GST_VIDEO_FORMAT_RGB:
591 case GST_VIDEO_FORMAT_BGR:
596 case GST_VIDEO_FORMAT_RGB16:
597 case GST_VIDEO_FORMAT_BGR16:
602 case GST_VIDEO_FORMAT_RGB15:
603 case GST_VIDEO_FORMAT_BGR15:
611 if (bpp == 32 || bpp == 24) {
618 mask >> (8 * gst_video_format_get_component_offset (format, 0,
621 mask >> (8 * gst_video_format_get_component_offset (format, 1,
624 mask >> (8 * gst_video_format_get_component_offset (format, 2,
626 } else if (bpp == 16) {
628 case GST_VIDEO_FORMAT_RGB16:
629 red_mask = GST_VIDEO_COMP1_MASK_16_INT;
630 green_mask = GST_VIDEO_COMP2_MASK_16_INT;
631 blue_mask = GST_VIDEO_COMP3_MASK_16_INT;
633 case GST_VIDEO_FORMAT_BGR16:
634 red_mask = GST_VIDEO_COMP3_MASK_16_INT;
635 green_mask = GST_VIDEO_COMP2_MASK_16_INT;
636 blue_mask = GST_VIDEO_COMP1_MASK_16_INT;
639 case GST_VIDEO_FORMAT_RGB15:
640 red_mask = GST_VIDEO_COMP1_MASK_15_INT;
641 green_mask = GST_VIDEO_COMP2_MASK_15_INT;
642 blue_mask = GST_VIDEO_COMP3_MASK_15_INT;
644 case GST_VIDEO_FORMAT_BGR15:
645 red_mask = GST_VIDEO_COMP3_MASK_15_INT;
646 green_mask = GST_VIDEO_COMP2_MASK_15_INT;
647 blue_mask = GST_VIDEO_COMP1_MASK_15_INT;
656 caps = gst_caps_new_simple ("video/x-raw-rgb",
657 "bpp", G_TYPE_INT, bpp,
658 "depth", G_TYPE_INT, depth,
659 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
660 "red_mask", G_TYPE_INT, red_mask,
661 "green_mask", G_TYPE_INT, green_mask,
662 "blue_mask", G_TYPE_INT, blue_mask,
663 "width", G_TYPE_INT, width,
664 "height", G_TYPE_INT, height,
665 "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
666 "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
669 mask >> (8 * gst_video_format_get_component_offset (format, 3,
671 gst_caps_set_simple (caps, "alpha_mask", G_TYPE_INT, alpha_mask, NULL);
676 if (gst_video_format_is_gray (format)) {
683 case GST_VIDEO_FORMAT_GRAY8:
685 endianness = G_BIG_ENDIAN;
687 case GST_VIDEO_FORMAT_GRAY16_BE:
689 endianness = G_BIG_ENDIAN;
691 case GST_VIDEO_FORMAT_GRAY16_LE:
693 endianness = G_LITTLE_ENDIAN;
701 caps = gst_caps_new_simple ("video/x-raw-gray",
702 "bpp", G_TYPE_INT, bpp,
703 "depth", G_TYPE_INT, depth,
704 "width", G_TYPE_INT, width,
705 "height", G_TYPE_INT, height,
706 "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
707 "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
709 caps = gst_caps_new_simple ("video/x-raw-gray",
710 "bpp", G_TYPE_INT, bpp,
711 "depth", G_TYPE_INT, depth,
712 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
713 "width", G_TYPE_INT, width,
714 "height", G_TYPE_INT, height,
715 "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
716 "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
726 * gst_video_format_from_fourcc:
727 * @fourcc: a FOURCC value representing raw YUV video
729 * Converts a FOURCC value into the corresponding #GstVideoFormat.
730 * If the FOURCC cannot be represented by #GstVideoFormat,
731 * #GST_VIDEO_FORMAT_UNKNOWN is returned.
735 * Returns: the #GstVideoFormat describing the FOURCC value
738 gst_video_format_from_fourcc (guint32 fourcc)
741 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
742 return GST_VIDEO_FORMAT_I420;
743 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
744 return GST_VIDEO_FORMAT_YV12;
745 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
746 return GST_VIDEO_FORMAT_YUY2;
747 case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'):
748 return GST_VIDEO_FORMAT_YVYU;
749 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
750 return GST_VIDEO_FORMAT_UYVY;
751 case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
752 return GST_VIDEO_FORMAT_AYUV;
753 case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
754 return GST_VIDEO_FORMAT_Y41B;
755 case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
756 return GST_VIDEO_FORMAT_Y42B;
757 case GST_MAKE_FOURCC ('Y', '4', '4', '4'):
758 return GST_VIDEO_FORMAT_Y444;
759 case GST_MAKE_FOURCC ('v', '2', '1', '0'):
760 return GST_VIDEO_FORMAT_v210;
761 case GST_MAKE_FOURCC ('v', '2', '1', '6'):
762 return GST_VIDEO_FORMAT_v216;
763 case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
764 return GST_VIDEO_FORMAT_NV12;
765 case GST_MAKE_FOURCC ('N', 'V', '2', '1'):
766 return GST_VIDEO_FORMAT_NV21;
767 case GST_MAKE_FOURCC ('v', '3', '0', '8'):
768 return GST_VIDEO_FORMAT_v308;
769 case GST_MAKE_FOURCC ('Y', '8', '0', '0'):
770 case GST_MAKE_FOURCC ('Y', '8', ' ', ' '):
771 case GST_MAKE_FOURCC ('G', 'R', 'E', 'Y'):
772 return GST_VIDEO_FORMAT_Y800;
773 case GST_MAKE_FOURCC ('Y', '1', '6', ' '):
774 return GST_VIDEO_FORMAT_Y16;
775 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'P'):
776 return GST_VIDEO_FORMAT_UYVP;
778 return GST_VIDEO_FORMAT_UNKNOWN;
783 * gst_video_format_to_fourcc:
784 * @format: a #GstVideoFormat video format
786 * Converts a #GstVideoFormat value into the corresponding FOURCC. Only
787 * a few YUV formats have corresponding FOURCC values. If @format has
788 * no corresponding FOURCC value, 0 is returned.
792 * Returns: the FOURCC corresponding to @format
795 gst_video_format_to_fourcc (GstVideoFormat format)
797 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
800 case GST_VIDEO_FORMAT_I420:
801 return GST_MAKE_FOURCC ('I', '4', '2', '0');
802 case GST_VIDEO_FORMAT_YV12:
803 return GST_MAKE_FOURCC ('Y', 'V', '1', '2');
804 case GST_VIDEO_FORMAT_YUY2:
805 return GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
806 case GST_VIDEO_FORMAT_YVYU:
807 return GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U');
808 case GST_VIDEO_FORMAT_UYVY:
809 return GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
810 case GST_VIDEO_FORMAT_AYUV:
811 return GST_MAKE_FOURCC ('A', 'Y', 'U', 'V');
812 case GST_VIDEO_FORMAT_Y41B:
813 return GST_MAKE_FOURCC ('Y', '4', '1', 'B');
814 case GST_VIDEO_FORMAT_Y42B:
815 return GST_MAKE_FOURCC ('Y', '4', '2', 'B');
816 case GST_VIDEO_FORMAT_Y444:
817 return GST_MAKE_FOURCC ('Y', '4', '4', '4');
818 case GST_VIDEO_FORMAT_v210:
819 return GST_MAKE_FOURCC ('v', '2', '1', '0');
820 case GST_VIDEO_FORMAT_v216:
821 return GST_MAKE_FOURCC ('v', '2', '1', '6');
822 case GST_VIDEO_FORMAT_NV12:
823 return GST_MAKE_FOURCC ('N', 'V', '1', '2');
824 case GST_VIDEO_FORMAT_NV21:
825 return GST_MAKE_FOURCC ('N', 'V', '2', '1');
826 case GST_VIDEO_FORMAT_v308:
827 return GST_MAKE_FOURCC ('v', '3', '0', '8');
828 case GST_VIDEO_FORMAT_Y800:
829 return GST_MAKE_FOURCC ('Y', '8', '0', '0');
830 case GST_VIDEO_FORMAT_Y16:
831 return GST_MAKE_FOURCC ('Y', '1', '6', ' ');
832 case GST_VIDEO_FORMAT_UYVP:
833 return GST_MAKE_FOURCC ('U', 'Y', 'V', 'P');
840 * gst_video_format_from_rgb32_masks:
841 * @red_mask: red bit mask
842 * @green_mask: green bit mask
843 * @blue_mask: blue bit mask
845 * Converts red, green, blue bit masks into the corresponding
850 * Returns: the #GstVideoFormat corresponding to the bit masks
852 static GstVideoFormat
853 gst_video_format_from_rgb32_masks (int red_mask, int green_mask, int blue_mask)
855 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
856 blue_mask == 0x0000ff00) {
857 return GST_VIDEO_FORMAT_RGBx;
859 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
860 blue_mask == 0xff000000) {
861 return GST_VIDEO_FORMAT_BGRx;
863 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
864 blue_mask == 0x000000ff) {
865 return GST_VIDEO_FORMAT_xRGB;
867 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
868 blue_mask == 0x00ff0000) {
869 return GST_VIDEO_FORMAT_xBGR;
872 return GST_VIDEO_FORMAT_UNKNOWN;
875 static GstVideoFormat
876 gst_video_format_from_rgba32_masks (int red_mask, int green_mask,
877 int blue_mask, int alpha_mask)
879 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
880 blue_mask == 0x0000ff00 && alpha_mask == 0x000000ff) {
881 return GST_VIDEO_FORMAT_RGBA;
883 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
884 blue_mask == 0xff000000 && alpha_mask == 0x000000ff) {
885 return GST_VIDEO_FORMAT_BGRA;
887 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
888 blue_mask == 0x000000ff && alpha_mask == 0xff000000) {
889 return GST_VIDEO_FORMAT_ARGB;
891 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
892 blue_mask == 0x00ff0000 && alpha_mask == 0xff000000) {
893 return GST_VIDEO_FORMAT_ABGR;
896 return GST_VIDEO_FORMAT_UNKNOWN;
899 static GstVideoFormat
900 gst_video_format_from_rgb24_masks (int red_mask, int green_mask, int blue_mask)
902 if (red_mask == 0xff0000 && green_mask == 0x00ff00 && blue_mask == 0x0000ff) {
903 return GST_VIDEO_FORMAT_RGB;
905 if (red_mask == 0x0000ff && green_mask == 0x00ff00 && blue_mask == 0xff0000) {
906 return GST_VIDEO_FORMAT_BGR;
909 return GST_VIDEO_FORMAT_UNKNOWN;
912 static GstVideoFormat
913 gst_video_format_from_rgb16_masks (int red_mask, int green_mask, int blue_mask)
915 if (red_mask == GST_VIDEO_COMP1_MASK_16_INT
916 && green_mask == GST_VIDEO_COMP2_MASK_16_INT
917 && blue_mask == GST_VIDEO_COMP3_MASK_16_INT) {
918 return GST_VIDEO_FORMAT_RGB16;
920 if (red_mask == GST_VIDEO_COMP3_MASK_16_INT
921 && green_mask == GST_VIDEO_COMP2_MASK_16_INT
922 && blue_mask == GST_VIDEO_COMP1_MASK_16_INT) {
923 return GST_VIDEO_FORMAT_BGR16;
925 if (red_mask == GST_VIDEO_COMP1_MASK_15_INT
926 && green_mask == GST_VIDEO_COMP2_MASK_15_INT
927 && blue_mask == GST_VIDEO_COMP3_MASK_15_INT) {
928 return GST_VIDEO_FORMAT_RGB15;
930 if (red_mask == GST_VIDEO_COMP3_MASK_15_INT
931 && green_mask == GST_VIDEO_COMP2_MASK_15_INT
932 && blue_mask == GST_VIDEO_COMP1_MASK_15_INT) {
933 return GST_VIDEO_FORMAT_BGR15;
936 return GST_VIDEO_FORMAT_UNKNOWN;
940 * gst_video_format_is_rgb:
941 * @format: a #GstVideoFormat
943 * Determine whether the video format is an RGB format.
947 * Returns: TRUE if @format represents RGB video
950 gst_video_format_is_rgb (GstVideoFormat format)
953 case GST_VIDEO_FORMAT_I420:
954 case GST_VIDEO_FORMAT_YV12:
955 case GST_VIDEO_FORMAT_YUY2:
956 case GST_VIDEO_FORMAT_YVYU:
957 case GST_VIDEO_FORMAT_UYVY:
958 case GST_VIDEO_FORMAT_AYUV:
959 case GST_VIDEO_FORMAT_Y41B:
960 case GST_VIDEO_FORMAT_Y42B:
961 case GST_VIDEO_FORMAT_Y444:
962 case GST_VIDEO_FORMAT_v210:
963 case GST_VIDEO_FORMAT_v216:
964 case GST_VIDEO_FORMAT_NV12:
965 case GST_VIDEO_FORMAT_NV21:
966 case GST_VIDEO_FORMAT_v308:
967 case GST_VIDEO_FORMAT_UYVP:
969 case GST_VIDEO_FORMAT_RGBx:
970 case GST_VIDEO_FORMAT_BGRx:
971 case GST_VIDEO_FORMAT_xRGB:
972 case GST_VIDEO_FORMAT_xBGR:
973 case GST_VIDEO_FORMAT_RGBA:
974 case GST_VIDEO_FORMAT_BGRA:
975 case GST_VIDEO_FORMAT_ARGB:
976 case GST_VIDEO_FORMAT_ABGR:
977 case GST_VIDEO_FORMAT_RGB:
978 case GST_VIDEO_FORMAT_BGR:
979 case GST_VIDEO_FORMAT_RGB16:
980 case GST_VIDEO_FORMAT_BGR16:
981 case GST_VIDEO_FORMAT_RGB15:
982 case GST_VIDEO_FORMAT_BGR15:
990 * gst_video_format_is_yuv:
991 * @format: a #GstVideoFormat
993 * Determine whether the video format is a YUV format.
997 * Returns: TRUE if @format represents YUV video
1000 gst_video_format_is_yuv (GstVideoFormat format)
1003 case GST_VIDEO_FORMAT_I420:
1004 case GST_VIDEO_FORMAT_YV12:
1005 case GST_VIDEO_FORMAT_YUY2:
1006 case GST_VIDEO_FORMAT_YVYU:
1007 case GST_VIDEO_FORMAT_UYVY:
1008 case GST_VIDEO_FORMAT_AYUV:
1009 case GST_VIDEO_FORMAT_Y41B:
1010 case GST_VIDEO_FORMAT_Y42B:
1011 case GST_VIDEO_FORMAT_Y444:
1012 case GST_VIDEO_FORMAT_v210:
1013 case GST_VIDEO_FORMAT_v216:
1014 case GST_VIDEO_FORMAT_NV12:
1015 case GST_VIDEO_FORMAT_NV21:
1016 case GST_VIDEO_FORMAT_v308:
1017 case GST_VIDEO_FORMAT_Y800:
1018 case GST_VIDEO_FORMAT_Y16:
1019 case GST_VIDEO_FORMAT_UYVP:
1021 case GST_VIDEO_FORMAT_RGBx:
1022 case GST_VIDEO_FORMAT_BGRx:
1023 case GST_VIDEO_FORMAT_xRGB:
1024 case GST_VIDEO_FORMAT_xBGR:
1025 case GST_VIDEO_FORMAT_RGBA:
1026 case GST_VIDEO_FORMAT_BGRA:
1027 case GST_VIDEO_FORMAT_ARGB:
1028 case GST_VIDEO_FORMAT_ABGR:
1029 case GST_VIDEO_FORMAT_RGB:
1030 case GST_VIDEO_FORMAT_BGR:
1031 case GST_VIDEO_FORMAT_RGB16:
1032 case GST_VIDEO_FORMAT_BGR16:
1033 case GST_VIDEO_FORMAT_RGB15:
1034 case GST_VIDEO_FORMAT_BGR15:
1042 * gst_video_format_is_gray:
1043 * @format: a #GstVideoFormat
1045 * Determine whether the video format is a grayscale format.
1049 * Returns: TRUE if @format represents grayscale video
1052 gst_video_format_is_gray (GstVideoFormat format)
1055 case GST_VIDEO_FORMAT_GRAY8:
1056 case GST_VIDEO_FORMAT_GRAY16_BE:
1057 case GST_VIDEO_FORMAT_GRAY16_LE:
1058 case GST_VIDEO_FORMAT_Y800:
1059 case GST_VIDEO_FORMAT_Y16:
1067 * gst_video_format_has_alpha:
1068 * @format: a #GstVideoFormat
1070 * Returns TRUE or FALSE depending on if the video format provides an
1075 * Returns: TRUE if @format has an alpha channel
1078 gst_video_format_has_alpha (GstVideoFormat format)
1081 case GST_VIDEO_FORMAT_I420:
1082 case GST_VIDEO_FORMAT_YV12:
1083 case GST_VIDEO_FORMAT_YUY2:
1084 case GST_VIDEO_FORMAT_YVYU:
1085 case GST_VIDEO_FORMAT_UYVY:
1086 case GST_VIDEO_FORMAT_Y41B:
1087 case GST_VIDEO_FORMAT_Y42B:
1088 case GST_VIDEO_FORMAT_Y444:
1089 case GST_VIDEO_FORMAT_v210:
1090 case GST_VIDEO_FORMAT_v216:
1091 case GST_VIDEO_FORMAT_NV12:
1092 case GST_VIDEO_FORMAT_NV21:
1093 case GST_VIDEO_FORMAT_v308:
1094 case GST_VIDEO_FORMAT_Y800:
1095 case GST_VIDEO_FORMAT_Y16:
1096 case GST_VIDEO_FORMAT_UYVP:
1098 case GST_VIDEO_FORMAT_AYUV:
1099 case GST_VIDEO_FORMAT_RGBA:
1100 case GST_VIDEO_FORMAT_BGRA:
1101 case GST_VIDEO_FORMAT_ARGB:
1102 case GST_VIDEO_FORMAT_ABGR:
1104 case GST_VIDEO_FORMAT_RGBx:
1105 case GST_VIDEO_FORMAT_BGRx:
1106 case GST_VIDEO_FORMAT_xRGB:
1107 case GST_VIDEO_FORMAT_xBGR:
1108 case GST_VIDEO_FORMAT_RGB:
1109 case GST_VIDEO_FORMAT_BGR:
1110 case GST_VIDEO_FORMAT_RGB16:
1111 case GST_VIDEO_FORMAT_BGR16:
1112 case GST_VIDEO_FORMAT_RGB15:
1113 case GST_VIDEO_FORMAT_BGR15:
1121 * gst_video_format_get_row_stride:
1122 * @format: a #GstVideoFormat
1123 * @component: the component index
1124 * @width: the width of video
1126 * Calculates the row stride (number of bytes from one row of pixels to
1127 * the next) for the video component with an index of @component. For
1128 * YUV video, Y, U, and V have component indices of 0, 1, and 2,
1129 * respectively. For RGB video, R, G, and B have component indicies of
1130 * 0, 1, and 2, respectively. Alpha channels, if present, have a component
1131 * index of 3. The @width parameter always represents the width of the
1132 * video, not the component.
1136 * Returns: row stride of component @component
1139 gst_video_format_get_row_stride (GstVideoFormat format, int component,
1142 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1143 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1144 g_return_val_if_fail (width > 0, 0);
1147 case GST_VIDEO_FORMAT_I420:
1148 case GST_VIDEO_FORMAT_YV12:
1149 if (component == 0) {
1150 return GST_ROUND_UP_4 (width);
1152 return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
1154 case GST_VIDEO_FORMAT_YUY2:
1155 case GST_VIDEO_FORMAT_YVYU:
1156 case GST_VIDEO_FORMAT_UYVY:
1157 return GST_ROUND_UP_4 (width * 2);
1158 case GST_VIDEO_FORMAT_AYUV:
1159 case GST_VIDEO_FORMAT_RGBx:
1160 case GST_VIDEO_FORMAT_BGRx:
1161 case GST_VIDEO_FORMAT_xRGB:
1162 case GST_VIDEO_FORMAT_xBGR:
1163 case GST_VIDEO_FORMAT_RGBA:
1164 case GST_VIDEO_FORMAT_BGRA:
1165 case GST_VIDEO_FORMAT_ARGB:
1166 case GST_VIDEO_FORMAT_ABGR:
1168 case GST_VIDEO_FORMAT_RGB16:
1169 case GST_VIDEO_FORMAT_BGR16:
1170 case GST_VIDEO_FORMAT_RGB15:
1171 case GST_VIDEO_FORMAT_BGR15:
1172 return GST_ROUND_UP_4 (width * 2);
1173 case GST_VIDEO_FORMAT_RGB:
1174 case GST_VIDEO_FORMAT_BGR:
1175 case GST_VIDEO_FORMAT_v308:
1176 return GST_ROUND_UP_4 (width * 3);
1177 case GST_VIDEO_FORMAT_Y41B:
1178 if (component == 0) {
1179 return GST_ROUND_UP_4 (width);
1181 return GST_ROUND_UP_16 (width) / 4;
1183 case GST_VIDEO_FORMAT_Y42B:
1184 if (component == 0) {
1185 return GST_ROUND_UP_4 (width);
1187 return GST_ROUND_UP_8 (width) / 2;
1189 case GST_VIDEO_FORMAT_Y444:
1190 return GST_ROUND_UP_4 (width);
1191 case GST_VIDEO_FORMAT_v210:
1192 return ((width + 47) / 48) * 128;
1193 case GST_VIDEO_FORMAT_v216:
1194 return GST_ROUND_UP_8 (width * 4);
1195 case GST_VIDEO_FORMAT_NV12:
1196 case GST_VIDEO_FORMAT_NV21:
1197 return GST_ROUND_UP_4 (width);
1198 case GST_VIDEO_FORMAT_GRAY8:
1199 case GST_VIDEO_FORMAT_Y800:
1200 return GST_ROUND_UP_4 (width);
1201 case GST_VIDEO_FORMAT_GRAY16_BE:
1202 case GST_VIDEO_FORMAT_GRAY16_LE:
1203 case GST_VIDEO_FORMAT_Y16:
1204 return GST_ROUND_UP_4 (width * 2);
1205 case GST_VIDEO_FORMAT_UYVP:
1206 return GST_ROUND_UP_4 ((width * 2 * 5 + 3) / 4);
1213 * gst_video_format_get_pixel_stride:
1214 * @format: a #GstVideoFormat
1215 * @component: the component index
1217 * Calculates the pixel stride (number of bytes from one pixel to the
1218 * pixel to its immediate left) for the video component with an index
1219 * of @component. See @gst_video_format_get_row_stride for a description
1220 * of the component index.
1224 * Returns: pixel stride of component @component
1227 gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
1229 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1230 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1233 case GST_VIDEO_FORMAT_I420:
1234 case GST_VIDEO_FORMAT_YV12:
1235 case GST_VIDEO_FORMAT_Y41B:
1236 case GST_VIDEO_FORMAT_Y42B:
1237 case GST_VIDEO_FORMAT_Y444:
1239 case GST_VIDEO_FORMAT_YUY2:
1240 case GST_VIDEO_FORMAT_YVYU:
1241 case GST_VIDEO_FORMAT_UYVY:
1242 if (component == 0) {
1247 case GST_VIDEO_FORMAT_AYUV:
1248 case GST_VIDEO_FORMAT_RGBx:
1249 case GST_VIDEO_FORMAT_BGRx:
1250 case GST_VIDEO_FORMAT_xRGB:
1251 case GST_VIDEO_FORMAT_xBGR:
1252 case GST_VIDEO_FORMAT_RGBA:
1253 case GST_VIDEO_FORMAT_BGRA:
1254 case GST_VIDEO_FORMAT_ARGB:
1255 case GST_VIDEO_FORMAT_ABGR:
1257 case GST_VIDEO_FORMAT_RGB16:
1258 case GST_VIDEO_FORMAT_BGR16:
1259 case GST_VIDEO_FORMAT_RGB15:
1260 case GST_VIDEO_FORMAT_BGR15:
1262 case GST_VIDEO_FORMAT_RGB:
1263 case GST_VIDEO_FORMAT_BGR:
1264 case GST_VIDEO_FORMAT_v308:
1266 case GST_VIDEO_FORMAT_v210:
1267 /* v210 is packed at the bit level, so pixel stride doesn't make sense */
1269 case GST_VIDEO_FORMAT_v216:
1270 if (component == 0) {
1275 case GST_VIDEO_FORMAT_NV12:
1276 case GST_VIDEO_FORMAT_NV21:
1277 if (component == 0) {
1282 case GST_VIDEO_FORMAT_GRAY8:
1283 case GST_VIDEO_FORMAT_Y800:
1285 case GST_VIDEO_FORMAT_GRAY16_BE:
1286 case GST_VIDEO_FORMAT_GRAY16_LE:
1287 case GST_VIDEO_FORMAT_Y16:
1289 case GST_VIDEO_FORMAT_UYVP:
1290 /* UYVP is packed at the bit level, so pixel stride doesn't make sense */
1298 * gst_video_format_get_component_width:
1299 * @format: a #GstVideoFormat
1300 * @component: the component index
1301 * @width: the width of video
1303 * Calculates the width of the component. See
1304 * @gst_video_format_get_row_stride for a description
1305 * of the component index.
1309 * Returns: width of component @component
1312 gst_video_format_get_component_width (GstVideoFormat format,
1313 int component, int width)
1315 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1316 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1317 g_return_val_if_fail (width > 0, 0);
1320 case GST_VIDEO_FORMAT_I420:
1321 case GST_VIDEO_FORMAT_YV12:
1322 case GST_VIDEO_FORMAT_YUY2:
1323 case GST_VIDEO_FORMAT_YVYU:
1324 case GST_VIDEO_FORMAT_UYVY:
1325 case GST_VIDEO_FORMAT_Y42B:
1326 case GST_VIDEO_FORMAT_v210:
1327 case GST_VIDEO_FORMAT_v216:
1328 case GST_VIDEO_FORMAT_NV12:
1329 case GST_VIDEO_FORMAT_NV21:
1330 case GST_VIDEO_FORMAT_UYVP:
1331 if (component == 0) {
1334 return GST_ROUND_UP_2 (width) / 2;
1336 case GST_VIDEO_FORMAT_Y41B:
1337 if (component == 0) {
1340 return GST_ROUND_UP_4 (width) / 4;
1342 case GST_VIDEO_FORMAT_AYUV:
1343 case GST_VIDEO_FORMAT_RGBx:
1344 case GST_VIDEO_FORMAT_BGRx:
1345 case GST_VIDEO_FORMAT_xRGB:
1346 case GST_VIDEO_FORMAT_xBGR:
1347 case GST_VIDEO_FORMAT_RGBA:
1348 case GST_VIDEO_FORMAT_BGRA:
1349 case GST_VIDEO_FORMAT_ARGB:
1350 case GST_VIDEO_FORMAT_ABGR:
1351 case GST_VIDEO_FORMAT_RGB:
1352 case GST_VIDEO_FORMAT_BGR:
1353 case GST_VIDEO_FORMAT_RGB16:
1354 case GST_VIDEO_FORMAT_BGR16:
1355 case GST_VIDEO_FORMAT_RGB15:
1356 case GST_VIDEO_FORMAT_BGR15:
1357 case GST_VIDEO_FORMAT_Y444:
1358 case GST_VIDEO_FORMAT_v308:
1359 case GST_VIDEO_FORMAT_GRAY8:
1360 case GST_VIDEO_FORMAT_GRAY16_BE:
1361 case GST_VIDEO_FORMAT_GRAY16_LE:
1362 case GST_VIDEO_FORMAT_Y800:
1363 case GST_VIDEO_FORMAT_Y16:
1371 * gst_video_format_get_component_height:
1372 * @format: a #GstVideoFormat
1373 * @component: the component index
1374 * @height: the height of video
1376 * Calculates the height of the component. See
1377 * @gst_video_format_get_row_stride for a description
1378 * of the component index.
1382 * Returns: height of component @component
1385 gst_video_format_get_component_height (GstVideoFormat format,
1386 int component, int height)
1388 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1389 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1390 g_return_val_if_fail (height > 0, 0);
1393 case GST_VIDEO_FORMAT_I420:
1394 case GST_VIDEO_FORMAT_YV12:
1395 case GST_VIDEO_FORMAT_NV12:
1396 case GST_VIDEO_FORMAT_NV21:
1397 if (component == 0) {
1400 return GST_ROUND_UP_2 (height) / 2;
1402 case GST_VIDEO_FORMAT_Y41B:
1403 case GST_VIDEO_FORMAT_Y42B:
1404 case GST_VIDEO_FORMAT_YUY2:
1405 case GST_VIDEO_FORMAT_YVYU:
1406 case GST_VIDEO_FORMAT_UYVY:
1407 case GST_VIDEO_FORMAT_AYUV:
1408 case GST_VIDEO_FORMAT_RGBx:
1409 case GST_VIDEO_FORMAT_BGRx:
1410 case GST_VIDEO_FORMAT_xRGB:
1411 case GST_VIDEO_FORMAT_xBGR:
1412 case GST_VIDEO_FORMAT_RGBA:
1413 case GST_VIDEO_FORMAT_BGRA:
1414 case GST_VIDEO_FORMAT_ARGB:
1415 case GST_VIDEO_FORMAT_ABGR:
1416 case GST_VIDEO_FORMAT_RGB:
1417 case GST_VIDEO_FORMAT_BGR:
1418 case GST_VIDEO_FORMAT_RGB16:
1419 case GST_VIDEO_FORMAT_BGR16:
1420 case GST_VIDEO_FORMAT_RGB15:
1421 case GST_VIDEO_FORMAT_BGR15:
1422 case GST_VIDEO_FORMAT_Y444:
1423 case GST_VIDEO_FORMAT_v210:
1424 case GST_VIDEO_FORMAT_v216:
1425 case GST_VIDEO_FORMAT_v308:
1426 case GST_VIDEO_FORMAT_GRAY8:
1427 case GST_VIDEO_FORMAT_GRAY16_BE:
1428 case GST_VIDEO_FORMAT_GRAY16_LE:
1429 case GST_VIDEO_FORMAT_Y800:
1430 case GST_VIDEO_FORMAT_Y16:
1431 case GST_VIDEO_FORMAT_UYVP:
1439 * gst_video_format_get_component_offset:
1440 * @format: a #GstVideoFormat
1441 * @component: the component index
1442 * @width: the width of video
1443 * @height: the height of video
1445 * Calculates the offset (in bytes) of the first pixel of the component
1446 * with index @component. For packed formats, this will typically be a
1447 * small integer (0, 1, 2, 3). For planar formats, this will be a
1448 * (relatively) large offset to the beginning of the second or third
1449 * component planes. See @gst_video_format_get_row_stride for a description
1450 * of the component index.
1454 * Returns: offset of component @component
1457 gst_video_format_get_component_offset (GstVideoFormat format,
1458 int component, int width, int height)
1460 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1461 g_return_val_if_fail (component >= 0 && component <= 3, 0);
1462 g_return_val_if_fail (width > 0 && height > 0, 0);
1465 case GST_VIDEO_FORMAT_I420:
1469 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1470 if (component == 2) {
1471 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1472 GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1473 (GST_ROUND_UP_2 (height) / 2);
1476 case GST_VIDEO_FORMAT_YV12: /* same as I420, but components 1+2 swapped */
1480 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1481 if (component == 1) {
1482 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
1483 GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1484 (GST_ROUND_UP_2 (height) / 2);
1487 case GST_VIDEO_FORMAT_YUY2:
1495 case GST_VIDEO_FORMAT_YVYU:
1503 case GST_VIDEO_FORMAT_UYVY:
1511 case GST_VIDEO_FORMAT_AYUV:
1521 case GST_VIDEO_FORMAT_RGBx:
1522 case GST_VIDEO_FORMAT_RGBA:
1532 case GST_VIDEO_FORMAT_BGRx:
1533 case GST_VIDEO_FORMAT_BGRA:
1543 case GST_VIDEO_FORMAT_xRGB:
1544 case GST_VIDEO_FORMAT_ARGB:
1554 case GST_VIDEO_FORMAT_xBGR:
1555 case GST_VIDEO_FORMAT_ABGR:
1565 case GST_VIDEO_FORMAT_RGB:
1566 case GST_VIDEO_FORMAT_v308:
1574 case GST_VIDEO_FORMAT_BGR:
1582 case GST_VIDEO_FORMAT_Y41B:
1586 return GST_ROUND_UP_4 (width) * height;
1588 return (GST_ROUND_UP_4 (width) +
1589 (GST_ROUND_UP_16 (width) / 4)) * height;
1591 case GST_VIDEO_FORMAT_Y42B:
1595 return GST_ROUND_UP_4 (width) * height;
1597 return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_8 (width) / 2)) * height;
1599 case GST_VIDEO_FORMAT_Y444:
1600 return GST_ROUND_UP_4 (width) * height * component;
1601 case GST_VIDEO_FORMAT_v210:
1602 /* v210 is bit-packed, so this doesn't make sense */
1604 case GST_VIDEO_FORMAT_v216:
1612 case GST_VIDEO_FORMAT_NV12:
1616 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1618 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) + 1;
1619 case GST_VIDEO_FORMAT_NV21:
1623 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) + 1;
1625 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1626 case GST_VIDEO_FORMAT_GRAY8:
1627 case GST_VIDEO_FORMAT_GRAY16_BE:
1628 case GST_VIDEO_FORMAT_GRAY16_LE:
1629 case GST_VIDEO_FORMAT_Y800:
1630 case GST_VIDEO_FORMAT_Y16:
1632 case GST_VIDEO_FORMAT_UYVP:
1633 /* UYVP is bit-packed, so this doesn't make sense */
1641 * gst_video_format_get_size:
1642 * @format: a #GstVideoFormat
1643 * @width: the width of video
1644 * @height: the height of video
1646 * Calculates the total number of bytes in the raw video format. This
1647 * number should be used when allocating a buffer for raw video.
1651 * Returns: size (in bytes) of raw video format
1654 gst_video_format_get_size (GstVideoFormat format, int width, int height)
1658 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1659 g_return_val_if_fail (width > 0 && height > 0, 0);
1662 case GST_VIDEO_FORMAT_I420:
1663 case GST_VIDEO_FORMAT_YV12:
1664 size = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
1665 size += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
1666 (GST_ROUND_UP_2 (height) / 2) * 2;
1668 case GST_VIDEO_FORMAT_YUY2:
1669 case GST_VIDEO_FORMAT_YVYU:
1670 case GST_VIDEO_FORMAT_UYVY:
1671 return GST_ROUND_UP_4 (width * 2) * height;
1672 case GST_VIDEO_FORMAT_AYUV:
1673 case GST_VIDEO_FORMAT_RGBx:
1674 case GST_VIDEO_FORMAT_BGRx:
1675 case GST_VIDEO_FORMAT_xRGB:
1676 case GST_VIDEO_FORMAT_xBGR:
1677 case GST_VIDEO_FORMAT_RGBA:
1678 case GST_VIDEO_FORMAT_BGRA:
1679 case GST_VIDEO_FORMAT_ARGB:
1680 case GST_VIDEO_FORMAT_ABGR:
1681 return width * 4 * height;
1682 case GST_VIDEO_FORMAT_RGB16:
1683 case GST_VIDEO_FORMAT_BGR16:
1684 case GST_VIDEO_FORMAT_RGB15:
1685 case GST_VIDEO_FORMAT_BGR15:
1686 return GST_ROUND_UP_4 (width * 2) * height;
1687 case GST_VIDEO_FORMAT_RGB:
1688 case GST_VIDEO_FORMAT_BGR:
1689 case GST_VIDEO_FORMAT_v308:
1690 return GST_ROUND_UP_4 (width * 3) * height;
1691 case GST_VIDEO_FORMAT_Y41B:
1692 /* simplification of ROUNDUP4(w)*h + 2*((ROUNDUP16(w)/4)*h */
1693 return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_16 (width) / 2)) * height;
1694 case GST_VIDEO_FORMAT_Y42B:
1695 /* simplification of ROUNDUP4(w)*h + 2*(ROUNDUP8(w)/2)*h */
1696 return (GST_ROUND_UP_4 (width) + GST_ROUND_UP_8 (width)) * height;
1697 case GST_VIDEO_FORMAT_Y444:
1698 return GST_ROUND_UP_4 (width) * height * 3;
1699 case GST_VIDEO_FORMAT_v210:
1700 return ((width + 47) / 48) * 128 * height;
1701 case GST_VIDEO_FORMAT_v216:
1702 return GST_ROUND_UP_8 (width * 4) * height;
1703 case GST_VIDEO_FORMAT_NV12:
1704 case GST_VIDEO_FORMAT_NV21:
1705 return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) * 3 / 2;
1706 case GST_VIDEO_FORMAT_GRAY8:
1707 case GST_VIDEO_FORMAT_Y800:
1708 return GST_ROUND_UP_4 (width) * height;
1709 case GST_VIDEO_FORMAT_GRAY16_BE:
1710 case GST_VIDEO_FORMAT_GRAY16_LE:
1711 case GST_VIDEO_FORMAT_Y16:
1712 return GST_ROUND_UP_4 (width * 2) * height;
1713 case GST_VIDEO_FORMAT_UYVP:
1714 return GST_ROUND_UP_4 ((width * 2 * 5 + 3) / 4) * height;
1721 * gst_video_format_convert:
1722 * @format: a #GstVideoFormat
1723 * @width: the width of video
1724 * @height: the height of video
1725 * @fps_n: frame rate numerator
1726 * @fps_d: frame rate denominator
1727 * @src_format: #GstFormat of the @src_value
1728 * @src_value: value to convert
1729 * @dest_format: #GstFormat of the @dest_value
1730 * @dest_value: pointer to destination value
1732 * Converts among various #GstFormat types. This function handles
1733 * GST_FORMAT_BYTES, GST_FORMAT_TIME, and GST_FORMAT_DEFAULT. For
1734 * raw video, GST_FORMAT_DEFAULT corresponds to video frames. This
1735 * function can be to handle pad queries of the type GST_QUERY_CONVERT.
1739 * Returns: TRUE if the conversion was successful.
1742 gst_video_format_convert (GstVideoFormat format, int width, int height,
1743 int fps_n, int fps_d,
1744 GstFormat src_format, gint64 src_value,
1745 GstFormat dest_format, gint64 * dest_value)
1747 gboolean ret = FALSE;
1750 g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
1751 g_return_val_if_fail (width > 0 && height > 0, 0);
1753 size = gst_video_format_get_size (format, width, height);
1755 GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
1756 src_value, gst_format_get_name (src_format),
1757 gst_format_get_name (dest_format));
1759 if (src_format == dest_format) {
1760 *dest_value = src_value;
1765 if (src_value == -1) {
1771 /* bytes to frames */
1772 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_DEFAULT) {
1774 *dest_value = gst_util_uint64_scale_int (src_value, 1, size);
1776 GST_ERROR ("blocksize is 0");
1783 /* frames to bytes */
1784 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_BYTES) {
1785 *dest_value = gst_util_uint64_scale_int (src_value, size, 1);
1790 /* time to frames */
1791 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_DEFAULT) {
1793 *dest_value = gst_util_uint64_scale (src_value,
1794 fps_n, GST_SECOND * fps_d);
1796 GST_ERROR ("framerate denominator is 0");
1803 /* frames to time */
1804 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_TIME) {
1806 *dest_value = gst_util_uint64_scale (src_value,
1807 GST_SECOND * fps_d, fps_n);
1809 GST_ERROR ("framerate numerator is 0");
1817 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
1819 *dest_value = gst_util_uint64_scale (src_value,
1820 fps_n * size, GST_SECOND * fps_d);
1822 GST_ERROR ("framerate denominator is 0");
1830 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_TIME) {
1831 if (fps_n != 0 && size != 0) {
1832 *dest_value = gst_util_uint64_scale (src_value,
1833 GST_SECOND * fps_d, fps_n * size);
1835 GST_ERROR ("framerate denominator and/or blocksize is 0");
1843 GST_DEBUG ("ret=%d result %" G_GINT64_FORMAT, ret, *dest_value);
1848 #define GST_VIDEO_EVENT_STILL_STATE_NAME "GstEventStillFrame"
1851 * gst_video_event_new_still_frame:
1852 * @in_still: boolean value for the still-frame state of the event.
1854 * Creates a new Still Frame event. If @in_still is %TRUE, then the event
1855 * represents the start of a still frame sequence. If it is %FALSE, then
1856 * the event ends a still frame sequence.
1858 * To parse an event created by gst_video_event_new_still_frame() use
1859 * gst_video_event_parse_still_frame().
1861 * Returns: The new GstEvent
1865 gst_video_event_new_still_frame (gboolean in_still)
1867 GstEvent *still_event;
1870 s = gst_structure_new (GST_VIDEO_EVENT_STILL_STATE_NAME,
1871 "still-state", G_TYPE_BOOLEAN, in_still, NULL);
1872 still_event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
1878 * gst_video_event_parse_still_frame:
1879 * @event: A #GstEvent to parse
1880 * @in_still: A boolean to receive the still-frame status from the event, or NULL
1882 * Parse a #GstEvent, identify if it is a Still Frame event, and
1883 * return the still-frame state from the event if it is.
1884 * If the event represents the start of a still frame, the in_still
1885 * variable will be set to TRUE, otherwise FALSE. It is OK to pass NULL for the
1886 * in_still variable order to just check whether the event is a valid still-frame
1889 * Create a still frame event using gst_video_event_new_still_frame()
1891 * Returns: %TRUE if the event is a valid still-frame event. %FALSE if not
1895 gst_video_event_parse_still_frame (GstEvent * event, gboolean * in_still)
1897 const GstStructure *s;
1898 gboolean ev_still_state;
1900 g_return_val_if_fail (event != NULL, FALSE);
1902 if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_DOWNSTREAM)
1903 return FALSE; /* Not a still frame event */
1905 s = gst_event_get_structure (event);
1907 || !gst_structure_has_name (s, GST_VIDEO_EVENT_STILL_STATE_NAME))
1908 return FALSE; /* Not a still frame event */
1909 if (!gst_structure_get_boolean (s, "still-state", &ev_still_state))
1910 return FALSE; /* Not a still frame event */
1912 *in_still = ev_still_state;