2 * test-subpicture.c - Test GstVaapiSubpicture
4 * Copyright (C) <2011-2013> Intel Corporation
5 * Copyright (C) <2011> Collabora Ltd.
6 * Copyright (C) <2011> Thibault Saunier <thibault.saunier@collabora.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "gst/vaapi/sysdeps.h"
25 #include <gst/vaapi/gstvaapisurface.h>
28 #include "test-subpicture-data.h"
30 static inline void pause(void)
32 g_print("Press any key to continue...\n");
36 static gchar *g_codec_str;
37 static gdouble g_global_alpha = 1.0;
39 static GOptionEntry g_options[] = {
42 G_OPTION_ARG_STRING, &g_codec_str,
43 "codec to test", NULL },
44 { "global-alpha", 'g',
46 G_OPTION_ARG_DOUBLE, &g_global_alpha,
47 "global-alpha value", NULL },
52 upload_subpicture(GstBuffer *buffer, const VideoSubpictureInfo *subinfo)
54 const guint32 * const src = subinfo->data;
55 guint i, len = subinfo->data_size / 4;
59 if (!gst_buffer_map(buffer, &map_info, GST_MAP_WRITE))
61 dst = (guint32 *)map_info.data;
63 /* Convert from RGBA source to ARGB */
64 for (i = 0; i < len; i++) {
65 const guint32 rgba = src[i];
66 dst[i] = (rgba >> 8) | (rgba << 24);
69 gst_buffer_unmap(buffer, &map_info);
73 main(int argc, char *argv[])
75 GstVaapiDisplay *display;
76 GstVaapiWindow *window;
77 GstVaapiDecoder *decoder;
78 GstVaapiSurfaceProxy *proxy;
79 GstVaapiSurface *surface;
81 VideoSubpictureInfo subinfo;
82 GstVaapiRectangle subrect;
83 GstVideoOverlayRectangle *overlay;
84 GstVideoOverlayComposition *compo;
87 static const guint win_width = 640;
88 static const guint win_height = 480;
90 if (!video_output_init(&argc, argv, g_options))
91 g_error("failed to initialize video output subsystem");
93 if (g_global_alpha != 1.0)
94 flags |= GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA;
96 g_print("Test subpicture\n");
98 display = video_output_create_display(NULL);
100 g_error("could not create VA display");
102 window = video_output_create_window(display, win_width, win_height);
104 g_error("could not create window");
106 decoder = decoder_new(display, g_codec_str);
108 g_error("could not create decoder");
110 if (!decoder_put_buffers(decoder))
111 g_error("could not fill decoder with sample data");
113 proxy = decoder_get_surface(decoder);
115 g_error("could not get decoded surface");
117 surface = gst_vaapi_surface_proxy_get_surface(proxy);
119 subpicture_get_info(&subinfo);
120 buffer = gst_buffer_new_and_alloc(subinfo.data_size);
121 upload_subpicture(buffer, &subinfo);
123 /* We position the subpicture at the bottom center */
124 subrect.x = (gst_vaapi_surface_get_width(surface) - subinfo.width) / 2;
125 subrect.y = gst_vaapi_surface_get_height(surface) - subinfo.height - 10;
126 subrect.height = subinfo.height;
127 subrect.width = subinfo.width;
130 GstVideoMeta * const vmeta =
131 gst_buffer_add_video_meta(buffer, GST_VIDEO_FRAME_FLAG_NONE,
132 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB,
133 subinfo.width, subinfo.height);
135 g_error("could not create video meta");
137 overlay = gst_video_overlay_rectangle_new_raw(buffer,
138 subrect.x, subrect.y, subrect.width, subrect.height, flags);
141 g_error("could not create video overlay");
142 gst_buffer_unref(buffer);
144 if (flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA)
145 gst_video_overlay_rectangle_set_global_alpha(overlay, g_global_alpha);
147 compo = gst_video_overlay_composition_new(overlay);
149 g_error("could not create video overlay composition");
150 gst_video_overlay_rectangle_unref(overlay);
152 if (!gst_vaapi_surface_set_subpictures_from_composition(surface, compo,
154 g_error("could not create subpictures from video overlay compoition");
156 gst_vaapi_window_show(window);
158 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL,
159 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
160 g_error("could not render surface");
164 gst_video_overlay_composition_unref(compo);
165 gst_vaapi_surface_proxy_unref(proxy);
166 gst_vaapi_decoder_unref(decoder);
167 gst_vaapi_window_unref(window);
168 gst_vaapi_display_unref(display);