1 /**************************************************************************
3 * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4 * Copyright 2014 Advanced Micro Devices, Inc.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
27 **************************************************************************/
29 #include "pipe/p_screen.h"
31 #include "util/u_video.h"
32 #include "util/u_memory.h"
34 #include "vl/vl_winsys.h"
36 #include "va_private.h"
38 #include "util/u_handle_table.h"
40 DEBUG_GET_ONCE_BOOL_OPTION(mpeg4
, "VAAPI_MPEG4_ENABLED", false)
43 vlVaQueryConfigProfiles(VADriverContextP ctx
, VAProfile
*profile_list
, int *num_profiles
)
45 struct pipe_screen
*pscreen
;
46 enum pipe_video_profile p
;
50 return VA_STATUS_ERROR_INVALID_CONTEXT
;
54 pscreen
= VL_VA_PSCREEN(ctx
);
55 for (p
= PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
; p
<= PIPE_VIDEO_PROFILE_VP9_PROFILE2
; ++p
) {
56 if (u_reduce_video_profile(p
) == PIPE_VIDEO_FORMAT_MPEG4
&& !debug_get_option_mpeg4())
59 if (pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
, PIPE_VIDEO_CAP_SUPPORTED
)) {
60 vap
= PipeToProfile(p
);
61 if (vap
!= VAProfileNone
)
62 profile_list
[(*num_profiles
)++] = vap
;
66 /* Support postprocessing through vl_compositor */
67 profile_list
[(*num_profiles
)++] = VAProfileNone
;
69 return VA_STATUS_SUCCESS
;
73 vlVaQueryConfigEntrypoints(VADriverContextP ctx
, VAProfile profile
,
74 VAEntrypoint
*entrypoint_list
, int *num_entrypoints
)
76 struct pipe_screen
*pscreen
;
77 enum pipe_video_profile p
;
80 return VA_STATUS_ERROR_INVALID_CONTEXT
;
84 if (profile
== VAProfileNone
) {
85 entrypoint_list
[(*num_entrypoints
)++] = VAEntrypointVideoProc
;
86 return VA_STATUS_SUCCESS
;
89 p
= ProfileToPipe(profile
);
90 if (p
== PIPE_VIDEO_PROFILE_UNKNOWN
)
91 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
93 pscreen
= VL_VA_PSCREEN(ctx
);
94 if (pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
95 PIPE_VIDEO_CAP_SUPPORTED
))
96 entrypoint_list
[(*num_entrypoints
)++] = VAEntrypointVLD
;
98 if (pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_ENCODE
,
99 PIPE_VIDEO_CAP_SUPPORTED
))
100 entrypoint_list
[(*num_entrypoints
)++] = VAEntrypointEncSlice
;
102 if (num_entrypoints
== 0)
103 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
105 assert(*num_entrypoints
<= ctx
->max_entrypoints
);
107 return VA_STATUS_SUCCESS
;
111 vlVaGetConfigAttributes(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
112 VAConfigAttrib
*attrib_list
, int num_attribs
)
114 struct pipe_screen
*pscreen
;
118 return VA_STATUS_ERROR_INVALID_CONTEXT
;
120 pscreen
= VL_VA_PSCREEN(ctx
);
122 for (i
= 0; i
< num_attribs
; ++i
) {
124 if (entrypoint
== VAEntrypointVLD
) {
125 switch (attrib_list
[i
].type
) {
126 case VAConfigAttribRTFormat
:
127 value
= VA_RT_FORMAT_YUV420
;
128 if (pscreen
->is_video_format_supported(pscreen
, PIPE_FORMAT_P016
,
129 ProfileToPipe(profile
),
130 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
))
131 value
|= VA_RT_FORMAT_YUV420_10BPP
;
134 value
= VA_ATTRIB_NOT_SUPPORTED
;
137 } else if (entrypoint
== VAEntrypointEncSlice
) {
138 switch (attrib_list
[i
].type
) {
139 case VAConfigAttribRTFormat
:
140 value
= VA_RT_FORMAT_YUV420
;
142 case VAConfigAttribRateControl
:
143 value
= VA_RC_CQP
| VA_RC_CBR
| VA_RC_VBR
;
145 case VAConfigAttribEncPackedHeaders
:
148 case VAConfigAttribEncMaxRefFrames
:
152 value
= VA_ATTRIB_NOT_SUPPORTED
;
155 } else if (entrypoint
== VAEntrypointVideoProc
) {
156 switch (attrib_list
[i
].type
) {
157 case VAConfigAttribRTFormat
:
158 value
= (VA_RT_FORMAT_YUV420
|
159 VA_RT_FORMAT_YUV420_10BPP
|
163 value
= VA_ATTRIB_NOT_SUPPORTED
;
167 value
= VA_ATTRIB_NOT_SUPPORTED
;
169 attrib_list
[i
].value
= value
;
172 return VA_STATUS_SUCCESS
;
176 vlVaCreateConfig(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
177 VAConfigAttrib
*attrib_list
, int num_attribs
, VAConfigID
*config_id
)
181 struct pipe_screen
*pscreen
;
182 enum pipe_video_profile p
;
183 unsigned int supported_rt_formats
;
186 return VA_STATUS_ERROR_INVALID_CONTEXT
;
188 drv
= VL_VA_DRIVER(ctx
);
191 return VA_STATUS_ERROR_INVALID_CONTEXT
;
193 config
= CALLOC(1, sizeof(vlVaConfig
));
195 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
197 if (profile
== VAProfileNone
&& entrypoint
== VAEntrypointVideoProc
) {
198 config
->entrypoint
= PIPE_VIDEO_ENTRYPOINT_UNKNOWN
;
199 config
->profile
= PIPE_VIDEO_PROFILE_UNKNOWN
;
200 supported_rt_formats
= VA_RT_FORMAT_YUV420
|
201 VA_RT_FORMAT_YUV420_10BPP
|
203 for (int i
= 0; i
< num_attribs
; i
++) {
204 if (attrib_list
[i
].type
== VAConfigAttribRTFormat
) {
205 if (attrib_list
[i
].value
& supported_rt_formats
) {
206 config
->rt_format
= attrib_list
[i
].value
;
209 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT
;
214 /* Default value if not specified in the input attributes. */
215 if (!config
->rt_format
)
216 config
->rt_format
= supported_rt_formats
;
218 mtx_lock(&drv
->mutex
);
219 *config_id
= handle_table_add(drv
->htab
, config
);
220 mtx_unlock(&drv
->mutex
);
221 return VA_STATUS_SUCCESS
;
224 p
= ProfileToPipe(profile
);
225 if (p
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
227 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
230 pscreen
= VL_VA_PSCREEN(ctx
);
232 switch (entrypoint
) {
233 case VAEntrypointVLD
:
234 if (!pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
235 PIPE_VIDEO_CAP_SUPPORTED
)) {
237 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
240 config
->entrypoint
= PIPE_VIDEO_ENTRYPOINT_BITSTREAM
;
243 case VAEntrypointEncSlice
:
244 if (!pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_ENCODE
,
245 PIPE_VIDEO_CAP_SUPPORTED
)) {
247 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
250 config
->entrypoint
= PIPE_VIDEO_ENTRYPOINT_ENCODE
;
255 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT
;
259 supported_rt_formats
= VA_RT_FORMAT_YUV420
;
260 if (pscreen
->is_video_format_supported(pscreen
, PIPE_FORMAT_P016
, p
,
262 supported_rt_formats
|= VA_RT_FORMAT_YUV420_10BPP
;
264 for (int i
= 0; i
<num_attribs
; i
++) {
265 if (attrib_list
[i
].type
== VAConfigAttribRateControl
) {
266 if (attrib_list
[i
].value
== VA_RC_CBR
)
267 config
->rc
= PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT
;
268 else if (attrib_list
[i
].value
== VA_RC_VBR
)
269 config
->rc
= PIPE_H264_ENC_RATE_CONTROL_METHOD_VARIABLE
;
271 config
->rc
= PIPE_H264_ENC_RATE_CONTROL_METHOD_DISABLE
;
273 if (attrib_list
[i
].type
== VAConfigAttribRTFormat
) {
274 if (attrib_list
[i
].value
& supported_rt_formats
) {
275 config
->rt_format
= attrib_list
[i
].value
;
278 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT
;
283 /* Default value if not specified in the input attributes. */
284 if (!config
->rt_format
)
285 config
->rt_format
= supported_rt_formats
;
287 mtx_lock(&drv
->mutex
);
288 *config_id
= handle_table_add(drv
->htab
, config
);
289 mtx_unlock(&drv
->mutex
);
291 return VA_STATUS_SUCCESS
;
295 vlVaDestroyConfig(VADriverContextP ctx
, VAConfigID config_id
)
301 return VA_STATUS_ERROR_INVALID_CONTEXT
;
303 drv
= VL_VA_DRIVER(ctx
);
306 return VA_STATUS_ERROR_INVALID_CONTEXT
;
308 mtx_lock(&drv
->mutex
);
309 config
= handle_table_get(drv
->htab
, config_id
);
312 mtx_unlock(&drv
->mutex
);
313 return VA_STATUS_ERROR_INVALID_CONFIG
;
317 handle_table_remove(drv
->htab
, config_id
);
318 mtx_unlock(&drv
->mutex
);
320 return VA_STATUS_SUCCESS
;
324 vlVaQueryConfigAttributes(VADriverContextP ctx
, VAConfigID config_id
, VAProfile
*profile
,
325 VAEntrypoint
*entrypoint
, VAConfigAttrib
*attrib_list
, int *num_attribs
)
331 return VA_STATUS_ERROR_INVALID_CONTEXT
;
333 drv
= VL_VA_DRIVER(ctx
);
336 return VA_STATUS_ERROR_INVALID_CONTEXT
;
338 mtx_lock(&drv
->mutex
);
339 config
= handle_table_get(drv
->htab
, config_id
);
340 mtx_unlock(&drv
->mutex
);
343 return VA_STATUS_ERROR_INVALID_CONFIG
;
345 *profile
= PipeToProfile(config
->profile
);
347 switch (config
->entrypoint
) {
348 case PIPE_VIDEO_ENTRYPOINT_BITSTREAM
:
349 *entrypoint
= VAEntrypointVLD
;
351 case PIPE_VIDEO_ENTRYPOINT_ENCODE
:
352 *entrypoint
= VAEntrypointEncSlice
;
354 case PIPE_VIDEO_ENTRYPOINT_UNKNOWN
:
355 *entrypoint
= VAEntrypointVideoProc
;
358 return VA_STATUS_ERROR_INVALID_CONFIG
;
362 attrib_list
[0].type
= VAConfigAttribRTFormat
;
363 attrib_list
[0].value
= config
->rt_format
;
365 return VA_STATUS_SUCCESS
;