2 * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
4 * gstmemory.h: Header for memory blocks
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.
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.
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.
23 #ifndef __GST_MEMORY_H__
24 #define __GST_MEMORY_H__
26 #include <gst/gstconfig.h>
28 #include <glib-object.h>
32 typedef struct _GstMemory GstMemory;
33 typedef struct _GstMemoryInfo GstMemoryInfo;
34 typedef struct _GstMemoryImpl GstMemoryImpl;
37 GST_MEMORY_FLAG_READONLY = (1 << 0),
38 GST_MEMORY_FLAG_MUTABLE = (1 << 1),
43 * @impl: pointer to the #GstMemoryImpl
45 * @paret: parent memory block
47 * Base structure for memory implementations. Custom memory will put this structure
48 * as the first member of their structure.
51 const GstMemoryImpl *impl;
64 * GST_MEMORY_TRACE_NAME:
66 * The name used for tracing memory allocations.
68 #define GST_MEMORY_TRACE_NAME "GstMemory"
70 typedef gsize (*GstMemoryGetSizesFunction) (GstMemory *mem, gsize *maxsize);
72 typedef gpointer (*GstMemoryMapFunction) (GstMemory *mem, gsize *size, gsize *maxsize,
74 typedef gboolean (*GstMemoryUnmapFunction) (GstMemory *mem, gpointer data, gsize size);
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,
89 * The #GstMemoryInfo is used to register new memory implementations.
91 struct _GstMemoryInfo {
92 GstMemoryGetSizesFunction get_sizes;
93 GstMemoryTrimFunction trim;
94 GstMemoryMapFunction map;
95 GstMemoryUnmapFunction unmap;
96 GstMemoryFreeFunction free;
98 GstMemoryCopyFunction copy;
99 GstMemoryExtractFunction extract;
100 GstMemorySubFunction sub;
101 GstMemoryIsSpanFunction is_span;
104 void _gst_memory_init (void);
106 GstMemory * gst_memory_ref (GstMemory *mem);
107 void gst_memory_unref (GstMemory *mem);
109 gsize gst_memory_get_sizes (GstMemory *mem, gsize *maxsize);
110 void gst_memory_trim (GstMemory *mem, gsize offset, gsize size);
112 gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize,
114 gboolean gst_memory_unmap (GstMemory *mem, gpointer data, gsize size);
116 GstMemory * gst_memory_copy (GstMemory *mem);
117 void gst_memory_extract (GstMemory *mem, gsize offset, gpointer dest,
119 GstMemory * gst_memory_sub (GstMemory *mem, gsize offset, gsize size);
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);
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);
135 const GstMemoryImpl * gst_memory_register (const gchar *impl, const GstMemoryInfo *info);
138 const GstMemoryInfo * gst_memory_get_info (const gchar * impl);
143 #endif /* __GST_MEMORY_H__ */