Blame gst/gstmemory.h

Packit f546b1
/* GStreamer
Packit f546b1
 * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
Packit f546b1
 *
Packit f546b1
 * gstmemory.h: Header for memory blocks
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_MEMORY_H__
Packit f546b1
#define __GST_MEMORY_H__
Packit f546b1
Packit f546b1
#include <gst/gstconfig.h>
Packit f546b1
Packit f546b1
#include <glib-object.h>
Packit f546b1
#include <gst/gstminiobject.h>
Packit f546b1
#include <gst/gstobject.h>
Packit f546b1
Packit f546b1
G_BEGIN_DECLS
Packit f546b1
Packit f546b1
GST_API GType _gst_memory_type;
Packit f546b1
#define GST_TYPE_MEMORY (_gst_memory_type)
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
GType gst_memory_get_type(void);
Packit f546b1
Packit f546b1
typedef struct _GstMemory GstMemory;
Packit f546b1
typedef struct _GstAllocator GstAllocator;
Packit f546b1
Packit f546b1
#define GST_MEMORY_CAST(mem)   ((GstMemory *)(mem))
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMemoryFlags:
Packit f546b1
 * @GST_MEMORY_FLAG_READONLY: memory is readonly. It is not allowed to map the
Packit f546b1
 * memory with #GST_MAP_WRITE.
Packit f546b1
 * @GST_MEMORY_FLAG_NO_SHARE: memory must not be shared. Copies will have to be
Packit f546b1
 * made when this memory needs to be shared between buffers.
Packit f546b1
 * @GST_MEMORY_FLAG_ZERO_PREFIXED: the memory prefix is filled with 0 bytes
Packit f546b1
 * @GST_MEMORY_FLAG_ZERO_PADDED: the memory padding is filled with 0 bytes
Packit f546b1
 * @GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS: the memory is physically contiguous. (Since 1.2)
Packit f546b1
 * @GST_MEMORY_FLAG_NOT_MAPPABLE: the memory can't be mapped via gst_memory_map() without any preconditions. (Since 1.2)
Packit f546b1
 * @GST_MEMORY_FLAG_LAST: first flag that can be used for custom purposes
Packit f546b1
 *
Packit f546b1
 * Flags for wrapped memory.
Packit f546b1
 */
Packit f546b1
typedef enum {
Packit f546b1
  GST_MEMORY_FLAG_READONLY      = GST_MINI_OBJECT_FLAG_LOCK_READONLY,
Packit f546b1
  GST_MEMORY_FLAG_NO_SHARE      = (GST_MINI_OBJECT_FLAG_LAST << 0),
Packit f546b1
  GST_MEMORY_FLAG_ZERO_PREFIXED = (GST_MINI_OBJECT_FLAG_LAST << 1),
Packit f546b1
  GST_MEMORY_FLAG_ZERO_PADDED   = (GST_MINI_OBJECT_FLAG_LAST << 2),
Packit f546b1
  GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS = (GST_MINI_OBJECT_FLAG_LAST << 3),
Packit f546b1
  GST_MEMORY_FLAG_NOT_MAPPABLE  = (GST_MINI_OBJECT_FLAG_LAST << 4),
Packit f546b1
Packit f546b1
  GST_MEMORY_FLAG_LAST          = (GST_MINI_OBJECT_FLAG_LAST << 16)
Packit f546b1
} GstMemoryFlags;
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GST_MEMORY_FLAGS:
Packit f546b1
 * @mem: a #GstMemory.
Packit f546b1
 *
Packit f546b1
 * A flags word containing #GstMemoryFlags flags set on @mem
Packit f546b1
 */
Packit f546b1
#define GST_MEMORY_FLAGS(mem)  GST_MINI_OBJECT_FLAGS (mem)
Packit f546b1
/**
Packit f546b1
 * GST_MEMORY_FLAG_IS_SET:
Packit f546b1
 * @mem: a #GstMemory.
Packit f546b1
 * @flag: the #GstMemoryFlags to check.
Packit f546b1
 *
Packit f546b1
 * Gives the status of a specific flag on a @mem.
Packit f546b1
 */
Packit f546b1
#define GST_MEMORY_FLAG_IS_SET(mem,flag)   GST_MINI_OBJECT_FLAG_IS_SET (mem,flag)
Packit f546b1
/**
Packit f546b1
 * GST_MEMORY_FLAG_UNSET:
Packit f546b1
 * @mem: a #GstMemory.
Packit f546b1
 * @flag: the #GstMemoryFlags to clear.
Packit f546b1
 *
Packit f546b1
 * Clear a specific flag on a @mem.
Packit f546b1
 */
Packit f546b1
#define GST_MEMORY_FLAG_UNSET(mem,flag)   GST_MINI_OBJECT_FLAG_UNSET (mem, flag)
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GST_MEMORY_IS_READONLY:
Packit f546b1
 * @mem: a #GstMemory.
