mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-23 06:26:23 +00:00
fdmemory: add flag to avoid close of the fd
Add GST_FD_MEMORY_FLAG_DONT_CLOSE to avoid closing the fd when the memory is freed. When you can guarantee the lifetime of the fd is longer than the memory, this can save a dup() call.
This commit is contained in:
parent
70149451ea
commit
38622ee1e8
2 changed files with 7 additions and 2 deletions
|
@ -65,7 +65,8 @@ gst_fd_mem_free (GstAllocator * allocator, GstMemory * gmem)
|
||||||
|
|
||||||
munmap ((void *) mem->data, gmem->maxsize);
|
munmap ((void *) mem->data, gmem->maxsize);
|
||||||
}
|
}
|
||||||
if (mem->fd >= 0 && gmem->parent == NULL)
|
if (mem->fd >= 0 && gmem->parent == NULL
|
||||||
|
&& !(mem->flags & GST_FD_MEMORY_FLAG_DONT_CLOSE))
|
||||||
close (mem->fd);
|
close (mem->fd);
|
||||||
g_mutex_clear (&mem->lock);
|
g_mutex_clear (&mem->lock);
|
||||||
g_slice_free (GstFdMemory, mem);
|
g_slice_free (GstFdMemory, mem);
|
||||||
|
@ -245,7 +246,8 @@ gst_fd_allocator_new (void)
|
||||||
* Return a %GstMemory that wraps a generic file descriptor.
|
* Return a %GstMemory that wraps a generic file descriptor.
|
||||||
*
|
*
|
||||||
* Returns: (transfer full): a GstMemory based on @allocator.
|
* Returns: (transfer full): a GstMemory based on @allocator.
|
||||||
* When the buffer will be released the allocator will close the @fd.
|
* When the buffer will be released the allocator will close the @fd unless
|
||||||
|
* the %GST_FD_MEMORY_FLAG_DONT_CLOSE flag is specified.
|
||||||
* The memory is only mmapped on gst_buffer_mmap() request.
|
* The memory is only mmapped on gst_buffer_mmap() request.
|
||||||
*
|
*
|
||||||
* Since: 1.6
|
* Since: 1.6
|
||||||
|
|
|
@ -45,6 +45,8 @@ typedef struct _GstFdAllocatorClass GstFdAllocatorClass;
|
||||||
* keep it mapped until the memory is destroyed.
|
* keep it mapped until the memory is destroyed.
|
||||||
* @GST_FD_MEMORY_FLAG_MAP_PRIVATE: do a private mapping instead of
|
* @GST_FD_MEMORY_FLAG_MAP_PRIVATE: do a private mapping instead of
|
||||||
* the default shared mapping.
|
* the default shared mapping.
|
||||||
|
* @GST_FD_MEMORY_FLAG_DONT_CLOSE: don't close the file descriptor when
|
||||||
|
* the memory is freed. Since: 1.10.
|
||||||
*
|
*
|
||||||
* Various flags to control the operation of the fd backed memory.
|
* Various flags to control the operation of the fd backed memory.
|
||||||
*
|
*
|
||||||
|
@ -54,6 +56,7 @@ typedef enum {
|
||||||
GST_FD_MEMORY_FLAG_NONE = 0,
|
GST_FD_MEMORY_FLAG_NONE = 0,
|
||||||
GST_FD_MEMORY_FLAG_KEEP_MAPPED = (1 << 0),
|
GST_FD_MEMORY_FLAG_KEEP_MAPPED = (1 << 0),
|
||||||
GST_FD_MEMORY_FLAG_MAP_PRIVATE = (1 << 1),
|
GST_FD_MEMORY_FLAG_MAP_PRIVATE = (1 << 1),
|
||||||
|
GST_FD_MEMORY_FLAG_DONT_CLOSE = (1 << 2),
|
||||||
} GstFdMemoryFlags;
|
} GstFdMemoryFlags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue