• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "gstvaprofile.h"
27 #include "gstvavideoformat.h"
28 
29 GArray *
gst_va_display_get_profiles(GstVaDisplay * self,guint32 codec,VAEntrypoint entrypoint)30 gst_va_display_get_profiles (GstVaDisplay * self, guint32 codec,
31     VAEntrypoint entrypoint)
32 {
33   GArray *ret = NULL;
34   VADisplay dpy;
35   VAEntrypoint *entrypoints;
36   VAProfile *profiles;
37   VAStatus status;
38   gint i, j, num_entrypoints = 0, num_profiles = 0;
39 
40   g_return_val_if_fail (GST_IS_VA_DISPLAY (self), NULL);
41 
42   dpy = gst_va_display_get_va_dpy (self);
43 
44   gst_va_display_lock (self);
45   num_profiles = vaMaxNumProfiles (dpy);
46   num_entrypoints = vaMaxNumEntrypoints (dpy);
47   gst_va_display_unlock (self);
48 
49   profiles = g_new (VAProfile, num_profiles);
50   entrypoints = g_new (VAEntrypoint, num_entrypoints);
51 
52   gst_va_display_lock (self);
53   status = vaQueryConfigProfiles (dpy, profiles, &num_profiles);
54   gst_va_display_unlock (self);
55   if (status != VA_STATUS_SUCCESS) {
56     GST_ERROR ("vaQueryConfigProfile: %s", vaErrorStr (status));
57     goto bail;
58   }
59 
60   for (i = 0; i < num_profiles; i++) {
61     if (codec != gst_va_profile_codec (profiles[i]))
62       continue;
63 
64     gst_va_display_lock (self);
65     status = vaQueryConfigEntrypoints (dpy, profiles[i], entrypoints,
66         &num_entrypoints);
67     gst_va_display_unlock (self);
68     if (status != VA_STATUS_SUCCESS) {
69       GST_ERROR ("vaQueryConfigEntrypoints: %s", vaErrorStr (status));
70       goto bail;
71     }
72 
73     for (j = 0; j < num_entrypoints; j++) {
74       if (entrypoints[j] == entrypoint) {
75         if (!ret)
76           ret = g_array_new (FALSE, FALSE, sizeof (VAProfile));
77         g_array_append_val (ret, profiles[i]);
78         break;
79       }
80     }
81   }
82 
83 bail:
84   g_free (entrypoints);
85   g_free (profiles);
86   return ret;
87 }
88 
89 GArray *
gst_va_display_get_image_formats(GstVaDisplay * self)90 gst_va_display_get_image_formats (GstVaDisplay * self)
91 {
92   GArray *ret = NULL;
93   GstVideoFormat format;
94   VADisplay dpy;
95   VAImageFormat *va_formats;
96   VAStatus status;
97   int i, max, num = 0;
98 
99   g_return_val_if_fail (GST_IS_VA_DISPLAY (self), NULL);
100 
101   dpy = gst_va_display_get_va_dpy (self);
102 
103   gst_va_display_lock (self);
104   max = vaMaxNumImageFormats (dpy);
105   gst_va_display_unlock (self);
106   if (max == 0)
107     return NULL;
108 
109   va_formats = g_new (VAImageFormat, max);
110 
111   gst_va_display_lock (self);
112   status = vaQueryImageFormats (dpy, va_formats, &num);
113   gst_va_display_unlock (self);
114 
115   gst_va_video_format_fix_map (va_formats, num);
116 
117   if (status != VA_STATUS_SUCCESS) {
118     GST_ERROR ("vaQueryImageFormats: %s", vaErrorStr (status));
119     goto bail;
120   }
121 
122   ret = g_array_sized_new (FALSE, FALSE, sizeof (GstVideoFormat), num);
123   for (i = 0; i < num; i++) {
124     format = gst_va_video_format_from_va_image_format (&va_formats[i]);
125     if (format != GST_VIDEO_FORMAT_UNKNOWN)
126       g_array_append_val (ret, format);
127   }
128 
129   if (ret->len == 0) {
130     g_array_unref (ret);
131     ret = NULL;
132   }
133 
134 bail:
135   g_free (va_formats);
136   return ret;
137 }
138 
139 gboolean
gst_va_display_has_vpp(GstVaDisplay * self)140 gst_va_display_has_vpp (GstVaDisplay * self)
141 {
142   VADisplay dpy;
143   VAEntrypoint *entrypoints;
144   VAStatus status;
145   int i, max, num;
146   gboolean found = FALSE;
147   g_return_val_if_fail (GST_IS_VA_DISPLAY (self), FALSE);
148 
149   dpy = gst_va_display_get_va_dpy (self);
150 
151   gst_va_display_lock (self);
152   max = vaMaxNumEntrypoints (dpy);
153   gst_va_display_unlock (self);
154 
155   entrypoints = g_new (VAEntrypoint, max);
156 
157   gst_va_display_lock (self);
158   status = vaQueryConfigEntrypoints (dpy, VAProfileNone, entrypoints, &num);
159   gst_va_display_unlock (self);
160   if (status != VA_STATUS_SUCCESS) {
161     GST_ERROR ("vaQueryImageFormats: %s", vaErrorStr (status));
162     goto bail;
163   }
164 
165   for (i = 0; i < num; i++) {
166     if (entrypoints[i] == VAEntrypointVideoProc) {
167       found = TRUE;
168       break;
169     }
170   }
171 
172 bail:
173   g_free (entrypoints);
174   return found;
175 }
176