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 main(int argc, char *argv[])
36 GstVaapiDisplay *display;
37 GstVaapiWindow *window;
38 GstVaapiSurface *surface;
39 GstVaapiImage *image = NULL;
40 guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
43 static const GstVaapiImageFormat image_formats[] = {
55 static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
56 static const guint width = 320;
57 static const guint height = 240;
58 static const guint win_width = 640;
59 static const guint win_height = 480;
61 gst_init(&argc, &argv);
63 display = gst_vaapi_display_x11_new(NULL);
65 g_error("could not create Gst/VA display");
67 surface = gst_vaapi_surface_new(display, chroma_type, width, height);
69 g_error("could not create Gst/VA surface");
71 for (i = 0; image_formats[i]; i++) {
72 const GstVaapiImageFormat format = image_formats[i];
74 image = image_generate(display, format, width, height);
76 if (image_upload(image, surface))
78 g_object_unref(image);
82 g_error("could not create Gst/VA image");
84 if (!gst_vaapi_surface_sync(surface))
85 g_error("could not complete image upload");
88 g_print("# Create window with gst_vaapi_window_x11_new()\n");
91 window = gst_vaapi_window_x11_new(display, win_width, win_height);
93 g_error("could not create window");
95 gst_vaapi_window_show(window);
97 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
98 g_error("could not render surface");
101 g_object_unref(window);
105 g_print("# Create window with gst_vaapi_window_x11_new_with_xid()\n");
108 Display * const dpy = gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(display));
111 unsigned long white_pixel, black_pixel;
113 screen = DefaultScreen(dpy);
114 rootwin = RootWindow(dpy, screen);
115 white_pixel = WhitePixel(dpy, screen);
116 black_pixel = BlackPixel(dpy, screen);
118 win = XCreateSimpleWindow(
121 0, 0, win_width, win_height,
126 g_error("could not create X window");
128 window = gst_vaapi_window_x11_new_with_xid(display, win);
130 g_error("could not create window");
132 gst_vaapi_window_show(window);
134 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
135 g_error("could not render surface");
138 g_object_unref(window);
139 XUnmapWindow(dpy, win);
140 XDestroyWindow(dpy, win);
143 g_object_unref(image);
144 g_object_unref(surface);
145 g_object_unref(display);