1 /*
2  * GStreamer
3  * Copyright (C) 2015 Alessandro Decina <twi@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_IO_SURFACE_MEMORY_H_
22 #define _GST_IO_SURFACE_MEMORY_H_
23 
24 #include <IOSurface/IOSurface.h>
25 #include <gst/gst.h>
26 #include <gst/gstallocator.h>
27 #include <gst/video/video.h>
28 #include <gst/gl/gl.h>
29 #include <gst/gl/gstglfuncs.h>
30 
31 G_BEGIN_DECLS
32 
33 #define GST_TYPE_IO_SURFACE_MEMORY_ALLOCATOR (gst_io_surface_memory_allocator_get_type())
34 GType gst_io_surface_memory_allocator_get_type(void);
35 
36 #define GST_IS_IO_SURFACE_MEMORY_ALLOCATOR(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_IO_SURFACE_MEMORY_ALLOCATOR))
37 #define GST_IS_IO_SURFACE_MEMORY_ALLOCATOR_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_IO_SURFACE_MEMORY_ALLOCATOR))
38 #define GST_IO_SURFACE_MEMORY_ALLOCATOR_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_IO_SURFACE_MEMORY_ALLOCATOR, GstIOSurfaceMemoryAllocatorClass))
39 #define GST_IO_SURFACE_MEMORY_ALLOCATOR(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_IO_SURFACE_MEMORY_ALLOCATOR, GstIOSurfaceMemoryAllocator))
40 #define GST_IO_SURFACE_MEMORY_ALLOCATOR_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_IO_SURFACE_MEMORY_ALLOCATOR, GstIOSurfaceMemoryAllocatorClass))
41 #define GST_IO_SURFACE_MEMORY_ALLOCATOR_CAST(obj)            ((GstIOSurfaceMemoryAllocator *)(obj))
42 
43 typedef struct _GstIOSurfaceMemory
44 {
45   GstGLMemory gl_mem;
46   IOSurfaceRef surface;
47 } GstIOSurfaceMemory;
48 
49 #define GST_IO_SURFACE_MEMORY_ALLOCATOR_NAME   "IOSurfaceMemory"
50 
51 void gst_ios_surface_memory_init (void);
52 
53 GstIOSurfaceMemory *
54 gst_io_surface_memory_wrapped (GstGLContext * context,
55     IOSurfaceRef surface,
56     GstGLTextureTarget target,
57     GstGLFormat tex_format,
58     GstVideoInfo * info,
59     guint plane,
60     GstVideoAlignment *valign,
61     gpointer user_data,
62     GDestroyNotify notify);
63 
64 void gst_io_surface_memory_set_surface (GstIOSurfaceMemory *memory, IOSurfaceRef surface);
65 
66 gboolean gst_is_io_surface_memory (GstMemory * mem);
67 
68 typedef struct _GstIOSurfaceMemoryAllocator
69 {
70   GstGLMemoryAllocator allocator;
71 } GstIOSurfaceMemoryAllocator;
72 
73 typedef struct _GstIOSurfaceMemoryAllocatorClass
74 {
75   GstGLMemoryAllocatorClass parent_class;
76 } GstIOSurfaceMemoryAllocatorClass;
77 
78 G_END_DECLS
79 
80 #endif /* _GST_IO_SURFACE_MEMORY_H_ */
81