3 * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef _GST_GL_MEMORY_H_
22 #define _GST_GL_MEMORY_H_
24 #include <gst/gl/gstglbasememory.h>
25 #include <gst/gl/gstglformat.h>
29 #define GST_TYPE_GL_MEMORY_ALLOCATOR (gst_gl_memory_allocator_get_type())
31 GType gst_gl_memory_allocator_get_type(void);
33 #define GST_IS_GL_MEMORY_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GL_MEMORY_ALLOCATOR))
34 #define GST_IS_GL_MEMORY_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GL_MEMORY_ALLOCATOR))
35 #define GST_GL_MEMORY_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_GL_MEMORY_ALLOCATOR, GstGLMemoryAllocatorClass))
36 #define GST_GL_MEMORY_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GL_MEMORY_ALLOCATOR, GstGLMemoryAllocator))
37 #define GST_GL_MEMORY_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_GL_MEMORY_ALLOCATOR, GstGLMemoryAllocatorClass))
38 #define GST_GL_MEMORY_ALLOCATOR_CAST(obj) ((GstGLMemoryAllocator *)(obj))
40 #define GST_GL_MEMORY_CAST(obj) ((GstGLMemory *) obj)
43 * GST_CAPS_FEATURE_MEMORY_GL_MEMORY:
45 * Name of the caps feature for indicating the use of #GstGLMemory
47 #define GST_CAPS_FEATURE_MEMORY_GL_MEMORY "memory:GLMemory"
49 * GST_GL_MEMORY_VIDEO_FORMATS_STR:
51 * List of video formats that are supported by #GstGLMemory
53 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
54 #define MEMORY_VIDEO_EXT_FORMATS ", BGR10A2_LE, RGB10A2_LE, P010_10LE, P016_LE"
56 #define MEMORY_VIDEO_EXT_FORMATS ", P010_10BE, P016_BE"
59 #define GST_GL_MEMORY_VIDEO_FORMATS_STR \
60 "{ RGBA, BGRA, RGBx, BGRx, ARGB, ABGR, xRGB, xBGR, RGB, BGR, RGB16, BGR16, " \
61 "AYUV, VUYA, Y410, I420, YV12, NV12, NV21, YUY2, UYVY, Y41B, Y42B, Y444, " \
62 "GRAY8, GRAY16_LE, GRAY16_BE, ARGB64" MEMORY_VIDEO_EXT_FORMATS "}"
66 * @mem: the parent #GstGLBaseMemory object
67 * @tex_id: the GL texture id for this memory
68 * @tex_target: the GL texture target for this memory
69 * @tex_format: the texture type
70 * @info: the texture's #GstVideoInfo
71 * @valign: data alignment for system memory mapping
72 * @plane: data plane in @info
73 * @tex_scaling: GL shader scaling parameters for @valign and/or width/height
75 * Represents information about a GL texture
82 GstGLTextureTarget tex_target;
83 GstGLFormat tex_format;
85 GstVideoAlignment valign;
87 gfloat tex_scaling[2];
90 gboolean texture_wrapped;
95 gpointer _padding[GST_PADDING];
99 #define GST_TYPE_GL_VIDEO_ALLOCATION_PARAMS (gst_gl_video_allocation_params_get_type())
101 GType gst_gl_video_allocation_params_get_type (void);
103 typedef struct _GstGLVideoAllocationParams GstGLVideoAllocationParams;
106 * GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO:
108 * GL allocation flag indicating the allocation of 2D video frames
110 #define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO (1 << 3)
113 * GstGLVideoAllocationParams:
114 * @parent: the parent #GstGLAllocationParams structure
115 * @v_info: the #GstVideoInfo to allocate
116 * @plane: the video plane index to allocate
117 * @valign: the #GstVideoAlignment to align the system representation to (may be %NULL for the default)
118 * @target: the #GstGLTextureTarget to allocate
119 * @tex_format: the #GstGLFormat to allocate
121 struct _GstGLVideoAllocationParams
123 GstGLAllocationParams parent;
125 GstVideoInfo *v_info;
127 GstVideoAlignment *valign;
128 GstGLTextureTarget target;
129 GstGLFormat tex_format;
132 gpointer _padding[GST_PADDING];
136 gboolean gst_gl_video_allocation_params_init_full (GstGLVideoAllocationParams * params,
139 GstGLAllocationParamsCopyFunc copy,
140 GstGLAllocationParamsFreeFunc free,
141 GstGLContext * context,
142 GstAllocationParams * alloc_params,
143 GstVideoInfo * v_info,
145 GstVideoAlignment * valign,
146 GstGLTextureTarget target,
147 GstGLFormat tex_format,
148 gpointer wrapped_data,
151 GDestroyNotify notify);
153 GstGLVideoAllocationParams * gst_gl_video_allocation_params_new (GstGLContext * context,
154 GstAllocationParams * alloc_params,
155 GstVideoInfo * v_info,
157 GstVideoAlignment * valign,
158 GstGLTextureTarget target,
159 GstGLFormat tex_format);
161 GstGLVideoAllocationParams * gst_gl_video_allocation_params_new_wrapped_data (GstGLContext * context,
162 GstAllocationParams * alloc_params,
163 GstVideoInfo * v_info,
165 GstVideoAlignment * valign,
166 GstGLTextureTarget target,
167 GstGLFormat tex_format,
168 gpointer wrapped_data,
170 GDestroyNotify notify);
173 GstGLVideoAllocationParams * gst_gl_video_allocation_params_new_wrapped_texture (GstGLContext * context,
174 GstAllocationParams * alloc_params,
175 GstVideoInfo * v_info,
177 GstVideoAlignment * valign,
178 GstGLTextureTarget target,
179 GstGLFormat tex_format,
182 GDestroyNotify notify);
185 GstGLVideoAllocationParams * gst_gl_video_allocation_params_new_wrapped_gl_handle (GstGLContext * context,
186 GstAllocationParams * alloc_params,
187 GstVideoInfo * v_info,
189 GstVideoAlignment * valign,
190 GstGLTextureTarget target,
191 GstGLFormat tex_format,
194 GDestroyNotify notify);
198 void gst_gl_video_allocation_params_free_data (GstGLVideoAllocationParams * params);
201 void gst_gl_video_allocation_params_copy_data (GstGLVideoAllocationParams * src_vid,
202 GstGLVideoAllocationParams * dest_vid);
205 * GstGLMemoryAllocator
207 * Opaque #GstGLMemoryAllocator struct
209 struct _GstGLMemoryAllocator
212 GstGLBaseMemoryAllocator parent;
214 gpointer _padding[GST_PADDING];
218 * GstGLMemoryAllocatorClass:
219 * @map: provide a custom map implementation
220 * @copy: provide a custom copy implementation
221 * @unmap: provide a custom unmap implementation
223 struct _GstGLMemoryAllocatorClass
226 GstGLBaseMemoryAllocatorClass parent_class;
229 GstGLBaseMemoryAllocatorMapFunction map;
230 GstGLBaseMemoryAllocatorCopyFunction copy;
231 GstGLBaseMemoryAllocatorUnmapFunction unmap;
234 gpointer _padding[GST_PADDING];
237 #include <gst/gl/gstglbasememory.h>
240 * GST_GL_MEMORY_ALLOCATOR_NAME:
242 * The name of the GL memory allocator
244 #define GST_GL_MEMORY_ALLOCATOR_NAME "GLMemory"
247 void gst_gl_memory_init_once (void);
249 gboolean gst_is_gl_memory (GstMemory * mem);
252 void gst_gl_memory_init (GstGLMemory * mem,
253 GstAllocator * allocator,
255 GstGLContext * context,
256 GstGLTextureTarget target,
257 GstGLFormat tex_format,
258 GstAllocationParams *params,
261 GstVideoAlignment *valign,
263 GDestroyNotify notify);
266 gboolean gst_gl_memory_copy_into (GstGLMemory *gl_mem,
268 GstGLTextureTarget target,
269 GstGLFormat tex_format,
273 gboolean gst_gl_memory_copy_teximage (GstGLMemory * src,
275 GstGLTextureTarget out_target,
276 GstGLFormat out_tex_format,
281 gboolean gst_gl_memory_read_pixels (GstGLMemory * gl_mem,
282 gpointer read_pointer);
284 void gst_gl_memory_texsubimage (GstGLMemory * gl_mem,
285 gpointer read_pointer);
289 gint gst_gl_memory_get_texture_width (GstGLMemory * gl_mem);
291 gint gst_gl_memory_get_texture_height (GstGLMemory * gl_mem);
293 GstGLFormat gst_gl_memory_get_texture_format (GstGLMemory * gl_mem);
295 GstGLTextureTarget gst_gl_memory_get_texture_target (GstGLMemory * gl_mem);
297 guint gst_gl_memory_get_texture_id (GstGLMemory * gl_mem);
300 gboolean gst_gl_memory_setup_buffer (GstGLMemoryAllocator * allocator,
302 GstGLVideoAllocationParams * params,
303 GstGLFormat *tex_formats,
304 gpointer *wrapped_data,
305 gsize n_wrapped_pointers);
308 GstGLMemoryAllocator * gst_gl_memory_allocator_get_default (GstGLContext *context);
312 #endif /* _GST_GL_MEMORY_H_ */