~ubuntu-branches/ubuntu/trusty/gstreamer1.0/trusty

« back to all changes in this revision

Viewing changes to gst/gstmemory.h

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2012-08-08 18:12:33 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120808181233-riejwxprfsxh1njl
Tags: 0.11.93-1
* New upstream release:
  + debian/libgstreamer.symbols:
    - Update symbols file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#define GST_TYPE_MEMORY (gst_memory_get_type())
33
33
GType gst_memory_get_type(void);
34
34
 
35
 
#define GST_TYPE_ALLOCATOR (gst_allocator_get_type())
36
 
GType gst_allocator_get_type(void);
37
 
 
38
 
#define GST_TYPE_ALLOCATION_PARAMS (gst_allocation_params_get_type())
39
 
GType gst_allocation_params_get_type(void);
40
 
 
41
35
typedef struct _GstMemory GstMemory;
42
 
typedef struct _GstMemoryInfo GstMemoryInfo;
43
36
typedef struct _GstAllocator GstAllocator;
44
 
typedef struct _GstAllocationParams GstAllocationParams;
45
 
 
46
 
/**
47
 
 * gst_memory_alignment:
48
 
 *
49
 
 * The default memory alignment in bytes - 1
50
 
 * an alignment of 7 would be the same as what malloc() guarantees.
51
 
 */
52
 
GST_EXPORT gsize gst_memory_alignment;
53
37
 
54
38
#define GST_MEMORY_CAST(mem)   ((GstMemory *)(mem))
55
39
 
66
50
 * Flags for wrapped memory.
67
51
 */
68
52
typedef enum {
69
 
  GST_MEMORY_FLAG_READONLY      = (1 << 0),
70
 
  GST_MEMORY_FLAG_NO_SHARE      = (1 << 1),
71
 
  GST_MEMORY_FLAG_ZERO_PREFIXED = (1 << 2),
72
 
  GST_MEMORY_FLAG_ZERO_PADDED   = (1 << 3),
 
53
  GST_MEMORY_FLAG_READONLY      = GST_MINI_OBJECT_FLAG_LOCK_READONLY,
 
54
  GST_MEMORY_FLAG_NO_SHARE      = (GST_MINI_OBJECT_FLAG_LAST << 0),
 
55
  GST_MEMORY_FLAG_ZERO_PREFIXED = (GST_MINI_OBJECT_FLAG_LAST << 1),
 
56
  GST_MEMORY_FLAG_ZERO_PADDED   = (GST_MINI_OBJECT_FLAG_LAST << 2),
73
57
 
74
 
  GST_MEMORY_FLAG_LAST          = (1 << 16)
 
58
  GST_MEMORY_FLAG_LAST          = (GST_MINI_OBJECT_FLAG_LAST << 16)
75
59
} GstMemoryFlags;
76
60
 
77
61
/**
80
64
 *
81
65
 * A flags word containing #GstMemoryFlags flags set on @mem
82
66
 */
83
 
#define GST_MEMORY_FLAGS(mem)  (GST_MEMORY_CAST (mem)->flags)
 
67
#define GST_MEMORY_FLAGS(mem)  GST_MINI_OBJECT_FLAGS (mem)
84
68
/**
85
69
 * GST_MEMORY_FLAG_IS_SET:
86
70
 * @mem: a #GstMemory.
88
72
 *
89
73
 * Gives the status of a specific flag on a @mem.
90
74
 */
91
 
#define GST_MEMORY_FLAG_IS_SET(mem,flag)   !!(GST_MEMORY_FLAGS (mem) & (flag))
 
75
#define GST_MEMORY_FLAG_IS_SET(mem,flag)   GST_MINI_OBJECT_FLAG_IS_SET (mem,flag)
92
76
/**
93
77
 * GST_MEMORY_FLAG_UNSET:
94
78
 * @mem: a #GstMemory.
96
80
 *
97
81
 * Clear a specific flag on a @mem.
98
82
 */
99
 
#define GST_MEMORY_FLAG_UNSET(mem,flag)   (GST_MEMORY_FLAGS (mem) &= ~(flag))
 
