GstFdMemory *mem = (GstFdMemory *) gmem;
if (mem->data) {
- g_warning (G_STRLOC ":%s: Freeing memory %p still mapped", G_STRFUNC, mem);
+ if (!(mem->flags & GST_FD_MEMORY_FLAG_KEEP_MAPPED))
+ g_warning (G_STRLOC ":%s: Freeing memory %p still mapped", G_STRFUNC,
+ mem);
+
munmap ((void *) mem->data, gmem->maxsize);
}
if (mem->fd >= 0 && gmem->parent == NULL)
if (gmem->parent)
return gst_fd_mem_map (gmem->parent, maxsize, flags);
- g_mutex_lock (&mem->lock);
-
prot = flags & GST_MAP_READ ? PROT_READ : 0;
prot |= flags & GST_MAP_WRITE ? PROT_WRITE : 0;
+ g_mutex_lock (&mem->lock);
/* do not mmap twice the buffer */
if (mem->data) {
/* only return address if mapping flags are a subset
}
if (mem->fd != -1) {
- mem->data = mmap (0, gmem->maxsize, prot, MAP_SHARED, mem->fd, 0);
+ gint flags;
+
+ flags =
+ (mem->flags & GST_FD_MEMORY_FLAG_MAP_PRIVATE) ? MAP_PRIVATE :
+ MAP_SHARED;
+
+ mem->data = mmap (0, gmem->maxsize, prot, flags, mem->fd, 0);
if (mem->data == MAP_FAILED) {
mem->data = NULL;
GST_ERROR ("%p: fd %d: mmap failed: %s", mem, mem->fd,
if (gmem->parent)
return gst_fd_mem_unmap (gmem->parent);
- g_mutex_lock (&mem->lock);
+ if (mem->flags & GST_FD_MEMORY_FLAG_KEEP_MAPPED)
+ return;
+ g_mutex_lock (&mem->lock);
if (mem->data && !(--mem->mmap_count)) {
munmap ((void *) mem->data, gmem->maxsize);
mem->data = NULL;
* @allocator: allocator to be used for this memory
* @fd: file descriptor
* @size: memory size
+ * @flags: extra #GstFdMemoryFlags
*
* Return a %GstMemory that wraps a file descriptor.
*
* Since: 1.2
*/
GstMemory *
-__gst_fd_memory_new (GstAllocator * allocator, gint fd, gsize size)
+__gst_fd_memory_new (GstAllocator * allocator, gint fd, gsize size,
+ GstFdMemoryFlags flags)
{
#ifdef HAVE_MMAP
GstFdMemory *mem;
mem = g_slice_new0 (GstFdMemory);
gst_memory_init (GST_MEMORY_CAST (mem), 0, allocator, NULL, size, 0, 0, size);
+ mem->flags = flags;
mem->fd = fd;
g_mutex_init (&mem->lock);
G_BEGIN_DECLS
+/**
+ * @GST_FD_MEMORY_FLAG_NONE: no flag
+ * @GST_FD_MEMORY_FLAG_KEEP_MAPPED: once the memory is mapped,
+ * keep it mapped until the memory is destroyed.
+ * @GST_FD_MEMORY_FLAG_MAP_PRIVATE: do a private mapping instead of
+ * the default shared mapping.
+ *
+ * Various flags to control the operation of the fd backed memory.
+ */
+typedef enum {
+ GST_FD_MEMORY_FLAG_NONE = 0,
+ GST_FD_MEMORY_FLAG_KEEP_MAPPED = (1 << 0),
+ GST_FD_MEMORY_FLAG_MAP_PRIVATE = (1 << 1),
+} GstFdMemoryFlags;
+
/*
- * GstFdfMemory
+ * GstFdMemory
+ * @flags: #GstFdMemoryFlags
* @fd: the file descriptor associated this memory
* @data: mmapped address
* @mmapping_flags: mmapping flags
{
GstMemory mem;
+ GstFdMemoryFlags flags;
gint fd;
gpointer data;
gint mmapping_flags;
void __gst_fd_memory_class_init_allocator (GstAllocatorClass * allocator);
void __gst_fd_memory_init_allocator (GstAllocator * allocator, const gchar *type);
-GstMemory * __gst_fd_memory_new (GstAllocator * allocator, gint fd, gsize size);
+GstMemory * __gst_fd_memory_new (GstAllocator * allocator, gint fd, gsize size,
+ GstFdMemoryFlags flags);
G_END_DECLS