Packit f546b1
 *
Packit f546b1
 * Check if @mem is readonly.
Packit f546b1
 */
Packit f546b1
#define GST_MEMORY_IS_READONLY(mem)        GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_READONLY)
Packit f546b1
/**
Packit f546b1
 * GST_MEMORY_IS_NO_SHARE:
Packit f546b1
 * @mem: a #GstMemory.
Packit f546b1
 *
Packit f546b1
 * Check if @mem cannot be shared between buffers
Packit f546b1
 */
Packit f546b1
#define GST_MEMORY_IS_NO_SHARE(mem)        GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_NO_SHARE)
Packit f546b1
/**
Packit f546b1
 * GST_MEMORY_IS_ZERO_PREFIXED:
Packit f546b1
 * @mem: a #GstMemory.
Packit f546b1
 *
Packit f546b1
 * Check if the prefix in @mem is 0 filled.
Packit f546b1
 */
Packit f546b1
#define GST_MEMORY_IS_ZERO_PREFIXED(mem)   GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_ZERO_PREFIXED)
Packit f546b1
/**
Packit f546b1
 * GST_MEMORY_IS_ZERO_PADDED:
Packit f546b1
 * @mem: a #GstMemory.
Packit f546b1
 *
Packit f546b1
 * Check if the padding in @mem is 0 filled.
Packit f546b1
 */
Packit f546b1
#define GST_MEMORY_IS_ZERO_PADDED(mem)     GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_ZERO_PADDED)
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GST_MEMORY_IS_PHYSICALLY_CONTIGUOUS:
Packit f546b1
 * @mem: a #GstMemory.
Packit f546b1
 *
Packit f546b1
 * Check if @mem is physically contiguous.
Packit f546b1
 *
Packit f546b1
 * Since: 1.2
Packit f546b1
 */
Packit f546b1
#define GST_MEMORY_IS_PHYSICALLY_CONTIGUOUS(mem)     GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS)
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GST_MEMORY_IS_NOT_MAPPABLE:
Packit f546b1
 * @mem: a #GstMemory.
Packit f546b1
 *
Packit f546b1
 * Check if @mem can't be mapped via gst_memory_map() without any preconditions
Packit f546b1
 *
Packit f546b1
 * Since: 1.2
Packit f546b1
 */
Packit f546b1
#define GST_MEMORY_IS_NOT_MAPPABLE(mem)     GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_NOT_MAPPABLE)
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMemory:
Packit f546b1
 * @mini_object: parent structure
Packit f546b1
 * @allocator: pointer to the #GstAllocator
Packit f546b1
 * @parent: parent memory block
Packit f546b1
 * @maxsize: the maximum size allocated
Packit f546b1
 * @align: the alignment of the memory
Packit f546b1
 * @offset: the offset where valid data starts
Packit f546b1
 * @size: the size of valid data
Packit f546b1
 *
Packit f546b1
 * Base structure for memory implementations. Custom memory will put this structure
Packit f546b1
 * as the first member of their structure.
Packit f546b1
 */
Packit f546b1
struct _GstMemory {
Packit f546b1
  GstMiniObject   mini_object;
Packit f546b1
Packit f546b1
  GstAllocator   *allocator;
Packit f546b1
Packit f546b1
  GstMemory      *parent;
Packit f546b1
  gsize           maxsize;
Packit f546b1
  gsize           align;
Packit f546b1
  gsize           offset;
Packit f546b1
  gsize           size;
Packit f546b1
};
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMapFlags:
Packit f546b1
 * @GST_MAP_READ: map for read access
Packit f546b1
 * @GST_MAP_WRITE: map for write access
Packit f546b1
 * @GST_MAP_FLAG_LAST: first flag that can be used for custom purposes
Packit f546b1
 *
Packit f546b1
 * Flags used when mapping memory
Packit f546b1
 */
Packit f546b1
typedef enum {
Packit f546b1
  GST_MAP_READ      = GST_LOCK_FLAG_READ,
Packit f546b1
  GST_MAP_WRITE     = GST_LOCK_FLAG_WRITE,
Packit f546b1
Packit f546b1
  GST_MAP_FLAG_LAST = (1 << 16)
Packit f546b1
} GstMapFlags;
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GST_MAP_READWRITE: (value 3) (type GstMapFlags)
Packit f546b1
 *
Packit f546b1
 * GstMapFlags value alias for GST_MAP_READ | GST_MAP_WRITE
Packit f546b1
 */
Packit f546b1
#define GST_MAP_READWRITE      ((GstMapFlags) (GST_MAP_READ | GST_MAP_WRITE))
Packit f546b1
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMapInfo:
Packit f546b1
 * @memory: a pointer to the mapped memory
Packit f546b1
 * @flags: flags used when mapping the memory
