memory: more fixes
[platform/upstream/gstreamer.git] / gst / gstmemory.h
1 /* GStreamer
2  * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
3  *
4  * gstmemory.h: Header for memory blocks
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22
23 #ifndef __GST_MEMORY_H__
24 #define __GST_MEMORY_H__
25
26 #include <gst/gstconfig.h>
27
28 #include <glib-object.h>
29
30 G_BEGIN_DECLS
31
32 typedef struct _GstMemory GstMemory;
33 typedef struct _GstMemoryInfo GstMemoryInfo;
34 typedef struct _GstMemoryImpl GstMemoryImpl;
35
36 typedef enum {
37   GST_MEMORY_FLAG_READONLY = (1 << 0),
38   GST_MEMORY_FLAG_MUTABLE  = (1 << 1),
39 } GstMemoryFlags;
40
41 /**
42  * GstMemory:
43  * @impl: pointer to the #GstMemoryImpl
44  * @refcount: refcount
45  * @paret: parent memory block
46  *
47  * Base structure for memory implementations. Custom memory will put this structure
48  * as the first member of their structure.
49  */
50 struct _GstMemory {
51   const GstMemoryImpl *impl;
52
53   GstMemoryFlags  flags;
54   gint            refcount;
55   GstMemory      *parent;
56 };
57
58 typedef enum {
59   GST_MAP_READ,
60   GST_MAP_WRITE,
61 } GstMapFlags;
62
63 /**
64  * GST_MEMORY_TRACE_NAME:
65  *
66  * The name used for tracing memory allocations.
67  */
68 #define GST_MEMORY_TRACE_NAME           "GstMemory"
69
70 typedef gsize (*GstMemoryGetSizesFunction)  (GstMemory *mem, gsize *maxsize);
71
72 typedef gpointer (*GstMemoryMapFunction)    (GstMemory *mem, gsize *size, gsize *maxsize,
73                                              GstMapFlags flags);
74 typedef gboolean (*GstMemoryUnmapFunction)  (GstMemory *mem, gpointer data, gsize size);
75
76 typedef void        (*GstMemoryFreeFunction)      (GstMemory *mem);
77 typedef GstMemory * (*GstMemoryCopyFunction)      (GstMemory *mem);
78 typedef void        (*GstMemoryExtractFunction)   (GstMemory *mem, gsize offset,
79                                                    gpointer dest, gsize size);
80 typedef void        (*GstMemoryTrimFunction)  (GstMemory *mem, gsize offset, gsize size);
81 typedef GstMemory * (*GstMemorySubFunction)   (GstMemory *mem, gsize offset, gsize size);
82 typedef gboolean    (*GstMemoryIsSpanFunction) (GstMemory *mem1, GstMemory *mem2,
83                                                 gsize *offset);
84
85 /**
86  * GstMemoryInfo:
87  * @get_sizes:
88  *
89  * The #GstMemoryInfo is used to register new memory implementations.
90  */
91 struct _GstMemoryInfo {
92   GstMemoryGetSizesFunction get_sizes;
93   GstMemoryTrimFunction     trim;
94   GstMemoryMapFunction      map;
95   GstMemoryUnmapFunction    unmap;
96   GstMemoryFreeFunction     free;
97
98   GstMemoryCopyFunction     copy;
99   GstMemoryExtractFunction  extract;
100   GstMemorySubFunction      sub;
101   GstMemoryIsSpanFunction   is_span;
102 };
103
104 void _gst_memory_init (void);
105
106 GstMemory * gst_memory_ref        (GstMemory *mem);
107 void        gst_memory_unref      (GstMemory *mem);
108
109 gsize       gst_memory_get_sizes  (GstMemory *mem, gsize *maxsize);
110 void        gst_memory_trim       (GstMemory *mem, gsize offset, gsize size);
111
112 gpointer    gst_memory_map        (GstMemory *mem, gsize *size, gsize *maxsize,
113                                    GstMapFlags flags);
114 gboolean    gst_memory_unmap      (GstMemory *mem, gpointer data, gsize size);
115
116 GstMemory * gst_memory_copy       (GstMemory *mem);
117 void        gst_memory_extract    (GstMemory *mem, gsize offset, gpointer dest,
118                                    gsize size);
119 GstMemory * gst_memory_sub        (GstMemory *mem, gsize offset, gsize size);
120
121 gboolean    gst_memory_is_span    (GstMemory **mem1, gsize len1,
122                                    GstMemory **mem2, gsize len2,
123                                    GstMemory **parent, gsize *offset);
124 GstMemory * gst_memory_span       (GstMemory **mem1, gsize len1, gsize offset,
125                                    GstMemory **mem2, gsize len2, gsize size);
126
127
128 GstMemory * gst_memory_new_wrapped (gpointer data, GFreeFunc free_func,
129                                     gsize maxsize, gsize offset, gsize size);
130 GstMemory * gst_memory_new_alloc   (gsize maxsize, gsize align);
131 GstMemory * gst_memory_new_copy    (gsize maxsize, gsize align, gpointer data,
132                                     gsize offset, gsize size);
133
134
135 const GstMemoryImpl *  gst_memory_register    (const gchar *impl, const GstMemoryInfo *info);
136
137 #if 0
138 const GstMemoryInfo *  gst_memory_get_info    (const gchar * impl);
139 #endif
140
141 G_END_DECLS
142
143 #endif /* __GST_MEMORY_H__ */