Blame gst/gstallocator.h

Packit f546b1
/* GStreamer
Packit f546b1
 * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
Packit f546b1
 *
Packit f546b1
 * gstallocator.h: Header for memory allocation
Packit f546b1
 *
Packit f546b1
 * This library is free software; you can redistribute it and/or
Packit f546b1
 * modify it under the terms of the GNU Library General Public
Packit f546b1
 * License as published by the Free Software Foundation; either
Packit f546b1
 * version 2 of the License, or (at your option) any later version.
Packit f546b1
 *
Packit f546b1
 * This library is distributed in the hope that it will be useful,
Packit f546b1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit f546b1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit f546b1
 * Library General Public License for more details.
Packit f546b1
 *
Packit f546b1
 * You should have received a copy of the GNU Library General Public
Packit f546b1
 * License along with this library; if not, write to the
Packit f546b1
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit f546b1
 * Boston, MA 02110-1301, USA.
Packit f546b1
 */
Packit f546b1
Packit f546b1
Packit f546b1
#ifndef __GST_ALLOCATOR_H__
Packit f546b1
#define __GST_ALLOCATOR_H__
Packit f546b1
Packit f546b1
#include <gst/gstmemory.h>
Packit f546b1
#include <gst/gstobject.h>
Packit f546b1
Packit f546b1
G_BEGIN_DECLS
Packit f546b1
Packit f546b1
typedef struct _GstAllocatorPrivate GstAllocatorPrivate;
Packit f546b1
typedef struct _GstAllocatorClass GstAllocatorClass;
Packit f546b1
Packit f546b1
#define GST_TYPE_ALLOCATOR                 (gst_allocator_get_type())
Packit f546b1
#define GST_IS_ALLOCATOR(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_ALLOCATOR))
Packit f546b1
#define GST_IS_ALLOCATOR_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_ALLOCATOR))
Packit f546b1
#define GST_ALLOCATOR_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ALLOCATOR, GstAllocatorClass))
Packit f546b1
#define GST_ALLOCATOR(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_ALLOCATOR, GstAllocator))
Packit f546b1
#define GST_ALLOCATOR_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_ALLOCATOR, GstAllocatorClass))
Packit f546b1
#define GST_ALLOCATOR_CAST(obj)            ((GstAllocator *)(obj))
Packit f546b1
Packit f546b1
#define GST_TYPE_ALLOCATION_PARAMS (gst_allocation_params_get_type())
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
GType gst_allocation_params_get_type(void);
Packit f546b1
Packit f546b1
typedef struct _GstAllocationParams GstAllocationParams;
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_memory_alignment:
Packit f546b1
 *
Packit f546b1
 * The default memory alignment in bytes - 1
Packit f546b1
 * an alignment of 7 would be the same as what malloc() guarantees.
Packit f546b1
 */
Packit f546b1
Packit f546b1
GST_API gsize gst_memory_alignment;
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GST_ALLOCATOR_SYSMEM:
Packit f546b1
 *
Packit f546b1
 * The allocator name for the default system memory allocator
Packit f546b1
 */
Packit f546b1
#define GST_ALLOCATOR_SYSMEM   "SystemMemory"
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstAllocationParams:
Packit f546b1
 * @flags: flags to control allocation
Packit f546b1
 * @align: the desired alignment of the memory
Packit f546b1
 * @prefix: the desired prefix
Packit f546b1
 * @padding: the desired padding
Packit f546b1
 *
Packit f546b1
 * Parameters to control the allocation of memory
Packit f546b1
 */
Packit f546b1
struct _GstAllocationParams {
Packit f546b1
  GstMemoryFlags flags;
Packit f546b1
  gsize          align;
Packit f546b1
  gsize          prefix;
Packit f546b1
  gsize          padding;
Packit f546b1
Packit f546b1
  /*< private >*/
Packit f546b1
  gpointer _gst_reserved[GST_PADDING];
Packit f546b1
};
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstAllocatorFlags:
Packit f546b1
 * @GST_ALLOCATOR_FLAG_CUSTOM_ALLOC: The allocator has a custom alloc function.
Packit f546b1
 * @GST_ALLOCATOR_FLAG_LAST: first flag that can be used for custom purposes
Packit f546b1
 *
Packit f546b1
 * Flags for allocators.
Packit f546b1
 */
Packit f546b1
typedef enum {
Packit f546b1
  GST_ALLOCATOR_FLAG_CUSTOM_ALLOC  = (GST_OBJECT_FLAG_LAST << 0),
Packit f546b1
Packit f546b1
  GST_ALLOCATOR_FLAG_LAST          = (GST_OBJECT_FLAG_LAST << 16)
Packit f546b1
} GstAllocatorFlags;
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstAllocator:
Packit f546b1
 * @mem_map: the implementation of the GstMemoryMapFunction
