From: Mark Nauwelaerts Date: Tue, 17 Jul 2012 11:46:43 +0000 (+0200) Subject: videooverlaycomposition: replace API parameters with required video meta on pixel... X-Git-Tag: 1.19.3~511^2~6179 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f89c7b605fe2ecb15922b313cb49fd0928a8fd63;p=platform%2Fupstream%2Fgstreamer.git videooverlaycomposition: replace API parameters with required video meta on pixel data --- diff --git a/gst-libs/gst/video/video-overlay-composition.c b/gst-libs/gst/video/video-overlay-composition.c index ee38063..f153e0c 100644 --- a/gst-libs/gst/video/video-overlay-composition.c +++ b/gst-libs/gst/video/video-overlay-composition.c @@ -100,9 +100,6 @@ struct _GstVideoOverlayRectangle /* Info on overlay pixels (format, width, height) */ GstVideoInfo info; - /* cached stride */ - guint stride; - /* The flags associated to this rectangle */ GstVideoOverlayFormatFlags flags; @@ -642,9 +639,6 @@ gst_video_overlay_rectangle_is_same_alpha_type (GstVideoOverlayFormatFlags /** * gst_video_overlay_rectangle_new_argb: * @pixels: (transfer none): a #GstBuffer pointing to the pixel memory - * @width: the width of the rectangle in @pixels - * @height: the height of the rectangle in @pixels - * @stride: the stride of the rectangle in @pixels in bytes (>= 4*width) * @render_x: the X co-ordinate on the video where the top-left corner of this * overlay rectangle should be rendered to * @render_y: the Y co-ordinate on the video where the top-left corner of this @@ -662,29 +656,44 @@ gst_video_overlay_rectangle_is_same_alpha_type (GstVideoOverlayFormatFlags * component value. Unless specified in the flags, the RGB values are * non-premultiplied. This is the format that is used by most hardware, * and also many rendering libraries such as Cairo, for example. + * The pixel data buffer must have #GstVideoMeta set. * * Returns: (transfer full): a new #GstVideoOverlayRectangle. Unref with * gst_video_overlay_rectangle_unref() when no longer needed. */ GstVideoOverlayRectangle * gst_video_overlay_rectangle_new_argb (GstBuffer * pixels, - guint width, guint height, guint stride, gint render_x, gint render_y, - guint render_width, guint render_height, GstVideoOverlayFormatFlags flags) + gint render_x, gint render_y, guint render_width, guint render_height, + GstVideoOverlayFormatFlags flags) { GstVideoOverlayRectangle *rect; GstVideoFormat format; - gint strides[GST_VIDEO_MAX_PLANES]; - gsize offsets[GST_VIDEO_MAX_PLANES]; + GstVideoMeta *vmeta; + guint width, height; g_return_val_if_fail (GST_IS_BUFFER (pixels), NULL); - /* technically ((height-1)*stride)+width might be okay too */ - g_return_val_if_fail (gst_buffer_get_size (pixels) >= height * stride, NULL); - g_return_val_if_fail (gst_buffer_is_writable (pixels), NULL); - g_return_val_if_fail (stride >= (4 * width), NULL); - g_return_val_if_fail (height > 0 && width > 0, NULL); g_return_val_if_fail (render_height > 0 && render_width > 0, NULL); g_return_val_if_fail (gst_video_overlay_rectangle_check_flags (flags), NULL); +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + format = GST_VIDEO_FORMAT_BGRA; +#else + format = GST_VIDEO_FORMAT_ARGB; +#endif + + /* buffer must have video meta with some expected settings */ + vmeta = gst_buffer_get_video_meta (pixels); + g_return_val_if_fail (vmeta, NULL); + g_return_val_if_fail (vmeta->format == format, NULL); + g_return_val_if_fail (vmeta->flags == GST_VIDEO_FRAME_FLAG_NONE, NULL); + + width = vmeta->width; + height = vmeta->height; + + /* technically ((height-1)*stride)+width might be okay too */ + g_return_val_if_fail (gst_buffer_get_size (pixels) >= height * width, NULL); + g_return_val_if_fail (height > 0 && width > 0, NULL); + rect = (GstVideoOverlayRectangle *) g_slice_new0 (GstVideoOverlayRectangle); gst_mini_object_init (GST_MINI_OBJECT_CAST (rect), 0, @@ -694,16 +703,6 @@ gst_video_overlay_rectangle_new_argb (GstBuffer * pixels, g_mutex_init (&rect->lock); -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - format = GST_VIDEO_FORMAT_BGRA; -#else - format = GST_VIDEO_FORMAT_ARGB; -#endif - - strides[0] = stride; - offsets[0] = 0; - gst_buffer_add_video_meta_full (pixels, GST_VIDEO_FRAME_FLAG_NONE, - format, width, height, 1, offsets, strides); rect->pixels = gst_buffer_ref (pixels); rect->scaled_rectangles = NULL; @@ -716,7 +715,6 @@ gst_video_overlay_rectangle_new_argb (GstBuffer * pixels, rect->y = render_y; rect->render_width = render_width; rect->render_height = render_height; - rect->stride = stride; rect->global_alpha = 1.0; rect->applied_global_alpha = 1.0; @@ -936,8 +934,7 @@ gst_video_overlay_rectangle_apply_global_alpha (GstVideoOverlayRectangle * rect, static GstBuffer * gst_video_overlay_rectangle_get_pixels_argb_internal (GstVideoOverlayRectangle * - rectangle, guint * stride, GstVideoOverlayFormatFlags flags, - gboolean unscaled) + rectangle, GstVideoOverlayFormatFlags flags, gboolean unscaled) { GstVideoOverlayFormatFlags new_flags; GstVideoOverlayRectangle *scaled_rect = NULL; @@ -952,7 +949,6 @@ gst_video_overlay_rectangle_get_pixels_argb_internal (GstVideoOverlayRectangle * gboolean revert_global_alpha; g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), NULL); - g_return_val_if_fail (stride != NULL, NULL); g_return_val_if_fail (gst_video_overlay_rectangle_check_flags (flags), NULL); width = GST_VIDEO_INFO_WIDTH (&rectangle->info); @@ -976,7 +972,6 @@ gst_video_overlay_rectangle_get_pixels_argb_internal (GstVideoOverlayRectangle * if ((!apply_global_alpha || rectangle->applied_global_alpha == rectangle->global_alpha) && (!revert_global_alpha || rectangle->applied_global_alpha == 1.0)) { - *stride = rectangle->stride; return rectangle->pixels; } else { /* only apply/revert global-alpha */ @@ -1012,6 +1007,8 @@ gst_video_overlay_rectangle_get_pixels_argb_internal (GstVideoOverlayRectangle * gst_video_blend_scale_linear_RGBA (&rectangle->info, rectangle->pixels, wanted_height, wanted_width, &scaled_info, &buf); info = scaled_info; + gst_buffer_add_video_meta (buf, GST_VIDEO_FRAME_FLAG_NONE, + GST_VIDEO_INFO_FORMAT (&rectangle->info), wanted_width, wanted_height); } else { /* if we don't have to scale, we have to modify the alpha values, so we * need to make a copy of the pixel memory (and we take ownership below) */ @@ -1033,7 +1030,6 @@ gst_video_overlay_rectangle_get_pixels_argb_internal (GstVideoOverlayRectangle * gst_video_frame_unmap (&frame); scaled_rect = gst_video_overlay_rectangle_new_argb (buf, - wanted_width, wanted_height, info.stride[0], 0, 0, wanted_width, wanted_height, new_flags); if (rectangle->global_alpha != 1.0) gst_video_overlay_rectangle_set_global_alpha (scaled_rect, @@ -1059,7 +1055,6 @@ done: } GST_RECTANGLE_UNLOCK (rectangle); - *stride = scaled_rect->stride; return scaled_rect->pixels; } @@ -1067,8 +1062,6 @@ done: /** * gst_video_overlay_rectangle_get_pixels_argb: * @rectangle: a #GstVideoOverlayRectangle - * @stride: (out) (allow-none): address of guint variable where to store the - * row stride of the ARGB pixel data in the buffer * @flags: flags * If a global_alpha value != 1 is set for the rectangle, the caller * should set the #GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA flag @@ -1076,28 +1069,22 @@ done: * global_alpha is applied internally before returning the pixel-data. * * Returns: (transfer none): a #GstBuffer holding the ARGB pixel data with - * row stride @stride and width and height of the render dimensions as per + * width and height of the render dimensions as per * gst_video_overlay_rectangle_get_render_rectangle(). This function does * not return a reference, the caller should obtain a reference of her own * with gst_buffer_ref() if needed. */ GstBuffer * gst_video_overlay_rectangle_get_pixels_argb (GstVideoOverlayRectangle * - rectangle, guint * stride, GstVideoOverlayFormatFlags flags) + rectangle, GstVideoOverlayFormatFlags flags) { return gst_video_overlay_rectangle_get_pixels_argb_internal (rectangle, - stride, flags, FALSE); + flags, FALSE); } /** * gst_video_overlay_rectangle_get_pixels_unscaled_argb: * @rectangle: a #GstVideoOverlayRectangle - * @width: (out): address where to store the width of the unscaled - * rectangle in pixels - * @height: (out): address where to store the height of the unscaled - * rectangle in pixels - * @stride: (out): address of guint variable where to store the row - * stride of the ARGB pixel data in the buffer * @flags: flags. * If a global_alpha value != 1 is set for the rectangle, the caller * should set the #GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA flag @@ -1110,23 +1097,17 @@ gst_video_overlay_rectangle_get_pixels_argb (GstVideoOverlayRectangle * * gst_video_overlay_rectangle_get_render_rectangle(). * * Returns: (transfer none): a #GstBuffer holding the ARGB pixel data with - * row stride @stride. This function does not return a reference, the caller + * #GstVideoMeta set. This function does not return a reference, the caller * should obtain a reference of her own with gst_buffer_ref() if needed. */ GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_argb (GstVideoOverlayRectangle * - rectangle, guint * width, guint * height, guint * stride, - GstVideoOverlayFormatFlags flags) + rectangle, GstVideoOverlayFormatFlags flags) { g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), NULL); - g_return_val_if_fail (width != NULL, NULL); - g_return_val_if_fail (height != NULL, NULL); - g_return_val_if_fail (stride != NULL, NULL); - *width = GST_VIDEO_INFO_WIDTH (&rectangle->info); - *height = GST_VIDEO_INFO_HEIGHT (&rectangle->info); return gst_video_overlay_rectangle_get_pixels_argb_internal (rectangle, - stride, flags, TRUE); + flags, TRUE); } /** @@ -1221,8 +1202,6 @@ gst_video_overlay_rectangle_copy (GstVideoOverlayRectangle * rectangle) g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), NULL); copy = gst_video_overlay_rectangle_new_argb (rectangle->pixels, - GST_VIDEO_INFO_WIDTH (&rectangle->info), - GST_VIDEO_INFO_HEIGHT (&rectangle->info), rectangle->stride, rectangle->x, rectangle->y, rectangle->render_width, rectangle->render_height, rectangle->flags); if (rectangle->global_alpha != 1) diff --git a/gst-libs/gst/video/video-overlay-composition.h b/gst-libs/gst/video/video-overlay-composition.h index 1b3d4d2..3d38f97 100644 --- a/gst-libs/gst/video/video-overlay-composition.h +++ b/gst-libs/gst/video/video-overlay-composition.h @@ -101,11 +101,21 @@ typedef enum { GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA = 2 } GstVideoOverlayFormatFlags; +/** + * GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB: + * + * Supported RGB overlay video format. + */ +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +#define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB GST_VIDEO_FORMAT_BGRA +#else +#define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB GST_VIDEO_FORMAT_ARGB +#endif + GType gst_video_overlay_rectangle_get_type (void); GstVideoOverlayRectangle * gst_video_overlay_rectangle_new_argb (GstBuffer * pixels, - guint width, guint height, guint stride, - gint render_x, gint render_y, + gint render_x, gint render_y, guint render_width, guint render_height, GstVideoOverlayFormatFlags flags); @@ -126,13 +136,9 @@ gboolean gst_video_overlay_rectangle_get_render_rectangle guint * render_height); GstBuffer * gst_video_overlay_rectangle_get_pixels_argb (GstVideoOverlayRectangle * rectangle, - guint * stride, GstVideoOverlayFormatFlags flags); GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_argb (GstVideoOverlayRectangle * rectangle, - guint * width, - guint * height, - guint * stride, GstVideoOverlayFormatFlags flags); GstVideoOverlayFormatFlags gst_video_overlay_rectangle_get_flags (GstVideoOverlayRectangle * rectangle); diff --git a/tests/check/libs/video.c b/tests/check/libs/video.c index 7bbc3e3..8407c16 100644 --- a/tests/check/libs/video.c +++ b/tests/check/libs/video.c @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -871,6 +872,7 @@ GST_START_TEST (test_overlay_composition) GstVideoOverlayRectangle *rect1, *rect2; GstVideoOverlayCompositionMeta *ometa; GstBuffer *pix1, *pix2, *buf; + GstVideoMeta *vmeta; guint seq1, seq2; guint w, h, stride; gint x, y; @@ -879,7 +881,9 @@ GST_START_TEST (test_overlay_composition) pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50); gst_buffer_memset (pix1, 0, 0, gst_buffer_get_size (pix1)); - rect1 = gst_video_overlay_rectangle_new_argb (pix1, 200, 50, 200 * 4, + gst_buffer_add_video_meta (pix1, GST_VIDEO_FRAME_FLAG_NONE, + GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, 200, 50); + rect1 = gst_video_overlay_rectangle_new_argb (pix1, 600, 50, 300, 50, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); gst_buffer_unref (pix1); @@ -939,8 +943,9 @@ GST_START_TEST (test_overlay_composition) fail_unless_equals_int (h, 51); /* get scaled pixbuf and touch last byte */ - pix1 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride, + pix1 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + stride = 4 * w; fail_unless (gst_buffer_get_size (pix1) > ((h - 1) * stride + (w * 4) - 1), "size %u vs. last pixel offset %u", gst_buffer_get_size (pix1), ((h - 1) * stride + (w * 4) - 1)); @@ -954,8 +959,9 @@ GST_START_TEST (test_overlay_composition) fail_unless_equals_int (h, 50); /* get scaled pixbuf and touch last byte */ - pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect2, &stride, + pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect2, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + stride = 4 * w; fail_unless (gst_buffer_get_size (pix2) > ((h - 1) * stride + (w * 4) - 1), "size %u vs. last pixel offset %u", gst_buffer_get_size (pix1), ((h - 1) * stride + (w * 4) - 1)); @@ -963,20 +969,26 @@ GST_START_TEST (test_overlay_composition) fail_unless_equals_int (val, 0); /* get scaled pixbuf again, should be the same buffer as before (caching) */ - pix1 = gst_video_overlay_rectangle_get_pixels_argb (rect2, &stride, + pix1 = gst_video_overlay_rectangle_get_pixels_argb (rect2, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); fail_unless (pix1 == pix2); /* now compare the original unscaled ones */ - pix1 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect2, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + pix1 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect2, + GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + + vmeta = gst_buffer_get_video_meta (pix2); + fail_unless (vmeta != NULL); + w = vmeta->width; + h = vmeta->height; /* the original pixel buffers should be identical */ fail_unless (pix1 == pix2); fail_unless_equals_int (w, 200); fail_unless_equals_int (h, 50); + stride = 4 * w; /* touch last byte */ fail_unless (gst_buffer_get_size (pix1) > ((h - 1) * stride + (w * 4) - 1), @@ -1023,43 +1035,54 @@ GST_END_TEST; GST_START_TEST (test_overlay_composition_premultiplied_alpha) { GstVideoOverlayRectangle *rect1; + GstVideoMeta *vmeta; GstBuffer *pix1, *pix2, *pix3, *pix4, *pix5; GstBuffer *pix6, *pix7, *pix8, *pix9, *pix10; guint8 *data5, *data7; - guint w, h, stride, w2, h2, stride2; + guint w, h, w2, h2; GstMapInfo map; pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50); gst_buffer_memset (pix1, 0, 0x80, gst_buffer_get_size (pix1)); - rect1 = gst_video_overlay_rectangle_new_argb (pix1, 200, 50, 200 * 4, + gst_buffer_add_video_meta (pix1, GST_VIDEO_FRAME_FLAG_NONE, + GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, 200, 50); + rect1 = gst_video_overlay_rectangle_new_argb (pix1, 600, 50, 300, 50, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); gst_buffer_unref (pix1); /* same flags, unscaled, should be the same buffer */ - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); fail_unless (pix1 == pix2); /* same flags, but scaled */ - pix3 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride, + pix3 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); fail_if (pix3 == pix1 || pix3 == pix2); /* same again, should hopefully get the same (cached) buffer as before */ - pix4 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride, + pix4 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); fail_unless (pix4 == pix3); /* just to update the vars */ - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + + vmeta = gst_buffer_get_video_meta (pix2); + fail_unless (vmeta != NULL); + w = vmeta->width; + h = vmeta->height; /* now, let's try to get premultiplied alpha from the unpremultiplied input */ - pix5 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w2, &h2, - &stride2, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); + pix5 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); fail_if (pix5 == pix1 || pix5 == pix2 || pix5 == pix3); - fail_unless_equals_int (stride, stride2); + vmeta = gst_buffer_get_video_meta (pix5); + fail_unless (vmeta != NULL); + w2 = vmeta->width; + h2 = vmeta->height; fail_unless_equals_int (w, w2); fail_unless_equals_int (h, h2); fail_unless_equals_int (gst_buffer_get_size (pix2), @@ -1085,20 +1108,19 @@ GST_START_TEST (test_overlay_composition_premultiplied_alpha) /* same again, now we should be getting back the same buffer as before, * as it should have been cached */ - pix6 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w2, &h2, - &stride2, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); + pix6 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); fail_unless (pix6 == pix5); /* just to update the stride var */ - pix3 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride, + pix3 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); fail_unless (pix3 == pix4); /* now try to get scaled premultiplied alpha from unpremultiplied input */ - pix7 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride2, + pix7 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); fail_if (pix7 == pix1 || pix7 == pix2 || pix7 == pix3 || pix7 == pix5); - fail_unless_equals_int (stride, stride2); gst_buffer_map (pix7, &map, GST_MAP_READ); data7 = map.data; @@ -1120,16 +1142,16 @@ GST_START_TEST (test_overlay_composition_premultiplied_alpha) gst_buffer_unmap (pix7, &map); /* and the same again, it should be cached now */ - pix8 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride2, + pix8 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); fail_unless (pix8 == pix7); /* make sure other cached stuff is still there */ - pix9 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride, + pix9 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); fail_unless (pix9 == pix3); - pix10 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w2, &h2, - &stride2, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); + pix10 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); fail_unless (pix10 == pix5); gst_video_overlay_rectangle_unref (rect1); @@ -1141,8 +1163,9 @@ GST_START_TEST (test_overlay_composition_global_alpha) { GstVideoOverlayRectangle *rect1; GstBuffer *pix1, *pix2, *pix3, *pix4, *pix5; + GstVideoMeta *vmeta; guint8 *data2, *data4, *data5; - guint w, h, stride, stride3, w4, h4, stride4, stride5; + guint w, h, w4, h4; guint seq1, seq2; gfloat ga1, ga2; GstVideoOverlayFormatFlags flags1; @@ -1151,25 +1174,35 @@ GST_START_TEST (test_overlay_composition_global_alpha) pix1 = gst_buffer_new_and_alloc (200 * sizeof (guint32) * 50); gst_buffer_memset (pix1, 0, 0x80, gst_buffer_get_size (pix1)); - rect1 = gst_video_overlay_rectangle_new_argb (pix1, 200, 50, 200 * 4, + gst_buffer_add_video_meta (pix1, GST_VIDEO_FRAME_FLAG_NONE, + GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, 200, 50); + rect1 = gst_video_overlay_rectangle_new_argb (pix1, 600, 50, 300, 50, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); gst_buffer_unref (pix1); /* same flags, unscaled, should be the same buffer */ - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); fail_unless (pix1 == pix2); + vmeta = gst_buffer_get_video_meta (pix2); + fail_unless (vmeta != NULL); + w = vmeta->width; + h = vmeta->height; + /* same flags, but scaled */ - pix3 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride3, + pix3 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); fail_if (pix3 == pix1 || pix3 == pix2); /* get unscaled premultiplied data, new cached rectangle should be created */ - pix4 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w4, &h4, - &stride4, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); + pix4 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); fail_if (pix4 == pix2 || pix4 == pix3); - fail_unless_equals_int (stride, stride4); + vmeta = gst_buffer_get_video_meta (pix4); + fail_unless (vmeta != NULL); + w4 = vmeta->width; + h4 = vmeta->height; fail_unless_equals_int (w, w4); fail_unless_equals_int (h, h4); fail_unless_equals_int (gst_buffer_get_size (pix2), @@ -1194,11 +1227,10 @@ GST_START_TEST (test_overlay_composition_global_alpha) gst_buffer_unmap (pix4, &map); /* now premultiplied and scaled, again a new cached rectangle should be cached */ - pix5 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride5, + pix5 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); fail_if (pix5 == pix2 || pix5 == pix3 || pix5 == pix4); /* stride and size should be equal to the first scaled rect */ - fail_unless_equals_int (stride5, stride3); fail_unless_equals_int (gst_buffer_get_size (pix5), gst_buffer_get_size (pix3)); /* data should be different (premutliplied) though */ @@ -1240,8 +1272,8 @@ GST_START_TEST (test_overlay_composition_global_alpha) fail_unless_equals_int (flags1, GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA); /* request unscaled pixel-data, global-alpha not applied */ - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA); + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA); /* this should just return the same buffer */ fail_unless (pix2 == pix1); /* make sure we got the initial data (input=0x80808080) */ @@ -1263,8 +1295,8 @@ GST_START_TEST (test_overlay_composition_global_alpha) gst_buffer_unmap (pix2, &map); /* unscaled pixel-data, global-alpha applied */ - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); /* this should be the same buffer with on-the-fly modified alpha-channel */ fail_unless (pix2 == pix1); gst_buffer_map (pix2, &map, GST_MAP_READ); @@ -1290,8 +1322,8 @@ GST_START_TEST (test_overlay_composition_global_alpha) ga2 = gst_video_overlay_rectangle_get_global_alpha (rect1); fail_unless_equals_float (ga2, 0.25); /* and again request unscaled pixel-data, global-alpha applied */ - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); fail_unless (pix2 == pix1); /* make sure we got the initial data with adjusted alpha-channel */ gst_buffer_map (pix2, &map, GST_MAP_READ); @@ -1313,8 +1345,8 @@ GST_START_TEST (test_overlay_composition_global_alpha) /* again: unscaled pixel-data, global-alpha not applied, * this should revert alpha-channel to initial values */ - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA); + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA); fail_unless (pix2 == pix1); /* make sure we got the initial data (input=0x80808080) */ gst_buffer_map (pix2, &map, GST_MAP_READ); @@ -1335,7 +1367,7 @@ GST_START_TEST (test_overlay_composition_global_alpha) gst_buffer_unmap (pix2, &map); /* now scaled, global-alpha not applied */ - pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride, + pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA); /* this should just return the rect/buffer, that was cached for these * scaling dimensions */ @@ -1359,7 +1391,7 @@ GST_START_TEST (test_overlay_composition_global_alpha) gst_buffer_unmap (pix2, &map); /* scaled, global-alpha (0.25) applied */ - pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride, + pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); /* this should just return the rect/buffer, that was cached for these * scaling dimensions with modified alpha channel */ @@ -1384,8 +1416,8 @@ GST_START_TEST (test_overlay_composition_global_alpha) /* now unscaled premultiplied data, global-alpha not applied, * is this really a valid use case?*/ - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA | + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA | GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA); /* this should just return the rect/buffer, that was cached for the * premultiplied data */ @@ -1409,8 +1441,8 @@ GST_START_TEST (test_overlay_composition_global_alpha) gst_buffer_unmap (pix2, &map); /* unscaled premultiplied data, global-alpha (0.25) applied */ - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); /* this should just return the rect/buffer, that was cached for the * premultiplied data */ fail_unless (pix2 == pix4); @@ -1440,8 +1472,8 @@ GST_START_TEST (test_overlay_composition_global_alpha) gst_video_overlay_rectangle_set_global_alpha (rect1, 0.75); /* and verify that also premultiplied data is adjusted * correspondingly (though with increasing rounding errors) */ - pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, &w, &h, - &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); + pix2 = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect1, + GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); /* this should just return the rect/buffer, that was cached for the * premultiplied data */ fail_unless (pix2 == pix4); @@ -1468,13 +1500,12 @@ GST_START_TEST (test_overlay_composition_global_alpha) /* now scaled and premultiplied data, global-alpha not applied, * is this really a valid use case?*/ - pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride, + pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA | GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA); /* this should just return the rect/buffer, that was cached for the * first premultiplied+scaled rect*/ fail_unless (pix2 == pix5); - fail_unless (stride == stride5); /* make sure we got what we expected */ gst_buffer_map (pix2, &map, GST_MAP_READ); data2 = map.data; @@ -1494,12 +1525,11 @@ GST_START_TEST (test_overlay_composition_global_alpha) gst_buffer_unmap (pix2, &map); /* scaled and premultiplied data, global-alpha applied */ - pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, &stride, + pix2 = gst_video_overlay_rectangle_get_pixels_argb (rect1, GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA); /* this should just return the rect/buffer, that was cached for the * first premultiplied+scaled rect*/ fail_unless (pix2 == pix5); - fail_unless (stride == stride5); /* make sure we got what we expected; see above note about rounding errors! */ gst_buffer_map (pix2, &map, GST_MAP_READ); data2 = map.data;