2011-03-18 17:35:42 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
|
|
|
|
*
|
|
|
|
* gstmemory.h: Header for memory blocks
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __GST_MEMORY_H__
|
|
|
|
#define __GST_MEMORY_H__
|
|
|
|
|
2011-03-21 08:51:53 +00:00
|
|
|
#include <gst/gstconfig.h>
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
2011-03-18 18:28:17 +00:00
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
typedef struct _GstMemory GstMemory;
|
|
|
|
typedef struct _GstMemoryInfo GstMemoryInfo;
|
2011-03-18 18:28:17 +00:00
|
|
|
typedef struct _GstMemoryImpl GstMemoryImpl;
|
2011-03-18 17:35:42 +00:00
|
|
|
|
2011-03-19 09:45:37 +00:00
|
|
|
typedef enum {
|
2011-03-23 19:52:27 +00:00
|
|
|
GST_MEMORY_FLAG_READONLY = (1 << 0)
|
2011-03-19 09:45:37 +00:00
|
|
|
} GstMemoryFlags;
|
|
|
|
|
2011-03-23 19:52:27 +00:00
|
|
|
|
|
|
|
#define GST_MEMORY_IS_WRITABLE(mem) (((mem)->refcount == 1) && \
|
|
|
|
(((mem)->parent == NULL) || ((mem)->parent->refcount == 1)) && \
|
|
|
|
(((mem)->flags & GST_MEMORY_FLAG_READONLY) == 0))
|
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
/**
|
|
|
|
* GstMemory:
|
2011-03-19 09:45:37 +00:00
|
|
|
* @impl: pointer to the #GstMemoryImpl
|
|
|
|
* @refcount: refcount
|
2011-03-30 14:47:55 +00:00
|
|
|
* @parent: parent memory block
|
2011-03-18 17:35:42 +00:00
|
|
|
*
|
|
|
|
* Base structure for memory implementations. Custom memory will put this structure
|
|
|
|
* as the first member of their structure.
|
|
|
|
*/
|
|
|
|
struct _GstMemory {
|
2011-03-18 18:28:17 +00:00
|
|
|
const GstMemoryImpl *impl;
|
2011-03-18 17:35:42 +00:00
|
|
|
|
2011-03-19 09:45:37 +00:00
|
|
|
GstMemoryFlags flags;
|
|
|
|
gint refcount;
|
|
|
|
GstMemory *parent;
|
2011-03-18 17:35:42 +00:00
|
|
|
};
|
|
|
|
|
2011-03-18 18:28:17 +00:00
|
|
|
typedef enum {
|
2011-03-28 08:28:02 +00:00
|
|
|
GST_MAP_READ = (1 << 0),
|
|
|
|
GST_MAP_WRITE = (1 << 1),
|
2011-03-18 18:28:17 +00:00
|
|
|
} GstMapFlags;
|
|
|
|
|
2011-03-28 08:28:02 +00:00
|
|
|
#define GST_MAP_READWRITE (GST_MAP_READ | GST_MAP_WRITE)
|
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
/**
|
|
|
|
* GST_MEMORY_TRACE_NAME:
|
|
|
|
*
|
|
|
|
* The name used for tracing memory allocations.
|
|
|
|
*/
|
|
|
|
#define GST_MEMORY_TRACE_NAME "GstMemory"
|
|
|
|
|
2011-03-30 14:47:55 +00:00
|
|
|
typedef gsize (*GstMemoryGetSizesFunction) (GstMemory *mem, gsize *maxsize);
|
|
|
|
typedef void (*GstMemoryResizeFunction) (GstMemory *mem, gsize offset, gsize size);
|
2011-03-18 17:35:42 +00:00
|
|
|
|
2011-03-30 14:47:55 +00:00
|
|
|
typedef gpointer (*GstMemoryMapFunction) (GstMemory *mem, gsize *size, gsize *maxsize,
|
|
|
|
GstMapFlags flags);
|
|
|
|
typedef gboolean (*GstMemoryUnmapFunction) (GstMemory *mem, gpointer data, gsize size);
|
2011-03-18 20:45:39 +00:00
|
|
|
typedef void (*GstMemoryFreeFunction) (GstMemory *mem);
|
2011-03-30 14:47:55 +00:00
|
|
|
|
2011-03-22 19:51:06 +00:00
|
|
|
typedef GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem, gsize offset, gsize size);
|
2011-03-30 14:47:55 +00:00
|
|
|
typedef GstMemory * (*GstMemoryShareFunction) (GstMemory *mem, gsize offset, gsize size);
|
|
|
|
typedef gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1, GstMemory *mem2, gsize *offset);
|
2011-03-18 17:35:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstMemoryInfo:
|
2011-03-19 09:45:37 +00:00
|
|
|
* @get_sizes:
|
2011-03-18 17:35:42 +00:00
|
|
|
*
|
2011-03-19 09:45:37 +00:00
|
|
|
* The #GstMemoryInfo is used to register new memory implementations.
|
2011-03-18 17:35:42 +00:00
|
|
|
*/
|
|
|
|
struct _GstMemoryInfo {
|
|
|
|
GstMemoryGetSizesFunction get_sizes;
|
2011-03-30 14:47:55 +00:00
|
|
|
GstMemoryResizeFunction resize;
|
2011-03-18 17:35:42 +00:00
|
|
|
GstMemoryMapFunction map;
|
|
|
|
GstMemoryUnmapFunction unmap;
|
2011-03-18 18:28:17 +00:00
|
|
|
GstMemoryFreeFunction free;
|
2011-03-18 20:45:39 +00:00
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
GstMemoryCopyFunction copy;
|
2011-03-30 14:47:55 +00:00
|
|
|
GstMemoryShareFunction share;
|
2011-03-18 20:45:39 +00:00
|
|
|
GstMemoryIsSpanFunction is_span;
|
2011-03-18 17:35:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void _gst_memory_init (void);
|
|
|
|
|
2011-03-22 19:51:06 +00:00
|
|
|
/* allocating memory blocks */
|
2011-03-23 19:52:27 +00:00
|
|
|
GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, GFreeFunc free_func,
|
2011-03-22 19:51:06 +00:00
|
|
|
gsize maxsize, gsize offset, gsize size);
|
|
|
|
GstMemory * gst_memory_new_alloc (gsize maxsize, gsize align);
|
|
|
|
GstMemory * gst_memory_new_copy (gsize maxsize, gsize align, gpointer data,
|
|
|
|
gsize offset, gsize size);
|
|
|
|
|
|
|
|
/* refcounting */
|
2011-03-18 17:35:42 +00:00
|
|
|
GstMemory * gst_memory_ref (GstMemory *mem);
|
|
|
|
void gst_memory_unref (GstMemory *mem);
|
|
|
|
|
2011-03-22 19:51:06 +00:00
|
|
|
/* getting/setting memory properties */
|
2011-03-18 17:35:42 +00:00
|
|
|
gsize gst_memory_get_sizes (GstMemory *mem, gsize *maxsize);
|
2011-03-30 14:47:55 +00:00
|
|
|
void gst_memory_resize (GstMemory *mem, gsize offset, gsize size);
|
2011-03-18 17:35:42 +00:00
|
|
|
|
2011-03-22 19:51:06 +00:00
|
|
|
/* retriveing data */
|
2011-03-18 17:35:42 +00:00
|
|
|
gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize,
|
|
|
|
GstMapFlags flags);
|
|
|
|
gboolean gst_memory_unmap (GstMemory *mem, gpointer data, gsize size);
|
2011-03-29 17:17:55 +00:00
|
|
|
|
2011-03-22 19:51:06 +00:00
|
|
|
/* copy and subregions */
|
|
|
|
GstMemory * gst_memory_copy (GstMemory *mem, gsize offset, gsize size);
|
2011-03-30 14:47:55 +00:00
|
|
|
GstMemory * gst_memory_share (GstMemory *mem, gsize offset, gsize size);
|
2011-03-18 20:45:39 +00:00
|
|
|
|
2011-03-29 17:17:55 +00:00
|
|
|
/* span memory */
|
2011-03-29 14:52:21 +00:00
|
|
|
gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset);
|
2011-03-30 14:47:55 +00:00
|
|
|
|
2011-03-21 12:07:42 +00:00
|
|
|
GstMemory * gst_memory_span (GstMemory **mem1, gsize len1, gsize offset,
|
|
|
|
GstMemory **mem2, gsize len2, gsize size);
|
2011-03-18 17:35:42 +00:00
|
|
|
|
|
|
|
|
2011-03-18 18:28:17 +00:00
|
|
|
const GstMemoryImpl * gst_memory_register (const gchar *impl, const GstMemoryInfo *info);
|
|
|
|
|
2011-03-18 17:35:42 +00:00
|
|
|
#if 0
|
|
|
|
const GstMemoryInfo * gst_memory_get_info (const gchar * impl);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __GST_MEMORY_H__ */
|