Packit f546b1
 * @data: (array length=size): a pointer to the mapped data
Packit f546b1
 * @size: the valid size in @data
Packit f546b1
 * @maxsize: the maximum bytes in @data
Packit f546b1
 * @user_data: extra private user_data that the implementation of the memory
Packit f546b1
 *             can use to store extra info.
Packit f546b1
 *
Packit f546b1
 * A structure containing the result of a map operation such as
Packit f546b1
 * gst_memory_map(). It contains the data and size.
Packit f546b1
 */
Packit f546b1
typedef struct {
Packit f546b1
  GstMemory *memory;
Packit f546b1
  GstMapFlags flags;
Packit f546b1
  guint8 *data;
Packit f546b1
  gsize size;
Packit f546b1
  gsize maxsize;
Packit f546b1
  /*< protected >*/
Packit f546b1
  gpointer user_data[4];
Packit f546b1
Packit f546b1
  /*< private >*/
Packit f546b1
  gpointer _gst_reserved[GST_PADDING];
Packit f546b1
} GstMapInfo;
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GST_MAP_INFO_INIT:
Packit f546b1
 *
Packit f546b1
 * Initializer for #GstMapInfo
Packit f546b1
 */
Packit f546b1
#define GST_MAP_INFO_INIT { NULL, (GstMapFlags) 0, NULL, 0, 0, { NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL}}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMemoryMapFunction:
Packit f546b1
 * @mem: a #GstMemory
Packit f546b1
 * @maxsize: size to map
Packit f546b1
 * @flags: access mode for the memory
Packit f546b1
 *
Packit f546b1
 * Get the memory of @mem that can be accessed according to the mode specified
Packit f546b1
 * in @flags. The function should return a pointer that contains at least
Packit f546b1
 * @maxsize bytes.
Packit f546b1
 *
Packit f546b1
 * Returns: a pointer to memory of which at least @maxsize bytes can be
Packit f546b1
 * accessed according to the access pattern in @flags.
Packit f546b1
 */
Packit f546b1
typedef gpointer    (*GstMemoryMapFunction)       (GstMemory *mem, gsize maxsize, GstMapFlags flags);
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMemoryMapFullFunction:
Packit f546b1
 * @mem: a #GstMemory
Packit f546b1
 * @info: the #GstMapInfo to map with
Packit f546b1
 * @maxsize: size to map
Packit f546b1
 *
Packit f546b1
 * Get the memory of @mem that can be accessed according to the mode specified
Packit f546b1
 * in @info's flags. The function should return a pointer that contains at least
Packit f546b1
 * @maxsize bytes.
Packit f546b1
 *
Packit f546b1
 * Returns: a pointer to memory of which at least @maxsize bytes can be
Packit f546b1
 * accessed according to the access pattern in @info's flags.
Packit f546b1
 */
Packit f546b1
typedef gpointer    (*GstMemoryMapFullFunction)       (GstMemory *mem, GstMapInfo * info, gsize maxsize);
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMemoryUnmapFunction:
Packit f546b1
 * @mem: a #GstMemory
Packit f546b1
 *
Packit f546b1
 * Return the pointer previously retrieved with gst_memory_map().
Packit f546b1
 */
Packit f546b1
typedef void        (*GstMemoryUnmapFunction)     (GstMemory *mem);
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMemoryUnmapFullFunction:
Packit f546b1
 * @mem: a #GstMemory
Packit f546b1
 * @info: a #GstMapInfo
Packit f546b1
 *
Packit f546b1
 * Return the pointer previously retrieved with gst_memory_map() with @info.
Packit f546b1
 */
Packit f546b1
typedef void        (*GstMemoryUnmapFullFunction)     (GstMemory *mem, GstMapInfo * info);
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMemoryCopyFunction:
Packit f546b1
 * @mem: a #GstMemory
Packit f546b1
 * @offset: an offset
Packit f546b1
 * @size: a size or -1
Packit f546b1
 *
Packit f546b1
 * Copy @size bytes from @mem starting at @offset and return them wrapped in a
Packit f546b1
 * new GstMemory object.
Packit f546b1
 * If @size is set to -1, all bytes starting at @offset are copied.
Packit f546b1
 *
Packit f546b1
 * Returns: a new #GstMemory object wrapping a copy of the requested region in
Packit f546b1
 * @mem.
Packit f546b1
 */
Packit f546b1
typedef GstMemory * (*GstMemoryCopyFunction)      (GstMemory *mem, gssize offset, gssize size);
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMemoryShareFunction:
Packit f546b1
 * @mem: a #GstMemory
Packit f546b1
 * @offset: an offset
Packit f546b1
 * @size: a size or -1
Packit f546b1
 *
Packit f546b1
 * Share @size bytes from @mem starting at @offset and return them wrapped in a