83
#define GST_MEMORY_FLAG_UNSET(mem,flag)   GST_MINI_OBJECT_FLAG_UNSET (mem, flag)
100
84
 
101
85
/**
102
86
 * GST_MEMORY_IS_READONLY:
106
90
 */
107
91
#define GST_MEMORY_IS_READONLY(mem)        GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_READONLY)
108
92
/**
 
93
 * GST_MEMORY_IS_NO_SHARE:
 
94
 * @mem: a #GstMemory.
 
95
 *
 
96
 * Check if @mem cannot be shared between buffers
 
97
 */
 
98
#define GST_MEMORY_IS_NO_SHARE(mem)        GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_NO_SHARE)
 
99
/**
109
100
 * GST_MEMORY_IS_ZERO_PREFIXED:
110
101
 * @mem: a #GstMemory.
111
102
 *
123
114
 
124
115
/**
125
116
 * GstMemory:
 
117
 * @mini_object: parent structure
126
118
 * @allocator: pointer to the #GstAllocator
127
 
 * @flags: memory flags
128
 
 * @refcount: refcount
129
119
 * @parent: parent memory block
130
 
 * @state: private state
131
120
 * @maxsize: the maximum size allocated
132
121
 * @align: the alignment of the memory
133
122
 * @offset: the offset where valid data starts
137
126
 * as the first member of their structure.
138
127
 */
139
128
struct _GstMemory {
 
129
  GstMiniObject   mini_object;
 
130
 
140
131
  GstAllocator   *allocator;
141
132
 
142
 
  GstMemoryFlags  flags;
143
 
  gint            refcount;
144
133
  GstMemory      *parent;
145
 
  volatile gint   state;
146
134
  gsize           maxsize;
147
135
  gsize           align;
148
136
  gsize           offset;
158
146
 * Flags used when mapping memory
159
147
 */
160
148
typedef enum {
161
 
  GST_MAP_READ      = (1 << 0),
162
 
  GST_MAP_WRITE     = (1 << 1),
 
149
  GST_MAP_READ      = GST_LOCK_FLAG_READ,
 
150
  GST_MAP_WRITE     = GST_LOCK_FLAG_WRITE,
163
151
 
164
152
  GST_MAP_FLAG_LAST = (1 << 16)
165
153
} GstMapFlags;
166
154
 
167
155
/**
 
156
 * GST_MAP_READWRITE:
 
157
 *
 
158
 * GstMapFlags value alias for GST_MAP_READ | GST_MAP_WRITE
 
159
 */
 
160
#define GST_MAP_READWRITE      (GST_MAP_READ | GST_MAP_WRITE)
 
161
 
 
162
 
 
163
/**
168
164
 * GstMapInfo:
169
165
 * @memory: a pointer to the mapped memory
170
166
 * @flags: flags used when mapping the memory
171
 
 * @data: a pointer to the mapped data
 
167
 * @data: (array length=size): a pointer to the mapped data
172
168
 * @size: the valid size in @data
173
169
 * @maxsize: the maximum bytes in @data
174
170
 * @user_data: extra private user_data that the implementation of the memory
195
191
#define GST_MAP_INFO_INIT { NULL, 0, NULL, 0, 0, }
196
192
 
197
193
/**
198
 
 * GST_MAP_READWRITE:
199
 
 *
200
 
 * Map for readwrite access
201
 
 */
202
 
#define GST_MAP_READWRITE      (GST_MAP_READ | GST_MAP_WRITE)
203
 
 
204
 
/**
205
 
 * GST_ALLOCATOR_SYSMEM:
206
 
 *
207
 
 * The allocator name for the default system memory allocator
208
 
 */
209
 
#define GST_ALLOCATOR_SYSMEM   "SystemMemory"
210
 
 
211
 
/**
212
 
 * GstAllocationParams:
213
 
 * @flags: flags to control allocation
214
 
 * @align: the desired alignment of the memory
215
 
 * @prefix: the disired prefix
216
 
 * @padding: the desired padding
217
 
 *
218
 
 * Parameters to control the allocation of memory
219
 
 */
220
 
struct _GstAllocationParams {
221
 
  GstMemoryFlags flags;
222
 
  gsize          align;
223
 
  gsize          prefix;
224
 
