2 * gstvaapidisplay.c - VA display abstraction
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Copyright (C) 2011-2013 Intel Corporation
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
24 * SECTION:gstvaapidisplay
25 * @short_description: VA display abstraction
30 #include "gstvaapiutils.h"
31 #include "gstvaapivalue.h"
32 #include "gstvaapidisplay.h"
33 #include "gstvaapidisplay_priv.h"
34 #include "gstvaapiworkarounds.h"
35 #include "gstvaapiversion.h"
38 #include "gstvaapidebug.h"
40 GST_DEBUG_CATEGORY(gst_debug_vaapi);
42 /* Ensure those symbols are actually defined in the resulting libraries */
43 #undef gst_vaapi_display_ref
44 #undef gst_vaapi_display_unref
45 #undef gst_vaapi_display_replace
47 typedef struct _GstVaapiConfig GstVaapiConfig;
48 struct _GstVaapiConfig {
49 GstVaapiProfile profile;
50 GstVaapiEntrypoint entrypoint;
53 typedef struct _GstVaapiProperty GstVaapiProperty;
54 struct _GstVaapiProperty {
56 VADisplayAttribute attribute;
60 typedef struct _GstVaapiFormatInfo GstVaapiFormatInfo;
61 struct _GstVaapiFormatInfo {
62 GstVideoFormat format;
66 #define DEFAULT_RENDER_MODE GST_VAAPI_RENDER_MODE_TEXTURE
67 #define DEFAULT_ROTATION GST_VAAPI_ROTATION_0
82 static GstVaapiDisplayCache *g_display_cache = NULL;
84 static GParamSpec *g_properties[N_PROPERTIES] = { NULL, };
87 gst_vaapi_display_properties_init(void);
90 get_attribute(GstVaapiDisplay *display, VADisplayAttribType type, gint *value);
93 set_attribute(GstVaapiDisplay *display, VADisplayAttribType type, gint value);
96 get_color_balance(GstVaapiDisplay *display, guint prop_id, gfloat *v);
99 set_color_balance(GstVaapiDisplay *display, guint prop_id, gfloat v);
102 libgstvaapi_init_once(void)
104 static gsize g_once = FALSE;
106 if (!g_once_init_enter(&g_once))
109 GST_DEBUG_CATEGORY_INIT(gst_debug_vaapi, "vaapi", 0, "VA-API helper");
111 /* Dump gstreamer-vaapi version for debugging purposes */
112 GST_INFO("gstreamer-vaapi version %s", GST_VAAPI_VERSION_ID);
114 gst_vaapi_display_properties_init();
116 g_once_init_leave(&g_once, TRUE);
119 static inline GstVaapiDisplayCache *
120 get_display_cache(void)
122 if (!g_display_cache)
123 g_display_cache = gst_vaapi_display_cache_new();
124 return g_display_cache;
127 GstVaapiDisplayCache *
128 gst_vaapi_display_get_cache(void)
130 return get_display_cache();
134 free_display_cache(void)
136 if (!g_display_cache)
138 if (gst_vaapi_display_cache_get_size(g_display_cache) > 0)
140 gst_vaapi_display_cache_free(g_display_cache);
141 g_display_cache = NULL;
144 /* GstVaapiDisplayType enumerations */
146 gst_vaapi_display_type_get_type(void)
148 static GType g_type = 0;
150 static const GEnumValue display_types[] = {
151 { GST_VAAPI_DISPLAY_TYPE_ANY,
152 "Auto detection", "any" },
154 { GST_VAAPI_DISPLAY_TYPE_X11,
155 "VA/X11 display", "x11" },
158 { GST_VAAPI_DISPLAY_TYPE_GLX,
159 "VA/GLX display", "glx" },
162 { GST_VAAPI_DISPLAY_TYPE_WAYLAND,
163 "VA/Wayland display", "wayland" },
166 { GST_VAAPI_DISPLAY_TYPE_DRM,
167 "VA/DRM display", "drm" },
173 g_type = g_enum_register_static("GstVaapiDisplayType", display_types);
177 /* Append GstVideoFormat to formats array */
179 append_format(GArray *formats, GstVideoFormat format, guint flags)
181 GstVaapiFormatInfo fi;
185 g_array_append_val(formats, fi);
188 /* Append VAImageFormats to formats array */
190 append_formats(GArray *formats, const VAImageFormat *va_formats,
191 guint *flags, guint n)
193 GstVideoFormat format;
194 const GstVaapiFormatInfo *YV12_fip = NULL;
195 const GstVaapiFormatInfo *I420_fip = NULL;
198 for (i = 0; i < n; i++) {
199 const VAImageFormat * const va_format = &va_formats[i];
200 const GstVaapiFormatInfo **fipp;
202 format = gst_vaapi_video_format_from_va_format(va_format);
203 if (format == GST_VIDEO_FORMAT_UNKNOWN) {
204 GST_DEBUG("unsupported format %" GST_FOURCC_FORMAT,
205 GST_FOURCC_ARGS(va_format->fourcc));
208 append_format(formats, format, flags ? flags[i] : 0);
211 case GST_VIDEO_FORMAT_YV12:
214 case GST_VIDEO_FORMAT_I420:
222 *fipp = &g_array_index(formats, GstVaapiFormatInfo,
226 /* Append I420 (resp. YV12) format if YV12 (resp. I420) is not
227 supported by the underlying driver */
228 if (YV12_fip && !I420_fip)
229 append_format(formats, GST_VIDEO_FORMAT_I420, YV12_fip->flags);
230 else if (I420_fip && !YV12_fip)
231 append_format(formats, GST_VIDEO_FORMAT_YV12, I420_fip->flags);
234 /* Sort image formats. Prefer YUV formats first */
236 compare_yuv_formats(gconstpointer a, gconstpointer b)
238 const GstVideoFormat fmt1 = ((GstVaapiFormatInfo *)a)->format;
239 const GstVideoFormat fmt2 = ((GstVaapiFormatInfo *)b)->format;
241 const gboolean is_fmt1_yuv = gst_vaapi_video_format_is_yuv(fmt1);
242 const gboolean is_fmt2_yuv = gst_vaapi_video_format_is_yuv(fmt2);
244 if (is_fmt1_yuv != is_fmt2_yuv)
245 return is_fmt1_yuv ? -1 : 1;
247 return ((gint)gst_vaapi_video_format_get_score(fmt1) -
248 (gint)gst_vaapi_video_format_get_score(fmt2));
251 /* Sort subpicture formats. Prefer RGB formats first */
253 compare_rgb_formats(gconstpointer a, gconstpointer b)
255 const GstVideoFormat fmt1 = ((GstVaapiFormatInfo *)a)->format;
256 const GstVideoFormat fmt2 = ((GstVaapiFormatInfo *)b)->format;
258 const gboolean is_fmt1_rgb = gst_vaapi_video_format_is_rgb(fmt1);
259 const gboolean is_fmt2_rgb = gst_vaapi_video_format_is_rgb(fmt2);
261 if (is_fmt1_rgb != is_fmt2_rgb)
262 return is_fmt1_rgb ? -1 : 1;
264 return ((gint)gst_vaapi_video_format_get_score(fmt1) -
265 (gint)gst_vaapi_video_format_get_score(fmt2));
268 /* Check if configs array contains profile at entrypoint */
269 static inline gboolean
272 GstVaapiProfile profile,
273 GstVaapiEntrypoint entrypoint
276 GstVaapiConfig *config;
282 for (i = 0; i < configs->len; i++) {
283 config = &g_array_index(configs, GstVaapiConfig, i);
284 if (config->profile == profile && config->entrypoint == entrypoint)
290 /* HACK: append H.263 Baseline profile if MPEG-4:2 Simple profile is supported */
292 append_h263_config(GArray *configs)
294 GstVaapiConfig *config, tmp_config;
295 GstVaapiConfig *mpeg4_simple_config = NULL;
296 GstVaapiConfig *h263_baseline_config = NULL;
299 if (!WORKAROUND_H263_BASELINE_DECODE_PROFILE)
305 for (i = 0; i < configs->len; i++) {
306 config = &g_array_index(configs, GstVaapiConfig, i);
307 if (config->profile == GST_VAAPI_PROFILE_MPEG4_SIMPLE)
308 mpeg4_simple_config = config;
309 else if (config->profile == GST_VAAPI_PROFILE_H263_BASELINE)
310 h263_baseline_config = config;
313 if (mpeg4_simple_config && !h263_baseline_config) {
314 tmp_config = *mpeg4_simple_config;
315 tmp_config.profile = GST_VAAPI_PROFILE_H263_BASELINE;
316 g_array_append_val(configs, tmp_config);
320 /* Convert configs array to profiles as GstCaps */
322 get_profile_caps(GArray *configs)
324 GstVaapiConfig *config;
325 GstCaps *out_caps, *caps;
331 out_caps = gst_caps_new_empty();
335 for (i = 0; i < configs->len; i++) {
336 config = &g_array_index(configs, GstVaapiConfig, i);
337 caps = gst_vaapi_profile_get_caps(config->profile);
339 out_caps = gst_caps_merge(out_caps, caps);
344 /* Find format info */
345 static const GstVaapiFormatInfo *
346 find_format_info(GArray *formats, GstVideoFormat format)
348 const GstVaapiFormatInfo *fip;
351 for (i = 0; i < formats->len; i++) {
352 fip = &g_array_index(formats, GstVaapiFormatInfo, i);
353 if (fip->format == format)
359 /* Check if formats array contains format */
360 static inline gboolean
361 find_format(GArray *formats, GstVideoFormat format)
363 return find_format_info(formats, format) != NULL;
366 /* Convert formats array to GstCaps */
368 get_format_caps(GArray *formats)
370 const GstVaapiFormatInfo *fip;
371 GstCaps *out_caps, *caps;
374 out_caps = gst_caps_new_empty();
378 for (i = 0; i < formats->len; i++) {
379 fip = &g_array_index(formats, GstVaapiFormatInfo, i);
380 caps = gst_vaapi_video_format_to_caps(fip->format);
382 gst_caps_append(out_caps, caps);
387 /* Find display attribute */
388 static const GstVaapiProperty *
389 find_property(GArray *properties, const gchar *name)
391 GstVaapiProperty *prop;
397 for (i = 0; i < properties->len; i++) {
398 prop = &g_array_index(properties, GstVaapiProperty, i);
399 if (strcmp(prop->name, name) == 0)
406 static const GstVaapiProperty *
407 find_property_by_type(GArray *properties, VADisplayAttribType type)
409 GstVaapiProperty *prop;
412 for (i = 0; i < properties->len; i++) {
413 prop = &g_array_index(properties, GstVaapiProperty, i);
414 if (prop->attribute.type == type)
421 static inline const GstVaapiProperty *
422 find_property_by_pspec(GstVaapiDisplay *display, GParamSpec *pspec)
424 GstVaapiDisplayPrivate * const priv =
425 GST_VAAPI_DISPLAY_GET_PRIVATE(display);
427 return find_property(priv->properties, pspec->name);
431 find_property_id(const gchar *name)
438 static const property_map g_property_map[] = {
439 { GST_VAAPI_DISPLAY_PROP_RENDER_MODE, PROP_RENDER_MODE },
440 { GST_VAAPI_DISPLAY_PROP_ROTATION, PROP_ROTATION },
441 { GST_VAAPI_DISPLAY_PROP_HUE, PROP_HUE },
442 { GST_VAAPI_DISPLAY_PROP_SATURATION, PROP_SATURATION },
443 { GST_VAAPI_DISPLAY_PROP_BRIGHTNESS, PROP_BRIGHTNESS },
444 { GST_VAAPI_DISPLAY_PROP_CONTRAST, PROP_CONTRAST },
448 const property_map *m;
449 for (m = g_property_map; m->name != NULL; m++) {
450 if (strcmp(m->name, name) == 0)
457 gst_vaapi_display_calculate_pixel_aspect_ratio(GstVaapiDisplay *display)
459 GstVaapiDisplayPrivate * const priv =
460 GST_VAAPI_DISPLAY_GET_PRIVATE(display);
461 gdouble ratio, delta;
462 gint i, j, index, windex;
464 static const gint par[][2] = {
465 {1, 1}, /* regular screen */
466 {16, 15}, /* PAL TV */
467 {11, 10}, /* 525 line Rec.601 video */
468 {54, 59}, /* 625 line Rec.601 video */
469 {64, 45}, /* 1280x1024 on 16:9 display */
470 {5, 3}, /* 1280x1024 on 4:3 display */
471 {4, 3} /* 800x600 on 16:9 display */
474 /* First, calculate the "real" ratio based on the X values;
475 * which is the "physical" w/h divided by the w/h in pixels of the
477 if (!priv->width || !priv->height || !priv->width_mm || !priv->height_mm)
480 ratio = (gdouble)(priv->width_mm * priv->height) /
481 (priv->height_mm * priv->width);
482 GST_DEBUG("calculated pixel aspect ratio: %f", ratio);
484 /* Now, find the one from par[][2] with the lowest delta to the real one */
485 #define DELTA(idx, w) (ABS(ratio - ((gdouble)par[idx][w] / par[idx][!(w)])))
490 for (i = 1; i < G_N_ELEMENTS(par); i++) {
491 for (j = 0; j < 2; j++) {
492 const gdouble this_delta = DELTA(i, j);
493 if (this_delta < delta) {
502 priv->par_n = par[index][windex];
503 priv->par_d = par[index][windex ^ 1];
507 gst_vaapi_display_destroy(GstVaapiDisplay *display)
509 GstVaapiDisplayPrivate * const priv =
510 GST_VAAPI_DISPLAY_GET_PRIVATE(display);
512 if (priv->decoders) {
513 g_array_free(priv->decoders, TRUE);
514 priv->decoders = NULL;
517 if (priv->encoders) {
518 g_array_free(priv->encoders, TRUE);
519 priv->encoders = NULL;
522 if (priv->image_formats) {
523 g_array_free(priv->image_formats, TRUE);
524 priv->image_formats = NULL;
527 if (priv->subpicture_formats) {
528 g_array_free(priv->subpicture_formats, TRUE);
529 priv->subpicture_formats = NULL;
532 if (priv->properties) {
533 g_array_free(priv->properties, TRUE);
534 priv->properties = NULL;
539 vaTerminate(priv->display);
540 priv->display = NULL;
543 if (!priv->use_foreign_display) {
544 GstVaapiDisplayClass *klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
545 if (klass->close_display)
546 klass->close_display(display);
549 gst_vaapi_display_replace_internal(&priv->parent, NULL);
551 if (g_display_cache) {
552 gst_vaapi_display_cache_remove(get_display_cache(), display);
553 free_display_cache();
558 gst_vaapi_display_create(GstVaapiDisplay *display,
559 GstVaapiDisplayInitType init_type, gpointer init_value)
561 GstVaapiDisplayPrivate * const priv =
562 GST_VAAPI_DISPLAY_GET_PRIVATE(display);
563 const GstVaapiDisplayClass * const klass =
564 GST_VAAPI_DISPLAY_GET_CLASS(display);
565 GstVaapiDisplayCache *cache;
566 gboolean has_errors = TRUE;
567 VADisplayAttribute *display_attrs = NULL;
568 VAProfile *profiles = NULL;
569 VAEntrypoint *entrypoints = NULL;
570 VAImageFormat *formats = NULL;
571 unsigned int *flags = NULL;
572 gint i, j, n, num_entrypoints, major_version, minor_version;
574 GstVaapiDisplayInfo info;
575 const GstVaapiDisplayInfo *cached_info = NULL;
577 memset(&info, 0, sizeof(info));
578 info.display = display;
579 info.display_type = priv->display_type;
582 case GST_VAAPI_DISPLAY_INIT_FROM_VA_DISPLAY:
583 info.va_display = init_value;
584 priv->display = init_value;
585 priv->use_foreign_display = TRUE;
587 case GST_VAAPI_DISPLAY_INIT_FROM_DISPLAY_NAME:
588 if (klass->open_display && !klass->open_display(display, init_value))
591 case GST_VAAPI_DISPLAY_INIT_FROM_NATIVE_DISPLAY:
592 if (klass->bind_display && !klass->bind_display(display, init_value))
596 if (!klass->get_display || !klass->get_display(display, &info))
598 priv->display = info.va_display;
599 priv->display_type = info.display_type;
601 klass->get_size(display, &priv->width, &priv->height);
602 if (klass->get_size_mm)
603 klass->get_size_mm(display, &priv->width_mm, &priv->height_mm);
604 gst_vaapi_display_calculate_pixel_aspect_ratio(display);
610 cache = get_display_cache();
613 cached_info = gst_vaapi_display_cache_lookup_by_va_display(cache,
616 gst_vaapi_display_replace_internal(&priv->parent,
617 cached_info->display);
618 priv->display_type = cached_info->display_type;
622 status = vaInitialize(priv->display, &major_version, &minor_version);
623 if (!vaapi_check_status(status, "vaInitialize()"))
625 GST_DEBUG("VA-API version %d.%d", major_version, minor_version);
629 profiles = g_new(VAProfile, vaMaxNumProfiles(priv->display));
632 entrypoints = g_new(VAEntrypoint, vaMaxNumEntrypoints(priv->display));
635 status = vaQueryConfigProfiles(priv->display, profiles, &n);
636 if (!vaapi_check_status(status, "vaQueryConfigProfiles()"))
639 GST_DEBUG("%d profiles", n);
640 for (i = 0; i < n; i++) {
641 #if VA_CHECK_VERSION(0,34,0)
642 /* Introduced in VA/VPP API */
643 if (profiles[i] == VAProfileNone)
646 GST_DEBUG(" %s", string_of_VAProfile(profiles[i]));
649 priv->decoders = g_array_new(FALSE, FALSE, sizeof(GstVaapiConfig));
652 priv->encoders = g_array_new(FALSE, FALSE, sizeof(GstVaapiConfig));
656 for (i = 0; i < n; i++) {
657 GstVaapiConfig config;
659 config.profile = gst_vaapi_profile(profiles[i]);
663 status = vaQueryConfigEntrypoints(
666 entrypoints, &num_entrypoints
668 if (!vaapi_check_status(status, "vaQueryConfigEntrypoints()"))
671 for (j = 0; j < num_entrypoints; j++) {
672 config.entrypoint = gst_vaapi_entrypoint(entrypoints[j]);
673 switch (config.entrypoint) {
674 case GST_VAAPI_ENTRYPOINT_VLD:
675 case GST_VAAPI_ENTRYPOINT_IDCT:
676 case GST_VAAPI_ENTRYPOINT_MOCO:
677 g_array_append_val(priv->decoders, config);
679 case GST_VAAPI_ENTRYPOINT_SLICE_ENCODE:
680 g_array_append_val(priv->encoders, config);
685 append_h263_config(priv->decoders);
687 /* Video processing API */
689 status = vaQueryConfigEntrypoints(priv->display, VAProfileNone,
690 entrypoints, &num_entrypoints);
691 if (vaapi_check_status(status, "vaQueryEntrypoints() [VAProfileNone]")) {
692 for (j = 0; j < num_entrypoints; j++) {
693 if (entrypoints[j] == VAEntrypointVideoProc)
694 priv->has_vpp = TRUE;
699 /* VA display attributes */
701 g_new(VADisplayAttribute, vaMaxNumDisplayAttributes(priv->display));
705 n = 0; /* XXX: workaround old GMA500 bug */
706 status = vaQueryDisplayAttributes(priv->display, display_attrs, &n);
707 if (!vaapi_check_status(status, "vaQueryDisplayAttributes()"))
710 priv->properties = g_array_new(FALSE, FALSE, sizeof(GstVaapiProperty));
711 if (!priv->properties)
714 GST_DEBUG("%d display attributes", n);
715 for (i = 0; i < n; i++) {
716 VADisplayAttribute * const attr = &display_attrs[i];
717 GstVaapiProperty prop;
720 GST_DEBUG(" %s", string_of_VADisplayAttributeType(attr->type));
722 switch (attr->type) {
723 #if !VA_CHECK_VERSION(0,34,0)
724 case VADisplayAttribDirectSurface:
725 prop.name = GST_VAAPI_DISPLAY_PROP_RENDER_MODE;
728 case VADisplayAttribRenderMode:
729 prop.name = GST_VAAPI_DISPLAY_PROP_RENDER_MODE;
731 case VADisplayAttribRotation:
732 prop.name = GST_VAAPI_DISPLAY_PROP_ROTATION;
734 case VADisplayAttribHue:
735 prop.name = GST_VAAPI_DISPLAY_PROP_HUE;
737 case VADisplayAttribSaturation:
738 prop.name = GST_VAAPI_DISPLAY_PROP_SATURATION;
740 case VADisplayAttribBrightness:
741 prop.name = GST_VAAPI_DISPLAY_PROP_BRIGHTNESS;
743 case VADisplayAttribContrast:
744 prop.name = GST_VAAPI_DISPLAY_PROP_CONTRAST;
753 /* Assume the attribute is really supported if we can get the
754 * actual and current value */
755 if (!get_attribute(display, attr->type, &value))
758 /* Some drivers (e.g. EMGD) have completely random initial
760 if (value < attr->min_value || value > attr->max_value)
763 prop.attribute = *attr;
764 prop.old_value = value;
765 g_array_append_val(priv->properties, prop);
768 /* VA image formats */
769 formats = g_new(VAImageFormat, vaMaxNumImageFormats(priv->display));
772 status = vaQueryImageFormats(priv->display, formats, &n);
773 if (!vaapi_check_status(status, "vaQueryImageFormats()"))
776 GST_DEBUG("%d image formats", n);
777 for (i = 0; i < n; i++)
778 GST_DEBUG(" %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS(formats[i].fourcc));
780 priv->image_formats =
781 g_array_new(FALSE, FALSE, sizeof(GstVaapiFormatInfo));
782 if (!priv->image_formats)
784 append_formats(priv->image_formats, formats, NULL, n);
785 g_array_sort(priv->image_formats, compare_yuv_formats);
787 /* VA subpicture formats */
788 n = vaMaxNumSubpictureFormats(priv->display);
789 formats = g_renew(VAImageFormat, formats, n);
790 flags = g_new(guint, n);
791 if (!formats || !flags)
793 status = vaQuerySubpictureFormats(priv->display, formats, flags, (guint *)&n);
794 if (!vaapi_check_status(status, "vaQuerySubpictureFormats()"))
797 GST_DEBUG("%d subpicture formats", n);
798 for (i = 0; i < n; i++) {
799 GST_DEBUG(" %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS(formats[i].fourcc));
800 flags[i] = to_GstVaapiSubpictureFlags(flags[i]);
803 priv->subpicture_formats =
804 g_array_new(FALSE, FALSE, sizeof(GstVaapiFormatInfo));
805 if (!priv->subpicture_formats)
807 append_formats(priv->subpicture_formats, formats, flags, n);
808 g_array_sort(priv->subpicture_formats, compare_rgb_formats);
811 if (!gst_vaapi_display_cache_add(cache, &info))
817 g_free(display_attrs);
826 gst_vaapi_display_lock_default(GstVaapiDisplay *display)
828 GstVaapiDisplayPrivate *priv = GST_VAAPI_DISPLAY_GET_PRIVATE(display);
831 priv = GST_VAAPI_DISPLAY_GET_PRIVATE(priv->parent);
832 g_rec_mutex_lock(&priv->mutex);
836 gst_vaapi_display_unlock_default(GstVaapiDisplay *display)
838 GstVaapiDisplayPrivate *priv = GST_VAAPI_DISPLAY_GET_PRIVATE(display);
841 priv = GST_VAAPI_DISPLAY_GET_PRIVATE(priv->parent);
842 g_rec_mutex_unlock(&priv->mutex);
846 gst_vaapi_display_init(GstVaapiDisplay *display)
848 GstVaapiDisplayPrivate * const priv =
849 GST_VAAPI_DISPLAY_GET_PRIVATE(display);
850 const GstVaapiDisplayClass * const dpy_class =
851 GST_VAAPI_DISPLAY_GET_CLASS(display);
853 priv->display_type = GST_VAAPI_DISPLAY_TYPE_ANY;
857 g_rec_mutex_init(&priv->mutex);
860 dpy_class->init(display);
864 gst_vaapi_display_finalize(GstVaapiDisplay *display)
866 GstVaapiDisplayPrivate * const priv =
867 GST_VAAPI_DISPLAY_GET_PRIVATE(display);
869 gst_vaapi_display_destroy(display);
870 g_rec_mutex_clear(&priv->mutex);
874 gst_vaapi_display_class_init(GstVaapiDisplayClass *klass)
876 GstVaapiMiniObjectClass * const object_class =
877 GST_VAAPI_MINI_OBJECT_CLASS(klass);
878 GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);
880 libgstvaapi_init_once();
882 object_class->size = sizeof(GstVaapiDisplay);
883 object_class->finalize = (GDestroyNotify)gst_vaapi_display_finalize;
884 dpy_class->lock = gst_vaapi_display_lock_default;
885 dpy_class->unlock = gst_vaapi_display_unlock_default;
889 gst_vaapi_display_properties_init(void)
892 * GstVaapiDisplay:render-mode:
894 * The VA display rendering mode, expressed as a #GstVaapiRenderMode.
896 g_properties[PROP_RENDER_MODE] =
897 g_param_spec_enum(GST_VAAPI_DISPLAY_PROP_RENDER_MODE,
899 "The display rendering mode",
900 GST_VAAPI_TYPE_RENDER_MODE,
905 * GstVaapiDisplay:rotation:
907 * The VA display rotation mode, expressed as a #GstVaapiRotation.
909 g_properties[PROP_ROTATION] =
910 g_param_spec_enum(GST_VAAPI_DISPLAY_PROP_ROTATION,
912 "The display rotation mode",
913 GST_VAAPI_TYPE_ROTATION,
918 * GstVaapiDisplay:hue:
920 * The VA display hue, expressed as a float value. Range is -180.0
921 * to 180.0. Default value is 0.0 and represents no modification.
923 g_properties[PROP_HUE] =
924 g_param_spec_float(GST_VAAPI_DISPLAY_PROP_HUE,
926 "The display hue value",
931 * GstVaapiDisplay:saturation:
933 * The VA display saturation, expressed as a float value. Range is
934 * 0.0 to 2.0. Default value is 1.0 and represents no modification.
936 g_properties[PROP_SATURATION] =
937 g_param_spec_float(GST_VAAPI_DISPLAY_PROP_SATURATION,
939 "The display saturation value",
944 * GstVaapiDisplay:brightness:
946 * The VA display brightness, expressed as a float value. Range is
947 * -1.0 to 1.0. Default value is 0.0 and represents no modification.
949 g_properties[PROP_BRIGHTNESS] =
950 g_param_spec_float(GST_VAAPI_DISPLAY_PROP_BRIGHTNESS,
952 "The display brightness value",
957 * GstVaapiDisplay:contrast:
959 * The VA display contrast, expressed as a float value. Range is
960 * 0.0 to 2.0. Default value is 1.0 and represents no modification.
962 g_properties[PROP_CONTRAST] =
963 g_param_spec_float(GST_VAAPI_DISPLAY_PROP_CONTRAST,
965 "The display contrast value",
970 static inline const GstVaapiDisplayClass *
971 gst_vaapi_display_class(void)
973 static GstVaapiDisplayClass g_class;
974 static gsize g_class_init = FALSE;
976 if (g_once_init_enter(&g_class_init)) {
977 gst_vaapi_display_class_init(&g_class);
978 g_once_init_leave(&g_class_init, TRUE);
984 gst_vaapi_display_new(const GstVaapiDisplayClass *klass,
985 GstVaapiDisplayInitType init_type, gpointer init_value)
987 GstVaapiDisplay *display;
989 display = (GstVaapiDisplay *)
990 gst_vaapi_mini_object_new0(GST_VAAPI_MINI_OBJECT_CLASS(klass));
994 gst_vaapi_display_init(display);
995 if (!gst_vaapi_display_create(display, init_type, init_value))
1000 gst_vaapi_display_unref_internal(display);
1005 * gst_vaapi_display_new_with_display:
1006 * @va_display: a #VADisplay
1008 * Creates a new #GstVaapiDisplay, using @va_display as the VA
1011 * Return value: the newly created #GstVaapiDisplay object
1014 gst_vaapi_display_new_with_display(VADisplay va_display)
1016 GstVaapiDisplayCache * const cache = get_display_cache();
1017 const GstVaapiDisplayInfo *info;
1019 g_return_val_if_fail(va_display != NULL, NULL);
1020 g_return_val_if_fail(cache != NULL, NULL);
1022 info = gst_vaapi_display_cache_lookup_by_va_display(cache, va_display);
1024 return gst_vaapi_display_ref_internal(info->display);
1026 return gst_vaapi_display_new(gst_vaapi_display_class(),
1027 GST_VAAPI_DISPLAY_INIT_FROM_VA_DISPLAY, va_display);
1031 * gst_vaapi_display_ref:
1032 * @display: a #GstVaapiDisplay
1034 * Atomically increases the reference count of the given @display by one.
1036 * Returns: The same @display argument
1039 gst_vaapi_display_ref(GstVaapiDisplay *display)
1041 return gst_vaapi_display_ref_internal(display);
1045 * gst_vaapi_display_unref:
1046 * @display: a #GstVaapiDisplay
1048 * Atomically decreases the reference count of the @display by one. If
1049 * the reference count reaches zero, the display will be free'd.
1052 gst_vaapi_display_unref(GstVaapiDisplay *display)
1054 gst_vaapi_display_unref_internal(display);
1058 * gst_vaapi_display_replace:
1059 * @old_display_ptr: a pointer to a #GstVaapiDisplay
1060 * @new_display: a #GstVaapiDisplay
1062 * Atomically replaces the display display held in @old_display_ptr
1063 * with @new_display. This means that @old_display_ptr shall reference
1064 * a valid display. However, @new_display can be NULL.
1067 gst_vaapi_display_replace(GstVaapiDisplay **old_display_ptr,
1068 GstVaapiDisplay *new_display)
1070 gst_vaapi_display_replace_internal(old_display_ptr, new_display);
1074 * gst_vaapi_display_lock:
1075 * @display: a #GstVaapiDisplay
1077 * Locks @display. If @display is already locked by another thread,
1078 * the current thread will block until @display is unlocked by the
1082 gst_vaapi_display_lock(GstVaapiDisplay *display)
1084 GstVaapiDisplayClass *klass;
1086 g_return_if_fail(display != NULL);
1088 klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
1090 klass->lock(display);
1094 * gst_vaapi_display_unlock:
1095 * @display: a #GstVaapiDisplay
1097 * Unlocks @display. If another thread is blocked in a
1098 * gst_vaapi_display_lock() call for @display, it will be woken and
1099 * can lock @display itself.
1102 gst_vaapi_display_unlock(GstVaapiDisplay *display)
1104 GstVaapiDisplayClass *klass;
1106 g_return_if_fail(display != NULL);
1108 klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
1110 klass->unlock(display);
1114 * gst_vaapi_display_sync:
1115 * @display: a #GstVaapiDisplay
1117 * Flushes any requests queued for the windowing system and waits until
1118 * all requests have been handled. This is often used for making sure
1119 * that the display is synchronized with the current state of the program.
1121 * This is most useful for X11. On windowing systems where requests are
1122 * handled synchronously, this function will do nothing.
1125 gst_vaapi_display_sync(GstVaapiDisplay *display)
1127 GstVaapiDisplayClass *klass;
1129 g_return_if_fail(display != NULL);
1131 klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
1133 klass->sync(display);
1134 else if (klass->flush)
1135 klass->flush(display);
1139 * gst_vaapi_display_flush:
1140 * @display: a #GstVaapiDisplay
1142 * Flushes any requests queued for the windowing system.
1144 * This is most useful for X11. On windowing systems where requests
1145 * are handled synchronously, this function will do nothing.
1148 gst_vaapi_display_flush(GstVaapiDisplay *display)
1150 GstVaapiDisplayClass *klass;
1152 g_return_if_fail(display != NULL);
1154 klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
1156 klass->flush(display);
1160 * gst_vaapi_display_get_display:
1161 * @display: a #GstVaapiDisplay
1163 * Returns the #GstVaapiDisplayType bound to @display.
1165 * Return value: the #GstVaapiDisplayType
1168 gst_vaapi_display_get_display_type(GstVaapiDisplay *display)
1170 g_return_val_if_fail(display != NULL, GST_VAAPI_DISPLAY_TYPE_ANY);
1172 return GST_VAAPI_DISPLAY_GET_PRIVATE(display)->display_type;
1176 * gst_vaapi_display_get_display:
1177 * @display: a #GstVaapiDisplay
1179 * Returns the #VADisplay bound to @display.
1181 * Return value: the #VADisplay
1184 gst_vaapi_display_get_display(GstVaapiDisplay *display)
1186 g_return_val_if_fail(display != NULL, NULL);
1188 return GST_VAAPI_DISPLAY_GET_PRIVATE(display)->display;
1192 * gst_vaapi_display_get_width:
1193 * @display: a #GstVaapiDisplay
1195 * Retrieves the width of a #GstVaapiDisplay.
1197 * Return value: the width of the @display, in pixels
1200 gst_vaapi_display_get_width(GstVaapiDisplay *display)
1202 g_return_val_if_fail(display != NULL, 0);
1204 return GST_VAAPI_DISPLAY_GET_PRIVATE(display)->width;
1208 * gst_vaapi_display_get_height:
1209 * @display: a #GstVaapiDisplay
1211 * Retrieves the height of a #GstVaapiDisplay
1213 * Return value: the height of the @display, in pixels
1216 gst_vaapi_display_get_height(GstVaapiDisplay *display)
1218 g_return_val_if_fail(display != NULL, 0);
1220 return GST_VAAPI_DISPLAY_GET_PRIVATE(display)->height;
1224 * gst_vaapi_display_get_size:
1225 * @display: a #GstVaapiDisplay
1226 * @pwidth: return location for the width, or %NULL
1227 * @pheight: return location for the height, or %NULL
1229 * Retrieves the dimensions of a #GstVaapiDisplay.
1232 gst_vaapi_display_get_size(GstVaapiDisplay *display, guint *pwidth, guint *pheight)
1234 g_return_if_fail(GST_VAAPI_DISPLAY(display));
1237 *pwidth = GST_VAAPI_DISPLAY_GET_PRIVATE(display)->width;
1240 *pheight = GST_VAAPI_DISPLAY_GET_PRIVATE(display)->height;
1244 * gst_vaapi_display_get_pixel_aspect_ratio:
1245 * @display: a #GstVaapiDisplay
1246 * @par_n: return location for the numerator of pixel aspect ratio, or %NULL
1247 * @par_d: return location for the denominator of pixel aspect ratio, or %NULL
1249 * Retrieves the pixel aspect ratio of a #GstVaapiDisplay.
1252 gst_vaapi_display_get_pixel_aspect_ratio(
1253 GstVaapiDisplay *display,
1258 g_return_if_fail(display != NULL);
1261 *par_n = GST_VAAPI_DISPLAY_GET_PRIVATE(display)->par_n;
1264 *par_d = GST_VAAPI_DISPLAY_GET_PRIVATE(display)->par_d;
1268 * gst_vaapi_display_get_decode_caps:
1269 * @display: a #GstVaapiDisplay
1271 * Gets the supported profiles for decoding as #GstCaps capabilities.
1273 * Return value: a newly allocated #GstCaps object, possibly empty
1276 gst_vaapi_display_get_decode_caps(GstVaapiDisplay *display)
1278 g_return_val_if_fail(display != NULL, NULL);
1280 return get_profile_caps(GST_VAAPI_DISPLAY_GET_PRIVATE(display)->decoders);
1284 * gst_vaapi_display_has_decoder:
1285 * @display: a #GstVaapiDisplay
1286 * @profile: a #VAProfile
1287 * @entrypoint: a #GstVaaiEntrypoint
1289 * Returns whether VA @display supports @profile for decoding at the
1290 * specified @entrypoint.
1292 * Return value: %TRUE if VA @display supports @profile for decoding.
1295 gst_vaapi_display_has_decoder(
1296 GstVaapiDisplay *display,
1297 GstVaapiProfile profile,
1298 GstVaapiEntrypoint entrypoint
1301 g_return_val_if_fail(display != NULL, FALSE);
1304 GST_VAAPI_DISPLAY_GET_PRIVATE(display)->decoders, profile, entrypoint);
1308 * gst_vaapi_display_get_encode_caps:
1309 * @display: a #GstVaapiDisplay
1311 * Gets the supported profiles for decoding as #GstCaps capabilities.
1313 * Return value: a newly allocated #GstCaps object, possibly empty
1316 gst_vaapi_display_get_encode_caps(GstVaapiDisplay *display)
1318 g_return_val_if_fail(display != NULL, NULL);
1320 return get_profile_caps(GST_VAAPI_DISPLAY_GET_PRIVATE(display)->encoders);
1324 * gst_vaapi_display_has_encoder:
1325 * @display: a #GstVaapiDisplay
1326 * @profile: a #VAProfile
1327 * @entrypoint: a #GstVaapiEntrypoint
1329 * Returns whether VA @display supports @profile for encoding at the
1330 * specified @entrypoint.
1332 * Return value: %TRUE if VA @display supports @profile for encoding.
1335 gst_vaapi_display_has_encoder(
1336 GstVaapiDisplay *display,
1337 GstVaapiProfile profile,
1338 GstVaapiEntrypoint entrypoint
1341 g_return_val_if_fail(display != NULL, FALSE);
1344 GST_VAAPI_DISPLAY_GET_PRIVATE(display)->encoders, profile, entrypoint);
1348 * gst_vaapi_display_get_image_caps:
1349 * @display: a #GstVaapiDisplay
1351 * Gets the supported image formats for gst_vaapi_surface_get_image()
1352 * or gst_vaapi_surface_put_image() as #GstCaps capabilities.
1354 * Note that this method does not necessarily map image formats
1355 * returned by vaQueryImageFormats(). The set of capabilities can be
1356 * stripped down, if gstreamer-vaapi does not support the format, or
1357 * expanded to cover compatible formats not exposed by the underlying
1358 * driver. e.g. I420 can be supported even if the driver only exposes
1361 * Return value: a newly allocated #GstCaps object, possibly empty
1364 gst_vaapi_display_get_image_caps(GstVaapiDisplay *display)
1366 g_return_val_if_fail(display != NULL, NULL);
1368 return get_format_caps(
1369 GST_VAAPI_DISPLAY_GET_PRIVATE(display)->image_formats);
1373 * gst_vaapi_display_has_image_format:
1374 * @display: a #GstVaapiDisplay
1375 * @format: a #GstVideoFormat
1377 * Returns whether VA @display supports @format image format.
1379 * Return value: %TRUE if VA @display supports @format image format
1382 gst_vaapi_display_has_image_format(
1383 GstVaapiDisplay *display,
1384 GstVideoFormat format
1387 g_return_val_if_fail(display != NULL, FALSE);
1388 g_return_val_if_fail(format, FALSE);
1391 GST_VAAPI_DISPLAY_GET_PRIVATE(display)->image_formats, format))
1394 /* XXX: try subpicture formats since some drivers could report a
1395 * set of VA image formats that is not a superset of the set of VA
1396 * subpicture formats
1399 GST_VAAPI_DISPLAY_GET_PRIVATE(display)->subpicture_formats, format);
1403 * gst_vaapi_display_get_subpicture_caps:
1404 * @display: a #GstVaapiDisplay
1406 * Gets the supported subpicture formats as #GstCaps capabilities.
1408 * Note that this method does not necessarily map subpicture formats
1409 * returned by vaQuerySubpictureFormats(). The set of capabilities can
1410 * be stripped down if gstreamer-vaapi does not support the
1411 * format. e.g. this is the case for paletted formats like IA44.
1413 * Return value: a newly allocated #GstCaps object, possibly empty
1416 gst_vaapi_display_get_subpicture_caps(GstVaapiDisplay *display)
1418 g_return_val_if_fail(display != NULL, NULL);
1420 return get_format_caps(
1421 GST_VAAPI_DISPLAY_GET_PRIVATE(display)->subpicture_formats);
1425 * gst_vaapi_display_has_subpicture_format:
1426 * @display: a #GstVaapiDisplay
1427 * @format: a #GstVideoFormat
1428 * @flags_ptr: pointer to #GstVaapiSubpictureFlags, or zero
1430 * Returns whether VA @display supports @format subpicture format with
1431 * the supplied @flags.
1433 * Return value: %TRUE if VA @display supports @format subpicture format
1436 gst_vaapi_display_has_subpicture_format(
1437 GstVaapiDisplay *display,
1438 GstVideoFormat format,
1442 const GstVaapiFormatInfo *fip;
1444 g_return_val_if_fail(display != NULL, FALSE);
1445 g_return_val_if_fail(format, FALSE);
1447 fip = find_format_info(
1448 GST_VAAPI_DISPLAY_GET_PRIVATE(display)->subpicture_formats, format);
1453 *flags_ptr = fip->flags;
1458 * gst_vaapi_display_has_property:
1459 * @display: a #GstVaapiDisplay
1460 * @name: the property name to check
1462 * Returns whether VA @display supports the requested property. The
1463 * check is performed against the property @name. So, the client
1464 * application may perform this check only once and cache this
1467 * Return value: %TRUE if VA @display supports property @name
1470 gst_vaapi_display_has_property(GstVaapiDisplay *display, const gchar *name)
1472 g_return_val_if_fail(display != NULL, FALSE);
1473 g_return_val_if_fail(name, FALSE);
1475 return find_property(
1476 GST_VAAPI_DISPLAY_GET_PRIVATE(display)->properties, name) != NULL;
1480 gst_vaapi_display_get_property(GstVaapiDisplay *display, const gchar *name,
1483 const GstVaapiProperty *prop;
1485 g_return_val_if_fail(display != NULL, FALSE);
1486 g_return_val_if_fail(name != NULL, FALSE);
1487 g_return_val_if_fail(out_value != NULL, FALSE);
1489 prop = find_property(
1490 GST_VAAPI_DISPLAY_GET_PRIVATE(display)->properties, name);
1494 switch (prop->attribute.type) {
1495 case VADisplayAttribRenderMode: {
1496 GstVaapiRenderMode mode;
1497 if (!gst_vaapi_display_get_render_mode(display, &mode))
1499 g_value_init(out_value, GST_VAAPI_TYPE_RENDER_MODE);
1500 g_value_set_enum(out_value, mode);
1503 case VADisplayAttribRotation: {
1504 GstVaapiRotation rotation;
1505 rotation = gst_vaapi_display_get_rotation(display);
1506 g_value_init(out_value, GST_VAAPI_TYPE_ROTATION);
1507 g_value_set_enum(out_value, rotation);
1510 case VADisplayAttribHue:
1511 case VADisplayAttribSaturation:
1512 case VADisplayAttribBrightness:
1513 case VADisplayAttribContrast: {
1515 if (!get_color_balance(display, find_property_id(name), &value))
1517 g_value_init(out_value, G_TYPE_FLOAT);
1518 g_value_set_float(out_value, value);
1522 GST_WARNING("unsupported property '%s'", name);
1529 gst_vaapi_display_set_property(GstVaapiDisplay *display, const gchar *name,
1530 const GValue *value)
1532 const GstVaapiProperty *prop;
1534 g_return_val_if_fail(display != NULL, FALSE);
1535 g_return_val_if_fail(name != NULL, FALSE);
1536 g_return_val_if_fail(value != NULL, FALSE);
1538 prop = find_property(
1539 GST_VAAPI_DISPLAY_GET_PRIVATE(display)->properties, name);
1543 switch (prop->attribute.type) {
1544 case VADisplayAttribRenderMode: {
1545 GstVaapiRenderMode mode;
1546 if (!G_VALUE_HOLDS(value, GST_VAAPI_TYPE_RENDER_MODE))
1548 mode = g_value_get_enum(value);
1549 return gst_vaapi_display_set_render_mode(display, mode);
1551 case VADisplayAttribRotation: {
1552 GstVaapiRotation rotation;
1553 if (!G_VALUE_HOLDS(value, GST_VAAPI_TYPE_ROTATION))
1555 rotation = g_value_get_enum(value);
1556 return gst_vaapi_display_set_rotation(display, rotation);
1558 case VADisplayAttribHue:
1559 case VADisplayAttribSaturation:
1560 case VADisplayAttribBrightness:
1561 case VADisplayAttribContrast: {
1563 if (!G_VALUE_HOLDS(value, G_TYPE_FLOAT))
1565 v = g_value_get_float(value);
1566 return set_color_balance(display, find_property_id(name), v);
1572 GST_WARNING("unsupported property '%s'", name);
1577 get_attribute(GstVaapiDisplay *display, VADisplayAttribType type, gint *value)
1579 GstVaapiDisplayPrivate * const priv =
1580 GST_VAAPI_DISPLAY_GET_PRIVATE(display);
1581 VADisplayAttribute attr;
1585 attr.flags = VA_DISPLAY_ATTRIB_GETTABLE;
1586 status = vaGetDisplayAttributes(priv->display, &attr, 1);
1587 if (!vaapi_check_status(status, "vaGetDisplayAttributes()"))
1589 *value = attr.value;
1594 set_attribute(GstVaapiDisplay *display, VADisplayAttribType type, gint value)
1596 GstVaapiDisplayPrivate * const priv =
1597 GST_VAAPI_DISPLAY_GET_PRIVATE(display);
1598 VADisplayAttribute attr;
1603 attr.flags = VA_DISPLAY_ATTRIB_SETTABLE;
1604 status = vaSetDisplayAttributes(priv->display, &attr, 1);
1605 if (!vaapi_check_status(status, "vaSetDisplayAttributes()"))
1611 get_render_mode_VADisplayAttribRenderMode(
1612 GstVaapiDisplay *display,
1613 GstVaapiRenderMode *pmode
1616 gint modes, devices;
1618 if (!get_attribute(display, VADisplayAttribRenderDevice, &devices))
1622 if (!get_attribute(display, VADisplayAttribRenderMode, &modes))
1625 /* Favor "overlay" mode since it is the most restrictive one */
1626 if (modes & (VA_RENDER_MODE_LOCAL_OVERLAY|VA_RENDER_MODE_EXTERNAL_OVERLAY))
1627 *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
1629 *pmode = GST_VAAPI_RENDER_MODE_TEXTURE;
1634 get_render_mode_VADisplayAttribDirectSurface(
1635 GstVaapiDisplay *display,
1636 GstVaapiRenderMode *pmode
1639 #if VA_CHECK_VERSION(0,34,0)
1640 /* VADisplayAttribDirectsurface was removed in VA-API >= 0.34.0 */
1643 gint direct_surface;
1645 if (!get_attribute(display, VADisplayAttribDirectSurface, &direct_surface))
1648 *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
1650 *pmode = GST_VAAPI_RENDER_MODE_TEXTURE;
1656 get_render_mode_default(
1657 GstVaapiDisplay *display,
1658 GstVaapiRenderMode *pmode
1661 GstVaapiDisplayPrivate * const priv =
1662 GST_VAAPI_DISPLAY_GET_PRIVATE(display);
1664 switch (priv->display_type) {
1666 case GST_VAAPI_DISPLAY_TYPE_WAYLAND:
1667 /* wl_buffer mapped from VA surface through vaGetSurfaceBufferWl() */
1668 *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
1672 case GST_VAAPI_DISPLAY_TYPE_DRM:
1673 /* vaGetSurfaceBufferDRM() returns the underlying DRM buffer handle */
1674 *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
1678 /* This includes VA/X11 and VA/GLX modes */
1679 *pmode = DEFAULT_RENDER_MODE;
1686 * gst_vaapi_display_get_render_mode:
1687 * @display: a #GstVaapiDisplay
1688 * @pmode: return location for the VA @display rendering mode
1690 * Returns the current VA @display rendering mode.
1692 * Return value: %TRUE if VA @display rendering mode could be determined
1695 gst_vaapi_display_get_render_mode(
1696 GstVaapiDisplay *display,
1697 GstVaapiRenderMode *pmode
1700 g_return_val_if_fail(display != NULL, FALSE);
1702 /* Try with render-mode attribute */
1703 if (get_render_mode_VADisplayAttribRenderMode(display, pmode))
1706 /* Try with direct-surface attribute */
1707 if (get_render_mode_VADisplayAttribDirectSurface(display, pmode))
1710 /* Default: determine from the display type */
1711 return get_render_mode_default(display, pmode);
1715 * gst_vaapi_display_set_render_mode:
1716 * @display: a #GstVaapiDisplay
1717 * @mode: the #GstVaapiRenderMode to set
1719 * Sets the VA @display rendering mode to the supplied @mode. This
1720 * function returns %FALSE if the rendering mode could not be set,
1721 * e.g. run-time switching rendering mode is not supported.
1723 * Return value: %TRUE if VA @display rendering @mode could be changed
1724 * to the requested value
1727 gst_vaapi_display_set_render_mode(
1728 GstVaapiDisplay *display,
1729 GstVaapiRenderMode mode
1732 gint modes, devices;
1734 g_return_val_if_fail(display != NULL, FALSE);
1736 if (!get_attribute(display, VADisplayAttribRenderDevice, &devices))
1741 case GST_VAAPI_RENDER_MODE_OVERLAY:
1742 if (devices & VA_RENDER_DEVICE_LOCAL)
1743 modes |= VA_RENDER_MODE_LOCAL_OVERLAY;
1744 if (devices & VA_RENDER_DEVICE_EXTERNAL)
1745 modes |= VA_RENDER_MODE_EXTERNAL_OVERLAY;
1747 case GST_VAAPI_RENDER_MODE_TEXTURE:
1748 if (devices & VA_RENDER_DEVICE_LOCAL)
1749 modes |= VA_RENDER_MODE_LOCAL_GPU;
1750 if (devices & VA_RENDER_DEVICE_EXTERNAL)
1751 modes |= VA_RENDER_MODE_EXTERNAL_GPU;
1756 if (!set_attribute(display, VADisplayAttribRenderMode, modes))
1762 * gst_vaapi_display_get_rotation:
1763 * @display: a #GstVaapiDisplay
1765 * Returns the current VA @display rotation angle. If the VA driver
1766 * does not support "rotation" display attribute, then the display is
1767 * assumed to be un-rotated.
1769 * Return value: the current #GstVaapiRotation value
1772 gst_vaapi_display_get_rotation(GstVaapiDisplay *display)
1776 g_return_val_if_fail(display != NULL, DEFAULT_ROTATION);
1778 if (!get_attribute(display, VADisplayAttribRotation, &value))
1779 value = VA_ROTATION_NONE;
1780 return to_GstVaapiRotation(value);
1784 * gst_vaapi_display_set_rotation:
1785 * @display: a #GstVaapiDisplay
1786 * @rotation: the #GstVaapiRotation value to set
1788 * Sets the VA @display rotation angle to the supplied @rotation
1789 * value. This function returns %FALSE if the rotation angle could not
1790 * be set, e.g. the VA driver does not allow to change the display
1793 * Return value: %TRUE if VA @display rotation angle could be changed
1794 * to the requested value
1797 gst_vaapi_display_set_rotation(
1798 GstVaapiDisplay *display,
1799 GstVaapiRotation rotation
1804 g_return_val_if_fail(display != NULL, FALSE);
1806 value = from_GstVaapiRotation(rotation);
1807 if (!set_attribute(display, VADisplayAttribRotation, value))
1812 /* Get color balance attributes */
1814 get_color_balance(GstVaapiDisplay *display, guint prop_id, gfloat *v)
1816 GParamSpecFloat * const pspec = G_PARAM_SPEC_FLOAT(g_properties[prop_id]);
1817 const GstVaapiProperty *prop;
1818 const VADisplayAttribute *attr;
1825 prop = find_property_by_pspec(display, &pspec->parent_instance);
1828 attr = &prop->attribute;
1830 if (!get_attribute(display, attr->type, &value))
1833 /* Scale wrt. the medium ("default") value */
1834 out_value = pspec->default_value;
1835 if (value > attr->value)
1836 out_value += ((gfloat)(value - attr->value) /
1837 (attr->max_value - attr->value) *
1838 (pspec->maximum - pspec->default_value));
1839 else if (value < attr->value)
1840 out_value -= ((gfloat)(attr->value - value) /
1841 (attr->value - attr->min_value) *
1842 (pspec->default_value - pspec->minimum));
1847 /* Set color balance attribute */
1849 set_color_balance(GstVaapiDisplay *display, guint prop_id, gfloat v)
1851 GParamSpecFloat * const pspec = G_PARAM_SPEC_FLOAT(g_properties[prop_id]);
1852 const GstVaapiProperty *prop;
1853 const VADisplayAttribute *attr;
1859 prop = find_property_by_pspec(display, &pspec->parent_instance);
1862 attr = &prop->attribute;
1864 /* Scale wrt. the medium ("default") value */
1865 value = attr->value;
1866 if (v > pspec->default_value)
1867 value += ((v - pspec->default_value) /
1868 (pspec->maximum - pspec->default_value) *
1869 (attr->max_value - attr->value));
1870 else if (v < pspec->default_value)
1871 value -= ((pspec->default_value - v) /
1872 (pspec->default_value - pspec->minimum) *
1873 (attr->value - attr->min_value));
1874 if (!set_attribute(display, attr->type, value))