X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstmemory.h;h=8244da928d7c039e2b2c6ba348620c2440466563;hb=37edc474e3dc292d53e64f9415536da1741ecede;hp=c69ee596d2b597ed704fa1f487595562c1176285;hpb=1d052f0ccef9872a2d7c82e4286298f34df13b95;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstmemory.h b/gst/gstmemory.h index c69ee59..8244da9 100644 --- a/gst/gstmemory.h +++ b/gst/gstmemory.h @@ -15,8 +15,8 @@ * * 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. + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ @@ -26,30 +26,19 @@ #include #include +#include +#include G_BEGIN_DECLS -#define GST_TYPE_MEMORY (gst_memory_get_type()) -GType gst_memory_get_type(void); - -#define GST_TYPE_ALLOCATOR (gst_allocator_get_type()) -GType gst_allocator_get_type(void); +GST_API GType _gst_memory_type; +#define GST_TYPE_MEMORY (_gst_memory_type) -#define GST_TYPE_ALLOCATION_PARAMS (gst_allocation_params_get_type()) -GType gst_allocation_params_get_type(void); +GST_API +GType gst_memory_get_type(void); typedef struct _GstMemory GstMemory; -typedef struct _GstMemoryInfo GstMemoryInfo; typedef struct _GstAllocator GstAllocator; -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. - */ -GST_EXPORT gsize gst_memory_alignment; #define GST_MEMORY_CAST(mem) ((GstMemory *)(mem)) @@ -61,17 +50,21 @@ GST_EXPORT gsize gst_memory_alignment; * made when this memory needs to be shared between buffers. * @GST_MEMORY_FLAG_ZERO_PREFIXED: the memory prefix is filled with 0 bytes * @GST_MEMORY_FLAG_ZERO_PADDED: the memory padding is filled with 0 bytes + * @GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS: the memory is physically contiguous. (Since 1.2) + * @GST_MEMORY_FLAG_NOT_MAPPABLE: the memory can't be mapped via gst_memory_map() without any preconditions. (Since 1.2) * @GST_MEMORY_FLAG_LAST: first flag that can be used for custom purposes * * Flags for wrapped memory. */ typedef enum { - GST_MEMORY_FLAG_READONLY = (1 << 0), - GST_MEMORY_FLAG_NO_SHARE = (1 << 1), - GST_MEMORY_FLAG_ZERO_PREFIXED = (1 << 2), - GST_MEMORY_FLAG_ZERO_PADDED = (1 << 3), - - GST_MEMORY_FLAG_LAST = (1 << 16) + GST_MEMORY_FLAG_READONLY = GST_MINI_OBJECT_FLAG_LOCK_READONLY, + GST_MEMORY_FLAG_NO_SHARE = (GST_MINI_OBJECT_FLAG_LAST << 0), + GST_MEMORY_FLAG_ZERO_PREFIXED = (GST_MINI_OBJECT_FLAG_LAST << 1), + GST_MEMORY_FLAG_ZERO_PADDED = (GST_MINI_OBJECT_FLAG_LAST << 2), + GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS = (GST_MINI_OBJECT_FLAG_LAST << 3), + GST_MEMORY_FLAG_NOT_MAPPABLE = (GST_MINI_OBJECT_FLAG_LAST << 4), + + GST_MEMORY_FLAG_LAST = (GST_MINI_OBJECT_FLAG_LAST << 16) } GstMemoryFlags; /** @@ -80,7 +73,7 @@ typedef enum { * * A flags word containing #GstMemoryFlags flags set on @mem */ -#define GST_MEMORY_FLAGS(mem) (GST_MEMORY_CAST (mem)->flags) +#define GST_MEMORY_FLAGS(mem) GST_MINI_OBJECT_FLAGS (mem) /** * GST_MEMORY_FLAG_IS_SET: * @mem: a #GstMemory. @@ -88,7 +81,7 @@ typedef enum { * * Gives the status of a specific flag on a @mem. */ -#define GST_MEMORY_FLAG_IS_SET(mem,flag) !!(GST_MEMORY_FLAGS (mem) & (flag)) +#define GST_MEMORY_FLAG_IS_SET(mem,flag) GST_MINI_OBJECT_FLAG_IS_SET (mem,flag) /** * GST_MEMORY_FLAG_UNSET: * @mem: a #GstMemory. @@ -96,7 +89,7 @@ typedef enum { * * Clear a specific flag on a @mem. */ -#define GST_MEMORY_FLAG_UNSET(mem,flag) (GST_MEMORY_FLAGS (mem) &= ~(flag)) +#define GST_MEMORY_FLAG_UNSET(mem,flag) GST_MINI_OBJECT_FLAG_UNSET (mem, flag) /** * GST_MEMORY_IS_READONLY: @@ -106,6 +99,13 @@ typedef enum { */ #define GST_MEMORY_IS_READONLY(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_READONLY) /** + * GST_MEMORY_IS_NO_SHARE: + * @mem: a #GstMemory. + * + * Check if @mem cannot be shared between buffers + */ +#define GST_MEMORY_IS_NO_SHARE(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_NO_SHARE) +/** * GST_MEMORY_IS_ZERO_PREFIXED: * @mem: a #GstMemory. * @@ -120,14 +120,31 @@ typedef enum { */ #define GST_MEMORY_IS_ZERO_PADDED(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_ZERO_PADDED) +/** + * GST_MEMORY_IS_PHYSICALLY_CONTIGUOUS: + * @mem: a #GstMemory. + * + * Check if @mem is physically contiguous. + * + * Since: 1.2 + */ +#define GST_MEMORY_IS_PHYSICALLY_CONTIGUOUS(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS) + +/** + * GST_MEMORY_IS_NOT_MAPPABLE: + * @mem: a #GstMemory. + * + * Check if @mem can't be mapped via gst_memory_map() without any preconditions + * + * Since: 1.2 + */ +#define GST_MEMORY_IS_NOT_MAPPABLE(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_NOT_MAPPABLE) /** * GstMemory: + * @mini_object: parent structure * @allocator: pointer to the #GstAllocator - * @flags: memory flags - * @refcount: refcount * @parent: parent memory block - * @state: private state * @maxsize: the maximum size allocated * @align: the alignment of the memory * @offset: the offset where valid data starts @@ -137,12 +154,11 @@ typedef enum { * as the first member of their structure. */ struct _GstMemory { + GstMiniObject mini_object; + GstAllocator *allocator; - GstMemoryFlags flags; - gint refcount; GstMemory *parent; - volatile gint state; gsize maxsize; gsize align; gsize offset; @@ -158,17 +174,25 @@ struct _GstMemory { * Flags used when mapping memory */ typedef enum { - GST_MAP_READ = (1 << 0), - GST_MAP_WRITE = (1 << 1), + GST_MAP_READ = GST_LOCK_FLAG_READ, + GST_MAP_WRITE = GST_LOCK_FLAG_WRITE, GST_MAP_FLAG_LAST = (1 << 16) } GstMapFlags; /** + * GST_MAP_READWRITE: (value 3) (type GstMapFlags) + * + * GstMapFlags value alias for GST_MAP_READ | GST_MAP_WRITE + */ +#define GST_MAP_READWRITE ((GstMapFlags) (GST_MAP_READ | GST_MAP_WRITE)) + + +/** * GstMapInfo: * @memory: a pointer to the mapped memory * @flags: flags used when mapping the memory - * @data: a pointer to the mapped data + * @data: (array length=size): a pointer to the mapped data * @size: the valid size in @data * @maxsize: the maximum bytes in @data * @user_data: extra private user_data that the implementation of the memory @@ -183,71 +207,19 @@ typedef struct { guint8 *data; gsize size; gsize maxsize; - /*< private >*/ + /*< protected >*/ gpointer user_data[4]; -} GstMapInfo; - -/** - * GST_MAP_INFO_INIT: - * - * Initializer for #GstMapInfo - */ -#define GST_MAP_INFO_INIT { NULL, 0, NULL, 0, 0, } - -/** - * GST_MAP_READWRITE: - * - * Map for readwrite access - */ -#define GST_MAP_READWRITE (GST_MAP_READ | GST_MAP_WRITE) - -/** - * 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 disired 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]; -}; +} GstMapInfo; /** - * GstAllocatorAllocFunction: - * @allocator: a #GstAllocator - * @size: the size - * @params: allocator params - * @user_data: user data - * - * Allocate a new #GstMemory from @allocator that can hold at least @size - * bytes (+ padding) and is aligned to (@align + 1) bytes. - * - * The offset and size of the memory should be set and the prefix/padding must - * be filled with 0 if @params flags contains #GST_MEMORY_FLAG_ZERO_PREFIXED and - * #GST_MEMORY_FLAG_ZERO_PADDED respectively. - * - * @user_data is the data that was used when creating @allocator. + * GST_MAP_INFO_INIT: * - * Returns: a newly allocated #GstMemory. Free with gst_memory_unref() + * Initializer for #GstMapInfo */ -typedef GstMemory * (*GstAllocatorAllocFunction) (GstAllocator *allocator, - gsize size, GstAllocationParams *params, - gpointer user_data); +#define GST_MAP_INFO_INIT { NULL, (GstMapFlags) 0, NULL, 0, 0, { NULL, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL}} /** * GstMemoryMapFunction: @@ -265,23 +237,36 @@ typedef GstMemory * (*GstAllocatorAllocFunction) (GstAllocator *allocator, typedef gpointer (*GstMemoryMapFunction) (GstMemory *mem, gsize maxsize, GstMapFlags flags); /** + * GstMemoryMapFullFunction: + * @mem: a #GstMemory + * @info: the #GstMapInfo to map with + * @maxsize: size to map + * + * Get the memory of @mem that can be accessed according to the mode specified + * in @info's flags. The function should return a pointer that contains at least + * @maxsize bytes. + * + * Returns: a pointer to memory of which at least @maxsize bytes can be + * accessed according to the access pattern in @info's flags. + */ +typedef gpointer (*GstMemoryMapFullFunction) (GstMemory *mem, GstMapInfo * info, gsize maxsize); + +/** * GstMemoryUnmapFunction: * @mem: a #GstMemory * * Return the pointer previously retrieved with gst_memory_map(). - * - * Returns: %TRUE on success. */ typedef void (*GstMemoryUnmapFunction) (GstMemory *mem); /** - * GstMemoryFreeFunction: + * GstMemoryUnmapFullFunction: * @mem: a #GstMemory + * @info: a #GstMapInfo * - * Free the memory used by @mem. This function is usually called when the - * refcount of the @mem has reached 0. + * Return the pointer previously retrieved with gst_memory_map() with @info. */ -typedef void (*GstMemoryFreeFunction) (GstMemory *mem); +typedef void (*GstMemoryUnmapFullFunction) (GstMemory *mem, GstMapInfo * info); /** * GstMemoryCopyFunction: @@ -325,92 +310,86 @@ typedef GstMemory * (*GstMemoryShareFunction) (GstMemory *mem, gssize offset */ typedef gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1, GstMemory *mem2, gsize *offset); +GST_API +void gst_memory_init (GstMemory *mem, GstMemoryFlags flags, + GstAllocator *allocator, GstMemory *parent, + gsize maxsize, gsize align, + gsize offset, gsize size); +GST_API +gboolean gst_memory_is_type (GstMemory *mem, const gchar *mem_type); + +/* refcounting */ /** - * GstMemoryInfo: - * @mem_type: the memory type this allocator provides - * @alloc: the implementation of the GstAllocatorAllocFunction - * @mem_map: the implementation of the GstMemoryMapFunction - * @mem_unmap: the implementation of the GstMemoryUnmapFunction - * @mem_free: the implementation of the GstMemoryFreeFunction - * @mem_copy: the implementation of the GstMemoryCopyFunction - * @mem_share: the implementation of the GstMemoryShareFunction - * @mem_is_span: the implementation of the GstMemoryIsSpanFunction - * - * The #GstMemoryInfo is used to register new memory allocators and contain - * the implementations for various memory operations. + * gst_memory_ref: + * @memory: The memory to refcount + * + * Increase the refcount of this memory. + * + * Returns: (transfer full): @memory (for convenience when doing assignments) */ -struct _GstMemoryInfo { - const gchar *mem_type; - - GstAllocatorAllocFunction alloc; - - GstMemoryMapFunction mem_map; - GstMemoryUnmapFunction mem_unmap; - GstMemoryFreeFunction mem_free; - - GstMemoryCopyFunction mem_copy; - GstMemoryShareFunction mem_share; - GstMemoryIsSpanFunction mem_is_span; - - /*< private >*/ - gpointer _gst_reserved[GST_PADDING]; -}; +static inline GstMemory * +gst_memory_ref (GstMemory * memory) +{ + return (GstMemory *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (memory)); +} /** - * GstAllocator: + * gst_memory_unref: + * @memory: (transfer full): the memory to refcount * - * An opaque type returned from gst_allocator_new() or gst_allocator_find() - * that can be used to allocator memory. + * Decrease the refcount of an memory, freeing it if the refcount reaches 0. */ +static inline void +gst_memory_unref (GstMemory * memory) +{ + gst_mini_object_unref (GST_MINI_OBJECT_CAST (memory)); +} -/* allocators */ -GstAllocator * gst_allocator_new (const GstMemoryInfo * info, - gpointer user_data, GDestroyNotify notify); -const gchar * gst_allocator_get_memory_type (GstAllocator * allocator); - -GstAllocator * gst_allocator_ref (GstAllocator * allocator); -void gst_allocator_unref (GstAllocator * allocator); - -void gst_allocator_register (const gchar *name, GstAllocator *allocator); -GstAllocator * gst_allocator_find (const gchar *name); - -void gst_allocator_set_default (GstAllocator * allocator); - -/* allocating memory blocks */ -void gst_allocation_params_init (GstAllocationParams *params); -GstAllocationParams * - gst_allocation_params_copy (const GstAllocationParams *params) G_GNUC_MALLOC; -void gst_allocation_params_free (GstAllocationParams *params); +/* getting/setting memory properties */ -GstMemory * gst_allocator_alloc (GstAllocator * allocator, gsize size, - GstAllocationParams *params); +GST_API +gsize gst_memory_get_sizes (GstMemory *mem, gsize *offset, gsize *maxsize); -GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, gsize maxsize, - gsize offset, gsize size, gpointer user_data, - GDestroyNotify notify); +GST_API +void gst_memory_resize (GstMemory *mem, gssize offset, gsize size); -/* refcounting */ -GstMemory * gst_memory_ref (GstMemory *mem); -void gst_memory_unref (GstMemory *mem); +#define gst_memory_lock(m,f) gst_mini_object_lock (GST_MINI_OBJECT_CAST (m), (f)) +#define gst_memory_unlock(m,f) gst_mini_object_unlock (GST_MINI_OBJECT_CAST (m), (f)) +#define gst_memory_is_writable(m) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (m)) +#define gst_memory_make_writable(m) GST_MEMORY_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (m))) -gboolean gst_memory_is_exclusive (GstMemory *mem); +/* retrieving data */ -/* getting/setting memory properties */ -gsize gst_memory_get_sizes (GstMemory *mem, gsize *offset, gsize *maxsize); -void gst_memory_resize (GstMemory *mem, gssize offset, gsize size); +GST_API +GstMemory * gst_memory_make_mapped (GstMemory *mem, GstMapInfo *info, GstMapFlags flags) G_GNUC_WARN_UNUSED_RESULT; -/* retrieving data */ -GstMemory * gst_memory_make_mapped (GstMemory *mem, GstMapInfo *info, GstMapFlags flags); +GST_API gboolean gst_memory_map (GstMemory *mem, GstMapInfo *info, GstMapFlags flags); + +GST_API void gst_memory_unmap (GstMemory *mem, GstMapInfo *info); /* copy and subregions */ -GstMemory * gst_memory_copy (GstMemory *mem, gssize offset, gssize size); -GstMemory * gst_memory_share (GstMemory *mem, gssize offset, gssize size); + +GST_API +GstMemory * gst_memory_copy (GstMemory *mem, gssize offset, gssize size) G_GNUC_WARN_UNUSED_RESULT; + +GST_API +GstMemory * gst_memory_share (GstMemory *mem, gssize offset, gssize size) G_GNUC_WARN_UNUSED_RESULT; /* span memory */ + +GST_API gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset); +#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstMemory, gst_memory_unref) +#endif + +#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAllocator, gst_object_unref) +#endif + G_END_DECLS #endif /* __GST_MEMORY_H__ */