ignore bitparser error
[platform/upstream/gstreamer-vaapi.git] / tests / test-windows.c
1 /*
2  *  test-windows.c - Test GstVaapiWindow
3  *
4  *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5  *    Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6  *  Copyright (C) 2012-2013 Intel Corporation
7  *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public License
11  *  as published by the Free Software Foundation; either version 2.1
12  *  of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free
21  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  *  Boston, MA 02110-1301 USA
23  */
24
25 #include "gst/vaapi/sysdeps.h"
26 #include <gst/vaapi/gstvaapisurface.h>
27 #include <gst/vaapi/gstvaapiimage.h>
28 #if USE_DRM
29 # include <gst/vaapi/gstvaapidisplay_drm.h>
30 # include <gst/vaapi/gstvaapiwindow_drm.h>
31 #endif
32 #if USE_X11
33 # include <gst/vaapi/gstvaapidisplay_x11.h>
34 # include <gst/vaapi/gstvaapiwindow_x11.h>
35 #endif
36 #if USE_WAYLAND
37 # include <gst/vaapi/gstvaapidisplay_wayland.h>
38 # include <gst/vaapi/gstvaapiwindow_wayland.h>
39 #endif
40 #include "image.h"
41
42 static inline void
43 pause(void)
44 {
45     g_print("Press any key to continue...\n");
46     getchar();
47 }
48
49 static GstVaapiSurface *
50 create_test_surface(GstVaapiDisplay *display, guint width, guint height)
51 {
52     GstVaapiImage *image = NULL;
53     GstVaapiSurface *surface;
54     guint i;
55
56     static const GstVaapiChromaType  chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
57     static const GstVideoFormat image_formats[] = {
58         GST_VIDEO_FORMAT_NV12,
59         GST_VIDEO_FORMAT_YV12,
60         GST_VIDEO_FORMAT_I420,
61         GST_VIDEO_FORMAT_AYUV,
62         GST_VIDEO_FORMAT_ARGB,
63         GST_VIDEO_FORMAT_BGRA,
64         GST_VIDEO_FORMAT_RGBA,
65         GST_VIDEO_FORMAT_ABGR,
66         GST_VIDEO_FORMAT_UNKNOWN
67     };
68
69     surface = gst_vaapi_surface_new(display, chroma_type, width, height);
70     if (!surface)
71         g_error("could not create Gst/VA surface");
72
73     for (i = 0; image_formats[i] != GST_VIDEO_FORMAT_UNKNOWN; i++) {
74         const GstVideoFormat format = image_formats[i];
75
76         image = image_generate(display, format, width, height);
77         if (!image)
78             break;
79         if (image_upload(image, surface))
80             break;
81     }
82     if (!image)
83         g_error("could not create Gst/VA image");
84
85     if (!gst_vaapi_surface_sync(surface))
86         g_error("could not complete image upload");
87
88     gst_vaapi_object_unref(image);
89     return surface;
90 }
91
92 int
93 main(int argc, char *argv[])
94 {
95     GstVaapiDisplay *display;
96     GstVaapiWindow *window;
97     GstVaapiSurface *surface;
98     guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
99
100     static const guint width       = 320;
101     static const guint height      = 240;
102     static const guint win_width   = 640;
103     static const guint win_height  = 480;
104
105     gst_init(&argc, &argv);
106
107 #if USE_DRM
108     display = gst_vaapi_display_drm_new(NULL);
109     if (!display)
110         g_error("could not create Gst/VA (DRM) display");
111
112     surface = create_test_surface(display, width, height);
113     if (!surface)
114         g_error("could not create Gst/VA surface");
115
116     g_print("#\n");
117     g_print("# Create window with gst_vaapi_window_drm_new()\n");
118     g_print("#\n");
119     {
120         window = gst_vaapi_window_drm_new(display, win_width, win_height);
121         if (!window)
122             g_error("could not create dummy window");
123
124         gst_vaapi_window_show(window);
125
126         if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
127             g_error("could not render surface");
128
129         pause();
130         gst_vaapi_window_unref(window);
131     }
132
133     gst_vaapi_object_unref(surface);
134     gst_vaapi_display_unref(display);
135 #endif
136
137 #if USE_X11
138     display = gst_vaapi_display_x11_new(NULL);
139     if (!display)
140         g_error("could not create Gst/VA display");
141
142     surface = create_test_surface(display, width, height);
143     if (!surface)
144         g_error("could not create Gst/VA surface");
145
146     g_print("#\n");
147     g_print("# Create window with gst_vaapi_window_x11_new()\n");
148     g_print("#\n");
149     {
150         window = gst_vaapi_window_x11_new(display, win_width, win_height);
151         if (!window)
152             g_error("could not create window");
153
154         gst_vaapi_window_show(window);
155
156         if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
157             g_error("could not render surface");
158
159         pause();
160         gst_vaapi_window_unref(window);
161     }
162
163     g_print("#\n");
164     g_print("# Create window with gst_vaapi_window_x11_new_with_xid()\n");
165     g_print("#\n");
166     {
167         Display * const dpy = gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(display));
168         Window rootwin, win;
169         int screen;
170         unsigned long white_pixel, black_pixel;
171
172         screen      = DefaultScreen(dpy);
173         rootwin     = RootWindow(dpy, screen);
174         white_pixel = WhitePixel(dpy, screen);
175         black_pixel = BlackPixel(dpy, screen);
176
177         win = XCreateSimpleWindow(
178             dpy,
179             rootwin,
180             0, 0, win_width, win_height,
181             0, black_pixel,
182             white_pixel
183         );
184         if (!win)
185             g_error("could not create X window");
186
187         window = gst_vaapi_window_x11_new_with_xid(display, win);
188         if (!window)
189             g_error("could not create window");
190
191         gst_vaapi_window_show(window);
192
193         if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
194             g_error("could not render surface");
195
196         pause();
197         gst_vaapi_window_unref(window);
198         XUnmapWindow(dpy, win);
199         XDestroyWindow(dpy, win);
200     }
201
202     gst_vaapi_object_unref(surface);
203     gst_vaapi_display_unref(display);
204 #endif
205
206 #if USE_WAYLAND
207     display = gst_vaapi_display_wayland_new(NULL);
208     if (!display)
209         g_error("could not create Gst/VA (Wayland) display");
210
211     surface = create_test_surface(display, width, height);
212     if (!surface)
213         g_error("could not create Gst/VA surface");
214
215     g_print("#\n");
216     g_print("# Create window with gst_vaapi_window_wayland_new()\n");
217     g_print("#\n");
218     {
219         window = gst_vaapi_window_wayland_new(display, win_width, win_height);
220         if (!window)
221             g_error("could not create window");
222
223         gst_vaapi_window_show(window);
224
225         if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
226             g_error("could not render surface");
227
228         pause();
229         gst_vaapi_window_unref(window);
230     }
231
232     gst_vaapi_object_unref(surface);
233     gst_vaapi_display_unref(display);
234 #endif
235
236     gst_deinit();
237     return 0;
238 }