va: Fix struct empty initialization syntax
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / va / gstvadisplay_priv.c
1 /* GStreamer
2  * Copyright (C) 2020 Igalia, S.L.
3  *     Author: Víctor Jáquez <vjaquez@igalia.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "gstvadisplay_priv.h"
26
27 #include <gst/va/gstvavideoformat.h>
28
29 #include "gstvaprofile.h"
30
31 GArray *
32 gst_va_display_get_profiles (GstVaDisplay * self, guint32 codec,
33     VAEntrypoint entrypoint)
34 {
35   GArray *ret = NULL;
36   VADisplay dpy;
37   VAEntrypoint *entrypoints;
38   VAProfile *profiles;
39   VAStatus status;
40   gint i, j, num_entrypoints = 0, num_profiles = 0;
41
42   g_return_val_if_fail (GST_IS_VA_DISPLAY (self), NULL);
43
44   dpy = gst_va_display_get_va_dpy (self);
45
46   num_profiles = vaMaxNumProfiles (dpy);
47   num_entrypoints = vaMaxNumEntrypoints (dpy);
48
49   profiles = g_new (VAProfile, num_profiles);
50   entrypoints = g_new (VAEntrypoint, num_entrypoints);
51
52   status = vaQueryConfigProfiles (dpy, profiles, &num_profiles);
53   if (status != VA_STATUS_SUCCESS) {
54     GST_ERROR ("vaQueryConfigProfile: %s", vaErrorStr (status));
55     goto bail;
56   }
57
58   for (i = 0; i < num_profiles; i++) {
59     if (codec != gst_va_profile_codec (profiles[i]))
60       continue;
61
62     status = vaQueryConfigEntrypoints (dpy, profiles[i], entrypoints,
63         &num_entrypoints);
64     if (status != VA_STATUS_SUCCESS) {
65       GST_ERROR ("vaQueryConfigEntrypoints: %s", vaErrorStr (status));
66       goto bail;
67     }
68
69     for (j = 0; j < num_entrypoints; j++) {
70       if (entrypoints[j] == entrypoint) {
71         if (!ret)
72           ret = g_array_new (FALSE, FALSE, sizeof (VAProfile));
73         g_array_append_val (ret, profiles[i]);
74         break;
75       }
76     }
77   }
78
79 bail:
80   g_free (entrypoints);
81   g_free (profiles);
82   return ret;
83 }
84
85 GArray *
86 gst_va_display_get_image_formats (GstVaDisplay * self)
87 {
88   GArray *ret = NULL;
89   GstVideoFormat format;
90   VADisplay dpy;
91   VAImageFormat *va_formats;
92   VAStatus status;
93   int i, max, num = 0;
94
95   g_return_val_if_fail (GST_IS_VA_DISPLAY (self), NULL);
96
97   dpy = gst_va_display_get_va_dpy (self);
98
99   max = vaMaxNumImageFormats (dpy);
100   if (max == 0)
101     return NULL;
102
103   va_formats = g_new (VAImageFormat, max);
104
105   status = vaQueryImageFormats (dpy, va_formats, &num);
106
107   gst_va_video_format_fix_map (va_formats, num);
108
109   if (status != VA_STATUS_SUCCESS) {
110     GST_ERROR ("vaQueryImageFormats: %s", vaErrorStr (status));
111     goto bail;
112   }
113
114   ret = g_array_sized_new (FALSE, FALSE, sizeof (GstVideoFormat), num);
115   for (i = 0; i < num; i++) {
116     format = gst_va_video_format_from_va_image_format (&va_formats[i]);
117     if (format != GST_VIDEO_FORMAT_UNKNOWN)
118       g_array_append_val (ret, format);
119   }
120
121   if (ret->len == 0) {
122     g_array_unref (ret);
123     ret = NULL;
124   }
125
126 bail:
127   g_free (va_formats);
128   return ret;
129 }
130
131 gboolean
132 gst_va_display_has_vpp (GstVaDisplay * self)
133 {
134   VADisplay dpy;
135   VAEntrypoint *entrypoints;
136   VAStatus status;
137   int i, max, num;
138   gboolean found = FALSE;
139   g_return_val_if_fail (GST_IS_VA_DISPLAY (self), FALSE);
140
141   dpy = gst_va_display_get_va_dpy (self);
142
143   max = vaMaxNumEntrypoints (dpy);
144
145   entrypoints = g_new (VAEntrypoint, max);
146
147   status = vaQueryConfigEntrypoints (dpy, VAProfileNone, entrypoints, &num);
148   if (status != VA_STATUS_SUCCESS) {
149     GST_ERROR ("vaQueryImageFormats: %s", vaErrorStr (status));
150     goto bail;
151   }
152
153   for (i = 0; i < num; i++) {
154     if (entrypoints[i] == VAEntrypointVideoProc) {
155       found = TRUE;
156       break;
157     }
158   }
159
160 bail:
161   g_free (entrypoints);
162   return found;
163 }