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>
37 #include "pipe/p_video_enums.h"
38 #include "pipe/p_video_codec.h"
39 #include "pipe/p_video_state.h"
41 #include "vl/vl_compositor.h"
42 #include "vl/vl_csc.h"
44 #define VL_VA_DRIVER(ctx) ((vlVaDriver *)ctx->pDriverData)
45 #define VL_VA_PSCREEN(ctx) (VL_VA_DRIVER(ctx)->vscreen->pscreen)
47 #define VL_VA_MAX_IMAGE_FORMATS 6
49 static inline enum pipe_video_chroma_format
50 ChromaToPipe(int format
)
53 case VA_RT_FORMAT_YUV420
:
54 return PIPE_VIDEO_CHROMA_FORMAT_420
;
55 case VA_RT_FORMAT_YUV422
:
56 return PIPE_VIDEO_CHROMA_FORMAT_422
;
57 case VA_RT_FORMAT_YUV444
:
58 return PIPE_VIDEO_CHROMA_FORMAT_444
;
61 return PIPE_VIDEO_CHROMA_FORMAT_420
;
65 static inline enum pipe_format
66 YCbCrToPipe(unsigned format
)
69 case VA_FOURCC('N','V','1','2'):
70 return PIPE_FORMAT_NV12
;
71 case VA_FOURCC('I','4','2','0'):
72 return PIPE_FORMAT_IYUV
;
73 case VA_FOURCC('Y','V','1','2'):
74 return PIPE_FORMAT_YV12
;
75 case VA_FOURCC('Y','U','Y','V'):
76 return PIPE_FORMAT_YUYV
;
77 case VA_FOURCC('U','Y','V','Y'):
78 return PIPE_FORMAT_UYVY
;
79 case VA_FOURCC('B','G','R','A'):
80 return PIPE_FORMAT_B8G8R8A8_UNORM
;
83 return PIPE_FORMAT_NONE
;
87 static inline VAProfile
88 PipeToProfile(enum pipe_video_profile profile
)
91 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
:
92 return VAProfileMPEG2Simple
;
93 case PIPE_VIDEO_PROFILE_MPEG2_MAIN
:
94 return VAProfileMPEG2Main
;
95 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
:
96 return VAProfileMPEG4Simple
;
97 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
:
98 return VAProfileMPEG4AdvancedSimple
;
99 case PIPE_VIDEO_PROFILE_VC1_SIMPLE
:
100 return VAProfileVC1Simple
;
101 case PIPE_VIDEO_PROFILE_VC1_MAIN
:
102 return VAProfileVC1Main
;
103 case PIPE_VIDEO_PROFILE_VC1_ADVANCED
:
104 return VAProfileVC1Advanced
;
105 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
:
106 return VAProfileH264Baseline
;
107 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
:
108 return VAProfileH264Main
;
109 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
:
110 return VAProfileH264High
;
111 case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED
:
112 return VAProfileNone
;
119 static inline enum pipe_video_profile
120 ProfileToPipe(VAProfile profile
)
123 case VAProfileMPEG2Simple
:
124 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
;
125 case VAProfileMPEG2Main
:
126 return PIPE_VIDEO_PROFILE_MPEG2_MAIN
;
127 case VAProfileMPEG4Simple
:
128 return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
;
129 case VAProfileMPEG4AdvancedSimple
:
130 return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
;
131 case VAProfileVC1Simple
:
132 return PIPE_VIDEO_PROFILE_VC1_SIMPLE
;
133 case VAProfileVC1Main
:
134 return PIPE_VIDEO_PROFILE_VC1_MAIN
;
135 case VAProfileVC1Advanced
:
136 return PIPE_VIDEO_PROFILE_VC1_ADVANCED
;
137 case VAProfileH264Baseline
:
138 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
;
139 case VAProfileH264Main
:
140 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
;
141 case VAProfileH264High
:
142 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
;
144 return PIPE_VIDEO_PROFILE_UNKNOWN
;
149 struct vl_screen
*vscreen
;
150 struct pipe_context
*pipe
;
151 struct handle_table
*htab
;
152 struct vl_compositor compositor
;
153 struct vl_compositor_state cstate
;
158 struct pipe_video_codec
*decoder
;
159 struct pipe_video_buffer
*target
;
161 struct pipe_picture_desc base
;
162 struct pipe_mpeg12_picture_desc mpeg12
;
163 struct pipe_mpeg4_picture_desc mpeg4
;
164 struct pipe_vc1_picture_desc vc1
;
165 struct pipe_h264_picture_desc h264
;
169 unsigned long long int frame_num
;
170 unsigned int start_code_size
;
171 unsigned int vti_bits
;
172 unsigned int quant_scale
;
173 VAPictureParameterBufferMPEG4 pps
;
174 uint8_t start_code
[32];
181 unsigned int num_elements
;
186 struct pipe_video_buffer templat
, *buffer
;
187 struct pipe_fence_handle
*fence
;
191 VAStatus
VA_DRIVER_INIT_FUNC(VADriverContextP ctx
);
194 VAStatus
vlVaTerminate(VADriverContextP ctx
);
195 VAStatus
vlVaQueryConfigProfiles(VADriverContextP ctx
, VAProfile
*profile_list
,int *num_profiles
);
196 VAStatus
vlVaQueryConfigEntrypoints(VADriverContextP ctx
, VAProfile profile
,
197 VAEntrypoint
*entrypoint_list
, int *num_entrypoints
);
198 VAStatus
vlVaGetConfigAttributes(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
199 VAConfigAttrib
*attrib_list
, int num_attribs
);
200 VAStatus
vlVaCreateConfig(VADriverContextP ctx
, VAProfile profile
, VAEntrypoint entrypoint
,
201 VAConfigAttrib
*attrib_list
, int num_attribs
, VAConfigID
*config_id
);
202 VAStatus
vlVaDestroyConfig(VADriverContextP ctx
, VAConfigID config_id
);
203 VAStatus
vlVaQueryConfigAttributes(VADriverContextP ctx
, VAConfigID config_id
, VAProfile
*profile
,
204 VAEntrypoint
*entrypoint
, VAConfigAttrib
*attrib_list
, int *num_attribs
);
205 VAStatus
vlVaCreateSurfaces(VADriverContextP ctx
, int width
, int height
, int format
,
206 int num_surfaces
, VASurfaceID
*surfaces
);
207 VAStatus
vlVaDestroySurfaces(VADriverContextP ctx
, VASurfaceID
*surface_list
, int num_surfaces
);
208 VAStatus
vlVaCreateContext(VADriverContextP ctx
, VAConfigID config_id
, int picture_width
, int picture_height
,
209 int flag
, VASurfaceID
*render_targets
, int num_render_targets
, VAContextID
*context
);
210 VAStatus
vlVaDestroyContext(VADriverContextP ctx
, VAContextID context
);
211 VAStatus
vlVaCreateBuffer(VADriverContextP ctx
, VAContextID context
, VABufferType type
, unsigned int size
,
212 unsigned int num_elements
, void *data
, VABufferID
*buf_id
);
213 VAStatus
vlVaBufferSetNumElements(VADriverContextP ctx
, VABufferID buf_id
, unsigned int num_elements
);
214 VAStatus
vlVaMapBuffer(VADriverContextP ctx
, VABufferID buf_id
, void **pbuf
);
215 VAStatus
vlVaUnmapBuffer(VADriverContextP ctx
, VABufferID buf_id
);
216 VAStatus
vlVaDestroyBuffer(VADriverContextP ctx
, VABufferID buffer_id
);
217 VAStatus
vlVaBeginPicture(VADriverContextP ctx
, VAContextID context
, VASurfaceID render_target
);
218 VAStatus
vlVaRenderPicture(VADriverContextP ctx
, VAContextID context
, VABufferID
*buffers
, int num_buffers
);
219 VAStatus
vlVaEndPicture(VADriverContextP ctx
, VAContextID context
);
220 VAStatus
vlVaSyncSurface(VADriverContextP ctx
, VASurfaceID render_target
);
221 VAStatus
vlVaQuerySurfaceStatus(VADriverContextP ctx
, VASurfaceID render_target
, VASurfaceStatus
*status
);
222 VAStatus
vlVaQuerySurfaceError(VADriverContextP ctx
, VASurfaceID render_target
,
223 VAStatus error_status
, void **error_info
);
224 VAStatus
vlVaPutSurface(VADriverContextP ctx
, VASurfaceID surface
, void* draw
, short srcx
, short srcy
,
225 unsigned short srcw
, unsigned short srch
, short destx
, short desty
, unsigned short destw
,
226 unsigned short desth
, VARectangle
*cliprects
, unsigned int number_cliprects
,
228 VAStatus
vlVaQueryImageFormats(VADriverContextP ctx
, VAImageFormat
*format_list
, int *num_formats
);
229 VAStatus
vlVaQuerySubpictureFormats(VADriverContextP ctx
, VAImageFormat
*format_list
,
230 unsigned int *flags
, unsigned int *num_formats
);
231 VAStatus
vlVaCreateImage(VADriverContextP ctx
, VAImageFormat
*format
, int width
, int height
, VAImage
*image
);
232 VAStatus
vlVaDeriveImage(VADriverContextP ctx
, VASurfaceID surface
, VAImage
*image
);
233 VAStatus
vlVaDestroyImage(VADriverContextP ctx
, VAImageID image
);
234 VAStatus
vlVaSetImagePalette(VADriverContextP ctx
, VAImageID image
, unsigned char *palette
);
235 VAStatus
vlVaGetImage(VADriverContextP ctx
, VASurfaceID surface
, int x
, int y
,
236 unsigned int width
, unsigned int height
, VAImageID image
);
237 VAStatus
vlVaPutImage(VADriverContextP ctx
, VASurfaceID surface
, VAImageID image
, int src_x
, int src_y
,
238 unsigned int src_width
, unsigned int src_height
, int dest_x
, int dest_y
,
239 unsigned int dest_width
, unsigned int dest_height
);
240 VAStatus
vlVaQuerySubpictureFormats(VADriverContextP ctx
, VAImageFormat
*format_list
,
241 unsigned int *flags
, unsigned int *num_formats
);
242 VAStatus
vlVaCreateSubpicture(VADriverContextP ctx
, VAImageID image
, VASubpictureID
*subpicture
);
243 VAStatus
vlVaDestroySubpicture(VADriverContextP ctx
, VASubpictureID subpicture
);
244 VAStatus
vlVaSubpictureImage(VADriverContextP ctx
, VASubpictureID subpicture
, VAImageID image
);
245 VAStatus
vlVaSetSubpictureChromakey(VADriverContextP ctx
, VASubpictureID subpicture
,
246 unsigned int chromakey_min
, unsigned int chromakey_max
,
247 unsigned int chromakey_mask
);
248 VAStatus
vlVaSetSubpictureGlobalAlpha(VADriverContextP ctx
, VASubpictureID subpicture
, float global_alpha
);
249 VAStatus
vlVaAssociateSubpicture(VADriverContextP ctx
, VASubpictureID subpicture
, VASurfaceID
*target_surfaces
,
250 int num_surfaces
, short src_x
, short src_y
,
251 unsigned short src_width
, unsigned short src_height
,
252 short dest_x
, short dest_y
, unsigned short dest_width
, unsigned short dest_height
,
254 VAStatus
vlVaDeassociateSubpicture(VADriverContextP ctx
, VASubpictureID subpicture
,
255 VASurfaceID
*target_surfaces
, int num_surfaces
);
256 VAStatus
vlVaQueryDisplayAttributes(VADriverContextP ctx
, VADisplayAttribute
*attr_list
, int *num_attributes
);
257 VAStatus
vlVaGetDisplayAttributes(VADriverContextP ctx
, VADisplayAttribute
*attr_list
, int num_attributes
);
258 VAStatus
vlVaSetDisplayAttributes(VADriverContextP ctx
, VADisplayAttribute
*attr_list
, int num_attributes
);
259 VAStatus
vlVaBufferInfo(VADriverContextP ctx
, VABufferID buf_id
, VABufferType
*type
,
260 unsigned int *size
, unsigned int *num_elements
);
261 VAStatus
vlVaLockSurface(VADriverContextP ctx
, VASurfaceID surface
, unsigned int *fourcc
,
262 unsigned int *luma_stride
, unsigned int *chroma_u_stride
, unsigned int *chroma_v_stride
,
263 unsigned int *luma_offset
, unsigned int *chroma_u_offset
, unsigned int *chroma_v_offset
,
264 unsigned int *buffer_name
, void **buffer
);
265 VAStatus
vlVaUnlockSurface(VADriverContextP ctx
, VASurfaceID surface
);
267 #endif //VA_PRIVATE_H