Fix make dist.
[profile/ivi/gstreamer-vaapi.git] / tests / test-display.c
1 /*
2  *  test-display.c - Test GstVaapiDisplayX11
3  *
4  *  gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <gst/video/video.h>
22 #ifdef USE_X11
23 #include <gst/vaapi/gstvaapidisplay_x11.h>
24 #endif
25 #ifdef USE_GLX
26 #include <gst/vaapi/gstvaapidisplay_glx.h>
27 #endif
28
29 #if USE_VAAPI_GLX
30 # include <va/va_glx.h>
31 #else
32 # define vaGetDisplayGLX(dpy) vaGetDisplay(dpy)
33 #endif
34
35 static void
36 print_profile_caps(GstCaps *caps, const gchar *name)
37 {
38     guint i, n_caps = gst_caps_get_size(caps);
39     gint version;
40     const gchar *profile;
41     gboolean has_version;
42
43     g_print("%u %s caps\n", n_caps, name);
44
45     for (i = 0; i < gst_caps_get_size(caps); i++) {
46         GstStructure * const structure = gst_caps_get_structure(caps, i);
47         if (!structure)
48             g_error("could not get caps structure %d", i);
49
50         has_version = (
51             gst_structure_get_int(structure, "version", &version) ||
52             gst_structure_get_int(structure, "mpegversion", &version)
53         );
54
55         g_print("  %s", gst_structure_get_name(structure));
56         if (has_version)
57             g_print("%d", version);
58
59         profile = gst_structure_get_string(structure, "profile");
60         if (!profile)
61             g_error("could not get structure profile");
62         g_print(": %s profile\n", profile);
63     }
64 }
65
66 static void
67 print_format_caps(GstCaps *caps, const gchar *name)
68 {
69     guint i, n_caps = gst_caps_get_size(caps);
70
71     g_print("%u %s caps\n", n_caps, name);
72
73     for (i = 0; i < gst_caps_get_size(caps); i++) {
74         GstStructure * const structure = gst_caps_get_structure(caps, i);
75         if (!structure)
76             g_error("could not get caps structure %d", i);
77
78         g_print("  %s:", gst_structure_get_name(structure));
79
80         if (gst_structure_has_name(structure, "video/x-raw-yuv")) {
81             guint32 fourcc;
82
83             gst_structure_get_fourcc(structure, "format", &fourcc);
84
85             g_print(" fourcc '%c%c%c%c'",
86                     fourcc & 0xff,
87                     (fourcc >> 8) & 0xff,
88                     (fourcc >> 16) & 0xff,
89                     (fourcc >> 24) & 0xff);
90         }
91         else {
92             gint bpp, endian, rmask, gmask, bmask, amask;
93             gboolean has_alpha;
94
95             gst_structure_get_int(structure, "bpp",         &bpp);
96             gst_structure_get_int(structure, "endianness",  &endian);
97             gst_structure_get_int(structure, "red_mask",    &rmask);
98             gst_structure_get_int(structure, "blue_mask",   &bmask);
99             gst_structure_get_int(structure, "green_mask",  &gmask);
100             has_alpha = gst_structure_get_int(structure, "alpha_mask", &amask);
101
102             g_print(" %d bits per pixel, %s endian,",
103                     bpp, endian == G_BIG_ENDIAN ? "big" : "little");
104             g_print(" %s masks", has_alpha ? "rgba" : "rgb");
105             g_print(" 0x%08x 0x%08x 0x%08x", rmask, gmask, bmask);
106             if (has_alpha)
107                 g_print(" 0x%08x", amask);
108         }
109         g_print("\n");
110     }
111 }
112
113 static void
114 dump_caps(GstVaapiDisplay *display)
115 {
116     GstCaps *caps;
117
118     caps = gst_vaapi_display_get_decode_caps(display);
119     if (!caps)
120         g_error("could not get VA decode caps");
121
122     print_profile_caps(caps, "decoders");
123     gst_caps_unref(caps);
124
125     caps = gst_vaapi_display_get_encode_caps(display);
126     if (!caps)
127         g_error("could not get VA encode caps");
128
129     print_profile_caps(caps, "encoders");
130     gst_caps_unref(caps);
131
132     caps = gst_vaapi_display_get_image_caps(display);
133     if (!caps)
134         g_error("could not get VA image caps");
135
136     print_format_caps(caps, "image");
137     gst_caps_unref(caps);
138
139     caps = gst_vaapi_display_get_subpicture_caps(display);
140     if (!caps)
141         g_error("could not get VA subpicture caps");
142
143     print_format_caps(caps, "subpicture");
144     gst_caps_unref(caps);
145 }
146
147 int
148 main(int argc, char *argv[])
149 {
150     Display *x11_display;
151     VADisplay va_display;
152     GstVaapiDisplay *display;
153     guint width, height, par_n, par_d;
154
155     gst_init(&argc, &argv);
156
157 #ifdef USE_X11
158     g_print("#\n");
159     g_print("# Create display with gst_vaapi_display_x11_new()\n");
160     g_print("#\n");
161     {
162         display = gst_vaapi_display_x11_new(NULL);
163         if (!display)
164             g_error("could not create Gst/VA display");
165
166         gst_vaapi_display_get_size(display, &width, &height);
167         g_print("Display size: %ux%u\n", width, height);
168
169         gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
170         g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
171
172         dump_caps(display);
173         g_object_unref(display);
174     }
175     g_print("\n");
176
177     g_print("#\n");
178     g_print("# Create display with gst_vaapi_display_x11_new_with_display()\n");
179     g_print("#\n");
180     {
181         x11_display = XOpenDisplay(NULL);
182         if (!x11_display)
183             g_error("could not create X11 display");
184
185         display = gst_vaapi_display_x11_new_with_display(x11_display);
186         if (!display)
187             g_error("could not create Gst/VA display");
188
189         dump_caps(display);
190         g_object_unref(display);
191         XCloseDisplay(x11_display);
192     }
193     g_print("\n");
194
195     g_print("#\n");
196     g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplay()]\n");
197     g_print("#\n");
198     {
199         x11_display = XOpenDisplay(NULL);
200         if (!x11_display)
201             g_error("could not create X11 display");
202
203         va_display = vaGetDisplay(x11_display);
204         if (!va_display)
205             g_error("could not create VA display");
206
207         display = gst_vaapi_display_new_with_display(va_display);
208         if (!display)
209             g_error("could not create Gst/VA display");
210
211         dump_caps(display);
212         g_object_unref(display);
213         XCloseDisplay(x11_display);
214     }
215     g_print("\n");
216 #endif
217
218 #ifdef USE_GLX
219     g_print("#\n");
220     g_print("# Create display with gst_vaapi_display_glx_new()\n");
221     g_print("#\n");
222     {
223         display = gst_vaapi_display_glx_new(NULL);
224         if (!display)
225             g_error("could not create Gst/VA display");
226
227         gst_vaapi_display_get_size(display, &width, &height);
228         g_print("Display size: %ux%u\n", width, height);
229
230         gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
231         g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
232
233         dump_caps(display);
234         g_object_unref(display);
235     }
236     g_print("\n");
237
238     g_print("#\n");
239     g_print("# Create display with gst_vaapi_display_glx_new_with_display()\n");
240     g_print("#\n");
241     {
242         x11_display = XOpenDisplay(NULL);
243         if (!x11_display)
244             g_error("could not create X11 display");
245
246         display = gst_vaapi_display_glx_new_with_display(x11_display);
247         if (!display)
248             g_error("could not create Gst/VA display");
249
250         dump_caps(display);
251         g_object_unref(display);
252         XCloseDisplay(x11_display);
253     }
254     g_print("\n");
255
256     g_print("#\n");
257     g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayGLX()]\n");
258     g_print("#\n");
259     {
260         x11_display = XOpenDisplay(NULL);
261         if (!x11_display)
262             g_error("could not create X11 display");
263
264         va_display = vaGetDisplayGLX(x11_display);
265         if (!va_display)
266             g_error("could not create VA display");
267
268         display = gst_vaapi_display_new_with_display(va_display);
269         if (!display)
270             g_error("could not create Gst/VA display");
271
272         dump_caps(display);
273         g_object_unref(display);
274         XCloseDisplay(x11_display);
275     }
276     g_print("\n");
277 #endif
278
279     gst_deinit();
280     return 0;
281 }