Search
SailfishOS Open Build Service
>
Projects
>
home:sledge
:
branches:nemo:devel:hw:ti:omap4:common
>
gst-plugins-base
> 0001-add-rowstride-support-to-video-utility-functions.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File 0001-add-rowstride-support-to-video-utility-functions.patch of Package gst-plugins-base
From 89d4e3edd2ab010df3d141b262b3961004da8253 Mon Sep 17 00:00:00 2001 From: Rob Clark <rob@ti.com> Date: Thu, 30 Jul 2009 14:50:05 -0500 Subject: [PATCH 01/38] add rowstride support to video utility functions --- gst-libs/gst/video/gstvideofilter.c | 8 +- gst-libs/gst/video/video.c | 252 ++++++++++++++++++++++++++++------- gst-libs/gst/video/video.h | 27 +++-- 3 files changed, 223 insertions(+), 64 deletions(-) diff --git a/gst-libs/gst/video/gstvideofilter.c b/gst-libs/gst/video/gstvideofilter.c index 2d08a60..6b2d7b7 100644 --- a/gst-libs/gst/video/gstvideofilter.c +++ b/gst-libs/gst/video/gstvideofilter.c @@ -21,7 +21,7 @@ /** * SECTION:gstvideofilter * @short_description: Base class for video filters - * + * * <refsect2> * <para> * Provides useful functions and a base class for video filters. @@ -78,14 +78,14 @@ gst_video_filter_get_unit_size (GstBaseTransform * btrans, GstCaps * caps, guint * size) { GstVideoFormat fmt; - gint width, height; + gint width, height, rowstride; - if (!gst_video_format_parse_caps (caps, &fmt, &width, &height)) { + if (!gst_video_format_parse_caps_strided (caps, &fmt, &width, &height, &rowstride)) { GST_WARNING_OBJECT (btrans, "Failed to parse caps %" GST_PTR_FORMAT, caps); return FALSE; } - *size = gst_video_format_get_size (fmt, width, height); + *size = gst_video_format_get_size_strided (fmt, width, height, rowstride); GST_DEBUG_OBJECT (btrans, "Returning size %u bytes for caps %" GST_PTR_FORMAT, *size, caps); diff --git a/gst-libs/gst/video/video.c b/gst-libs/gst/video/video.c index a369387..5003d62 100644 --- a/gst-libs/gst/video/video.c +++ b/gst-libs/gst/video/video.c @@ -31,7 +31,7 @@ * * <refsect2> * <para> - * This library contains some helper functions and includes the + * This library contains some helper functions and includes the * videosink and videofilter base classes. * </para> * </refsect2> @@ -53,7 +53,7 @@ static GstVideoFormat gst_video_format_from_rgb16_masks (int red_mask, * * A convenience function to retrieve a GValue holding the framerate * from the caps on a pad. - * + * * The pad needs to have negotiated caps containing a framerate property. * * Returns: NULL if the pad has no configured caps or the configured caps @@ -106,7 +106,7 @@ gst_video_frame_rate (GstPad * pad) * * Inspect the caps of the provided pad and retrieve the width and height of * the video frames it is configured for. - * + * * The pad needs to have negotiated caps containing width and height properties. * * Returns: TRUE if the width and height could be retrieved. @@ -158,13 +158,13 @@ gst_video_get_size (GstPad * pad, gint * width, gint * height) * @display_par_n: Numerator of the pixel aspect ratio of the display device * @display_par_d: Denominator of the pixel aspect ratio of the display device * - * Given the Pixel Aspect Ratio and size of an input video frame, and the - * pixel aspect ratio of the intended display device, calculates the actual + * Given the Pixel Aspect Ratio and size of an input video frame, and the + * pixel aspect ratio of the intended display device, calculates the actual * display ratio the video will be rendered with. * - * Returns: A boolean indicating success and a calculated Display Ratio in the - * dar_n and dar_d parameters. - * The return value is FALSE in the case of integer overflow or other error. + * Returns: A boolean indicating success and a calculated Display Ratio in the + * dar_n and dar_d parameters. + * The return value is FALSE in the case of integer overflow or other error. * * Since: 0.10.7 */ @@ -308,28 +308,15 @@ gst_video_parse_caps_chroma_site (GstCaps * caps) } /** - * gst_video_format_parse_caps: - * @caps: the #GstCaps to parse - * @format: the #GstVideoFormat of the video represented by @caps (output) - * @width: the width of the video represented by @caps, may be NULL (output) - * @height: the height of the video represented by @caps, may be NULL (output) - * - * Determines the #GstVideoFormat of @caps and places it in the location - * pointed to by @format. Extracts the size of the video and places it - * in the location pointed to by @width and @height. If @caps does not - * represent one of the raw video formats listed in #GstVideoFormat, the - * function will fail and return FALSE. - * - * Since: 0.10.16 - * - * Returns: TRUE if @caps was parsed correctly. + * see gst_video_format_parse_caps_strided and gst_video_format_parse_caps */ -gboolean -gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format, - int *width, int *height) +static gboolean +parse_caps (GstCaps * caps, GstVideoFormat * format, gint *width, gint *height, + gboolean stride_ok, gint *rowstride) { GstStructure *structure; gboolean ok = TRUE; + gboolean strided = FALSE; if (!gst_caps_is_fixed (caps)) return FALSE; @@ -337,7 +324,10 @@ gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format, structure = gst_caps_get_structure (caps, 0); if (format) { - if (gst_structure_has_name (structure, "video/x-raw-yuv")) { + if (gst_structure_has_name (structure, "video/x-raw-yuv") || + (stride_ok && + gst_structure_has_name (structure, "video/x-raw-yuv-strided") && + (strided=TRUE) /* single '=' intentional */)) { guint32 fourcc; ok &= gst_structure_get_fourcc (structure, "format", &fourcc); @@ -346,7 +336,10 @@ gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format, if (*format == GST_VIDEO_FORMAT_UNKNOWN) { ok = FALSE; } - } else if (gst_structure_has_name (structure, "video/x-raw-rgb")) { + } else if (gst_structure_has_name (structure, "video/x-raw-rgb") || + (stride_ok && + gst_structure_has_name (structure, "video/x-raw-rgb-strided") && + (strided=TRUE) /* single '=' intentional */)) { int depth; int bpp; int endianness = 0; @@ -434,6 +427,10 @@ gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format, } } + /* note: should we require that the caps have these fields, even if + * the caller does not particularly request them?? + */ + if (width) { ok &= gst_structure_get_int (structure, "width", width); } @@ -442,11 +439,70 @@ gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format, ok &= gst_structure_get_int (structure, "height", height); } + if (rowstride) { + if (strided) { + ok &= gst_structure_get_int (structure, "rowstride", rowstride); + } else { + *rowstride = 0; /* not a strided format */ + } + } + return ok; } /** + * gst_video_format_parse_caps_strided: + * @caps: the #GstCaps to parse + * @format: the #GstVideoFormat of the video represented by @caps (output) + * @width: the width of the video represented by @caps, may be NULL (output) + * @height: the height of the video represented by @caps, may be NULL (output) + * @rowstride: the rowstride (in bytes) represented by @caps, or 0 if there + * is no rowstride, may be NULL (output) + * + * Determines the #GstVideoFormat of @caps and places it in the location + * pointed to by @format. Extracts the size of the video and places it + * in the location pointed to by @width and @height. Extracts the row- + * stride and places it in the location pointed to by @rowstride. If + * @caps does not represent one of the raw video formats listed in + * #GstVideoFormat, the function will fail and return FALSE. + * + * Since: ??? + * + * Returns: TRUE if @caps was parsed correctly. + */ +gboolean +gst_video_format_parse_caps_strided (GstCaps * caps, GstVideoFormat * format, + int *width, int *height, int *rowstride) +{ + return parse_caps (caps, format, width, height, TRUE, rowstride); +} + +/** + * gst_video_format_parse_caps: + * @caps: the #GstCaps to parse + * @format: the #GstVideoFormat of the video represented by @caps (output) + * @width: the width of the video represented by @caps, may be NULL (output) + * @height: the height of the video represented by @caps, may be NULL (output) + * + * Determines the #GstVideoFormat of @caps and places it in the location + * pointed to by @format. Extracts the size of the video and places it + * in the location pointed to by @width and @height. If @caps does not + * represent one of the raw video formats listed in #GstVideoFormat, the + * function will fail and return FALSE. + * + * Since: 0.10.16 + * + * Returns: TRUE if @caps was parsed correctly. + */ +gboolean +gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format, + int *width, int *height) +{ + return parse_caps (caps, format, width, height, FALSE, NULL); +} + +/** * gst_video_parse_caps_framerate: * @caps: pointer to a #GstCaps instance * @fps_n: pointer to integer to hold numerator of frame rate (output) @@ -545,16 +601,17 @@ gst_video_format_new_caps_interlaced (GstVideoFormat format, } static GstCaps * -gst_video_format_new_caps_raw (GstVideoFormat format) +gst_video_format_new_caps_raw_strided (GstVideoFormat format, int rowstride) { + GstCaps *caps = NULL; + g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL); if (gst_video_format_is_yuv (format)) { - return gst_caps_new_simple ("video/x-raw-yuv", + caps = gst_caps_new_simple (rowstride ? + "video/x-raw-yuv-strided" : "video/x-raw-yuv", "format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format), NULL); - } - if (gst_video_format_is_rgb (format)) { - GstCaps *caps; + } else if (gst_video_format_is_rgb (format)) { int red_mask = 0; int blue_mask = 0; int green_mask = 0; @@ -664,7 +721,8 @@ gst_video_format_new_caps_raw (GstVideoFormat format) return NULL; } - caps = gst_caps_new_simple ("video/x-raw-rgb", + caps = gst_caps_new_simple (rowstride ? + "video/x-raw-rgb-strided" : "video/x-raw-rgb", "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth, NULL); if (bpp != 8) { @@ -680,11 +738,7 @@ gst_video_format_new_caps_raw (GstVideoFormat format) mask >> (8 * gst_video_format_get_component_offset (format, 3, 0, 0)); gst_caps_set_simple (caps, "alpha_mask", G_TYPE_INT, alpha_mask, NULL); } - return caps; - } - - if (gst_video_format_is_gray (format)) { - GstCaps *caps; + } else if (gst_video_format_is_gray (format)) { int bpp; int depth; int endianness; @@ -716,11 +770,39 @@ gst_video_format_new_caps_raw (GstVideoFormat format) "depth", G_TYPE_INT, depth, "endianness", G_TYPE_INT, endianness, NULL); } + } else { + return NULL; + } - return caps; + if (rowstride) { + gst_caps_set_simple (caps, "rowstride", G_TYPE_INT, rowstride, NULL); } - return NULL; + return caps; +} + +/** + * gst_video_format_new_caps: + * @format: the #GstVideoFormat describing the raw video format + * @width: width of video + * @height: height of video + * @framerate_n: numerator of frame rate + * @framerate_d: denominator of frame rate + * @par_n: numerator of pixel aspect ratio + * @par_d: denominator of pixel aspect ratio + * + * Creates a new #GstCaps object based on the parameters provided. + * + * Since: 0.10.16 + * + * Returns: a new #GstCaps object, or NULL if there was an error + */ +GstCaps * +gst_video_format_new_caps (GstVideoFormat format, int width, int height, + int framerate_n, int framerate_d, int par_n, int par_d) +{ + return gst_video_format_new_caps_strided (format, width, height, 0, + framerate_n, framerate_d, par_n, par_d); } /** @@ -743,7 +825,7 @@ gst_video_format_new_template_caps (GstVideoFormat format) g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL); - caps = gst_video_format_new_caps_raw (format); + caps = gst_video_format_new_caps_raw_strided (format, 0); if (caps) { GValue value = { 0 }; GValue v = { 0 }; @@ -773,10 +855,11 @@ gst_video_format_new_template_caps (GstVideoFormat format) } /** - * gst_video_format_new_caps: + * gst_video_format_new_caps_strided: * @format: the #GstVideoFormat describing the raw video format * @width: width of video * @height: height of video + * @rowstride: the rowstride (in bytes), or 0 if no rowstride * @framerate_n: numerator of frame rate * @framerate_d: denominator of frame rate * @par_n: numerator of pixel aspect ratio @@ -784,13 +867,14 @@ gst_video_format_new_template_caps (GstVideoFormat format) * * Creates a new #GstCaps object based on the parameters provided. * - * Since: 0.10.16 + * Since: ??? * * Returns: a new #GstCaps object, or NULL if there was an error */ GstCaps * -gst_video_format_new_caps (GstVideoFormat format, int width, - int height, int framerate_n, int framerate_d, int par_n, int par_d) +gst_video_format_new_caps_strided (GstVideoFormat format, + int width, int height, int rowstride, + int framerate_n, int framerate_d, int par_n, int par_d) { GstCaps *caps; GstStructure *structure; @@ -798,7 +882,7 @@ gst_video_format_new_caps (GstVideoFormat format, int width, g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL); g_return_val_if_fail (width > 0 && height > 0, NULL); - caps = gst_video_format_new_caps_raw (format); + caps = gst_video_format_new_caps_raw_strided (format, rowstride); if (caps) { structure = gst_caps_get_structure (caps, 0); @@ -812,7 +896,6 @@ gst_video_format_new_caps (GstVideoFormat format, int width, return caps; } - /** * gst_video_format_from_fourcc: * @fourcc: a FOURCC value representing raw YUV video @@ -954,7 +1037,7 @@ gst_video_format_to_fourcc (GstVideoFormat format) * @blue_mask: blue bit mask * * Converts red, green, blue bit masks into the corresponding - * #GstVideoFormat. + * #GstVideoFormat. * * Since: 0.10.16 * @@ -1193,7 +1276,7 @@ gst_video_format_is_gray (GstVideoFormat format) /** * gst_video_format_has_alpha: * @format: a #GstVideoFormat - * + * * Returns TRUE or FALSE depending on if the video format provides an * alpha channel. * @@ -2067,6 +2150,75 @@ gst_video_format_get_size (GstVideoFormat format, int width, int height) } /** + * gst_video_format_get_size_strided: + * @format: a #GstVideoFormat + * @width: the width of video (in pixels) + * @height: the height of video (in pixels) + * @rowstride: the rowstride (in bytes), or 0 if no rowstride (in which + * case the returned value is same as #gst_video_format_get_size()) + * + * Calculates the total number of bytes in the raw video format, for a buffer + * which may have a rowstride in bytes + * + * Since: ??? + * + * Returns: size (in bytes) of raw video format + */ +int +gst_video_format_get_size_strided (GstVideoFormat format, + int width, int height, int rowstride) +{ + if(!rowstride) + return gst_video_format_get_size (format, width, height); + + g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, 0); + g_return_val_if_fail (width > 0 && height > 0, 0); + + switch (format) { + /* all packed formats have the same calculation, ie. rowstride * height + */ + case GST_VIDEO_FORMAT_RGBx: + case GST_VIDEO_FORMAT_BGRx: + case GST_VIDEO_FORMAT_xRGB: + case GST_VIDEO_FORMAT_xBGR: + case GST_VIDEO_FORMAT_RGBA: + case GST_VIDEO_FORMAT_BGRA: + case GST_VIDEO_FORMAT_ARGB: + case GST_VIDEO_FORMAT_ABGR: + case GST_VIDEO_FORMAT_RGB16: + case GST_VIDEO_FORMAT_BGR16: + case GST_VIDEO_FORMAT_RGB15: + case GST_VIDEO_FORMAT_BGR15: + case GST_VIDEO_FORMAT_RGB: + case GST_VIDEO_FORMAT_BGR: + case GST_VIDEO_FORMAT_YUY2: + case GST_VIDEO_FORMAT_YVYU: + case GST_VIDEO_FORMAT_UYVY: + case GST_VIDEO_FORMAT_AYUV: + case GST_VIDEO_FORMAT_v210: + case GST_VIDEO_FORMAT_v216: + return GST_ROUND_UP_4 (rowstride * height); + + /* these planar formats have 2x sub-sampling in the vertical direction, + * so U/V have half as many rows as Y: + */ + case GST_VIDEO_FORMAT_I420: + case GST_VIDEO_FORMAT_YV12: + return GST_ROUND_UP_4 (2 * rowstride * height); + + /* these planar formats have no sub-sampling in the vertical direction, + * so each plane has 'height' number of rows + */ + case GST_VIDEO_FORMAT_Y41B: + case GST_VIDEO_FORMAT_Y42B: + case GST_VIDEO_FORMAT_Y444: + return GST_ROUND_UP_4 (3 * rowstride * height); + default: + return 0; + } +} + +/** * gst_video_format_convert: * @format: a #GstVideoFormat * @width: the width of video diff --git a/gst-libs/gst/video/video.h b/gst-libs/gst/video/video.h index fdd6b43..8a1e5e0 100644 --- a/gst-libs/gst/video/video.h +++ b/gst-libs/gst/video/video.h @@ -33,7 +33,7 @@ G_BEGIN_DECLS * @GST_VIDEO_FORMAT_I420: planar 4:2:0 YUV * @GST_VIDEO_FORMAT_YV12: planar 4:2:0 YVU (like I420 but UV planes swapped) * @GST_VIDEO_FORMAT_YUY2: packed 4:2:2 YUV (Y0-U0-Y1-V0 Y2-U2-Y3-V2 Y4 ...) - * @GST_VIDEO_FORMAT_UYVY: packed 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...) + * @GST_VIDEO_FORMAT_UYVY: packed 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...) * @GST_VIDEO_FORMAT_AYUV: packed 4:4:4 YUV with alpha channel (A0-Y0-U0-V0 ...) * @GST_VIDEO_FORMAT_RGBx: sparse rgb packed into 32 bit, space last * @GST_VIDEO_FORMAT_BGRx: sparse reverse rgb packed into 32 bit, space last @@ -264,13 +264,13 @@ typedef enum { #define GST_VIDEO_CAPS_RGBx \ __GST_VIDEO_CAPS_MAKE_32 (1, 2, 3) - + #define GST_VIDEO_CAPS_xRGB \ __GST_VIDEO_CAPS_MAKE_32 (2, 3, 4) - + #define GST_VIDEO_CAPS_BGRx \ __GST_VIDEO_CAPS_MAKE_32 (3, 2, 1) - + #define GST_VIDEO_CAPS_xBGR \ __GST_VIDEO_CAPS_MAKE_32 (4, 3, 2) @@ -278,13 +278,13 @@ typedef enum { #define GST_VIDEO_CAPS_RGBA \ __GST_VIDEO_CAPS_MAKE_32A (1, 2, 3, 4) - + #define GST_VIDEO_CAPS_ARGB \ __GST_VIDEO_CAPS_MAKE_32A (2, 3, 4, 1) - + #define GST_VIDEO_CAPS_BGRA \ __GST_VIDEO_CAPS_MAKE_32A (3, 2, 1, 4) - + #define GST_VIDEO_CAPS_ABGR \ __GST_VIDEO_CAPS_MAKE_32A (4, 3, 2, 1) @@ -300,7 +300,7 @@ typedef enum { #define GST_VIDEO_CAPS_BGRx_HOST_ENDIAN \ GST_VIDEO_CAPS_xRGB #endif - + /* 15/16 bit */ #define GST_VIDEO_CAPS_RGB_16 \ @@ -442,13 +442,15 @@ gboolean gst_video_get_size (GstPad *pad, gint *height); gboolean gst_video_calculate_display_ratio (guint *dar_n, guint *dar_d, - guint video_width, guint video_height, - guint video_par_n, guint video_par_d, + guint video_width, guint video_height, + guint video_par_n, guint video_par_d, guint display_par_n, guint display_par_d); gboolean gst_video_format_parse_caps (GstCaps *caps, GstVideoFormat *format, int *width, int *height); gboolean gst_video_format_parse_caps_interlaced (GstCaps *caps, gboolean *interlaced); +gboolean gst_video_format_parse_caps_strided (GstCaps * caps, GstVideoFormat * format, + int *width, int *height, int *rowstride); gboolean gst_video_parse_caps_framerate (GstCaps *caps, int *fps_n, int *fps_d); gboolean gst_video_parse_caps_pixel_aspect_ratio (GstCaps *caps, @@ -463,6 +465,9 @@ GstCaps * gst_video_format_new_caps_interlaced (GstVideoFormat format, int width, int height, int framerate_n, int framerate_d, int par_n, int par_d, gboolean interlaced); GstCaps * gst_video_format_new_template_caps (GstVideoFormat format); +GstCaps * gst_video_format_new_caps_strided (GstVideoFormat format, + int width, int height, int rowstride, + int framerate_n, int framerate_d, int par_n, int par_d); GstVideoFormat gst_video_format_from_fourcc (guint32 fourcc); guint32 gst_video_format_to_fourcc (GstVideoFormat format); gboolean gst_video_format_is_rgb (GstVideoFormat format); @@ -480,6 +485,8 @@ int gst_video_format_get_component_height (GstVideoFormat format, int component, int gst_video_format_get_component_offset (GstVideoFormat format, int component, int width, int height); int gst_video_format_get_size (GstVideoFormat format, int width, int height); +int gst_video_format_get_size_strided (GstVideoFormat format, + int width, int height, int rowstride); gboolean gst_video_format_convert (GstVideoFormat format, int width, int height, int fps_n, int fps_d, GstFormat src_format, gint64 src_value, -- 1.7.5.4