  gsize          padding;
225
 
 
226
 
  /*< private >*/
227
 
  gpointer _gst_reserved[GST_PADDING];
228
 
};
229
 
 
230
 
/**
231
 
 * GstAllocatorAllocFunction:
232
 
 * @allocator: a #GstAllocator
233
 
 * @size: the size
234
 
 * @params: allocator params
235
 
 * @user_data: user data
236
 
 *
237
 
 * Allocate a new #GstMemory from @allocator that can hold at least @size
238
 
 * bytes (+ padding) and is aligned to (@align + 1) bytes.
239
 
 *
240
 
 * The offset and size of the memory should be set and the prefix/padding must
241
 
 * be filled with 0 if @params flags contains #GST_MEMORY_FLAG_ZERO_PREFIXED and
242
 
 * #GST_MEMORY_FLAG_ZERO_PADDED respectively.
243
 
 *
244
 
 * @user_data is the data that was used when creating @allocator.
245
 
 *
246
 
 * Returns: a newly allocated #GstMemory. Free with gst_memory_unref()
247
 
 */
248
 
typedef GstMemory *  (*GstAllocatorAllocFunction)  (GstAllocator *allocator,
249
 
                                                    gsize size, GstAllocationParams *params,
250
 
                                                    gpointer user_data);
251
 
 
252
 
/**
253
194
 * GstMemoryMapFunction:
254
195
 * @mem: a #GstMemory
255
196
 * @maxsize: size to map
275
216
typedef void        (*GstMemoryUnmapFunction)     (GstMemory *mem);
276
217
 
277
218
/**
278
 
 * GstMemoryFreeFunction:
279
 
 * @mem: a #GstMemory
280
 
 *
281
 
 * Free the memory used by @mem. This function is usually called when the
282
 
 * refcount of the @mem has reached 0.
283
 
 */
284
 
typedef void        (*GstMemoryFreeFunction)      (GstMemory *mem);
285
 
 
286
 
/**
287
219
 * GstMemoryCopyFunction:
288
220
 * @mem: a #GstMemory
289
221
 * @offset: an offset
325
257
 */
326
258
typedef gboolean    (*GstMemoryIsSpanFunction)    (GstMemory *mem1, GstMemory *mem2, gsize *offset);
327
259
 
328
 
/**
329
 
 * GstMemoryInfo:
330
 
 * @mem_type: the memory type this allocator provides
331
 
 * @alloc: the implementation of the GstAllocatorAllocFunction
332
 
 * @mem_map: the implementation of the GstMemoryMapFunction
333
 
 * @mem_unmap: the implementation of the GstMemoryUnmapFunction
334
 
 * @mem_free: the implementation of the GstMemoryFreeFunction
335
 
 * @mem_copy: the implementation of the GstMemoryCopyFunction
336
 
 * @mem_share: the implementation of the GstMemoryShareFunction
337
 
 * @mem_is_span: the implementation of the GstMemoryIsSpanFunction
338
 
 *
339
 
 * The #GstMemoryInfo is used to register new memory allocators and contain
340
 
 * the implementations for various memory operations.
341
 
 */
342
 
struct _GstMemoryInfo {
343
 
  const gchar              *mem_type;
344
 
 
345
 
  GstAllocatorAllocFunction alloc;
346
 
 
347
 
  GstMemoryMapFunction      mem_map;
348
 
  GstMemoryUnmapFunction    mem_unmap;
349
 
  GstMemoryFreeFunction     mem_free;
350
 
 
351
 
  GstMemoryCopyFunction     mem_copy;
352
 
  GstMemoryShareFunction    mem_share;
353
 
  GstMemoryIsSpanFunction   mem_is_span;
354
 
 
355
 
  /*< private >*/
356
 
