1/*
2 * GStreamer
3 * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
4 *
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.
9 *
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.
14 *
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.
19 */
20
21#ifndef _GST_GL_MEMORY_H_
22#define _GST_GL_MEMORY_H_
23
24#include <gst/gl/gstglbasememory.h>
25#include <gst/gl/gstglformat.h>
26
27G_BEGIN_DECLS
28
29#define GST_TYPE_GL_MEMORY_ALLOCATOR (gst_gl_memory_allocator_get_type())
30GST_GL_API
31GType gst_gl_memory_allocator_get_type(void);
32
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))
39
40#define GST_GL_MEMORY_CAST(obj) ((GstGLMemory *) obj)
41
42/**
43 * GST_CAPS_FEATURE_MEMORY_GL_MEMORY:
44 *
45 * Name of the caps feature for indicating the use of #GstGLMemory
46 */
47#define GST_CAPS_FEATURE_MEMORY_GL_MEMORY "memory:GLMemory"
48/**
49 * GST_GL_MEMORY_VIDEO_EXT_FORMATS: (skip)
50 */
51#if G_BYTE_ORDER == G_LITTLE_ENDIAN
52#define GST_GL_MEMORY_VIDEO_EXT_FORMATS \
53 ", BGR10A2_LE, RGB10A2_LE, P010_10LE, P012_LE, P016_LE, Y212_LE, Y412_LE"
54#else
55#define GST_GL_MEMORY_VIDEO_EXT_FORMATS \
56 ", P010_10BE, P012_BE, P016_BE, Y212_BE, Y412_BE"
57#endif
58
59/**
60 * GST_GL_MEMORY_VIDEO_FORMATS_STR:
61 *
62 * List of video formats that are supported by #GstGLMemory
63 */
64#define GST_GL_MEMORY_VIDEO_FORMATS_STR \
65 "{ RGBA, BGRA, RGBx, BGRx, ARGB, ABGR, xRGB, xBGR, GBRA, GBR, RGBP, BGRP, RGB, BGR, RGB16, BGR16, " \
66 "AYUV, VUYA, Y410, I420, YV12, NV12, NV21, NV16, NV61, YUY2, UYVY, Y210, Y41B, " \
67 "Y42B, Y444, GRAY8, GRAY16_LE, GRAY16_BE, ARGB64, A420, AV12" \
68 GST_GL_MEMORY_VIDEO_EXT_FORMATS "}"
69
70/**
71 * GstGLMemory:
72 * @mem: the parent #GstGLBaseMemory object
73 * @tex_id: the GL texture id for this memory
74 * @tex_target: the GL texture target for this memory
75 * @tex_format: the texture type
76 * @info: the texture's #GstVideoInfo
77 * @valign: data alignment for system memory mapping
78 * @plane: data plane in @info
79 * @tex_scaling: GL shader scaling parameters for @valign and/or width/height
80 *
81 * Represents information about a GL texture
82 */
83struct _GstGLMemory
84{
85 GstGLBaseMemory mem;
86
87 guint tex_id;
88 GstGLTextureTarget tex_target;
89 GstGLFormat tex_format;
90 GstVideoInfo info;
91 GstVideoAlignment valign;
92 guint plane;
93 gfloat tex_scaling[2];
94
95 /*< protected >*/
96 gboolean texture_wrapped;
97 guint unpack_length;
98 guint tex_width;
99
100 /*< private >*/
101 gpointer _padding[GST_PADDING];
102};
103
104
105#define GST_TYPE_GL_VIDEO_ALLOCATION_PARAMS (gst_gl_video_allocation_params_get_type())
106GST_GL_API
107GType gst_gl_video_allocation_params_get_type (void);
108
109typedef struct _GstGLVideoAllocationParams GstGLVideoAllocationParams;
110
111/**
112 * GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO:
113 *
114 * GL allocation flag indicating the allocation of 2D video frames
115 */
116#define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO (1 << 3)
117
118/**
119 * GstGLVideoAllocationParams:
120 * @parent: the parent #GstGLAllocationParams structure
121 * @v_info: the #GstVideoInfo to allocate
122 * @plane: the video plane index to allocate
123 * @valign: the #GstVideoAlignment to align the system representation to (may be %NULL for the default)
124 * @target: the #GstGLTextureTarget to allocate
125 * @tex_format: the #GstGLFormat to allocate
126 */
127struct _GstGLVideoAllocationParams
128{
129 GstGLAllocationParams parent;
130
131 GstVideoInfo *v_info;
132 guint plane;
133 GstVideoAlignment *valign;
134 GstGLTextureTarget target;
135 GstGLFormat tex_format;
136
137 /*< private >*/
138 gpointer _padding[GST_PADDING];
139};
140
141GST_GL_API
142gboolean gst_gl_video_allocation_params_init_full (GstGLVideoAllocationParams * params,
143 gsize struct_size,
144 guint alloc_flags,
145 GstGLAllocationParamsCopyFunc copy,
146 GstGLAllocationParamsFreeFunc free,
147 GstGLContext * context,
148 const GstAllocationParams * alloc_params,
149 const GstVideoInfo * v_info,
150 guint plane,
151 const GstVideoAlignment * valign,
152 GstGLTextureTarget target,
153 GstGLFormat tex_format,
154 gpointer wrapped_data,
155 gpointer gl_handle,
156 gpointer user_data,
157 GDestroyNotify notify);
158GST_GL_API
159GstGLVideoAllocationParams * gst_gl_video_allocation_params_new (GstGLContext * context,
160 const GstAllocationParams * alloc_params,
161 const GstVideoInfo * v_info,
162 guint plane,
163 const GstVideoAlignment * valign,
164 GstGLTextureTarget target,
165 GstGLFormat tex_format);
166GST_GL_API
167GstGLVideoAllocationParams * gst_gl_video_allocation_params_new_wrapped_data (GstGLContext * context,
168 const GstAllocationParams * alloc_params,
169 const GstVideoInfo * v_info,
170 guint plane,
171 const GstVideoAlignment * valign,
172 GstGLTextureTarget target,
173 GstGLFormat tex_format,
174 gpointer wrapped_data,
175 gpointer user_data,
176 GDestroyNotify notify);
177
178GST_GL_API
179GstGLVideoAllocationParams * gst_gl_video_allocation_params_new_wrapped_texture (GstGLContext * context,
180 const GstAllocationParams * alloc_params,
181 const GstVideoInfo * v_info,
182 guint plane,
183 const GstVideoAlignment * valign,
184 GstGLTextureTarget target,
185 GstGLFormat tex_format,
186 guint tex_id,
187 gpointer user_data,
188 GDestroyNotify notify);
189
190GST_GL_API
191GstGLVideoAllocationParams * gst_gl_video_allocation_params_new_wrapped_gl_handle (GstGLContext * context,
192 const GstAllocationParams * alloc_params,
193 const GstVideoInfo * v_info,
194 guint plane,
195 const GstVideoAlignment * valign,
196 GstGLTextureTarget target,
197 GstGLFormat tex_format,
198 gpointer gl_handle,
199 gpointer user_data,
200 GDestroyNotify notify);
201
202/* subclass usage */
203GST_GL_API
204void gst_gl_video_allocation_params_free_data (GstGLVideoAllocationParams * params);
205/* subclass usage */
206GST_GL_API
207void gst_gl_video_allocation_params_copy_data (GstGLVideoAllocationParams * src_vid,
208 GstGLVideoAllocationParams * dest_vid);
209
210/**
211 * GstGLMemoryAllocator
212 *
213 * Opaque #GstGLMemoryAllocator struct
214 */
215struct _GstGLMemoryAllocator
216{
217 /*< private >*/
218 GstGLBaseMemoryAllocator parent;
219
220 gpointer _padding[GST_PADDING];
221};
222
223/**
224 * GstGLMemoryAllocatorClass:
225 * @map: provide a custom map implementation
226 * @copy: provide a custom copy implementation
227 * @unmap: provide a custom unmap implementation
228 */
229struct _GstGLMemoryAllocatorClass
230{
231 /*< private >*/
232 GstGLBaseMemoryAllocatorClass parent_class;
233
234 /*< public >*/
235 GstGLBaseMemoryAllocatorMapFunction map;
236 GstGLBaseMemoryAllocatorCopyFunction copy;
237 GstGLBaseMemoryAllocatorUnmapFunction unmap;
238
239 /*< private >*/
240 gpointer _padding[GST_PADDING];
241};
242
243#include <gst/gl/gstglbasememory.h>
244
245/**
246 * GST_GL_MEMORY_ALLOCATOR_NAME:
247 *
248 * The name of the GL memory allocator
249 */
250#define GST_GL_MEMORY_ALLOCATOR_NAME "GLMemory"
251
252/**
253 * GST_TYPE_GL_MEMORY:
254 *
255 * Since: 1.20
256 */
257#define GST_TYPE_GL_MEMORY (gst_gl_memory_get_type())
258GST_GL_API
259GType gst_gl_memory_get_type(void);
260
261GST_GL_API
262void gst_gl_memory_init_once (void);
263GST_GL_API
264gboolean gst_is_gl_memory (GstMemory * mem);
265
266GST_GL_API
267void gst_gl_memory_init (GstGLMemory * mem,
268 GstAllocator * allocator,
269 GstMemory * parent,
270 GstGLContext * context,
271 GstGLTextureTarget target,
272 GstGLFormat tex_format,
273 const GstAllocationParams *params,
274 const GstVideoInfo * info,
275 guint plane,
276 const GstVideoAlignment *valign,
277 gpointer user_data,
278 GDestroyNotify notify);
279
280GST_GL_API
281gboolean gst_gl_memory_copy_into (GstGLMemory *gl_mem,
282 guint tex_id,
283 GstGLTextureTarget target,
284 GstGLFormat tex_format,
285 gint width,
286 gint height);
287GST_GL_API
288gboolean gst_gl_memory_copy_teximage (GstGLMemory * src,
289 guint tex_id,
290 GstGLTextureTarget out_target,
291 GstGLFormat out_tex_format,
292 gint out_width,
293 gint out_height);
294
295GST_GL_API
296gboolean gst_gl_memory_read_pixels (GstGLMemory * gl_mem,
297 gpointer write_pointer);
298GST_GL_API
299void gst_gl_memory_texsubimage (GstGLMemory * gl_mem,
300 gpointer read_pointer);
301
302/* accessors */
303GST_GL_API
304gint gst_gl_memory_get_texture_width (GstGLMemory * gl_mem);
305GST_GL_API
306gint gst_gl_memory_get_texture_height (GstGLMemory * gl_mem);
307GST_GL_API
308GstGLFormat gst_gl_memory_get_texture_format (GstGLMemory * gl_mem);
309GST_GL_API
310GstGLTextureTarget gst_gl_memory_get_texture_target (GstGLMemory * gl_mem);
311GST_GL_API
312guint gst_gl_memory_get_texture_id (GstGLMemory * gl_mem);
313
314GST_GL_API
315gboolean gst_gl_memory_setup_buffer (GstGLMemoryAllocator * allocator,
316 GstBuffer * buffer,
317 GstGLVideoAllocationParams * params,
318 GstGLFormat *tex_formats,
319 gpointer *wrapped_data,
320 gsize n_wrapped_pointers);
321
322GST_GL_API
323GstGLMemoryAllocator * gst_gl_memory_allocator_get_default (GstGLContext *context);
324
325G_END_DECLS
326
327#endif /* _GST_GL_MEMORY_H_ */
328

source code of include/gstreamer-1.0/gst/gl/gstglmemory.h