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_surfaces_LDADD = libutils.la $(TEST_LIBS)
test_subpicture_SOURCES = test-subpicture.c test-subpicture-data.c test_subpicture_SOURCES = test-subpicture.c test-subpicture-data.c
test_subpicture_CFLAGS = $(TEST_CFLAGS) test_subpicture_CFLAGS = $(TEST_CFLAGS) $(GST_VIDEO_CFLAGS)
test_subpicture_LDADD = libutils.la libutils_dec.la $(TEST_LIBS) test_subpicture_LDADD = libutils.la libutils_dec.la $(TEST_LIBS) \
$(GST_VIDEO_LIBS)
test_windows_SOURCES = test-windows.c test_windows_SOURCES = test-windows.c
test_windows_CFLAGS = $(TEST_CFLAGS) test_windows_CFLAGS = $(TEST_CFLAGS)

View file

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