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_MPEG4_AVC_HIGH10
:
152 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH422
:
153 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH444
:
154 case PIPE_VIDEO_PROFILE_HEVC_MAIN_10
:
155 case PIPE_VIDEO_PROFILE_HEVC_MAIN_12
:
156 case PIPE_VIDEO_PROFILE_HEVC_MAIN_STILL
:
157 case PIPE_VIDEO_PROFILE_HEVC_MAIN_444
:
158 case PIPE_VIDEO_PROFILE_UNKNOWN
:
159 return VAProfileNone
;
166 static inline enum pipe_video_profile
167 ProfileToPipe(VAProfile profile
)
170 case VAProfileMPEG2Simple
:
171 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
;
172 case VAProfileMPEG2Main
:
173 return PIPE_VIDEO_PROFILE_MPEG2_MAIN
;
174 case VAProfileMPEG4Simple
:
175 return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
;
176 case VAProfileMPEG4AdvancedSimple
:
177 return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
;
178 case VAProfileVC1Simple
:
179 return PIPE_VIDEO_PROFILE_VC1_SIMPLE
;
180 case VAProfileVC1Main
:
181 return PIPE_VIDEO_PROFILE_VC1_MAIN
;
182 case VAProfileVC1Advanced
:
183 return PIPE_VIDEO_PROFILE_VC1_ADVANCED
;
184 case VAProfileH264Baseline
:
185 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
;
186 case VAProfileH264Main
:
187 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
;
188 case VAProfileH264High
:
189 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
;
190 case VAProfileHEVCMain
:
191 return PIPE_VIDEO_PROFILE_HEVC_MAIN
;
193 return PIPE_VIDEO_PROFILE_UNKNOWN
;
195 return PIPE_VIDEO_PROFILE_UNKNOWN
;
200 struct vl_screen
*vscreen
;
201 struct pipe_context
*pipe
;
202 struct handle_table
*htab
;
203 struct vl_compositor compositor
;
204 struct vl_compositor_state cstate
;
211 struct u_rect src_rect
;
212 struct u_rect dst_rect
;
214 struct pipe_sampler_view
*sampler
;
218 struct pipe_video_codec templat
, *decoder
;
219 struct pipe_video_buffer
*target
;
221 struct pipe_picture_desc base
;
222 struct pipe_mpeg12_picture_desc mpeg12
;
223 struct pipe_mpeg4_picture_desc mpeg4
;
224 struct pipe_vc1_picture_desc vc1
;
225 struct pipe_h264_picture_desc h264
;
226 struct pipe_h265_picture_desc h265
;
230 unsigned long long int frame_num
;
231 unsigned int start_code_size
;
232 unsigned int vti_bits
;
233 unsigned int quant_scale
;
234 VAPictureParameterBufferMPEG4 pps
;
235 uint8_t start_code
[32];
242 unsigned int num_elements
;
245 struct pipe_resource
*resource
;
246 struct pipe_transfer
*transfer
;
247 struct pipe_fence_handle
*fence
;
249 unsigned int export_refcount
;
250 VABufferInfo export_state
;
254 struct pipe_video_buffer templat
, *buffer
;
255 struct pipe_fence_handle
*fence
;
256 struct util_dynarray subpics
; /* vlVaSubpicture */
260 VAStatus
VA_DRIVER_INIT_FUNC(VADriverContextP ctx
);
263 VAStatus
vlVaTerminate(VADriverContextP ctx
);
264 VAStatus
vlVaQueryConfigProfiles(VADriverContextP ctx
, VAProfile
*profile_list
,int *num_profiles
);
265 VAStatus
vlVaQueryConfigEntrypoints(VADriverContextP ctx
, VAProfile profile
,
266 VAEntrypoint
*entrypoint_list
, int *num_entrypoints
);
267 VAStatus
vlVaGetConfigAttributes(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
268 VAConfigAttrib
*attrib_list
, int num_attribs
);
269 VAStatus
vlVaCreateConfig(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
270 VAConfigAttrib
*attrib_list
, int num_attribs
, VAConfigID
*config_id
);
271 VAStatus
vlVaDestroyConfig(VADriverContextP ctx
, VAConfigID config_id
);
272 VAStatus
vlVaQueryConfigAttributes(VADriverContextP ctx
, VAConfigID config_id
, VAProfile
*profile
,
273 VAEntrypoint
*entrypoint
, VAConfigAttrib
*attrib_list
, int *num_attribs
);
274 VAStatus
vlVaCreateSurfaces(VADriverContextP ctx
, int width
, int height
, int format
,
275 int num_surfaces
, VASurfaceID
*surfaces
);
276 VAStatus
vlVaDestroySurfaces(VADriverContextP ctx
, VASurfaceID
*surface_list
, int num_surfaces
);
277 VAStatus
vlVaCreateContext(VADriverContextP ctx
, VAConfigID config_id
, int picture_width
, int picture_height
,
278 int flag
, VASurfaceID
*render_targets
, int num_render_targets
, VAContextID
*context
);
279 VAStatus
vlVaDestroyContext(VADriverContextP ctx
, VAContextID context
);
280 VAStatus
vlVaCreateBuffer(VADriverContextP ctx
, VAContextID context
, VABufferType type
, unsigned int size
,
281 unsigned int num_elements
, void *data
, VABufferID
*buf_id
);
282 VAStatus
vlVaBufferSetNumElements(VADriverContextP ctx
, VABufferID buf_id
, unsigned int num_elements
);
283 VAStatus
vlVaMapBuffer(VADriverContextP ctx
, VABufferID buf_id
, void **pbuf
);
284 VAStatus
vlVaUnmapBuffer(VADriverContextP ctx
, VABufferID buf_id
);
285 VAStatus
vlVaDestroyBuffer(VADriverContextP ctx
, VABufferID buffer_id
);
286 VAStatus
vlVaBeginPicture(VADriverContextP ctx
, VAContextID context
, VASurfaceID render_target
);
287 VAStatus
vlVaRenderPicture(VADriverContextP ctx
, VAContextID context
, VABufferID
*buffers
, int num_buffers
);
288 VAStatus
vlVaEndPicture(VADriverContextP ctx
, VAContextID context
);
289 VAStatus
vlVaSyncSurface(VADriverContextP ctx
, VASurfaceID render_target
);
290 VAStatus
vlVaQuerySurfaceStatus(VADriverContextP ctx
, VASurfaceID render_target
, VASurfaceStatus
*status
);
291 VAStatus
vlVaQuerySurfaceError(VADriverContextP ctx
, VASurfaceID render_target
,
292 VAStatus error_status
, void **error_info
);
293 VAStatus
vlVaPutSurface(VADriverContextP ctx
, VASurfaceID surface
, void* draw
, short srcx
, short srcy
,
294 unsigned short srcw
, unsigned short srch
, short destx
, short desty
, unsigned short destw
,
295 unsigned short desth
, VARectangle
*cliprects
, unsigned int number_cliprects
,
297 VAStatus
vlVaQueryImageFormats(VADriverContextP ctx
, VAImageFormat
*format_list
, int *num_formats
);
298 VAStatus
vlVaQuerySubpictureFormats(VADriverContextP ctx
, VAImageFormat
*format_list
,
299 unsigned int *flags
, unsigned int *num_formats
);
300 VAStatus
vlVaCreateImage(VADriverContextP ctx
, VAImageFormat
*format
, int width
, int height
, VAImage
*image
);
301 VAStatus
vlVaDeriveImage(VADriverContextP ctx
, VASurfaceID surface
, VAImage
*image
);
302 VAStatus
vlVaDestroyImage(VADriverContextP ctx
, VAImageID image
);
303 VAStatus
vlVaSetImagePalette(VADriverContextP ctx
, VAImageID image
, unsigned char *palette
);
304 VAStatus
vlVaGetImage(VADriverContextP ctx
, VASurfaceID surface
, int x
, int y
,
305 unsigned int width
, unsigned int height
, VAImageID image
);
306 VAStatus
vlVaPutImage(VADriverContextP ctx
, VASurfaceID surface
, VAImageID image
, int src_x
, int src_y
,
307 unsigned int src_width
, unsigned int src_height
, int dest_x
, int dest_y
,
308 unsigned int dest_width
, unsigned int dest_height
);
309 VAStatus
vlVaQuerySubpictureFormats(VADriverContextP ctx
, VAImageFormat
*format_list
,
310 unsigned int *flags
, unsigned int *num_formats
);
311 VAStatus
vlVaCreateSubpicture(VADriverContextP ctx
, VAImageID image
, VASubpictureID
*subpicture
);
312 VAStatus
vlVaDestroySubpicture(VADriverContextP ctx
, VASubpictureID subpicture
);
313 VAStatus
vlVaSubpictureImage(VADriverContextP ctx
, VASubpictureID subpicture
, VAImageID image
);
314 VAStatus
vlVaSetSubpictureChromakey(VADriverContextP ctx
, VASubpictureID subpicture
,
315 unsigned int chromakey_min
, unsigned int chromakey_max
,
316 unsigned int chromakey_mask
);
317 VAStatus
vlVaSetSubpictureGlobalAlpha(VADriverContextP ctx
, VASubpictureID subpicture
, float global_alpha
);
318 VAStatus
vlVaAssociateSubpicture(VADriverContextP ctx
, VASubpictureID subpicture
, VASurfaceID
*target_surfaces
,
319 int num_surfaces
, short src_x
, short src_y
,
320 unsigned short src_width
, unsigned short src_height
,
321 short dest_x
, short dest_y
, unsigned short dest_width
, unsigned short dest_height
,
323 VAStatus
vlVaDeassociateSubpicture(VADriverContextP ctx
, VASubpictureID subpicture
,
324 VASurfaceID
*target_surfaces
, int num_surfaces
);
325 VAStatus
vlVaQueryDisplayAttributes(VADriverContextP ctx
, VADisplayAttribute
*attr_list
, int *num_attributes
);
326 VAStatus
vlVaGetDisplayAttributes(VADriverContextP ctx
, VADisplayAttribute
*attr_list
, int num_attributes
);
327 VAStatus
vlVaSetDisplayAttributes(VADriverContextP ctx
, VADisplayAttribute
*attr_list
, int num_attributes
);
328 VAStatus
vlVaBufferInfo(VADriverContextP ctx
, VABufferID buf_id
, VABufferType
*type
,
329 unsigned int *size
, unsigned int *num_elements
);
330 VAStatus
vlVaLockSurface(VADriverContextP ctx
, VASurfaceID surface
, unsigned int *fourcc
,
331 unsigned int *luma_stride
, unsigned int *chroma_u_stride
, unsigned int *chroma_v_stride
,
332 unsigned int *luma_offset
, unsigned int *chroma_u_offset
, unsigned int *chroma_v_offset
,
333 unsigned int *buffer_name
, void **buffer
);
334 VAStatus
vlVaUnlockSurface(VADriverContextP ctx
, VASurfaceID surface
);
335 VAStatus
vlVaCreateSurfaces2(VADriverContextP ctx
, unsigned int format
, unsigned int width
, unsigned int height
,
336 VASurfaceID
*surfaces
, unsigned int num_surfaces
, VASurfaceAttrib
*attrib_list
,
337 unsigned int num_attribs
);
338 VAStatus
vlVaQuerySurfaceAttributes(VADriverContextP ctx
, VAConfigID config
, VASurfaceAttrib
*attrib_list
,
339 unsigned int *num_attribs
);
341 VAStatus
vlVaAcquireBufferHandle(VADriverContextP ctx
, VABufferID buf_id
, VABufferInfo
*out_buf_info
);
342 VAStatus
vlVaReleaseBufferHandle(VADriverContextP ctx
, VABufferID buf_id
);
344 VAStatus
vlVaQueryVideoProcFilters(VADriverContextP ctx
, VAContextID context
, VAProcFilterType
*filters
,
345 unsigned int *num_filters
);
346 VAStatus
vlVaQueryVideoProcFilterCaps(VADriverContextP ctx
, VAContextID context
, VAProcFilterType type
,
347 void *filter_caps
, unsigned int *num_filter_caps
);
348 VAStatus
vlVaQueryVideoProcPipelineCaps(VADriverContextP ctx
, VAContextID context
, VABufferID
*filters
,
349 unsigned int num_filters
, VAProcPipelineCaps
*pipeline_cap
);
351 // internal functions
352 VAStatus
vlVaHandleVAProcPipelineParameterBufferType(vlVaDriver
*drv
, vlVaContext
*context
, vlVaBuffer
*buf
);
353 void vlVaGetReferenceFrame(vlVaDriver
*drv
, VASurfaceID surface_id
, struct pipe_video_buffer
**ref_frame
);
354 void vlVaHandlePictureParameterBufferMPEG12(vlVaDriver
*drv
, vlVaContext
*context
, vlVaBuffer
*buf
);
355 void vlVaHandleIQMatrixBufferMPEG12(vlVaContext
*context
, vlVaBuffer
*buf
);
356 void vlVaHandlePictureParameterBufferH264(vlVaDriver
*drv
, vlVaContext
*context
, vlVaBuffer
*buf
);
357 void vlVaHandleIQMatrixBufferH264(vlVaContext
*context
, vlVaBuffer
*buf
);
358 void vlVaHandleSliceParameterBufferH264(vlVaContext
*context
, vlVaBuffer
*buf
);
359 void vlVaHandlePictureParameterBufferVC1(vlVaDriver
*drv
, vlVaContext
*context
, vlVaBuffer
*buf
);
360 void vlVaHandlePictureParameterBufferMPEG4(vlVaDriver
*drv
, vlVaContext
*context
, vlVaBuffer
*buf
);
361 void vlVaHandleIQMatrixBufferMPEG4(vlVaContext
*context
, vlVaBuffer
*buf
);
362 void vlVaHandleSliceParameterBufferMPEG4(vlVaContext
*context
, vlVaBuffer
*buf
);
363 void vlVaDecoderFixMPEG4Startcode(vlVaContext
*context
);
364 void vlVaHandlePictureParameterBufferHEVC(vlVaDriver
*drv
, vlVaContext
*context
, vlVaBuffer
*buf
);
365 void vlVaHandleIQMatrixBufferHEVC(vlVaContext
*context
, vlVaBuffer
*buf
);
366 void vlVaHandleSliceParameterBufferHEVC(vlVaContext
*context
, vlVaBuffer
*buf
);
368 #endif //VA_PRIVATE_H