2 * gstvaapidisplay.c - VA display abstraction
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6 * Copyright (C) 2011-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
26 * SECTION:gstvaapidisplay
27 * @short_description: VA display abstraction
31 #include "gstvaapiutils.h"
32 #include "gstvaapivalue.h"
33 #include "gstvaapidisplay.h"
34 #include "gstvaapitexturemap.h"
35 #include "gstvaapidisplay_priv.h"
36 #include "gstvaapiworkarounds.h"
38 /* Debug category for all vaapi libs */
39 GST_DEBUG_CATEGORY (gst_debug_vaapi);
41 /* Debug category for VaapiDisplay */
42 GST_DEBUG_CATEGORY (gst_debug_vaapi_display);
43 #define GST_CAT_DEFAULT gst_debug_vaapi_display
46 G_ADD_PRIVATE (GstVaapiDisplay); \
47 GST_DEBUG_CATEGORY_INIT (gst_debug_vaapi_display, \
48 "vaapidisplay", 0, "VA-API Display"); \
49 GST_DEBUG_CATEGORY_INIT (gst_debug_vaapi, "vaapi", 0, "VA-API helper");
51 G_DEFINE_TYPE_WITH_CODE (GstVaapiDisplay, gst_vaapi_display, GST_TYPE_OBJECT,
54 typedef struct _GstVaapiProfileConfig GstVaapiProfileConfig;
55 struct _GstVaapiProfileConfig
57 GstVaapiProfile profile;
58 guint32 entrypoints; /* bits map of GstVaapiEntrypoint */
61 typedef struct _GstVaapiProperty GstVaapiProperty;
62 struct _GstVaapiProperty
65 VADisplayAttribute attribute;
69 typedef struct _GstVaapiFormatInfo GstVaapiFormatInfo;
70 struct _GstVaapiFormatInfo
72 GstVideoFormat format;
76 #define DEFAULT_RENDER_MODE GST_VAAPI_RENDER_MODE_TEXTURE
77 #define DEFAULT_ROTATION GST_VAAPI_ROTATION_0
79 #define ENTRY_POINT_FLAG(entry) (1U << G_PASTE(GST_VAAPI_ENTRYPOINT_, entry))
94 static GParamSpec *g_properties[N_PROPERTIES] = { NULL, };
97 get_attribute (GstVaapiDisplay * display, VADisplayAttribType type,
101 set_attribute (GstVaapiDisplay * display, VADisplayAttribType type, gint value);
104 get_color_balance (GstVaapiDisplay * display, guint prop_id, gfloat * v);
107 set_color_balance (GstVaapiDisplay * display, guint prop_id, gfloat v);
109 /* GstVaapiDisplayType enumerations */
111 gst_vaapi_display_type_get_type (void)
113 static GType g_type = 0;
115 static const GEnumValue display_types[] = {
116 {GST_VAAPI_DISPLAY_TYPE_ANY,
117 "Auto detection", "any"},
119 {GST_VAAPI_DISPLAY_TYPE_X11,
120 "VA/X11 display", "x11"},
123 {GST_VAAPI_DISPLAY_TYPE_GLX,
124 "VA/GLX display", "glx"},
127 {GST_VAAPI_DISPLAY_TYPE_EGL,
128 "VA/EGL display", "egl"},
131 {GST_VAAPI_DISPLAY_TYPE_WAYLAND,
132 "VA/Wayland display", "wayland"},
135 {GST_VAAPI_DISPLAY_TYPE_DRM,
136 "VA/DRM display", "drm"},
142 g_type = g_enum_register_static ("GstVaapiDisplayType", display_types);
147 * gst_vaapi_display_type_is_compatible:
148 * @type1: the #GstVaapiDisplayType to test
149 * @type2: the reference #GstVaapiDisplayType
151 * Compares whether #GstVaapiDisplay @type1 is compatible with @type2.
152 * That is, if @type2 is in "any" category, or derived from @type1.
154 * Returns: %TRUE if @type1 is compatible with @type2, %FALSE otherwise.
157 gst_vaapi_display_type_is_compatible (GstVaapiDisplayType type1,
158 GstVaapiDisplayType type2)
164 case GST_VAAPI_DISPLAY_TYPE_GLX:
165 if (type2 == GST_VAAPI_DISPLAY_TYPE_X11)
171 return type2 == GST_VAAPI_DISPLAY_TYPE_ANY;
174 /* Append GstVideoFormat to formats array */
176 append_format (GArray * formats, GstVideoFormat format, guint flags)
178 GstVaapiFormatInfo fi;
182 g_array_append_val (formats, fi);
185 /* Append VAImageFormats to formats array */
187 append_formats (GArray * formats, const VAImageFormat * va_formats,
188 guint * flags, guint n)
190 GstVideoFormat format;
193 const GstVaapiFormatInfo *fip;
196 for (i = 0; i < n; i++) {
197 const VAImageFormat *const va_format = &va_formats[i];
199 format = gst_vaapi_video_format_from_va_format (va_format);
200 if (format == GST_VIDEO_FORMAT_UNKNOWN) {
201 GST_DEBUG ("unsupported format %" GST_FOURCC_FORMAT,
202 GST_FOURCC_ARGS (va_format->fourcc));
205 append_format (formats, format, flags ? flags[i] : 0);
208 case GST_VIDEO_FORMAT_YV12:
209 YV12_idx = formats->len - 1;
211 case GST_VIDEO_FORMAT_I420:
212 I420_idx = formats->len - 1;
219 /* Append I420 (resp. YV12) format if YV12 (resp. I420) is not
220 supported by the underlying driver */
221 if ((YV12_idx != -1) && (I420_idx == -1)) {
222 fip = &g_array_index (formats, GstVaapiFormatInfo, YV12_idx);
223 append_format (formats, GST_VIDEO_FORMAT_I420, fip->flags);
224 } else if ((I420_idx != -1) && (YV12_idx == -1)) {
225 fip = &g_array_index (formats, GstVaapiFormatInfo, I420_idx);
226 append_format (formats, GST_VIDEO_FORMAT_YV12, fip->flags);
230 /* Sort image formats. Prefer YUV formats first */
232 compare_yuv_formats (gconstpointer a, gconstpointer b)
234 const GstVideoFormat fmt1 = ((GstVaapiFormatInfo *) a)->format;
235 const GstVideoFormat fmt2 = ((GstVaapiFormatInfo *) b)->format;
237 const gboolean is_fmt1_yuv = gst_vaapi_video_format_is_yuv (fmt1);
238 const gboolean is_fmt2_yuv = gst_vaapi_video_format_is_yuv (fmt2);
240 if (is_fmt1_yuv != is_fmt2_yuv)
241 return is_fmt1_yuv ? -1 : 1;
243 return ((gint) gst_vaapi_video_format_get_score (fmt1) -
244 (gint) gst_vaapi_video_format_get_score (fmt2));
247 /* Sort subpicture formats. Prefer RGB formats first */
249 compare_rgb_formats (gconstpointer a, gconstpointer b)
251 const GstVideoFormat fmt1 = ((GstVaapiFormatInfo *) a)->format;
252 const GstVideoFormat fmt2 = ((GstVaapiFormatInfo *) b)->format;
254 const gboolean is_fmt1_rgb = gst_vaapi_video_format_is_rgb (fmt1);
255 const gboolean is_fmt2_rgb = gst_vaapi_video_format_is_rgb (fmt2);
257 if (is_fmt1_rgb != is_fmt2_rgb)
258 return is_fmt1_rgb ? -1 : 1;
260 return ((gint) gst_vaapi_video_format_get_score (fmt1) -
261 (gint) gst_vaapi_video_format_get_score (fmt2));
264 /* Check if configs array contains profile at entrypoint */
265 static inline gboolean
266 find_config (GPtrArray * configs, GstVaapiProfile profile,
267 GstVaapiEntrypoint entrypoint)
269 GstVaapiProfileConfig *config;
275 for (i = 0; i < configs->len; i++) {
276 config = g_ptr_array_index (configs, i);
277 if (config->profile == profile
278 && (config->entrypoints & (1U << entrypoint)))
284 /* HACK: append H.263 Baseline profile if MPEG-4:2 Simple profile is supported */
286 append_h263_config (GArray * configs, GPtrArray * decoders)
288 GstVaapiProfileConfig *config, tmp_config;
289 GstVaapiProfileConfig *mpeg4_simple_config = NULL;
290 GstVaapiProfileConfig *h263_baseline_config = NULL;
293 if (!WORKAROUND_H263_BASELINE_DECODE_PROFILE)
299 for (i = 0; i < decoders->len; i++) {
300 config = g_ptr_array_index (decoders, i);
301 if (config->profile == GST_VAAPI_PROFILE_MPEG4_SIMPLE)
302 mpeg4_simple_config = config;
303 else if (config->profile == GST_VAAPI_PROFILE_H263_BASELINE)
304 h263_baseline_config = config;
307 if (mpeg4_simple_config && !h263_baseline_config) {
308 tmp_config = *mpeg4_simple_config;
309 tmp_config.profile = GST_VAAPI_PROFILE_H263_BASELINE;
310 tmp_config.entrypoints = ENTRY_POINT_FLAG (VLD);
311 g_array_append_val (configs, tmp_config);
312 g_ptr_array_add (decoders, &g_array_index (configs,
313 GstVaapiProfileConfig, configs->len - 1));
317 /* Sort profiles. Group per codec */
319 compare_profiles (gconstpointer a, gconstpointer b)
321 const GstVaapiProfileConfig *const config1 = (GstVaapiProfileConfig *) a;
322 const GstVaapiProfileConfig *const config2 = (GstVaapiProfileConfig *) b;
324 g_assert (config1->profile != config2->profile);
325 return config1->profile - config2->profile;
328 /* Convert configs array to profiles as GstCaps */
330 get_profiles (GPtrArray * configs, GstVaapiCodec codec)
332 GstVaapiProfileConfig *config;
333 GArray *out_profiles;
339 out_profiles = g_array_new (FALSE, FALSE, sizeof (GstVaapiProfile));
343 for (i = 0; i < configs->len; i++) {
344 config = g_ptr_array_index (configs, i);
345 if (!codec || (codec == gst_vaapi_profile_get_codec (config->profile)))
346 g_array_append_val (out_profiles, config->profile);
351 /* Find format info */
352 static const GstVaapiFormatInfo *
353 find_format_info (GArray * formats, GstVideoFormat format)
355 const GstVaapiFormatInfo *fip;
358 for (i = 0; i < formats->len; i++) {
359 fip = &g_array_index (formats, GstVaapiFormatInfo, i);
360 if (fip->format == format)
366 /* Check if formats array contains format */
367 static inline gboolean
368 find_format (GArray * formats, GstVideoFormat format)
370 return find_format_info (formats, format) != NULL;
373 /* Convert formats array to GstCaps */
375 get_formats (GArray * formats)
377 const GstVaapiFormatInfo *fip;
381 out_formats = g_array_new (FALSE, FALSE, sizeof (GstVideoFormat));
385 for (i = 0; i < formats->len; i++) {
386 fip = &g_array_index (formats, GstVaapiFormatInfo, i);
387 g_array_append_val (out_formats, fip->format);
392 /* Find display attribute */
393 static const GstVaapiProperty *
394 find_property (GArray * properties, const gchar * name)
396 GstVaapiProperty *prop;
402 for (i = 0; i < properties->len; i++) {
403 prop = &g_array_index (properties, GstVaapiProperty, i);
404 if (strcmp (prop->name, name) == 0)
411 static const GstVaapiProperty *
412 find_property_by_type (GArray * properties, VADisplayAttribType type)
414 GstVaapiProperty *prop;
417 for (i = 0; i < properties->len; i++) {
418 prop = &g_array_index (properties, GstVaapiProperty, i);
419 if (prop->attribute.type == type)
426 static inline const GstVaapiProperty *
427 find_property_by_pspec (GstVaapiDisplay * display, GParamSpec * pspec)
429 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
431 return find_property (priv->properties, pspec->name);
435 find_property_id (const gchar * name)
443 static const property_map g_property_map[] = {
444 {GST_VAAPI_DISPLAY_PROP_RENDER_MODE, PROP_RENDER_MODE},
445 {GST_VAAPI_DISPLAY_PROP_ROTATION, PROP_ROTATION},
446 {GST_VAAPI_DISPLAY_PROP_HUE, PROP_HUE},
447 {GST_VAAPI_DISPLAY_PROP_SATURATION, PROP_SATURATION},
448 {GST_VAAPI_DISPLAY_PROP_BRIGHTNESS, PROP_BRIGHTNESS},
449 {GST_VAAPI_DISPLAY_PROP_CONTRAST, PROP_CONTRAST},
453 const property_map *m;
454 for (m = g_property_map; m->name != NULL; m++) {
455 if (strcmp (m->name, name) == 0)
461 /* Initialize VA profiles (decoders, encoders) */
463 ensure_profiles (GstVaapiDisplay * display)
465 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
466 VAProfile *profiles = NULL;
467 VAEntrypoint *entrypoints = NULL;
468 gint i, j, n, num_entrypoints;
470 gboolean success = FALSE;
472 GST_VAAPI_DISPLAY_LOCK (display);
474 if (priv->has_profiles) {
475 GST_VAAPI_DISPLAY_UNLOCK (display);
479 priv->codecs = g_array_new (FALSE, FALSE, sizeof (GstVaapiProfileConfig));
483 priv->decoders = g_ptr_array_new ();
486 priv->encoders = g_ptr_array_new ();
489 priv->has_profiles = TRUE;
492 profiles = g_new (VAProfile, vaMaxNumProfiles (priv->display));
495 entrypoints = g_new (VAEntrypoint, vaMaxNumEntrypoints (priv->display));
500 status = vaQueryConfigProfiles (priv->display, profiles, &n);
501 if (!vaapi_check_status (status, "vaQueryConfigProfiles()"))
504 GST_DEBUG ("%d profiles", n);
505 for (i = 0; i < n; i++) {
506 if (profiles[i] == VAProfileNone)
508 GST_DEBUG (" %s", string_of_VAProfile (profiles[i]));
511 for (i = 0; i < n; i++) {
512 GstVaapiProfileConfig config = { 0, };
514 config.profile = gst_vaapi_profile (profiles[i]);
518 status = vaQueryConfigEntrypoints (priv->display,
519 profiles[i], entrypoints, &num_entrypoints);
520 if (!vaapi_check_status (status, "vaQueryConfigEntrypoints()"))
523 for (j = 0; j < num_entrypoints; j++)
524 config.entrypoints |= (1U << gst_vaapi_entrypoint (entrypoints[j]));
526 priv->codecs = g_array_append_val (priv->codecs, config);
529 for (i = 0; i < priv->codecs->len; i++) {
530 GstVaapiProfileConfig *cfg;
532 cfg = &g_array_index (priv->codecs, GstVaapiProfileConfig, i);
534 if ((cfg->entrypoints & ENTRY_POINT_FLAG (VLD))
535 || (cfg->entrypoints & ENTRY_POINT_FLAG (IDCT))
536 || (cfg->entrypoints & ENTRY_POINT_FLAG (MOCO)))
537 g_ptr_array_add (priv->decoders, cfg);
538 if ((cfg->entrypoints & ENTRY_POINT_FLAG (SLICE_ENCODE))
539 || (cfg->entrypoints & ENTRY_POINT_FLAG (PICTURE_ENCODE))
540 || (cfg->entrypoints & ENTRY_POINT_FLAG (SLICE_ENCODE_LP)))
541 g_ptr_array_add (priv->encoders, cfg);
544 append_h263_config (priv->codecs, priv->decoders);
546 g_ptr_array_sort (priv->decoders, compare_profiles);
547 g_ptr_array_sort (priv->encoders, compare_profiles);
549 /* Video processing API */
550 status = vaQueryConfigEntrypoints (priv->display, VAProfileNone,
551 entrypoints, &num_entrypoints);
552 if (vaapi_check_status (status, "vaQueryEntrypoints() [VAProfileNone]")) {
553 for (j = 0; j < num_entrypoints; j++) {
554 if (entrypoints[j] == VAEntrypointVideoProc)
555 priv->has_vpp = TRUE;
562 g_free (entrypoints);
563 GST_VAAPI_DISPLAY_UNLOCK (display);
567 /* Initialize VA display attributes */
569 ensure_properties (GstVaapiDisplay * display)
571 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
572 VADisplayAttribute *display_attrs = NULL;
575 gboolean success = FALSE;
577 if (priv->properties)
580 priv->properties = g_array_new (FALSE, FALSE, sizeof (GstVaapiProperty));
581 if (!priv->properties)
584 /* VA display attributes */
586 g_new (VADisplayAttribute, vaMaxNumDisplayAttributes (priv->display));
591 status = vaQueryDisplayAttributes (priv->display, display_attrs, &n);
592 if (!vaapi_check_status (status, "vaQueryDisplayAttributes()"))
595 GST_DEBUG ("%d display attributes", n);
596 for (i = 0; i < n; i++) {
597 VADisplayAttribute *const attr = &display_attrs[i];
598 GstVaapiProperty prop;
601 GST_DEBUG (" %s", string_of_VADisplayAttributeType (attr->type));
603 switch (attr->type) {
604 case VADisplayAttribRenderMode:
605 prop.name = GST_VAAPI_DISPLAY_PROP_RENDER_MODE;
607 case VADisplayAttribRotation:
608 prop.name = GST_VAAPI_DISPLAY_PROP_ROTATION;
610 case VADisplayAttribHue:
611 prop.name = GST_VAAPI_DISPLAY_PROP_HUE;
613 case VADisplayAttribSaturation:
614 prop.name = GST_VAAPI_DISPLAY_PROP_SATURATION;
616 case VADisplayAttribBrightness:
617 prop.name = GST_VAAPI_DISPLAY_PROP_BRIGHTNESS;
619 case VADisplayAttribContrast:
620 prop.name = GST_VAAPI_DISPLAY_PROP_CONTRAST;
629 /* Assume the attribute is really supported if we can get the
630 * actual and current value */
631 if (!get_attribute (display, attr->type, &value))
634 /* Some drivers (e.g. EMGD) have completely random initial
636 if (value < attr->min_value || value > attr->max_value)
639 prop.attribute = *attr;
640 prop.old_value = value;
641 g_array_append_val (priv->properties, prop);
646 g_free (display_attrs);
650 /* Initialize VA image formats */
652 ensure_image_formats (GstVaapiDisplay * display)
654 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
655 VAImageFormat *formats = NULL;
657 gint i, n, max_images;
658 gboolean success = FALSE;
660 GST_VAAPI_DISPLAY_LOCK (display);
661 if (priv->image_formats) {
662 GST_VAAPI_DISPLAY_UNLOCK (display);
666 priv->image_formats = g_array_new (FALSE, FALSE, sizeof (GstVaapiFormatInfo));
667 if (!priv->image_formats)
670 /* VA image formats */
671 max_images = vaMaxNumImageFormats (priv->display);
672 formats = g_new (VAImageFormat, max_images);
677 status = vaQueryImageFormats (priv->display, formats, &n);
678 if (!vaapi_check_status (status, "vaQueryImageFormats()"))
681 /* XXX(victor): Force RGBA in i965 display formats.
683 * This is required for GLTextureUploadMeta since it only negotiates
684 * RGBA, nevertheless i965 driver only reports RGBx breaking back
687 * Side effects are not expected since it worked before commit
689 if (gst_vaapi_display_has_driver_quirks (display,
690 GST_VAAPI_DRIVER_QUIRK_MISSING_RGBA_IMAGE_FORMAT)) {
691 formats = g_renew (VAImageFormat, formats, max_images + 1);
693 formats[n].fourcc = VA_FOURCC_RGBA;
694 formats[n].byte_order = VA_LSB_FIRST;
695 formats[n].bits_per_pixel = 32;
696 formats[n].depth = 32;
697 formats[n].red_mask = 0x000000ff;
698 formats[n].green_mask = 0x0000ff00;
699 formats[n].blue_mask = 0x00ff0000;
700 formats[n].alpha_mask = 0xff000000;
704 GST_DEBUG ("%d image formats", n);
705 for (i = 0; i < n; i++)
706 GST_DEBUG (" %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (formats[i].fourcc));
708 if (!gst_vaapi_video_format_create_map (formats, n)) {
709 GST_ERROR ("fail to create map between gst video format and vaImageFormat");
713 append_formats (priv->image_formats, formats, NULL, n);
714 g_array_sort (priv->image_formats, compare_yuv_formats);
719 GST_VAAPI_DISPLAY_UNLOCK (display);
723 /* Initialize VA subpicture formats */
725 ensure_subpicture_formats (GstVaapiDisplay * display)
727 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
728 VAImageFormat *formats = NULL;
729 unsigned int *flags = NULL;
732 gboolean success = FALSE;
734 GST_VAAPI_DISPLAY_LOCK (display);
735 if (priv->subpicture_formats) {
736 GST_VAAPI_DISPLAY_UNLOCK (display);
740 priv->subpicture_formats =
741 g_array_new (FALSE, FALSE, sizeof (GstVaapiFormatInfo));
742 if (!priv->subpicture_formats)
745 /* VA subpicture formats */
746 n = vaMaxNumSubpictureFormats (priv->display);
747 formats = g_new (VAImageFormat, n);
750 flags = g_new (guint, n);
755 status = vaQuerySubpictureFormats (priv->display, formats, flags, &n);
756 if (!vaapi_check_status (status, "vaQuerySubpictureFormats()"))
759 GST_DEBUG ("%d subpicture formats", n);
760 for (i = 0; i < n; i++) {
761 GST_DEBUG (" %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (formats[i].fourcc));
762 flags[i] = to_GstVaapiSubpictureFlags (flags[i]);
765 append_formats (priv->subpicture_formats, formats, flags, n);
766 g_array_sort (priv->subpicture_formats, compare_rgb_formats);
772 GST_VAAPI_DISPLAY_UNLOCK (display);
776 /* Ensures the VA driver vendor string was copied */
778 ensure_vendor_string (GstVaapiDisplay * display)
780 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
781 const gchar *vendor_string;
783 GST_VAAPI_DISPLAY_LOCK (display);
784 if (!priv->vendor_string) {
785 vendor_string = vaQueryVendorString (priv->display);
787 priv->vendor_string = g_strdup (vendor_string);
788 GST_INFO_OBJECT (display, "vendor: %s", priv->vendor_string);
790 GST_VAAPI_DISPLAY_UNLOCK (display);
791 return priv->vendor_string != NULL;
795 set_driver_quirks (GstVaapiDisplay * display)
797 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
803 const char *match_string;
805 } vaapi_driver_quirks_table[] = {
806 /* @XXX(victor): is this string enough to identify it */
807 { "AMD", GST_VAAPI_DRIVER_QUIRK_NO_CHECK_SURFACE_PUT_IMAGE },
808 { "i965", GST_VAAPI_DRIVER_QUIRK_NO_CHECK_VPP_COLOR_STD },
809 { "i965", GST_VAAPI_DRIVER_QUIRK_MISSING_RGBA_IMAGE_FORMAT },
810 { "iHD", GST_VAAPI_DRIVER_QUIRK_JPEG_ENC_SHIFT_VALUE_BY_50 },
811 { "iHD", GST_VAAPI_DRIVER_QUIRK_HEVC_ENC_SLICE_NOT_SPAN_TILE },
812 { "i965", GST_VAAPI_DRIVER_QUIRK_JPEG_DEC_BROKEN_FORMATS },
816 if (!ensure_vendor_string (display))
819 for (i = 0; i < G_N_ELEMENTS (vaapi_driver_quirks_table); i++) {
820 const char *match_str = vaapi_driver_quirks_table[i].match_string;
821 if (g_strstr_len (priv->vendor_string, strlen (priv->vendor_string),
822 match_str) != NULL) {
823 priv->driver_quirks |= vaapi_driver_quirks_table[i].quirks;
827 GST_INFO_OBJECT (display, "Matched driver string \"%s\", setting quirks "
828 "(%#x)", priv->vendor_string, priv->driver_quirks);
832 gst_vaapi_display_calculate_pixel_aspect_ratio (GstVaapiDisplay * display)
834 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
835 gdouble ratio, delta;
836 gint i, j, index, windex;
838 static const gint par[][2] = {
839 {1, 1}, /* regular screen */
840 {16, 15}, /* PAL TV */
841 {11, 10}, /* 525 line Rec.601 video */
842 {54, 59}, /* 625 line Rec.601 video */
843 {64, 45}, /* 1280x1024 on 16:9 display */
844 {5, 3}, /* 1280x1024 on 4:3 display */
845 {4, 3} /* 800x600 on 16:9 display */
848 /* First, calculate the "real" ratio based on the X values;
849 * which is the "physical" w/h divided by the w/h in pixels of the
851 if (!priv->width || !priv->height || !priv->width_mm || !priv->height_mm)
854 ratio = (gdouble) (priv->width_mm * priv->height) /
855 (priv->height_mm * priv->width);
856 GST_DEBUG ("calculated pixel aspect ratio: %f", ratio);
858 /* Now, find the one from par[][2] with the lowest delta to the real one */
859 #define DELTA(idx, w) (ABS(ratio - ((gdouble)par[idx][w] / par[idx][!(w)])))
860 delta = DELTA (0, 0);
864 for (i = 1; i < G_N_ELEMENTS (par); i++) {
865 for (j = 0; j < 2; j++) {
866 const gdouble this_delta = DELTA (i, j);
867 if (this_delta < delta) {
876 priv->par_n = par[index][windex];
877 priv->par_d = par[index][windex ^ 1];
881 gst_vaapi_display_ensure_screen_resolution (GstVaapiDisplay * display)
883 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
884 const GstVaapiDisplayClass *const klass =
885 GST_VAAPI_DISPLAY_GET_CLASS (display);
887 if (priv->got_scrres)
891 klass->get_size (display, &priv->width, &priv->height);
892 if (klass->get_size_mm)
893 klass->get_size_mm (display, &priv->width_mm, &priv->height_mm);
895 gst_vaapi_display_calculate_pixel_aspect_ratio (display);
896 priv->got_scrres = TRUE;
900 gst_vaapi_display_destroy (GstVaapiDisplay * display)
902 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
903 GstVaapiDisplayClass *klass = GST_VAAPI_DISPLAY_GET_CLASS (display);
905 g_clear_pointer (&priv->decoders, g_ptr_array_unref);
906 g_clear_pointer (&priv->encoders, g_ptr_array_unref);
907 g_clear_pointer (&priv->codecs, g_array_unref);
908 g_clear_pointer (&priv->image_formats, g_array_unref);
909 g_clear_pointer (&priv->subpicture_formats, g_array_unref);
910 g_clear_pointer (&priv->properties, g_array_unref);
914 vaTerminate (priv->display);
915 priv->display = NULL;
918 if (klass->close_display)
919 klass->close_display (display);
921 g_clear_pointer (&priv->display_name, g_free);
922 g_clear_pointer (&priv->vendor_string, g_free);
924 gst_vaapi_display_replace (&priv->parent, NULL);
928 gst_vaapi_display_create (GstVaapiDisplay * display,
929 GstVaapiDisplayInitType init_type, gpointer data)
931 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
932 const GstVaapiDisplayClass *const klass =
933 GST_VAAPI_DISPLAY_GET_CLASS (display);
934 GstVaapiDisplayInfo info = {
939 case GST_VAAPI_DISPLAY_INIT_FROM_VA_DISPLAY:{
940 GstVaapiDisplayInfo *p_info = data;
942 info.va_display = p_info->va_display;
943 priv->display = p_info->va_display;
944 priv->use_foreign_display = TRUE;
946 if (!klass->bind_display)
949 data = p_info->native_display;
952 case GST_VAAPI_DISPLAY_INIT_FROM_DISPLAY_NAME:
953 if (klass->open_display && !klass->open_display (display, data))
956 case GST_VAAPI_DISPLAY_INIT_FROM_NATIVE_DISPLAY:
958 if (klass->bind_display && !klass->bind_display (display, data))
962 if (!klass->get_display || !klass->get_display (display, &info))
964 priv->display = info.va_display;
965 priv->native_display = info.native_display;
972 if (!vaapi_initialize (priv->display))
976 GST_INFO_OBJECT (display, "new display addr=%p", display);
977 g_free (priv->display_name);
978 priv->display_name = g_strdup (info.display_name);
980 set_driver_quirks (display);
982 if (!ensure_image_formats (display)) {
983 gst_vaapi_display_destroy (display);
991 gst_vaapi_display_lock_default (GstVaapiDisplay * display)
993 GstVaapiDisplayPrivate *priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
996 priv = GST_VAAPI_DISPLAY_GET_PRIVATE (priv->parent);
997 g_rec_mutex_lock (&priv->mutex);
1001 gst_vaapi_display_unlock_default (GstVaapiDisplay * display)
1003 GstVaapiDisplayPrivate *priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
1006 priv = GST_VAAPI_DISPLAY_GET_PRIVATE (priv->parent);
1007 g_rec_mutex_unlock (&priv->mutex);
1011 gst_vaapi_display_init (GstVaapiDisplay * display)
1013 GstVaapiDisplayPrivate *const priv =
1014 gst_vaapi_display_get_instance_private (display);
1016 display->priv = priv;
1020 g_rec_mutex_init (&priv->mutex);
1024 _set_property (GstVaapiDisplay * display, const GstVaapiProperty * prop,
1025 const GValue * value)
1027 switch (prop->attribute.type) {
1028 case VADisplayAttribRenderMode:{
1029 GstVaapiRenderMode mode;
1030 if (!G_VALUE_HOLDS (value, GST_VAAPI_TYPE_RENDER_MODE))
1032 mode = g_value_get_enum (value);
1033 return gst_vaapi_display_set_render_mode (display, mode);
1035 case VADisplayAttribRotation:{
1036 GstVaapiRotation rotation;
1037 if (!G_VALUE_HOLDS (value, GST_VAAPI_TYPE_ROTATION))
1039 rotation = g_value_get_enum (value);
1040 return gst_vaapi_display_set_rotation (display, rotation);
1042 case VADisplayAttribHue:
1043 case VADisplayAttribSaturation:
1044 case VADisplayAttribBrightness:
1045 case VADisplayAttribContrast:{
1047 if (!G_VALUE_HOLDS (value, G_TYPE_FLOAT))
1049 v = g_value_get_float (value);
1050 return set_color_balance (display, find_property_id (prop->name), v);
1056 GST_WARNING ("unsupported property '%s'", prop->name);
1061 gst_vaapi_display_set_property (GObject * object, guint property_id,
1062 const GValue * value, GParamSpec * pspec)
1064 GstVaapiDisplay *display = GST_VAAPI_DISPLAY (object);
1065 const GstVaapiProperty *prop;
1067 if (!ensure_properties (display))
1070 prop = find_property_by_pspec (display, pspec);
1072 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1076 _set_property (display, prop, value);
1080 _get_property (GstVaapiDisplay * display, const GstVaapiProperty * prop,
1083 switch (prop->attribute.type) {
1084 case VADisplayAttribRenderMode:{
1085 GstVaapiRenderMode mode;
1086 if (!gst_vaapi_display_get_render_mode (display, &mode))
1088 if (!G_IS_VALUE (value))
1089 g_value_init (value, GST_VAAPI_TYPE_RENDER_MODE);
1090 g_value_set_enum (value, mode);
1093 case VADisplayAttribRotation:{
1094 GstVaapiRotation rotation;
1095 rotation = gst_vaapi_display_get_rotation (display);
1096 if (!G_IS_VALUE (value))
1097 g_value_init (value, GST_VAAPI_TYPE_ROTATION);
1098 g_value_set_enum (value, rotation);
1101 case VADisplayAttribHue:
1102 case VADisplayAttribSaturation:
1103 case VADisplayAttribBrightness:
1104 case VADisplayAttribContrast:{
1106 if (!get_color_balance (display, find_property_id (prop->name), &val))
1108 if (!G_IS_VALUE (value))
1109 g_value_init (value, G_TYPE_FLOAT);
1110 g_value_set_float (value, val);
1114 GST_WARNING ("unsupported property '%s'", prop->name);
1121 gst_vaapi_display_get_property (GObject * object, guint property_id,
1122 GValue * value, GParamSpec * pspec)
1124 GstVaapiDisplay *display = GST_VAAPI_DISPLAY (object);
1125 const GstVaapiProperty *prop;
1127 if (property_id == PROP_VA_DISPLAY) {
1128 g_value_set_pointer (value, gst_vaapi_display_get_display (display));
1132 if (!ensure_properties (display))
1135 prop = find_property_by_pspec (display, pspec);
1137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1141 _get_property (display, prop, value);
1145 gst_vaapi_display_finalize (GObject * object)
1147 GstVaapiDisplay *const display = GST_VAAPI_DISPLAY (object);
1148 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
1150 gst_vaapi_display_destroy (display);
1151 g_rec_mutex_clear (&priv->mutex);
1153 G_OBJECT_CLASS (gst_vaapi_display_parent_class)->finalize (object);
1157 gst_vaapi_display_class_init (GstVaapiDisplayClass * klass)
1159 GObjectClass *const object_class = G_OBJECT_CLASS (klass);
1161 object_class->finalize = gst_vaapi_display_finalize;
1162 object_class->set_property = gst_vaapi_display_set_property;
1163 object_class->get_property = gst_vaapi_display_get_property;
1165 klass->lock = gst_vaapi_display_lock_default;
1166 klass->unlock = gst_vaapi_display_unlock_default;
1169 * GstVaapiDisplay:render-mode:
1171 * The VA display rendering mode, expressed as a #GstVaapiRenderMode.
1173 g_properties[PROP_RENDER_MODE] =
1174 g_param_spec_enum (GST_VAAPI_DISPLAY_PROP_RENDER_MODE,
1176 "The display rendering mode",
1177 GST_VAAPI_TYPE_RENDER_MODE, DEFAULT_RENDER_MODE, G_PARAM_READWRITE);
1180 * GstVaapiDisplay:rotation:
1182 * The VA display rotation mode, expressed as a #GstVaapiRotation.
1184 g_properties[PROP_ROTATION] =
1185 g_param_spec_enum (GST_VAAPI_DISPLAY_PROP_ROTATION,
1187 "The display rotation mode",
1188 GST_VAAPI_TYPE_ROTATION, DEFAULT_ROTATION, G_PARAM_READWRITE);
1191 * GstVaapiDisplay:hue:
1193 * The VA display hue, expressed as a float value. Range is -180.0
1194 * to 180.0. Default value is 0.0 and represents no modification.
1196 g_properties[PROP_HUE] =
1197 g_param_spec_float (GST_VAAPI_DISPLAY_PROP_HUE,
1198 "hue", "The display hue value", -180.0, 180.0, 0.0, G_PARAM_READWRITE);
1201 * GstVaapiDisplay:saturation:
1203 * The VA display saturation, expressed as a float value. Range is
1204 * 0.0 to 2.0. Default value is 1.0 and represents no modification.
1206 g_properties[PROP_SATURATION] =
1207 g_param_spec_float (GST_VAAPI_DISPLAY_PROP_SATURATION,
1209 "The display saturation value", 0.0, 2.0, 1.0, G_PARAM_READWRITE);
1212 * GstVaapiDisplay:brightness:
1214 * The VA display brightness, expressed as a float value. Range is
1215 * -1.0 to 1.0. Default value is 0.0 and represents no modification.
1217 g_properties[PROP_BRIGHTNESS] =
1218 g_param_spec_float (GST_VAAPI_DISPLAY_PROP_BRIGHTNESS,
1220 "The display brightness value", -1.0, 1.0, 0.0, G_PARAM_READWRITE);
1223 * GstVaapiDisplay:contrast:
1225 * The VA display contrast, expressed as a float value. Range is 0.0
1226 * to 2.0. Default value is 1.0 and represents no modification.
1228 g_properties[PROP_CONTRAST] =
1229 g_param_spec_float (GST_VAAPI_DISPLAY_PROP_CONTRAST,
1231 "The display contrast value", 0.0, 2.0, 1.0, G_PARAM_READWRITE);
1234 * GstVaapiDisplay:va-display:
1236 * The VA display handle, expressed as a #VADisplay.
1238 g_properties[PROP_VA_DISPLAY] =
1239 g_param_spec_pointer ("va-display", "VADisplay",
1240 "VA Display handler", G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1242 g_object_class_install_properties (object_class, N_PROPERTIES, g_properties);
1243 gst_type_mark_as_plugin_api (gst_vaapi_display_type_get_type (), 0);
1247 * gst_vaapi_display_config:
1248 * @display: instance of #GstVaapiDisplay
1249 * @init_type: type of initialization #GstVaapiDisplayInitType
1250 * @init_value: a pointer to the structure with the initialization
1253 * Binds @display to the VA layer; otherwise it is just an empty
1256 * Returns: the configured @display if it was configured correctly;
1257 * otherwise unrefs @display and returns %NULL.
1260 gst_vaapi_display_config (GstVaapiDisplay * display,
1261 GstVaapiDisplayInitType init_type, gpointer init_value)
1263 g_return_val_if_fail (display && GST_VAAPI_IS_DISPLAY (display), NULL);
1265 if (!gst_vaapi_display_create (display, init_type, init_value))
1272 gst_object_unref (display);
1278 * gst_vaapi_display_new_with_display:
1279 * @va_display: a #VADisplay
1281 * Creates a new #GstVaapiDisplay, using @va_display as the VA
1284 * Return value: the newly created #GstVaapiDisplay object
1287 gst_vaapi_display_new_with_display (VADisplay va_display)
1289 GstVaapiDisplayInfo info = {
1290 .va_display = va_display,
1293 return gst_vaapi_display_config (g_object_new (GST_TYPE_VAAPI_DISPLAY, NULL),
1294 GST_VAAPI_DISPLAY_INIT_FROM_VA_DISPLAY, &info);
1298 * gst_vaapi_display_replace:
1299 * @old_display_ptr: a pointer to a #GstVaapiDisplay
1300 * @new_display: a #GstVaapiDisplay
1302 * Atomically replaces the display display held in @old_display_ptr
1303 * with @new_display. This means that @old_display_ptr shall reference
1304 * a valid display. However, @new_display can be NULL.
1307 gst_vaapi_display_replace (GstVaapiDisplay ** old_display_ptr,
1308 GstVaapiDisplay * new_display)
1310 gst_object_replace ((GstObject **) old_display_ptr,
1311 (GstObject *) new_display);
1315 * gst_vaapi_display_lock:
1316 * @display: a #GstVaapiDisplay
1318 * Locks @display. If @display is already locked by another thread,
1319 * the current thread will block until @display is unlocked by the
1323 gst_vaapi_display_lock (GstVaapiDisplay * display)
1325 GstVaapiDisplayClass *klass;
1327 g_return_if_fail (display != NULL);
1329 klass = GST_VAAPI_DISPLAY_GET_CLASS (display);
1331 klass->lock (display);
1335 * gst_vaapi_display_unlock:
1336 * @display: a #GstVaapiDisplay
1338 * Unlocks @display. If another thread is blocked in a
1339 * gst_vaapi_display_lock() call for @display, it will be woken and
1340 * can lock @display itself.
1343 gst_vaapi_display_unlock (GstVaapiDisplay * display)
1345 GstVaapiDisplayClass *klass;
1347 g_return_if_fail (display != NULL);
1349 klass = GST_VAAPI_DISPLAY_GET_CLASS (display);
1351 klass->unlock (display);
1355 * gst_vaapi_display_sync:
1356 * @display: a #GstVaapiDisplay
1358 * Flushes any requests queued for the windowing system and waits until
1359 * all requests have been handled. This is often used for making sure
1360 * that the display is synchronized with the current state of the program.
1362 * This is most useful for X11. On windowing systems where requests are
1363 * handled synchronously, this function will do nothing.
1366 gst_vaapi_display_sync (GstVaapiDisplay * display)
1368 GstVaapiDisplayClass *klass;
1370 g_return_if_fail (display != NULL);
1372 klass = GST_VAAPI_DISPLAY_GET_CLASS (display);
1374 klass->sync (display);
1375 else if (klass->flush)
1376 klass->flush (display);
1380 * gst_vaapi_display_flush:
1381 * @display: a #GstVaapiDisplay
1383 * Flushes any requests queued for the windowing system.
1385 * This is most useful for X11. On windowing systems where requests
1386 * are handled synchronously, this function will do nothing.
1389 gst_vaapi_display_flush (GstVaapiDisplay * display)
1391 GstVaapiDisplayClass *klass;
1393 g_return_if_fail (display != NULL);
1395 klass = GST_VAAPI_DISPLAY_GET_CLASS (display);
1397 klass->flush (display);
1401 * gst_vaapi_display_get_class_type:
1402 * @display: a #GstVaapiDisplay
1404 * Returns the #GstVaapiDisplayType of @display. This is the type of
1405 * the object, thus the associated class, not the type of the VA
1408 * Return value: the #GstVaapiDisplayType
1411 gst_vaapi_display_get_class_type (GstVaapiDisplay * display)
1413 g_return_val_if_fail (display != NULL, GST_VAAPI_DISPLAY_TYPE_ANY);
1415 return GST_VAAPI_DISPLAY_GET_CLASS_TYPE (display);
1419 * gst_vaapi_display_get_display_type:
1420 * @display: a #GstVaapiDisplay
1422 * Returns the #GstVaapiDisplayType of the VA display bound to
1423 * @display. This is not the type of the @display object.
1425 * Return value: the #GstVaapiDisplayType
1428 gst_vaapi_display_get_display_type (GstVaapiDisplay * display)
1430 g_return_val_if_fail (display != NULL, GST_VAAPI_DISPLAY_TYPE_ANY);
1432 return GST_VAAPI_DISPLAY_VADISPLAY_TYPE (display);
1436 * gst_vaapi_display_get_display_type:
1437 * @display: a #GstVaapiDisplay
1439 * Returns the @display name.
1441 * Return value: the display name
1444 gst_vaapi_display_get_display_name (GstVaapiDisplay * display)
1446 g_return_val_if_fail (display != NULL, NULL);
1448 return GST_VAAPI_DISPLAY_GET_PRIVATE (display)->display_name;
1452 * gst_vaapi_display_get_display:
1453 * @display: a #GstVaapiDisplay
1455 * Returns the #VADisplay bound to @display.
1457 * Return value: the #VADisplay
1460 gst_vaapi_display_get_display (GstVaapiDisplay * display)
1462 g_return_val_if_fail (display != NULL, NULL);
1464 return GST_VAAPI_DISPLAY_GET_PRIVATE (display)->display;
1468 * gst_vaapi_display_get_width:
1469 * @display: a #GstVaapiDisplay
1471 * Retrieves the width of a #GstVaapiDisplay.
1473 * Return value: the width of the @display, in pixels
1476 gst_vaapi_display_get_width (GstVaapiDisplay * display)
1478 g_return_val_if_fail (display != NULL, 0);
1480 gst_vaapi_display_ensure_screen_resolution (display);
1482 return GST_VAAPI_DISPLAY_GET_PRIVATE (display)->width;
1486 * gst_vaapi_display_get_height:
1487 * @display: a #GstVaapiDisplay
1489 * Retrieves the height of a #GstVaapiDisplay
1491 * Return value: the height of the @display, in pixels
1494 gst_vaapi_display_get_height (GstVaapiDisplay * display)
1496 g_return_val_if_fail (display != NULL, 0);
1498 gst_vaapi_display_ensure_screen_resolution (display);
1500 return GST_VAAPI_DISPLAY_GET_PRIVATE (display)->height;
1504 * gst_vaapi_display_get_size:
1505 * @display: a #GstVaapiDisplay
1506 * @pwidth: return location for the width, or %NULL
1507 * @pheight: return location for the height, or %NULL
1509 * Retrieves the dimensions of a #GstVaapiDisplay.
1512 gst_vaapi_display_get_size (GstVaapiDisplay * display, guint * pwidth,
1515 g_return_if_fail (GST_VAAPI_DISPLAY (display));
1517 gst_vaapi_display_ensure_screen_resolution (display);
1520 *pwidth = GST_VAAPI_DISPLAY_GET_PRIVATE (display)->width;
1523 *pheight = GST_VAAPI_DISPLAY_GET_PRIVATE (display)->height;
1527 * gst_vaapi_display_get_pixel_aspect_ratio:
1528 * @display: a #GstVaapiDisplay
1529 * @par_n: return location for the numerator of pixel aspect ratio, or %NULL
1530 * @par_d: return location for the denominator of pixel aspect ratio, or %NULL
1532 * Retrieves the pixel aspect ratio of a #GstVaapiDisplay.
1535 gst_vaapi_display_get_pixel_aspect_ratio (GstVaapiDisplay * display,
1536 guint * par_n, guint * par_d)
1538 g_return_if_fail (display != NULL);
1540 gst_vaapi_display_ensure_screen_resolution (display);
1543 *par_n = GST_VAAPI_DISPLAY_GET_PRIVATE (display)->par_n;
1546 *par_d = GST_VAAPI_DISPLAY_GET_PRIVATE (display)->par_d;
1550 * gst_vaapi_display_has_video_processing:
1551 * @display: a #GstVaapiDisplay
1553 * Checks whether the underlying VA driver implementation supports
1554 * video processing (VPP) acceleration.
1556 * Returns: %TRUE if some VPP features are available
1559 gst_vaapi_display_has_video_processing (GstVaapiDisplay * display)
1561 g_return_val_if_fail (display != NULL, FALSE);
1563 if (!ensure_profiles (display))
1565 return GST_VAAPI_DISPLAY_GET_PRIVATE (display)->has_vpp;
1569 * gst_vaapi_display_get_decode_profiles:
1570 * @display: a #GstVaapiDisplay
1572 * Gets the supported profiles for decoding. The caller owns an extra
1573 * reference to the resulting array of #GstVaapiProfile elements, so
1574 * it shall be released with g_array_unref() after usage.
1576 * Return value: a newly allocated #GArray, or %NULL if error or if
1577 * decoding is not supported at all
1580 gst_vaapi_display_get_decode_profiles (GstVaapiDisplay * display)
1582 g_return_val_if_fail (display != NULL, NULL);
1584 if (!ensure_profiles (display))
1586 return get_profiles (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->decoders, 0);
1590 * gst_vaapi_display_has_decoder:
1591 * @display: a #GstVaapiDisplay
1592 * @profile: a #VAProfile
1593 * @entrypoint: a #GstVaaiEntrypoint
1595 * Returns whether VA @display supports @profile for decoding at the
1596 * specified @entrypoint.
1598 * Return value: %TRUE if VA @display supports @profile for decoding.
1601 gst_vaapi_display_has_decoder (GstVaapiDisplay * display,
1602 GstVaapiProfile profile, GstVaapiEntrypoint entrypoint)
1604 g_return_val_if_fail (display != NULL, FALSE);
1606 if (!ensure_profiles (display))
1608 return find_config (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->decoders,
1609 profile, entrypoint);
1613 * gst_vaapi_display_get_encode_profiles:
1614 * @display: a #GstVaapiDisplay
1616 * Gets the supported profiles for encoding. The caller owns an extra
1617 * reference to the resulting array of #GstVaapiProfile elements, so
1618 * it shall be released with g_array_unref() after usage.
1620 * Return value: a newly allocated #GArray, or %NULL if error or if
1621 * encoding is not supported at all
1624 gst_vaapi_display_get_encode_profiles (GstVaapiDisplay * display)
1626 g_return_val_if_fail (display != NULL, NULL);
1628 if (!ensure_profiles (display))
1630 return get_profiles (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->encoders, 0);
1634 * gst_vaapi_display_get_encode_profiles_by_codec:
1635 * @display: a #GstVaapiDisplay
1636 * @codec: a #GstVaapiCodec
1638 * Gets the supported profiles which belongs to @codec for encoding.
1639 * The caller owns an extra reference to the resulting array of
1640 * #GstVaapiProfile elements, so it shall be released with g_array_unref()
1643 * Return value: a newly allocated #GArray, or %NULL if error or if
1644 * no encoding profile is found specified by the @codec.
1647 gst_vaapi_display_get_encode_profiles_by_codec (GstVaapiDisplay * display,
1648 GstVaapiCodec codec)
1650 g_return_val_if_fail (display != NULL, NULL);
1652 if (!ensure_profiles (display))
1654 return get_profiles (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->encoders,
1659 * gst_vaapi_display_has_encoder:
1660 * @display: a #GstVaapiDisplay
1661 * @profile: a #VAProfile
1662 * @entrypoint: a #GstVaapiEntrypoint
1664 * Returns whether VA @display supports @profile for encoding at the
1665 * specified @entrypoint.
1667 * Return value: %TRUE if VA @display supports @profile for encoding.
1670 gst_vaapi_display_has_encoder (GstVaapiDisplay * display,
1671 GstVaapiProfile profile, GstVaapiEntrypoint entrypoint)
1673 g_return_val_if_fail (display != NULL, FALSE);
1675 if (!ensure_profiles (display))
1677 return find_config (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->encoders,
1678 profile, entrypoint);
1682 * gst_vaapi_display_get_image_formats:
1683 * @display: a #GstVaapiDisplay
1685 * Gets the supported image formats for gst_vaapi_surface_get_image()
1686 * or gst_vaapi_surface_put_image().
1688 * Note that this method does not necessarily map image formats
1689 * returned by vaQueryImageFormats(). The set of capabilities can be
1690 * stripped down, if gstreamer-vaapi does not support the format, or
1691 * expanded to cover compatible formats not exposed by the underlying
1692 * driver. e.g. I420 can be supported even if the driver only exposes
1695 * Note: the caller owns an extra reference to the resulting array of
1696 * #GstVideoFormat elements, so it shall be released with
1697 * g_array_unref() after usage.
1699 * Return value: a newly allocated #GArray, or %NULL on error or if
1703 gst_vaapi_display_get_image_formats (GstVaapiDisplay * display)
1705 g_return_val_if_fail (display != NULL, NULL);
1707 if (!ensure_image_formats (display))
1709 return get_formats (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->image_formats);
1713 * gst_vaapi_display_has_image_format:
1714 * @display: a #GstVaapiDisplay
1715 * @format: a #GstVideoFormat
1717 * Returns whether VA @display supports @format image format.
1719 * Return value: %TRUE if VA @display supports @format image format
1722 gst_vaapi_display_has_image_format (GstVaapiDisplay * display,
1723 GstVideoFormat format)
1725 GstVaapiDisplayPrivate *priv;
1727 g_return_val_if_fail (display != NULL, FALSE);
1728 g_return_val_if_fail (format, FALSE);
1730 priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
1732 if (!ensure_image_formats (display))
1734 if (find_format (priv->image_formats, format))
1737 /* XXX: try subpicture formats since some drivers could report a
1738 * set of VA image formats that is not a superset of the set of VA
1739 * subpicture formats
1741 if (!ensure_subpicture_formats (display))
1743 return find_format (priv->subpicture_formats, format);
1747 * gst_vaapi_display_get_subpicture_formats:
1748 * @display: a #GstVaapiDisplay
1750 * Gets the supported subpicture formats.
1752 * Note that this method does not necessarily map subpicture formats
1753 * returned by vaQuerySubpictureFormats(). The set of capabilities can
1754 * be stripped down if gstreamer-vaapi does not support the
1755 * format. e.g. this is the case for paletted formats like IA44.
1757 * Note: the caller owns an extra reference to the resulting array of
1758 * #GstVideoFormat elements, so it shall be released with
1759 * g_array_unref() after usage.
1761 * Return value: a newly allocated #GArray, or %NULL on error of if
1765 gst_vaapi_display_get_subpicture_formats (GstVaapiDisplay * display)
1767 g_return_val_if_fail (display != NULL, NULL);
1769 if (!ensure_subpicture_formats (display))
1772 get_formats (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->subpicture_formats);
1776 * gst_vaapi_display_has_subpicture_format:
1777 * @display: a #GstVaapiDisplay
1778 * @format: a #GstVideoFormat
1779 * @flags_ptr: pointer to #GstVaapiSubpictureFlags, or zero
1781 * Returns whether VA @display supports @format subpicture format with
1782 * the supplied @flags.
1784 * Return value: %TRUE if VA @display supports @format subpicture format
1787 gst_vaapi_display_has_subpicture_format (GstVaapiDisplay * display,
1788 GstVideoFormat format, guint * flags_ptr)
1790 GstVaapiDisplayPrivate *priv;
1791 const GstVaapiFormatInfo *fip;
1793 g_return_val_if_fail (display != NULL, FALSE);
1794 g_return_val_if_fail (format, FALSE);
1796 priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
1798 if (!ensure_subpicture_formats (display))
1801 fip = find_format_info (priv->subpicture_formats, format);
1806 *flags_ptr = fip->flags;
1811 * gst_vaapi_display_has_property:
1812 * @display: a #GstVaapiDisplay
1813 * @name: the property name to check
1815 * Returns whether VA @display supports the requested property. The
1816 * check is performed against the property @name. So, the client
1817 * application may perform this check only once and cache this
1820 * Return value: %TRUE if VA @display supports property @name
1823 gst_vaapi_display_has_property (GstVaapiDisplay * display, const gchar * name)
1825 g_return_val_if_fail (display != NULL, FALSE);
1826 g_return_val_if_fail (name, FALSE);
1828 if (!ensure_properties (display))
1830 return find_property (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->properties,
1835 get_attribute (GstVaapiDisplay * display, VADisplayAttribType type,
1838 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
1839 VADisplayAttribute attr = { 0, };
1843 attr.flags = VA_DISPLAY_ATTRIB_GETTABLE;
1844 status = vaGetDisplayAttributes (priv->display, &attr, 1);
1845 if (!vaapi_check_status (status, "vaGetDisplayAttributes()"))
1847 *value = attr.value;
1852 set_attribute (GstVaapiDisplay * display, VADisplayAttribType type, gint value)
1854 GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
1855 VADisplayAttribute attr = { 0, };
1860 attr.flags = VA_DISPLAY_ATTRIB_SETTABLE;
1861 status = vaSetDisplayAttributes (priv->display, &attr, 1);
1862 if (!vaapi_check_status (status, "vaSetDisplayAttributes()"))
1868 get_render_mode_VADisplayAttribRenderMode (GstVaapiDisplay * display,
1869 GstVaapiRenderMode * pmode)
1871 gint modes, devices;
1873 if (!get_attribute (display, VADisplayAttribRenderDevice, &devices))
1877 if (!get_attribute (display, VADisplayAttribRenderMode, &modes))
1880 /* Favor "overlay" mode since it is the most restrictive one */
1881 if (modes & (VA_RENDER_MODE_LOCAL_OVERLAY | VA_RENDER_MODE_EXTERNAL_OVERLAY))
1882 *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
1884 *pmode = GST_VAAPI_RENDER_MODE_TEXTURE;
1889 get_render_mode_default (GstVaapiDisplay * display, GstVaapiRenderMode * pmode)
1891 switch (GST_VAAPI_DISPLAY_VADISPLAY_TYPE (display)) {
1893 case GST_VAAPI_DISPLAY_TYPE_WAYLAND:
1894 /* wl_buffer mapped from VA surface through vaGetSurfaceBufferWl() */
1895 *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
1899 case GST_VAAPI_DISPLAY_TYPE_DRM:
1900 /* vaGetSurfaceBufferDRM() returns the underlying DRM buffer handle */
1901 *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
1905 /* This includes VA/X11 and VA/GLX modes */
1906 *pmode = DEFAULT_RENDER_MODE;
1913 * gst_vaapi_display_get_render_mode:
1914 * @display: a #GstVaapiDisplay
1915 * @pmode: return location for the VA @display rendering mode
1917 * Returns the current VA @display rendering mode.
1919 * Return value: %TRUE if VA @display rendering mode could be determined
1922 gst_vaapi_display_get_render_mode (GstVaapiDisplay * display,
1923 GstVaapiRenderMode * pmode)
1925 g_return_val_if_fail (display != NULL, FALSE);
1927 /* Try with render-mode attribute */
1928 if (get_render_mode_VADisplayAttribRenderMode (display, pmode))
1931 /* Default: determine from the display type */
1932 return get_render_mode_default (display, pmode);
1936 * gst_vaapi_display_set_render_mode:
1937 * @display: a #GstVaapiDisplay
1938 * @mode: the #GstVaapiRenderMode to set
1940 * Sets the VA @display rendering mode to the supplied @mode. This
1941 * function returns %FALSE if the rendering mode could not be set,
1942 * e.g. run-time switching rendering mode is not supported.
1944 * Return value: %TRUE if VA @display rendering @mode could be changed
1945 * to the requested value
1948 gst_vaapi_display_set_render_mode (GstVaapiDisplay * display,
1949 GstVaapiRenderMode mode)
1951 gint modes, devices;
1953 g_return_val_if_fail (display != NULL, FALSE);
1955 if (!get_attribute (display, VADisplayAttribRenderDevice, &devices))
1960 case GST_VAAPI_RENDER_MODE_OVERLAY:
1961 if (devices & VA_RENDER_DEVICE_LOCAL)
1962 modes |= VA_RENDER_MODE_LOCAL_OVERLAY;
1963 if (devices & VA_RENDER_DEVICE_EXTERNAL)
1964 modes |= VA_RENDER_MODE_EXTERNAL_OVERLAY;
1966 case GST_VAAPI_RENDER_MODE_TEXTURE:
1967 if (devices & VA_RENDER_DEVICE_LOCAL)
1968 modes |= VA_RENDER_MODE_LOCAL_GPU;
1969 if (devices & VA_RENDER_DEVICE_EXTERNAL)
1970 modes |= VA_RENDER_MODE_EXTERNAL_GPU;
1975 if (!set_attribute (display, VADisplayAttribRenderMode, modes))
1981 * gst_vaapi_display_get_rotation:
1982 * @display: a #GstVaapiDisplay
1984 * Returns the current VA @display rotation angle. If the VA driver
1985 * does not support "rotation" display attribute, then the display is
1986 * assumed to be un-rotated.
1988 * Return value: the current #GstVaapiRotation value
1991 gst_vaapi_display_get_rotation (GstVaapiDisplay * display)
1995 g_return_val_if_fail (display != NULL, DEFAULT_ROTATION);
1997 if (!get_attribute (display, VADisplayAttribRotation, &value))
1998 value = VA_ROTATION_NONE;
1999 return to_GstVaapiRotation (value);
2003 * gst_vaapi_display_set_rotation:
2004 * @display: a #GstVaapiDisplay
2005 * @rotation: the #GstVaapiRotation value to set
2007 * Sets the VA @display rotation angle to the supplied @rotation
2008 * value. This function returns %FALSE if the rotation angle could not
2009 * be set, e.g. the VA driver does not allow to change the display
2012 * Return value: %TRUE if VA @display rotation angle could be changed
2013 * to the requested value
2016 gst_vaapi_display_set_rotation (GstVaapiDisplay * display,
2017 GstVaapiRotation rotation)
2021 g_return_val_if_fail (display != NULL, FALSE);
2023 value = from_GstVaapiRotation (rotation);
2024 if (!set_attribute (display, VADisplayAttribRotation, value))
2029 /* Get color balance attributes */
2031 get_color_balance (GstVaapiDisplay * display, guint prop_id, gfloat * v)
2033 GParamSpecFloat *const pspec = G_PARAM_SPEC_FLOAT (g_properties[prop_id]);
2034 const GstVaapiProperty *prop;
2035 const VADisplayAttribute *attr;
2039 if (!ensure_properties (display))
2045 prop = find_property_by_pspec (display, &pspec->parent_instance);
2048 attr = &prop->attribute;
2050 if (!get_attribute (display, attr->type, &value))
2053 /* Scale wrt. the medium ("default") value */
2054 out_value = pspec->default_value;
2055 if (value > attr->value)
2056 out_value += ((gfloat) (value - attr->value) /
2057 (attr->max_value - attr->value) *
2058 (pspec->maximum - pspec->default_value));
2059 else if (value < attr->value)
2060 out_value -= ((gfloat) (attr->value - value) /
2061 (attr->value - attr->min_value) *
2062 (pspec->default_value - pspec->minimum));
2067 /* Set color balance attribute */
2069 set_color_balance (GstVaapiDisplay * display, guint prop_id, gfloat v)
2071 GParamSpecFloat *const pspec = G_PARAM_SPEC_FLOAT (g_properties[prop_id]);
2072 const GstVaapiProperty *prop;
2073 const VADisplayAttribute *attr;
2076 if (!ensure_properties (display))
2082 prop = find_property_by_pspec (display, &pspec->parent_instance);
2085 attr = &prop->attribute;
2087 /* Scale wrt. the medium ("default") value */
2088 value = attr->value;
2089 if (v > pspec->default_value)
2090 value += ((v - pspec->default_value) /
2091 (pspec->maximum - pspec->default_value) *
2092 (attr->max_value - attr->value));
2093 else if (v < pspec->default_value)
2094 value -= ((pspec->default_value - v) /
2095 (pspec->default_value - pspec->minimum) *
2096 (attr->value - attr->min_value));
2097 if (!set_attribute (display, attr->type, value))
2103 * gst_vaapi_display_get_vendor_string:
2104 * @display: a #GstVaapiDisplay
2106 * Returns the VA driver vendor string attached to the supplied VA @display.
2107 * The @display owns the vendor string, do *not* de-allocate it.
2109 * This function is thread safe.
2111 * Return value: the current #GstVaapiRotation value
2114 gst_vaapi_display_get_vendor_string (GstVaapiDisplay * display)
2116 g_return_val_if_fail (display != NULL, NULL);
2118 if (!ensure_vendor_string (display))
2120 return GST_VAAPI_DISPLAY_GET_PRIVATE (display)->vendor_string;
2124 * gst_vaapi_display_has_opengl:
2125 * @display: a #GstVaapiDisplay
2127 * Returns wether the @display that was created does support OpenGL
2128 * context to be attached.
2130 * This function is thread safe.
2132 * Return value: %TRUE if the @display supports OpenGL context, %FALSE
2136 gst_vaapi_display_has_opengl (GstVaapiDisplay * display)
2138 GstVaapiDisplayClass *klass;
2140 g_return_val_if_fail (display != NULL, FALSE);
2142 klass = GST_VAAPI_DISPLAY_GET_CLASS (display);
2143 return (klass->display_type == GST_VAAPI_DISPLAY_TYPE_GLX ||
2144 klass->display_type == GST_VAAPI_DISPLAY_TYPE_EGL);
2148 * gst_vaapi_display_reset_texture_map:
2149 * @display: a #GstVaapiDisplay
2151 * Reset the internal #GstVaapiTextureMap if available.
2153 * This function is thread safe.
2156 gst_vaapi_display_reset_texture_map (GstVaapiDisplay * display)
2158 GstVaapiDisplayClass *klass;
2159 GstVaapiTextureMap *map;
2161 g_return_if_fail (display != NULL);
2163 if (!gst_vaapi_display_has_opengl (display))
2165 klass = GST_VAAPI_DISPLAY_GET_CLASS (display);
2166 if (!klass->get_texture_map)
2168 if ((map = klass->get_texture_map (display)))
2169 gst_vaapi_texture_map_reset (map);
2173 * gst_vaapi_display_get_driver_quirks:
2174 * @display: a #GstVaapiDisplay
2175 * @quirks: the #GstVaapiDriverQuirks bitwise to check
2177 * Returns: %TRUE if @quirks are set in @display's driver
2180 gst_vaapi_display_has_driver_quirks (GstVaapiDisplay * display, guint quirks)
2182 g_return_val_if_fail (display != NULL, FALSE);
2184 return (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->driver_quirks & quirks);