2012-07-09 14:02:50 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
|
|
|
|
*
|
|
|
|
* gstallocator.h: Header for memory allocation
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-07-09 14:02:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __GST_ALLOCATOR_H__
|
|
|
|
#define __GST_ALLOCATOR_H__
|
|
|
|
|
|
|
|
#include <gst/gstmemory.h>
|
2015-08-10 22:35:21 +00:00
|
|
|
#include <gst/gstobject.h>
|
2012-07-09 14:02:50 +00:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
typedef struct _GstAllocatorPrivate GstAllocatorPrivate;
|
|
|
|
typedef struct _GstAllocatorClass GstAllocatorClass;
|
|
|
|
|
|
|
|
#define GST_TYPE_ALLOCATOR (gst_allocator_get_type())
|
|
|
|
#define GST_IS_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_ALLOCATOR))
|
|
|
|
#define GST_IS_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_ALLOCATOR))
|
|
|
|
#define GST_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ALLOCATOR, GstAllocatorClass))
|
|
|
|
#define GST_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_ALLOCATOR, GstAllocator))
|
|
|
|
#define GST_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_ALLOCATOR, GstAllocatorClass))
|
|
|
|
#define GST_ALLOCATOR_CAST(obj) ((GstAllocator *)(obj))
|
|
|
|
|
|
|
|
#define GST_TYPE_ALLOCATION_PARAMS (gst_allocation_params_get_type())
|
2017-05-10 09:56:16 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2012-07-09 14:02:50 +00:00
|
|
|
GType gst_allocation_params_get_type(void);
|
|
|
|
|
|
|
|
typedef struct _GstAllocationParams GstAllocationParams;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_memory_alignment:
|
|
|
|
*
|
|
|
|
* The default memory alignment in bytes - 1
|
|
|
|
* an alignment of 7 would be the same as what malloc() guarantees.
|
|
|
|
*/
|
2017-05-10 09:56:16 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API gsize gst_memory_alignment;
|
2012-07-09 14:02:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GST_ALLOCATOR_SYSMEM:
|
|
|
|
*
|
|
|
|
* The allocator name for the default system memory allocator
|
|
|
|
*/
|
|
|
|
#define GST_ALLOCATOR_SYSMEM "SystemMemory"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstAllocationParams:
|
|
|
|
* @flags: flags to control allocation
|
|
|
|
* @align: the desired alignment of the memory
|
|
|
|
* @prefix: the desired prefix
|
|
|
|
* @padding: the desired padding
|
|
|
|
*
|
|
|
|
* Parameters to control the allocation of memory
|
|
|
|
*/
|
|
|
|
struct _GstAllocationParams {
|
|
|
|
GstMemoryFlags flags;
|
|
|
|
gsize align;
|
|
|
|
gsize prefix;
|
|
|
|
gsize padding;
|
|
|
|
|
|
|
|
/*< private >*/
|
|
|
|
gpointer _gst_reserved[GST_PADDING];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstAllocatorFlags:
|
2012-07-09 14:22:04 +00:00
|
|
|
* @GST_ALLOCATOR_FLAG_CUSTOM_ALLOC: The allocator has a custom alloc function.
|
2012-07-09 14:02:50 +00:00
|
|
|
* @GST_ALLOCATOR_FLAG_LAST: first flag that can be used for custom purposes
|
|
|
|
*
|
|
|
|
* Flags for allocators.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
GST_ALLOCATOR_FLAG_CUSTOM_ALLOC = (GST_OBJECT_FLAG_LAST << 0),
|
|
|
|
|
|
|
|
GST_ALLOCATOR_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 16)
|
|
|
|
} GstAllocatorFlags;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstAllocator:
|
|
|
|
* @mem_map: the implementation of the GstMemoryMapFunction
|
|
|
|
* @mem_unmap: the implementation of the GstMemoryUnmapFunction
|
|
|
|
* @mem_copy: the implementation of the GstMemoryCopyFunction
|
|
|
|
* @mem_share: the implementation of the GstMemoryShareFunction
|
|
|
|
* @mem_is_span: the implementation of the GstMemoryIsSpanFunction
|
2015-06-03 14:03:16 +00:00
|
|
|
* @mem_map_full: the implementation of the GstMemoryMapFullFunction.
|
2015-06-14 00:19:59 +00:00
|
|
|
* Will be used instead of @mem_map if present. (Since 1.6)
|
2015-06-03 08:03:36 +00:00
|
|
|
* @mem_unmap_full: the implementation of the GstMemoryUnmapFullFunction.
|
2015-06-14 00:19:59 +00:00
|
|
|
* Will be used instead of @mem_unmap if present. (Since 1.6)
|
2012-07-09 14:02:50 +00:00
|
|
|
*
|
|
|
|
* The #GstAllocator is used to create new memory.
|
|
|
|
*/
|
|
|
|
struct _GstAllocator
|
|
|
|
{
|
|
|
|
GstObject object;
|
|
|
|
|
2015-06-03 08:03:36 +00:00
|
|
|
const gchar *mem_type;
|
2012-07-09 14:02:50 +00:00
|
|
|
|
2014-01-31 07:35:41 +00:00
|
|
|
/*< public >*/
|
2015-06-03 08:03:36 +00:00
|
|
|
GstMemoryMapFunction mem_map;
|
|
|
|
GstMemoryUnmapFunction mem_unmap;
|
2012-07-09 14:02:50 +00:00
|
|
|
|
2015-06-03 08:03:36 +00:00
|
|
|
GstMemoryCopyFunction mem_copy;
|
|
|
|
GstMemoryShareFunction mem_share;
|
|
|
|
GstMemoryIsSpanFunction mem_is_span;
|
|
|
|
|
2015-06-03 14:03:16 +00:00
|
|
|
GstMemoryMapFullFunction mem_map_full;
|
2015-06-03 08:03:36 +00:00
|
|
|
GstMemoryUnmapFullFunction mem_unmap_full;
|
2012-07-09 14:02:50 +00:00
|
|
|
|
2012-07-09 14:22:04 +00:00
|
|
|
/*< private >*/
|
2015-06-03 14:03:16 +00:00
|
|
|
gpointer _gst_reserved[GST_PADDING - 2];
|
2012-07-09 14:02:50 +00:00
|
|
|
|
|
|
|
GstAllocatorPrivate *priv;
|
|
|
|
};
|
|
|
|
|
2014-01-31 07:35:41 +00:00
|
|
|
/**
|
|
|
|
* GstAllocatorClass:
|
|
|
|
* @object_class: Object parent class
|
|
|
|
* @alloc: implementation that acquires memory
|
|
|
|
* @free: implementation that releases memory
|
|
|
|
*
|
|
|
|
* The #GstAllocator is used to create new memory.
|
|
|
|
*/
|
2012-07-09 14:02:50 +00:00
|
|
|
struct _GstAllocatorClass {
|
|
|
|
GstObjectClass object_class;
|
|
|
|
|
2014-01-31 07:35:41 +00:00
|
|
|
/*< public >*/
|
2012-07-09 14:02:50 +00:00
|
|
|
GstMemory * (*alloc) (GstAllocator *allocator, gsize size,
|
2012-07-27 10:12:37 +00:00
|
|
|
GstAllocationParams *params);
|
2012-07-09 14:02:50 +00:00
|
|
|
void (*free) (GstAllocator *allocator, GstMemory *memory);
|
|
|
|
|
|
|
|
/*< private >*/
|
|
|
|
gpointer _gst_reserved[GST_PADDING];
|
|
|
|
};
|
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2017-05-10 09:56:16 +00:00
|
|
|
GType gst_allocator_get_type (void);
|
2012-07-09 14:02:50 +00:00
|
|
|
|
|
|
|
/* allocators */
|
2017-05-10 09:56:16 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2012-07-09 14:02:50 +00:00
|
|
|
void gst_allocator_register (const gchar *name, GstAllocator *allocator);
|
2017-05-10 09:56:16 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2012-07-09 14:02:50 +00:00
|
|
|
GstAllocator * gst_allocator_find (const gchar *name);
|
2017-05-10 09:56:16 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2012-07-09 14:02:50 +00:00
|
|
|
void gst_allocator_set_default (GstAllocator * allocator);
|
|
|
|
|
|
|
|
/* allocation parameters */
|
2017-05-10 09:56:16 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2012-07-09 14:02:50 +00:00
|
|
|
void gst_allocation_params_init (GstAllocationParams *params);
|
2017-05-10 09:56:16 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2012-07-09 14:02:50 +00:00
|
|
|
GstAllocationParams *
|
|
|
|
gst_allocation_params_copy (const GstAllocationParams *params) G_GNUC_MALLOC;
|
2017-05-10 09:56:16 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2012-07-09 14:02:50 +00:00
|
|
|
void gst_allocation_params_free (GstAllocationParams *params);
|
|
|
|
|
|
|
|
/* allocating memory blocks */
|
2017-05-10 09:56:16 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2012-07-09 14:02:50 +00:00
|
|
|
GstMemory * gst_allocator_alloc (GstAllocator * allocator, gsize size,
|
|
|
|
GstAllocationParams *params);
|
2017-05-10 09:56:16 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2012-07-09 14:22:04 +00:00
|
|
|
void gst_allocator_free (GstAllocator * allocator, GstMemory *memory);
|
2012-07-09 14:02:50 +00:00
|
|
|
|
2018-03-12 23:03:26 +00:00
|
|
|
GST_API
|
2012-07-09 14:02:50 +00:00
|
|
|
GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, gsize maxsize,
|
|
|
|
gsize offset, gsize size, gpointer user_data,
|
|
|
|
GDestroyNotify notify);
|
|
|
|
|
2015-11-10 17:38:59 +00:00
|
|
|
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
|
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAllocationParams, gst_allocation_params_free)
|
|
|
|
#endif
|
|
|
|
|
2012-07-09 14:02:50 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __GST_ALLOCATOR_H__ */
|