2 * test-display.c - Test GstVaapiDisplayX11
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>
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.
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.
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
25 #include "gst/vaapi/sysdeps.h"
26 #include <gst/video/video.h>
28 # include <gst/vaapi/gstvaapidisplay_drm.h>
29 # include <va/va_drm.h>
32 # ifndef DRM_DEVICE_PATH
33 # define DRM_DEVICE_PATH "/dev/dri/card0"
37 # include <gst/vaapi/gstvaapidisplay_x11.h>
40 # include <gst/vaapi/gstvaapidisplay_glx.h>
43 # include <gst/vaapi/gstvaapidisplay_wayland.h>
46 #ifdef HAVE_VA_VA_GLX_H
47 # include <va/va_glx.h>
50 /* Set to 1 to check display cache works (shared VA display) */
51 #define CHECK_DISPLAY_CACHE 1
54 print_value(const GValue *value, const gchar *name)
58 value_string = g_strdup_value_contents(value);
61 g_print(" %s: %s\n", name, value_string);
66 print_profiles(GArray *profiles, const gchar *name)
69 const gchar *codec_name, *profile_name;
72 g_print("%u %s caps\n", profiles->len, name);
74 for (i = 0; i < profiles->len; i++) {
75 const GstVaapiProfile profile =
76 g_array_index(profiles, GstVaapiProfile, i);
78 codec = gst_vaapi_profile_get_codec(profile);
82 codec_name = gst_vaapi_codec_get_name(codec);
86 profile_name = gst_vaapi_profile_get_name(profile);
90 g_print(" %s: %s profile\n", codec_name, profile_name);
95 print_format_yuv(const VAImageFormat *va_format)
97 const guint32 fourcc = va_format->fourcc;
99 g_print(" fourcc '%c%c%c%c'",
101 (fourcc >> 8) & 0xff,
102 (fourcc >> 16) & 0xff,
103 (fourcc >> 24) & 0xff);
107 print_format_rgb(const VAImageFormat *va_format)
109 g_print(" %d bits per pixel, %s endian,",
110 va_format->bits_per_pixel,
111 va_format->byte_order == VA_MSB_FIRST ? "big" : "little");
112 g_print(" %s masks", va_format->alpha_mask ? "rgba" : "rgb");
113 g_print(" 0x%08x 0x%08x 0x%08x",
114 va_format->red_mask, va_format->green_mask, va_format->blue_mask);
115 if (va_format->alpha_mask)
116 g_print(" 0x%08x", va_format->alpha_mask);
120 print_formats(GArray *formats, const gchar *name)
124 g_print("%u %s caps\n", formats->len, name);
126 for (i = 0; i < formats->len; i++) {
127 const GstVideoFormat format = g_array_index(formats, GstVideoFormat, i);
128 const VAImageFormat *va_format;
130 g_print(" %s:", gst_vaapi_video_format_to_string(format));
132 va_format = gst_vaapi_video_format_to_va_format(format);
134 g_error("could not determine VA format");
136 if (gst_vaapi_video_format_is_yuv(format))
137 print_format_yuv(va_format);
139 print_format_rgb(va_format);
144 typedef struct _GstVaapiDisplayProperty GstVaapiDisplayProperty;
145 struct _GstVaapiDisplayProperty {
151 gst_vaapi_display_property_free(GstVaapiDisplayProperty *prop)
155 g_value_unset(&prop->value);
156 g_slice_free(GstVaapiDisplayProperty, prop);
159 static GstVaapiDisplayProperty *
160 gst_vaapi_display_property_new(const gchar *name)
162 GstVaapiDisplayProperty *prop;
164 prop = g_slice_new0(GstVaapiDisplayProperty);
172 free_property_cb(gpointer data, gpointer user_data)
174 gst_vaapi_display_property_free(data);
178 dump_properties(GstVaapiDisplay *display)
180 GstVaapiDisplayProperty *prop;
181 GPtrArray *properties;
184 static const gchar *g_properties[] = {
185 GST_VAAPI_DISPLAY_PROP_RENDER_MODE,
186 GST_VAAPI_DISPLAY_PROP_ROTATION,
187 GST_VAAPI_DISPLAY_PROP_HUE,
188 GST_VAAPI_DISPLAY_PROP_SATURATION,
189 GST_VAAPI_DISPLAY_PROP_BRIGHTNESS,
190 GST_VAAPI_DISPLAY_PROP_CONTRAST,
194 properties = g_ptr_array_new();
198 for (i = 0; g_properties[i] != NULL; i++) {
199 const gchar * const name = g_properties[i];
201 if (!gst_vaapi_display_has_property(display, name))
204 prop = gst_vaapi_display_property_new(name);
206 GST_ERROR("failed to allocate GstVaapiDisplayProperty");
210 if (!gst_vaapi_display_get_property(display, name, &prop->value)) {
211 GST_ERROR("failed to get property '%s'", name);
214 g_ptr_array_add(properties, prop);
217 g_print("%u properties\n", properties->len);
218 for (i = 0; i < properties->len; i++) {
219 prop = g_ptr_array_index(properties, i);
220 print_value(&prop->value, prop->name);
225 g_ptr_array_foreach(properties, free_property_cb, NULL);
226 g_ptr_array_free(properties, TRUE);
231 dump_info(GstVaapiDisplay *display)
233 GArray *profiles, *formats;
235 profiles = gst_vaapi_display_get_decode_profiles(display);
237 g_error("could not get VA decode profiles");
239 print_profiles(profiles, "decoders");
240 g_array_unref(profiles);
242 profiles = gst_vaapi_display_get_encode_profiles(display);
244 g_error("could not get VA encode profiles");
246 print_profiles(profiles, "encoders");
247 g_array_unref(profiles);
249 formats = gst_vaapi_display_get_image_formats(display);
251 g_error("could not get VA image formats");
253 print_formats(formats, "image");
254 g_array_unref(formats);
256 formats = gst_vaapi_display_get_subpicture_formats(display);
258 g_error("could not get VA subpicture formats");
260 print_formats(formats, "subpicture");
261 g_array_unref(formats);
263 dump_properties(display);
267 main(int argc, char *argv[])
269 GstVaapiDisplay *display, *display2;
270 guint width, height, par_n, par_d;
272 gst_init(&argc, &argv);
276 g_print("# Create display with gst_vaapi_display_drm_new()\n");
279 display = gst_vaapi_display_drm_new(NULL);
281 g_error("could not create Gst/VA display");
284 gst_vaapi_display_unref(display);
289 g_print("# Create display with gst_vaapi_display_drm_new_with_device()\n");
294 drm_device = open(DRM_DEVICE_PATH, O_RDWR|O_CLOEXEC);
296 g_error("could not open DRM device");
298 display = gst_vaapi_display_drm_new_with_device(drm_device);
300 g_error("could not create Gst/VA display");
303 gst_vaapi_display_unref(display);
309 g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayDRM()]\n");
313 VADisplay va_display;
315 drm_device = open(DRM_DEVICE_PATH, O_RDWR|O_CLOEXEC);
317 g_error("could not open DRM device");
319 va_display = vaGetDisplayDRM(drm_device);
321 g_error("could not create VA display");
323 display = gst_vaapi_display_new_with_display(va_display);
325 g_error("could not create Gst/VA display");
328 gst_vaapi_display_unref(display);
336 g_print("# Create display with gst_vaapi_display_x11_new()\n");
339 display = gst_vaapi_display_x11_new(NULL);
341 g_error("could not create Gst/VA display");
343 if (CHECK_DISPLAY_CACHE) {
344 display2 = gst_vaapi_display_x11_new(NULL);
346 /* Check for the same X11 display */
347 g_assert(gst_vaapi_display_x11_get_display(
348 GST_VAAPI_DISPLAY_X11(display)) ==
349 gst_vaapi_display_x11_get_display(
350 GST_VAAPI_DISPLAY_X11(display2)));
352 /* Check for the same VA display */
353 g_assert(gst_vaapi_display_get_display(display) ==
354 gst_vaapi_display_get_display(display2));
356 gst_vaapi_display_unref(display2);
359 display2 = gst_vaapi_display_glx_new(NULL);
361 /* Check for the different X11 display */
362 /* XXX: it is also desired to cache underlying X11 displays */
363 g_assert(gst_vaapi_display_x11_get_display(
364 GST_VAAPI_DISPLAY_X11(display)) !=
365 gst_vaapi_display_x11_get_display(
366 GST_VAAPI_DISPLAY_X11(display2)));
368 /* Check for different VA display */
369 g_assert(gst_vaapi_display_get_display(display) !=
370 gst_vaapi_display_get_display(display2));
372 gst_vaapi_display_unref(display2);
376 gst_vaapi_display_get_size(display, &width, &height);
377 g_print("Display size: %ux%u\n", width, height);
379 gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
380 g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
383 gst_vaapi_display_unref(display);
388 g_print("# Create display with gst_vaapi_display_x11_new_with_display()\n");
391 Display *x11_display;
393 x11_display = XOpenDisplay(NULL);
395 g_error("could not create X11 display");
397 display = gst_vaapi_display_x11_new_with_display(x11_display);
399 g_error("could not create Gst/VA display");
401 if (CHECK_DISPLAY_CACHE) {
402 display2 = gst_vaapi_display_x11_new_with_display(x11_display);
404 /* Check for the same VA display */
405 g_assert(gst_vaapi_display_get_display(display) ==
406 gst_vaapi_display_get_display(display2));
408 gst_vaapi_display_unref(display2);
412 gst_vaapi_display_unref(display);
413 XCloseDisplay(x11_display);
418 g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplay()]\n");
421 Display *x11_display;
422 VADisplay va_display;
424 x11_display = XOpenDisplay(NULL);
426 g_error("could not create X11 display");
428 va_display = vaGetDisplay(x11_display);
430 g_error("could not create VA display");
432 display = gst_vaapi_display_new_with_display(va_display);
434 g_error("could not create Gst/VA display");
437 gst_vaapi_display_unref(display);
438 XCloseDisplay(x11_display);
445 g_print("# Create display with gst_vaapi_display_glx_new()\n");
448 display = gst_vaapi_display_glx_new(NULL);
450 g_error("could not create Gst/VA display");
452 if (CHECK_DISPLAY_CACHE) {
453 display2 = gst_vaapi_display_glx_new(NULL);
455 /* Check for the same X11 display */
456 g_assert(gst_vaapi_display_x11_get_display(
457 GST_VAAPI_DISPLAY_X11(display)) ==
458 gst_vaapi_display_x11_get_display(
459 GST_VAAPI_DISPLAY_X11(display2)));
461 /* Check for the same VA display */
462 g_assert(gst_vaapi_display_get_display(display) ==
463 gst_vaapi_display_get_display(display2));
465 gst_vaapi_display_unref(display2);
467 display2 = gst_vaapi_display_x11_new(NULL);
469 /* Check for the same X11 display */
470 g_assert(gst_vaapi_display_x11_get_display(
471 GST_VAAPI_DISPLAY_X11(display)) ==
472 gst_vaapi_display_x11_get_display(
473 GST_VAAPI_DISPLAY_X11(display2)));
475 /* Check for the same VA display */
476 g_assert(gst_vaapi_display_get_display(display) ==
477 gst_vaapi_display_get_display(display2));
479 gst_vaapi_display_unref(display2);
482 gst_vaapi_display_get_size(display, &width, &height);
483 g_print("Display size: %ux%u\n", width, height);
485 gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
486 g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
489 gst_vaapi_display_unref(display);
494 g_print("# Create display with gst_vaapi_display_glx_new_with_display()\n");
497 Display *x11_display;
499 x11_display = XOpenDisplay(NULL);
501 g_error("could not create X11 display");
503 display = gst_vaapi_display_glx_new_with_display(x11_display);
505 g_error("could not create Gst/VA display");
508 gst_vaapi_display_unref(display);
509 XCloseDisplay(x11_display);
513 #ifdef HAVE_VA_VA_GLX_H
515 g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayGLX()]\n");
518 Display *x11_display;
519 VADisplay va_display;
521 x11_display = XOpenDisplay(NULL);
523 g_error("could not create X11 display");
525 va_display = vaGetDisplayGLX(x11_display);
527 g_error("could not create VA display");
529 display = gst_vaapi_display_new_with_display(va_display);
531 g_error("could not create Gst/VA display");
534 gst_vaapi_display_unref(display);
535 XCloseDisplay(x11_display);
543 g_print("# Create display with gst_vaapi_display_wayland_new()\n");
546 display = gst_vaapi_display_wayland_new(NULL);
548 g_error("could not create Gst/VA display");
550 gst_vaapi_display_get_size(display, &width, &height);
551 g_print("Display size: %ux%u\n", width, height);
553 gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
554 g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
557 gst_vaapi_display_unref(display);