2011-06-07 16:18:27 +00:00
|
|
|
GstMemory
|
|
|
|
---------
|
|
|
|
|
|
|
|
This document describes the design of the memory objects.
|
|
|
|
|
|
|
|
GstMemory objects are usually added to GstBuffer objects and contain the
|
|
|
|
multimedia data passed around in the pipeline.
|
|
|
|
|
|
|
|
Requirements
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
|
|
- It must be possible to have different memory allocators
|
|
|
|
- It must be possible to efficiently share memory objects, copy, span
|
|
|
|
and trim.
|
|
|
|
|
|
|
|
|
|
|
|
Allocators
|
|
|
|
~~~~~~~~~~
|
|
|
|
|
2012-03-09 13:30:01 +00:00
|
|
|
GstMemory objects are created by allocators. Allocators are created from
|
|
|
|
a GstMemoryInfo structure.
|
2011-06-07 16:18:27 +00:00
|
|
|
|
|
|
|
struct _GstMemoryInfo {
|
2012-03-09 13:30:01 +00:00
|
|
|
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;
|
2011-06-07 16:18:27 +00:00
|
|
|
};
|
|
|
|
|
2012-03-09 13:30:01 +00:00
|
|
|
Allocators are refcounted. It is also possible to register the allocator to the
|
|
|
|
GStreamer system. This way, the allocator can be retrieved by name.
|
|
|
|
|
|
|
|
After an allocator is created, new GstMemory can be created with
|
2011-06-07 16:18:27 +00:00
|
|
|
|
2012-01-05 11:39:17 +00:00
|
|
|
GstMemory * gst_allocator_alloc (const GstAllocator * allocator,
|
|
|
|
gsize maxsize, gsize align);
|
2011-06-07 16:18:27 +00:00
|
|
|
|
|
|
|
The GstMemory object is a refcounted object that must be freed with
|
|
|
|
gst_memory_unref ().
|
|
|
|
|
|
|
|
It is also possible to create a new GstMemory object that wraps existing
|
|
|
|
memory with:
|
|
|
|
|
2012-03-09 13:30:01 +00:00
|
|
|
GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags,
|
|
|
|
gpointer data, gsize maxsize,
|
|
|
|
gsize offset, gsize size,
|
|
|
|
gpointer user_data,
|
|
|
|
GDestroyNotify notify);
|
2011-06-07 16:18:27 +00:00
|
|
|
|
2011-06-08 10:04:49 +00:00
|
|
|
Lifecycle
|
|
|
|
~~~~~~~~~
|
|
|
|
|
|
|
|
GstMemory objects are refcounted. When the GstMemory object is first created, it
|
|
|
|
has a refcount of 1.
|
|
|
|
|
|
|
|
Each variable holding a reference to the GstMemory object is responsible for
|
|
|
|
updating the refcount.
|
|
|
|
|
|
|
|
When the refcount reaches 0, and thus no objects hold a reference anymore, we
|
|
|
|
can free the memory. The GstMemoryFreeFunction of the allocator will be called
|
|
|
|
to cleanup the memory.
|
|
|
|
|
|
|
|
|
2011-06-07 16:18:27 +00:00
|
|
|
Memory layout
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
GstMemory manages a memory region. The accesible part of the managed region is
|
|
|
|
defined by an offset relative to the start of the region and a size. This
|
|
|
|
means that the managed region can be larger than what is visible to the user of
|
|
|
|
GstMemory API.
|
|
|
|
|
|
|
|
Schematically, GstMemory has a pointer to a memory region of _maxsize_. The area
|
|
|
|
starting from _offset_ and _size_ is accessible.
|
|
|
|
|
|
|
|
memory
|
|
|
|
GstMemory ->*----------------------------------------------------*
|
|
|
|
^----------------------------------------------------^
|
|
|
|
maxsize
|
|
|
|
^--------------------------------------^
|
|
|
|
offset size
|
|
|
|
|
|
|
|
The current properties of the accessible memory can be retrieved with:
|
|
|
|
|
2012-01-05 11:39:17 +00:00
|
|
|
gsize gst_memory_get_sizes (GstMemory *mem, gsize *offset, gsize *maxsize);
|
2011-06-07 16:18:27 +00:00
|
|
|
|
|
|
|
The offset and size can be changed with:
|
|
|
|
|
2012-01-05 11:39:17 +00:00
|
|
|
void gst_memory_resize (GstMemory *mem, gssize offset, gsize size);
|
2011-06-08 10:04:49 +00:00
|
|
|
|
2011-06-07 16:18:27 +00:00
|
|
|
|
|
|
|
Data Access
|
|
|
|
~~~~~~~~~~~
|
|
|
|
|
2011-06-08 10:04:49 +00:00
|
|
|
Access to the memory region is always controlled with a map and unmap method
|
|
|
|
call. This allows the implementation to monitor the access patterns or set up
|
|
|
|
the required memory mappings when needed.
|
|
|
|
|
|
|
|
Mapping a memory region requires the caller to specify the access method: READ
|
2012-03-09 13:30:01 +00:00
|
|
|
and/or WRITE.
|
2011-06-08 10:04:49 +00:00
|
|
|
|
|
|
|
After the data has been accessed in the object, the unmap call must be
|
2012-03-09 13:30:01 +00:00
|
|
|
performed.
|
2011-06-08 10:04:49 +00:00
|
|
|
|
2012-01-05 15:41:58 +00:00
|
|
|
It is allowed to map multiple times with different access modes. for each of
|
2012-01-06 12:10:18 +00:00
|
|
|
the map calls, an corresponding unmap call needs to be made. WRITE-only memory
|
|
|
|
cannot be mapped in READ mode and READ-only memory cannot be mapped in WRITE
|
|
|
|
mode.
|
2012-01-05 15:41:58 +00:00
|
|
|
|
|
|
|
The memory pointer returned from the map call is guaranteed to remain valid in
|
|
|
|
the requested mapping mode until the corresponding unmap call is performed on
|
|
|
|
the pointer.
|
|
|
|
|
|
|
|
When multiple map operations are nested and return the same pointer, the pointer
|
|
|
|
is valid until the last unmap call is done.
|
|
|
|
|
|
|
|
When the final reference on a memory object is dropped, all outstanding
|
2012-03-09 13:30:01 +00:00
|
|
|
mappings should have been unmapped.
|
2012-01-05 16:02:48 +00:00
|
|
|
|
2012-03-09 13:30:01 +00:00
|
|
|
Resizing a GstMemory does not influence any current mappings an any way.
|
2011-06-08 10:04:49 +00:00
|
|
|
|
|
|
|
Copy
|
|
|
|
~~~~
|
|
|
|
|
|
|
|
A GstMemory copy can be made with the gst_memory_copy() call. Normally,
|
|
|
|
allocators will implement a custom version of this function to make a copy of
|
|
|
|
the same kind of memory as the original one.
|
|
|
|
|
|
|
|
This is what the fallback version of the copy function will do, albeit slower
|
|
|
|
than what as custom implementation could do.
|
|
|
|
|
|
|
|
The copy operation is only required to copy the visible range of the memory
|
|
|
|
block.
|
|
|
|
|
|
|
|
|
|
|
|
Share
|
|
|
|
~~~~~
|
2011-06-07 16:18:27 +00:00
|
|
|
|
2011-06-08 10:04:49 +00:00
|
|
|
A memory region can be shared between GstMemory object with the
|
|
|
|
gst_memory_share() operation.
|
2011-06-07 16:18:27 +00:00
|
|
|
|
|
|
|
|