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 #ifdef HAVE_GST_VIDEO_OVERLAY_HWCAPS
45 { "global-alpha", 'g',
47 G_OPTION_ARG_DOUBLE, &g_global_alpha,
48 "global-alpha value", NULL },
54 upload_subpicture(GstBuffer *buffer, const VideoSubpictureInfo *subinfo)
56 const guint32 * const src = subinfo->data;
57 guint i, len = subinfo->data_size / 4;
61 if (!gst_buffer_map(buffer, &map_info, GST_MAP_WRITE))
63 dst = (guint32 *)map_info.data;
65 /* Convert from RGBA source to ARGB */
66 for (i = 0; i < len; i++) {
67 const guint32 rgba = src[i];
68 dst[i] = (rgba >> 8) | (rgba << 24);
71 gst_buffer_unmap(buffer, &map_info);
75 main(int argc, char *argv[])
77 GstVaapiDisplay *display;
78 GstVaapiWindow *window;
79 GstVaapiDecoder *decoder;
80 GstVaapiSurfaceProxy *proxy;
81 GstVaapiSurface *surface;
83 VideoSubpictureInfo subinfo;
84 GstVaapiRectangle subrect;
85 GstVideoOverlayRectangle *overlay;
86 GstVideoOverlayComposition *compo;
89 static const guint win_width = 640;
90 static const guint win_height = 480;
92 if (!video_output_init(&argc, argv, g_options))
93 g_error("failed to initialize video output subsystem");
95 #ifdef HAVE_GST_VIDEO_OVERLAY_HWCAPS
96 if (g_global_alpha != 1.0)
97 flags |= GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA;
100 g_print("Test subpicture\n");
102 display = video_output_create_display(NULL);
104 g_error("could not create VA display");
106 window = video_output_create_window(display, win_width, win_height);
108 g_error("could not create window");
110 decoder = decoder_new(display, g_codec_str);
112 g_error("could not create decoder");
114 if (!decoder_put_buffers(decoder))
115 g_error("could not fill decoder with sample data");
117 proxy = decoder_get_surface(decoder);
119 g_error("could not get decoded surface");
121 surface = gst_vaapi_surface_proxy_get_surface(proxy);
123 subpicture_get_info(&subinfo);
124 buffer = gst_buffer_new_and_alloc(subinfo.data_size);
125 upload_subpicture(buffer, &subinfo);
127 /* We position the subpicture at the bottom center */
128 subrect.x = (gst_vaapi_surface_get_width(surface) - subinfo.width) / 2;
129 subrect.y = gst_vaapi_surface_get_height(surface) - subinfo.height - 10;
130 subrect.height = subinfo.height;
131 subrect.width = subinfo.width;
133 #if GST_CHECK_VERSION(1,0,0)
135 GstVideoMeta * const vmeta =
136 gst_buffer_add_video_meta(buffer, GST_VIDEO_FRAME_FLAG_NONE,
137 GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB,
138 subinfo.width, subinfo.height);
140 g_error("could not create video meta");
142 overlay = gst_video_overlay_rectangle_new_raw(buffer,
143 subrect.x, subrect.y, subrect.width, subrect.height, flags);
146 overlay = gst_video_overlay_rectangle_new_argb(buffer,
147 subinfo.width, subinfo.height, subinfo.width * 4,
148 subrect.x, subrect.y, subrect.width, subrect.height, flags);
151 g_error("could not create video overlay");
152 gst_buffer_unref(buffer);
154 #ifdef HAVE_GST_VIDEO_OVERLAY_HWCAPS
155 if (flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA)
156 gst_video_overlay_rectangle_set_global_alpha(overlay, g_global_alpha);
159 compo = gst_video_overlay_composition_new(overlay);
161 g_error("could not create video overlay composition");
162 gst_video_overlay_rectangle_unref(overlay);
164 if (!gst_vaapi_surface_set_subpictures_from_composition(surface, compo,
166 g_error("could not create subpictures from video overlay compoition");
168 gst_vaapi_window_show(window);
170 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL,
171 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
172 g_error("could not render surface");
176 gst_video_overlay_composition_unref(compo);
177 gst_vaapi_surface_proxy_unref(proxy);
178 gst_vaapi_decoder_unref(decoder);
179 gst_vaapi_window_unref(window);
180 gst_vaapi_display_unref(display);