2 * test-display.c - Test GstVaapiDisplayX11
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
23 #include <gst/video/video.h>
25 # include <gst/vaapi/gstvaapidisplay_drm.h>
26 # include <va/va_drm.h>
29 # ifndef DRM_DEVICE_PATH
30 # define DRM_DEVICE_PATH "/dev/dri/card0"
34 # include <gst/vaapi/gstvaapidisplay_x11.h>
37 # include <gst/vaapi/gstvaapidisplay_glx.h>
40 # include <gst/vaapi/gstvaapidisplay_wayland.h>
43 #ifdef HAVE_VA_VA_GLX_H
44 # include <va/va_glx.h>
48 print_value(const GValue *value, const gchar *name)
52 value_string = g_strdup_value_contents(value);
55 g_print(" %s: %s\n", name, value_string);
60 print_profile_caps(GstCaps *caps, const gchar *name)
62 guint i, n_caps = gst_caps_get_size(caps);
67 g_print("%u %s caps\n", n_caps, name);
69 for (i = 0; i < gst_caps_get_size(caps); i++) {
70 GstStructure * const structure = gst_caps_get_structure(caps, i);
72 g_error("could not get caps structure %d", i);
75 gst_structure_get_int(structure, "version", &version) ||
76 gst_structure_get_int(structure, "mpegversion", &version)
79 g_print(" %s", gst_structure_get_name(structure));
81 g_print("%d", version);
83 profile = gst_structure_get_string(structure, "profile");
85 g_error("could not get structure profile");
86 g_print(": %s profile\n", profile);
91 print_format_caps(GstCaps *caps, const gchar *name)
93 guint i, n_caps = gst_caps_get_size(caps);
95 g_print("%u %s caps\n", n_caps, name);
97 for (i = 0; i < gst_caps_get_size(caps); i++) {
98 GstStructure * const structure = gst_caps_get_structure(caps, i);
100 g_error("could not get caps structure %d", i);
102 g_print(" %s:", gst_structure_get_name(structure));
104 if (gst_structure_has_name(structure, "video/x-raw-yuv")) {
107 gst_structure_get_fourcc(structure, "format", &fourcc);
109 g_print(" fourcc '%c%c%c%c'",
111 (fourcc >> 8) & 0xff,
112 (fourcc >> 16) & 0xff,
113 (fourcc >> 24) & 0xff);
116 gint bpp, endian, rmask, gmask, bmask, amask;
119 gst_structure_get_int(structure, "bpp", &bpp);
120 gst_structure_get_int(structure, "endianness", &endian);
121 gst_structure_get_int(structure, "red_mask", &rmask);
122 gst_structure_get_int(structure, "blue_mask", &bmask);
123 gst_structure_get_int(structure, "green_mask", &gmask);
124 has_alpha = gst_structure_get_int(structure, "alpha_mask", &amask);
126 g_print(" %d bits per pixel, %s endian,",
127 bpp, endian == G_BIG_ENDIAN ? "big" : "little");
128 g_print(" %s masks", has_alpha ? "rgba" : "rgb");
129 g_print(" 0x%08x 0x%08x 0x%08x", rmask, gmask, bmask);
131 g_print(" 0x%08x", amask);
137 typedef struct _GstVaapiDisplayProperty GstVaapiDisplayProperty;
138 struct _GstVaapiDisplayProperty {
144 gst_vaapi_display_property_free(GstVaapiDisplayProperty *prop)
148 g_value_unset(&prop->value);
149 g_slice_free(GstVaapiDisplayProperty, prop);
152 static GstVaapiDisplayProperty *
153 gst_vaapi_display_property_new(const gchar *name)
155 GstVaapiDisplayProperty *prop;
157 prop = g_slice_new0(GstVaapiDisplayProperty);
165 free_property_cb(gpointer data, gpointer user_data)
167 gst_vaapi_display_property_free(data);
170 static inline GParamSpec *
171 get_display_property(GstVaapiDisplay *display, const gchar *name)
175 klass = G_OBJECT_CLASS(GST_VAAPI_DISPLAY_GET_CLASS(display));
178 return g_object_class_find_property(klass, name);
182 dump_properties(GstVaapiDisplay *display)
184 GstVaapiDisplayProperty *prop;
185 GPtrArray *properties;
188 static const gchar *g_properties[] = {
189 GST_VAAPI_DISPLAY_PROP_RENDER_MODE,
190 GST_VAAPI_DISPLAY_PROP_ROTATION,
191 GST_VAAPI_DISPLAY_PROP_HUE,
192 GST_VAAPI_DISPLAY_PROP_SATURATION,
193 GST_VAAPI_DISPLAY_PROP_BRIGHTNESS,
194 GST_VAAPI_DISPLAY_PROP_CONTRAST,
198 properties = g_ptr_array_new();
202 for (i = 0; g_properties[i] != NULL; i++) {
203 GParamSpec *pspec = get_display_property(display, g_properties[i]);
206 GST_ERROR("failed to find GstVaapiDisplay property '%s'",
211 if (!gst_vaapi_display_has_property(display, pspec->name))
214 prop = gst_vaapi_display_property_new(pspec->name);
216 GST_ERROR("failed to allocate GstVaapiDisplayProperty");
220 g_value_init(&prop->value, pspec->value_type);
221 g_object_get_property(G_OBJECT(display), pspec->name, &prop->value);
222 g_ptr_array_add(properties, prop);
225 g_print("%u properties\n", properties->len);
226 for (i = 0; i < properties->len; i++) {
227 prop = g_ptr_array_index(properties, i);
228 print_value(&prop->value, prop->name);
233 g_ptr_array_foreach(properties, free_property_cb, NULL);
234 g_ptr_array_free(properties, TRUE);
239 dump_info(GstVaapiDisplay *display)
243 caps = gst_vaapi_display_get_decode_caps(display);
245 g_error("could not get VA decode caps");
247 print_profile_caps(caps, "decoders");
248 gst_caps_unref(caps);
250 caps = gst_vaapi_display_get_encode_caps(display);
252 g_error("could not get VA encode caps");
254 print_profile_caps(caps, "encoders");
255 gst_caps_unref(caps);
257 caps = gst_vaapi_display_get_image_caps(display);
259 g_error("could not get VA image caps");
261 print_format_caps(caps, "image");
262 gst_caps_unref(caps);
264 caps = gst_vaapi_display_get_subpicture_caps(display);
266 g_error("could not get VA subpicture caps");
268 print_format_caps(caps, "subpicture");
269 gst_caps_unref(caps);
271 dump_properties(display);
275 main(int argc, char *argv[])
277 GstVaapiDisplay *display;
278 guint width, height, par_n, par_d;
280 gst_init(&argc, &argv);
284 g_print("# Create display with gst_vaapi_display_drm_new()\n");
287 display = gst_vaapi_display_drm_new(NULL);
289 g_error("could not create Gst/VA display");
292 g_object_unref(display);
297 g_print("# Create display with gst_vaapi_display_drm_new_with_device()\n");
302 drm_device = open(DRM_DEVICE_PATH, O_RDWR|O_CLOEXEC);
304 g_error("could not open DRM device");
306 display = gst_vaapi_display_drm_new_with_device(drm_device);
308 g_error("could not create Gst/VA display");
311 g_object_unref(display);
317 g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayDRM()]\n");
321 VADisplay va_display;
323 drm_device = open(DRM_DEVICE_PATH, O_RDWR|O_CLOEXEC);
325 g_error("could not open DRM device");
327 va_display = vaGetDisplayDRM(drm_device);
329 g_error("could not create VA display");
331 display = gst_vaapi_display_new_with_display(va_display);
333 g_error("could not create Gst/VA display");
336 g_object_unref(display);
344 g_print("# Create display with gst_vaapi_display_x11_new()\n");
347 display = gst_vaapi_display_x11_new(NULL);
349 g_error("could not create Gst/VA display");
351 gst_vaapi_display_get_size(display, &width, &height);
352 g_print("Display size: %ux%u\n", width, height);
354 gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
355 g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
358 g_object_unref(display);
363 g_print("# Create display with gst_vaapi_display_x11_new_with_display()\n");
366 Display *x11_display;
368 x11_display = XOpenDisplay(NULL);
370 g_error("could not create X11 display");
372 display = gst_vaapi_display_x11_new_with_display(x11_display);
374 g_error("could not create Gst/VA display");
377 g_object_unref(display);
378 XCloseDisplay(x11_display);
383 g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplay()]\n");
386 Display *x11_display;
387 VADisplay va_display;
389 x11_display = XOpenDisplay(NULL);
391 g_error("could not create X11 display");
393 va_display = vaGetDisplay(x11_display);
395 g_error("could not create VA display");
397 display = gst_vaapi_display_new_with_display(va_display);
399 g_error("could not create Gst/VA display");
402 g_object_unref(display);
403 XCloseDisplay(x11_display);
410 g_print("# Create display with gst_vaapi_display_glx_new()\n");
413 display = gst_vaapi_display_glx_new(NULL);
415 g_error("could not create Gst/VA display");
417 gst_vaapi_display_get_size(display, &width, &height);
418 g_print("Display size: %ux%u\n", width, height);
420 gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
421 g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
424 g_object_unref(display);
429 g_print("# Create display with gst_vaapi_display_glx_new_with_display()\n");
432 Display *x11_display;
434 x11_display = XOpenDisplay(NULL);
436 g_error("could not create X11 display");
438 display = gst_vaapi_display_glx_new_with_display(x11_display);
440 g_error("could not create Gst/VA display");
443 g_object_unref(display);
444 XCloseDisplay(x11_display);
448 #ifdef HAVE_VA_VA_GLX_H
450 g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayGLX()]\n");
453 Display *x11_display;
454 VADisplay va_display;
456 x11_display = XOpenDisplay(NULL);
458 g_error("could not create X11 display");
460 va_display = vaGetDisplayGLX(x11_display);
462 g_error("could not create VA display");
464 display = gst_vaapi_display_new_with_display(va_display);
466 g_error("could not create Gst/VA display");
469 g_object_unref(display);
470 XCloseDisplay(x11_display);
478 g_print("# Create display with gst_vaapi_display_wayland_new()\n");
481 display = gst_vaapi_display_wayland_new(NULL);
483 g_error("could not create Gst/VA display");
485 gst_vaapi_display_get_size(display, &width, &height);
486 g_print("Display size: %ux%u\n", width, height);
488 gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
489 g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
492 g_object_unref(display);