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 **************************************************************************/
35 #include <va/va_backend.h>
36 #include <va/va_backend_vpp.h>
37 #include <va/va_drmcommon.h>
39 #include "pipe/p_video_enums.h"
40 #include "pipe/p_video_codec.h"
41 #include "pipe/p_video_state.h"
43 #include "vl/vl_compositor.h"
44 #include "vl/vl_csc.h"
46 #include "util/u_dynarray.h"
48 #define VL_VA_DRIVER(ctx) ((vlVaDriver *)ctx->pDriverData)
49 #define VL_VA_PSCREEN(ctx) (VL_VA_DRIVER(ctx)->vscreen->pscreen)
51 #define VL_VA_MAX_IMAGE_FORMATS 9
53 static inline enum pipe_video_chroma_format
54 ChromaToPipe(int format
)
57 case VA_RT_FORMAT_YUV420
:
58 return PIPE_VIDEO_CHROMA_FORMAT_420
;
59 case VA_RT_FORMAT_YUV422
:
60 return PIPE_VIDEO_CHROMA_FORMAT_422
;
61 case VA_RT_FORMAT_YUV444
:
62 return PIPE_VIDEO_CHROMA_FORMAT_444
;
64 return PIPE_VIDEO_CHROMA_FORMAT_NONE
;
68 static inline enum pipe_format
69 VaFourccToPipeFormat(unsigned format
)
72 case VA_FOURCC('N','V','1','2'):
73 return PIPE_FORMAT_NV12
;
74 case VA_FOURCC('I','4','2','0'):
75 return PIPE_FORMAT_IYUV
;
76 case VA_FOURCC('Y','V','1','2'):
77 return PIPE_FORMAT_YV12
;
78 case VA_FOURCC('Y','U','Y','V'):
79 return PIPE_FORMAT_YUYV
;
80 case VA_FOURCC('U','Y','V','Y'):
81 return PIPE_FORMAT_UYVY
;
82 case VA_FOURCC('B','G','R','A'):
83 return PIPE_FORMAT_B8G8R8A8_UNORM
;
84 case VA_FOURCC('R','G','B','A'):
85 return PIPE_FORMAT_R8G8B8A8_UNORM
;
86 case VA_FOURCC('B','G','R','X'):
87 return PIPE_FORMAT_B8G8R8X8_UNORM
;
88 case VA_FOURCC('R','G','B','X'):
89 return PIPE_FORMAT_R8G8B8X8_UNORM
;
92 return PIPE_FORMAT_NONE
;
96 static inline unsigned
97 PipeFormatToVaFourcc(enum pipe_format p_format
)
100 case PIPE_FORMAT_NV12
:
101 return VA_FOURCC('N','V','1','2');
102 case PIPE_FORMAT_IYUV
:
103 return VA_FOURCC('I','4','2','0');
104 case PIPE_FORMAT_YV12
:
105 return VA_FOURCC('Y','V','1','2');
106 case PIPE_FORMAT_UYVY
:
107 return VA_FOURCC('U','Y','V','Y');
108 case PIPE_FORMAT_YUYV
:
109 return VA_FOURCC('Y','U','Y','V');
110 case PIPE_FORMAT_B8G8R8A8_UNORM
:
111 return VA_FOURCC('B','G','R','A');
112 case PIPE_FORMAT_R8G8B8A8_UNORM
:
113 return VA_FOURCC('R','G','B','A');
114 case PIPE_FORMAT_B8G8R8X8_UNORM
:
115 return VA_FOURCC('B','G','R','X');
116 case PIPE_FORMAT_R8G8B8X8_UNORM
:
117 return VA_FOURCC('R','G','B','X');
124 static inline VAProfile
125 PipeToProfile(enum pipe_video_profile profile
)
128 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
:
129 return VAProfileMPEG2Simple
;
130 case PIPE_VIDEO_PROFILE_MPEG2_MAIN
:
131 return VAProfileMPEG2Main
;
132 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
:
133 return VAProfileMPEG4Simple
;
134 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
:
135 return VAProfileMPEG4AdvancedSimple
;
136 case PIPE_VIDEO_PROFILE_VC1_SIMPLE
:
137 return VAProfileVC1Simple
;
138 case PIPE_VIDEO_PROFILE_VC1_MAIN
:
139 return VAProfileVC1Main
;
140 case PIPE_VIDEO_PROFILE_VC1_ADVANCED
:
141 return VAProfileVC1Advanced
;
142 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
:
143 return VAProfileH264Baseline
;
144 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
:
145 return VAProfileH264Main
;
146 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
:
147 return VAProfileH264High
;
148 case PIPE_VIDEO_PROFILE_HEVC_MAIN
:
149 return VAProfileHEVCMain
;
150 case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED
:
151 case PIPE_VIDEO_PROFILE_UNKNOWN
:
152 return VAProfileNone
;
159 static inline enum pipe_video_profile
160 ProfileToPipe(VAProfile profile
)
163 case VAProfileMPEG2Simple
:
164 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
;
165 case VAProfileMPEG2Main
:
166 return PIPE_VIDEO_PROFILE_MPEG2_MAIN
;
167 case VAProfileMPEG4Simple
:
168 return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
;
169 case VAProfileMPEG4AdvancedSimple
:
170 return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
;
171 case VAProfileVC1Simple
:
172 return PIPE_VIDEO_PROFILE_VC1_SIMPLE
;
173 case VAProfileVC1Main
:
174 return PIPE_VIDEO_PROFILE_VC1_MAIN
;
175 case VAProfileVC1Advanced
:
176 return PIPE_VIDEO_PROFILE_VC1_ADVANCED
;
177 case VAProfileH264Baseline
:
178 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
;
179 case VAProfileH264Main
:
180 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
;
181 case VAProfileH264High
:
182 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
;
183 case VAProfileHEVCMain
:
184 return PIPE_VIDEO_PROFILE_HEVC_MAIN
;
186 return PIPE_VIDEO_PROFILE_UNKNOWN
;
188 return PIPE_VIDEO_PROFILE_UNKNOWN
;
193 struct vl_screen
*vscreen
;
194 struct pipe_context
*pipe
;
195 struct handle_table
*htab
;
196 struct vl_compositor compositor
;
197 struct vl_compositor_state cstate
;
204 struct u_rect src_rect
;
205 struct u_rect dst_rect
;
207 struct pipe_sampler_view
*sampler
;
211 struct pipe_video_codec
*decoder
;
212 struct pipe_video_buffer
*target
;
214 struct pipe_picture_desc base
;
215 struct pipe_mpeg12_picture_desc mpeg12
;
216 struct pipe_mpeg4_picture_desc mpeg4
;
217 struct pipe_vc1_picture_desc vc1
;
218 struct pipe_h264_picture_desc h264
;
219 struct pipe_h265_picture_desc h265
;
223 unsigned long long int frame_num
;
224 unsigned int start_code_size
;
225 unsigned int vti_bits
;
226 unsigned int quant_scale
;
227 VAPictureParameterBufferMPEG4 pps
;
228 uint8_t start_code
[32];
235 unsigned int num_elements
;
238 struct pipe_resource
*resource
;
239 struct pipe_transfer
*transfer
;
240 struct pipe_fence_handle
*fence
;
242 unsigned int export_refcount
;
243 VABufferInfo export_state
;
247 struct pipe_video_buffer templat
, *buffer
;
248 struct pipe_fence_handle
*fence
;
249 struct util_dynarray subpics
; /* vlVaSubpicture */
253 VAStatus
VA_DRIVER_INIT_FUNC(VADriverContextP ctx
);
256 VAStatus
vlVaTerminate(VADriverContextP ctx
);
257 VAStatus
vlVaQueryConfigProfiles(VADriverContextP ctx
, VAProfile
*profile_list
,int *num_profiles
);
258 VAStatus
vlVaQueryConfigEntrypoints(VADriverContextP ctx
, VAProfile profile
,
259 VAEntrypoint
*entrypoint_list
, int *num_entrypoints
);
260 VAStatus
vlVaGetConfigAttributes(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
261 VAConfigAttrib
*attrib_list
, int num_attribs
);
262 VAStatus
vlVaCreateConfig(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
263 VAConfigAttrib
*attrib_list
, int num_attribs
, VAConfigID
*config_id
);
264 VAStatus
vlVaDestroyConfig(VADriverContextP ctx
, VAConfigID config_id
);
265 VAStatus
vlVaQueryConfigAttributes(VADriverContextP ctx
, VAConfigID config_id
, VAProfile
*profile
,
266 VAEntrypoint
*entrypoint
, VAConfigAttrib
*attrib_list
, int *num_attribs
);
267 VAStatus
vlVaCreateSurfaces(VADriverContextP ctx
, int width
, int height
, int format
,
268 int num_surfaces
, VASurfaceID
*surfaces
);
269 VAStatus
vlVaDestroySurfaces(VADriverContextP ctx
, VASurfaceID
*surface_list
, int num_surfaces
);
270 VAStatus
vlVaCreateContext(VADriverContextP ctx
, VAConfigID config_id
, int picture_width
, int picture_height
,
271 int flag
, VASurfaceID
*render_targets
, int num_render_targets
, VAContextID
*context
);
272 VAStatus
vlVaDestroyContext(VADriverContextP ctx
, VAContextID context
);
273 VAStatus
vlVaCreateBuffer(VADriverContextP ctx
, VAContextID context
, VABufferType type
, unsigned int size
,
274 unsigned int num_elements
, void *data
, VABufferID
*buf_id
);
275 VAStatus
vlVaBufferSetNumElements(VADriverContextP ctx
, VABufferID buf_id
, unsigned int num_elements
);
276 VAStatus
vlVaMapBuffer(VADriverContextP ctx
, VABufferID buf_id
, void **pbuf
);
277 VAStatus
vlVaUnmapBuffer(VADriverContextP ctx
, VABufferID buf_id
);
278 VAStatus
vlVaDestroyBuffer(VADriverContextP ctx
, VABufferID buffer_id
);
279 VAStatus
vlVaBeginPicture(VADriverContextP ctx
, VAContextID context
, VASurfaceID render_target
);
280 VAStatus
vlVaRenderPicture(VADriverContextP ctx
, VAContextID context
, VABufferID
*buffers
, int num_buffers
);
281 VAStatus
vlVaEndPicture(VADriverContextP ctx
, VAContextID context
);
282 VAStatus
vlVaSyncSurface(VADriverContextP ctx
, VASurfaceID render_target
);
283 VAStatus
vlVaQuerySurfaceStatus(VADriverContextP ctx
, VASurfaceID render_target
, VASurfaceStatus
*status
);
284 VAStatus
vlVaQuerySurfaceError(VADriverContextP ctx
, VASurfaceID render_target
,
285 VAStatus error_status
, void **error_info
);
286 VAStatus
vlVaPutSurface(VADriverContextP ctx
, VASurfaceID surface
, void* draw
, short srcx
, short srcy
,
287 unsigned short srcw
, unsigned short srch
, short destx
, short desty
, unsigned short destw
,
288 unsigned short desth
, VARectangle
*cliprects
, unsigned int number_cliprects
,
290 VAStatus
vlVaQueryImageFormats(VADriverContextP ctx
, VAImageFormat
*format_list
, int *num_formats
);
291 VAStatus
vlVaQuerySubpictureFormats(VADriverContextP ctx
, VAImageFormat
*format_list
,
292 unsigned int *flags
, unsigned int *num_formats
);
293 VAStatus
vlVaCreateImage(VADriverContextP ctx
, VAImageFormat
*format
, int width
, int height
, VAImage
*image
);
294 VAStatus
vlVaDeriveImage(VADriverContextP ctx
, VASurfaceID surface
, VAImage
*image
);
295 VAStatus
vlVaDestroyImage(VADriverContextP ctx
, VAImageID image
);
296 VAStatus
vlVaSetImagePalette(VADriverContextP ctx
, VAImageID image
, unsigned char *palette
);
297 VAStatus
vlVaGetImage(VADriverContextP ctx
, VASurfaceID surface
, int x
, int y
,
298 unsigned int width
, unsigned int height
, VAImageID image
);
299 VAStatus
vlVaPutImage(VADriverContextP ctx
, VASurfaceID surface
, VAImageID image
, int src_x
, int src_y
,
300 unsigned int src_width
, unsigned int src_height
, int dest_x
, int dest_y
,
301 unsigned int dest_width
, unsigned int dest_height
);
302 VAStatus
vlVaQuerySubpictureFormats(VADriverContextP ctx
, VAImageFormat
*format_list
,
303 unsigned int *flags
, unsigned int *num_formats
);
304 VAStatus
vlVaCreateSubpicture(VADriverContextP ctx
, VAImageID image
, VASubpictureID
*subpicture
);
305 VAStatus
vlVaDestroySubpicture(VADriverContextP ctx
, VASubpictureID subpicture
);
306 VAStatus
vlVaSubpictureImage(VADriverContextP ctx
, VASubpictureID subpicture
, VAImageID image
);
307 VAStatus
vlVaSetSubpictureChromakey(VADriverContextP ctx
, VASubpictureID subpicture
,
308 unsigned int chromakey_min
, unsigned int chromakey_max
,
309 unsigned int chromakey_mask
);
310 VAStatus
vlVaSetSubpictureGlobalAlpha(VADriverContextP ctx
, VASubpictureID subpicture
, float global_alpha
);
311 VAStatus
vlVaAssociateSubpicture(VADriverContextP ctx
, VASubpictureID subpicture
, VASurfaceID
*target_surfaces
,
312 int num_surfaces
, short src_x
, short src_y
,
313 unsigned short src_width
, unsigned short src_height
,
314 short dest_x
, short dest_y
, unsigned short dest_width
, unsigned short dest_height
,
316 VAStatus
vlVaDeassociateSubpicture(VADriverContextP ctx
, VASubpictureID subpicture
,
317 VASurfaceID
*target_surfaces
, int num_surfaces
);
318 VAStatus
vlVaQueryDisplayAttributes(VADriverContextP ctx
, VADisplayAttribute
*attr_list
, int *num_attributes
);
319 VAStatus
vlVaGetDisplayAttributes(VADriverContextP ctx
, VADisplayAttribute
*attr_list
, int num_attributes
);
320 VAStatus
vlVaSetDisplayAttributes(VADriverContextP ctx
, VADisplayAttribute
*attr_list
, int num_attributes
);
321 VAStatus
vlVaBufferInfo(VADriverContextP ctx
, VABufferID buf_id
, VABufferType
*type
,
322 unsigned int *size
, unsigned int *num_elements
);
323 VAStatus
vlVaLockSurface(VADriverContextP ctx
, VASurfaceID surface
, unsigned int *fourcc
,
324 unsigned int *luma_stride
, unsigned int *chroma_u_stride
, unsigned int *chroma_v_stride
,
325 unsigned int *luma_offset
, unsigned int *chroma_u_offset
, unsigned int *chroma_v_offset
,
326 unsigned int *buffer_name
, void **buffer
);
327 VAStatus
vlVaUnlockSurface(VADriverContextP ctx
, VASurfaceID surface
);
328 VAStatus
vlVaCreateSurfaces2(VADriverContextP ctx
, unsigned int format
, unsigned int width
, unsigned int height
,
329 VASurfaceID
*surfaces
, unsigned int num_surfaces
, VASurfaceAttrib
*attrib_list
,
330 unsigned int num_attribs
);
331 VAStatus
vlVaQuerySurfaceAttributes(VADriverContextP ctx
, VAConfigID config
, VASurfaceAttrib
*attrib_list
,
332 unsigned int *num_attribs
);
334 VAStatus
vlVaAcquireBufferHandle(VADriverContextP ctx
, VABufferID buf_id
, VABufferInfo
*out_buf_info
);
335 VAStatus
vlVaReleaseBufferHandle(VADriverContextP ctx
, VABufferID buf_id
);
337 VAStatus
vlVaQueryVideoProcFilters(VADriverContextP ctx
, VAContextID context
, VAProcFilterType
*filters
,
338 unsigned int *num_filters
);
339 VAStatus
vlVaQueryVideoProcFilterCaps(VADriverContextP ctx
, VAContextID context
, VAProcFilterType type
,
340 void *filter_caps
, unsigned int *num_filter_caps
);
341 VAStatus
vlVaQueryVideoProcPipelineCaps(VADriverContextP ctx
, VAContextID context
, VABufferID
*filters
,
342 unsigned int num_filters
, VAProcPipelineCaps
*pipeline_cap
);
344 // internal functions
345 VAStatus
vlVaHandleVAProcPipelineParameterBufferType(vlVaDriver
*drv
, vlVaContext
*context
, vlVaBuffer
*buf
);
347 #endif //VA_PRIVATE_H