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_fourcc.h>
40 #include <vlc_picture_pool.h>
42 /**************************
43 * VA instance management *
44 **************************/
46 typedef void (*vlc_vaapi_native_destroy_cb
)(VANativeDisplay
);
47 struct vlc_vaapi_instance
;
49 /* Initializes the VADisplay and sets the reference counter to 1. If not NULL,
50 * native_destroy_cb will be called when the instance is released in order to
51 * destroy the native holder (that can be a drm/x11/wl). On error, dpy is
52 * terminated and the destroy callback is called. */
53 struct vlc_vaapi_instance
*
54 vlc_vaapi_InitializeInstance(vlc_object_t
*o
, VADisplay dpy
,
55 VANativeDisplay native
,
56 vlc_vaapi_native_destroy_cb native_destroy_cb
);
58 /* Get and Initializes a VADisplay from a DRM device. If device is NULL, this
59 * function will try to open default devices. */
60 struct vlc_vaapi_instance
*
61 vlc_vaapi_InitializeInstanceDRM(vlc_object_t
*o
,
62 VADisplay (*pf_getDisplayDRM
)(int),
63 VADisplay
*pdpy
, const char *device
);
66 /* Increments the VAAPI instance refcount */
68 vlc_vaapi_HoldInstance(struct vlc_vaapi_instance
*inst
);
70 /* Decrements the VAAPI instance refcount, and call vaTerminate if that counter
73 vlc_vaapi_ReleaseInstance(struct vlc_vaapi_instance
*inst
);
75 /**************************
76 * VAAPI create & destroy *
77 **************************/
79 /* Creates a VA context from the VA configuration and the width / height of the
80 * pictures to process. */
82 vlc_vaapi_CreateContext(vlc_object_t
*o
, VADisplay dpy
, VAConfigID conf
,
83 int pic_w
, int pic_h
, int flag
,
84 VASurfaceID
*render_targets
, int num_render_targets
);
86 /* Creates a VA buffer for 'num_elements' elements of 'size' bytes and
87 * initalized with 'data'. If 'data' is NULL, then the content of the buffer is
90 vlc_vaapi_CreateBuffer(vlc_object_t
*o
, VADisplay dpy
, VAContextID ctx
,
91 VABufferType type
, unsigned int size
,
92 unsigned int num_elements
, void *data
);
94 /* Creates a VA image from a VA surface. */
96 vlc_vaapi_DeriveImage(vlc_object_t
*o
, VADisplay dpy
,
97 VASurfaceID surface
, VAImage
*image
);
99 /* Creates a VA image */
101 vlc_vaapi_CreateImage(vlc_object_t
*o
, VADisplay dpy
, VAImageFormat
*format
,
102 int width
, int height
, VAImage
*image
);
104 /* Destroys a VA configuration. */
106 vlc_vaapi_DestroyConfig(vlc_object_t
*o
, VADisplay dpy
, VAConfigID conf
);
108 /* Destroys a VA context. */
110 vlc_vaapi_DestroyContext(vlc_object_t
*o
, VADisplay dpy
, VAContextID ctx
);
112 /* Destroys a VA buffer. */
114 vlc_vaapi_DestroyBuffer(vlc_object_t
*o
, VADisplay dpy
, VABufferID buf
);
116 /* Destroys a VA image. */
118 vlc_vaapi_DestroyImage(vlc_object_t
*o
, VADisplay dpy
, VAImageID image
);
120 /***********************
121 * VAAPI buffer access *
122 ***********************/
124 /* Maps the specified buffer to '*p_buf'. */
126 vlc_vaapi_MapBuffer(vlc_object_t
*o
, VADisplay dpy
,
127 VABufferID buf_id
, void **p_buf
);
129 /* Unmaps the specified buffer so that the driver can read from it. */
131 vlc_vaapi_UnmapBuffer(vlc_object_t
*o
, VADisplay dpy
, VABufferID buf_id
);
134 vlc_vaapi_AcquireBufferHandle(vlc_object_t
*o
, VADisplay dpy
, VABufferID buf_id
,
135 VABufferInfo
*buf_info
);
138 vlc_vaapi_ReleaseBufferHandle(vlc_object_t
*o
, VADisplay dpy
, VABufferID buf_id
);
144 /* Checks if the specified filter is available. */
146 vlc_vaapi_IsVideoProcFilterAvailable(vlc_object_t
*o
,
147 VADisplay dpy
, VAContextID ctx
,
148 VAProcFilterType filter
);
150 /* Retrieves the list of available capabilities of a filter. */
152 vlc_vaapi_QueryVideoProcFilterCaps(vlc_object_t
*o
, VADisplay dpy
,
154 VAProcFilterType filter
, void *caps
,
155 unsigned int *p_num_caps
);
157 /* Retrieves the available capabilities of the pipeline. */
159 vlc_vaapi_QueryVideoProcPipelineCaps(vlc_object_t
*o
, VADisplay dpy
,
160 VAContextID ctx
, VABufferID
*filters
,
161 unsigned int num_filters
,
162 VAProcPipelineCaps
*pipeline_caps
);
168 /* Tells the driver the specified surface is the next surface to render. */
170 vlc_vaapi_BeginPicture(vlc_object_t
*o
, VADisplay dpy
,
171 VAContextID ctx
, VASurfaceID surface
);
173 /* Send buffers (describing rendering operations to perform on the current
174 * surface) to the driver, which are automatically destroyed afterwards. */
176 vlc_vaapi_RenderPicture(vlc_object_t
*o
, VADisplay dpy
, VAContextID ctx
,
177 VABufferID
*buffers
, int num_buffers
);
179 /* Tells the driver it can begins to process all the pending operations
180 * (specified with vlc_vaapi_RenderPicture) on the current surface. */
182 vlc_vaapi_EndPicture(vlc_object_t
*o
, VADisplay dpy
, VAContextID ctx
);
188 /* Creates a VAConfigID */
190 vlc_vaapi_CreateConfigChecked(vlc_object_t
*o
, VADisplay dpy
,
191 VAProfile i_profile
, VAEntrypoint entrypoint
,
192 int i_force_vlc_chroma
);
194 /* Create a pool backed by VASurfaceID. render_targets will destroyed once
195 * the pool and every pictures are released. */
197 vlc_vaapi_PoolNew(vlc_object_t
*o
, struct vlc_vaapi_instance
*vainst
,
198 VADisplay dpy
, unsigned count
, VASurfaceID
**render_targets
,
199 const video_format_t
*restrict fmt
, bool b_force_fourcc
);
201 /* Get render targets from a pic_sys allocated by the vaapi pool (see
202 * vlc_vaapi_PoolNew()) */
204 vlc_vaapi_PicSysGetRenderTargets(picture_sys_t
*sys
,
205 VASurfaceID
**render_targets
);
207 /* Get and hold the VADisplay instance attached to the picture sys */
208 struct vlc_vaapi_instance
*
209 vlc_vaapi_PicSysHoldInstance(picture_sys_t
*sys
, VADisplay
*dpy
);
211 /* Attachs the VASurface to the picture context, the picture must be allocated
212 * by a vaapi pool (see vlc_vaapi_PoolNew()) */
214 vlc_vaapi_PicAttachContext(picture_t
*pic
);
216 /* Get the VASurfaceID attached to the pic */
218 vlc_vaapi_PicGetSurface(picture_t
*pic
);
220 /* Get the VADisplay attached to the pic (valid while the pic is alive) */
222 vlc_vaapi_PicGetDisplay(picture_t
*pic
);
225 vlc_vaapi_IsChromaOpaque(int i_vlc_chroma
)
227 return i_vlc_chroma
== VLC_CODEC_VAAPI_420
228 || i_vlc_chroma
== VLC_CODEC_VAAPI_420_10BPP
;
231 #endif /* VLC_VAAPI_H */