memory: add memory implementation
[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/gst.h>
27
28 G_BEGIN_DECLS
29
30 typedef struct _GstMemory GstMemory;
31 typedef struct _GstMemoryInfo GstMemoryInfo;
32 typedef struct _GstMemoryImpl GstMemoryImpl;
33
34 /**
35  * GstMemory:
36  * @info: pointer to the #GstMemoryInfo
37  *
38  * Base structure for memory implementations. Custom memory will put this structure
39  * as the first member of their structure.
40  */
41 struct _GstMemory {
42   const GstMemoryImpl *impl;
43
44   gint refcount;
45 };
46
47 typedef enum {
48   GST_MAP_READ,
49   GST_MAP_WRITE,
50 } GstMapFlags;
51
52 /**
53  * GST_MEMORY_TRACE_NAME:
54  *
55  * The name used for tracing memory allocations.
56  */
57 #define GST_MEMORY_TRACE_NAME           "GstMemory"
58
59 typedef gsize (*GstMemoryGetSizesFunction)  (GstMemory *mem, gsize *maxsize);
60
61 typedef void  (*GstMemorySetSizeFunction)   (GstMemory *mem, gsize size);
62 typedef gpointer (*GstMemoryMapFunction)    (GstMemory *mem, gsize *size, gsize *maxsize,
63                                              GstMapFlags flags);
64 typedef gboolean (*GstMemoryUnmapFunction)  (GstMemory *mem, gpointer data, gsize size);
65
66 typedef void        (*GstMemoryFreeFunction)  (GstMemory *mem);
67 typedef GstMemory * (*GstMemoryCopyFunction)  (GstMemory *mem);
68
69 /**
70  * GstMemoryInfo:
71  * @impl: tag indentifying the implementor of the api
72  * @size: size of the memory structure
73  *
74  * The #GstMemoryInfo provides information about a specific metadata
75  * structure.
76  */
77 struct _GstMemoryInfo {
78   GstMemoryGetSizesFunction get_sizes;
79   GstMemorySetSizeFunction  set_size;
80   GstMemoryMapFunction      map;
81   GstMemoryUnmapFunction    unmap;
82   GstMemoryFreeFunction     free;
83   GstMemoryCopyFunction     copy;
84 };
85
86 void _gst_memory_init (void);
87
88 GstMemory * gst_memory_ref        (GstMemory *mem);
89 void        gst_memory_unref      (GstMemory *mem);
90
91 gsize       gst_memory_get_sizes  (GstMemory *mem, gsize *maxsize);
92 void        gst_memory_set_size   (GstMemory *mem, gsize size);
93
94 gpointer    gst_memory_map        (GstMemory *mem, gsize *size, gsize *maxsize,
95                                    GstMapFlags flags);
96 gboolean    gst_memory_unmap      (GstMemory *mem, gpointer data, gsize size);
97
98 GstMemory * gst_memory_copy       (GstMemory *mem);
99
100
101 GstMemory * gst_memory_new_wrapped (gpointer data, GFreeFunc free_func,
102                                     gsize maxsize, gsize offset, gsize size);
103 GstMemory * gst_memory_new_alloc   (gsize maxsize, gsize align);
104
105
106 const GstMemoryImpl *  gst_memory_register    (const gchar *impl, const GstMemoryInfo *info);
107
108 #if 0
109 const GstMemoryInfo *  gst_memory_get_info    (const gchar * impl);
110 #endif
111
112 G_END_DECLS
113
114 #endif /* __GST_MEMORY_H__ */