tests: use GstVideoOverlayComposition API for subpicture test.

This commit is contained in:
Gwenole Beauchesne 2013-01-10 13:09:28 +01:00
parent 886f6d9f11
commit cbf2f27168
2 changed files with 37 additions and 52 deletions

View file

@ -89,8 +89,9 @@ test_surfaces_CFLAGS = $(TEST_CFLAGS)
test_surfaces_LDADD = libutils.la $(TEST_LIBS)
test_subpicture_SOURCES = test-subpicture.c test-subpicture-data.c
test_subpicture_CFLAGS = $(TEST_CFLAGS)
test_subpicture_LDADD = libutils.la libutils_dec.la $(TEST_LIBS)
test_subpicture_CFLAGS = $(TEST_CFLAGS) $(GST_VIDEO_CFLAGS)
test_subpicture_LDADD = libutils.la libutils_dec.la $(TEST_LIBS) \
$(GST_VIDEO_LIBS)
test_windows_SOURCES = test-windows.c
test_windows_CFLAGS = $(TEST_CFLAGS)

View file

@ -44,15 +44,16 @@ static GOptionEntry g_options[] = {
};
static void
upload_image (guint8 *dst, const guint32 *src, guint size)
upload_subpicture(GstBuffer *buffer, const VideoSubpictureInfo *subinfo)
{
guint i;
guint32 * const dst = (guint32 *)GST_BUFFER_DATA(buffer);
const guint32 * const src = subinfo->data;
guint i, len = subinfo->data_size / 4;
for (i = 0; i < size; i += 4) {
dst[i ] = *src >> 24;
dst[i + 1] = *src >> 16;
dst[i + 2] = *src >> 8;
dst[i + 3] = *src++;
/* Convert from RGBA source to ARGB */
for (i = 0; i < len; i++) {
const guint32 rgba = src[i];
dst[i] = (rgba >> 8) | (rgba << 24);
}
}
@ -65,11 +66,10 @@ main(int argc, char *argv[])
GstVaapiSurface *surface;
GstBuffer *buffer;
VideoSubpictureInfo subinfo;
GstVaapiImage *subtitle_image;
GstVaapiSubpicture *subpicture;
GstCaps *argbcaps;
GstVaapiRectangle sub_rect;
guint surf_width, surf_height;
GstVaapiRectangle subrect;
GstVideoOverlayRectangle *overlay;
GstVideoOverlayComposition *compo;
guint flags = 0;
static const guint win_width = 640;
static const guint win_height = 480;
@ -98,47 +98,31 @@ main(int argc, char *argv[])
if (!surface)
g_error("could not get decoded surface");
gst_vaapi_surface_get_size(surface, &surf_width, &surf_height);
printf("surface size %dx%d\n", surf_width, surf_height);
subpicture_get_info(&subinfo);
buffer = gst_buffer_new_and_alloc(subinfo.data_size);
upload_subpicture(buffer, &subinfo);
subpicture_get_info (&subinfo);
/* We position the subpicture at the bottom center */
subrect.x = (gst_vaapi_surface_get_width(surface) - subinfo.width) / 2;
subrect.y = gst_vaapi_surface_get_height(surface) - subinfo.height - 10;
subrect.height = subinfo.height;
subrect.width = subinfo.width;
/* Adding subpicture */
argbcaps = gst_caps_new_simple ("video/x-raw-rgb",
"endianness", G_TYPE_INT, G_BIG_ENDIAN,
"bpp", G_TYPE_INT, 32,
"red_mask", G_TYPE_INT, 0xff000000,
"green_mask", G_TYPE_INT, 0x00ff0000,
"blue_mask", G_TYPE_INT, 0x0000ff00,
"alpha_mask", G_TYPE_INT, 0x000000ff,
"width", G_TYPE_INT, subinfo.width,
"height", G_TYPE_INT, subinfo.height,
NULL);
overlay = gst_video_overlay_rectangle_new_argb(buffer,
subinfo.width, subinfo.height, subinfo.width * 4,
subrect.x, subrect.y, subrect.width, subrect.height, flags);
if (!overlay)
g_error("could not create video overlay");
gst_buffer_unref(buffer);
buffer = gst_buffer_new_and_alloc (subinfo.data_size);
upload_image (GST_BUFFER_DATA (buffer), subinfo.data, subinfo.data_size);
gst_buffer_set_caps (buffer, argbcaps);
compo = gst_video_overlay_composition_new(overlay);
if (!compo)
g_error("could not create video overlay composition");
gst_video_overlay_rectangle_unref(overlay);
subtitle_image = gst_vaapi_image_new (display,
GST_VAAPI_IMAGE_RGBA, subinfo.width, subinfo.height);
if (!gst_vaapi_image_update_from_buffer (subtitle_image, buffer, NULL))
g_error ("could not update VA image with subtitle data");
subpicture = gst_vaapi_subpicture_new (subtitle_image, 0);
/* We position it as a subtitle, centered at the bottom. */
sub_rect.x = (surf_width - subinfo.width) / 2;
sub_rect.y = surf_height - subinfo.height - 10;
sub_rect.height = subinfo.height;
sub_rect.width = subinfo.width;
if (!gst_vaapi_surface_associate_subpicture (
surface,
subpicture,
NULL,
&sub_rect))
g_error("could not associate subpicture");
if (!gst_vaapi_surface_set_subpictures_from_composition(surface, compo,
FALSE))
g_error("could not create subpictures from video overlay compoition");
gst_vaapi_window_show(window);
@ -148,7 +132,7 @@ main(int argc, char *argv[])
pause();
gst_buffer_unref(buffer);
gst_video_overlay_composition_unref(compo);
g_object_unref(decoder);
g_object_unref(window);
g_object_unref(display);