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
;
98 if (pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_ENCODE
,
99 PIPE_VIDEO_CAP_SUPPORTED
))
100 entrypoint_list
[(*num_entrypoints
)++] = VAEntrypointEncSlice
;
103 if (num_entrypoints
== 0)
104 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
106 return VA_STATUS_SUCCESS
;
110 vlVaGetConfigAttributes(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
111 VAConfigAttrib
*attrib_list
, int num_attribs
)
116 return VA_STATUS_ERROR_INVALID_CONTEXT
;
118 for (i
= 0; i
< num_attribs
; ++i
) {
120 switch (attrib_list
[i
].type
) {
121 case VAConfigAttribRTFormat
:
122 value
= VA_RT_FORMAT_YUV420
;
124 case VAConfigAttribRateControl
:
128 value
= VA_ATTRIB_NOT_SUPPORTED
;
131 attrib_list
[i
].value
= value
;
134 return VA_STATUS_SUCCESS
;
138 vlVaCreateConfig(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
139 VAConfigAttrib
*attrib_list
, int num_attribs
, VAConfigID
*config_id
)
143 struct pipe_screen
*pscreen
;
144 enum pipe_video_profile p
;
147 return VA_STATUS_ERROR_INVALID_CONTEXT
;
149 drv
= VL_VA_DRIVER(ctx
);
152 return VA_STATUS_ERROR_INVALID_CONTEXT
;
154 config
= CALLOC(1, sizeof(vlVaConfig
));
156 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
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
;
167 p
= ProfileToPipe(profile
);
168 if (p
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
170 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
173 pscreen
= VL_VA_PSCREEN(ctx
);
175 switch (entrypoint
) {
176 case VAEntrypointVLD
:
177 if (!pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
178 PIPE_VIDEO_CAP_SUPPORTED
)) {
180 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
183 config
->entrypoint
= PIPE_VIDEO_ENTRYPOINT_BITSTREAM
;
187 case VAEntrypointEncSlice
:
188 if (!pscreen
->get_video_param(pscreen
, p
, PIPE_VIDEO_ENTRYPOINT_ENCODE
,
189 PIPE_VIDEO_CAP_SUPPORTED
)) {
191 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE
;
194 config
->entrypoint
= PIPE_VIDEO_ENTRYPOINT_ENCODE
;
200 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT
;
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
;
212 config
->rc
= PIPE_H264_ENC_RATE_CONTROL_METHOD_DISABLE
;
216 pipe_mutex_lock(drv
->mutex
);
217 *config_id
= handle_table_add(drv
->htab
, config
);
218 pipe_mutex_unlock(drv
->mutex
);
220 return VA_STATUS_SUCCESS
;
224 vlVaDestroyConfig(VADriverContextP ctx
, VAConfigID config_id
)
230 return VA_STATUS_ERROR_INVALID_CONTEXT
;
232 drv
= VL_VA_DRIVER(ctx
);
235 return VA_STATUS_ERROR_INVALID_CONTEXT
;
237 pipe_mutex_lock(drv
->mutex
);
238 config
= handle_table_get(drv
->htab
, config_id
);
241 return VA_STATUS_ERROR_INVALID_CONFIG
;
244 handle_table_remove(drv
->htab
, config_id
);
245 pipe_mutex_unlock(drv
->mutex
);
247 return VA_STATUS_SUCCESS
;
251 vlVaQueryConfigAttributes(VADriverContextP ctx
, VAConfigID config_id
, VAProfile
*profile
,
252 VAEntrypoint
*entrypoint
, VAConfigAttrib
*attrib_list
, int *num_attribs
)
258 return VA_STATUS_ERROR_INVALID_CONTEXT
;
260 drv
= VL_VA_DRIVER(ctx
);
263 return VA_STATUS_ERROR_INVALID_CONTEXT
;
265 pipe_mutex_lock(drv
->mutex
);
266 config
= handle_table_get(drv
->htab
, config_id
);
267 pipe_mutex_unlock(drv
->mutex
);
270 return VA_STATUS_ERROR_INVALID_CONFIG
;
272 *profile
= PipeToProfile(config
->profile
);
274 if (config
->profile
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
275 *entrypoint
= VAEntrypointVideoProc
;
277 return VA_STATUS_SUCCESS
;
280 *entrypoint
= config
->entrypoint
;
283 attrib_list
[0].type
= VAConfigAttribRTFormat
;
284 attrib_list
[0].value
= VA_RT_FORMAT_YUV420
;
286 return VA_STATUS_SUCCESS
;