![]() |
![]() |
![]() |
GStreamer 0.11 Core Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
#include <gst/gst.h> struct GstMemory; struct GstMemoryInfo; GstAllocator; enum GstMemoryFlags; enum GstMapFlags; #define GST_MAP_READWRITE gpointer (*GstMemoryMapFunction) (GstMemory *mem
,gsize maxsize
,GstMapFlags flags
); void (*GstMemoryUnmapFunction) (GstMemory *mem
); void (*GstMemoryFreeFunction) (GstMemory *mem
); GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem
,gssize offset
,gssize size
); GstMemory * (*GstMemoryShareFunction) (GstMemory *mem
,gssize offset
,gssize size
); gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1
,GstMemory *mem2
,gsize *offset
); GstMemory * gst_allocator_alloc (GstAllocator *allocator
,gsize maxsize
,gsize align
); GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags
,gpointer data
,GFreeFunc free_func
,gsize maxsize
,gsize offset
,gsize size
); GstMemory * gst_memory_ref (GstMemory *mem
); void gst_memory_unref (GstMemory *mem
); gsize gst_memory_get_sizes (GstMemory *mem
,gsize *offset
,gsize *maxsize
); void gst_memory_resize (GstMemory *mem
,gssize offset
,gsize size
); gboolean gst_memory_map (GstMemory *mem
,GstMapInfo *info
,GstMapFlags flags
); void gst_memory_unmap (GstMemory *mem
,GstMapInfo *info
); GstMemory * gst_memory_copy (GstMemory *mem
,gssize offset
,gssize size
); GstMemory * gst_memory_share (GstMemory *mem
,gssize offset
,gssize size
); gboolean gst_memory_is_span (GstMemory *mem1
,GstMemory *mem2
,gsize *offset
); #define GST_ALLOCATOR_SYSMEM GstAllocator * gst_allocator_find (const gchar *name
); void gst_allocator_register (const gchar *name
,GstAllocator *alloc
); void gst_allocator_set_default (GstAllocator *allocator
);
GstMemory is a lightweight refcounted object that wraps a region of memory. They are typically used to manage the data of a GstBuffer.
A GstMemory object has an allocated region of memory of maxsize. The maximum size does not change during the lifetime of the memory object. The memory also has an offset and size property that specifies the valid range of memory in the allocated region.
Memory is usually created by allocators with a gst_allocator_alloc()
method call. When NULL is used as the allocator, the default allocator will
be used.
New allocators can be registered with gst_allocator_register()
.
Allocators are identified by name and can be retrieved with
gst_allocator_find()
.
New memory can be created with gst_memory_new_wrapped()
that wraps the memory
allocated elsewhere.
Refcounting of the memory block is performed with gst_memory_ref()
and
gst_memory_unref()
.
The size of the memory can be retrieved and changed with
gst_memory_get_sizes()
and gst_memory_resize()
respectively.
Getting access to the data of the memory is performed with gst_memory_map()
.
The call will return a pointer to offset bytes into the region of memory.
After the memory access is completed, gst_memory_unmap()
should be called.
Memory can be copied with gst_memory_copy()
, which will returnn a writable
copy. gst_memory_share()
will create a new memory block that shares the
memory with an existing memory block at a custom offset and with a custom
size.
Memory can be efficiently merged when gst_memory_is_span()
returns TRUE.
Last reviewed on 2011-06-08 (0.11.0)
struct GstMemory { GstAllocator *allocator; GstMemoryFlags flags; gint refcount; GstMemory *parent; volatile gint state; gsize maxsize; gsize align; gsize offset; gsize size; };
Base structure for memory implementations. Custom memory will put this structure as the first member of their structure.
GstAllocator * |
pointer to the GstAllocator |
GstMemoryFlags |
memory flags |
refcount | |
GstMemory * |
parent memory block |
private state | |
the maximum size allocated | |
the alignment of the memory | |
the offset where valid data starts | |
the size of valid data |
struct GstMemoryInfo { const gchar *mem_type; GstAllocatorAllocFunction alloc; GstMemoryMapFunction mem_map; GstMemoryUnmapFunction mem_unmap; GstMemoryFreeFunction mem_free; GstMemoryCopyFunction mem_copy; GstMemoryShareFunction mem_share; GstMemoryIsSpanFunction mem_is_span; };
The GstMemoryInfo is used to register new memory allocators and contain the implementations for various memory operations.
the implementation of the GstAllocatorAllocFunction | |
GstMemoryMapFunction |
the implementation of the GstMemoryMapFunction |
GstMemoryUnmapFunction |
the implementation of the GstMemoryUnmapFunction |
GstMemoryFreeFunction |
the implementation of the GstMemoryFreeFunction |
GstMemoryCopyFunction |
the implementation of the GstMemoryCopyFunction |
GstMemoryShareFunction |
the implementation of the GstMemoryShareFunction |
GstMemoryIsSpanFunction |
the implementation of the GstMemoryIsSpanFunction |
typedef enum { GST_MEMORY_FLAG_READONLY = (1 << 0), GST_MEMORY_FLAG_NO_SHARE = (1 << 1), GST_MEMORY_FLAG_LAST = (1 << 16) } GstMemoryFlags;
Flags for wrapped memory.
memory is readonly. It is not allowed to map the memory with GST_MAP_WRITE. | |
memory must not be shared. Copies will have to be made when this memory needs to be shared between buffers. | |
first flag that can be used for custom purposes |
typedef enum { GST_MAP_READ = (1 << 0), GST_MAP_WRITE = (1 << 1), GST_MAP_FLAG_LAST = (1 << 16) } GstMapFlags;
Flags used when mapping memory
gpointer (*GstMemoryMapFunction) (GstMemory *mem
,gsize maxsize
,GstMapFlags flags
);
Get the memory of mem
that can be accessed according to the mode specified
in flags
. The function should return a pointer that contains at least
maxsize
bytes.
|
a GstMemory |
|
size to map |
|
access mode for the memory |
Returns : |
a pointer to memory of which at least maxsize bytes can be
accessed according to the access pattern in flags . |
void (*GstMemoryUnmapFunction) (GstMemory *mem
);
Return the pointer previously retrieved with gst_memory_map()
.
|
a GstMemory |
Returns : |
TRUE on success. |
void (*GstMemoryFreeFunction) (GstMemory *mem
);
Free the memory used by mem
. This function is usually called when the
refcount of the mem
has reached 0.
|
a GstMemory |
GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem
,gssize offset
,gssize size
);
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.
GstMemory * (*GstMemoryShareFunction) (GstMemory *mem
,gssize offset
,gssize size
);
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
.
gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1
,GstMemory *mem2
,gsize *offset
);
Check if mem1
and mem2
occupy contiguous memory and return the offset of
mem1
in the parent buffer in offset
.
GstMemory * gst_allocator_alloc (GstAllocator *allocator
,gsize maxsize
,gsize align
);
Use allocator
to allocate a new memory block with memory that is at least
maxsize
big and has the given alignment.
When allocator
is NULL, the default allocator will be used.
align
is given as a bitmask so that align
+ 1 equals the amount of bytes to
align to. For example, to align to 8 bytes, use an alignment of 7.
|
a GstAllocator to use. [transfer none][allow-none] |
|
allocated size of data
|
|
alignment for the data |
Returns : |
a new GstMemory. [transfer full] |
GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags
,gpointer data
,GFreeFunc free_func
,gsize maxsize
,gsize offset
,gsize size
);
Allocate a new memory block that wraps the given data
.
|
GstMemoryFlags |
|
data to wrap |
|
function to free data
|
|
allocated size of data
|
|
offset in data
|
|
size of valid data |
Returns : |
a new GstMemory. |
GstMemory * gst_memory_ref (GstMemory *mem
);
Increases the refcount of mem
.
|
a GstMemory |
Returns : |
mem with increased refcount |
void gst_memory_unref (GstMemory *mem
);
Decreases the refcount of mem
. When the refcount reaches 0, the free
function of mem
will be called.
|
a GstMemory |
gsize gst_memory_get_sizes (GstMemory *mem
,gsize *offset
,gsize *maxsize
);
Get the current size
, offset
and maxsize
of mem
.
|
a GstMemory |
|
pointer to offset |
|
pointer to maxsize |
Returns : |
the current sizes of mem
|
void gst_memory_resize (GstMemory *mem
,gssize offset
,gsize size
);
Resize the memory region. mem
should be writable and offset + size should be
less than the maxsize of mem
.
|
a GstMemory |
|
a new offset |
|
a new size |
gboolean gst_memory_map (GstMemory *mem
,GstMapInfo *info
,GstMapFlags flags
);
Fill info
with the pointer and sizes of the memory in mem
that can be
accessed according to flags
.
This function can return FALSE
for various reasons:
the memory backed by mem
is not accessible with the given flags
.
the memory was already mapped with a different mapping.
info
and its contents remain valid for as long as mem
is valid and
until gst_memory_unmap()
is called.
For each gst_memory_map()
call, a corresponding gst_memory_unmap()
call
should be done.
|
a GstMemory |
|
pointer for info. [out] |
|
mapping flags |
Returns : |
TRUE if the map operation was successful. |
void gst_memory_unmap (GstMemory *mem
,GstMapInfo *info
);
Release the memory obtained with gst_memory_map()
|
a GstMemory |
|
a GstMapInfo |
GstMemory * gst_memory_copy (GstMemory *mem
,gssize offset
,gssize size
);
Return a copy of size
bytes from mem
starting from offset
. This copy is
guaranteed to be writable. size
can be set to -1 to return a copy all bytes
from offset
.
GstMemory * gst_memory_share (GstMemory *mem
,gssize offset
,gssize size
);
Return a shared copy of size
bytes from mem
starting from offset
. No
memory copy is performed and the memory region is simply shared. The result
is guaranteed to be not-writable. size
can be set to -1 to return a share
all bytes from offset
.
gboolean gst_memory_is_span (GstMemory *mem1
,GstMemory *mem2
,gsize *offset
);
Check if mem1
and mem2 share the memory with a common parent memory object
and that the memory is contiguous.
If this is the case, the memory of mem1
and mem2
can be merged
efficiently by performing gst_memory_share()
on the parent object from
the returned offset
.
#define GST_ALLOCATOR_SYSMEM "SystemMemory"
The allocator name for the default system memory allocator
GstAllocator * gst_allocator_find (const gchar *name
);
Find a previously registered allocator with name
. When name
is NULL, the
default allocator will be returned.
|
the name of the allocator |
Returns : |
a GstAllocator or NULL when the allocator with name was not
registered. Use gst_allocator_unref() to release the allocator after usage. [transfer full]
|
void gst_allocator_register (const gchar *name
,GstAllocator *alloc
);
Registers the memory allocator
with name
. This function takes ownership of
allocator
.
|
the name of the allocator |
|
GstAllocator. [transfer full] |
void gst_allocator_set_default (GstAllocator *allocator
);
Set the default allocator. This function takes ownership of allocator
.
|
a GstAllocator. [transfer full] |