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"
33 #include "vl/vl_winsys.h"
35 #include "va_private.h"
37 #include "util/u_handle_table.h"
39 DEBUG_GET_ONCE_BOOL_OPTION(mpeg4
, "VAAPI_MPEG4_ENABLED", false)
42 vlVaQueryConfigProfiles(VADriverContextP ctx
, VAProfile
*profile_list
, int *num_profiles
)
44 struct pipe_screen
*pscreen
;
45 enum pipe_video_profile p
;
49 return VA_STATUS_ERROR_INVALID_CONTEXT
;
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())
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
;
65 /* Support postprocessing through vl_compositor */
66 profile_list
[(*num_profiles
)++] = VAProfileNone
;
68 return VA_STATUS_SUCCESS
;
72 vlVaQueryConfigEntrypoints(VADriverContextP ctx
, VAProfile profile
,
73 VAEntrypoint
*entrypoint_list
, int *num_entrypoints
)
75 struct pipe_screen
*pscreen
;
76 enum pipe_video_profile p
;
79 return VA_STATUS_ERROR_INVALID_CONTEXT
;
83 if (profile
== VAProfileNone
) {
84 entrypoint_list
[(*num_entrypoints
)++] = VAEntrypointVideoProc
;
85 return VA_STATUS_SUCCESS
;
88 p
= ProfileToPipe(profile
);
89 if (p
== PIPE_VIDEO_PROFILE_UNKNOWN
)
90 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
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
;
97 if (pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_ENCODE
,
98 PIPE_VIDEO_CAP_SUPPORTED
))
99 entrypoint_list
[(*num_entrypoints
)++] = VAEntrypointEncSlice
;
101 if (num_entrypoints
== 0)
102 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
104 return VA_STATUS_SUCCESS
;
108 vlVaGetConfigAttributes(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
109 VAConfigAttrib
*attrib_list
, int num_attribs
)
114 return VA_STATUS_ERROR_INVALID_CONTEXT
;
116 for (i
= 0; i
< num_attribs
; ++i
) {
118 if (entrypoint
== VAEntrypointVLD
) {
119 switch (attrib_list
[i
].type
) {
120 case VAConfigAttribRTFormat
:
121 value
= VA_RT_FORMAT_YUV420
;
124 value
= VA_ATTRIB_NOT_SUPPORTED
;
127 } else if (entrypoint
== VAEntrypointEncSlice
) {
128 switch (attrib_list
[i
].type
) {
129 case VAConfigAttribRTFormat
:
130 value
= VA_RT_FORMAT_YUV420
;
132 case VAConfigAttribRateControl
:
133 value
= VA_RC_CQP
| VA_RC_CBR
| VA_RC_VBR
;
135 case VAConfigAttribEncPackedHeaders
:
138 case VAConfigAttribEncMaxRefFrames
:
142 value
= VA_ATTRIB_NOT_SUPPORTED
;
145 } else if (entrypoint
== VAEntrypointVideoProc
) {
146 switch (attrib_list
[i
].type
) {
147 case VAConfigAttribRTFormat
:
148 value
= (VA_RT_FORMAT_YUV420
|
152 value
= VA_ATTRIB_NOT_SUPPORTED
;
156 value
= VA_ATTRIB_NOT_SUPPORTED
;
158 attrib_list
[i
].value
= value
;
161 return VA_STATUS_SUCCESS
;
165 vlVaCreateConfig(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
166 VAConfigAttrib
*attrib_list
, int num_attribs
, VAConfigID
*config_id
)
170 struct pipe_screen
*pscreen
;
171 enum pipe_video_profile p
;
174 return VA_STATUS_ERROR_INVALID_CONTEXT
;
176 drv
= VL_VA_DRIVER(ctx
);
179 return VA_STATUS_ERROR_INVALID_CONTEXT
;
181 config
= CALLOC(1, sizeof(vlVaConfig
));
183 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
185 if (profile
== VAProfileNone
&& entrypoint
== VAEntrypointVideoProc
) {
186 config
->entrypoint
= VAEntrypointVideoProc
;
187 config
->profile
= PIPE_VIDEO_PROFILE_UNKNOWN
;
188 for (int i
= 0; i
< num_attribs
; i
++) {
189 if (attrib_list
[i
].type
== VAConfigAttribRTFormat
) {
190 if (attrib_list
[i
].value
& (VA_RT_FORMAT_YUV420
| VA_RT_FORMAT_RGB32
)) {
191 config
->rt_format
= attrib_list
[i
].value
;
194 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT
;
199 /* Default value if not specified in the input attributes. */
200 if (!config
->rt_format
)
201 config
->rt_format
= VA_RT_FORMAT_YUV420
| VA_RT_FORMAT_RGB32
;
203 pipe_mutex_lock(drv
->mutex
);
204 *config_id
= handle_table_add(drv
->htab
, config
);
205 pipe_mutex_unlock(drv
->mutex
);
206 return VA_STATUS_SUCCESS
;
209 p
= ProfileToPipe(profile
);
210 if (p
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
212 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
215 pscreen
= VL_VA_PSCREEN(ctx
);
217 switch (entrypoint
) {
218 case VAEntrypointVLD
:
219 if (!pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
220 PIPE_VIDEO_CAP_SUPPORTED
)) {
222 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
225 config
->entrypoint
= PIPE_VIDEO_ENTRYPOINT_BITSTREAM
;
228 case VAEntrypointEncSlice
:
229 if (!pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_ENCODE
,
230 PIPE_VIDEO_CAP_SUPPORTED
)) {
232 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
235 config
->entrypoint
= PIPE_VIDEO_ENTRYPOINT_ENCODE
;
240 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT
;
245 for (int i
= 0; i
<num_attribs
; i
++) {
246 if (attrib_list
[i
].type
== VAConfigAttribRateControl
) {
247 if (attrib_list
[i
].value
== VA_RC_CBR
)
248 config
->rc
= PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT
;
249 else if (attrib_list
[i
].value
== VA_RC_VBR
)
250 config
->rc
= PIPE_H264_ENC_RATE_CONTROL_METHOD_VARIABLE
;
252 config
->rc
= PIPE_H264_ENC_RATE_CONTROL_METHOD_DISABLE
;
254 if (attrib_list
[i
].type
== VAConfigAttribRTFormat
) {
255 if (attrib_list
[i
].value
== VA_RT_FORMAT_YUV420
) {
256 config
->rt_format
= attrib_list
[i
].value
;
259 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT
;
264 /* Default value if not specified in the input attributes. */
265 if (!config
->rt_format
)
266 config
->rt_format
= VA_RT_FORMAT_YUV420
;
268 pipe_mutex_lock(drv
->mutex
);
269 *config_id
= handle_table_add(drv
->htab
, config
);
270 pipe_mutex_unlock(drv
->mutex
);
272 return VA_STATUS_SUCCESS
;
276 vlVaDestroyConfig(VADriverContextP ctx
, VAConfigID config_id
)
282 return VA_STATUS_ERROR_INVALID_CONTEXT
;
284 drv
= VL_VA_DRIVER(ctx
);
287 return VA_STATUS_ERROR_INVALID_CONTEXT
;
289 pipe_mutex_lock(drv
->mutex
);
290 config
= handle_table_get(drv
->htab
, config_id
);
293 return VA_STATUS_ERROR_INVALID_CONFIG
;
296 handle_table_remove(drv
->htab
, config_id
);
297 pipe_mutex_unlock(drv
->mutex
);
299 return VA_STATUS_SUCCESS
;
303 vlVaQueryConfigAttributes(VADriverContextP ctx
, VAConfigID config_id
, VAProfile
*profile
,
304 VAEntrypoint
*entrypoint
, VAConfigAttrib
*attrib_list
, int *num_attribs
)
310 return VA_STATUS_ERROR_INVALID_CONTEXT
;
312 drv
= VL_VA_DRIVER(ctx
);
315 return VA_STATUS_ERROR_INVALID_CONTEXT
;
317 pipe_mutex_lock(drv
->mutex
);
318 config
= handle_table_get(drv
->htab
, config_id
);
319 pipe_mutex_unlock(drv
->mutex
);
322 return VA_STATUS_ERROR_INVALID_CONFIG
;
324 *profile
= PipeToProfile(config
->profile
);
326 if (config
->profile
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
327 *entrypoint
= VAEntrypointVideoProc
;
329 return VA_STATUS_SUCCESS
;
332 *entrypoint
= config
->entrypoint
;
335 attrib_list
[0].type
= VAConfigAttribRTFormat
;
336 attrib_list
[0].value
= config
->rt_format
;
338 return VA_STATUS_SUCCESS
;