2011-03-18 17:35:42 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
|
|
|
|
*
|
|
|
|
* gstmemory.h: Header for memory blocks
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __GST_MEMORY_H__
|
|
|
|
#define __GST_MEMORY_H__
|
|
|
|
|
2011-03-21 08:51:53 +00:00
|
|
|
#include <gst/gstconfig.h>
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
2011-03-18 18:28:17 +00:00
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2011-11-10 12:51:28 +00:00
|
|
|
#define GST_TYPE_MEMORY (gst_memory_get_type())
|
|
|
|
GType gst_memory_get_type(void);
|
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
typedef struct _GstMemory GstMemory;
|
|
|
|
typedef struct _GstMemoryInfo GstMemoryInfo;
|
2011-06-22 09:42:46 +00:00
|
|
|
typedef struct _GstAllocator GstAllocator;
|
2011-03-18 17:35:42 +00:00
|
|
|
|
2011-12-16 01:20:27 +00:00
|
|
|
GST_EXPORT gsize gst_memory_alignment;
|
2011-06-10 14:46:12 +00:00
|
|
|
|
2011-03-30 16:45:08 +00:00
|
|
|
/**
|
|
|
|
* GstMemoryFlags:
|
2011-04-07 14:02:43 +00:00
|
|
|
* @GST_MEMORY_FLAG_READONLY: memory is readonly. It is not allowed to map the
|
|
|
|
* memory with #GST_MAP_WRITE.
|
|
|
|
* @GST_MEMORY_FLAG_NO_SHARE: memory must not be shared. Copies will have to be
|
|
|
|
* made when this memory needs to be shared between buffers.
|
2011-06-05 17:11:22 +00:00
|
|
|
* @GST_MEMORY_FLAG_LAST: first flag that can be used for custom purposes
|
2011-03-30 16:45:08 +00:00
|
|
|
*
|
|
|
|
* Flags for wrapped memory.
|
|
|
|
*/
|
2011-03-19 09:45:37 +00:00
|
|
|
typedef enum {
|
2011-04-07 14:02:43 +00:00
|
|
|
GST_MEMORY_FLAG_READONLY = (1 << 0),
|
|
|
|
GST_MEMORY_FLAG_NO_SHARE = (1 << 1),
|
|
|
|
|
2011-12-19 16:00:18 +00:00
|
|
|
GST_MEMORY_FLAG_LAST = (1 << 16)
|
2011-03-19 09:45:37 +00:00
|
|
|
} GstMemoryFlags;
|
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
/**
|
|
|
|
* GstMemory:
|
2011-06-22 09:42:46 +00:00
|
|
|
* @allocator: pointer to the #GstAllocator
|
2011-03-30 16:45:08 +00:00
|
|
|
* @flags: memory flags
|
2011-03-19 09:45:37 +00:00
|
|
|
* @refcount: refcount
|
2011-03-30 14:47:55 +00:00
|
|
|
* @parent: parent memory block
|
2012-01-06 12:10:18 +00:00
|
|
|
* @state: private state
|
2012-01-19 08:12:05 +00:00
|
|
|
* @maxsize: the maximum size allocated
|
|
|
|
* @align: the alignment of the memory
|
|
|
|
* @offset: the offset where valid data starts
|
|
|
|
* @size: the size of valid data
|
2011-03-18 17:35:42 +00:00
|
|
|
*
|
|
|
|
* Base structure for memory implementations. Custom memory will put this structure
|
|
|
|
* as the first member of their structure.
|
|
|
|
*/
|
|
|
|
struct _GstMemory {
|
2011-06-22 09:42:46 +00:00
|
|
|
const GstAllocator *allocator;
|
2011-03-18 17:35:42 +00:00
|
|
|
|
2011-03-19 09:45:37 +00:00
|
|
|
GstMemoryFlags flags;
|
|
|
|
gint refcount;
|
|
|
|
GstMemory *parent;
|
2012-01-06 12:10:18 +00:00
|
|
|
volatile gint state;
|
2012-01-19 08:12:05 +00:00
|
|
|
gsize maxsize;
|
|
|
|
gsize align;
|
|
|
|
gsize offset;
|
|
|
|
gsize size;
|
2011-03-18 17:35:42 +00:00
|
|
|
};
|
|
|
|
|
2011-03-30 16:45:08 +00:00
|
|
|
/**
|
|
|
|
* GstMapFlags:
|
|
|
|
* @GST_MAP_READ: map for read access
|
|
|
|
* @GST_MAP_WRITE: map for write access
|
2011-12-19 16:00:18 +00:00
|
|
|
* @GST_MAP_FLAG_LAST: first flag that can be used for custom purposes
|
2011-03-30 16:45:08 +00:00
|
|
|
*
|
|
|
|
* Flags used when mapping memory
|
|
|
|
*/
|
2011-03-18 18:28:17 +00:00
|
|
|
typedef enum {
|
2011-12-19 16:00:18 +00:00
|
|
|
GST_MAP_READ = (1 << 0),
|
|
|
|
GST_MAP_WRITE = (1 << 1),
|
|
|
|
|
|
|
|
GST_MAP_FLAG_LAST = (1 << 16)
|
2011-03-18 18:28:17 +00:00
|
|
|
} GstMapFlags;
|
|
|
|
|
2012-01-20 13:23:57 +00:00
|
|
|
/**
|
|
|
|
* GstMapInfo:
|
|
|
|
* @memory: a pointer to the mapped memory
|
2012-01-24 13:37:25 +00:00
|
|
|
* @flags: flags used when mapping the memory
|
2012-01-20 13:23:57 +00:00
|
|
|
* @data: a pointer to the mapped data
|
|
|
|
* @size: the valid size in @data
|
|
|
|
* @maxsize: the maximum bytes in @data
|
|
|
|
*
|
|
|
|
* A structure containing the result of a map operation such as
|
|
|
|
* gst_memory_map(). It contains the data and size.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
GstMemory *memory;
|
2012-01-24 13:37:25 +00:00
|
|
|
GstMapFlags flags;
|
2012-01-20 15:10:26 +00:00
|
|
|
guint8 *data;
|
2012-01-20 13:23:57 +00:00
|
|
|
gsize size;
|
|
|
|
gsize maxsize;
|
|
|
|
} GstMapInfo;
|
|
|
|
|
2012-01-24 13:37:25 +00:00
|
|
|
#define GST_MAP_INFO_INIT { NULL, 0, NULL, 0, 0 }
|
|
|
|
|
2011-03-30 16:45:08 +00:00
|
|
|
/**
|
|
|
|
* GST_MAP_READWRITE:
|
|
|
|
*
|
|
|
|
* Map for readwrite access
|
|
|
|
*/
|
2011-03-28 08:28:02 +00:00
|
|
|
#define GST_MAP_READWRITE (GST_MAP_READ | GST_MAP_WRITE)
|
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
/**
|
2011-06-22 09:42:46 +00:00
|
|
|
* GST_ALLOCATOR_SYSMEM:
|
2011-03-18 17:35:42 +00:00
|
|
|
*
|
2011-06-22 09:42:46 +00:00
|
|
|
* The allocator name for the default system memory allocator
|
2011-03-18 17:35:42 +00:00
|
|
|
*/
|
2011-06-22 09:42:46 +00:00
|
|
|
#define GST_ALLOCATOR_SYSMEM "SystemMemory"
|
2011-03-18 17:35:42 +00:00
|
|
|
|
2011-06-07 14:14:50 +00:00
|
|
|
/**
|
2011-06-07 15:34:17 +00:00
|
|
|
* GstMemoryAllocFunction:
|
2011-06-22 09:42:46 +00:00
|
|
|
* @allocator: a #GstAllocator
|
2011-06-07 14:14:50 +00:00
|
|
|
* @maxsize: the maxsize
|
|
|
|
* @align: the alignment
|
2011-06-07 15:54:33 +00:00
|
|
|
* @user_data: user data
|
2011-06-07 14:14:50 +00:00
|
|
|
*
|
2011-06-07 15:54:33 +00:00
|
|
|
* Allocate a new #GstMemory from @allocator that can hold at least @maxsize bytes
|
|
|
|
* and is aligned to (@align + 1) bytes.
|
|
|
|
*
|
|
|
|
* @user_data is the data that was used when registering @allocator.
|
2011-06-07 14:14:50 +00:00
|
|
|
*
|
|
|
|
* Returns: a newly allocated #GstMemory. Free with gst_memory_unref()
|
|
|
|
*/
|
2011-06-22 09:42:46 +00:00
|
|
|
typedef GstMemory * (*GstMemoryAllocFunction) (const GstAllocator *allocator,
|
2011-06-07 15:54:33 +00:00
|
|
|
gsize maxsize, gsize align,
|
|
|
|
gpointer user_data);
|
2011-06-07 14:14:50 +00:00
|
|
|
|
2011-03-30 16:45:08 +00:00
|
|
|
/**
|
|
|
|
* GstMemoryMapFunction:
|
|
|
|
* @mem: a #GstMemory
|
2012-01-19 08:12:05 +00:00
|
|
|
* @maxsize: size to map
|
2011-03-30 16:45:08 +00:00
|
|
|
* @flags: access mode for the memory
|
|
|
|
*
|
|
|
|
* Get the memory of @mem that can be accessed according to the mode specified
|
2012-01-19 08:12:05 +00:00
|
|
|
* in @flags. The function should return a pointer that contains at least
|
|
|
|
* @maxsize bytes.
|
2011-03-30 16:45:08 +00:00
|
|
|
*
|
2012-01-19 08:12:05 +00:00
|
|
|
* Returns: a pointer to memory of which at least @maxsize bytes can be
|
|
|
|
* accessed according to the access pattern in @flags.
|
2011-03-30 16:45:08 +00:00
|
|
|
*/
|
2012-01-19 08:12:05 +00:00
|
|
|
typedef gpointer (*GstMemoryMapFunction) (GstMemory *mem, gsize maxsize, GstMapFlags flags);
|
2011-03-30 16:45:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstMemoryUnmapFunction:
|
|
|
|
* @mem: a #GstMemory
|
|
|
|
*
|
2012-01-19 08:12:05 +00:00
|
|
|
* Return the pointer previously retrieved with gst_memory_map().
|
2011-03-30 16:45:08 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
2012-01-19 08:12:05 +00:00
|
|
|
typedef void (*GstMemoryUnmapFunction) (GstMemory *mem);
|
2011-03-30 16:45:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstMemoryFreeFunction:
|
|
|
|
* @mem: a #GstMemory
|
|
|
|
*
|
|
|
|
* Free the memory used by @mem. This function is usually called when the
|
|
|
|
* refcount of the @mem has reached 0.
|
|
|
|
*/
|
2011-03-18 20:45:39 +00:00
|
|
|
typedef void (*GstMemoryFreeFunction) (GstMemory *mem);
|
2011-03-30 14:47:55 +00:00
|
|
|
|
2011-03-30 16:45:08 +00:00
|
|
|
/**
|
|
|
|
* GstMemoryCopyFunction:
|
|
|
|
* @mem: a #GstMemory
|
|
|
|
* @offset: an offset
|
2011-11-11 01:47:30 +00:00
|
|
|
* @size: a size or -1
|
2011-03-30 16:45:08 +00:00
|
|
|
*
|
|
|
|
* Copy @size bytes from @mem starting at @offset and return them wrapped in a
|
|
|
|
* new GstMemory object.
|
|
|
|
* If @size is set to -1, all bytes starting at @offset are copied.
|
|
|
|
*
|
|
|
|
* Returns: a new #GstMemory object wrapping a copy of the requested region in
|
|
|
|
* @mem.
|
|
|
|
*/
|
2011-11-11 01:47:30 +00:00
|
|
|
typedef GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem, gssize offset, gssize size);
|
2011-03-30 16:45:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstMemoryShareFunction:
|
|
|
|
* @mem: a #GstMemory
|
|
|
|
* @offset: an offset
|
2011-11-11 01:47:30 +00:00
|
|
|
* @size: a size or -1
|
2011-03-30 16:45:08 +00:00
|
|
|
*
|
|
|
|
* Share @size bytes from @mem starting at @offset and return them wrapped in a
|
|
|
|
* new GstMemory object. If @size is set to -1, all bytes starting at @offset are
|
|
|
|
* shared. This function does not make a copy of the bytes in @mem.
|
|
|
|
*
|
|
|
|
* Returns: a new #GstMemory object sharing the requested region in @mem.
|
|
|
|
*/
|
2011-11-11 01:47:30 +00:00
|
|
|
typedef GstMemory * (*GstMemoryShareFunction) (GstMemory *mem, gssize offset, gssize size);
|
2011-03-30 16:45:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstMemoryIsSpanFunction:
|
|
|
|
* @mem1: a #GstMemory
|
2011-06-05 17:11:22 +00:00
|
|
|
* @mem2: a #GstMemory
|
2011-03-30 16:45:08 +00:00
|
|
|
* @offset: a result offset
|
|
|
|
*
|
|
|
|
* Check if @mem1 and @mem2 occupy contiguous memory and return the offset of
|
|
|
|
* @mem1 in the parent buffer in @offset.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @mem1 and @mem2 are in contiguous memory.
|
|
|
|
*/
|
2011-03-30 14:47:55 +00:00
|
|
|
typedef gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1, GstMemory *mem2, gsize *offset);
|
2011-03-18 17:35:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstMemoryInfo:
|
2011-06-07 14:14:50 +00:00
|
|
|
* @alloc: the implementation of the GstMemoryAllocFunction
|
2011-03-30 16:45:08 +00:00
|
|
|
* @map: the implementation of the GstMemoryMapFunction
|
|
|
|
* @unmap: the implementation of the GstMemoryUnmapFunction
|
|
|
|
* @free: the implementation of the GstMemoryFreeFunction
|
|
|
|
* @copy: the implementation of the GstMemoryCopyFunction
|
|
|
|
* @share: the implementation of the GstMemoryShareFunction
|
|
|
|
* @is_span: the implementation of the GstMemoryIsSpanFunction
|
2011-06-07 14:14:50 +00:00
|
|
|
* @user_data: generic user data for the allocator
|
2011-03-18 17:35:42 +00:00
|
|
|
*
|
2011-06-07 14:14:50 +00:00
|
|
|
* The #GstMemoryInfo is used to register new memory allocators and contain
|
2011-03-30 16:45:08 +00:00
|
|
|
* the implementations for various memory operations.
|
2011-03-18 17:35:42 +00:00
|
|
|
*/
|
|
|
|
struct _GstMemoryInfo {
|
2011-06-07 14:14:50 +00:00
|
|
|
GstMemoryAllocFunction alloc;
|
2011-03-18 17:35:42 +00:00
|
|
|
GstMemoryMapFunction map;
|
|
|
|
GstMemoryUnmapFunction unmap;
|
2011-03-18 18:28:17 +00:00
|
|
|
GstMemoryFreeFunction free;
|
2011-03-18 20:45:39 +00:00
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
GstMemoryCopyFunction copy;
|
2011-03-30 14:47:55 +00:00
|
|
|
GstMemoryShareFunction share;
|
2011-03-18 20:45:39 +00:00
|
|
|
GstMemoryIsSpanFunction is_span;
|
2011-06-07 14:14:50 +00:00
|
|
|
|
|
|
|
gpointer user_data;
|
2011-11-11 15:52:41 +00:00
|
|
|
|
2011-11-14 09:27:01 +00:00
|
|
|
/*< private >*/
|
2011-11-11 15:52:41 +00:00
|
|
|
gpointer _gst_reserved[GST_PADDING];
|
2011-03-18 17:35:42 +00:00
|
|
|
};
|
|
|
|
|
2011-06-07 14:14:50 +00:00
|
|
|
/* allocators */
|
2011-06-22 09:42:46 +00:00
|
|
|
const GstAllocator * gst_allocator_register (const gchar *name, const GstMemoryInfo *info);
|
|
|
|
const GstAllocator * gst_allocator_find (const gchar *name);
|
2011-06-07 14:14:50 +00:00
|
|
|
|
2011-06-22 09:42:46 +00:00
|
|
|
void gst_allocator_set_default (const GstAllocator * allocator);
|
2011-06-07 14:14:50 +00:00
|
|
|
|
2011-03-22 19:51:06 +00:00
|
|
|
/* allocating memory blocks */
|
2011-06-22 09:42:46 +00:00
|
|
|
GstMemory * gst_allocator_alloc (const GstAllocator * allocator,
|
2011-06-07 14:14:50 +00:00
|
|
|
gsize maxsize, gsize align);
|
2011-06-22 09:42:46 +00:00
|
|
|
|
2011-06-07 14:14:50 +00:00
|
|
|
GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, GFreeFunc free_func,
|
|
|
|
gsize maxsize, gsize offset, gsize size);
|
2011-03-22 19:51:06 +00:00
|
|
|
|
|
|
|
/* refcounting */
|
2012-01-16 14:57:35 +00:00
|
|
|
GstMemory * gst_memory_ref (GstMemory *mem);
|
|
|
|
void gst_memory_unref (GstMemory *mem);
|
2011-03-18 17:35:42 +00:00
|
|
|
|
2011-03-22 19:51:06 +00:00
|
|
|
/* getting/setting memory properties */
|
2012-01-16 14:57:35 +00:00
|
|
|
gsize gst_memory_get_sizes (GstMemory *mem, gsize *offset, gsize *maxsize);
|
|
|
|
void gst_memory_resize (GstMemory *mem, gssize offset, gsize size);
|
2011-03-18 17:35:42 +00:00
|
|
|
|
2011-06-07 15:34:17 +00:00
|
|
|
/* retrieving data */
|
2012-01-16 14:57:35 +00:00
|
|
|
gboolean gst_memory_is_writable (GstMemory *mem);
|
|
|
|
|
2012-01-20 13:56:49 +00:00
|
|
|
GstMemory * gst_memory_make_mapped (GstMemory *mem, GstMapInfo *info, GstMapFlags flags);
|
2012-01-20 13:23:57 +00:00
|
|
|
gboolean gst_memory_map (GstMemory *mem, GstMapInfo *info, GstMapFlags flags);
|
|
|
|
void gst_memory_unmap (GstMemory *mem, GstMapInfo *info);
|
2011-03-29 17:17:55 +00:00
|
|
|
|
2011-03-22 19:51:06 +00:00
|
|
|
/* copy and subregions */
|
2012-01-16 14:57:35 +00:00
|
|
|
GstMemory * gst_memory_copy (GstMemory *mem, gssize offset, gssize size);
|
|
|
|
GstMemory * gst_memory_share (GstMemory *mem, gssize offset, gssize size);
|
2011-03-18 20:45:39 +00:00
|
|
|
|
2011-03-29 17:17:55 +00:00
|
|
|
/* span memory */
|
2012-01-16 14:57:35 +00:00
|
|
|
gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset);
|
2011-03-30 14:47:55 +00:00
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __GST_MEMORY_H__ */
|