2 * gstvaapivideomemory.h - Gstreamer/VA video memory
4 * Copyright (C) 2013 Intel Corporation
5 * Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
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.
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.
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
23 #ifndef GST_VAAPI_VIDEO_MEMORY_H
24 #define GST_VAAPI_VIDEO_MEMORY_H
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>
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;
41 /* ------------------------------------------------------------------------ */
42 /* --- GstVaapiVideoMemory --- */
43 /* ------------------------------------------------------------------------ */
45 #define GST_VAAPI_VIDEO_MEMORY_CAST(mem) \
46 ((GstVaapiVideoMemory *) (mem))
48 #define GST_VAAPI_IS_VIDEO_MEMORY(mem) \
49 ((mem) && (mem)->allocator && GST_VAAPI_IS_VIDEO_ALLOCATOR((mem)->allocator))
51 #define GST_VAAPI_VIDEO_MEMORY_NAME "GstVaapiVideoMemory"
53 #define GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE "memory:VASurface"
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)
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
71 * The set of all #GstVaapiVideoMemory map types.
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;
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.
87 * The set of extended #GstMemory flags.
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;
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.
104 * Set the usage of GstVaapiImage in GstVaapiVideoMemory.
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;
113 * GstVaapiVideoMemory:
115 * A VA video memory object holder, including VA surfaces, images and
118 struct _GstVaapiVideoMemory
120 GstMemory parent_instance;
123 GstVaapiSurfaceProxy *proxy;
124 const GstVideoInfo *surface_info;
125 GstVaapiSurface *surface;
126 const GstVideoInfo *image_info;
127 GstVaapiImage *image;
128 GstVaapiVideoMeta *meta;
131 VASurfaceID map_surface_id;
132 GstVaapiImageUsageFlags usage_flag;
138 gst_vaapi_video_memory_new (GstAllocator * allocator, GstVaapiVideoMeta * meta);
142 gst_video_meta_map_vaapi_memory (GstVideoMeta * meta, guint plane,
143 GstMapInfo * info, gpointer * data, gint * stride, GstMapFlags flags);
147 gst_video_meta_unmap_vaapi_memory (GstVideoMeta * meta, guint plane,
152 gst_vaapi_video_memory_reset_surface (GstVaapiVideoMemory * mem);
156 gst_vaapi_video_memory_sync (GstVaapiVideoMemory * mem);
158 /* ------------------------------------------------------------------------ */
159 /* --- GstVaapiVideoAllocator --- */
160 /* ------------------------------------------------------------------------ */
161 #define GST_MAP_VAAPI (GST_MAP_FLAG_LAST << 1)
163 #define GST_VAAPI_VIDEO_ALLOCATOR_CAST(allocator) \
164 ((GstVaapiVideoAllocator *) (allocator))
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))
175 * GstVaapiVideoAllocator:
177 * A VA video memory allocator object.
179 struct _GstVaapiVideoAllocator
181 GstAllocator parent_instance;
184 GstVideoInfo allocation_info;
185 GstVideoInfo surface_info;
186 GstVaapiVideoPool *surface_pool;
187 GstVideoInfo image_info;
188 GstVaapiVideoPool *image_pool;
189 GstVaapiImageUsageFlags usage_flag;
193 * GstVaapiVideoAllocatorClass:
195 * A VA video memory allocator class.
197 struct _GstVaapiVideoAllocatorClass
199 GstAllocatorClass parent_class;
204 gst_vaapi_video_allocator_get_type (void) G_GNUC_CONST;
208 gst_vaapi_video_allocator_new (GstVaapiDisplay * display,
209 const GstVideoInfo * alloc_info, guint surface_alloc_flags,
210 GstVaapiImageUsageFlags req_usage_flag);
212 /* ------------------------------------------------------------------------ */
213 /* --- GstVaapiDmaBufMemory --- */
214 /* ------------------------------------------------------------------------ */
218 gst_vaapi_dmabuf_memory_new (GstAllocator * allocator,
219 GstVaapiVideoMeta * meta);
223 gst_vaapi_dmabuf_memory_holds_surface (GstMemory * mem);
225 /* ------------------------------------------------------------------------ */
226 /* --- GstVaapiDmaBufAllocator --- */
227 /* ------------------------------------------------------------------------ */
229 #define GST_VAAPI_DMABUF_ALLOCATOR_CAST(allocator) \
230 ((GstVaapiDmaBufAllocator *) (allocator))
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))
240 #define GST_VAAPI_DMABUF_ALLOCATOR_NAME "GstVaapiDmaBufAllocator"
243 * GstVaapiDmaBufAllocator:
245 * A VA dmabuf memory allocator object.
247 struct _GstVaapiDmaBufAllocator
249 GstDmaBufAllocator parent_instance;
252 GstPadDirection direction;
256 * GstVaapiDmaBufoAllocatorClass:
258 * A VA dmabuf memory allocator class.
260 struct _GstVaapiDmaBufAllocatorClass
262 GstDmaBufAllocatorClass parent_class;
267 gst_vaapi_dmabuf_allocator_get_type (void) G_GNUC_CONST;
271 gst_vaapi_dmabuf_allocator_new (GstVaapiDisplay * display,
272 const GstVideoInfo * alloc_info, guint surface_alloc_flags,
273 GstPadDirection direction);
277 gst_allocator_get_vaapi_video_info (GstAllocator * allocator,
278 guint * out_flags_ptr);
282 gst_allocator_set_vaapi_video_info (GstAllocator * allocator,
283 const GstVideoInfo * alloc_info, guint surface_alloc_flags);
287 gst_allocator_set_vaapi_negotiated_video_info (GstAllocator * allocator,
288 const GstVideoInfo * negotiated_vinfo);
292 gst_allocator_get_vaapi_negotiated_video_info (GstAllocator * allocator);
296 gst_vaapi_is_dmabuf_allocator (GstAllocator * allocator);
300 gst_vaapi_dmabuf_can_map (GstVaapiDisplay * display, GstAllocator * allocator);
304 #endif /* GST_VAAPI_VIDEO_MEMORY_H */