st/va: add function to handle misc param type frame rate
[mesa.git] / src / gallium / state_trackers / va / config.c
1 /**************************************************************************
2 *
3 * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4 * Copyright 2014 Advanced Micro Devices, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 #include "pipe/p_screen.h"
30
31 #include "util/u_video.h"
32
33 #include "vl/vl_winsys.h"
34
35 #include "va_private.h"
36
37 #include "util/u_handle_table.h"
38
39 DEBUG_GET_ONCE_BOOL_OPTION(mpeg4, "VAAPI_MPEG4_ENABLED", false)
40
41 VAStatus
42 vlVaQueryConfigProfiles(VADriverContextP ctx, VAProfile *profile_list, int *num_profiles)
43 {
44 struct pipe_screen *pscreen;
45 enum pipe_video_profile p;
46 VAProfile vap;
47
48 if (!ctx)
49 return VA_STATUS_ERROR_INVALID_CONTEXT;
50
51 *num_profiles = 0;
52
53 pscreen = VL_VA_PSCREEN(ctx);
54 for (p = PIPE_VIDEO_PROFILE_MPEG2_SIMPLE; p <= PIPE_VIDEO_PROFILE_HEVC_MAIN_444; ++p) {
55 if (u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 && !debug_get_option_mpeg4())
56 continue;
57
58 if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED)) {
59 vap = PipeToProfile(p);
60 if (vap != VAProfileNone)
61 profile_list[(*num_profiles)++] = vap;
62 }
63 }
64
65 /* Support postprocessing through vl_compositor */
66 profile_list[(*num_profiles)++] = VAProfileNone;
67
68 return VA_STATUS_SUCCESS;
69 }
70
71 VAStatus
72 vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile,
73 VAEntrypoint *entrypoint_list, int *num_entrypoints)
74 {
75 struct pipe_screen *pscreen;
76 enum pipe_video_profile p;
77
78 if (!ctx)
79 return VA_STATUS_ERROR_INVALID_CONTEXT;
80
81 *num_entrypoints = 0;
82
83 if (profile == VAProfileNone) {
84 entrypoint_list[(*num_entrypoints)++] = VAEntrypointVideoProc;
85 return VA_STATUS_SUCCESS;
86 }
87
88 p = ProfileToPipe(profile);
89 if (p == PIPE_VIDEO_PROFILE_UNKNOWN)
90 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
91
92 pscreen = VL_VA_PSCREEN(ctx);
93 if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
94 PIPE_VIDEO_CAP_SUPPORTED))
95 entrypoint_list[(*num_entrypoints)++] = VAEntrypointVLD;
96
97 #if 0
98 if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE,
99 PIPE_VIDEO_CAP_SUPPORTED))
100 entrypoint_list[(*num_entrypoints)++] = VAEntrypointEncSlice;
101 #endif
102
103 if (num_entrypoints == 0)
104 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
105
106 return VA_STATUS_SUCCESS;
107 }
108
109 VAStatus
110 vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
111 VAConfigAttrib *attrib_list, int num_attribs)
112 {
113 int i;
114
115 if (!ctx)
116 return VA_STATUS_ERROR_INVALID_CONTEXT;
117
118 for (i = 0; i < num_attribs; ++i) {
119 unsigned int value;
120 switch (attrib_list[i].type) {
121 case VAConfigAttribRTFormat:
122 value = VA_RT_FORMAT_YUV420;
123 break;
124 case VAConfigAttribRateControl:
125 value = VA_RC_NONE;
126 break;
127 default:
128 value = VA_ATTRIB_NOT_SUPPORTED;
129 break;
130 }
131 attrib_list[i].value = value;
132 }
133
134 return VA_STATUS_SUCCESS;
135 }
136
137 VAStatus
138 vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
139 VAConfigAttrib *attrib_list, int num_attribs, VAConfigID *config_id)
140 {
141 vlVaDriver *drv;
142 vlVaConfig *config;
143 struct pipe_screen *pscreen;
144 enum pipe_video_profile p;
145
146 if (!ctx)
147 return VA_STATUS_ERROR_INVALID_CONTEXT;
148
149 drv = VL_VA_DRIVER(ctx);
150
151 if (!drv)
152 return VA_STATUS_ERROR_INVALID_CONTEXT;
153
154 config = CALLOC(1, sizeof(vlVaConfig));
155 if (!config)
156 return VA_STATUS_ERROR_ALLOCATION_FAILED;
157
158 if (profile == VAProfileNone && entrypoint == VAEntrypointVideoProc) {
159 config->entrypoint = VAEntrypointVideoProc;
160 config->profile = PIPE_VIDEO_PROFILE_UNKNOWN;
161 pipe_mutex_lock(drv->mutex);
162 *config_id = handle_table_add(drv->htab, config);
163 pipe_mutex_unlock(drv->mutex);
164 return VA_STATUS_SUCCESS;
165 }
166
167 p = ProfileToPipe(profile);
168 if (p == PIPE_VIDEO_PROFILE_UNKNOWN) {
169 FREE(config);
170 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
171 }
172
173 pscreen = VL_VA_PSCREEN(ctx);
174
175 switch (entrypoint) {
176 case VAEntrypointVLD:
177 if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
178 PIPE_VIDEO_CAP_SUPPORTED)) {
179 FREE(config);
180 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
181 }
182
183 config->entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM;
184 break;
185
186 #if 0
187 case VAEntrypointEncSlice:
188 if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE,
189 PIPE_VIDEO_CAP_SUPPORTED)) {
190 FREE(config);
191 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
192 }
193
194 config->entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE;
195 break;
196 #endif
197
198 default:
199 FREE(config);
200 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
201 }
202
203 config->profile = p;
204
205 for (int i = 0; i <num_attribs ; i++) {
206 if (attrib_list[i].type == VAConfigAttribRateControl) {
207 if (attrib_list[i].value == VA_RC_CBR)
208 config->rc = PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT;
209 else if (attrib_list[i].value == VA_RC_VBR)
210 config->rc = PIPE_H264_ENC_RATE_CONTROL_METHOD_VARIABLE;
211 else
212 config->rc = PIPE_H264_ENC_RATE_CONTROL_METHOD_DISABLE;
213 }
214 }
215
216 pipe_mutex_lock(drv->mutex);
217 *config_id = handle_table_add(drv->htab, config);
218 pipe_mutex_unlock(drv->mutex);
219
220 return VA_STATUS_SUCCESS;
221 }
222
223 VAStatus
224 vlVaDestroyConfig(VADriverContextP ctx, VAConfigID config_id)
225 {
226 vlVaDriver *drv;
227 vlVaConfig *config;
228
229 if (!ctx)
230 return VA_STATUS_ERROR_INVALID_CONTEXT;
231
232 drv = VL_VA_DRIVER(ctx);
233
234 if (!drv)
235 return VA_STATUS_ERROR_INVALID_CONTEXT;
236
237 pipe_mutex_lock(drv->mutex);
238 config = handle_table_get(drv->htab, config_id);
239
240 if (!config)
241 return VA_STATUS_ERROR_INVALID_CONFIG;
242
243 FREE(config);
244 handle_table_remove(drv->htab, config_id);
245 pipe_mutex_unlock(drv->mutex);
246
247 return VA_STATUS_SUCCESS;
248 }
249
250 VAStatus
251 vlVaQueryConfigAttributes(VADriverContextP ctx, VAConfigID config_id, VAProfile *profile,
252 VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, int *num_attribs)
253 {
254 vlVaDriver *drv;
255 vlVaConfig *config;
256
257 if (!ctx)
258 return VA_STATUS_ERROR_INVALID_CONTEXT;
259
260 drv = VL_VA_DRIVER(ctx);
261
262 if (!drv)
263 return VA_STATUS_ERROR_INVALID_CONTEXT;
264
265 pipe_mutex_lock(drv->mutex);
266 config = handle_table_get(drv->htab, config_id);
267 pipe_mutex_unlock(drv->mutex);
268
269 if (!config)
270 return VA_STATUS_ERROR_INVALID_CONFIG;
271
272 *profile = PipeToProfile(config->profile);
273
274 if (config->profile == PIPE_VIDEO_PROFILE_UNKNOWN) {
275 *entrypoint = VAEntrypointVideoProc;
276 *num_attribs = 0;
277 return VA_STATUS_SUCCESS;
278 }
279
280 *entrypoint = config->entrypoint;
281
282 *num_attribs = 1;
283 attrib_list[0].type = VAConfigAttribRTFormat;
284 attrib_list[0].value = VA_RT_FORMAT_YUV420;
285
286 return VA_STATUS_SUCCESS;
287 }