2011-10-14 16:00:12 +00:00
|
|
|
/*
|
|
|
|
* test-subpicture.c - Test GstVaapiSubpicture
|
|
|
|
*
|
|
|
|
* Copyright (C) <2011> Intel Corporation
|
|
|
|
* Copyright (C) <2011> Collabora Ltd.
|
|
|
|
* Copyright (C) <2011> Thibault Saunier <thibault.saunier@collabora.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2012-01-16 13:19:00 +00:00
|
|
|
#include "config.h"
|
2011-10-14 16:00:12 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <gst/vaapi/gstvaapisurface.h>
|
2013-01-10 10:26:17 +00:00
|
|
|
#include "decoder.h"
|
2012-07-23 13:17:03 +00:00
|
|
|
#include "output.h"
|
2011-10-14 16:00:12 +00:00
|
|
|
#include "test-subpicture-data.h"
|
|
|
|
|
|
|
|
static inline void pause(void)
|
|
|
|
{
|
|
|
|
g_print("Press any key to continue...\n");
|
|
|
|
getchar();
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *g_codec_str;
|
|
|
|
|
|
|
|
static GOptionEntry g_options[] = {
|
|
|
|
{ "codec", 'c',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_STRING, &g_codec_str,
|
|
|
|
"codec to test", NULL },
|
|
|
|
{ NULL, }
|
|
|
|
};
|
|
|
|
|
2011-10-17 16:43:15 +00:00
|
|
|
static void
|
|
|
|
upload_image (guint8 *dst, const guint32 *src, guint size)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 16:00:12 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GstVaapiDisplay *display;
|
|
|
|
GstVaapiWindow *window;
|
2013-01-10 10:26:17 +00:00
|
|
|
GstVaapiDecoder *decoder;
|
2011-10-17 16:43:15 +00:00
|
|
|
GstVaapiSurface *surface;
|
2013-01-10 10:26:17 +00:00
|
|
|
GstBuffer *buffer;
|
2011-10-14 16:00:12 +00:00
|
|
|
VideoSubpictureInfo subinfo;
|
|
|
|
GstVaapiImage *subtitle_image;
|
|
|
|
GstVaapiSubpicture *subpicture;
|
2011-10-17 16:43:15 +00:00
|
|
|
GstCaps *argbcaps;
|
|
|
|
GstVaapiRectangle sub_rect;
|
|
|
|
guint surf_width, surf_height;
|
2011-10-14 16:00:12 +00:00
|
|
|
|
|
|
|
static const guint win_width = 640;
|
|
|
|
static const guint win_height = 480;
|
|
|
|
|
2012-07-23 13:17:03 +00:00
|
|
|
if (!video_output_init(&argc, argv, g_options))
|
|
|
|
g_error("failed to initialize video output subsystem");
|
2011-10-14 16:00:12 +00:00
|
|
|
|
2013-01-10 10:26:17 +00:00
|
|
|
g_print("Test subpicture\n");
|
2011-10-14 16:00:12 +00:00
|
|
|
|
2012-07-23 13:17:03 +00:00
|
|
|
display = video_output_create_display(NULL);
|
2011-10-14 16:00:12 +00:00
|
|
|
if (!display)
|
|
|
|
g_error("could not create VA display");
|
|
|
|
|
2012-07-23 13:17:03 +00:00
|
|
|
window = video_output_create_window(display, win_width, win_height);
|
2011-10-14 16:00:12 +00:00
|
|
|
if (!window)
|
|
|
|
g_error("could not create window");
|
|
|
|
|
2013-01-10 10:26:17 +00:00
|
|
|
decoder = decoder_new(display, g_codec_str);
|
2011-10-14 16:00:12 +00:00
|
|
|
if (!decoder)
|
2013-01-10 10:26:17 +00:00
|
|
|
g_error("could not create decoder");
|
2011-10-14 16:00:12 +00:00
|
|
|
|
2013-01-10 10:26:17 +00:00
|
|
|
if (!decoder_put_buffers(decoder))
|
|
|
|
g_error("could not fill decoder with sample data");
|
2011-10-14 16:00:12 +00:00
|
|
|
|
2013-01-10 10:26:17 +00:00
|
|
|
surface = decoder_get_surface(decoder);
|
2011-10-17 16:43:15 +00:00
|
|
|
if (!surface)
|
2013-01-10 10:26:17 +00:00
|
|
|
g_error("could not get decoded surface");
|
2011-10-17 16:43:15 +00:00
|
|
|
|
|
|
|
gst_vaapi_surface_get_size(surface, &surf_width, &surf_height);
|
|
|
|
printf("surface size %dx%d\n", surf_width, surf_height);
|
|
|
|
|
2011-10-14 16:00:12 +00:00
|
|
|
subpicture_get_info (&subinfo);
|
|
|
|
|
|
|
|
/* Adding subpicture */
|
|
|
|
argbcaps = gst_caps_new_simple ("video/x-raw-rgb",
|
2011-10-17 16:43:15 +00:00
|
|
|
"endianness", G_TYPE_INT, G_BIG_ENDIAN,
|
2011-10-14 16:00:12 +00:00
|
|
|
"bpp", G_TYPE_INT, 32,
|
2011-10-17 16:43:15 +00:00
|
|
|
"red_mask", G_TYPE_INT, 0xff000000,
|
|
|
|
"green_mask", G_TYPE_INT, 0x00ff0000,
|
|
|
|
"blue_mask", G_TYPE_INT, 0x0000ff00,
|
|
|
|
"alpha_mask", G_TYPE_INT, 0x000000ff,
|
2011-10-14 16:00:12 +00:00
|
|
|
"width", G_TYPE_INT, subinfo.width,
|
|
|
|
"height", G_TYPE_INT, subinfo.height,
|
|
|
|
NULL);
|
|
|
|
|
2011-10-17 16:43:15 +00:00
|
|
|
buffer = gst_buffer_new_and_alloc (subinfo.data_size);
|
|
|
|
upload_image (GST_BUFFER_DATA (buffer), subinfo.data, subinfo.data_size);
|
2011-10-14 16:00:12 +00:00
|
|
|
gst_buffer_set_caps (buffer, argbcaps);
|
|
|
|
|
|
|
|
subtitle_image = gst_vaapi_image_new (display,
|
|
|
|
GST_VAAPI_IMAGE_RGBA, subinfo.width, subinfo.height);
|
|
|
|
|
2011-12-12 13:34:03 +00:00
|
|
|
if (!gst_vaapi_image_update_from_buffer (subtitle_image, buffer, NULL))
|
2011-10-17 16:43:15 +00:00
|
|
|
g_error ("could not update VA image with subtitle data");
|
2011-10-14 16:00:12 +00:00
|
|
|
|
2012-05-15 08:24:08 +00:00
|
|
|
subpicture = gst_vaapi_subpicture_new (subtitle_image, 0);
|
2011-10-14 16:00:12 +00:00
|
|
|
|
|
|
|
/* We position it as a subtitle, centered at the bottom. */
|
2011-10-17 16:43:15 +00:00
|
|
|
sub_rect.x = (surf_width - subinfo.width) / 2;
|
|
|
|
sub_rect.y = surf_height - subinfo.height - 10;
|
2011-10-14 16:00:12 +00:00
|
|
|
sub_rect.height = subinfo.height;
|
2011-10-17 16:43:15 +00:00
|
|
|
sub_rect.width = subinfo.width;
|
2011-10-14 16:00:12 +00:00
|
|
|
|
|
|
|
if (!gst_vaapi_surface_associate_subpicture (
|
2011-10-17 16:43:15 +00:00
|
|
|
surface,
|
2011-10-14 16:00:12 +00:00
|
|
|
subpicture,
|
|
|
|
NULL,
|
|
|
|
&sub_rect))
|
|
|
|
g_error("could not associate subpicture");
|
|
|
|
|
|
|
|
gst_vaapi_window_show(window);
|
|
|
|
|
2013-01-10 10:26:17 +00:00
|
|
|
if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL,
|
|
|
|
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
|
2011-10-14 16:00:12 +00:00
|
|
|
g_error("could not render surface");
|
|
|
|
|
|
|
|
pause();
|
|
|
|
|
|
|
|
gst_buffer_unref(buffer);
|
|
|
|
g_object_unref(decoder);
|
|
|
|
g_object_unref(window);
|
|
|
|
g_object_unref(display);
|
|
|
|
g_free(g_codec_str);
|
2012-07-23 13:17:03 +00:00
|
|
|
video_output_exit();
|
2011-10-14 16:00:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|