gst_plugins_base/gst-libs/gst/video/video.c
changeset 0 0e761a78d257
child 8 4a7fac7dd34a
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     1 /* GStreamer
       
     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>
       
     5  *
       
     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.
       
    10  *
       
    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.
       
    15  *
       
    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.
       
    20  */
       
    21 
       
    22 #ifdef HAVE_CONFIG_H
       
    23 #  include "config.h"
       
    24 #endif
       
    25 
       
    26 #include "video.h"
       
    27 
       
    28 /**
       
    29  * SECTION:gstvideo
       
    30  * @short_description: Support library for video operations
       
    31  *
       
    32  * <refsect2>
       
    33  * <para>
       
    34  * This library contains some helper functions and includes the 
       
    35  * videosink and videofilter base classes.
       
    36  * </para>
       
    37  * </refsect2>
       
    38  */
       
    39 
       
    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 
       
    47 
       
    48 /* This is simply a convenience function, nothing more or less */
       
    49 #ifdef __SYMBIAN32__
       
    50 EXPORT_C
       
    51 #endif
       
    52 
       
    53 const GValue *
       
    54 gst_video_frame_rate (GstPad * pad)
       
    55 {
       
    56   const GValue *fps;
       
    57   gchar *fps_string;
       
    58 
       
    59   const GstCaps *caps = NULL;
       
    60   GstStructure *structure;
       
    61 
       
    62   /* get pad caps */
       
    63   caps = GST_PAD_CAPS (pad);
       
    64   if (caps == NULL) {
       
    65     g_warning ("gstvideo: failed to get caps of pad %s:%s",
       
    66         GST_DEBUG_PAD_NAME (pad));
       
    67     return NULL;
       
    68   }
       
    69 
       
    70   structure = gst_caps_get_structure (caps, 0);
       
    71   if ((fps = gst_structure_get_value (structure, "framerate")) == NULL) {
       
    72     g_warning ("gstvideo: failed to get framerate property of pad %s:%s",
       
    73         GST_DEBUG_PAD_NAME (pad));
       
    74     return NULL;
       
    75   }
       
    76   if (!GST_VALUE_HOLDS_FRACTION (fps)) {
       
    77     g_warning
       
    78         ("gstvideo: framerate property of pad %s:%s is not of type Fraction",
       
    79         GST_DEBUG_PAD_NAME (pad));
       
    80     return NULL;
       
    81   }
       
    82 
       
    83   fps_string = gst_value_serialize (fps);
       
    84   GST_DEBUG ("Framerate request on pad %s:%s: %s",
       
    85       GST_DEBUG_PAD_NAME (pad), fps_string);
       
    86   g_free (fps_string);
       
    87 
       
    88   return fps;
       
    89 }
       
    90 #ifdef __SYMBIAN32__
       
    91 EXPORT_C
       
    92 #endif
       
    93 
       
    94 
       
    95 gboolean
       
    96 gst_video_get_size (GstPad * pad, gint * width, gint * height)
       
    97 {
       
    98   const GstCaps *caps = NULL;
       
    99   GstStructure *structure;
       
   100   gboolean ret;
       
   101 
       
   102   g_return_val_if_fail (pad != NULL, FALSE);
       
   103   g_return_val_if_fail (width != NULL, FALSE);
       
   104   g_return_val_if_fail (height != NULL, FALSE);
       
   105 
       
   106   caps = GST_PAD_CAPS (pad);
       
   107 
       
   108   if (caps == NULL) {
       
   109     g_warning ("gstvideo: failed to get caps of pad %s:%s",
       
   110         GST_DEBUG_PAD_NAME (pad));
       
   111     return FALSE;
       
   112   }
       
   113 
       
   114   structure = gst_caps_get_structure (caps, 0);
       
   115   ret = gst_structure_get_int (structure, "width", width);
       
   116   ret &= gst_structure_get_int (structure, "height", height);
       
   117 
       
   118   if (!ret) {
       
   119     g_warning ("gstvideo: failed to get size properties on pad %s:%s",
       
   120         GST_DEBUG_PAD_NAME (pad));
       
   121     return FALSE;
       
   122   }
       
   123 
       
   124   GST_DEBUG ("size request on pad %s:%s: %dx%d",
       
   125       GST_DEBUG_PAD_NAME (pad), width ? *width : -1, height ? *height : -1);
       
   126 
       
   127   return TRUE;
       
   128 }
       
   129 
       
   130 /**
       
   131  * gst_video_calculate_display_ratio:
       
   132  * @dar_n: Numerator of the calculated display_ratio
       
   133  * @dar_d: Denominator of the calculated display_ratio
       
   134  * @video_width: Width of the video frame in pixels
       
   135  * @video_height: Height of the video frame in pixels
       
   136  * @video_par_n: Numerator of the pixel aspect ratio of the input video.
       
   137  * @video_par_d: Denominator of the pixel aspect ratio of the input video.
       
   138  * @display_par_n: Numerator of the pixel aspect ratio of the display device
       
   139  * @display_par_d: Denominator of the pixel aspect ratio of the display device
       
   140  *
       
   141  * Given the Pixel Aspect Ratio and size of an input video frame, and the 
       
   142  * pixel aspect ratio of the intended display device, calculates the actual 
       
   143  * display ratio the video will be rendered with.
       
   144  *
       
   145  * Returns: A boolean indicating success and a calculated Display Ratio in the 
       
   146  * dar_n and dar_d parameters. 
       
   147  * The return value is FALSE in the case of integer overflow or other error. 
       
   148  *
       
   149  * Since: 0.10.7
       
   150  */
       
   151 #ifdef __SYMBIAN32__
       
   152 EXPORT_C
       
   153 #endif
       
   154 
       
   155 gboolean
       
   156 gst_video_calculate_display_ratio (guint * dar_n, guint * dar_d,
       
   157     guint video_width, guint video_height,
       
   158     guint video_par_n, guint video_par_d,
       
   159     guint display_par_n, guint display_par_d)
       
   160 {
       
   161   gint num, den;
       
   162 
       
   163   GValue display_ratio = { 0, };
       
   164   GValue tmp = { 0, };
       
   165   GValue tmp2 = { 0, };
       
   166 
       
   167   g_return_val_if_fail (dar_n != NULL, FALSE);
       
   168   g_return_val_if_fail (dar_d != NULL, FALSE);
       
   169 
       
   170   g_value_init (&display_ratio, GST_TYPE_FRACTION);
       
   171   g_value_init (&tmp, GST_TYPE_FRACTION);
       
   172   g_value_init (&tmp2, GST_TYPE_FRACTION);
       
   173 
       
   174   /* Calculate (video_width * video_par_n * display_par_d) /
       
   175    * (video_height * video_par_d * display_par_n) */
       
   176   gst_value_set_fraction (&display_ratio, video_width, video_height);
       
   177   gst_value_set_fraction (&tmp, video_par_n, video_par_d);
       
   178 
       
   179   if (!gst_value_fraction_multiply (&tmp2, &display_ratio, &tmp))
       
   180     goto error_overflow;
       
   181 
       
   182   gst_value_set_fraction (&tmp, display_par_d, display_par_n);
       
   183 
       
   184   if (!gst_value_fraction_multiply (&display_ratio, &tmp2, &tmp))
       
   185     goto error_overflow;
       
   186 
       
   187   num = gst_value_get_fraction_numerator (&display_ratio);
       
   188   den = gst_value_get_fraction_denominator (&display_ratio);
       
   189 
       
   190   g_value_unset (&display_ratio);
       
   191   g_value_unset (&tmp);
       
   192   g_value_unset (&tmp2);
       
   193 
       
   194   g_return_val_if_fail (num > 0, FALSE);
       
   195   g_return_val_if_fail (den > 0, FALSE);
       
   196 
       
   197   *dar_n = num;
       
   198   *dar_d = den;
       
   199 
       
   200   return TRUE;
       
   201 error_overflow:
       
   202   g_value_unset (&display_ratio);
       
   203   g_value_unset (&tmp);
       
   204   g_value_unset (&tmp2);
       
   205   return FALSE;
       
   206 }
       
   207 
       
   208 /**
       
   209  * gst_video_format_parse_caps:
       
   210  * @caps: the #GstCaps to parse
       
   211  * @format: the #GstVideoFormat of the video represented by @caps (output)
       
   212  * @width: the width of the video represented by @caps (output)
       
   213  * @height: the height of the video represented by @caps (output)
       
   214  *
       
   215  * Determines the #GstVideoFormat of @caps and places it in the location
       
   216  * pointed to by @format.  Extracts the size of the video and places it
       
   217  * in the location pointed to by @width and @height.  If @caps does not
       
   218  * represent one of the raw video formats listed in #GstVideoFormat, the
       
   219  * function will fail and return FALSE.
       
   220  *
       
   221  * Since: 0.10.16
       
   222  *
       
   223  * Returns: TRUE if @caps was parsed correctly.
       
   224  */
       
   225 #ifdef __SYMBIAN32__
       
   226 EXPORT_C
       
   227 #endif
       
   228 
       
   229 gboolean
       
   230 gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format,
       
   231     int *width, int *height)
       
   232 {
       
   233   GstStructure *structure;
       
   234   gboolean ok = TRUE;
       
   235 
       
   236   if (!gst_caps_is_fixed (caps))
       
   237     return FALSE;
       
   238 
       
   239   structure = gst_caps_get_structure (caps, 0);
       
   240 
       
   241   if (format) {
       
   242     if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
       
   243       guint32 fourcc;
       
   244 
       
   245       ok &= gst_structure_get_fourcc (structure, "format", &fourcc);
       
   246 
       
   247       *format = gst_video_format_from_fourcc (fourcc);
       
   248       if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
       
   249         ok = FALSE;
       
   250       }
       
   251     } else if (gst_structure_has_name (structure, "video/x-raw-rgb")) {
       
   252       int depth;
       
   253       int bpp;
       
   254       int endianness;
       
   255       int red_mask;
       
   256       int green_mask;
       
   257       int blue_mask;
       
   258       int alpha_mask;
       
   259       gboolean have_alpha;
       
   260 
       
   261       ok &= gst_structure_get_int (structure, "depth", &depth);
       
   262       ok &= gst_structure_get_int (structure, "bpp", &bpp);
       
   263       ok &= gst_structure_get_int (structure, "endianness", &endianness);
       
   264       ok &= gst_structure_get_int (structure, "red_mask", &red_mask);
       
   265       ok &= gst_structure_get_int (structure, "green_mask", &green_mask);
       
   266       ok &= gst_structure_get_int (structure, "blue_mask", &blue_mask);
       
   267       have_alpha = gst_structure_get_int (structure, "alpha_mask", &alpha_mask);
       
   268 
       
   269       if (depth == 24 && bpp == 32 && endianness == G_BIG_ENDIAN) {
       
   270         *format = gst_video_format_from_rgb32_masks (red_mask, green_mask,
       
   271             blue_mask);
       
   272         if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
       
   273           ok = FALSE;
       
   274         }
       
   275       } else if (depth == 32 && bpp == 32 && endianness == G_BIG_ENDIAN &&
       
   276           have_alpha) {
       
   277         *format = gst_video_format_from_rgba32_masks (red_mask, green_mask,
       
   278             blue_mask, alpha_mask);
       
   279         if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
       
   280           ok = FALSE;
       
   281         }
       
   282       } else if (depth == 24 && bpp == 24 && endianness == G_BIG_ENDIAN) {
       
   283         *format = gst_video_format_from_rgb24_masks (red_mask, green_mask,
       
   284             blue_mask);
       
   285         if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
       
   286           ok = FALSE;
       
   287         }
       
   288       } else {
       
   289         ok = FALSE;
       
   290       }
       
   291     } else {
       
   292       ok = FALSE;
       
   293     }
       
   294   }
       
   295 
       
   296   if (width) {
       
   297     ok &= gst_structure_get_int (structure, "width", width);
       
   298   }
       
   299 
       
   300   if (height) {
       
   301     ok &= gst_structure_get_int (structure, "height", height);
       
   302   }
       
   303 
       
   304   return ok;
       
   305 }
       
   306 
       
   307 /**
       
   308  * gst_video_parse_caps_framerate:
       
   309  * @caps:
       
   310  * @fps_n: pointer to numerator of frame rate (output)
       
   311  * @fps_d: pointer to denominator of frame rate (output)
       
   312  *
       
   313  * Extracts the frame rate from @caps and places the values in the locations
       
   314  * pointed to by @fps_n and @fps_d.  Returns TRUE if the values could be
       
   315  * parsed correctly, FALSE if not.
       
   316  *
       
   317  * This function can be used with #GstCaps that have any media type; it
       
   318  * is not limited to formats handled by #GstVideoFormat.
       
   319  *
       
   320  * Since: 0.10.16
       
   321  *
       
   322  * Returns: TRUE if @caps was parsed correctly.
       
   323  */
       
   324 #ifdef __SYMBIAN32__
       
   325 EXPORT_C
       
   326 #endif
       
   327 
       
   328 gboolean
       
   329 gst_video_parse_caps_framerate (GstCaps * caps, int *fps_n, int *fps_d)
       
   330 {
       
   331   GstStructure *structure;
       
   332 
       
   333   if (!gst_caps_is_fixed (caps))
       
   334     return FALSE;
       
   335 
       
   336   structure = gst_caps_get_structure (caps, 0);
       
   337 
       
   338   return gst_structure_get_fraction (structure, "framerate", fps_n, fps_d);
       
   339 }
       
   340 
       
   341 /**
       
   342  * gst_video_parse_caps_pixel_aspect_ratio:
       
   343  * @caps:
       
   344  * @par_n: pointer to numerator of pixel aspect ratio (output)
       
   345  * @par_d: pointer to denominator of pixel aspect ratio (output)
       
   346  *
       
   347  * Extracts the pixel aspect ratio from @caps and places the values in
       
   348  * the locations pointed to by @par_n and @par_d.  Returns TRUE if the
       
   349  * values could be parsed correctly, FALSE if not.
       
   350  *
       
   351  * This function can be used with #GstCaps that have any media type; it
       
   352  * is not limited to formats handled by #GstVideoFormat.
       
   353  *
       
   354  * Since: 0.10.16
       
   355  *
       
   356  * Returns: TRUE if @caps was parsed correctly.
       
   357  */
       
   358 #ifdef __SYMBIAN32__
       
   359 EXPORT_C
       
   360 #endif
       
   361 
       
   362 gboolean
       
   363 gst_video_parse_caps_pixel_aspect_ratio (GstCaps * caps, int *par_n, int *par_d)
       
   364 {
       
   365   GstStructure *structure;
       
   366 
       
   367   if (!gst_caps_is_fixed (caps))
       
   368     return FALSE;
       
   369 
       
   370   structure = gst_caps_get_structure (caps, 0);
       
   371 
       
   372   if (!gst_structure_get_fraction (structure, "pixel-aspect-ratio",
       
   373           par_n, par_d)) {
       
   374     *par_n = 1;
       
   375     *par_d = 1;
       
   376   }
       
   377   return TRUE;
       
   378 }
       
   379 
       
   380 /**
       
   381  * gst_video_format_new_caps:
       
   382  * @format: the #GstVideoFormat describing the raw video format
       
   383  * @width: width of video
       
   384  * @height: height of video
       
   385  * @framerate_n: numerator of frame rate
       
   386  * @framerate_d: denominator of frame rate
       
   387  * @par_n: numerator of pixel aspect ratio
       
   388  * @par_d: denominator of pixel aspect ratio
       
   389  *
       
   390  * Creates a new #GstCaps object based on the parameters provided.
       
   391  *
       
   392  * Since: 0.10.16
       
   393  *
       
   394  * Returns: a new #GstCaps object, or NULL if there was an error
       
   395  */
       
   396 #ifdef __SYMBIAN32__
       
   397 EXPORT_C
       
   398 #endif
       
   399 
       
   400 GstCaps *
       
   401 gst_video_format_new_caps (GstVideoFormat format, int width, int height,
       
   402     int framerate_n, int framerate_d, int par_n, int par_d)
       
   403 {
       
   404   if (gst_video_format_is_yuv (format)) {
       
   405     return gst_caps_new_simple ("video/x-raw-yuv",
       
   406         "format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format),
       
   407         "width", G_TYPE_INT, width,
       
   408         "height", G_TYPE_INT, height,
       
   409         "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
       
   410         "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
       
   411   }
       
   412   if (gst_video_format_is_rgb (format)) {
       
   413     GstCaps *caps;
       
   414     int red_mask;
       
   415     int blue_mask;
       
   416     int green_mask;
       
   417     int alpha_mask;
       
   418     int depth;
       
   419     int bpp;
       
   420     gboolean have_alpha;
       
   421     unsigned int mask;
       
   422 
       
   423     switch (format) {
       
   424       case GST_VIDEO_FORMAT_RGBx:
       
   425       case GST_VIDEO_FORMAT_BGRx:
       
   426       case GST_VIDEO_FORMAT_xRGB:
       
   427       case GST_VIDEO_FORMAT_xBGR:
       
   428         bpp = 32;
       
   429         depth = 24;
       
   430         have_alpha = FALSE;
       
   431         break;
       
   432       case GST_VIDEO_FORMAT_RGBA:
       
   433       case GST_VIDEO_FORMAT_BGRA:
       
   434       case GST_VIDEO_FORMAT_ARGB:
       
   435       case GST_VIDEO_FORMAT_ABGR:
       
   436         bpp = 32;
       
   437         depth = 32;
       
   438         have_alpha = TRUE;
       
   439         break;
       
   440       case GST_VIDEO_FORMAT_RGB:
       
   441       case GST_VIDEO_FORMAT_BGR:
       
   442         bpp = 24;
       
   443         depth = 24;
       
   444         have_alpha = FALSE;
       
   445         break;
       
   446       default:
       
   447         return NULL;
       
   448     }
       
   449     if (bpp == 32) {
       
   450       mask = 0xff000000;
       
   451     } else {
       
   452       mask = 0xff0000;
       
   453     }
       
   454     red_mask =
       
   455         mask >> (8 * gst_video_format_get_component_offset (format, 0, width,
       
   456             height));
       
   457     green_mask =
       
   458         mask >> (8 * gst_video_format_get_component_offset (format, 1, width,
       
   459             height));
       
   460     blue_mask =
       
   461         mask >> (8 * gst_video_format_get_component_offset (format, 2, width,
       
   462             height));
       
   463 
       
   464     caps = gst_caps_new_simple ("video/x-raw-rgb",
       
   465         "bpp", G_TYPE_INT, bpp,
       
   466         "depth", G_TYPE_INT, depth,
       
   467         "endianness", G_TYPE_INT, G_BIG_ENDIAN,
       
   468         "red_mask", G_TYPE_INT, red_mask,
       
   469         "green_mask", G_TYPE_INT, green_mask,
       
   470         "blue_mask", G_TYPE_INT, blue_mask,
       
   471         "width", G_TYPE_INT, width,
       
   472         "height", G_TYPE_INT, height,
       
   473         "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
       
   474         "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
       
   475     if (have_alpha) {
       
   476       alpha_mask =
       
   477           mask >> (8 * gst_video_format_get_component_offset (format, 3, width,
       
   478               height));
       
   479       gst_caps_set_simple (caps, "alpha_mask", G_TYPE_INT, alpha_mask, NULL);
       
   480     }
       
   481     return caps;
       
   482   }
       
   483   return NULL;
       
   484 }
       
   485 
       
   486 /**
       
   487  * gst_video_format_from_fourcc:
       
   488  * @fourcc: a FOURCC value representing raw YUV video
       
   489  *
       
   490  * Converts a FOURCC value into the corresponding #GstVideoFormat.
       
   491  * If the FOURCC cannot be represented by #GstVideoFormat,
       
   492  * #GST_VIDEO_FORMAT_UNKNOWN is returned.
       
   493  *
       
   494  * Since: 0.10.16
       
   495  *
       
   496  * Returns: the #GstVideoFormat describing the FOURCC value
       
   497  */
       
   498 #ifdef __SYMBIAN32__
       
   499 EXPORT_C
       
   500 #endif
       
   501 
       
   502 GstVideoFormat
       
   503 gst_video_format_from_fourcc (guint32 fourcc)
       
   504 {
       
   505   switch (fourcc) {
       
   506     case GST_MAKE_FOURCC ('I', '4', '2', '0'):
       
   507       return GST_VIDEO_FORMAT_I420;
       
   508     case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
       
   509       return GST_VIDEO_FORMAT_YV12;
       
   510     case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
       
   511       return GST_VIDEO_FORMAT_YUY2;
       
   512     case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
       
   513       return GST_VIDEO_FORMAT_UYVY;
       
   514     case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
       
   515       return GST_VIDEO_FORMAT_AYUV;
       
   516     case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
       
   517       return GST_VIDEO_FORMAT_Y41B;
       
   518     case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
       
   519       return GST_VIDEO_FORMAT_Y42B;
       
   520     default:
       
   521       return GST_VIDEO_FORMAT_UNKNOWN;
       
   522   }
       
   523 }
       
   524 
       
   525 /**
       
   526  * gst_video_format_to_fourcc:
       
   527  * @format: a #GstVideoFormat video format
       
   528  *
       
   529  * Converts a #GstVideoFormat value into the corresponding FOURCC.  Only
       
   530  * a few YUV formats have corresponding FOURCC values.  If @format has
       
   531  * no corresponding FOURCC value, 0 is returned.
       
   532  *
       
   533  * Since: 0.10.16
       
   534  *
       
   535  * Returns: the FOURCC corresponding to @format
       
   536  */
       
   537 #ifdef __SYMBIAN32__
       
   538 EXPORT_C
       
   539 #endif
       
   540 
       
   541 guint32
       
   542 gst_video_format_to_fourcc (GstVideoFormat format)
       
   543 {
       
   544   switch (format) {
       
   545     case GST_VIDEO_FORMAT_I420:
       
   546       return GST_MAKE_FOURCC ('I', '4', '2', '0');
       
   547     case GST_VIDEO_FORMAT_YV12:
       
   548       return GST_MAKE_FOURCC ('Y', 'V', '1', '2');
       
   549     case GST_VIDEO_FORMAT_YUY2:
       
   550       return GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
       
   551     case GST_VIDEO_FORMAT_UYVY:
       
   552       return GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
       
   553     case GST_VIDEO_FORMAT_AYUV:
       
   554       return GST_MAKE_FOURCC ('A', 'Y', 'U', 'V');
       
   555     case GST_VIDEO_FORMAT_Y41B:
       
   556       return GST_MAKE_FOURCC ('Y', '4', '1', 'B');
       
   557     case GST_VIDEO_FORMAT_Y42B:
       
   558       return GST_MAKE_FOURCC ('Y', '4', '2', 'B');
       
   559     default:
       
   560       return 0;
       
   561   }
       
   562 }
       
   563 
       
   564 /**
       
   565  * gst_video_format_from_rgb32_masks:
       
   566  * @red_mask: red bit mask
       
   567  * @green_mask: green bit mask
       
   568  * @blue_mask: blue bit mask
       
   569  *
       
   570  * Converts red, green, blue bit masks into the corresponding
       
   571  * #GstVideoFormat.  
       
   572  *
       
   573  * Since: 0.10.16
       
   574  *
       
   575  * Returns: the #GstVideoFormat corresponding to the bit masks
       
   576  */
       
   577 static GstVideoFormat
       
   578 gst_video_format_from_rgb32_masks (int red_mask, int green_mask, int blue_mask)
       
   579 {
       
   580   if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
       
   581       blue_mask == 0x0000ff00) {
       
   582     return GST_VIDEO_FORMAT_RGBx;
       
   583   }
       
   584   if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
       
   585       blue_mask == 0xff000000) {
       
   586     return GST_VIDEO_FORMAT_BGRx;
       
   587   }
       
   588   if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
       
   589       blue_mask == 0x000000ff) {
       
   590     return GST_VIDEO_FORMAT_xRGB;
       
   591   }
       
   592   if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
       
   593       blue_mask == 0x00ff0000) {
       
   594     return GST_VIDEO_FORMAT_xBGR;
       
   595   }
       
   596 
       
   597   return GST_VIDEO_FORMAT_UNKNOWN;
       
   598 }
       
   599 
       
   600 static GstVideoFormat
       
   601 gst_video_format_from_rgba32_masks (int red_mask, int green_mask, int blue_mask,
       
   602     int alpha_mask)
       
   603 {
       
   604   if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
       
   605       blue_mask == 0x0000ff00 && alpha_mask == 0x000000ff) {
       
   606     return GST_VIDEO_FORMAT_RGBA;
       
   607   }
       
   608   if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
       
   609       blue_mask == 0xff000000 && alpha_mask == 0x000000ff) {
       
   610     return GST_VIDEO_FORMAT_BGRA;
       
   611   }
       
   612   if (red_mask == 0x00ff0000 && green_mask == 0x0000ff00 &&
       
   613       blue_mask == 0x000000ff && alpha_mask == 0xff000000) {
       
   614     return GST_VIDEO_FORMAT_ARGB;
       
   615   }
       
   616   if (red_mask == 0x000000ff && green_mask == 0x0000ff00 &&
       
   617       blue_mask == 0x00ff0000 && alpha_mask == 0xff000000) {
       
   618     return GST_VIDEO_FORMAT_ABGR;
       
   619   }
       
   620 
       
   621   return GST_VIDEO_FORMAT_UNKNOWN;
       
   622 }
       
   623 
       
   624 static GstVideoFormat
       
   625 gst_video_format_from_rgb24_masks (int red_mask, int green_mask, int blue_mask)
       
   626 {
       
   627   if (red_mask == 0xff0000 && green_mask == 0x00ff00 && blue_mask == 0x0000ff) {
       
   628     return GST_VIDEO_FORMAT_RGB;
       
   629   }
       
   630   if (red_mask == 0x0000ff && green_mask == 0x00ff00 && blue_mask == 0xff0000) {
       
   631     return GST_VIDEO_FORMAT_BGR;
       
   632   }
       
   633 
       
   634   return GST_VIDEO_FORMAT_UNKNOWN;
       
   635 }
       
   636 
       
   637 /**
       
   638  * gst_video_format_is_rgb:
       
   639  * @format: a #GstVideoFormat
       
   640  *
       
   641  * Since: 0.10.16
       
   642  *
       
   643  * Returns: TRUE if @format represents RGB video
       
   644  */
       
   645 #ifdef __SYMBIAN32__
       
   646 EXPORT_C
       
   647 #endif
       
   648 
       
   649 gboolean
       
   650 gst_video_format_is_rgb (GstVideoFormat format)
       
   651 {
       
   652   switch (format) {
       
   653     case GST_VIDEO_FORMAT_I420:
       
   654     case GST_VIDEO_FORMAT_YV12:
       
   655     case GST_VIDEO_FORMAT_YUY2:
       
   656     case GST_VIDEO_FORMAT_UYVY:
       
   657     case GST_VIDEO_FORMAT_AYUV:
       
   658     case GST_VIDEO_FORMAT_Y41B:
       
   659     case GST_VIDEO_FORMAT_Y42B:
       
   660       return FALSE;
       
   661     case GST_VIDEO_FORMAT_RGBx:
       
   662     case GST_VIDEO_FORMAT_BGRx:
       
   663     case GST_VIDEO_FORMAT_xRGB:
       
   664     case GST_VIDEO_FORMAT_xBGR:
       
   665     case GST_VIDEO_FORMAT_RGBA:
       
   666     case GST_VIDEO_FORMAT_BGRA:
       
   667     case GST_VIDEO_FORMAT_ARGB:
       
   668     case GST_VIDEO_FORMAT_ABGR:
       
   669     case GST_VIDEO_FORMAT_RGB:
       
   670     case GST_VIDEO_FORMAT_BGR:
       
   671       return TRUE;
       
   672     default:
       
   673       return FALSE;
       
   674   }
       
   675 }
       
   676 
       
   677 /**
       
   678  * gst_video_format_is_yuv:
       
   679  * @format: a #GstVideoFormat
       
   680  *
       
   681  * Since: 0.10.16
       
   682  *
       
   683  * Returns: TRUE if @format represents YUV video
       
   684  */
       
   685 #ifdef __SYMBIAN32__
       
   686 EXPORT_C
       
   687 #endif
       
   688 
       
   689 gboolean
       
   690 gst_video_format_is_yuv (GstVideoFormat format)
       
   691 {
       
   692   switch (format) {
       
   693     case GST_VIDEO_FORMAT_I420:
       
   694     case GST_VIDEO_FORMAT_YV12:
       
   695     case GST_VIDEO_FORMAT_YUY2:
       
   696     case GST_VIDEO_FORMAT_UYVY:
       
   697     case GST_VIDEO_FORMAT_AYUV:
       
   698     case GST_VIDEO_FORMAT_Y41B:
       
   699     case GST_VIDEO_FORMAT_Y42B:
       
   700       return TRUE;
       
   701     case GST_VIDEO_FORMAT_RGBx:
       
   702     case GST_VIDEO_FORMAT_BGRx:
       
   703     case GST_VIDEO_FORMAT_xRGB:
       
   704     case GST_VIDEO_FORMAT_xBGR:
       
   705     case GST_VIDEO_FORMAT_RGBA:
       
   706     case GST_VIDEO_FORMAT_BGRA:
       
   707     case GST_VIDEO_FORMAT_ARGB:
       
   708     case GST_VIDEO_FORMAT_ABGR:
       
   709     case GST_VIDEO_FORMAT_RGB:
       
   710     case GST_VIDEO_FORMAT_BGR:
       
   711       return FALSE;
       
   712     default:
       
   713       return FALSE;
       
   714   }
       
   715 }
       
   716 
       
   717 /**
       
   718  * gst_video_format_has_alpha:
       
   719  * @format: a #GstVideoFormat
       
   720  *
       
   721  * Since: 0.10.16
       
   722  *
       
   723  * Returns: TRUE if @format has an alpha channel
       
   724  */
       
   725 #ifdef __SYMBIAN32__
       
   726 EXPORT_C
       
   727 #endif
       
   728 
       
   729 gboolean
       
   730 gst_video_format_has_alpha (GstVideoFormat format)
       
   731 {
       
   732   switch (format) {
       
   733     case GST_VIDEO_FORMAT_I420:
       
   734     case GST_VIDEO_FORMAT_YV12:
       
   735     case GST_VIDEO_FORMAT_YUY2:
       
   736     case GST_VIDEO_FORMAT_UYVY:
       
   737     case GST_VIDEO_FORMAT_Y41B:
       
   738     case GST_VIDEO_FORMAT_Y42B:
       
   739       return FALSE;
       
   740     case GST_VIDEO_FORMAT_AYUV:
       
   741     case GST_VIDEO_FORMAT_RGBA:
       
   742     case GST_VIDEO_FORMAT_BGRA:
       
   743     case GST_VIDEO_FORMAT_ARGB:
       
   744     case GST_VIDEO_FORMAT_ABGR:
       
   745       return TRUE;
       
   746     case GST_VIDEO_FORMAT_RGBx:
       
   747     case GST_VIDEO_FORMAT_BGRx:
       
   748     case GST_VIDEO_FORMAT_xRGB:
       
   749     case GST_VIDEO_FORMAT_xBGR:
       
   750     case GST_VIDEO_FORMAT_RGB:
       
   751     case GST_VIDEO_FORMAT_BGR:
       
   752       return FALSE;
       
   753     default:
       
   754       return FALSE;
       
   755   }
       
   756 }
       
   757 
       
   758 /**
       
   759  * gst_video_format_get_row_stride:
       
   760  * @format: a #GstVideoFormat
       
   761  * @component: the component index
       
   762  * @width: the width of video
       
   763  *
       
   764  * Calculates the row stride (number of bytes from one row of pixels to
       
   765  * the next) for the video component with an index of @component.  For
       
   766  * YUV video, Y, U, and V have component indices of 0, 1, and 2,
       
   767  * respectively.  For RGB video, R, G, and B have component indicies of
       
   768  * 0, 1, and 2, respectively.  Alpha channels, if present, have a component
       
   769  * index of 3.  The @width parameter always represents the width of the
       
   770  * video, not the component.
       
   771  *
       
   772  * Since: 0.10.16
       
   773  *
       
   774  * Returns: row stride of component @component
       
   775  */
       
   776 #ifdef __SYMBIAN32__
       
   777 EXPORT_C
       
   778 #endif
       
   779 
       
   780 int
       
   781 gst_video_format_get_row_stride (GstVideoFormat format, int component,
       
   782     int width)
       
   783 {
       
   784   switch (format) {
       
   785     case GST_VIDEO_FORMAT_I420:
       
   786     case GST_VIDEO_FORMAT_YV12:
       
   787       if (component == 0) {
       
   788         return GST_ROUND_UP_4 (width);
       
   789       } else {
       
   790         return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
       
   791       }
       
   792     case GST_VIDEO_FORMAT_YUY2:
       
   793     case GST_VIDEO_FORMAT_UYVY:
       
   794       return GST_ROUND_UP_4 (width * 2);
       
   795     case GST_VIDEO_FORMAT_AYUV:
       
   796     case GST_VIDEO_FORMAT_RGBx:
       
   797     case GST_VIDEO_FORMAT_BGRx:
       
   798     case GST_VIDEO_FORMAT_xRGB:
       
   799     case GST_VIDEO_FORMAT_xBGR:
       
   800     case GST_VIDEO_FORMAT_RGBA:
       
   801     case GST_VIDEO_FORMAT_BGRA:
       
   802     case GST_VIDEO_FORMAT_ARGB:
       
   803     case GST_VIDEO_FORMAT_ABGR:
       
   804       return width * 4;
       
   805     case GST_VIDEO_FORMAT_RGB:
       
   806     case GST_VIDEO_FORMAT_BGR:
       
   807       return GST_ROUND_UP_4 (width * 3);
       
   808     case GST_VIDEO_FORMAT_Y41B:
       
   809       if (component == 0) {
       
   810         return GST_ROUND_UP_4 (width);
       
   811       } else {
       
   812         return GST_ROUND_UP_8 (width) / 4;
       
   813       }
       
   814     case GST_VIDEO_FORMAT_Y42B:
       
   815       if (component == 0) {
       
   816         return GST_ROUND_UP_4 (width);
       
   817       } else {
       
   818         return GST_ROUND_UP_8 (width) / 2;
       
   819       }
       
   820     default:
       
   821       return 0;
       
   822   }
       
   823 }
       
   824 
       
   825 /**
       
   826  * gst_video_format_get_pixel_stride:
       
   827  * @format: a #GstVideoFormat
       
   828  * @component: the component index
       
   829  *
       
   830  * Calculates the pixel stride (number of bytes from one pixel to the
       
   831  * pixel to its immediate left) for the video component with an index
       
   832  * of @component.  See @gst_video_format_get_row_stride for a description
       
   833  * of the component index.
       
   834  *
       
   835  * Since: 0.10.16
       
   836  *
       
   837  * Returns: pixel stride of component @component
       
   838  */
       
   839 #ifdef __SYMBIAN32__
       
   840 EXPORT_C
       
   841 #endif
       
   842 
       
   843 int
       
   844 gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
       
   845 {
       
   846   switch (format) {
       
   847     case GST_VIDEO_FORMAT_I420:
       
   848     case GST_VIDEO_FORMAT_YV12:
       
   849     case GST_VIDEO_FORMAT_Y41B:
       
   850     case GST_VIDEO_FORMAT_Y42B:
       
   851       return 1;
       
   852     case GST_VIDEO_FORMAT_YUY2:
       
   853     case GST_VIDEO_FORMAT_UYVY:
       
   854       if (component == 0) {
       
   855         return 2;
       
   856       } else {
       
   857         return 4;
       
   858       }
       
   859     case GST_VIDEO_FORMAT_AYUV:
       
   860     case GST_VIDEO_FORMAT_RGBx:
       
   861     case GST_VIDEO_FORMAT_BGRx:
       
   862     case GST_VIDEO_FORMAT_xRGB:
       
   863     case GST_VIDEO_FORMAT_xBGR:
       
   864     case GST_VIDEO_FORMAT_RGBA:
       
   865     case GST_VIDEO_FORMAT_BGRA:
       
   866     case GST_VIDEO_FORMAT_ARGB:
       
   867     case GST_VIDEO_FORMAT_ABGR:
       
   868       return 4;
       
   869     case GST_VIDEO_FORMAT_RGB:
       
   870     case GST_VIDEO_FORMAT_BGR:
       
   871       return 3;
       
   872     default:
       
   873       return 0;
       
   874   }
       
   875 }
       
   876 
       
   877 /**
       
   878  * gst_video_format_get_component_width:
       
   879  * @format: a #GstVideoFormat
       
   880  * @component: the component index
       
   881  * @width: the width of video
       
   882  *
       
   883  * Calculates the width of the component.  See
       
   884  * @gst_video_format_get_row_stride for a description
       
   885  * of the component index.
       
   886  *
       
   887  * Since: 0.10.16
       
   888  *
       
   889  * Returns: width of component @component
       
   890  */
       
   891 #ifdef __SYMBIAN32__
       
   892 EXPORT_C
       
   893 #endif
       
   894 
       
   895 int
       
   896 gst_video_format_get_component_width (GstVideoFormat format, int component,
       
   897     int width)
       
   898 {
       
   899   switch (format) {
       
   900     case GST_VIDEO_FORMAT_I420:
       
   901     case GST_VIDEO_FORMAT_YV12:
       
   902     case GST_VIDEO_FORMAT_YUY2:
       
   903     case GST_VIDEO_FORMAT_UYVY:
       
   904       if (component == 0) {
       
   905         return width;
       
   906       } else {
       
   907         return GST_ROUND_UP_2 (width) / 2;
       
   908       }
       
   909     case GST_VIDEO_FORMAT_Y41B:        /* CHECKME: component_width for Y41B */
       
   910       if (component == 0) {
       
   911         return width;
       
   912       } else {
       
   913         return GST_ROUND_UP_8 (width) / 4;
       
   914       }
       
   915     case GST_VIDEO_FORMAT_Y42B:        /* CHECKME: component_width for Y42B */
       
   916       if (component == 0) {
       
   917         return width;
       
   918       } else {
       
   919         return GST_ROUND_UP_8 (width) / 2;
       
   920       }
       
   921     case GST_VIDEO_FORMAT_AYUV:
       
   922     case GST_VIDEO_FORMAT_RGBx:
       
   923     case GST_VIDEO_FORMAT_BGRx:
       
   924     case GST_VIDEO_FORMAT_xRGB:
       
   925     case GST_VIDEO_FORMAT_xBGR:
       
   926     case GST_VIDEO_FORMAT_RGBA:
       
   927     case GST_VIDEO_FORMAT_BGRA:
       
   928     case GST_VIDEO_FORMAT_ARGB:
       
   929     case GST_VIDEO_FORMAT_ABGR:
       
   930     case GST_VIDEO_FORMAT_RGB:
       
   931     case GST_VIDEO_FORMAT_BGR:
       
   932       return width;
       
   933     default:
       
   934       return 0;
       
   935   }
       
   936 }
       
   937 
       
   938 /**
       
   939  * gst_video_format_get_component_height:
       
   940  * @format: a #GstVideoFormat
       
   941  * @component: the component index
       
   942  * @height: the height of video
       
   943  *
       
   944  * Calculates the height of the component.  See
       
   945  * @gst_video_format_get_row_stride for a description
       
   946  * of the component index.
       
   947  *
       
   948  * Since: 0.10.16
       
   949  *
       
   950  * Returns: height of component @component
       
   951  */
       
   952 #ifdef __SYMBIAN32__
       
   953 EXPORT_C
       
   954 #endif
       
   955 
       
   956 int
       
   957 gst_video_format_get_component_height (GstVideoFormat format, int component,
       
   958     int height)
       
   959 {
       
   960   switch (format) {
       
   961     case GST_VIDEO_FORMAT_I420:
       
   962     case GST_VIDEO_FORMAT_YV12:
       
   963       if (component == 0) {
       
   964         return height;
       
   965       } else {
       
   966         return GST_ROUND_UP_2 (height) / 2;
       
   967       }
       
   968     case GST_VIDEO_FORMAT_Y41B:
       
   969     case GST_VIDEO_FORMAT_Y42B:
       
   970     case GST_VIDEO_FORMAT_YUY2:
       
   971     case GST_VIDEO_FORMAT_UYVY:
       
   972     case GST_VIDEO_FORMAT_AYUV:
       
   973     case GST_VIDEO_FORMAT_RGBx:
       
   974     case GST_VIDEO_FORMAT_BGRx:
       
   975     case GST_VIDEO_FORMAT_xRGB:
       
   976     case GST_VIDEO_FORMAT_xBGR:
       
   977     case GST_VIDEO_FORMAT_RGBA:
       
   978     case GST_VIDEO_FORMAT_BGRA:
       
   979     case GST_VIDEO_FORMAT_ARGB:
       
   980     case GST_VIDEO_FORMAT_ABGR:
       
   981     case GST_VIDEO_FORMAT_RGB:
       
   982     case GST_VIDEO_FORMAT_BGR:
       
   983       return height;
       
   984     default:
       
   985       return 0;
       
   986   }
       
   987 }
       
   988 
       
   989 /**
       
   990  * gst_video_format_get_component_offset:
       
   991  * @format: a #GstVideoFormat
       
   992  * @component: the component index
       
   993  * @width: the width of video
       
   994  * @height: the height of video
       
   995  *
       
   996  * Calculates the offset (in bytes) of the first pixel of the component
       
   997  * with index @component.  For packed formats, this will typically be a
       
   998  * small integer (0, 1, 2, 3).  For planar formats, this will be a
       
   999  * (relatively) large offset to the beginning of the second or third
       
  1000  * component planes.  See @gst_video_format_get_row_stride for a description
       
  1001  * of the component index.
       
  1002  *
       
  1003  * Since: 0.10.16
       
  1004  *
       
  1005  * Returns: offset of component @component
       
  1006  */
       
  1007 #ifdef __SYMBIAN32__
       
  1008 EXPORT_C
       
  1009 #endif
       
  1010 
       
  1011 int
       
  1012 gst_video_format_get_component_offset (GstVideoFormat format, int component,
       
  1013     int width, int height)
       
  1014 {
       
  1015   switch (format) {
       
  1016     case GST_VIDEO_FORMAT_I420:
       
  1017       if (component == 0)
       
  1018         return 0;
       
  1019       if (component == 1)
       
  1020         return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
       
  1021       if (component == 2) {
       
  1022         return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
       
  1023             GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
       
  1024             (GST_ROUND_UP_2 (height) / 2);
       
  1025       }
       
  1026       return 0;
       
  1027     case GST_VIDEO_FORMAT_YV12:        /* same as I420, but components 1+2 swapped */
       
  1028       if (component == 0)
       
  1029         return 0;
       
  1030       if (component == 2)
       
  1031         return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
       
  1032       if (component == 1) {
       
  1033         return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) +
       
  1034             GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
       
  1035             (GST_ROUND_UP_2 (height) / 2);
       
  1036       }
       
  1037       return 0;
       
  1038     case GST_VIDEO_FORMAT_YUY2:
       
  1039       if (component == 0)
       
  1040         return 0;
       
  1041       if (component == 1)
       
  1042         return 1;
       
  1043       if (component == 2)
       
  1044         return 3;
       
  1045       return 0;
       
  1046     case GST_VIDEO_FORMAT_UYVY:
       
  1047       if (component == 0)
       
  1048         return 1;
       
  1049       if (component == 1)
       
  1050         return 0;
       
  1051       if (component == 2)
       
  1052         return 2;
       
  1053       return 0;
       
  1054     case GST_VIDEO_FORMAT_AYUV:
       
  1055       if (component == 0)
       
  1056         return 1;
       
  1057       if (component == 1)
       
  1058         return 2;
       
  1059       if (component == 2)
       
  1060         return 3;
       
  1061       if (component == 3)
       
  1062         return 0;
       
  1063       return 0;
       
  1064     case GST_VIDEO_FORMAT_RGBx:
       
  1065     case GST_VIDEO_FORMAT_RGBA:
       
  1066       if (component == 0)
       
  1067         return 0;
       
  1068       if (component == 1)
       
  1069         return 1;
       
  1070       if (component == 2)
       
  1071         return 2;
       
  1072       if (component == 3)
       
  1073         return 3;
       
  1074       return 0;
       
  1075     case GST_VIDEO_FORMAT_BGRx:
       
  1076     case GST_VIDEO_FORMAT_BGRA:
       
  1077       if (component == 0)
       
  1078         return 2;
       
  1079       if (component == 1)
       
  1080         return 1;
       
  1081       if (component == 2)
       
  1082         return 0;
       
  1083       if (component == 3)
       
  1084         return 3;
       
  1085       return 0;
       
  1086     case GST_VIDEO_FORMAT_xRGB:
       
  1087     case GST_VIDEO_FORMAT_ARGB:
       
  1088       if (component == 0)
       
  1089         return 1;
       
  1090       if (component == 1)
       
  1091         return 2;
       
  1092       if (component == 2)
       
  1093         return 3;
       
  1094       if (component == 3)
       
  1095         return 0;
       
  1096       return 0;
       
  1097     case GST_VIDEO_FORMAT_xBGR:
       
  1098     case GST_VIDEO_FORMAT_ABGR:
       
  1099       if (component == 0)
       
  1100         return 3;
       
  1101       if (component == 1)
       
  1102         return 2;
       
  1103       if (component == 2)
       
  1104         return 1;
       
  1105       if (component == 3)
       
  1106         return 0;
       
  1107       return 0;
       
  1108     case GST_VIDEO_FORMAT_RGB:
       
  1109       if (component == 0)
       
  1110         return 0;
       
  1111       if (component == 1)
       
  1112         return 1;
       
  1113       if (component == 2)
       
  1114         return 2;
       
  1115       return 0;
       
  1116     case GST_VIDEO_FORMAT_BGR:
       
  1117       if (component == 0)
       
  1118         return 2;
       
  1119       if (component == 1)
       
  1120         return 1;
       
  1121       if (component == 2)
       
  1122         return 0;
       
  1123       return 0;
       
  1124     case GST_VIDEO_FORMAT_Y41B:
       
  1125       if (component == 0)
       
  1126         return 0;
       
  1127       if (component == 1)
       
  1128         return GST_ROUND_UP_4 (width) * height;
       
  1129       if (component == 2)
       
  1130         return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_8 (width) / 4)) * height;
       
  1131       return 0;
       
  1132     case GST_VIDEO_FORMAT_Y42B:
       
  1133       if (component == 0)
       
  1134         return 0;
       
  1135       if (component == 1)
       
  1136         return GST_ROUND_UP_4 (width) * height;
       
  1137       if (component == 2)
       
  1138         return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_8 (width) / 2)) * height;
       
  1139       return 0;
       
  1140     default:
       
  1141       return 0;
       
  1142   }
       
  1143 }
       
  1144 
       
  1145 /**
       
  1146  * gst_video_format_get_size:
       
  1147  * @format: a #GstVideoFormat
       
  1148  * @width: the width of video
       
  1149  * @height: the height of video
       
  1150  *
       
  1151  * Calculates the total number of bytes in the raw video format.  This
       
  1152  * number should be used when allocating a buffer for raw video.
       
  1153  *
       
  1154  * Since: 0.10.16
       
  1155  *
       
  1156  * Returns: size (in bytes) of raw video format
       
  1157  */
       
  1158 #ifdef __SYMBIAN32__
       
  1159 EXPORT_C
       
  1160 #endif
       
  1161 
       
  1162 int
       
  1163 gst_video_format_get_size (GstVideoFormat format, int width, int height)
       
  1164 {
       
  1165   int size;
       
  1166 
       
  1167   switch (format) {
       
  1168     case GST_VIDEO_FORMAT_I420:
       
  1169     case GST_VIDEO_FORMAT_YV12:
       
  1170       size = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
       
  1171       size += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
       
  1172           (GST_ROUND_UP_2 (height) / 2) * 2;
       
  1173       return size;
       
  1174     case GST_VIDEO_FORMAT_YUY2:
       
  1175     case GST_VIDEO_FORMAT_UYVY:
       
  1176       return GST_ROUND_UP_4 (width * 2) * height;
       
  1177     case GST_VIDEO_FORMAT_AYUV:
       
  1178     case GST_VIDEO_FORMAT_RGBx:
       
  1179     case GST_VIDEO_FORMAT_BGRx:
       
  1180     case GST_VIDEO_FORMAT_xRGB:
       
  1181     case GST_VIDEO_FORMAT_xBGR:
       
  1182     case GST_VIDEO_FORMAT_RGBA:
       
  1183     case GST_VIDEO_FORMAT_BGRA:
       
  1184     case GST_VIDEO_FORMAT_ARGB:
       
  1185     case GST_VIDEO_FORMAT_ABGR:
       
  1186       return width * 4 * height;
       
  1187     case GST_VIDEO_FORMAT_RGB:
       
  1188     case GST_VIDEO_FORMAT_BGR:
       
  1189       return GST_ROUND_UP_4 (width * 3) * height;
       
  1190     case GST_VIDEO_FORMAT_Y41B:
       
  1191       /* simplification of ROUNDUP4(w)*h + 2*((ROUNDUP8(w)/4)*h */
       
  1192       return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_8 (width) / 2)) * height;
       
  1193     case GST_VIDEO_FORMAT_Y42B:
       
  1194       /* simplification of ROUNDUP4(w)*h + 2*(ROUNDUP8(w)/2)*h: */
       
  1195       return (GST_ROUND_UP_4 (width) + GST_ROUND_UP_8 (width)) * height;
       
  1196     default:
       
  1197       return 0;
       
  1198   }
       
  1199 }
       
  1200 
       
  1201 /**
       
  1202  * gst_video_format_convert:
       
  1203  * @format: a #GstVideoFormat
       
  1204  * @width: the width of video
       
  1205  * @height: the height of video
       
  1206  * @fps_n: frame rate numerator
       
  1207  * @fps_d: frame rate denominator
       
  1208  * @src_format: #GstFormat of the @src_value
       
  1209  * @src_value: value to convert
       
  1210  * @dest_format: #GstFormat of the @dest_value
       
  1211  * @dest_value: pointer to destination value
       
  1212  *
       
  1213  * Converts among various #GstFormat types.  This function handles
       
  1214  * GST_FORMAT_BYTES, GST_FORMAT_TIME, and GST_FORMAT_DEFAULT.  For
       
  1215  * raw video, GST_FORMAT_DEFAULT corresponds to video frames.  This
       
  1216  * function can be to handle pad queries of the type GST_QUERY_CONVERT.
       
  1217  *
       
  1218  * Since: 0.10.16
       
  1219  *
       
  1220  * Returns: TRUE if the conversion was successful.
       
  1221  */
       
  1222 #ifdef __SYMBIAN32__
       
  1223 EXPORT_C
       
  1224 #endif
       
  1225 
       
  1226 gboolean
       
  1227 gst_video_format_convert (GstVideoFormat format, int width, int height,
       
  1228     int fps_n, int fps_d,
       
  1229     GstFormat src_format, gint64 src_value,
       
  1230     GstFormat dest_format, gint64 * dest_value)
       
  1231 {
       
  1232   gboolean ret = FALSE;
       
  1233   int size;
       
  1234 
       
  1235   size = gst_video_format_get_size (format, width, height);
       
  1236 
       
  1237   GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
       
  1238       src_value, gst_format_get_name (src_format),
       
  1239       gst_format_get_name (dest_format));
       
  1240 
       
  1241   if (src_format == dest_format) {
       
  1242     *dest_value = src_value;
       
  1243     ret = TRUE;
       
  1244     goto done;
       
  1245   }
       
  1246 
       
  1247   if (src_value == -1) {
       
  1248     *dest_value = -1;
       
  1249     ret = TRUE;
       
  1250     goto done;
       
  1251   }
       
  1252 
       
  1253   /* bytes to frames */
       
  1254   if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_DEFAULT) {
       
  1255     if (size != 0) {
       
  1256       *dest_value = gst_util_uint64_scale_int (src_value, 1, size);
       
  1257     } else {
       
  1258       GST_ERROR ("blocksize is 0");
       
  1259       *dest_value = 0;
       
  1260     }
       
  1261     ret = TRUE;
       
  1262     goto done;
       
  1263   }
       
  1264 
       
  1265   /* frames to bytes */
       
  1266   if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_BYTES) {
       
  1267     *dest_value = gst_util_uint64_scale_int (src_value, size, 1);
       
  1268     ret = TRUE;
       
  1269     goto done;
       
  1270   }
       
  1271 
       
  1272   /* time to frames */
       
  1273   if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_DEFAULT) {
       
  1274     if (fps_d != 0) {
       
  1275       *dest_value = gst_util_uint64_scale (src_value,
       
  1276           fps_n, GST_SECOND * fps_d);
       
  1277     } else {
       
  1278       GST_ERROR ("framerate denominator is 0");
       
  1279       *dest_value = 0;
       
  1280     }
       
  1281     ret = TRUE;
       
  1282     goto done;
       
  1283   }
       
  1284 
       
  1285   /* frames to time */
       
  1286   if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_TIME) {
       
  1287     if (fps_n != 0) {
       
  1288       *dest_value = gst_util_uint64_scale (src_value,
       
  1289           GST_SECOND * fps_d, fps_n);
       
  1290     } else {
       
  1291       GST_ERROR ("framerate numerator is 0");
       
  1292       *dest_value = 0;
       
  1293     }
       
  1294     ret = TRUE;
       
  1295     goto done;
       
  1296   }
       
  1297 
       
  1298   /* time to bytes */
       
  1299   if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
       
  1300     if (fps_d != 0) {
       
  1301       *dest_value = gst_util_uint64_scale (src_value,
       
  1302           fps_n * size, GST_SECOND * fps_d);
       
  1303     } else {
       
  1304       GST_ERROR ("framerate denominator is 0");
       
  1305       *dest_value = 0;
       
  1306     }
       
  1307     ret = TRUE;
       
  1308     goto done;
       
  1309   }
       
  1310 
       
  1311   /* bytes to time */
       
  1312   if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_TIME) {
       
  1313     if (fps_n != 0 && size != 0) {
       
  1314       *dest_value = gst_util_uint64_scale (src_value,
       
  1315           GST_SECOND * fps_d, fps_n * size);
       
  1316     } else {
       
  1317       GST_ERROR ("framerate denominator and/or blocksize is 0");
       
  1318       *dest_value = 0;
       
  1319     }
       
  1320     ret = TRUE;
       
  1321   }
       
  1322 
       
  1323 done:
       
  1324 
       
  1325   GST_DEBUG ("ret=%d result %" G_GINT64_FORMAT, ret, *dest_value);
       
  1326 
       
  1327   return ret;
       
  1328 }