gst_plugins_base/gst-libs/gst/video/video.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
    43     int green_mask, int blue_mask, int alpha_mask);
    43     int green_mask, int blue_mask, int alpha_mask);
    44 static GstVideoFormat gst_video_format_from_rgb24_masks (int red_mask,
    44 static GstVideoFormat gst_video_format_from_rgb24_masks (int red_mask,
    45     int green_mask, int blue_mask);
    45     int green_mask, int blue_mask);
    46 
    46 
    47 
    47 
    48 /**
    48 /* This is simply a convenience function, nothing more or less */
    49  * gst_video_frame_rate:
       
    50  * @pad: pointer to a #GstPad
       
    51  *
       
    52  * A convenience function to retrieve a GValue holding the framerate
       
    53  * from the caps on a pad.
       
    54  * 
       
    55  * The pad needs to have negotiated caps containing a framerate property.
       
    56  *
       
    57  * Returns: NULL if the pad has no configured caps or the configured caps
       
    58  * do not contain a framerate.
       
    59  *
       
    60  */
       
    61 #ifdef __SYMBIAN32__
    49 #ifdef __SYMBIAN32__
    62 EXPORT_C
    50 EXPORT_C
    63 #endif
    51 #endif
    64 
    52 
    65 const GValue *
    53 const GValue *
    97       GST_DEBUG_PAD_NAME (pad), fps_string);
    85       GST_DEBUG_PAD_NAME (pad), fps_string);
    98   g_free (fps_string);
    86   g_free (fps_string);
    99 
    87 
   100   return fps;
    88   return fps;
   101 }
    89 }
   102 
    90 #ifdef __SYMBIAN32__
   103 /**
    91 EXPORT_C
   104  * gst_video_get_size:
    92 #endif
   105  * @pad: pointer to a #GstPad
    93 
   106  * @width: pointer to integer to hold pixel width of the video frames (output)
       
   107  * @height: pointer to integer to hold pixel height of the video frames (output)
       
   108  *
       
   109  * Inspect the caps of the provided pad and retrieve the width and height of
       
   110  * the video frames it is configured for.
       
   111  * 
       
   112  * The pad needs to have negotiated caps containing width and height properties.
       
   113  *
       
   114  * Returns: TRUE if the width and height could be retrieved.
       
   115  *
       
   116  */
       
   117 #ifdef __SYMBIAN32__
       
   118 EXPORT_C
       
   119 #endif
       
   120 
    94 
   121 gboolean
    95 gboolean
   122 gst_video_get_size (GstPad * pad, gint * width, gint * height)
    96 gst_video_get_size (GstPad * pad, gint * width, gint * height)
   123 {
    97 {
   124   const GstCaps *caps = NULL;
    98   const GstCaps *caps = NULL;
   230   g_value_unset (&tmp2);
   204   g_value_unset (&tmp2);
   231   return FALSE;
   205   return FALSE;
   232 }
   206 }
   233 
   207 
   234 /**
   208 /**
   235  * gst_video_format_parse_caps_interlaced:
       
   236  * @caps: the fixed #GstCaps to parse
       
   237  * @interlaced: whether @caps represents interlaced video or not, may be NULL (output)
       
   238  *
       
   239  * Extracts whether the caps represents interlaced content or not and places it
       
   240  * in @interlaced.
       
   241  *
       
   242  * Since: 0.10.23
       
   243  *
       
   244  * Returns: TRUE if @caps was parsed correctly.
       
   245  */
       
   246 #ifdef __SYMBIAN32__
       
   247 EXPORT_C
       
   248 #endif
       
   249 
       
   250 gboolean
       
   251 gst_video_format_parse_caps_interlaced (GstCaps * caps, gboolean * interlaced)
       
   252 {
       
   253   GstStructure *structure;
       
   254 
       
   255   if (!gst_caps_is_fixed (caps))
       
   256     return FALSE;
       
   257 
       
   258   structure = gst_caps_get_structure (caps, 0);
       
   259 
       
   260   if (interlaced) {
       
   261     if (!gst_structure_get_boolean (structure, "interlaced", interlaced))
       
   262       *interlaced = FALSE;
       
   263   }
       
   264 
       
   265   return TRUE;
       
   266 }
       
   267 
       
   268 /**
       
   269  * gst_video_format_parse_caps:
   209  * gst_video_format_parse_caps:
   270  * @caps: the #GstCaps to parse
   210  * @caps: the #GstCaps to parse
   271  * @format: the #GstVideoFormat of the video represented by @caps (output)
   211  * @format: the #GstVideoFormat of the video represented by @caps (output)
   272  * @width: the width of the video represented by @caps, may be NULL (output)
   212  * @width: the width of the video represented by @caps (output)
   273  * @height: the height of the video represented by @caps, may be NULL (output)
   213  * @height: the height of the video represented by @caps (output)
   274  *
   214  *
   275  * Determines the #GstVideoFormat of @caps and places it in the location
   215  * Determines the #GstVideoFormat of @caps and places it in the location
   276  * pointed to by @format.  Extracts the size of the video and places it
   216  * pointed to by @format.  Extracts the size of the video and places it
   277  * in the location pointed to by @width and @height.  If @caps does not
   217  * in the location pointed to by @width and @height.  If @caps does not
   278  * represent one of the raw video formats listed in #GstVideoFormat, the
   218  * represent one of the raw video formats listed in #GstVideoFormat, the
   362   }
   302   }
   363 
   303 
   364   return ok;
   304   return ok;
   365 }
   305 }
   366 
   306 
   367 
       
   368 /**
   307 /**
   369  * gst_video_parse_caps_framerate:
   308  * gst_video_parse_caps_framerate:
   370  * @caps: pointer to a #GstCaps instance
   309  * @caps:
   371  * @fps_n: pointer to integer to hold numerator of frame rate (output)
   310  * @fps_n: pointer to numerator of frame rate (output)
   372  * @fps_d: pointer to integer to hold denominator of frame rate (output)
   311  * @fps_d: pointer to denominator of frame rate (output)
   373  *
   312  *
   374  * Extracts the frame rate from @caps and places the values in the locations
   313  * Extracts the frame rate from @caps and places the values in the locations
   375  * pointed to by @fps_n and @fps_d.  Returns TRUE if the values could be
   314  * pointed to by @fps_n and @fps_d.  Returns TRUE if the values could be
   376  * parsed correctly, FALSE if not.
   315  * parsed correctly, FALSE if not.
   377  *
   316  *
   399   return gst_structure_get_fraction (structure, "framerate", fps_n, fps_d);
   338   return gst_structure_get_fraction (structure, "framerate", fps_n, fps_d);
   400 }
   339 }
   401 
   340 
   402 /**
   341 /**
   403  * gst_video_parse_caps_pixel_aspect_ratio:
   342  * gst_video_parse_caps_pixel_aspect_ratio:
   404  * @caps: pointer to a #GstCaps instance
   343  * @caps:
   405  * @par_n: pointer to numerator of pixel aspect ratio (output)
   344  * @par_n: pointer to numerator of pixel aspect ratio (output)
   406  * @par_d: pointer to denominator of pixel aspect ratio (output)
   345  * @par_d: pointer to denominator of pixel aspect ratio (output)
   407  *
   346  *
   408  * Extracts the pixel aspect ratio from @caps and places the values in
   347  * Extracts the pixel aspect ratio from @caps and places the values in
   409  * the locations pointed to by @par_n and @par_d.  Returns TRUE if the
   348  * the locations pointed to by @par_n and @par_d.  Returns TRUE if the
   434           par_n, par_d)) {
   373           par_n, par_d)) {
   435     *par_n = 1;
   374     *par_n = 1;
   436     *par_d = 1;
   375     *par_d = 1;
   437   }
   376   }
   438   return TRUE;
   377   return TRUE;
   439 }
       
   440 
       
   441 /**
       
   442  * gst_video_format_new_caps_interlaced:
       
   443  * @format: the #GstVideoFormat describing the raw video format
       
   444  * @width: width of video
       
   445  * @height: height of video
       
   446  * @framerate_n: numerator of frame rate
       
   447  * @framerate_d: denominator of frame rate
       
   448  * @par_n: numerator of pixel aspect ratio
       
   449  * @par_d: denominator of pixel aspect ratio
       
   450  * @interlaced: #TRUE if the format is interlaced
       
   451  *
       
   452  * Creates a new #GstCaps object based on the parameters provided.
       
   453  *
       
   454  * Since: 0.10.23
       
   455  *
       
   456  * Returns: a new #GstCaps object, or NULL if there was an error
       
   457  */
       
   458 #ifdef __SYMBIAN32__
       
   459 EXPORT_C
       
   460 #endif
       
   461 
       
   462 GstCaps *
       
   463 gst_video_format_new_caps_interlaced (GstVideoFormat format, int width,
       
   464     int height, int framerate_n, int framerate_d, int par_n, int par_d,
       
   465     gboolean interlaced)
       
   466 {
       
   467   GstCaps *res;
       
   468 
       
   469   res =
       
   470       gst_video_format_new_caps (format, width, height, framerate_n,
       
   471       framerate_d, par_n, par_d);
       
   472   if (interlaced && (res != NULL))
       
   473     gst_caps_set_simple (res, "interlaced", G_TYPE_BOOLEAN, TRUE, NULL);
       
   474 
       
   475   return res;
       
   476 }
   378 }
   477 
   379 
   478 /**
   380 /**
   479  * gst_video_format_new_caps:
   381  * gst_video_format_new_caps:
   480  * @format: the #GstVideoFormat describing the raw video format
   382  * @format: the #GstVideoFormat describing the raw video format
   497 
   399 
   498 GstCaps *
   400 GstCaps *
   499 gst_video_format_new_caps (GstVideoFormat format, int width, int height,
   401 gst_video_format_new_caps (GstVideoFormat format, int width, int height,
   500     int framerate_n, int framerate_d, int par_n, int par_d)
   402     int framerate_n, int framerate_d, int par_n, int par_d)
   501 {
   403 {
   502   g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
       
   503   g_return_val_if_fail (width > 0 && height > 0, NULL);
       
   504 
       
   505   if (gst_video_format_is_yuv (format)) {
   404   if (gst_video_format_is_yuv (format)) {
   506     return gst_caps_new_simple ("video/x-raw-yuv",
   405     return gst_caps_new_simple ("video/x-raw-yuv",
   507         "format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format),
   406         "format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format),
   508         "width", G_TYPE_INT, width,
   407         "width", G_TYPE_INT, width,
   509         "height", G_TYPE_INT, height,
   408         "height", G_TYPE_INT, height,
   608       return GST_VIDEO_FORMAT_I420;
   507       return GST_VIDEO_FORMAT_I420;
   609     case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
   508     case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
   610       return GST_VIDEO_FORMAT_YV12;
   509       return GST_VIDEO_FORMAT_YV12;
   611     case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
   510     case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
   612       return GST_VIDEO_FORMAT_YUY2;
   511       return GST_VIDEO_FORMAT_YUY2;
   613     case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'):
       
   614       return GST_VIDEO_FORMAT_YVYU;
       
   615     case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
   512     case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
   616       return GST_VIDEO_FORMAT_UYVY;
   513       return GST_VIDEO_FORMAT_UYVY;
   617     case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
   514     case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
   618       return GST_VIDEO_FORMAT_AYUV;
   515       return GST_VIDEO_FORMAT_AYUV;
   619     case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
   516     case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
   620       return GST_VIDEO_FORMAT_Y41B;
   517       return GST_VIDEO_FORMAT_Y41B;
   621     case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
   518     case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
   622       return GST_VIDEO_FORMAT_Y42B;
   519       return GST_VIDEO_FORMAT_Y42B;
   623     case GST_MAKE_FOURCC ('Y', '4', '4', '4'):
       
   624       return GST_VIDEO_FORMAT_Y444;
       
   625     case GST_MAKE_FOURCC ('v', '2', '1', '0'):
       
   626       return GST_VIDEO_FORMAT_v210;
       
   627     case GST_MAKE_FOURCC ('v', '2', '1', '6'):
       
   628       return GST_VIDEO_FORMAT_v216;
       
   629     default:
   520     default:
   630       return GST_VIDEO_FORMAT_UNKNOWN;
   521       return GST_VIDEO_FORMAT_UNKNOWN;
   631   }
   522   }
   632 }
   523 }
   633 
   524 
   648 #endif
   539 #endif
   649 
   540 
   650 guint32
   541 guint32
   651 gst_video_format_to_fourcc (GstVideoFormat format)
   542 gst_video_format_to_fourcc (GstVideoFormat format)
   652 {
   543 {
   653   g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
       
   654 
       
   655   switch (format) {
   544   switch (format) {
   656     case GST_VIDEO_FORMAT_I420:
   545     case GST_VIDEO_FORMAT_I420:
   657       return GST_MAKE_FOURCC ('I', '4', '2', '0');
   546       return GST_MAKE_FOURCC ('I', '4', '2', '0');
   658     case GST_VIDEO_FORMAT_YV12:
   547     case GST_VIDEO_FORMAT_YV12:
   659       return GST_MAKE_FOURCC ('Y', 'V', '1', '2');
   548       return GST_MAKE_FOURCC ('Y', 'V', '1', '2');
   660     case GST_VIDEO_FORMAT_YUY2:
   549     case GST_VIDEO_FORMAT_YUY2:
   661       return GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
   550       return GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
   662     case GST_VIDEO_FORMAT_YVYU:
       
   663       return GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U');
       
   664     case GST_VIDEO_FORMAT_UYVY:
   551     case GST_VIDEO_FORMAT_UYVY:
   665       return GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
   552       return GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
   666     case GST_VIDEO_FORMAT_AYUV:
   553     case GST_VIDEO_FORMAT_AYUV:
   667       return GST_MAKE_FOURCC ('A', 'Y', 'U', 'V');
   554       return GST_MAKE_FOURCC ('A', 'Y', 'U', 'V');
   668     case GST_VIDEO_FORMAT_Y41B:
   555     case GST_VIDEO_FORMAT_Y41B:
   669       return GST_MAKE_FOURCC ('Y', '4', '1', 'B');
   556       return GST_MAKE_FOURCC ('Y', '4', '1', 'B');
   670     case GST_VIDEO_FORMAT_Y42B:
   557     case GST_VIDEO_FORMAT_Y42B:
   671       return GST_MAKE_FOURCC ('Y', '4', '2', 'B');
   558       return GST_MAKE_FOURCC ('Y', '4', '2', 'B');
   672     case GST_VIDEO_FORMAT_Y444:
       
   673       return GST_MAKE_FOURCC ('Y', '4', '4', '4');
       
   674     case GST_VIDEO_FORMAT_v210:
       
   675       return GST_MAKE_FOURCC ('v', '2', '1', '0');
       
   676     case GST_VIDEO_FORMAT_v216:
       
   677       return GST_MAKE_FOURCC ('v', '2', '1', '6');
       
   678     default:
   559     default:
   679       return 0;
   560       return 0;
   680   }
   561   }
   681 }
   562 }
   682 
   563 
   683 /*
   564 /**
   684  * gst_video_format_from_rgb32_masks:
   565  * gst_video_format_from_rgb32_masks:
   685  * @red_mask: red bit mask
   566  * @red_mask: red bit mask
   686  * @green_mask: green bit mask
   567  * @green_mask: green bit mask
   687  * @blue_mask: blue bit mask
   568  * @blue_mask: blue bit mask
   688  *
   569  *
   755 
   636 
   756 /**
   637 /**
   757  * gst_video_format_is_rgb:
   638  * gst_video_format_is_rgb:
   758  * @format: a #GstVideoFormat
   639  * @format: a #GstVideoFormat
   759  *
   640  *
   760  * Determine whether the video format is an RGB format.
       
   761  *
       
   762  * Since: 0.10.16
   641  * Since: 0.10.16
   763  *
   642  *
   764  * Returns: TRUE if @format represents RGB video
   643  * Returns: TRUE if @format represents RGB video
   765  */
   644  */
   766 #ifdef __SYMBIAN32__
   645 #ifdef __SYMBIAN32__
   772 {
   651 {
   773   switch (format) {
   652   switch (format) {
   774     case GST_VIDEO_FORMAT_I420:
   653     case GST_VIDEO_FORMAT_I420:
   775     case GST_VIDEO_FORMAT_YV12:
   654     case GST_VIDEO_FORMAT_YV12:
   776     case GST_VIDEO_FORMAT_YUY2:
   655     case GST_VIDEO_FORMAT_YUY2:
   777     case GST_VIDEO_FORMAT_YVYU:
       
   778     case GST_VIDEO_FORMAT_UYVY:
   656     case GST_VIDEO_FORMAT_UYVY:
   779     case GST_VIDEO_FORMAT_AYUV:
   657     case GST_VIDEO_FORMAT_AYUV:
   780     case GST_VIDEO_FORMAT_Y41B:
   658     case GST_VIDEO_FORMAT_Y41B:
   781     case GST_VIDEO_FORMAT_Y42B:
   659     case GST_VIDEO_FORMAT_Y42B:
   782     case GST_VIDEO_FORMAT_Y444:
       
   783     case GST_VIDEO_FORMAT_v210:
       
   784     case GST_VIDEO_FORMAT_v216:
       
   785       return FALSE;
   660       return FALSE;
   786     case GST_VIDEO_FORMAT_RGBx:
   661     case GST_VIDEO_FORMAT_RGBx:
   787     case GST_VIDEO_FORMAT_BGRx:
   662     case GST_VIDEO_FORMAT_BGRx:
   788     case GST_VIDEO_FORMAT_xRGB:
   663     case GST_VIDEO_FORMAT_xRGB:
   789     case GST_VIDEO_FORMAT_xBGR:
   664     case GST_VIDEO_FORMAT_xBGR:
   801 
   676 
   802 /**
   677 /**
   803  * gst_video_format_is_yuv:
   678  * gst_video_format_is_yuv:
   804  * @format: a #GstVideoFormat
   679  * @format: a #GstVideoFormat
   805  *
   680  *
   806  * Determine whether the video format is a YUV format.
       
   807  *
       
   808  * Since: 0.10.16
   681  * Since: 0.10.16
   809  *
   682  *
   810  * Returns: TRUE if @format represents YUV video
   683  * Returns: TRUE if @format represents YUV video
   811  */
   684  */
   812 #ifdef __SYMBIAN32__
   685 #ifdef __SYMBIAN32__
   818 {
   691 {
   819   switch (format) {
   692   switch (format) {
   820     case GST_VIDEO_FORMAT_I420:
   693     case GST_VIDEO_FORMAT_I420:
   821     case GST_VIDEO_FORMAT_YV12:
   694     case GST_VIDEO_FORMAT_YV12:
   822     case GST_VIDEO_FORMAT_YUY2:
   695     case GST_VIDEO_FORMAT_YUY2:
   823     case GST_VIDEO_FORMAT_YVYU:
       
   824     case GST_VIDEO_FORMAT_UYVY:
   696     case GST_VIDEO_FORMAT_UYVY:
   825     case GST_VIDEO_FORMAT_AYUV:
   697     case GST_VIDEO_FORMAT_AYUV:
   826     case GST_VIDEO_FORMAT_Y41B:
   698     case GST_VIDEO_FORMAT_Y41B:
   827     case GST_VIDEO_FORMAT_Y42B:
   699     case GST_VIDEO_FORMAT_Y42B:
   828     case GST_VIDEO_FORMAT_Y444:
       
   829     case GST_VIDEO_FORMAT_v210:
       
   830     case GST_VIDEO_FORMAT_v216:
       
   831       return TRUE;
   700       return TRUE;
   832     case GST_VIDEO_FORMAT_RGBx:
   701     case GST_VIDEO_FORMAT_RGBx:
   833     case GST_VIDEO_FORMAT_BGRx:
   702     case GST_VIDEO_FORMAT_BGRx:
   834     case GST_VIDEO_FORMAT_xRGB:
   703     case GST_VIDEO_FORMAT_xRGB:
   835     case GST_VIDEO_FORMAT_xBGR:
   704     case GST_VIDEO_FORMAT_xBGR:
   846 }
   715 }
   847 
   716 
   848 /**
   717 /**
   849  * gst_video_format_has_alpha:
   718  * gst_video_format_has_alpha:
   850  * @format: a #GstVideoFormat
   719  * @format: a #GstVideoFormat
   851  * 
       
   852  * Returns TRUE or FALSE depending on if the video format provides an
       
   853  * alpha channel.
       
   854  *
   720  *
   855  * Since: 0.10.16
   721  * Since: 0.10.16
   856  *
   722  *
   857  * Returns: TRUE if @format has an alpha channel
   723  * Returns: TRUE if @format has an alpha channel
   858  */
   724  */
   865 {
   731 {
   866   switch (format) {
   732   switch (format) {
   867     case GST_VIDEO_FORMAT_I420:
   733     case GST_VIDEO_FORMAT_I420:
   868     case GST_VIDEO_FORMAT_YV12:
   734     case GST_VIDEO_FORMAT_YV12:
   869     case GST_VIDEO_FORMAT_YUY2:
   735     case GST_VIDEO_FORMAT_YUY2:
   870     case GST_VIDEO_FORMAT_YVYU:
       
   871     case GST_VIDEO_FORMAT_UYVY:
   736     case GST_VIDEO_FORMAT_UYVY:
   872     case GST_VIDEO_FORMAT_Y41B:
   737     case GST_VIDEO_FORMAT_Y41B:
   873     case GST_VIDEO_FORMAT_Y42B:
   738     case GST_VIDEO_FORMAT_Y42B:
   874     case GST_VIDEO_FORMAT_Y444:
       
   875     case GST_VIDEO_FORMAT_v210:
       
   876     case GST_VIDEO_FORMAT_v216:
       
   877       return FALSE;
   739       return FALSE;
   878     case GST_VIDEO_FORMAT_AYUV:
   740     case GST_VIDEO_FORMAT_AYUV:
   879     case GST_VIDEO_FORMAT_RGBA:
   741     case GST_VIDEO_FORMAT_RGBA:
   880     case GST_VIDEO_FORMAT_BGRA:
   742     case GST_VIDEO_FORMAT_BGRA:
   881     case GST_VIDEO_FORMAT_ARGB:
   743     case GST_VIDEO_FORMAT_ARGB:
   917 
   779 
   918 int
   780 int
   919 gst_video_format_get_row_stride (GstVideoFormat format, int component,
   781 gst_video_format_get_row_stride (GstVideoFormat format, int component,
   920     int width)
   782     int width)
   921 {
   783 {
   922   g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
       
   923   g_return_val_if_fail (component >= 0 && component <= 3, 0);
       
   924   g_return_val_if_fail (width > 0, 0);
       
   925 
       
   926   switch (format) {
   784   switch (format) {
   927     case GST_VIDEO_FORMAT_I420:
   785     case GST_VIDEO_FORMAT_I420:
   928     case GST_VIDEO_FORMAT_YV12:
   786     case GST_VIDEO_FORMAT_YV12:
   929       if (component == 0) {
   787       if (component == 0) {
   930         return GST_ROUND_UP_4 (width);
   788         return GST_ROUND_UP_4 (width);
   931       } else {
   789       } else {
   932         return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
   790         return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
   933       }
   791       }
   934     case GST_VIDEO_FORMAT_YUY2:
   792     case GST_VIDEO_FORMAT_YUY2:
   935     case GST_VIDEO_FORMAT_YVYU:
       
   936     case GST_VIDEO_FORMAT_UYVY:
   793     case GST_VIDEO_FORMAT_UYVY:
   937       return GST_ROUND_UP_4 (width * 2);
   794       return GST_ROUND_UP_4 (width * 2);
   938     case GST_VIDEO_FORMAT_AYUV:
   795     case GST_VIDEO_FORMAT_AYUV:
   939     case GST_VIDEO_FORMAT_RGBx:
   796     case GST_VIDEO_FORMAT_RGBx:
   940     case GST_VIDEO_FORMAT_BGRx:
   797     case GST_VIDEO_FORMAT_BGRx:
   958       if (component == 0) {
   815       if (component == 0) {
   959         return GST_ROUND_UP_4 (width);
   816         return GST_ROUND_UP_4 (width);
   960       } else {
   817       } else {
   961         return GST_ROUND_UP_8 (width) / 2;
   818         return GST_ROUND_UP_8 (width) / 2;
   962       }
   819       }
   963     case GST_VIDEO_FORMAT_Y444:
       
   964       return GST_ROUND_UP_4 (width);
       
   965     case GST_VIDEO_FORMAT_v210:
       
   966       return ((width + 47) / 48) * 128;
       
   967     case GST_VIDEO_FORMAT_v216:
       
   968       return GST_ROUND_UP_8 (width * 4);
       
   969     default:
   820     default:
   970       return 0;
   821       return 0;
   971   }
   822   }
   972 }
   823 }
   973 
   824 
   990 #endif
   841 #endif
   991 
   842 
   992 int
   843 int
   993 gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
   844 gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
   994 {
   845 {
   995   g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
       
   996   g_return_val_if_fail (component >= 0 && component <= 3, 0);
       
   997 
       
   998   switch (format) {
   846   switch (format) {
   999     case GST_VIDEO_FORMAT_I420:
   847     case GST_VIDEO_FORMAT_I420:
  1000     case GST_VIDEO_FORMAT_YV12:
   848     case GST_VIDEO_FORMAT_YV12:
  1001     case GST_VIDEO_FORMAT_Y41B:
   849     case GST_VIDEO_FORMAT_Y41B:
  1002     case GST_VIDEO_FORMAT_Y42B:
   850     case GST_VIDEO_FORMAT_Y42B:
  1003     case GST_VIDEO_FORMAT_Y444:
       
  1004       return 1;
   851       return 1;
  1005     case GST_VIDEO_FORMAT_YUY2:
   852     case GST_VIDEO_FORMAT_YUY2:
  1006     case GST_VIDEO_FORMAT_YVYU:
       
  1007     case GST_VIDEO_FORMAT_UYVY:
   853     case GST_VIDEO_FORMAT_UYVY:
  1008       if (component == 0) {
   854       if (component == 0) {
  1009         return 2;
   855         return 2;
  1010       } else {
   856       } else {
  1011         return 4;
   857         return 4;
  1021     case GST_VIDEO_FORMAT_ABGR:
   867     case GST_VIDEO_FORMAT_ABGR:
  1022       return 4;
   868       return 4;
  1023     case GST_VIDEO_FORMAT_RGB:
   869     case GST_VIDEO_FORMAT_RGB:
  1024     case GST_VIDEO_FORMAT_BGR:
   870     case GST_VIDEO_FORMAT_BGR:
  1025       return 3;
   871       return 3;
  1026     case GST_VIDEO_FORMAT_v210:
       
  1027       /* v210 is packed at the bit level, so pixel stride doesn't make sense */
       
  1028       return 0;
       
  1029     case GST_VIDEO_FORMAT_v216:
       
  1030       if (component == 0) {
       
  1031         return 4;
       
  1032       } else {
       
  1033         return 8;
       
  1034       }
       
  1035     default:
   872     default:
  1036       return 0;
   873       return 0;
  1037   }
   874   }
  1038 }
   875 }
  1039 
   876 
  1057 
   894 
  1058 int
   895 int
  1059 gst_video_format_get_component_width (GstVideoFormat format, int component,
   896 gst_video_format_get_component_width (GstVideoFormat format, int component,
  1060     int width)
   897     int width)
  1061 {
   898 {
  1062   g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
       
  1063   g_return_val_if_fail (component >= 0 && component <= 3, 0);
       
  1064   g_return_val_if_fail (width > 0, 0);
       
  1065 
       
  1066   switch (format) {
   899   switch (format) {
  1067     case GST_VIDEO_FORMAT_I420:
   900     case GST_VIDEO_FORMAT_I420:
  1068     case GST_VIDEO_FORMAT_YV12:
   901     case GST_VIDEO_FORMAT_YV12:
  1069     case GST_VIDEO_FORMAT_YUY2:
   902     case GST_VIDEO_FORMAT_YUY2:
  1070     case GST_VIDEO_FORMAT_YVYU:
       
  1071     case GST_VIDEO_FORMAT_UYVY:
   903     case GST_VIDEO_FORMAT_UYVY:
  1072     case GST_VIDEO_FORMAT_Y42B:
       
  1073     case GST_VIDEO_FORMAT_v210:
       
  1074     case GST_VIDEO_FORMAT_v216:
       
  1075       if (component == 0) {
   904       if (component == 0) {
  1076         return width;
   905         return width;
  1077       } else {
   906       } else {
  1078         return GST_ROUND_UP_2 (width) / 2;
   907         return GST_ROUND_UP_2 (width) / 2;
  1079       }
   908       }
  1080     case GST_VIDEO_FORMAT_Y41B:
   909     case GST_VIDEO_FORMAT_Y41B:        /* CHECKME: component_width for Y41B */
  1081       if (component == 0) {
   910       if (component == 0) {
  1082         return width;
   911         return width;
  1083       } else {
   912       } else {
  1084         return GST_ROUND_UP_4 (width) / 4;
   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;
  1085       }
   920       }
  1086     case GST_VIDEO_FORMAT_AYUV:
   921     case GST_VIDEO_FORMAT_AYUV:
  1087     case GST_VIDEO_FORMAT_RGBx:
   922     case GST_VIDEO_FORMAT_RGBx:
  1088     case GST_VIDEO_FORMAT_BGRx:
   923     case GST_VIDEO_FORMAT_BGRx:
  1089     case GST_VIDEO_FORMAT_xRGB:
   924     case GST_VIDEO_FORMAT_xRGB:
  1092     case GST_VIDEO_FORMAT_BGRA:
   927     case GST_VIDEO_FORMAT_BGRA:
  1093     case GST_VIDEO_FORMAT_ARGB:
   928     case GST_VIDEO_FORMAT_ARGB:
  1094     case GST_VIDEO_FORMAT_ABGR:
   929     case GST_VIDEO_FORMAT_ABGR:
  1095     case GST_VIDEO_FORMAT_RGB:
   930     case GST_VIDEO_FORMAT_RGB:
  1096     case GST_VIDEO_FORMAT_BGR:
   931     case GST_VIDEO_FORMAT_BGR:
  1097     case GST_VIDEO_FORMAT_Y444:
       
  1098       return width;
   932       return width;
  1099     default:
   933     default:
  1100       return 0;
   934       return 0;
  1101   }
   935   }
  1102 }
   936 }
  1121 
   955 
  1122 int
   956 int
  1123 gst_video_format_get_component_height (GstVideoFormat format, int component,
   957 gst_video_format_get_component_height (GstVideoFormat format, int component,
  1124     int height)
   958     int height)
  1125 {
   959 {
  1126   g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
       
  1127   g_return_val_if_fail (component >= 0 && component <= 3, 0);
       
  1128   g_return_val_if_fail (height > 0, 0);
       
  1129 
       
  1130   switch (format) {
   960   switch (format) {
  1131     case GST_VIDEO_FORMAT_I420:
   961     case GST_VIDEO_FORMAT_I420:
  1132     case GST_VIDEO_FORMAT_YV12:
   962     case GST_VIDEO_FORMAT_YV12:
  1133       if (component == 0) {
   963       if (component == 0) {
  1134         return height;
   964         return height;
  1136         return GST_ROUND_UP_2 (height) / 2;
   966         return GST_ROUND_UP_2 (height) / 2;
  1137       }
   967       }
  1138     case GST_VIDEO_FORMAT_Y41B:
   968     case GST_VIDEO_FORMAT_Y41B:
  1139     case GST_VIDEO_FORMAT_Y42B:
   969     case GST_VIDEO_FORMAT_Y42B:
  1140     case GST_VIDEO_FORMAT_YUY2:
   970     case GST_VIDEO_FORMAT_YUY2:
  1141     case GST_VIDEO_FORMAT_YVYU:
       
  1142     case GST_VIDEO_FORMAT_UYVY:
   971     case GST_VIDEO_FORMAT_UYVY:
  1143     case GST_VIDEO_FORMAT_AYUV:
   972     case GST_VIDEO_FORMAT_AYUV:
  1144     case GST_VIDEO_FORMAT_RGBx:
   973     case GST_VIDEO_FORMAT_RGBx:
  1145     case GST_VIDEO_FORMAT_BGRx:
   974     case GST_VIDEO_FORMAT_BGRx:
  1146     case GST_VIDEO_FORMAT_xRGB:
   975     case GST_VIDEO_FORMAT_xRGB:
  1149     case GST_VIDEO_FORMAT_BGRA:
   978     case GST_VIDEO_FORMAT_BGRA:
  1150     case GST_VIDEO_FORMAT_ARGB:
   979     case GST_VIDEO_FORMAT_ARGB:
  1151     case GST_VIDEO_FORMAT_ABGR:
   980     case GST_VIDEO_FORMAT_ABGR:
  1152     case GST_VIDEO_FORMAT_RGB:
   981     case GST_VIDEO_FORMAT_RGB:
  1153     case GST_VIDEO_FORMAT_BGR:
   982     case GST_VIDEO_FORMAT_BGR:
  1154     case GST_VIDEO_FORMAT_Y444:
       
  1155     case GST_VIDEO_FORMAT_v210:
       
  1156     case GST_VIDEO_FORMAT_v216:
       
  1157       return height;
   983       return height;
  1158     default:
   984     default:
  1159       return 0;
   985       return 0;
  1160   }
   986   }
  1161 }
   987 }
  1184 
  1010 
  1185 int
  1011 int
  1186 gst_video_format_get_component_offset (GstVideoFormat format, int component,
  1012 gst_video_format_get_component_offset (GstVideoFormat format, int component,
  1187     int width, int height)
  1013     int width, int height)
  1188 {
  1014 {
  1189   g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
       
  1190   g_return_val_if_fail (component >= 0 && component <= 3, 0);
       
  1191   g_return_val_if_fail (width > 0 && height > 0, 0);
       
  1192 
       
  1193   switch (format) {
  1015   switch (format) {
  1194     case GST_VIDEO_FORMAT_I420:
  1016     case GST_VIDEO_FORMAT_I420:
  1195       if (component == 0)
  1017       if (component == 0)
  1196         return 0;
  1018         return 0;
  1197       if (component == 1)
  1019       if (component == 1)
  1219       if (component == 1)
  1041       if (component == 1)
  1220         return 1;
  1042         return 1;
  1221       if (component == 2)
  1043       if (component == 2)
  1222         return 3;
  1044         return 3;
  1223       return 0;
  1045       return 0;
  1224     case GST_VIDEO_FORMAT_YVYU:
       
  1225       if (component == 0)
       
  1226         return 0;
       
  1227       if (component == 1)
       
  1228         return 3;
       
  1229       if (component == 2)
       
  1230         return 1;
       
  1231       return 0;
       
  1232     case GST_VIDEO_FORMAT_UYVY:
  1046     case GST_VIDEO_FORMAT_UYVY:
  1233       if (component == 0)
  1047       if (component == 0)
  1234         return 1;
  1048         return 1;
  1235       if (component == 1)
  1049       if (component == 1)
  1236         return 0;
  1050         return 0;
  1321       if (component == 1)
  1135       if (component == 1)
  1322         return GST_ROUND_UP_4 (width) * height;
  1136         return GST_ROUND_UP_4 (width) * height;
  1323       if (component == 2)
  1137       if (component == 2)
  1324         return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_8 (width) / 2)) * height;
  1138         return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_8 (width) / 2)) * height;
  1325       return 0;
  1139       return 0;
  1326     case GST_VIDEO_FORMAT_Y444:
       
  1327       return GST_ROUND_UP_4 (width) * height * component;
       
  1328     case GST_VIDEO_FORMAT_v210:
       
  1329       /* v210 is bit-packed, so this doesn't make sense */
       
  1330       return 0;
       
  1331     case GST_VIDEO_FORMAT_v216:
       
  1332       if (component == 0)
       
  1333         return 0;
       
  1334       if (component == 1)
       
  1335         return 2;
       
  1336       if (component == 2)
       
  1337         return 6;
       
  1338       return 0;
       
  1339     default:
  1140     default:
  1340       return 0;
  1141       return 0;
  1341   }
  1142   }
  1342 }
  1143 }
  1343 
  1144 
  1360 
  1161 
  1361 int
  1162 int
  1362 gst_video_format_get_size (GstVideoFormat format, int width, int height)
  1163 gst_video_format_get_size (GstVideoFormat format, int width, int height)
  1363 {
  1164 {
  1364   int size;
  1165   int size;
  1365 
       
  1366   g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
       
  1367   g_return_val_if_fail (width > 0 && height > 0, 0);
       
  1368 
  1166 
  1369   switch (format) {
  1167   switch (format) {
  1370     case GST_VIDEO_FORMAT_I420:
  1168     case GST_VIDEO_FORMAT_I420:
  1371     case GST_VIDEO_FORMAT_YV12:
  1169     case GST_VIDEO_FORMAT_YV12:
  1372       size = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
  1170       size = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
  1373       size += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
  1171       size += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
  1374           (GST_ROUND_UP_2 (height) / 2) * 2;
  1172           (GST_ROUND_UP_2 (height) / 2) * 2;
  1375       return size;
  1173       return size;
  1376     case GST_VIDEO_FORMAT_YUY2:
  1174     case GST_VIDEO_FORMAT_YUY2:
  1377     case GST_VIDEO_FORMAT_YVYU:
       
  1378     case GST_VIDEO_FORMAT_UYVY:
  1175     case GST_VIDEO_FORMAT_UYVY:
  1379       return GST_ROUND_UP_4 (width * 2) * height;
  1176       return GST_ROUND_UP_4 (width * 2) * height;
  1380     case GST_VIDEO_FORMAT_AYUV:
  1177     case GST_VIDEO_FORMAT_AYUV:
  1381     case GST_VIDEO_FORMAT_RGBx:
  1178     case GST_VIDEO_FORMAT_RGBx:
  1382     case GST_VIDEO_FORMAT_BGRx:
  1179     case GST_VIDEO_FORMAT_BGRx:
  1394       /* simplification of ROUNDUP4(w)*h + 2*((ROUNDUP8(w)/4)*h */
  1191       /* simplification of ROUNDUP4(w)*h + 2*((ROUNDUP8(w)/4)*h */
  1395       return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_8 (width) / 2)) * height;
  1192       return (GST_ROUND_UP_4 (width) + (GST_ROUND_UP_8 (width) / 2)) * height;
  1396     case GST_VIDEO_FORMAT_Y42B:
  1193     case GST_VIDEO_FORMAT_Y42B:
  1397       /* simplification of ROUNDUP4(w)*h + 2*(ROUNDUP8(w)/2)*h: */
  1194       /* simplification of ROUNDUP4(w)*h + 2*(ROUNDUP8(w)/2)*h: */
  1398       return (GST_ROUND_UP_4 (width) + GST_ROUND_UP_8 (width)) * height;
  1195       return (GST_ROUND_UP_4 (width) + GST_ROUND_UP_8 (width)) * height;
  1399     case GST_VIDEO_FORMAT_Y444:
       
  1400       return GST_ROUND_UP_4 (width) * height * 3;
       
  1401     case GST_VIDEO_FORMAT_v210:
       
  1402       return ((width + 47) / 48) * 128 * height;
       
  1403     case GST_VIDEO_FORMAT_v216:
       
  1404       return GST_ROUND_UP_8 (width * 4) * height;
       
  1405     default:
  1196     default:
  1406       return 0;
  1197       return 0;
  1407   }
  1198   }
  1408 }
  1199 }
  1409 
  1200 
  1438     GstFormat src_format, gint64 src_value,
  1229     GstFormat src_format, gint64 src_value,
  1439     GstFormat dest_format, gint64 * dest_value)
  1230     GstFormat dest_format, gint64 * dest_value)
  1440 {
  1231 {
  1441   gboolean ret = FALSE;
  1232   gboolean ret = FALSE;
  1442   int size;
  1233   int size;
  1443 
       
  1444   g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0);
       
  1445   g_return_val_if_fail (width > 0 && height > 0, 0);
       
  1446 
  1234 
  1447   size = gst_video_format_get_size (format, width, height);
  1235   size = gst_video_format_get_size (format, width, height);
  1448 
  1236 
  1449   GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
  1237   GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
  1450       src_value, gst_format_get_name (src_format),
  1238       src_value, gst_format_get_name (src_format),