Copyright | Will Thompson, Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
GstMemory is a lightweight refcounted object that wraps a region of memory.
They are typically used to manage the data of a Buffer
.
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 allocatorAlloc
method call. When Nothing
is used as the allocator, the default allocator will
be used.
New allocators can be registered with allocatorRegister
.
Allocators are identified by name and can be retrieved with
allocatorFind
. allocatorSetDefault
can be used to change the
default allocator.
New memory can be created with memoryNewWrapped
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
memoryGetSizes
and memoryResize
respectively.
Getting access to the data of the memory is performed with memoryMap
.
The call will return a pointer to offset bytes into the region of memory.
After the memory access is completed, memoryUnmap
should be called.
Memory can be copied with memoryCopy
, which will return a writable
copy. memoryShare
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 memoryIsSpan
returns True
.
- newtype Memory = Memory (ManagedPtr Memory)
- newZeroMemory :: MonadIO m => m Memory
- noMemory :: Maybe Memory
- data MemoryCopyMethodInfo
- memoryCopy :: (HasCallStack, MonadIO m) => Memory -> Int64 -> Int64 -> m Memory
- data MemoryGetSizesMethodInfo
- memoryGetSizes :: (HasCallStack, MonadIO m) => Memory -> Word64 -> Word64 -> m Word64
- data MemoryIsSpanMethodInfo
- memoryIsSpan :: (HasCallStack, MonadIO m) => Memory -> Memory -> Word64 -> m Bool
- data MemoryIsTypeMethodInfo
- memoryIsType :: (HasCallStack, MonadIO m) => Memory -> Text -> m Bool
- data MemoryMakeMappedMethodInfo
- memoryMakeMapped :: (HasCallStack, MonadIO m) => Memory -> [MapFlags] -> m (Maybe Memory, MapInfo)
- data MemoryMapMethodInfo
- memoryMap :: (HasCallStack, MonadIO m) => Memory -> [MapFlags] -> m (Bool, MapInfo)
- memoryNewWrapped :: (HasCallStack, MonadIO m) => [MemoryFlags] -> ByteString -> Word64 -> Word64 -> Maybe DestroyNotify -> m Memory
- data MemoryResizeMethodInfo
- memoryResize :: (HasCallStack, MonadIO m) => Memory -> Int64 -> Word64 -> m ()
- data MemoryShareMethodInfo
- memoryShare :: (HasCallStack, MonadIO m) => Memory -> Int64 -> Int64 -> m Memory
- data MemoryUnmapMethodInfo
- memoryUnmap :: (HasCallStack, MonadIO m) => Memory -> MapInfo -> m ()
- getMemoryAlign :: MonadIO m => Memory -> m Word64
- memory_align :: AttrLabelProxy "align"
- setMemoryAlign :: MonadIO m => Memory -> Word64 -> m ()
- clearMemoryAllocator :: MonadIO m => Memory -> m ()
- getMemoryAllocator :: MonadIO m => Memory -> m (Maybe Allocator)
- memory_allocator :: AttrLabelProxy "allocator"
- setMemoryAllocator :: MonadIO m => Memory -> Ptr Allocator -> m ()
- getMemoryMaxsize :: MonadIO m => Memory -> m Word64
- memory_maxsize :: AttrLabelProxy "maxsize"
- setMemoryMaxsize :: MonadIO m => Memory -> Word64 -> m ()
- getMemoryMiniObject :: MonadIO m => Memory -> m MiniObject
- memory_miniObject :: AttrLabelProxy "miniObject"
- getMemoryOffset :: MonadIO m => Memory -> m Word64
- memory_offset :: AttrLabelProxy "offset"
- setMemoryOffset :: MonadIO m => Memory -> Word64 -> m ()
- clearMemoryParent :: MonadIO m => Memory -> m ()
- getMemoryParent :: MonadIO m => Memory -> m (Maybe Memory)
- memory_parent :: AttrLabelProxy "parent"
- setMemoryParent :: MonadIO m => Memory -> Ptr Memory -> m ()
- getMemorySize :: MonadIO m => Memory -> m Word64
- memory_size :: AttrLabelProxy "size"
- setMemorySize :: MonadIO m => Memory -> Word64 -> m ()
Exported types
Methods
copy
data MemoryCopyMethodInfo Source #
:: (HasCallStack, MonadIO m) | |
=> Memory |
|
-> Int64 |
|
-> Int64 |
|
-> m Memory | Returns: a new |
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
from offset
to the end of the memory region.
getSizes
:: (HasCallStack, MonadIO m) | |
=> Memory |
|
-> Word64 |
|
-> Word64 |
|
-> m Word64 | Returns: the current sizes of |
Get the current size
, offset
and maxsize
of mem
.
isSpan
:: (HasCallStack, MonadIO m) | |
=> Memory |
|
-> Memory |
|
-> Word64 |
|
-> m Bool | Returns: |
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 memoryShare
on the parent object from
the returned offset
.
isType
data MemoryIsTypeMethodInfo Source #
((~) * signature (Text -> m Bool), MonadIO m) => MethodInfo * MemoryIsTypeMethodInfo Memory signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Memory |
|
-> Text |
|
-> m Bool | Returns: |
Check if mem
if allocated with an allocator for memType
.
Since: 1.2
makeMapped
map
data MemoryMapMethodInfo Source #
:: (HasCallStack, MonadIO m) | |
=> Memory |
|
-> [MapFlags] |
|
-> m (Bool, MapInfo) | Returns: |
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 givenflags
. - the memory was already mapped with a different mapping.
info
and its contents remain valid for as long as mem
is valid and
until memoryUnmap
is called.
For each memoryMap
call, a corresponding memoryUnmap
call
should be done.
newWrapped
:: (HasCallStack, MonadIO m) | |
=> [MemoryFlags] |
|
-> ByteString |
|
-> Word64 |
|
-> Word64 |
|
-> Maybe DestroyNotify |
|
-> m Memory | Returns: a new |
Allocate a new memory block that wraps the given data
.
The prefix/padding must be filled with 0 if flags
contains
GST_MEMORY_FLAG_ZERO_PREFIXED
and GST_MEMORY_FLAG_ZERO_PADDED
respectively.
resize
data MemoryResizeMethodInfo Source #
((~) * signature (Int64 -> Word64 -> m ()), MonadIO m) => MethodInfo * MemoryResizeMethodInfo Memory signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Memory |
|
-> Int64 |
|
-> Word64 |
|
-> m () |
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.
share
data MemoryShareMethodInfo Source #
:: (HasCallStack, MonadIO m) | |
=> Memory |
|
-> Int64 |
|
-> Int64 |
|
-> m Memory | Returns: a new |
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 non-writable. size
can be set to -1 to return a shared
copy from offset
to the end of the memory region.
unmap
data MemoryUnmapMethodInfo Source #
((~) * signature (MapInfo -> m ()), MonadIO m) => MethodInfo * MemoryUnmapMethodInfo Memory signature Source # | |
Release the memory obtained with memoryMap
Properties
align
memory_align :: AttrLabelProxy "align" Source #
allocator
clearMemoryAllocator :: MonadIO m => Memory -> m () Source #
memory_allocator :: AttrLabelProxy "allocator" Source #
maxsize
memory_maxsize :: AttrLabelProxy "maxsize" Source #
miniObject
getMemoryMiniObject :: MonadIO m => Memory -> m MiniObject Source #
memory_miniObject :: AttrLabelProxy "miniObject" Source #
offset
memory_offset :: AttrLabelProxy "offset" Source #
parent
clearMemoryParent :: MonadIO m => Memory -> m () Source #
memory_parent :: AttrLabelProxy "parent" Source #
size
memory_size :: AttrLabelProxy "size" Source #