2 * test-subpicture.c - Test GstVaapiSubpicture
4 * Copyright (C) <2011> 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
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 guint32 * const dst = (guint32 *)GST_BUFFER_DATA(buffer);
55 const guint32 * const src = subinfo->data;
56 guint i, len = subinfo->data_size / 4;
58 /* Convert from RGBA source to ARGB */
59 for (i = 0; i < len; i++) {
60 const guint32 rgba = src[i];
61 dst[i] = (rgba >> 8) | (rgba << 24);
66 main(int argc, char *argv[])
68 GstVaapiDisplay *display;
69 GstVaapiWindow *window;
70 GstVaapiDecoder *decoder;
71 GstVaapiSurface *surface;
73 VideoSubpictureInfo subinfo;
74 GstVaapiRectangle subrect;
75 GstVideoOverlayRectangle *overlay;
76 GstVideoOverlayComposition *compo;
79 static const guint win_width = 640;
80 static const guint win_height = 480;
82 if (!video_output_init(&argc, argv, g_options))
83 g_error("failed to initialize video output subsystem");
85 if (g_global_alpha != 1.0)
86 flags |= GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA;
88 g_print("Test subpicture\n");
90 display = video_output_create_display(NULL);
92 g_error("could not create VA display");
94 window = video_output_create_window(display, win_width, win_height);
96 g_error("could not create window");
98 decoder = decoder_new(display, g_codec_str);
100 g_error("could not create decoder");
102 if (!decoder_put_buffers(decoder))
103 g_error("could not fill decoder with sample data");
105 surface = decoder_get_surface(decoder);
107 g_error("could not get decoded surface");
109 subpicture_get_info(&subinfo);
110 buffer = gst_buffer_new_and_alloc(subinfo.data_size);
111 upload_subpicture(buffer, &subinfo);
113 /* We position the subpicture at the bottom center */
114 subrect.x = (gst_vaapi_surface_get_width(surface) - subinfo.width) / 2;
115 subrect.y = gst_vaapi_surface_get_height(surface) - subinfo.height - 10;
116 subrect.height = subinfo.height;
117 subrect.width = subinfo.width;
119 overlay = gst_video_overlay_rectangle_new_argb(buffer,
120 subinfo.width, subinfo.height, subinfo.width * 4,
121 subrect.x, subrect.y, subrect.width, subrect.height, flags);
123 g_error("could not create video overlay");
124 gst_buffer_unref(buffer);
126 if (flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA)
127 gst_video_overlay_rectangle_set_global_alpha(overlay, g_global_alpha);
129 compo = gst_video_overlay_composition_new(overlay);
131 g_error("could not create video overlay composition");
132 gst_video_overlay_rectangle_unref(overlay);
134 if (!gst_vaapi_surface_set_subpictures_from_composition(surface, compo,
136 g_error("could not create subpictures from video overlay compoition");
138 gst_vaapi_window_show(window);
140 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL,
141 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
142 g_error("could not render surface");
146 gst_video_overlay_composition_unref(compo);
147 g_object_unref(decoder);
148 g_object_unref(window);
149 g_object_unref(display);