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"
30 #include "pipe/p_video_codec.h"
32 #include "util/u_memory.h"
33 #include "util/u_handle_table.h"
34 #include "util/u_video.h"
35 #include "vl/vl_winsys.h"
37 #include "va_private.h"
39 static struct VADriverVTable vtable
=
42 &vlVaQueryConfigProfiles
,
43 &vlVaQueryConfigEntrypoints
,
44 &vlVaGetConfigAttributes
,
47 &vlVaQueryConfigAttributes
,
53 &vlVaBufferSetNumElements
,
61 &vlVaQuerySurfaceStatus
,
62 &vlVaQuerySurfaceError
,
64 &vlVaQueryImageFormats
,
71 &vlVaQuerySubpictureFormats
,
72 &vlVaCreateSubpicture
,
73 &vlVaDestroySubpicture
,
75 &vlVaSetSubpictureChromakey
,
76 &vlVaSetSubpictureGlobalAlpha
,
77 &vlVaAssociateSubpicture
,
78 &vlVaDeassociateSubpicture
,
79 &vlVaQueryDisplayAttributes
,
80 &vlVaGetDisplayAttributes
,
81 &vlVaSetDisplayAttributes
,
88 VA_DRIVER_INIT_FUNC(VADriverContextP ctx
)
93 return VA_STATUS_ERROR_INVALID_CONTEXT
;
95 drv
= CALLOC(1, sizeof(vlVaDriver
));
97 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
99 drv
->vscreen
= vl_screen_create(ctx
->native_dpy
, ctx
->x11_screen
);
103 drv
->pipe
= drv
->vscreen
->pscreen
->context_create(drv
->vscreen
->pscreen
, drv
->vscreen
);
107 drv
->htab
= handle_table_create();
111 vl_compositor_init(&drv
->compositor
, drv
->pipe
);
112 vl_compositor_init_state(&drv
->cstate
, drv
->pipe
);
114 vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_BT_601
, NULL
, true, &drv
->csc
);
115 vl_compositor_set_csc_matrix(&drv
->cstate
, (const vl_csc_matrix
*)&drv
->csc
);
117 ctx
->pDriverData
= (void *)drv
;
118 ctx
->version_major
= 0;
119 ctx
->version_minor
= 1;
120 *ctx
->vtable
= vtable
;
121 ctx
->max_profiles
= PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
- PIPE_VIDEO_PROFILE_UNKNOWN
;
122 ctx
->max_entrypoints
= 1;
123 ctx
->max_attributes
= 1;
124 ctx
->max_image_formats
= VL_VA_MAX_IMAGE_FORMATS
;
125 ctx
->max_subpic_formats
= 1;
126 ctx
->max_display_attributes
= 1;
127 ctx
->str_vendor
= "mesa gallium vaapi";
129 return VA_STATUS_SUCCESS
;
132 drv
->pipe
->destroy(drv
->pipe
);
135 vl_screen_destroy(drv
->vscreen
);
139 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
143 vlVaCreateContext(VADriverContextP ctx
, VAConfigID config_id
, int picture_width
,
144 int picture_height
, int flag
, VASurfaceID
*render_targets
,
145 int num_render_targets
, VAContextID
*context_id
)
147 struct pipe_video_codec templat
= {};
149 vlVaContext
*context
;
152 return VA_STATUS_ERROR_INVALID_CONTEXT
;
154 if (!(picture_width
&& picture_height
))
155 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT
;
157 drv
= VL_VA_DRIVER(ctx
);
158 context
= CALLOC(1, sizeof(vlVaContext
));
160 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
162 templat
.profile
= config_id
;
163 templat
.entrypoint
= PIPE_VIDEO_ENTRYPOINT_BITSTREAM
;
164 templat
.chroma_format
= PIPE_VIDEO_CHROMA_FORMAT_420
;
165 templat
.width
= picture_width
;
166 templat
.height
= picture_height
;
167 templat
.max_references
= num_render_targets
;
168 templat
.expect_chunked_decode
= true;
170 context
->decoder
= drv
->pipe
->create_video_codec(drv
->pipe
, &templat
);
171 if (!context
->decoder
) {
173 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
176 if (u_reduce_video_profile(context
->decoder
->profile
) ==
177 PIPE_VIDEO_FORMAT_MPEG4_AVC
) {
178 context
->desc
.h264
.pps
= CALLOC_STRUCT(pipe_h264_pps
);
179 if (!context
->desc
.h264
.pps
) {
181 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
183 context
->desc
.h264
.pps
->sps
= CALLOC_STRUCT(pipe_h264_sps
);
184 if (!context
->desc
.h264
.pps
->sps
) {
185 FREE(context
->desc
.h264
.pps
);
187 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
191 context
->desc
.base
.profile
= config_id
;
192 *context_id
= handle_table_add(drv
->htab
, context
);
194 return VA_STATUS_SUCCESS
;
198 vlVaDestroyContext(VADriverContextP ctx
, VAContextID context_id
)
201 vlVaContext
*context
;
204 return VA_STATUS_ERROR_INVALID_CONTEXT
;
206 drv
= VL_VA_DRIVER(ctx
);
207 context
= handle_table_get(drv
->htab
, context_id
);
208 if (u_reduce_video_profile(context
->decoder
->profile
) ==
209 PIPE_VIDEO_FORMAT_MPEG4_AVC
) {
210 FREE(context
->desc
.h264
.pps
->sps
);
211 FREE(context
->desc
.h264
.pps
);
213 context
->decoder
->destroy(context
->decoder
);
215 handle_table_remove(drv
->htab
, context_id
);
217 return VA_STATUS_SUCCESS
;
221 vlVaTerminate(VADriverContextP ctx
)
226 return VA_STATUS_ERROR_INVALID_CONTEXT
;
228 drv
= ctx
->pDriverData
;
229 vl_compositor_cleanup_state(&drv
->cstate
);
230 vl_compositor_cleanup(&drv
->compositor
);
231 drv
->pipe
->destroy(drv
->pipe
);
232 vl_screen_destroy(drv
->vscreen
);
233 handle_table_destroy(drv
->htab
);
236 return VA_STATUS_SUCCESS
;