  gpointer _gst_reserved[GST_PADDING];
357
 
};
358
 
 
359
 
/**
360
 
 * GstAllocator:
361
 
 *
362
 
 * An opaque type returned from gst_allocator_new() or gst_allocator_find()
363
 
 * that can be used to allocator memory.
364
 
 */
365
 
 
366
 
/* allocators */
367
 
GstAllocator * gst_allocator_new             (const GstMemoryInfo * info,
368
 
                                              gpointer user_data, GDestroyNotify notify);
369
 
const gchar *  gst_allocator_get_memory_type (GstAllocator * allocator);
370
 
 
371
 
GstAllocator * gst_allocator_ref             (GstAllocator * allocator);
372
 
void           gst_allocator_unref           (GstAllocator * allocator);
373
 
 
374
 
void           gst_allocator_register        (const gchar *name, GstAllocator *allocator);
375
 
GstAllocator * gst_allocator_find            (const gchar *name);
376
 
 
377
 
void           gst_allocator_set_default     (GstAllocator * allocator);
378
 
 
379
 
/* allocating memory blocks */
380
 
void           gst_allocation_params_init     (GstAllocationParams *params);
381
 
GstAllocationParams *
382
 
               gst_allocation_params_copy     (const GstAllocationParams *params) G_GNUC_MALLOC;
383
 
void           gst_allocation_params_free     (GstAllocationParams *params);
384
 
 
385
 
GstMemory *    gst_allocator_alloc           (GstAllocator * allocator, gsize size,
386
 
                                              GstAllocationParams *params);
387
 
 
388
 
GstMemory *    gst_memory_new_wrapped  (GstMemoryFlags flags, gpointer data, gsize maxsize,
389
 
                                        gsize offset, gsize size, gpointer user_data,
390
 
                                        GDestroyNotify notify);
391
 
 
 
260
void           gst_memory_init         (GstMemory *mem, GstMemoryFlags flags,
 
261
                                        GstAllocator *allocator, GstMemory *parent,
 
262
                                        gsize maxsize, gsize align,
 
263
                                        gsize offset, gsize size);
392
264
/* refcounting */
393
 
GstMemory *    gst_memory_ref          (GstMemory *mem);
394
 
void           gst_memory_unref        (GstMemory *mem);
395
 
 
396
 
gboolean       gst_memory_is_exclusive (GstMemory *mem);
 
265
/**
 
266
 * gst_memory_ref:
 
267
 * @memory: The memory to refcount
 
268
 *
 
269
 * Increase the refcount of this memory.
 
270
 *
 
271
 * Returns: (transfer full): @memory (for convenience when doing assignments)
 
272
 */
 
273
#ifdef _FOOL_GTK_DOC_
 
274
G_INLINE_FUNC GstMemory * gst_memory_ref (GstMemory * memory);
 
275
#endif
 
276
 
 
277
static inline GstMemory *
 
278
gst_memory_ref (GstMemory * memory)
 
279
{
 
280
  return (GstMemory *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (memory));
 
281
}
 
282
 
 
283
/**
 
284
 * gst_memory_unref:
 
285
 * @memory: (transfer full): the memory to refcount
 
286
 *
 
287
 * Decrease the refcount of an memory, freeing it if the refcount reaches 0.
 
288
 */
 
289
#ifdef _FOOL_GTK_DOC_
 
290
G_INLINE_FUNC void gst_memory_unref (GstMemory * memory);
 
291
#endif
 
292
 
 
293
static inline void
 
294
gst_memory_unref (GstMemory * memory)
 
295
{
 
296
  gst_mini_object_unref (GST_MINI_OBJECT_CAST (memory));
 
297
}
397
298
 
398
299
/* getting/setting memory properties */
399
300
gsize          gst_memory_get_sizes    (GstMemory *mem, gsize *offset, gsize *maxsize);
400
301
void           gst_memory_resize       (GstMemory *mem, gssize offset, gsize size);
401
302
 
 
303
#define        gst_memory_lock(m,f)        gst_mini_object_lock (GST_MINI_OBJECT_CAST (m), (f))
 
304
#define        gst_memory_unlock(m,f)      gst_mini_object_unlock (GST_MINI_OBJECT_CAST (m), (f))
 
305
#define        gst_memory_is_writable(m)   gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (m))
 
306
 
402
307
/* retrieving data */
403
308
GstMemory *    gst_memory_make_mapped  (GstMemory *mem, GstMapInfo *info, GstMapFlags flags);
404
309
gboolean       gst_memory_map          (GstMemory *mem, GstMapInfo *info, GstMapFlags flags);