subpicture: add helper to create subpicture from GstVideoOverlayRectangle.

This commit is contained in:
Gwenole Beauchesne 2011-12-14 13:16:21 +01:00
parent 317c4e639e
commit 3227168487
3 changed files with 71 additions and 34 deletions

View file

@ -218,6 +218,68 @@ gst_vaapi_subpicture_new(GstVaapiImage *image)
NULL);
}
/**
* gst_vaapi_subpicture_new_from_overlay_rectangle:
* @display: a #GstVaapiDisplay
* @rect: a #GstVideoOverlayRectangle
*
* Helper function that creates a new #GstVaapiSubpicture from a
* #GstVideoOverlayRectangle. A new #GstVaapiImage is also created
* along the way and attached to the resulting subpicture. The
* subpicture holds a unique reference to the underlying image.
*
* Return value: the newly allocated #GstVaapiSubpicture object
*/
GstVaapiSubpicture *
gst_vaapi_subpicture_new_from_overlay_rectangle(
GstVaapiDisplay *display,
GstVideoOverlayRectangle *rect
)
{
GstVaapiSubpicture *subpicture;
GstVaapiImageFormat format;
GstVaapiImage *image;
GstVaapiImageRaw raw_image;
GstBuffer *buffer;
guint width, height, stride;
g_return_val_if_fail(GST_IS_VIDEO_OVERLAY_RECTANGLE(rect), NULL);
buffer = gst_video_overlay_rectangle_get_pixels_unscaled_argb(
rect,
&width, &height, &stride,
GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE
);
if (!buffer)
return NULL;
/* XXX: use gst_vaapi_image_format_from_video() */
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
format = GST_VAAPI_IMAGE_BGRA;
#else
format = GST_VAAPI_IMAGE_ARGB;
#endif
image = gst_vaapi_image_new(display, format, width, height);
if (!image)
return NULL;
raw_image.format = format;
raw_image.width = width;
raw_image.height = height;
raw_image.num_planes = 1;
raw_image.pixels[0] = GST_BUFFER_DATA(buffer);
raw_image.stride[0] = stride;
if (!gst_vaapi_image_update_from_raw(image, &raw_image, NULL)) {
GST_WARNING("could not update VA image with subtitle data");
g_object_unref(image);
return NULL;
}
subpicture = gst_vaapi_subpicture_new(image);
g_object_unref(image);
return subpicture;
}
/**
* gst_vaapi_subpicture_get_id:
* @subpicture: a #GstVaapiSubpicture

View file

@ -25,6 +25,7 @@
#include <gst/vaapi/gstvaapiobject.h>
#include <gst/vaapi/gstvaapidisplay.h>
#include <gst/vaapi/gstvaapiimage.h>
#include <gst/video/video-overlay-composition.h>
G_BEGIN_DECLS
@ -84,6 +85,12 @@ gst_vaapi_subpicture_get_type(void);
GstVaapiSubpicture *
gst_vaapi_subpicture_new(GstVaapiImage *image);
GstVaapiSubpicture *
gst_vaapi_subpicture_new_from_overlay_rectangle(
GstVaapiDisplay *display,
GstVideoOverlayRectangle *rect
);
GstVaapiID
gst_vaapi_subpicture_get_id(GstVaapiSubpicture *subpicture);

View file

@ -903,57 +903,25 @@ gst_vaapi_surface_set_subpictures_from_composition(
/* Overlay all the rectangles cantained in the overlay composition */
for (n = 0; n < nb_rectangles; ++n) {
GstBuffer *buf;
GstVideoOverlayRectangle *rect;
guint width, height, stride;
GstVaapiImageFormat format;
GstVaapiImage *subtitle_image;
GstVaapiRectangle sub_rect;
GstVaapiSubpicture *subpicture;
GstVaapiImageRaw raw_image;
rect = gst_video_overlay_composition_get_rectangle (composition, n);
buf = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect,
&width, &height, &stride, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
/* XXX: use gst_vaapi_image_format_from_video() */
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
format = GST_VAAPI_IMAGE_BGRA;
#else
format = GST_VAAPI_IMAGE_ARGB;
#endif
subtitle_image = gst_vaapi_image_new (display, format, width, height);
if (!subtitle_image)
return FALSE;
raw_image.format = format;
raw_image.width = width;
raw_image.height = height;
raw_image.num_planes = 1;
raw_image.pixels[0] = GST_BUFFER_DATA(buf);
raw_image.stride[0] = stride;
if (!gst_vaapi_image_update_from_raw (subtitle_image, &raw_image, NULL)) {
GST_WARNING ("could not update VA image with subtitle data");
g_object_unref (subtitle_image);
return FALSE;
}
subpicture = gst_vaapi_subpicture_new_from_overlay_rectangle (display,
rect);
gst_video_overlay_rectangle_get_render_rectangle (rect,
(gint *)&sub_rect.x, (gint *)&sub_rect.y,
&sub_rect.width, &sub_rect.height);
subpicture = gst_vaapi_subpicture_new (subtitle_image);
g_object_unref (subtitle_image);
if (!gst_vaapi_surface_associate_subpicture (surface, subpicture,
NULL, &sub_rect)) {
GST_WARNING ("could not render overlay rectangle %p", rect);
g_object_unref (subpicture);
return FALSE;
}
g_object_unref (subpicture);
}
return TRUE;
}