Merge branch 'move_subdir_editing-services' into tizen_gst_1.19.2_mono
[platform/upstream/gstreamer.git] / subprojects / gstreamer-vaapi / gst / vaapi / gstvaapivideomemory.h
1 /*
2  *  gstvaapivideomemory.h - Gstreamer/VA video memory
3  *
4  *  Copyright (C) 2013 Intel Corporation
5  *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
6  *
7  *  This library is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU Lesser General Public License
9  *  as published by the Free Software Foundation; either version 2.1
10  *  of the License, or (at your option) any later version.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public
18  *  License along with this library; if not, write to the Free
19  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  *  Boston, MA 02110-1301 USA
21  */
22
23 #ifndef GST_VAAPI_VIDEO_MEMORY_H
24 #define GST_VAAPI_VIDEO_MEMORY_H
25
26 #include <gst/gstallocator.h>
27 #include <gst/video/video-info.h>
28 #include <gst/vaapi/gstvaapidisplay.h>
29 #include <gst/vaapi/gstvaapivideopool.h>
30 #include "gstvaapivideometa.h"
31 #include <gst/allocators/allocators.h>
32
33 G_BEGIN_DECLS
34
35 typedef struct _GstVaapiVideoMemory GstVaapiVideoMemory;
36 typedef struct _GstVaapiVideoAllocator GstVaapiVideoAllocator;
37 typedef struct _GstVaapiVideoAllocatorClass GstVaapiVideoAllocatorClass;
38 typedef struct _GstVaapiDmaBufAllocator GstVaapiDmaBufAllocator;
39 typedef struct _GstVaapiDmaBufAllocatorClass GstVaapiDmaBufAllocatorClass;
40
41 /* ------------------------------------------------------------------------ */
42 /* --- GstVaapiVideoMemory                                              --- */
43 /* ------------------------------------------------------------------------ */
44
45 #define GST_VAAPI_VIDEO_MEMORY_CAST(mem) \
46   ((GstVaapiVideoMemory *) (mem))
47
48 #define GST_VAAPI_IS_VIDEO_MEMORY(mem) \
49   ((mem) && (mem)->allocator && GST_VAAPI_IS_VIDEO_ALLOCATOR((mem)->allocator))
50
51 #define GST_VAAPI_VIDEO_MEMORY_NAME             "GstVaapiVideoMemory"
52
53 #define GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE   "memory:VASurface"
54
55 #define GST_VAAPI_VIDEO_MEMORY_FLAG_IS_SET(mem, flag) \
56   GST_MEMORY_FLAG_IS_SET (mem, flag)
57 #define GST_VAAPI_VIDEO_MEMORY_FLAG_SET(mem, flag) \
58   GST_MINI_OBJECT_FLAG_SET (mem, flag)
59 #define GST_VAAPI_VIDEO_MEMORY_FLAG_UNSET(mem, flag) \
60   GST_MEMORY_FLAG_UNSET (mem, flag)
61
62 /**
63  * GstVaapiVideoMemoryMapType:
64  * @GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_SURFACE: map with gst_buffer_map()
65  *   and flags = 0x00 to return a #GstVaapiSurfaceProxy
66  * @GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_PLANAR: map individual plane with
67  *   gst_video_frame_map()
68  * @GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_LINEAR: map with gst_buffer_map()
69  *   and flags = GST_MAP_READ to return the raw pixels of the whole image
70  *
71  * The set of all #GstVaapiVideoMemory map types.
72  */
73 typedef enum
74 {
75   GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_SURFACE = 1,
76   GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_PLANAR,
77   GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_LINEAR
78 } GstVaapiVideoMemoryMapType;
79
80 /**
81  * GstVaapiVideoMemoryFlags:
82  * @GST_VAAPI_VIDEO_MEMORY_FLAG_SURFACE_IS_CURRENT: The embedded
83  *   #GstVaapiSurface has the up-to-date video frame contents.
84  * @GST_VAAPI_VIDEO_MEMORY_FLAG_IMAGE_IS_CURRENT: The embedded
85  *   #GstVaapiImage has the up-to-date video frame contents.
86  *
87  * The set of extended #GstMemory flags.
88  */
89 typedef enum
90 {
91   GST_VAAPI_VIDEO_MEMORY_FLAG_SURFACE_IS_CURRENT = GST_MEMORY_FLAG_LAST << 0,
92   GST_VAAPI_VIDEO_MEMORY_FLAG_IMAGE_IS_CURRENT = GST_MEMORY_FLAG_LAST << 1,
93 } GstVaapiVideoMemoryFlags;
94
95 /**
96  * GstVaapiImageUsageFlags:
97  * @GST_VAAPI_IMAGE_USAGE_FLAG_NATIVE_FORMATS: will use vaCreateImage +
98  * va{Put,Get}Image when writing or reading onto the system memory.
99  * @GST_VAAPI_IMAGE_USAGE_FLAG_DIRECT_UPLOAD: will try to use
100  * vaDeriveImage when writing data from the system memory.
101  * @GST_VAAPI_IMAGE_USAGE_FLAG_DIRECT_RENDER: will try to use
102  * vaDeriveImage with reading data onto the system memory.
103  *
104  * Set the usage of GstVaapiImage in GstVaapiVideoMemory.
105  **/
106 typedef enum {
107   GST_VAAPI_IMAGE_USAGE_FLAG_NATIVE_FORMATS,
108   GST_VAAPI_IMAGE_USAGE_FLAG_DIRECT_UPLOAD,
109   GST_VAAPI_IMAGE_USAGE_FLAG_DIRECT_RENDER,
110 } GstVaapiImageUsageFlags;
111
112 /**
113  * GstVaapiVideoMemory:
114  *
115  * A VA video memory object holder, including VA surfaces, images and
116  * proxies.
117  */
118 struct _GstVaapiVideoMemory
119 {
120   GstMemory parent_instance;
121
122   /*< private >*/
123   GstVaapiSurfaceProxy *proxy;
124   const GstVideoInfo *surface_info;
125   GstVaapiSurface *surface;
126   const GstVideoInfo *image_info;
127   GstVaapiImage *image;
128   GstVaapiVideoMeta *meta;
129   guint map_type;
130   gint map_count;
131   VASurfaceID map_surface_id;
132   GstVaapiImageUsageFlags usage_flag;
133   GMutex lock;
134 };
135
136 G_GNUC_INTERNAL
137 GstMemory *
138 gst_vaapi_video_memory_new (GstAllocator * allocator, GstVaapiVideoMeta * meta);
139
140 G_GNUC_INTERNAL
141 gboolean
142 gst_video_meta_map_vaapi_memory (GstVideoMeta * meta, guint plane,
143     GstMapInfo * info, gpointer * data, gint * stride, GstMapFlags flags);
144
145 G_GNUC_INTERNAL
146 gboolean
147 gst_video_meta_unmap_vaapi_memory (GstVideoMeta * meta, guint plane,
148     GstMapInfo * info);
149
150 G_GNUC_INTERNAL
151 void
152 gst_vaapi_video_memory_reset_surface (GstVaapiVideoMemory * mem);
153
154 G_GNUC_INTERNAL
155 gboolean
156 gst_vaapi_video_memory_sync (GstVaapiVideoMemory * mem);
157
158 /* ------------------------------------------------------------------------ */
159 /* --- GstVaapiVideoAllocator                                           --- */
160 /* ------------------------------------------------------------------------ */
161 #define GST_MAP_VAAPI (GST_MAP_FLAG_LAST << 1)
162
163 #define GST_VAAPI_VIDEO_ALLOCATOR_CAST(allocator) \
164   ((GstVaapiVideoAllocator *) (allocator))
165
166 #define GST_VAAPI_TYPE_VIDEO_ALLOCATOR \
167   (gst_vaapi_video_allocator_get_type ())
168 #define GST_VAAPI_VIDEO_ALLOCATOR(obj) \
169   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_VAAPI_TYPE_VIDEO_ALLOCATOR, \
170       GstVaapiVideoAllocator))
171 #define GST_VAAPI_IS_VIDEO_ALLOCATOR(obj) \
172   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_VAAPI_TYPE_VIDEO_ALLOCATOR))
173
174 /**
175  * GstVaapiVideoAllocator:
176  *
177  * A VA video memory allocator object.
178  */
179 struct _GstVaapiVideoAllocator
180 {
181   GstAllocator parent_instance;
182
183   /*< private >*/
184   GstVideoInfo allocation_info;
185   GstVideoInfo surface_info;
186   GstVaapiVideoPool *surface_pool;
187   GstVideoInfo image_info;
188   GstVaapiVideoPool *image_pool;
189   GstVaapiImageUsageFlags usage_flag;
190 };
191
192 /**
193  * GstVaapiVideoAllocatorClass:
194  *
195  * A VA video memory allocator class.
196  */
197 struct _GstVaapiVideoAllocatorClass
198 {
199   GstAllocatorClass parent_class;
200 };
201
202 G_GNUC_INTERNAL
203 GType
204 gst_vaapi_video_allocator_get_type (void) G_GNUC_CONST;
205
206 G_GNUC_INTERNAL
207 GstAllocator *
208 gst_vaapi_video_allocator_new (GstVaapiDisplay * display,
209     const GstVideoInfo * alloc_info, guint surface_alloc_flags,
210     GstVaapiImageUsageFlags req_usage_flag);
211
212 /* ------------------------------------------------------------------------ */
213 /* --- GstVaapiDmaBufMemory                                             --- */
214 /* ------------------------------------------------------------------------ */
215
216 G_GNUC_INTERNAL
217 GstMemory *
218 gst_vaapi_dmabuf_memory_new (GstAllocator * allocator,
219     GstVaapiVideoMeta * meta);
220
221 G_GNUC_INTERNAL
222 gboolean
223 gst_vaapi_dmabuf_memory_holds_surface (GstMemory * mem);
224
225 /* ------------------------------------------------------------------------ */
226 /* --- GstVaapiDmaBufAllocator                                          --- */
227 /* ------------------------------------------------------------------------ */
228
229 #define GST_VAAPI_DMABUF_ALLOCATOR_CAST(allocator) \
230   ((GstVaapiDmaBufAllocator *) (allocator))
231
232 #define GST_VAAPI_TYPE_DMABUF_ALLOCATOR \
233   (gst_vaapi_dmabuf_allocator_get_type ())
234 #define GST_VAAPI_DMABUF_ALLOCATOR(obj) \
235   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_VAAPI_TYPE_DMABUF_ALLOCATOR, \
236       GstVaapiDmaBufAllocator))
237 #define GST_VAAPI_IS_DMABUF_ALLOCATOR(obj) \
238   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_VAAPI_TYPE_DMABUF_ALLOCATOR))
239
240 #define GST_VAAPI_DMABUF_ALLOCATOR_NAME          "GstVaapiDmaBufAllocator"
241
242 /**
243  * GstVaapiDmaBufAllocator:
244  *
245  * A VA dmabuf memory allocator object.
246  */
247 struct _GstVaapiDmaBufAllocator
248 {
249   GstDmaBufAllocator parent_instance;
250
251   /*< private >*/
252   GstPadDirection direction;
253 };
254
255 /**
256  * GstVaapiDmaBufoAllocatorClass:
257  *
258  * A VA dmabuf memory allocator class.
259  */
260 struct _GstVaapiDmaBufAllocatorClass
261 {
262   GstDmaBufAllocatorClass parent_class;
263 };
264
265 G_GNUC_INTERNAL
266 GType
267 gst_vaapi_dmabuf_allocator_get_type (void) G_GNUC_CONST;
268
269 G_GNUC_INTERNAL
270 GstAllocator *
271 gst_vaapi_dmabuf_allocator_new (GstVaapiDisplay * display,
272     const GstVideoInfo * alloc_info, guint surface_alloc_flags,
273     GstPadDirection direction);
274
275 G_GNUC_INTERNAL
276 const GstVideoInfo *
277 gst_allocator_get_vaapi_video_info (GstAllocator * allocator,
278     guint * out_flags_ptr);
279
280 G_GNUC_INTERNAL
281 gboolean
282 gst_allocator_set_vaapi_video_info (GstAllocator * allocator,
283     const GstVideoInfo * alloc_info, guint surface_alloc_flags);
284
285 G_GNUC_INTERNAL
286 void
287 gst_allocator_set_vaapi_negotiated_video_info (GstAllocator * allocator,
288     const GstVideoInfo * negotiated_vinfo);
289
290 G_GNUC_INTERNAL
291 GstVideoInfo *
292 gst_allocator_get_vaapi_negotiated_video_info (GstAllocator * allocator);
293
294 G_GNUC_INTERNAL
295 gboolean
296 gst_vaapi_is_dmabuf_allocator (GstAllocator * allocator);
297
298 G_GNUC_INTERNAL
299 gboolean
300 gst_vaapi_dmabuf_can_map (GstVaapiDisplay * display, GstAllocator * allocator);
301
302 G_END_DECLS
303
304 #endif /* GST_VAAPI_VIDEO_MEMORY_H */