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 /* This is simply a convenience function, nothing more or less */
42 gst_video_frame_rate (GstPad * pad)
47 const GstCaps *caps = NULL;
48 GstStructure *structure;
51 caps = GST_PAD_CAPS (pad);
53 g_warning ("gstvideo: failed to get caps of pad %s:%s",
54 GST_DEBUG_PAD_NAME (pad));
58 structure = gst_caps_get_structure (caps, 0);
59 if ((fps = gst_structure_get_value (structure, "framerate")) == NULL) {
60 g_warning ("gstvideo: failed to get framerate property of pad %s:%s",
61 GST_DEBUG_PAD_NAME (pad));
64 if (!GST_VALUE_HOLDS_FRACTION (fps)) {
66 ("gstvideo: framerate property of pad %s:%s is not of type Fraction",
67 GST_DEBUG_PAD_NAME (pad));
71 fps_string = gst_value_serialize (fps);
72 GST_DEBUG ("Framerate request on pad %s:%s: %s",
73 GST_DEBUG_PAD_NAME (pad), fps_string);
80 gst_video_get_size (GstPad * pad, gint * width, gint * height)
82 const GstCaps *caps = NULL;
83 GstStructure *structure;
86 g_return_val_if_fail (pad != NULL, FALSE);
87 g_return_val_if_fail (width != NULL, FALSE);
88 g_return_val_if_fail (height != NULL, FALSE);
90 caps = GST_PAD_CAPS (pad);
93 g_warning ("gstvideo: failed to get caps of pad %s:%s",
94 GST_DEBUG_PAD_NAME (pad));
98 structure = gst_caps_get_structure (caps, 0);
99 ret = gst_structure_get_int (structure, "width", width);
100 ret &= gst_structure_get_int (structure, "height", height);
103 g_warning ("gstvideo: failed to get size properties on pad %s:%s",
104 GST_DEBUG_PAD_NAME (pad));
108 GST_DEBUG ("size request on pad %s:%s: %dx%d",
109 GST_DEBUG_PAD_NAME (pad), width ? *width : -1, height ? *height : -1);
115 * gst_video_calculate_display_ratio:
116 * @dar_n: Numerator of the calculated display_ratio
117 * @dar_d: Denominator of the calculated display_ratio
118 * @video_width: Width of the video frame in pixels
119 * @video_height: Height of the video frame in pixels
120 * @video_par_n: Numerator of the pixel aspect ratio of the input video.
121 * @video_par_d: Denominator of the pixel aspect ratio of the input video.
122 * @display_par_n: Numerator of the pixel aspect ratio of the display device
123 * @display_par_d: Denominator of the pixel aspect ratio of the display device
125 * Given the Pixel Aspect Ratio and size of an input video frame, and the
126 * pixel aspect ratio of the intended display device, calculates the actual
127 * display ratio the video will be rendered with.
129 * Returns: A boolean indicating success and a calculated Display Ratio in the
130 * dar_n and dar_d parameters.
131 * The return value is FALSE in the case of integer overflow or other error.
136 gst_video_calculate_display_ratio (guint * dar_n, guint * dar_d,
137 guint video_width, guint video_height,
138 guint video_par_n, guint video_par_d,
139 guint display_par_n, guint display_par_d)
143 GValue display_ratio = { 0, };
145 GValue tmp2 = { 0, };
147 g_return_val_if_fail (dar_n != NULL, FALSE);
148 g_return_val_if_fail (dar_d != NULL, FALSE);
150 g_value_init (&display_ratio, GST_TYPE_FRACTION);
151 g_value_init (&tmp, GST_TYPE_FRACTION);
152 g_value_init (&tmp2, GST_TYPE_FRACTION);
154 /* Calculate (video_width * video_par_n * display_par_d) /
155 * (video_height * video_par_d * display_par_n) */
156 gst_value_set_fraction (&display_ratio, video_width, video_height);
157 gst_value_set_fraction (&tmp, video_par_n, video_par_d);
159 if (!gst_value_fraction_multiply (&tmp2, &display_ratio, &tmp))
162 gst_value_set_fraction (&tmp, display_par_d, display_par_n);
164 if (!gst_value_fraction_multiply (&display_ratio, &tmp2, &tmp))
167 num = gst_value_get_fraction_numerator (&display_ratio);
168 den = gst_value_get_fraction_denominator (&display_ratio);
170 g_value_unset (&display_ratio);
171 g_value_unset (&tmp);
172 g_value_unset (&tmp2);
174 g_return_val_if_fail (num > 0, FALSE);
175 g_return_val_if_fail (den > 0, FALSE);
182 g_value_unset (&display_ratio);
183 g_value_unset (&tmp);
184 g_value_unset (&tmp2);
189 * gst_video_format_parse_caps:
190 * @caps: the #GstCaps to parse
191 * @format: the #GstVideoFormat of the video represented by @caps (output)
192 * @width: the width of the video represented by @caps (output)
193 * @height: the height of the video represented by @caps (output)
195 * Determines the #GstVideoFormat of @caps and places it in the location
196 * pointed to by @format. Extracts the size of the video and places it
197 * in the location pointed to by @width and @height. If @caps does not
198 * reprsent one of the raw video formats listed in #GstVideoFormat, the
199 * function will fail and return FALSE.
203 * Returns: TRUE if @caps was parsed correctly.
206 gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format,
207 int *width, int *height)
209 GstStructure *structure;
212 if (!gst_caps_is_fixed (caps))
215 structure = gst_caps_get_structure (caps, 0);
218 if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
221 ok &= gst_structure_get_fourcc (structure, "format", &fourcc);
223 *format = gst_video_format_from_fourcc (fourcc);
224 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
227 } else if (gst_structure_has_name (structure, "video/x-raw-rgb")) {
235 ok &= gst_structure_get_int (structure, "depth", &depth);
236 ok &= gst_structure_get_int (structure, "bpp", &bpp);
237 ok &= gst_structure_get_int (structure, "endianness", &endianness);
238 ok &= gst_structure_get_int (structure, "red_mask", &red_mask);
239 ok &= gst_structure_get_int (structure, "green_mask", &green_mask);
240 ok &= gst_structure_get_int (structure, "blue_mask", &blue_mask);
242 if (depth != 24 || bpp != 32 || endianness != G_BIG_ENDIAN) {
245 *format = gst_video_format_from_rgb32_masks (red_mask, green_mask,
247 if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
257 ok &= gst_structure_get_int (structure, "width", width);
261 ok &= gst_structure_get_int (structure, "height", height);
268 * gst_video_parse_caps_framerate:
270 * @fps_n: pointer to numerator of frame rate (output)
271 * @fps_d: pointer to denominator of frame rate (output)
273 * Extracts the frame rate from @caps and places the values in the locations
274 * pointed to by @fps_n and @fps_d. Returns TRUE if the values could be
275 * parsed correctly, FALSE if not.
277 * This function can be used with #GstCaps that have any media type; it
278 * is not limited to formats handled by #GstVideoFormat.
282 * Returns: TRUE if @caps was parsed correctly.
285 gst_video_parse_caps_framerate (GstCaps * caps, int *fps_n, int *fps_d)
287 GstStructure *structure;
289 if (!gst_caps_is_fixed (caps))
292 structure = gst_caps_get_structure (caps, 0);
294 return gst_structure_get_fraction (structure, "framerate", fps_n, fps_d);
298 * gst_video_parse_caps_pixel_aspect_ratio:
300 * @par_n: pointer to numerator of pixel aspect ratio (output)
301 * @par_d: pointer to denominator of pixel aspect ratio (output)
303 * Extracts the pixel aspect ratio from @caps and places the values in
304 * the locations pointed to by @par_n and @par_d. Returns TRUE if the
305 * values could be parsed correctly, FALSE if not.
307 * This function can be used with #GstCaps that have any media type; it
308 * is not limited to formats handled by #GstVideoFormat.
312 * Returns: TRUE if @caps was parsed correctly.
315 gst_video_parse_caps_pixel_aspect_ratio (GstCaps * caps, int *par_n, int *par_d)
317 GstStructure *structure;
319 if (!gst_caps_is_fixed (caps))
322 structure = gst_caps_get_structure (caps, 0);
324 if (!gst_structure_get_fraction (structure, "pixel-aspect-ratio",
333 * gst_video_format_new_caps:
334 * @format: the #GstVideoFormat describing the raw video format
335 * @width: width of video
336 * @height: height of video
337 * @framerate_n: numerator of frame rate
338 * @framerate_d: denominator of frame rate
339 * @par_n: numerator of pixel aspect ratio
340 * @par_d: denominator of pixel aspect ratio
342 * Creates a new #GstCaps object based on the parameters provided.
346 * Returns: a new #GstCaps object, or NULL if there was an error
349 gst_video_format_new_caps (GstVideoFormat format, int width, int height,
350 int framerate_n, int framerate_d, int par_n, int par_d)
352 if (gst_video_format_is_yuv (format)) {
353 return gst_caps_new_simple ("video/x-raw-yuv",
354 "format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format),
355 "width", G_TYPE_INT, width,
356 "height", G_TYPE_INT, height,
357 "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
358 "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
360 if (gst_video_format_is_rgb (format)) {
366 0xff000000U >> gst_video_format_get_component_offset (format, 0, width,
369 0xff000000U >> gst_video_format_get_component_offset (format, 1, width,
372 0xff000000U >> gst_video_format_get_component_offset (format, 2, width,
375 return gst_caps_new_simple ("video/x-raw-rgb",
376 "bpp", G_TYPE_INT, 32,
377 "depth", G_TYPE_INT, 24,
378 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
379 "red_mask", G_TYPE_INT, red_mask,
380 "green_mask", G_TYPE_INT, green_mask,
381 "blue_mask", G_TYPE_INT, blue_mask,
382 "width", G_TYPE_INT, width,
383 "height", G_TYPE_INT, height,
384 "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
385 "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
391 * gst_video_format_from_fourcc:
392 * @fourcc: a FOURCC value representing raw YUV video
394 * Converts a FOURCC value into the corresponding #GstVideoFormat.
395 * If the FOURCC cannot be represented by #GstVideoFormat,
396 * #GST_VIDEO_FORMAT_UNKNOWN is returned.
400 * Returns: the #GstVideoFormat describing the FOURCC value
403 gst_video_format_from_fourcc (guint32 fourcc)
406 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
407 return GST_VIDEO_FORMAT_I420;
408 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
409 return GST_VIDEO_FORMAT_YV12;
410 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
411 return GST_VIDEO_FORMAT_YUY2;
412 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
413 return GST_VIDEO_FORMAT_UYVY;
414 case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
415 return GST_VIDEO_FORMAT_AYUV;
417 return GST_VIDEO_FORMAT_UNKNOWN;
422 * gst_video_format_to_fourcc:
423 * @format: a #GstVideoFormat video format
425 * Converts a #GstVideoFormat value into the corresponding FOURCC. Only
426 * a few YUV formats have corresponding FOURCC values. If @format has
427 * no corresponding FOURCC value, 0 is returned.
431 * Returns: the FOURCC corresponding to @format
434 gst_video_format_to_fourcc (GstVideoFormat format)
437 case GST_VIDEO_FORMAT_I420:
438 return GST_MAKE_FOURCC ('I', '4', '2', '0');
439 case GST_VIDEO_FORMAT_YV12:
440 return GST_MAKE_FOURCC ('Y', 'V', '1', '2');
441 case GST_VIDEO_FORMAT_YUY2:
442 return GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
443 case GST_VIDEO_FORMAT_UYVY:
444 return GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
445 case GST_VIDEO_FORMAT_AYUV:
446 return GST_MAKE_FOURCC ('A', 'Y', 'U', 'V');
453 * gst_video_format_from_rgb32_masks:
454 * @red_mask: red bit mask
455 * @green_mask: green bit mask
456 * @blue_mask: blue bit mask
458 * Converts red, green, blue bit masks into the corresponding
463 * Returns: the #GstVideoFormat corresponding to the bit masks
466 gst_video_format_from_rgb32_masks (int red_mask, int green_mask, int blue_mask)
468 if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
469 blue_mask == 0x0000ff00) {
470 return GST_VIDEO_FORMAT_RGBx;
472 if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
473 blue_mask == 0xff000000) {
474 return GST_VIDEO_FORMAT_BGRx;
476 if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
477 blue_mask == 0x000000ff) {
478 return GST_VIDEO_FORMAT_xRGB;
480 if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
481 blue_mask == 0x00ff0000) {
482 return GST_VIDEO_FORMAT_xBGR;
485 return GST_VIDEO_FORMAT_UNKNOWN;
489 * gst_video_format_is_rgb:
490 * @format: a #GstVideoFormat
494 * Returns: TRUE if @format represents RGB video
497 gst_video_format_is_rgb (GstVideoFormat format)
500 case GST_VIDEO_FORMAT_I420:
501 case GST_VIDEO_FORMAT_YV12:
502 case GST_VIDEO_FORMAT_YUY2:
503 case GST_VIDEO_FORMAT_UYVY:
504 case GST_VIDEO_FORMAT_AYUV:
506 case GST_VIDEO_FORMAT_RGBx:
507 case GST_VIDEO_FORMAT_BGRx:
508 case GST_VIDEO_FORMAT_xRGB:
509 case GST_VIDEO_FORMAT_xBGR:
517 * gst_video_format_is_yuv:
518 * @format: a #GstVideoFormat
522 * Returns: TRUE if @format represents YUV video
525 gst_video_format_is_yuv (GstVideoFormat format)
528 case GST_VIDEO_FORMAT_I420:
529 case GST_VIDEO_FORMAT_YV12:
530 case GST_VIDEO_FORMAT_YUY2:
531 case GST_VIDEO_FORMAT_UYVY:
532 case GST_VIDEO_FORMAT_AYUV:
534 case GST_VIDEO_FORMAT_RGBx:
535 case GST_VIDEO_FORMAT_BGRx:
536 case GST_VIDEO_FORMAT_xRGB:
537 case GST_VIDEO_FORMAT_xBGR:
545 * gst_video_format_has_alpha:
546 * @format: a #GstVideoFormat
550 * Returns: TRUE if @format has an alpha channel
553 gst_video_format_has_alpha (GstVideoFormat format)
556 case GST_VIDEO_FORMAT_I420:
557 case GST_VIDEO_FORMAT_YV12:
558 case GST_VIDEO_FORMAT_YUY2:
559 case GST_VIDEO_FORMAT_UYVY:
561 case GST_VIDEO_FORMAT_AYUV:
563 case GST_VIDEO_FORMAT_RGBx:
564 case GST_VIDEO_FORMAT_BGRx:
565 case GST_VIDEO_FORMAT_xRGB:
566 case GST_VIDEO_FORMAT_xBGR:
574 * gst_video_format_get_row_stride:
575 * @format: a #GstVideoFormat
576 * @component: the component index
577 * @width: the width of video
579 * Calculates the row stride (number of bytes from one row of pixels to
580 * the next) for the video component with an index of @component. For
581 * YUV video, Y, U, and V have component indices of 0, 1, and 2,
582 * respectively. For RGB video, R, G, and B have component indicies of
583 * 0, 1, and 2, respectively. Alpha channels, if present, have a component
584 * index of 3. The @width parameter always represents the width of the
585 * video, not the component.
589 * Returns: row stride of component @component
592 gst_video_format_get_row_stride (GstVideoFormat format, int component,
596 case GST_VIDEO_FORMAT_I420:
597 case GST_VIDEO_FORMAT_YV12:
598 if (component == 0) {
599 return GST_ROUND_UP_4 (width);
601 return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
603 case GST_VIDEO_FORMAT_YUY2:
604 case GST_VIDEO_FORMAT_UYVY:
605 return GST_ROUND_UP_4 (width * 2);
606 case GST_VIDEO_FORMAT_AYUV:
607 case GST_VIDEO_FORMAT_RGBx:
608 case GST_VIDEO_FORMAT_BGRx:
609 case GST_VIDEO_FORMAT_xRGB:
610 case GST_VIDEO_FORMAT_xBGR:
618 * gst_video_format_get_pixel_stride:
619 * @format: a #GstVideoFormat
620 * @component: the component index
622 * Calculates the pixel stride (number of bytes from one pixel to the
623 * pixel to its immediate left) for the video component with an index
624 * of @component. See @gst_video_format_get_row_stride for a description
625 * of the component index.
629 * Returns: pixel stride of component @component
632 gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
635 case GST_VIDEO_FORMAT_I420:
636 case GST_VIDEO_FORMAT_YV12:
638 case GST_VIDEO_FORMAT_YUY2:
639 case GST_VIDEO_FORMAT_UYVY:
640 if (component == 0) {
645 case GST_VIDEO_FORMAT_AYUV:
646 case GST_VIDEO_FORMAT_RGBx:
647 case GST_VIDEO_FORMAT_BGRx:
648 case GST_VIDEO_FORMAT_xRGB:
649 case GST_VIDEO_FORMAT_xBGR:
657 * gst_video_format_get_component_width:
658 * @format: a #GstVideoFormat
659 * @component: the component index
660 * @width: the width of video
662 * Calculates the width of the component. See
663 * @gst_video_format_get_row_stride for a description
664 * of the component index.
668 * Returns: width of component @component
671 gst_video_format_get_component_width (GstVideoFormat format, int component,
675 case GST_VIDEO_FORMAT_I420:
676 case GST_VIDEO_FORMAT_YV12:
677 case GST_VIDEO_FORMAT_YUY2:
678 case GST_VIDEO_FORMAT_UYVY:
679 if (component == 0) {
682 return GST_ROUND_UP_2 (width) / 2;
684 case GST_VIDEO_FORMAT_AYUV:
685 case GST_VIDEO_FORMAT_RGBx:
686 case GST_VIDEO_FORMAT_BGRx:
687 case GST_VIDEO_FORMAT_xRGB:
688 case GST_VIDEO_FORMAT_xBGR:
696 * gst_video_format_get_component_height:
697 * @format: a #GstVideoFormat
698 * @component: the component index
699 * @height: the height of video
701 * Calculates the height of the component. See
702 * @gst_video_format_get_row_stride for a description
703 * of the component index.
707 * Returns: height of component @component
710 gst_video_format_get_component_height (GstVideoFormat format, int component,
714 case GST_VIDEO_FORMAT_I420:
715 case GST_VIDEO_FORMAT_YV12:
716 if (component == 0) {
719 return GST_ROUND_UP_2 (height) / 2;
721 case GST_VIDEO_FORMAT_YUY2:
722 case GST_VIDEO_FORMAT_UYVY:
723 case GST_VIDEO_FORMAT_AYUV:
724 case GST_VIDEO_FORMAT_RGBx:
725 case GST_VIDEO_FORMAT_BGRx:
726 case GST_VIDEO_FORMAT_xRGB:
727 case GST_VIDEO_FORMAT_xBGR:
735 * gst_video_format_get_component_offset:
736 * @format: a #GstVideoFormat
737 * @component: the component index
738 * @width: the width of video
739 * @height: the height of video
741 * Calculates the offset (in bytes) of the first pixel of the component
742 * with index @component. For packed formats, this will typically be a
743 * small integer (0, 1, 2, 3). For planar formats, this will be a
744 * (relatively) large offset to the beginning of the second or third
745 * component planes. See @gst_video_format_get_row_stride for a description
746 * of the component index.
750 * Returns: offset of component @component
753 gst_video_format_get_component_offset (GstVideoFormat format, int component,
754 int width, int height)
757 case GST_VIDEO_FORMAT_I420:
758 case GST_VIDEO_FORMAT_YV12:
759 if (component == 0) {
764 offset = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
765 if (component == 2) {
766 offset += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
767 (GST_ROUND_UP_2 (height) / 2);
771 case GST_VIDEO_FORMAT_YUY2:
779 case GST_VIDEO_FORMAT_UYVY:
787 case GST_VIDEO_FORMAT_AYUV:
797 case GST_VIDEO_FORMAT_RGBx:
807 case GST_VIDEO_FORMAT_BGRx:
817 case GST_VIDEO_FORMAT_xRGB:
827 case GST_VIDEO_FORMAT_xBGR:
843 * gst_video_format_get_size:
844 * @format: a #GstVideoFormat
845 * @width: the width of video
846 * @height: the height of video
848 * Calculates the total number of bytes in the raw video format. This
849 * number should be used when allocating a buffer for raw video.
853 * Returns: size (in bytes) of raw video format
856 gst_video_format_get_size (GstVideoFormat format, int width, int height)
861 case GST_VIDEO_FORMAT_I420:
862 case GST_VIDEO_FORMAT_YV12:
863 size = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
864 size += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
865 (GST_ROUND_UP_2 (height) / 2) * 2;
867 case GST_VIDEO_FORMAT_YUY2:
868 case GST_VIDEO_FORMAT_UYVY:
869 return GST_ROUND_UP_4 (width * 2) * height;
870 case GST_VIDEO_FORMAT_AYUV:
871 case GST_VIDEO_FORMAT_RGBx:
872 case GST_VIDEO_FORMAT_BGRx:
873 case GST_VIDEO_FORMAT_xRGB:
874 case GST_VIDEO_FORMAT_xBGR:
875 return width * 4 * height;
882 * gst_video_format_convert:
883 * @format: a #GstVideoFormat
884 * @width: the width of video
885 * @height: the height of video
886 * @fps_n: frame rate numerator
887 * @fps_d: frame rate denominator
888 * @src_format: #GstFormat of the @src_value
889 * @src_value: value to convert
890 * @dest_format: #GstFormat of the @dest_value
891 * @dest_value: pointer to destination value
893 * Converts among various #GstFormat types. This function handles
894 * GST_FORMAT_BYTES, GST_FORMAT_TIME, and GST_FORMAT_DEFAULT. For
895 * raw video, GST_FORMAT_DEFAULT corresponds to video frames. This
896 * function can be to handle pad queries of the type GST_QUERY_CONVERT.
900 * Returns: TRUE if the conversion was successful.
903 gst_video_format_convert (GstVideoFormat format, int width, int height,
904 int fps_n, int fps_d,
905 GstFormat src_format, gint64 src_value,
906 GstFormat dest_format, gint64 * dest_value)
908 gboolean ret = FALSE;
911 size = gst_video_format_get_size (format, width, height);
913 GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
914 src_value, gst_format_get_name (src_format),
915 gst_format_get_name (dest_format));
917 if (src_format == dest_format) {
918 *dest_value = src_value;
923 if (src_value == -1) {
929 /* bytes to frames */
930 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_DEFAULT) {
932 *dest_value = gst_util_uint64_scale_int (src_value, 1, size);
934 GST_ERROR ("blocksize is 0");
941 /* frames to bytes */
942 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_BYTES) {
943 *dest_value = gst_util_uint64_scale_int (src_value, size, 1);
949 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_DEFAULT) {
951 *dest_value = gst_util_uint64_scale (src_value,
952 fps_n, GST_SECOND * fps_d);
954 GST_ERROR ("framerate denominator is 0");
962 if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_TIME) {
964 *dest_value = gst_util_uint64_scale (src_value,
965 GST_SECOND * fps_d, fps_n);
967 GST_ERROR ("framerate numerator is 0");
975 if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
977 *dest_value = gst_util_uint64_scale (src_value,
978 fps_n * size, GST_SECOND * fps_d);
980 GST_ERROR ("framerate denominator is 0");
988 if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_TIME) {
989 if (fps_n != 0 && size != 0) {
990 *dest_value = gst_util_uint64_scale (src_value,
991 GST_SECOND * fps_d, fps_n * size);
993 GST_ERROR ("framerate denominator and/or blocksize is 0");
1001 GST_DEBUG ("ret=%d result %" G_GINT64_FORMAT, ret, *dest_value);