![]() |
![]() |
![]() |
GStreamer 1.0 Core Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
#include <gst/gst.h> enum GstMemoryFlags; #define GST_MEMORY_FLAGS (mem) #define GST_MEMORY_FLAG_IS_SET (mem, flag) #define GST_MEMORY_FLAG_UNSET (mem, flag) #define GST_MEMORY_IS_READONLY (mem) #define GST_MEMORY_IS_NO_SHARE (mem) #define GST_MEMORY_IS_ZERO_PADDED (mem) #define GST_MEMORY_IS_ZERO_PREFIXED (mem) struct GstMemory; enum GstMapFlags; #define GST_MAP_READWRITE GstMapInfo; #define GST_MAP_INFO_INIT gpointer (*GstMemoryMapFunction) (GstMemory *mem
,gsize maxsize
,GstMapFlags flags
); void (*GstMemoryUnmapFunction) (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
); void gst_memory_init (GstMemory *mem
,GstMemoryFlags flags
,GstAllocator *allocator
,GstMemory *parent
,gsize maxsize
,gsize align
,gsize offset
,gsize size
); GstMemory * gst_memory_ref (GstMemory *memory
); void gst_memory_unref (GstMemory *memory
); gsize gst_memory_get_sizes (GstMemory *mem
,gsize *offset
,gsize *maxsize
); void gst_memory_resize (GstMemory *mem
,gssize offset
,gsize size
); #define gst_memory_lock (m, f) #define gst_memory_unlock (m, f) #define gst_memory_is_writable (m) GstMemory * gst_memory_make_mapped (GstMemory *mem
,GstMapInfo *info
,GstMapFlags flags
); 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
);
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()
. gst_allocator_set_default()
can be used to change the
default allocator.
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 return 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 2012-03-28 (0.11.3)
typedef enum { GST_MEMORY_FLAG_READONLY = GST_MINI_OBJECT_FLAG_LOCK_READONLY, GST_MEMORY_FLAG_NO_SHARE = (GST_MINI_OBJECT_FLAG_LAST << 0), GST_MEMORY_FLAG_ZERO_PREFIXED = (GST_MINI_OBJECT_FLAG_LAST << 1), GST_MEMORY_FLAG_ZERO_PADDED = (GST_MINI_OBJECT_FLAG_LAST << 2), GST_MEMORY_FLAG_LAST = (GST_MINI_OBJECT_FLAG_LAST << 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. | |
the memory prefix is filled with 0 bytes | |
the memory padding is filled with 0 bytes | |
first flag that can be used for custom purposes |
#define GST_MEMORY_FLAGS(mem) GST_MINI_OBJECT_FLAGS (mem)
A flags word containing GstMemoryFlags flags set on mem
|
a GstMemory. |
#define GST_MEMORY_FLAG_IS_SET(mem,flag) GST_MINI_OBJECT_FLAG_IS_SET (mem,flag)
Gives the status of a specific flag on a mem
.
|
a GstMemory. |
|
the GstMemoryFlags to check. |
#define GST_MEMORY_FLAG_UNSET(mem,flag) GST_MINI_OBJECT_FLAG_UNSET (mem, flag)
Clear a specific flag on a mem
.
|
a GstMemory. |
|
the GstMemoryFlags to clear. |
#define GST_MEMORY_IS_READONLY(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_READONLY)
Check if mem
is readonly.
|
a GstMemory. |
#define GST_MEMORY_IS_NO_SHARE(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_NO_SHARE)
Check if mem
cannot be shared between buffers
|
a GstMemory. |
#define GST_MEMORY_IS_ZERO_PADDED(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_ZERO_PADDED)
Check if the padding in mem
is 0 filled.
|
a GstMemory. |
#define GST_MEMORY_IS_ZERO_PREFIXED(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_ZERO_PREFIXED)
Check if the prefix in mem
is 0 filled.
|
a GstMemory. |
struct GstMemory { GstMiniObject mini_object; GstAllocator *allocator; GstMemory *parent; 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.
GstMiniObject |
parent structure |
GstAllocator * |
pointer to the GstAllocator |
GstMemory * |
parent memory block |
the maximum size allocated | |
the alignment of the memory | |
the offset where valid data starts | |
the size of valid data |
typedef enum { GST_MAP_READ = GST_LOCK_FLAG_READ, GST_MAP_WRITE = GST_LOCK_FLAG_WRITE, GST_MAP_FLAG_LAST = (1 << 16) } GstMapFlags;
Flags used when mapping memory
#define GST_MAP_READWRITE (GST_MAP_READ | GST_MAP_WRITE)
GstMapFlags value alias for GST_MAP_READ | GST_MAP_WRITE
typedef struct { GstMemory *memory; GstMapFlags flags; guint8 *data; gsize size; gsize maxsize; } GstMapInfo;
A structure containing the result of a map operation such as
gst_memory_map()
. It contains the data and size.
GstMemory * |
a pointer to the mapped memory |
GstMapFlags |
flags used when mapping the memory |
a pointer to the mapped data. [array length=size] | |
the valid size in data
|
|
the maximum bytes in data
|
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()
.
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
.
void gst_memory_init (GstMemory *mem
,GstMemoryFlags flags
,GstAllocator *allocator
,GstMemory *parent
,gsize maxsize
,gsize align
,gsize offset
,gsize size
);
Initializes a newly allocated mem
with the given parameters. This function
will call gst_mini_object_init()
with the default memory parameters.
|
a GstMemory |
|
GstMemoryFlags |
|
the GstAllocator |
|
the parent of mem
|
|
the total size of the memory |
|
the alignment of the memory |
|
The offset in the memory |
|
the size of valid data in the memory |
GstMemory * gst_memory_ref (GstMemory *memory
);
Increase the refcount of this memory.
|
The memory to refcount |
Returns : |
memory (for convenience when doing assignments). [transfer full]
|
void gst_memory_unref (GstMemory *memory
);
Decrease the refcount of an memory, freeing it if the refcount reaches 0.
|
the memory to refcount. [transfer full] |
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
.
GST_MEMORY_FLAG_ZERO_PREFIXED and GST_MEMORY_FLAG_ZERO_PADDED will be cleared when offset or padding is increased respectively.
|
a GstMemory |
|
a new offset |
|
a new size |
#define gst_memory_unlock(m,f) gst_mini_object_unlock (GST_MINI_OBJECT_CAST (m), (f))
#define gst_memory_is_writable(m) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (m))
GstMemory * gst_memory_make_mapped (GstMemory *mem
,GstMapInfo *info
,GstMapFlags flags
);
Create a GstMemory object that is mapped with flags
. If mem
is mappable
with flags
, this function returns the mapped mem
directly. Otherwise a
mapped copy of mem
is returned.
This function takes ownership of old mem
and returns a reference to a new
GstMemory.
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.
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
.