Packit f546b1
 * new GstMemory object. If @size is set to -1, all bytes starting at @offset are
Packit f546b1
 * shared. This function does not make a copy of the bytes in @mem.
Packit f546b1
 *
Packit f546b1
 * Returns: a new #GstMemory object sharing the requested region in @mem.
Packit f546b1
 */
Packit f546b1
typedef GstMemory * (*GstMemoryShareFunction)     (GstMemory *mem, gssize offset, gssize size);
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * GstMemoryIsSpanFunction:
Packit f546b1
 * @mem1: a #GstMemory
Packit f546b1
 * @mem2: a #GstMemory
Packit f546b1
 * @offset: a result offset
Packit f546b1
 *
Packit f546b1
 * Check if @mem1 and @mem2 occupy contiguous memory and return the offset of
Packit f546b1
 * @mem1 in the parent buffer in @offset.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if @mem1 and @mem2 are in contiguous memory.
Packit f546b1
 */
Packit f546b1
typedef gboolean    (*GstMemoryIsSpanFunction)    (GstMemory *mem1, GstMemory *mem2, gsize *offset);
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
void           gst_memory_init         (GstMemory *mem, GstMemoryFlags flags,
Packit f546b1
                                        GstAllocator *allocator, GstMemory *parent,
Packit f546b1
                                        gsize maxsize, gsize align,
Packit f546b1
                                        gsize offset, gsize size);
Packit f546b1
GST_API
Packit f546b1
gboolean       gst_memory_is_type      (GstMemory *mem, const gchar *mem_type);
Packit f546b1
Packit f546b1
/* refcounting */
Packit f546b1
/**
Packit f546b1
 * gst_memory_ref:
Packit f546b1
 * @memory: The memory to refcount
Packit f546b1
 *
Packit f546b1
 * Increase the refcount of this memory.
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full): @memory (for convenience when doing assignments)
Packit f546b1
 */
Packit f546b1
static inline GstMemory *
Packit f546b1
gst_memory_ref (GstMemory * memory)
Packit f546b1
{
Packit f546b1
  return (GstMemory *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (memory));
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_memory_unref:
Packit f546b1
 * @memory: (transfer full): the memory to refcount
Packit f546b1
 *
Packit f546b1
 * Decrease the refcount of an memory, freeing it if the refcount reaches 0.
Packit f546b1
 */
Packit f546b1
static inline void
Packit f546b1
gst_memory_unref (GstMemory * memory)
Packit f546b1
{
Packit f546b1
  gst_mini_object_unref (GST_MINI_OBJECT_CAST (memory));
Packit f546b1
}
Packit f546b1
Packit f546b1
/* getting/setting memory properties */
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
gsize          gst_memory_get_sizes    (GstMemory *mem, gsize *offset, gsize *maxsize);
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
void           gst_memory_resize       (GstMemory *mem, gssize offset, gsize size);
Packit f546b1
Packit f546b1
#define        gst_memory_lock(m,f)        gst_mini_object_lock (GST_MINI_OBJECT_CAST (m), (f))
Packit f546b1
#define        gst_memory_unlock(m,f)      gst_mini_object_unlock (GST_MINI_OBJECT_CAST (m), (f))
Packit f546b1
#define        gst_memory_is_writable(m)   gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (m))
Packit f546b1
#define        gst_memory_make_writable(m) GST_MEMORY_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (m)))
Packit f546b1
Packit f546b1
/* retrieving data */
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
GstMemory *    gst_memory_make_mapped  (GstMemory *mem, GstMapInfo *info, GstMapFlags flags) G_GNUC_WARN_UNUSED_RESULT;
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
gboolean       gst_memory_map          (GstMemory *mem, GstMapInfo *info, GstMapFlags flags);
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
void           gst_memory_unmap        (GstMemory *mem, GstMapInfo *info);
Packit f546b1
Packit f546b1
/* copy and subregions */
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
GstMemory *    gst_memory_copy         (GstMemory *mem, gssize offset, gssize size) G_GNUC_WARN_UNUSED_RESULT;
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
GstMemory *    gst_memory_share        (GstMemory *mem, gssize offset, gssize size) G_GNUC_WARN_UNUSED_RESULT;
Packit f546b1
Packit f546b1
/* span memory */
Packit f546b1
Packit f546b1
GST_API
Packit f546b1
gboolean       gst_memory_is_span      (GstMemory *mem1, GstMemory *mem2, gsize *offset);
Packit f546b1
Packit f546b1
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
Packit f546b1
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstMemory, gst_memory_unref)
Packit f546b1
#endif
Packit f546b1
Packit f546b1
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
Packit f546b1
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAllocator, gst_object_unref)
Packit f546b1
#endif
Packit f546b1
Packit f546b1
G_END_DECLS
Packit f546b1
Packit f546b1
#endif /* __GST_MEMORY_H__ */