4 This document describes the design of the memory objects.
6 GstMemory objects are usually added to GstBuffer objects and contain the
7 multimedia data passed around in the pipeline.
12 - It must be possible to have different memory allocators
13 - It must be possible to efficiently share memory objects, copy, span
20 GstMemory objects are created by allocators. Allocators are created from
21 a GstMemoryInfo structure.
23 struct _GstMemoryInfo {
24 const gchar *mem_type;
26 GstAllocatorAllocFunction alloc;
28 GstMemoryMapFunction mem_map;
29 GstMemoryUnmapFunction mem_unmap;
30 GstMemoryFreeFunction mem_free;
32 GstMemoryCopyFunction mem_copy;
33 GstMemoryShareFunction mem_share;
34 GstMemoryIsSpanFunction mem_is_span;
37 Allocators are refcounted. It is also possible to register the allocator to the
38 GStreamer system. This way, the allocator can be retrieved by name.
40 After an allocator is created, new GstMemory can be created with
42 GstMemory * gst_allocator_alloc (const GstAllocator * allocator,
43 gsize maxsize, gsize align);
45 The GstMemory object is a refcounted object that must be freed with
48 It is also possible to create a new GstMemory object that wraps existing
51 GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags,
52 gpointer data, gsize maxsize,
53 gsize offset, gsize size,
55 GDestroyNotify notify);
60 GstMemory objects are refcounted. When the GstMemory object is first created, it
63 Each variable holding a reference to the GstMemory object is responsible for
64 updating the refcount.
66 When the refcount reaches 0, and thus no objects hold a reference anymore, we
67 can free the memory. The GstMemoryFreeFunction of the allocator will be called
68 to cleanup the memory.
74 GstMemory manages a memory region. The accesible part of the managed region is
75 defined by an offset relative to the start of the region and a size. This
76 means that the managed region can be larger than what is visible to the user of
79 Schematically, GstMemory has a pointer to a memory region of _maxsize_. The area
80 starting from _offset_ and _size_ is accessible.
83 GstMemory ->*----------------------------------------------------*
84 ^----------------------------------------------------^
86 ^--------------------------------------^
89 The current properties of the accessible memory can be retrieved with:
91 gsize gst_memory_get_sizes (GstMemory *mem, gsize *offset, gsize *maxsize);
93 The offset and size can be changed with:
95 void gst_memory_resize (GstMemory *mem, gssize offset, gsize size);
101 Access to the memory region is always controlled with a map and unmap method
102 call. This allows the implementation to monitor the access patterns or set up
103 the required memory mappings when needed.
105 Mapping a memory region requires the caller to specify the access method: READ
108 After the data has been accessed in the object, the unmap call must be
111 It is allowed to map multiple times with different access modes. for each of
112 the map calls, an corresponding unmap call needs to be made. WRITE-only memory
113 cannot be mapped in READ mode and READ-only memory cannot be mapped in WRITE
116 The memory pointer returned from the map call is guaranteed to remain valid in
117 the requested mapping mode until the corresponding unmap call is performed on
120 When multiple map operations are nested and return the same pointer, the pointer
121 is valid until the last unmap call is done.
123 When the final reference on a memory object is dropped, all outstanding
124 mappings should have been unmapped.
126 Resizing a GstMemory does not influence any current mappings an any way.
131 A GstMemory copy can be made with the gst_memory_copy() call. Normally,
132 allocators will implement a custom version of this function to make a copy of
133 the same kind of memory as the original one.
135 This is what the fallback version of the copy function will do, albeit slower
136 than what as custom implementation could do.
138 The copy operation is only required to copy the visible range of the memory
145 A memory region can be shared between GstMemory object with the
146 gst_memory_share() operation.