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