314bf38af353b14a335e4593eb73948034f25c30
[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     gboolean            create_display;
52     GArray             *profiles;
53     GArray             *image_formats;
54     GArray             *subpicture_formats;
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->create_display        = TRUE;
508     priv->profiles              = NULL;
509     priv->image_formats         = NULL;
510     priv->subpicture_formats    = NULL;
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_get_display:
574  * @display: a #GstVaapiDisplay
575  *
576  * Returns the #VADisplay bound to @display.
577  *
578  * Return value: the #VADisplay
579  */
580 VADisplay
581 gst_vaapi_display_get_display(GstVaapiDisplay *display)
582 {
583     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
584
585     return display->priv->display;
586 }
587
588 /**
589  * gst_vaapi_display_get_width:
590  * @display: a #GstVaapiDisplay
591  *
592  * Retrieves the width of a #GstVaapiDisplay.
593  *
594  * Return value: the width of the @display, in pixels
595  */
596 guint
597 gst_vaapi_display_get_width(GstVaapiDisplay *display)
598 {
599     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), 0);
600
601     return display->priv->width;
602 }
603
604 /**
605  * gst_vaapi_display_get_height:
606  * @display: a #GstVaapiDisplay
607  *
608  * Retrieves the height of a #GstVaapiDisplay
609  *
610  * Return value: the height of the @display, in pixels
611  */
612 guint
613 gst_vaapi_display_get_height(GstVaapiDisplay *display)
614 {
615     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), 0);
616
617     return display->priv->height;
618 }
619
620 /**
621  * gst_vaapi_display_get_size:
622  * @display: a #GstVaapiDisplay
623  * @pwidth: return location for the width, or %NULL
624  * @pheight: return location for the height, or %NULL
625  *
626  * Retrieves the dimensions of a #GstVaapiDisplay.
627  */
628 void
629 gst_vaapi_display_get_size(GstVaapiDisplay *display, guint *pwidth, guint *pheight)
630 {
631     g_return_if_fail(GST_VAAPI_DISPLAY(display));
632
633     if (pwidth)
634         *pwidth = display->priv->width;
635
636     if (pheight)
637         *pheight = display->priv->height;
638 }
639
640 /**
641  * gst_vaapi_display_get_pixel_aspect_ratio:
642  * @display: a #GstVaapiDisplay
643  * @par_n: return location for the numerator of pixel aspect ratio, or %NULL
644  * @par_d: return location for the denominator of pixel aspect ratio, or %NULL
645  *
646  * Retrieves the pixel aspect ratio of a #GstVaapiDisplay.
647  */
648 void
649 gst_vaapi_display_get_pixel_aspect_ratio(
650     GstVaapiDisplay *display,
651     guint           *par_n,
652     guint           *par_d
653 )
654 {
655     g_return_if_fail(GST_VAAPI_IS_DISPLAY(display));
656
657     if (par_n)
658         *par_n = display->priv->par_n;
659
660     if (par_d)
661         *par_d = display->priv->par_d;
662 }
663
664 /**
665  * gst_vaapi_display_has_profile:
666  * @display: a #GstVaapiDisplay
667  * @profile: a #VAProfile
668  *
669  * Returns whether VA @display supports @profile.
670  *
671  * Return value: %TRUE if VA @display supports @profile
672  */
673 gboolean
674 gst_vaapi_display_has_profile(GstVaapiDisplay *display, VAProfile profile)
675 {
676     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
677
678     return find_profile(display->priv->profiles, profile);
679 }
680
681 /**
682  * gst_vaapi_display_get_image_caps:
683  * @display: a #GstVaapiDisplay
684  *
685  * Gets the supported image formats for gst_vaapi_surface_get_image()
686  * or gst_vaapi_surface_put_image() as #GstCaps capabilities.
687  *
688  * Note that this method does not necessarily map image formats
689  * returned by vaQueryImageFormats(). The set of capabilities can be
690  * stripped down, if gstreamer-vaapi does not support the format, or
691  * expanded to cover compatible formats not exposed by the underlying
692  * driver. e.g. I420 can be supported even if the driver only exposes
693  * YV12.
694  *
695  * Return value: a newly allocated #GstCaps object, possibly empty
696  */
697 GstCaps *
698 gst_vaapi_display_get_image_caps(GstVaapiDisplay *display)
699 {
700     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
701
702     return get_caps(display->priv->image_formats);
703 }
704
705 /**
706  * gst_vaapi_display_has_image_format:
707  * @display: a #GstVaapiDisplay
708  * @format: a #GstVaapiFormat
709  *
710  * Returns whether VA @display supports @format image format.
711  *
712  * Return value: %TRUE if VA @display supports @format image format
713  */
714 gboolean
715 gst_vaapi_display_has_image_format(
716     GstVaapiDisplay    *display,
717     GstVaapiImageFormat format
718 )
719 {
720     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
721     g_return_val_if_fail(format, FALSE);
722
723     return find_format(display->priv->image_formats, format);
724 }
725
726 /**
727  * gst_vaapi_display_get_subpicture_caps:
728  * @display: a #GstVaapiDisplay
729  *
730  * Gets the supported subpicture formats as #GstCaps capabilities.
731  *
732  * Note that this method does not necessarily map subpicture formats
733  * returned by vaQuerySubpictureFormats(). The set of capabilities can
734  * be stripped down if gstreamer-vaapi does not support the
735  * format. e.g. this is the case for paletted formats like IA44.
736  *
737  * Return value: a newly allocated #GstCaps object, possibly empty
738  */
739 GstCaps *
740 gst_vaapi_display_get_subpicture_caps(GstVaapiDisplay *display)
741 {
742     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
743
744     return get_caps(display->priv->subpicture_formats);
745 }
746
747 /**
748  * gst_vaapi_display_has_subpicture_format:
749  * @display: a #GstVaapiDisplay
750  * @format: a #GstVaapiFormat
751  *
752  * Returns whether VA @display supports @format subpicture format.
753  *
754  * Return value: %TRUE if VA @display supports @format subpicture format
755  */
756 gboolean
757 gst_vaapi_display_has_subpicture_format(
758     GstVaapiDisplay    *display,
759     GstVaapiImageFormat format
760 )
761 {
762     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
763     g_return_val_if_fail(format, FALSE);
764
765     return find_format(display->priv->subpicture_formats, format);
766 }