1 /*****************************************************************************
2 * vlc_vaapi.h: VAAPI helper for VLC
3 *****************************************************************************
4 * Copyright (C) 2017 VLC authors, VideoLAN and VideoLabs
6 * Authors: Thomas Guillem <thomas@gllm.fr>
7 * Petri Hintukainen <phintuka@gmail.com>
8 * Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet@gmail.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 #ifndef VA_RT_FORMAT_YUV420_10BPP
31 # define VA_RT_FORMAT_YUV420_10BPP 0x00000100
34 #ifndef VA_FOURCC_P010
35 #define VA_FOURCC_P010 0x30313050
38 #include <vlc_common.h>
39 #include <vlc_codec.h>
40 #include <vlc_fourcc.h>
41 #include <vlc_picture_pool.h>
43 /**************************
44 * VAAPI create & destroy *
45 **************************/
47 /* Creates a VA context from the VA configuration and the width / height of the
48 * pictures to process. */
50 vlc_vaapi_CreateContext(vlc_object_t
*o
, VADisplay dpy
, VAConfigID conf
,
51 int pic_w
, int pic_h
, int flag
,
52 VASurfaceID
*render_targets
, int num_render_targets
);
54 /* Creates a VA buffer for 'num_elements' elements of 'size' bytes and
55 * initalized with 'data'. If 'data' is NULL, then the content of the buffer is
58 vlc_vaapi_CreateBuffer(vlc_object_t
*o
, VADisplay dpy
, VAContextID ctx
,
59 VABufferType type
, unsigned int size
,
60 unsigned int num_elements
, void *data
);
62 /* Creates a VA image from a VA surface. */
64 vlc_vaapi_DeriveImage(vlc_object_t
*o
, VADisplay dpy
,
65 VASurfaceID surface
, VAImage
*image
);
67 /* Creates a VA image */
69 vlc_vaapi_CreateImage(vlc_object_t
*o
, VADisplay dpy
, VAImageFormat
*format
,
70 int width
, int height
, VAImage
*image
);
72 /* Destroys a VA configuration. */
74 vlc_vaapi_DestroyConfig(vlc_object_t
*o
, VADisplay dpy
, VAConfigID conf
);
76 /* Destroys a VA context. */
78 vlc_vaapi_DestroyContext(vlc_object_t
*o
, VADisplay dpy
, VAContextID ctx
);
80 /* Destroys a VA buffer. */
82 vlc_vaapi_DestroyBuffer(vlc_object_t
*o
, VADisplay dpy
, VABufferID buf
);
84 /* Destroys a VA image. */
86 vlc_vaapi_DestroyImage(vlc_object_t
*o
, VADisplay dpy
, VAImageID image
);
88 /***********************
89 * VAAPI buffer access *
90 ***********************/
92 /* Maps the specified buffer to '*p_buf'. */
94 vlc_vaapi_MapBuffer(vlc_object_t
*o
, VADisplay dpy
,
95 VABufferID buf_id
, void **p_buf
);
97 /* Unmaps the specified buffer so that the driver can read from it. */
99 vlc_vaapi_UnmapBuffer(vlc_object_t
*o
, VADisplay dpy
, VABufferID buf_id
);
102 vlc_vaapi_AcquireBufferHandle(vlc_object_t
*o
, VADisplay dpy
, VABufferID buf_id
,
103 VABufferInfo
*buf_info
);
106 vlc_vaapi_ReleaseBufferHandle(vlc_object_t
*o
, VADisplay dpy
, VABufferID buf_id
);
112 /* Checks if the specified filter is available. */
114 vlc_vaapi_IsVideoProcFilterAvailable(vlc_object_t
*o
,
115 VADisplay dpy
, VAContextID ctx
,
116 VAProcFilterType filter
);
118 /* Retrieves the list of available capabilities of a filter. */
120 vlc_vaapi_QueryVideoProcFilterCaps(vlc_object_t
*o
, VADisplay dpy
,
122 VAProcFilterType filter
, void *caps
,
123 unsigned int *p_num_caps
);
125 /* Retrieves the available capabilities of the pipeline. */
127 vlc_vaapi_QueryVideoProcPipelineCaps(vlc_object_t
*o
, VADisplay dpy
,
128 VAContextID ctx
, VABufferID
*filters
,
129 unsigned int num_filters
,
130 VAProcPipelineCaps
*pipeline_caps
);
136 /* Tells the driver the specified surface is the next surface to render. */
138 vlc_vaapi_BeginPicture(vlc_object_t
*o
, VADisplay dpy
,
139 VAContextID ctx
, VASurfaceID surface
);
141 /* Send buffers (describing rendering operations to perform on the current
142 * surface) to the driver, which are automatically destroyed afterwards. */
144 vlc_vaapi_RenderPicture(vlc_object_t
*o
, VADisplay dpy
, VAContextID ctx
,
145 VABufferID
*buffers
, int num_buffers
);
147 /* Tells the driver it can begins to process all the pending operations
148 * (specified with vlc_vaapi_RenderPicture) on the current surface. */
150 vlc_vaapi_EndPicture(vlc_object_t
*o
, VADisplay dpy
, VAContextID ctx
);
156 struct vaapi_pic_context
163 /* Creates a VAConfigID */
165 vlc_vaapi_CreateConfigChecked(vlc_object_t
*o
, VADisplay dpy
,
166 VAProfile i_profile
, VAEntrypoint entrypoint
,
167 int i_force_vlc_chroma
);
169 /* Create a pool backed by VASurfaceID. render_targets will destroyed once
170 * the pool and every pictures are released. */
172 vlc_vaapi_PoolNew(vlc_object_t
*o
, vlc_video_context
*vctx
,
173 VADisplay dpy
, unsigned count
, VASurfaceID
**render_targets
,
174 const video_format_t
*restrict fmt
);
176 /* Attachs the VASurface to the picture context, the picture must be allocated
177 * by a vaapi pool (see vlc_vaapi_PoolNew()) */
179 vlc_vaapi_PicAttachContext(picture_t
*pic
);
181 /* Attachs the VASurface to the picture context */
183 vlc_vaapi_PicSetContext(picture_t
*pic
, struct vaapi_pic_context
*);
185 /* Get the VASurfaceID attached to the pic */
187 vlc_vaapi_PicGetSurface(picture_t
*pic
);
189 /* Get the VADisplay attached to the pic (valid while the pic is alive) */
191 vlc_vaapi_PicGetDisplay(picture_t
*pic
);
194 vlc_vaapi_IsChromaOpaque(int i_vlc_chroma
)
196 return i_vlc_chroma
== VLC_CODEC_VAAPI_420
197 || i_vlc_chroma
== VLC_CODEC_VAAPI_420_10BPP
;
200 void vlc_chroma_to_vaapi(int i_vlc_chroma
, unsigned *va_rt_format
, int *va_fourcc
);
202 #if VA_CHECK_VERSION(1, 1, 0)
204 vlc_vaapi_ExportSurfaceHandle(vlc_object_t
*o
,
212 /* This macro is designed to wrap any VA call, and in case of failure,
213 display the VA error string then goto the 'error' label (which you must
215 #define VA_CALL(o, f, args...) \
218 VAStatus s = f(args); \
219 if (s != VA_STATUS_SUCCESS) \
221 msg_Err(o, "%s: %s", #f, vaErrorStr(s)); \
226 #endif /* VLC_VAAPI_H */