2 * test-windows.c - Test GstVaapiWindow
4 * gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <gst/vaapi/gstvaapidisplay_x11.h>
22 #include <gst/vaapi/gstvaapiwindow_x11.h>
23 #include <gst/vaapi/gstvaapisurface.h>
24 #include <gst/vaapi/gstvaapiimage.h>
27 static inline void pause(void)
29 g_print("Press any key to continue...\n");
34 upload_image(GstVaapiSurface *surface, GstVaapiImage *image)
36 GstVaapiDisplay *display;
37 GstVaapiImageFormat format;
38 GstVaapiSubpicture *subpicture;
40 display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(surface));
44 format = gst_vaapi_image_get_format(image);
48 if (gst_vaapi_surface_put_image(surface, image))
51 g_print("could not upload %" GST_FOURCC_FORMAT" image to surface\n",
52 GST_FOURCC_ARGS(format));
54 if (!gst_vaapi_display_has_subpicture_format(display, format))
57 g_print("trying as a subpicture\n");
59 subpicture = gst_vaapi_subpicture_new(image);
61 g_error("could not create Gst/VA subpicture");
63 if (!gst_vaapi_surface_associate_subpicture(surface, subpicture,
65 g_error("could not associate subpicture to surface");
67 /* The surface holds a reference to the subpicture. This is safe */
68 g_object_unref(subpicture);
73 main(int argc, char *argv[])
75 GstVaapiDisplay *display;
76 GstVaapiWindow *window;
77 GstVaapiSurface *surface;
78 GstVaapiImage *image = NULL;
79 guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
82 static const GstVaapiImageFormat image_formats[] = {
94 static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
95 static const guint width = 320;
96 static const guint height = 240;
97 static const guint win_width = 640;
98 static const guint win_height = 480;
100 gst_init(&argc, &argv);
102 display = gst_vaapi_display_x11_new(NULL);
104 g_error("could not create Gst/VA display");
106 surface = gst_vaapi_surface_new(display, chroma_type, width, height);
108 g_error("could not create Gst/VA surface");
110 for (i = 0; image_formats[i]; i++) {
111 const GstVaapiImageFormat format = image_formats[i];
113 image = image_generate(display, format, width, height);
115 if (upload_image(surface, image))
117 g_object_unref(image);
121 g_error("could not create Gst/VA image");
123 if (!gst_vaapi_surface_sync(surface))
124 g_error("could not complete image upload");
127 g_print("# Create window with gst_vaapi_window_x11_new()\n");
130 window = gst_vaapi_window_x11_new(display, win_width, win_height);
132 g_error("could not create window");
134 gst_vaapi_window_show(window);
136 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
137 g_error("could not render surface");
140 g_object_unref(window);
144 g_print("# Create window with gst_vaapi_window_x11_new_with_xid()\n");
147 Display * const dpy = GST_VAAPI_DISPLAY_XDISPLAY(display);
150 unsigned long white_pixel, black_pixel;
152 screen = DefaultScreen(dpy);
153 rootwin = RootWindow(dpy, screen);
154 white_pixel = WhitePixel(dpy, screen);
155 black_pixel = BlackPixel(dpy, screen);
157 win = XCreateSimpleWindow(
160 0, 0, win_width, win_height,
165 g_error("could not create X window");
167 window = gst_vaapi_window_x11_new_with_xid(display, win);
169 g_error("could not create window");
171 gst_vaapi_window_show(window);
173 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
174 g_error("could not render surface");
177 g_object_unref(window);
178 XUnmapWindow(dpy, win);
179 XDestroyWindow(dpy, win);
182 g_object_unref(image);
183 g_object_unref(surface);
184 g_object_unref(display);