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_HEVC_MAIN_444
; ++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 return VA_STATUS_SUCCESS
;
109 vlVaGetConfigAttributes(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
110 VAConfigAttrib
*attrib_list
, int num_attribs
)
112 struct pipe_screen
*pscreen
;
116 return VA_STATUS_ERROR_INVALID_CONTEXT
;
118 pscreen
= VL_VA_PSCREEN(ctx
);
120 for (i
= 0; i
< num_attribs
; ++i
) {
122 if (entrypoint
== VAEntrypointVLD
) {
123 switch (attrib_list
[i
].type
) {
124 case VAConfigAttribRTFormat
:
125 value
= VA_RT_FORMAT_YUV420
;
126 if (pscreen
->is_video_format_supported(pscreen
, PIPE_FORMAT_P016
,
127 ProfileToPipe(profile
),
128 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
))
129 value
|= VA_RT_FORMAT_YUV420_10BPP
;
132 value
= VA_ATTRIB_NOT_SUPPORTED
;
135 } else if (entrypoint
== VAEntrypointEncSlice
) {
136 switch (attrib_list
[i
].type
) {
137 case VAConfigAttribRTFormat
:
138 value
= VA_RT_FORMAT_YUV420
;
140 case VAConfigAttribRateControl
:
141 value
= VA_RC_CQP
| VA_RC_CBR
| VA_RC_VBR
;
143 case VAConfigAttribEncPackedHeaders
:
146 case VAConfigAttribEncMaxRefFrames
:
150 value
= VA_ATTRIB_NOT_SUPPORTED
;
153 } else if (entrypoint
== VAEntrypointVideoProc
) {
154 switch (attrib_list
[i
].type
) {
155 case VAConfigAttribRTFormat
:
156 value
= (VA_RT_FORMAT_YUV420
|
157 VA_RT_FORMAT_YUV420_10BPP
|
161 value
= VA_ATTRIB_NOT_SUPPORTED
;
165 value
= VA_ATTRIB_NOT_SUPPORTED
;
167 attrib_list
[i
].value
= value
;
170 return VA_STATUS_SUCCESS
;
174 vlVaCreateConfig(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
175 VAConfigAttrib
*attrib_list
, int num_attribs
, VAConfigID
*config_id
)
179 struct pipe_screen
*pscreen
;
180 enum pipe_video_profile p
;
181 unsigned int supported_rt_formats
;
184 return VA_STATUS_ERROR_INVALID_CONTEXT
;
186 drv
= VL_VA_DRIVER(ctx
);
189 return VA_STATUS_ERROR_INVALID_CONTEXT
;
191 config
= CALLOC(1, sizeof(vlVaConfig
));
193 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
195 if (profile
== VAProfileNone
&& entrypoint
== VAEntrypointVideoProc
) {
196 config
->entrypoint
= VAEntrypointVideoProc
;
197 config
->profile
= PIPE_VIDEO_PROFILE_UNKNOWN
;
198 supported_rt_formats
= VA_RT_FORMAT_YUV420
|
199 VA_RT_FORMAT_YUV420_10BPP
|
201 for (int i
= 0; i
< num_attribs
; i
++) {
202 if (attrib_list
[i
].type
== VAConfigAttribRTFormat
) {
203 if (attrib_list
[i
].value
& supported_rt_formats
) {
204 config
->rt_format
= attrib_list
[i
].value
;
207 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT
;
212 /* Default value if not specified in the input attributes. */
213 if (!config
->rt_format
)
214 config
->rt_format
= supported_rt_formats
;
216 mtx_lock(&drv
->mutex
);
217 *config_id
= handle_table_add(drv
->htab
, config
);
218 mtx_unlock(&drv
->mutex
);
219 return VA_STATUS_SUCCESS
;
222 p
= ProfileToPipe(profile
);
223 if (p
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
225 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
228 pscreen
= VL_VA_PSCREEN(ctx
);
230 switch (entrypoint
) {
231 case VAEntrypointVLD
:
232 if (!pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
233 PIPE_VIDEO_CAP_SUPPORTED
)) {
235 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
238 config
->entrypoint
= PIPE_VIDEO_ENTRYPOINT_BITSTREAM
;
241 case VAEntrypointEncSlice
:
242 if (!pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_ENCODE
,
243 PIPE_VIDEO_CAP_SUPPORTED
)) {
245 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
248 config
->entrypoint
= PIPE_VIDEO_ENTRYPOINT_ENCODE
;
253 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT
;
257 supported_rt_formats
= VA_RT_FORMAT_YUV420
;
258 if (pscreen
->is_video_format_supported(pscreen
, PIPE_FORMAT_P016
, p
,
260 supported_rt_formats
|= VA_RT_FORMAT_YUV420_10BPP
;
262 for (int i
= 0; i
<num_attribs
; i
++) {
263 if (attrib_list
[i
].type
== VAConfigAttribRateControl
) {
264 if (attrib_list
[i
].value
== VA_RC_CBR
)
265 config
->rc
= PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT
;
266 else if (attrib_list
[i
].value
== VA_RC_VBR
)
267 config
->rc
= PIPE_H264_ENC_RATE_CONTROL_METHOD_VARIABLE
;
269 config
->rc
= PIPE_H264_ENC_RATE_CONTROL_METHOD_DISABLE
;
271 if (attrib_list
[i
].type
== VAConfigAttribRTFormat
) {
272 if (attrib_list
[i
].value
& supported_rt_formats
) {
273 config
->rt_format
= attrib_list
[i
].value
;
276 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT
;
281 /* Default value if not specified in the input attributes. */
282 if (!config
->rt_format
)
283 config
->rt_format
= supported_rt_formats
;
285 mtx_lock(&drv
->mutex
);
286 *config_id
= handle_table_add(drv
->htab
, config
);
287 mtx_unlock(&drv
->mutex
);
289 return VA_STATUS_SUCCESS
;
293 vlVaDestroyConfig(VADriverContextP ctx
, VAConfigID config_id
)
299 return VA_STATUS_ERROR_INVALID_CONTEXT
;
301 drv
= VL_VA_DRIVER(ctx
);
304 return VA_STATUS_ERROR_INVALID_CONTEXT
;
306 mtx_lock(&drv
->mutex
);
307 config
= handle_table_get(drv
->htab
, config_id
);
310 return VA_STATUS_ERROR_INVALID_CONFIG
;
313 handle_table_remove(drv
->htab
, config_id
);
314 mtx_unlock(&drv
->mutex
);
316 return VA_STATUS_SUCCESS
;
320 vlVaQueryConfigAttributes(VADriverContextP ctx
, VAConfigID config_id
, VAProfile
*profile
,
321 VAEntrypoint
*entrypoint
, VAConfigAttrib
*attrib_list
, int *num_attribs
)
327 return VA_STATUS_ERROR_INVALID_CONTEXT
;
329 drv
= VL_VA_DRIVER(ctx
);
332 return VA_STATUS_ERROR_INVALID_CONTEXT
;
334 mtx_lock(&drv
->mutex
);
335 config
= handle_table_get(drv
->htab
, config_id
);
336 mtx_unlock(&drv
->mutex
);
339 return VA_STATUS_ERROR_INVALID_CONFIG
;
341 *profile
= PipeToProfile(config
->profile
);
343 if (config
->profile
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
344 *entrypoint
= VAEntrypointVideoProc
;
346 return VA_STATUS_SUCCESS
;
349 *entrypoint
= config
->entrypoint
;
352 attrib_list
[0].type
= VAConfigAttribRTFormat
;
353 attrib_list
[0].value
= config
->rt_format
;
355 return VA_STATUS_SUCCESS
;