Packit f546b1
 * @mem_unmap: the implementation of the GstMemoryUnmapFunction
Packit f546b1
 * @mem_copy: the implementation of the GstMemoryCopyFunction
Packit f546b1
 * @mem_share: the implementation of the GstMemoryShareFunction
Packit f546b1
 * @mem_is_span: the implementation of the GstMemoryIsSpanFunction
Packit f546b1
 * @mem_map_full: the implementation of the GstMemoryMapFullFunction.
Packit f546b1
 *      Will be used instead of @mem_map if present. (Since 1.6)
Packit f546b1
 * @mem_unmap_full: the implementation of the GstMemoryUnmapFullFunction.
Packit f546b1
 *      Will be used instead of @mem_unmap if present. (Since 1.6)
Packit f546b1
 *
Packit f546b1
 * The #GstAllocator is used to create new memory.
Packit f546b1
 */
Packit f546b1
struct _GstAllocator
Packit f546b1
{
Packit f546b1
  GstObject  object;
Packit f546b1
Packit f546b1
  const gchar               *mem_type;
Packit f546b1
Packit f546b1
  /*< public >*/
Packit f546b1
  GstMemoryMapFunction       mem_map;
Packit f546b1
  GstMemoryUnmapFunction     mem_unmap;
Packit f546b1
Packit f546b1
  GstMemoryCopyFunction      mem_copy;
Packit f546b1
  GstMemoryShareFunction     mem_share;
Packit f546b1
  GstMemoryIsSpanFunction    mem_is_span;
Packit f546b1
Packit f546b1
  GstMemoryMapFullFunction   mem_map_full;
Packit f546b1
  GstMemoryUnmapFullFunction mem_unmap_full;
Packit f546b1
Packit f546b1
  /*< private >*/
Packit f546b1
  gpointer _gst_reserved[GST_PADDING - 2];
Packit f546b1
Packit f546b1
  GstAllocatorPrivate *priv;
Packit f546b1
};
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstAllocatorClass:
Packit f546b1
 * @object_class:  Object parent class
Packit f546b1
 * @alloc: implementation that acquires memory
Packit f546b1
 * @free: implementation that releases memory
Packit f546b1
 *
Packit f546b1
 * The #GstAllocator is used to create new memory.
Packit f546b1
 */
Packit f546b1
struct _GstAllocatorClass {
Packit f546b1
  GstObjectClass object_class;
Packit f546b1
Packit f546b1
  /*< public >*/
Packit f546b1
  GstMemory *  (*alloc)      (GstAllocator *allocator, gsize size,
Packit f546b1
                              GstAllocationParams *params);
Packit f546b1
  void         (*free)       (GstAllocator *allocator, GstMemory *memory);
Packit f546b1
Packit f546b1
  /*< private >*/
Packit f546b1
  gpointer _gst_reserved[GST_PADDING];
Packit f546b1
};
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
GType          gst_allocator_get_type (void);
Packit f546b1
Packit f546b1
/* allocators */
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
void           gst_allocator_register        (const gchar *name, GstAllocator *allocator);
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
GstAllocator * gst_allocator_find            (const gchar *name);
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
void           gst_allocator_set_default     (GstAllocator * allocator);
Packit f546b1
Packit f546b1
/* allocation parameters */
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
void           gst_allocation_params_init    (GstAllocationParams *params);
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
GstAllocationParams *
Packit f546b1
               gst_allocation_params_copy    (const GstAllocationParams *params) G_GNUC_MALLOC;
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
void           gst_allocation_params_free    (GstAllocationParams *params);
Packit f546b1
Packit f546b1
/* allocating memory blocks */
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
GstMemory *    gst_allocator_alloc           (GstAllocator * allocator, gsize size,
Packit f546b1
                                              GstAllocationParams *params);
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
void           gst_allocator_free            (GstAllocator * allocator, GstMemory *memory);
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
GstMemory *    gst_memory_new_wrapped  (GstMemoryFlags flags, gpointer data, gsize maxsize,
Packit f546b1
                                        gsize offset, gsize size, gpointer user_data,
Packit f546b1
                                        GDestroyNotify notify);
Packit f546b1
Packit f546b1
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
Packit f546b1
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAllocationParams, gst_allocation_params_free)
Packit f546b1
#endif
Packit f546b1
Packit f546b1
G_END_DECLS
Packit f546b1
Packit f546b1
#endif /* __GST_ALLOCATOR_H__ */