Add gst_vaapi_display_{sync,flush}() helpers.
[platform/upstream/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapidisplay.c
1 /*
2  *  gstvaapidisplay.c - VA display abstraction
3  *
4  *  gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19  */
20
21 /**
22  * SECTION:gstvaapidisplay
23  * @short_description: VA display abstraction
24  */
25
26 #include "config.h"
27 #include "gstvaapiutils.h"
28 #include "gstvaapidisplay.h"
29
30 #define DEBUG 1
31 #include "gstvaapidebug.h"
32
33 GST_DEBUG_CATEGORY(gst_debug_vaapi);
34
35 G_DEFINE_TYPE(GstVaapiDisplay, gst_vaapi_display, G_TYPE_OBJECT);
36
37 #define GST_VAAPI_DISPLAY_GET_PRIVATE(obj)                      \
38     (G_TYPE_INSTANCE_GET_PRIVATE((obj),                         \
39                                  GST_VAAPI_TYPE_DISPLAY,        \
40                                  GstVaapiDisplayPrivate))
41
42 struct _GstVaapiDisplayPrivate {
43     GStaticMutex        mutex;
44     VADisplay           display;
45     guint               width;
46     guint               height;
47     guint               width_mm;
48     guint               height_mm;
49     guint               par_n;
50     guint               par_d;
51     GArray             *profiles;
52     GArray             *image_formats;
53     GArray             *subpicture_formats;
54     guint               create_display  : 1;
55 };
56
57 enum {
58     PROP_0,
59
60     PROP_DISPLAY,
61     PROP_WIDTH,
62     PROP_HEIGHT
63 };
64
65 /* Append GstVaapiImageFormat to formats array */
66 static inline void
67 append_format(GArray *formats, GstVaapiImageFormat format)
68 {
69     g_array_append_val(formats, format);
70 }
71
72 /* Append VAImageFormats to formats array */
73 static void
74 append_formats(GArray *formats, const VAImageFormat *va_formats, guint n)
75 {
76     GstVaapiImageFormat format;
77     gboolean has_YV12 = FALSE;
78     gboolean has_I420 = FALSE;
79     guint i;
80
81     for (i = 0; i < n; i++) {
82         const VAImageFormat * const va_format = &va_formats[i];
83
84         format = gst_vaapi_image_format(va_format);
85         if (!format) {
86             GST_DEBUG("unsupported format %" GST_FOURCC_FORMAT,
87                       GST_FOURCC_ARGS(va_format->fourcc));
88             continue;
89         }
90
91         switch (format) {
92         case GST_VAAPI_IMAGE_YV12:
93             has_YV12 = TRUE;
94             break;
95         case GST_VAAPI_IMAGE_I420:
96             has_I420 = TRUE;
97             break;
98         default:
99             break;
100         }
101         append_format(formats, format);
102     }
103
104     /* Append I420 (resp. YV12) format if YV12 (resp. I420) is not
105        supported by the underlying driver */
106     if (has_YV12 && !has_I420)
107         append_format(formats, GST_VAAPI_IMAGE_I420);
108     else if (has_I420 && !has_YV12)
109         append_format(formats, GST_VAAPI_IMAGE_YV12);
110 }
111
112 /* Sort image formats. Prefer YUV formats first */
113 static gint
114 compare_yuv_formats(gconstpointer a, gconstpointer b)
115 {
116     const GstVaapiImageFormat fmt1 = *(GstVaapiImageFormat *)a;
117     const GstVaapiImageFormat fmt2 = *(GstVaapiImageFormat *)b;
118
119     const gboolean is_fmt1_yuv = gst_vaapi_image_format_is_yuv(fmt1);
120     const gboolean is_fmt2_yuv = gst_vaapi_image_format_is_yuv(fmt2);
121
122     if (is_fmt1_yuv != is_fmt2_yuv)
123         return is_fmt1_yuv ? -1 : 1;
124
125     return ((gint)gst_vaapi_image_format_get_score(fmt1) -
126             (gint)gst_vaapi_image_format_get_score(fmt2));
127 }
128
129 /* Sort subpicture formats. Prefer RGB formats first */
130 static gint
131 compare_rgb_formats(gconstpointer a, gconstpointer b)
132 {
133     const GstVaapiImageFormat fmt1 = *(GstVaapiImageFormat *)a;
134     const GstVaapiImageFormat fmt2 = *(GstVaapiImageFormat *)b;
135
136     const gboolean is_fmt1_rgb = gst_vaapi_image_format_is_rgb(fmt1);
137     const gboolean is_fmt2_rgb = gst_vaapi_image_format_is_rgb(fmt2);
138
139     if (is_fmt1_rgb != is_fmt2_rgb)
140         return is_fmt1_rgb ? -1 : 1;
141
142     return ((gint)gst_vaapi_image_format_get_score(fmt1) -
143             (gint)gst_vaapi_image_format_get_score(fmt2));
144 }
145
146 /* Check if profiles array contains profile */
147 static inline gboolean
148 find_profile(GArray *profiles, VAProfile profile)
149 {
150     guint i;
151
152     for (i = 0; i < profiles->len; i++)
153         if (g_array_index(profiles, VAProfile, i) == profile)
154             return TRUE;
155     return FALSE;
156 }
157
158 /* Check if formats array contains format */
159 static inline gboolean
160 find_format(GArray *formats, GstVaapiImageFormat format)
161 {
162     guint i;
163
164     for (i = 0; i < formats->len; i++)
165         if (g_array_index(formats, GstVaapiImageFormat, i) == format)
166             return TRUE;
167     return FALSE;
168 }
169
170 /* Convert formats array to GstCaps */
171 static GstCaps *
172 get_caps(GArray *formats)
173 {
174     GstVaapiImageFormat format;
175     GstCaps *out_caps, *caps;
176     guint i;
177
178     out_caps = gst_caps_new_empty();
179     if (!out_caps)
180         return NULL;
181
182     for (i = 0; i < formats->len; i++) {
183         format = g_array_index(formats, GstVaapiImageFormat, i);
184         caps   = gst_vaapi_image_format_get_caps(format);
185         if (caps)
186             gst_caps_append(out_caps, caps);
187     }
188     return out_caps;
189 }
190
191 static void
192 gst_vaapi_display_calculate_pixel_aspect_ratio(GstVaapiDisplay *display)
193 {
194     GstVaapiDisplayPrivate * const priv = display->priv;
195     gdouble ratio, delta;
196     gint i, index;
197
198     static const gint par[][2] = {
199         {1, 1},         /* regular screen            */
200         {16, 15},       /* PAL TV                    */
201         {11, 10},       /* 525 line Rec.601 video    */
202         {54, 59},       /* 625 line Rec.601 video    */
203         {64, 45},       /* 1280x1024 on 16:9 display */
204         {5, 3},         /* 1280x1024 on  4:3 display */
205         {4, 3}          /*  800x600  on 16:9 display */
206     };
207
208     /* First, calculate the "real" ratio based on the X values;
209      * which is the "physical" w/h divided by the w/h in pixels of the
210      * display */
211     if (!priv->width || !priv->height || !priv->width_mm || !priv->height_mm)
212         ratio = 1.0;
213     else
214         ratio = (gdouble)(priv->width_mm * priv->height) /
215             (priv->height_mm * priv->width);
216     GST_DEBUG("calculated pixel aspect ratio: %f", ratio);
217
218     /* Now, find the one from par[][2] with the lowest delta to the real one */
219 #define DELTA(idx) (ABS(ratio - ((gdouble)par[idx][0] / par[idx][1])))
220     delta = DELTA(0);
221     index = 0;
222
223     for (i = 1; i < G_N_ELEMENTS(par); i++) {
224         const gdouble this_delta = DELTA(i);
225         if (this_delta < delta) {
226             index = i;
227             delta = this_delta;
228         }
229     }
230 #undef DELTA
231
232     priv->par_n = par[index][0];
233     priv->par_d = par[index][1];
234 }
235
236 static void
237 gst_vaapi_display_destroy(GstVaapiDisplay *display)
238 {
239     GstVaapiDisplayPrivate * const priv = display->priv;
240
241     if (priv->profiles) {
242         g_array_free(priv->profiles, TRUE);
243         priv->profiles = NULL;
244     }
245
246     if (priv->image_formats) {
247         g_array_free(priv->image_formats, TRUE);
248         priv->image_formats = NULL;
249     }
250
251     if (priv->subpicture_formats) {
252         g_array_free(priv->subpicture_formats, TRUE);
253         priv->subpicture_formats = NULL;
254     }
255
256     if (priv->display) {
257         vaTerminate(priv->display);
258         priv->display = NULL;
259     }
260
261     if (priv->create_display) {
262         GstVaapiDisplayClass *klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
263         if (klass->close_display)
264             klass->close_display(display);
265     }
266 }
267
268 static gboolean
269 gst_vaapi_display_create(GstVaapiDisplay *display)
270 {
271     GstVaapiDisplayPrivate * const priv = display->priv;
272     gboolean            has_errors      = TRUE;
273     VAProfile          *profiles        = NULL;
274     VAImageFormat      *formats         = NULL;
275     unsigned int       *flags           = NULL;
276     gint                i, n, major_version, minor_version;
277     VAStatus            status;
278
279     if (!priv->display && priv->create_display) {
280         GstVaapiDisplayClass *klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
281         if (klass->open_display && !klass->open_display(display))
282             return FALSE;
283         if (klass->get_display) {
284             priv->display = klass->get_display(display);
285             if (!priv->display)
286                 return FALSE;
287         }
288         if (klass->get_size)
289             klass->get_size(display, &priv->width, &priv->height);
290         if (klass->get_size_mm)
291             klass->get_size_mm(display, &priv->width_mm, &priv->height_mm);
292         gst_vaapi_display_calculate_pixel_aspect_ratio(display);
293     }
294     if (!priv->display)
295         return FALSE;
296
297     status = vaInitialize(priv->display, &major_version, &minor_version);
298     if (!vaapi_check_status(status, "vaInitialize()"))
299         goto end;
300     GST_DEBUG("VA-API version %d.%d", major_version, minor_version);
301
302     /* VA profiles */
303     profiles = g_new(VAProfile, vaMaxNumProfiles(priv->display));
304     if (!profiles)
305         goto end;
306     status = vaQueryConfigProfiles(priv->display, profiles, &n);
307     if (!vaapi_check_status(status, "vaQueryConfigProfiles()"))
308         goto end;
309
310     GST_DEBUG("%d profiles", n);
311     for (i = 0; i < n; i++)
312         GST_DEBUG("  %s", string_of_VAProfile(profiles[i]));
313
314     priv->profiles = g_array_new(FALSE, FALSE, sizeof(VAProfile));
315     if (!priv->profiles)
316         goto end;
317     g_array_append_vals(priv->profiles, profiles, n);
318
319     /* VA image formats */
320     formats = g_new(VAImageFormat, vaMaxNumImageFormats(priv->display));
321     if (!formats)
322         goto end;
323     status = vaQueryImageFormats(priv->display, formats, &n);
324     if (!vaapi_check_status(status, "vaQueryImageFormats()"))
325         goto end;
326
327     GST_DEBUG("%d image formats", n);
328     for (i = 0; i < n; i++)
329         GST_DEBUG("  %s", string_of_FOURCC(formats[i].fourcc));
330
331     priv->image_formats =
332         g_array_new(FALSE, FALSE, sizeof(GstVaapiImageFormat));
333     if (!priv->image_formats)
334         goto end;
335     append_formats(priv->image_formats, formats, n);
336     g_array_sort(priv->image_formats, compare_yuv_formats);
337
338     /* VA subpicture formats */
339     n = vaMaxNumSubpictureFormats(priv->display);
340     formats = g_renew(VAImageFormat, formats, n);
341     flags   = g_new(guint, n);
342     if (!formats || !flags)
343         goto end;
344     status = vaQuerySubpictureFormats(priv->display, formats, flags, &n);
345     if (!vaapi_check_status(status, "vaQuerySubpictureFormats()"))
346         goto end;
347
348     GST_DEBUG("%d subpicture formats", n);
349     for (i = 0; i < n; i++)
350         GST_DEBUG("  %s", string_of_FOURCC(formats[i].fourcc));
351
352     priv->subpicture_formats =
353         g_array_new(FALSE, FALSE, sizeof(GstVaapiImageFormat));
354     if (!priv->subpicture_formats)
355         goto end;
356     append_formats(priv->subpicture_formats, formats, n);
357     g_array_sort(priv->subpicture_formats, compare_rgb_formats);
358
359     has_errors = FALSE;
360 end:
361     g_free(profiles);
362     g_free(formats);
363     g_free(flags);
364     return !has_errors;
365 }
366
367 static void
368 gst_vaapi_display_lock_default(GstVaapiDisplay *display)
369 {
370     g_static_mutex_lock(&display->priv->mutex);
371 }
372
373 static void
374 gst_vaapi_display_unlock_default(GstVaapiDisplay *display)
375 {
376     g_static_mutex_unlock(&display->priv->mutex);
377 }
378
379 static void
380 gst_vaapi_display_finalize(GObject *object)
381 {
382     GstVaapiDisplay * const display = GST_VAAPI_DISPLAY(object);
383
384     gst_vaapi_display_destroy(display);
385
386     G_OBJECT_CLASS(gst_vaapi_display_parent_class)->finalize(object);
387 }
388
389 static void
390 gst_vaapi_display_set_property(
391     GObject      *object,
392     guint         prop_id,
393     const GValue *value,
394     GParamSpec   *pspec
395 )
396 {
397     GstVaapiDisplay * const display = GST_VAAPI_DISPLAY(object);
398
399     switch (prop_id) {
400     case PROP_DISPLAY:
401         display->priv->display = g_value_get_pointer(value);
402         break;
403     default:
404         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
405         break;
406     }
407 }
408
409 static void
410 gst_vaapi_display_get_property(
411     GObject    *object,
412     guint       prop_id,
413     GValue     *value,
414     GParamSpec *pspec
415 )
416 {
417     GstVaapiDisplay * const display = GST_VAAPI_DISPLAY(object);
418
419     switch (prop_id) {
420     case PROP_DISPLAY:
421         g_value_set_pointer(value, gst_vaapi_display_get_display(display));
422         break;
423     case PROP_WIDTH:
424         g_value_set_uint(value, gst_vaapi_display_get_width(display));
425         break;
426     case PROP_HEIGHT:
427         g_value_set_uint(value, gst_vaapi_display_get_height(display));
428         break;
429     default:
430         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
431         break;
432     }
433 }
434
435 static void
436 gst_vaapi_display_constructed(GObject *object)
437 {
438     GstVaapiDisplay * const display = GST_VAAPI_DISPLAY(object);
439     GObjectClass *parent_class;
440
441     display->priv->create_display = display->priv->display == NULL;
442     gst_vaapi_display_create(display);
443
444     parent_class = G_OBJECT_CLASS(gst_vaapi_display_parent_class);
445     if (parent_class->constructed)
446         parent_class->constructed(object);
447 }
448
449 static void
450 gst_vaapi_display_class_init(GstVaapiDisplayClass *klass)
451 {
452     GObjectClass * const object_class = G_OBJECT_CLASS(klass);
453     GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);
454
455     GST_DEBUG_CATEGORY_INIT(gst_debug_vaapi, "vaapi", 0, "VA-API helper");
456
457     g_type_class_add_private(klass, sizeof(GstVaapiDisplayPrivate));
458
459     object_class->finalize      = gst_vaapi_display_finalize;
460     object_class->set_property  = gst_vaapi_display_set_property;
461     object_class->get_property  = gst_vaapi_display_get_property;
462     object_class->constructed   = gst_vaapi_display_constructed;
463
464     dpy_class->lock             = gst_vaapi_display_lock_default;
465     dpy_class->unlock           = gst_vaapi_display_unlock_default;
466
467     g_object_class_install_property
468         (object_class,
469          PROP_DISPLAY,
470          g_param_spec_pointer("display",
471                               "VA display",
472                               "VA display",
473                               G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
474
475     g_object_class_install_property
476         (object_class,
477          PROP_WIDTH,
478          g_param_spec_uint("width",
479                            "Width",
480                            "The display width",
481                            1, G_MAXUINT32, 1,
482                            G_PARAM_READABLE));
483
484     g_object_class_install_property
485         (object_class,
486          PROP_HEIGHT,
487          g_param_spec_uint("height",
488                            "height",
489                            "The display height",
490                            1, G_MAXUINT32, 1,
491                            G_PARAM_READABLE));
492 }
493
494 static void
495 gst_vaapi_display_init(GstVaapiDisplay *display)
496 {
497     GstVaapiDisplayPrivate *priv = GST_VAAPI_DISPLAY_GET_PRIVATE(display);
498
499     display->priv               = priv;
500     priv->display               = NULL;
501     priv->width                 = 0;
502     priv->height                = 0;
503     priv->width_mm              = 0;
504     priv->height_mm             = 0;
505     priv->par_n                 = 1;
506     priv->par_d                 = 1;
507     priv->profiles              = NULL;
508     priv->image_formats         = NULL;
509     priv->subpicture_formats    = NULL;
510     priv->create_display        = TRUE;
511
512     g_static_mutex_init(&priv->mutex);
513 }
514
515 /**
516  * gst_vaapi_display_new_with_display:
517  * @va_display: a #VADisplay
518  *
519  * Creates a new #GstVaapiDisplay, using @va_display as the VA
520  * display.
521  *
522  * Return value: the newly created #GstVaapiDisplay object
523  */
524 GstVaapiDisplay *
525 gst_vaapi_display_new_with_display(VADisplay va_display)
526 {
527     return g_object_new(GST_VAAPI_TYPE_DISPLAY,
528                         "display", va_display,
529                         NULL);
530 }
531
532 /**
533  * gst_vaapi_display_lock:
534  * @display: a #GstVaapiDisplay
535  *
536  * Locks @display. If @display is already locked by another thread,
537  * the current thread will block until @display is unlocked by the
538  * other thread.
539  */
540 void
541 gst_vaapi_display_lock(GstVaapiDisplay *display)
542 {
543     GstVaapiDisplayClass *klass;
544
545     g_return_if_fail(GST_VAAPI_IS_DISPLAY(display));
546
547     klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
548     if (klass->lock)
549         klass->lock(display);
550 }
551
552 /**
553  * gst_vaapi_display_unlock:
554  * @display: a #GstVaapiDisplay
555  *
556  * Unlocks @display. If another thread is blocked in a
557  * gst_vaapi_display_lock() call for @display, it will be woken and
558  * can lock @display itself.
559  */
560 void
561 gst_vaapi_display_unlock(GstVaapiDisplay *display)
562 {
563     GstVaapiDisplayClass *klass;
564
565     g_return_if_fail(GST_VAAPI_IS_DISPLAY(display));
566
567     klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
568     if (klass->unlock)
569         klass->unlock(display);
570 }
571
572 /**
573  * gst_vaapi_display_sync:
574  * @display: a #GstVaapiDisplay
575  *
576  * Flushes any requests queued for the windowing system and waits until
577  * all requests have been handled. This is often used for making sure
578  * that the display is synchronized with the current state of the program.
579  *
580  * This is most useful for X11. On windowing systems where requests are
581  * handled synchronously, this function will do nothing.
582  */
583 void
584 gst_vaapi_display_sync(GstVaapiDisplay *display)
585 {
586     GstVaapiDisplayClass *klass;
587
588     g_return_if_fail(GST_VAAPI_IS_DISPLAY(display));
589
590     klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
591     if (klass->sync)
592         klass->sync(display);
593     else if (klass->flush)
594         klass->flush(display);
595 }
596
597 /**
598  * gst_vaapi_display_sync:
599  * @display: a #GstVaapiDisplay
600  *
601  * Flushes any requests queued for the windowing system.
602  *
603  * This is most useful for X11. On windowing systems where requests
604  * are handled synchronously, this function will do nothing.
605  */
606 void
607 gst_vaapi_display_flush(GstVaapiDisplay *display)
608 {
609     GstVaapiDisplayClass *klass;
610
611     g_return_if_fail(GST_VAAPI_IS_DISPLAY(display));
612
613     klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
614     if (klass->flush)
615         klass->flush(display);
616 }
617
618 /**
619  * gst_vaapi_display_get_display:
620  * @display: a #GstVaapiDisplay
621  *
622  * Returns the #VADisplay bound to @display.
623  *
624  * Return value: the #VADisplay
625  */
626 VADisplay
627 gst_vaapi_display_get_display(GstVaapiDisplay *display)
628 {
629     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
630
631     return display->priv->display;
632 }
633
634 /**
635  * gst_vaapi_display_get_width:
636  * @display: a #GstVaapiDisplay
637  *
638  * Retrieves the width of a #GstVaapiDisplay.
639  *
640  * Return value: the width of the @display, in pixels
641  */
642 guint
643 gst_vaapi_display_get_width(GstVaapiDisplay *display)
644 {
645     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), 0);
646
647     return display->priv->width;
648 }
649
650 /**
651  * gst_vaapi_display_get_height:
652  * @display: a #GstVaapiDisplay
653  *
654  * Retrieves the height of a #GstVaapiDisplay
655  *
656  * Return value: the height of the @display, in pixels
657  */
658 guint
659 gst_vaapi_display_get_height(GstVaapiDisplay *display)
660 {
661     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), 0);
662
663     return display->priv->height;
664 }
665
666 /**
667  * gst_vaapi_display_get_size:
668  * @display: a #GstVaapiDisplay
669  * @pwidth: return location for the width, or %NULL
670  * @pheight: return location for the height, or %NULL
671  *
672  * Retrieves the dimensions of a #GstVaapiDisplay.
673  */
674 void
675 gst_vaapi_display_get_size(GstVaapiDisplay *display, guint *pwidth, guint *pheight)
676 {
677     g_return_if_fail(GST_VAAPI_DISPLAY(display));
678
679     if (pwidth)
680         *pwidth = display->priv->width;
681
682     if (pheight)
683         *pheight = display->priv->height;
684 }
685
686 /**
687  * gst_vaapi_display_get_pixel_aspect_ratio:
688  * @display: a #GstVaapiDisplay
689  * @par_n: return location for the numerator of pixel aspect ratio, or %NULL
690  * @par_d: return location for the denominator of pixel aspect ratio, or %NULL
691  *
692  * Retrieves the pixel aspect ratio of a #GstVaapiDisplay.
693  */
694 void
695 gst_vaapi_display_get_pixel_aspect_ratio(
696     GstVaapiDisplay *display,
697     guint           *par_n,
698     guint           *par_d
699 )
700 {
701     g_return_if_fail(GST_VAAPI_IS_DISPLAY(display));
702
703     if (par_n)
704         *par_n = display->priv->par_n;
705
706     if (par_d)
707         *par_d = display->priv->par_d;
708 }
709
710 /**
711  * gst_vaapi_display_has_profile:
712  * @display: a #GstVaapiDisplay
713  * @profile: a #VAProfile
714  *
715  * Returns whether VA @display supports @profile.
716  *
717  * Return value: %TRUE if VA @display supports @profile
718  */
719 gboolean
720 gst_vaapi_display_has_profile(GstVaapiDisplay *display, VAProfile profile)
721 {
722     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
723
724     return find_profile(display->priv->profiles, profile);
725 }
726
727 /**
728  * gst_vaapi_display_get_image_caps:
729  * @display: a #GstVaapiDisplay
730  *
731  * Gets the supported image formats for gst_vaapi_surface_get_image()
732  * or gst_vaapi_surface_put_image() as #GstCaps capabilities.
733  *
734  * Note that this method does not necessarily map image formats
735  * returned by vaQueryImageFormats(). The set of capabilities can be
736  * stripped down, if gstreamer-vaapi does not support the format, or
737  * expanded to cover compatible formats not exposed by the underlying
738  * driver. e.g. I420 can be supported even if the driver only exposes
739  * YV12.
740  *
741  * Return value: a newly allocated #GstCaps object, possibly empty
742  */
743 GstCaps *
744 gst_vaapi_display_get_image_caps(GstVaapiDisplay *display)
745 {
746     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
747
748     return get_caps(display->priv->image_formats);
749 }
750
751 /**
752  * gst_vaapi_display_has_image_format:
753  * @display: a #GstVaapiDisplay
754  * @format: a #GstVaapiFormat
755  *
756  * Returns whether VA @display supports @format image format.
757  *
758  * Return value: %TRUE if VA @display supports @format image format
759  */
760 gboolean
761 gst_vaapi_display_has_image_format(
762     GstVaapiDisplay    *display,
763     GstVaapiImageFormat format
764 )
765 {
766     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
767     g_return_val_if_fail(format, FALSE);
768
769     return find_format(display->priv->image_formats, format);
770 }
771
772 /**
773  * gst_vaapi_display_get_subpicture_caps:
774  * @display: a #GstVaapiDisplay
775  *
776  * Gets the supported subpicture formats as #GstCaps capabilities.
777  *
778  * Note that this method does not necessarily map subpicture formats
779  * returned by vaQuerySubpictureFormats(). The set of capabilities can
780  * be stripped down if gstreamer-vaapi does not support the
781  * format. e.g. this is the case for paletted formats like IA44.
782  *
783  * Return value: a newly allocated #GstCaps object, possibly empty
784  */
785 GstCaps *
786 gst_vaapi_display_get_subpicture_caps(GstVaapiDisplay *display)
787 {
788     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
789
790     return get_caps(display->priv->subpicture_formats);
791 }
792
793 /**
794  * gst_vaapi_display_has_subpicture_format:
795  * @display: a #GstVaapiDisplay
796  * @format: a #GstVaapiFormat
797  *
798  * Returns whether VA @display supports @format subpicture format.
799  *
800  * Return value: %TRUE if VA @display supports @format subpicture format
801  */
802 gboolean
803 gst_vaapi_display_has_subpicture_format(
804     GstVaapiDisplay    *display,
805     GstVaapiImageFormat format
806 )
807 {
808     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
809     g_return_val_if_fail(format, FALSE);
810
811     return find_format(display->priv->subpicture_formats, format);
812 }