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