buffer: more API tweaks

_trim -> _resize
_create_sub -> copy_region
This commit is contained in:
Wim Taymans 2011-03-30 16:47:55 +02:00
parent cf4117b240
commit ebb14d95b2
14 changed files with 115 additions and 122 deletions

View file

@ -26,10 +26,10 @@
* @see_also: #GstPad, #GstMiniObject * @see_also: #GstPad, #GstMiniObject
* *
* Buffers are the basic unit of data transfer in GStreamer. The #GstBuffer * Buffers are the basic unit of data transfer in GStreamer. The #GstBuffer
* type provides all the state necessary to define a region of memory as part * type provides all the state necessary to define the regions of memory as
* of a stream. Sub-buffers are also supported, allowing a smaller region of a * part of a stream. Region copies are also supported, allowing a smaller
* buffer to become its own buffer, with mechanisms in place to ensure that * region of a buffer to become its own buffer, with mechanisms in place to
* neither memory space goes away prematurely. * ensure that neither memory space goes away prematurely.
* *
* Buffers are usually created with gst_buffer_new(). After a buffer has been * Buffers are usually created with gst_buffer_new(). After a buffer has been
* created one will typically allocate memory for it and set the size of the * created one will typically allocate memory for it and set the size of the
@ -85,33 +85,29 @@
* next element. * next element.
* *
* To efficiently create a smaller buffer out of an existing one, you can * To efficiently create a smaller buffer out of an existing one, you can
* use gst_buffer_create_sub(). * use gst_buffer_copy_region().
* *
* If a plug-in wants to modify the buffer data in-place, it should first obtain * If a plug-in wants to modify the buffer data or metadata in-place, it should
* a buffer that is safe to modify by using gst_buffer_make_writable(). This * first obtain a buffer that is safe to modify by using
* function is optimized so that a copy will only be made when it is necessary. * gst_buffer_make_writable(). This function is optimized so that a copy will
* * only be made when it is necessary.
* A plugin that only wishes to modify the metadata of a buffer, such as the
* offset, timestamp or caps, should use gst_buffer_make_metadata_writable(),
* which will create a subbuffer of the original buffer to ensure the caller
* has sole ownership, and not copy the buffer data.
* *
* Several flags of the buffer can be set and unset with the * Several flags of the buffer can be set and unset with the
* GST_BUFFER_FLAG_SET() and GST_BUFFER_FLAG_UNSET() macros. Use * GST_BUFFER_FLAG_SET() and GST_BUFFER_FLAG_UNSET() macros. Use
* GST_BUFFER_FLAG_IS_SET() to test if a certain #GstBufferFlag is set. * GST_BUFFER_FLAG_IS_SET() to test if a certain #GstBufferFlag is set.
* *
* Buffers can be efficiently merged into a larger buffer with * Buffers can be efficiently merged into a larger buffer with
* gst_buffer_merge() and gst_buffer_span() if the gst_buffer_is_span_fast() * gst_buffer_span(), which avoids memory copies when the gst_buffer_is_span_fast()
* function returns TRUE. * function returns TRUE.
* *
* An element should either unref the buffer or push it out on a src pad * An element should either unref the buffer or push it out on a src pad
* using gst_pad_push() (see #GstPad). * using gst_pad_push() (see #GstPad).
* *
* Buffers are usually freed by unreffing them with gst_buffer_unref(). When * Buffers are usually freed by unreffing them with gst_buffer_unref(). When
* the refcount drops to 0, any data pointed to by GST_BUFFER_MALLOCDATA() will * the refcount drops to 0, any data pointed to by the buffer is unreffed as
* also be freed. * well.
* *
* Last reviewed on August 11th, 2006 (0.10.10) * Last reviewed on March 30, 2011 (0.11.0)
*/ */
#include "gst_private.h" #include "gst_private.h"
@ -318,7 +314,7 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
len = GST_BUFFER_MEM_LEN (src); len = GST_BUFFER_MEM_LEN (src);
left = size; left = size;
/* copy and subbuffer */ /* copy and make regions of the memory */
for (i = 0; i < len && left > 0; i++) { for (i = 0; i < len && left > 0; i++) {
mem = GST_BUFFER_MEM_PTR (src, i); mem = GST_BUFFER_MEM_PTR (src, i);
bsize = gst_memory_get_sizes (mem, NULL); bsize = gst_memory_get_sizes (mem, NULL);
@ -332,7 +328,7 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
tocopy = MIN (bsize - offset, left); tocopy = MIN (bsize - offset, left);
if (tocopy < bsize) { if (tocopy < bsize) {
/* we need to clip something */ /* we need to clip something */
mem = gst_memory_sub (mem, offset, tocopy); mem = gst_memory_share (mem, offset, tocopy);
} else { } else {
mem = gst_memory_ref (mem); mem = gst_memory_ref (mem);
} }
@ -547,7 +543,7 @@ gst_buffer_new_and_alloc (guint size)
gst_memory_unmap (mem, data, asize); gst_memory_unmap (mem, data, asize);
/* strip off the buffer */ /* strip off the buffer */
gst_memory_trim (mem, sizeof (GstBufferImpl), size); gst_memory_resize (mem, sizeof (GstBufferImpl), size);
newbuf = GST_BUFFER_CAST (data); newbuf = GST_BUFFER_CAST (data);
@ -697,7 +693,7 @@ gst_buffer_get_size (GstBuffer * buffer)
} }
/** /**
* gst_buffer_trim: * gst_buffer_resize:
* @buffer: a #GstBuffer. * @buffer: a #GstBuffer.
* @offset: the new offset * @offset: the new offset
* @size: the new size * @size: the new size
@ -705,7 +701,7 @@ gst_buffer_get_size (GstBuffer * buffer)
* Set the total size of the buffer * Set the total size of the buffer
*/ */
void void
gst_buffer_trim (GstBuffer * buffer, gsize offset, gsize size) gst_buffer_resize (GstBuffer * buffer, gsize offset, gsize size)
{ {
guint len; guint len;
guint si, di; guint si, di;
@ -741,10 +737,10 @@ gst_buffer_trim (GstBuffer * buffer, gsize offset, gsize size)
if (tocopy < bsize) { if (tocopy < bsize) {
/* we need to clip something */ /* we need to clip something */
if (GST_MEMORY_IS_WRITABLE (mem)) { if (GST_MEMORY_IS_WRITABLE (mem)) {
gst_memory_trim (mem, offset, tocopy); gst_memory_resize (mem, offset, tocopy);
} else { } else {
GstMemory *tmp; GstMemory *tmp;
tmp = gst_memory_sub (mem, offset, tocopy); tmp = gst_memory_share (mem, offset, tocopy);
gst_memory_unref (mem); gst_memory_unref (mem);
mem = tmp; mem = tmp;
} }
@ -1035,7 +1031,7 @@ gst_buffer_set_caps (GstBuffer * buffer, GstCaps * caps)
} }
/** /**
* gst_buffer_create_sub: * gst_buffer_copy_region:
* @parent: a #GstBuffer. * @parent: a #GstBuffer.
* @offset: the offset into parent #GstBuffer at which the new sub-buffer * @offset: the offset into parent #GstBuffer at which the new sub-buffer
* begins. * begins.
@ -1056,28 +1052,22 @@ gst_buffer_set_caps (GstBuffer * buffer, GstCaps * caps)
* invalid. * invalid.
*/ */
GstBuffer * GstBuffer *
gst_buffer_create_sub (GstBuffer * buffer, gsize offset, gsize size) gst_buffer_copy_region (GstBuffer * buffer, GstBufferCopyFlags flags,
gsize offset, gsize size)
{ {
GstBuffer *subbuffer; GstBuffer *copy;
gsize bufsize;
g_return_val_if_fail (buffer != NULL, NULL); g_return_val_if_fail (buffer != NULL, NULL);
g_return_val_if_fail (buffer->mini_object.refcount > 0, NULL);
bufsize = gst_buffer_get_size (buffer);
g_return_val_if_fail (bufsize >= offset, NULL);
if (size == -1)
size = bufsize - offset;
g_return_val_if_fail (bufsize >= offset + size, NULL);
/* create the new buffer */ /* create the new buffer */
subbuffer = gst_buffer_new (); copy = gst_buffer_new ();
GST_CAT_LOG (GST_CAT_BUFFER, "new subbuffer %p of %p %" G_GSIZE_FORMAT GST_CAT_LOG (GST_CAT_BUFFER, "new region copy %p of %p %" G_GSIZE_FORMAT
"-%" G_GSIZE_FORMAT, subbuffer, buffer, offset, size); "-%" G_GSIZE_FORMAT, copy, buffer, offset, size);
gst_buffer_copy_into (subbuffer, buffer, GST_BUFFER_COPY_ALL, offset, size); gst_buffer_copy_into (copy, buffer, flags, offset, size);
return subbuffer; return copy;
} }
static gboolean static gboolean
@ -1129,7 +1119,7 @@ _gst_buffer_arr_span (GstMemory ** mem[], gsize len[], guint n, gsize offset,
if (!writable if (!writable
&& _gst_buffer_arr_is_span_fast (mem, len, n, &poffset, &parent)) { && _gst_buffer_arr_is_span_fast (mem, len, n, &poffset, &parent)) {
span = gst_memory_sub (parent, offset + poffset, size); span = gst_memory_share (parent, offset + poffset, size);
} else { } else {
gsize count, left; gsize count, left;
guint8 *dest, *ptr; guint8 *dest, *ptr;

View file

@ -237,13 +237,12 @@ typedef enum {
/** /**
* GstBuffer: * GstBuffer:
* @mini_object: the parent structure * @mini_object: the parent structure
* @data: pointer to the buffer data * @pool: pointer to the pool owner of the buffer
* @size: size of buffer data * @caps: the #GstCaps describing the data format in this buffer
* @timestamp: timestamp of the buffer, can be #GST_CLOCK_TIME_NONE when the * @timestamp: timestamp of the buffer, can be #GST_CLOCK_TIME_NONE when the
* timestamp is not known or relevant. * timestamp is not known or relevant.
* @duration: duration in time of the buffer data, can be #GST_CLOCK_TIME_NONE * @duration: duration in time of the buffer data, can be #GST_CLOCK_TIME_NONE
* when the duration is not known or relevant. * when the duration is not known or relevant.
* @caps: the #GstCaps describing the data format in this buffer
* @offset: a media specific offset for the buffer data. * @offset: a media specific offset for the buffer data.
* For video frames, this is the frame number of this buffer. * For video frames, this is the frame number of this buffer.
* For audio samples, this is the offset of the first sample in this buffer. * For audio samples, this is the offset of the first sample in this buffer.
@ -251,11 +250,6 @@ typedef enum {
* byte in this buffer. * byte in this buffer.
* @offset_end: the last offset contained in this buffer. It has the same * @offset_end: the last offset contained in this buffer. It has the same
* format as @offset. * format as @offset.
* @malloc_data: a pointer to the allocated memory associated with this buffer.
* When the buffer is freed, this data will freed with @free_func.
* @free_func: a custom function that will be called with @malloc_data, defaults
* to g_free(). Since 0.10.22.
* @parent: the parent buffer if this is a subbuffer. Since 0.10.26.
* *
* The structure of a #GstBuffer. Use the associated macros to access the public * The structure of a #GstBuffer. Use the associated macros to access the public
* variables. * variables.
@ -302,7 +296,7 @@ void gst_buffer_extract (GstBuffer *buffer, gsize offset,
gpointer dest, gsize size); gpointer dest, gsize size);
gsize gst_buffer_get_size (GstBuffer *buffer); gsize gst_buffer_get_size (GstBuffer *buffer);
void gst_buffer_trim (GstBuffer *buffer, gsize offset, gsize size); void gst_buffer_resize (GstBuffer *buffer, gsize offset, gsize size);
/** /**
* gst_buffer_remove_memory: * gst_buffer_remove_memory:
@ -312,7 +306,7 @@ void gst_buffer_trim (GstBuffer *buffer, gsize offset, gsi
* Set the size of @b to @s. This will remove or trim the memory blocks * Set the size of @b to @s. This will remove or trim the memory blocks
* in the buffer. * in the buffer.
*/ */
#define gst_buffer_set_size(b,s) gst_buffer_trim ((b), 0, (s)) #define gst_buffer_set_size(b,s) gst_buffer_resize ((b), 0, (s))
/* getting memory */ /* getting memory */
gpointer gst_buffer_map (GstBuffer *buffer, gsize *size, gsize *maxsize, gpointer gst_buffer_map (GstBuffer *buffer, gsize *size, gsize *maxsize,
@ -386,6 +380,7 @@ gst_buffer_copy (const GstBuffer * buf)
/** /**
* GstBufferCopyFlags: * GstBufferCopyFlags:
* @GST_BUFFER_COPY_NONE: copy nothing
* @GST_BUFFER_COPY_FLAGS: flag indicating that buffer flags should be copied * @GST_BUFFER_COPY_FLAGS: flag indicating that buffer flags should be copied
* @GST_BUFFER_COPY_TIMESTAMPS: flag indicating that buffer timestamp, duration, * @GST_BUFFER_COPY_TIMESTAMPS: flag indicating that buffer timestamp, duration,
* offset and offset_end should be copied * offset and offset_end should be copied
@ -399,6 +394,7 @@ gst_buffer_copy (const GstBuffer * buf)
* function to specify which items should be copied. * function to specify which items should be copied.
*/ */
typedef enum { typedef enum {
GST_BUFFER_COPY_NONE = 0,
GST_BUFFER_COPY_FLAGS = (1 << 0), GST_BUFFER_COPY_FLAGS = (1 << 0),
GST_BUFFER_COPY_TIMESTAMPS = (1 << 1), GST_BUFFER_COPY_TIMESTAMPS = (1 << 1),
GST_BUFFER_COPY_CAPS = (1 << 2), GST_BUFFER_COPY_CAPS = (1 << 2),
@ -474,8 +470,9 @@ G_STMT_START { \
GstCaps* gst_buffer_get_caps (GstBuffer *buffer); GstCaps* gst_buffer_get_caps (GstBuffer *buffer);
void gst_buffer_set_caps (GstBuffer *buffer, GstCaps *caps); void gst_buffer_set_caps (GstBuffer *buffer, GstCaps *caps);
/* creating a subbuffer */ /* creating a region */
GstBuffer* gst_buffer_create_sub (GstBuffer *parent, gsize offset, gsize size); GstBuffer* gst_buffer_copy_region (GstBuffer *parent, GstBufferCopyFlags flags,
gsize offset, gsize size);
/* span, two buffers, intelligently */ /* span, two buffers, intelligently */
gboolean gst_buffer_is_span_fast (GstBuffer *buf1, GstBuffer *buf2); gboolean gst_buffer_is_span_fast (GstBuffer *buf1, GstBuffer *buf2);

View file

@ -47,6 +47,8 @@ G_BEGIN_DECLS
#define gst_pad_get_caps_reffed(p) gst_pad_get_caps(p) #define gst_pad_get_caps_reffed(p) gst_pad_get_caps(p)
#define gst_pad_peer_get_caps_reffed(p) gst_pad_peer_get_caps(p) #define gst_pad_peer_get_caps_reffed(p) gst_pad_peer_get_caps(p)
//#define gst_buffer_create_sub(b,o,s) gst_buffer_copy_region(b,GST_BUFFER_COPY_ALL,o,s)
#ifndef GST_DISABLE_DEPRECATED #ifndef GST_DISABLE_DEPRECATED
#endif /* not GST_DISABLE_DEPRECATED */ #endif /* not GST_DISABLE_DEPRECATED */

View file

@ -44,14 +44,14 @@ typedef struct
} GstMemoryDefault; } GstMemoryDefault;
static const GstMemoryImpl *_default_mem_impl; static const GstMemoryImpl *_default_mem_impl;
static const GstMemoryImpl *_default_sub_impl; static const GstMemoryImpl *_default_share_impl;
static void static void
_default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags, _default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags,
GstMemory * parent, gsize slice_size, gpointer data, GstMemory * parent, gsize slice_size, gpointer data,
GFreeFunc free_func, gsize maxsize, gsize offset, gsize size) GFreeFunc free_func, gsize maxsize, gsize offset, gsize size)
{ {
mem->mem.impl = data ? _default_mem_impl : _default_sub_impl; mem->mem.impl = data ? _default_mem_impl : _default_share_impl;
mem->mem.flags = flags; mem->mem.flags = flags;
mem->mem.refcount = 1; mem->mem.refcount = 1;
mem->mem.parent = parent ? gst_memory_ref (parent) : NULL; mem->mem.parent = parent ? gst_memory_ref (parent) : NULL;
@ -114,7 +114,7 @@ _default_mem_get_sizes (GstMemoryDefault * mem, gsize * maxsize)
} }
static void static void
_default_mem_trim (GstMemoryDefault * mem, gsize offset, gsize size) _default_mem_resize (GstMemoryDefault * mem, gsize offset, gsize size)
{ {
g_return_if_fail (size + mem->offset + offset <= mem->maxsize); g_return_if_fail (size + mem->offset + offset <= mem->maxsize);
@ -135,7 +135,7 @@ _default_mem_map (GstMemoryDefault * mem, gsize * size, gsize * maxsize,
} }
static gpointer static gpointer
_default_sub_map (GstMemoryDefault * mem, gsize * size, gsize * maxsize, _default_share_map (GstMemoryDefault * mem, gsize * size, gsize * maxsize,
GstMapFlags flags) GstMapFlags flags)
{ {
guint8 *data; guint8 *data;
@ -158,7 +158,7 @@ _default_mem_unmap (GstMemoryDefault * mem, gpointer data, gsize size)
} }
static gboolean static gboolean
_default_sub_unmap (GstMemoryDefault * mem, gpointer data, gsize size) _default_share_unmap (GstMemoryDefault * mem, gpointer data, gsize size)
{ {
gboolean res; gboolean res;
guint8 *ptr = data; guint8 *ptr = data;
@ -197,7 +197,7 @@ _default_mem_copy (GstMemoryDefault * mem, gsize offset, gsize size)
} }
static GstMemoryDefault * static GstMemoryDefault *
_default_mem_sub (GstMemoryDefault * mem, gsize offset, gsize size) _default_mem_share (GstMemoryDefault * mem, gsize offset, gsize size)
{ {
GstMemoryDefault *sub; GstMemoryDefault *sub;
GstMemory *parent; GstMemory *parent;
@ -244,7 +244,7 @@ _fallback_copy (GstMemory * mem, gsize offset, gsize size)
} }
static GstMemory * static GstMemory *
_fallback_sub (GstMemory * mem, gsize offset, gsize size) _fallback_share (GstMemory * mem, gsize offset, gsize size)
{ {
GstMemoryDefault *sub; GstMemoryDefault *sub;
GstMemory *parent; GstMemory *parent;
@ -268,19 +268,19 @@ _gst_memory_init (void)
{ {
static const GstMemoryInfo _mem_info = { static const GstMemoryInfo _mem_info = {
(GstMemoryGetSizesFunction) _default_mem_get_sizes, (GstMemoryGetSizesFunction) _default_mem_get_sizes,
(GstMemoryTrimFunction) _default_mem_trim, (GstMemoryResizeFunction) _default_mem_resize,
(GstMemoryMapFunction) _default_mem_map, (GstMemoryMapFunction) _default_mem_map,
(GstMemoryUnmapFunction) _default_mem_unmap, (GstMemoryUnmapFunction) _default_mem_unmap,
(GstMemoryFreeFunction) _default_mem_free, (GstMemoryFreeFunction) _default_mem_free,
(GstMemoryCopyFunction) _default_mem_copy, (GstMemoryCopyFunction) _default_mem_copy,
(GstMemorySubFunction) _default_mem_sub, (GstMemoryShareFunction) _default_mem_share,
(GstMemoryIsSpanFunction) _default_mem_is_span (GstMemoryIsSpanFunction) _default_mem_is_span
}; };
static const GstMemoryInfo _sub_info = { static const GstMemoryInfo _share_info = {
(GstMemoryGetSizesFunction) _default_mem_get_sizes, (GstMemoryGetSizesFunction) _default_mem_get_sizes,
(GstMemoryTrimFunction) _default_mem_trim, (GstMemoryResizeFunction) _default_mem_resize,
(GstMemoryMapFunction) _default_sub_map, (GstMemoryMapFunction) _default_share_map,
(GstMemoryUnmapFunction) _default_sub_unmap, (GstMemoryUnmapFunction) _default_share_unmap,
(GstMemoryFreeFunction) _default_mem_free, (GstMemoryFreeFunction) _default_mem_free,
NULL, NULL,
NULL, NULL,
@ -288,7 +288,8 @@ _gst_memory_init (void)
}; };
_default_mem_impl = gst_memory_register ("GstMemoryDefault", &_mem_info); _default_mem_impl = gst_memory_register ("GstMemoryDefault", &_mem_info);
_default_sub_impl = gst_memory_register ("GstMemorySubbuffer", &_sub_info); _default_share_impl =
gst_memory_register ("GstMemorySharebuffer", &_share_info);
} }
/** /**
@ -309,7 +310,7 @@ gst_memory_register (const gchar * name, const GstMemoryInfo * info)
g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (info != NULL, NULL); g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (info->get_sizes != NULL, NULL); g_return_val_if_fail (info->get_sizes != NULL, NULL);
g_return_val_if_fail (info->trim != NULL, NULL); g_return_val_if_fail (info->resize != NULL, NULL);
g_return_val_if_fail (info->map != NULL, NULL); g_return_val_if_fail (info->map != NULL, NULL);
g_return_val_if_fail (info->unmap != NULL, NULL); g_return_val_if_fail (info->unmap != NULL, NULL);
g_return_val_if_fail (info->free != NULL, NULL); g_return_val_if_fail (info->free != NULL, NULL);
@ -318,7 +319,7 @@ gst_memory_register (const gchar * name, const GstMemoryInfo * info)
impl->name = g_quark_from_string (name); impl->name = g_quark_from_string (name);
impl->info = *info; impl->info = *info;
INSTALL_FALLBACK (copy); INSTALL_FALLBACK (copy);
INSTALL_FALLBACK (sub); INSTALL_FALLBACK (share);
INSTALL_FALLBACK (is_span); INSTALL_FALLBACK (is_span);
GST_DEBUG ("register \"%s\" of size %" G_GSIZE_FORMAT, name); GST_DEBUG ("register \"%s\" of size %" G_GSIZE_FORMAT, name);
@ -437,19 +438,19 @@ gst_memory_copy (GstMemory * mem, gsize offset, gsize size)
} }
void void
gst_memory_trim (GstMemory * mem, gsize offset, gsize size) gst_memory_resize (GstMemory * mem, gsize offset, gsize size)
{ {
g_return_if_fail (mem != NULL); g_return_if_fail (mem != NULL);
mem->impl->info.trim (mem, offset, size); mem->impl->info.resize (mem, offset, size);
} }
GstMemory * GstMemory *
gst_memory_sub (GstMemory * mem, gsize offset, gsize size) gst_memory_share (GstMemory * mem, gsize offset, gsize size)
{ {
g_return_val_if_fail (mem != NULL, NULL); g_return_val_if_fail (mem != NULL, NULL);
return mem->impl->info.sub (mem, offset, size); return mem->impl->info.share (mem, offset, size);
} }
gboolean gboolean

View file

@ -46,7 +46,7 @@ typedef enum {
* GstMemory: * GstMemory:
* @impl: pointer to the #GstMemoryImpl * @impl: pointer to the #GstMemoryImpl
* @refcount: refcount * @refcount: refcount
* @paret: parent memory block * @parent: parent memory block
* *
* Base structure for memory implementations. Custom memory will put this structure * Base structure for memory implementations. Custom memory will put this structure
* as the first member of their structure. * as the first member of their structure.
@ -73,18 +73,17 @@ typedef enum {
*/ */
#define GST_MEMORY_TRACE_NAME "GstMemory" #define GST_MEMORY_TRACE_NAME "GstMemory"
typedef gsize (*GstMemoryGetSizesFunction) (GstMemory *mem, gsize *maxsize); typedef gsize (*GstMemoryGetSizesFunction) (GstMemory *mem, gsize *maxsize);
typedef void (*GstMemoryResizeFunction) (GstMemory *mem, gsize offset, gsize size);
typedef gpointer (*GstMemoryMapFunction) (GstMemory *mem, gsize *size, gsize *maxsize,
GstMapFlags flags);
typedef gboolean (*GstMemoryUnmapFunction) (GstMemory *mem, gpointer data, gsize size);
typedef gpointer (*GstMemoryMapFunction) (GstMemory *mem, gsize *size, gsize *maxsize,
GstMapFlags flags);
typedef gboolean (*GstMemoryUnmapFunction) (GstMemory *mem, gpointer data, gsize size);
typedef void (*GstMemoryFreeFunction) (GstMemory *mem); typedef void (*GstMemoryFreeFunction) (GstMemory *mem);
typedef GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem, gsize offset, gsize size); typedef GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem, gsize offset, gsize size);
typedef void (*GstMemoryTrimFunction) (GstMemory *mem, gsize offset, gsize size); typedef GstMemory * (*GstMemoryShareFunction) (GstMemory *mem, gsize offset, gsize size);
typedef GstMemory * (*GstMemorySubFunction) (GstMemory *mem, gsize offset, gsize size); typedef gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1, GstMemory *mem2, gsize *offset);
typedef gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1, GstMemory *mem2,
gsize *offset);
/** /**
* GstMemoryInfo: * GstMemoryInfo:
@ -94,13 +93,13 @@ typedef gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1, GstMemory *mem2
*/ */
struct _GstMemoryInfo { struct _GstMemoryInfo {
GstMemoryGetSizesFunction get_sizes; GstMemoryGetSizesFunction get_sizes;
GstMemoryTrimFunction trim; GstMemoryResizeFunction resize;
GstMemoryMapFunction map; GstMemoryMapFunction map;
GstMemoryUnmapFunction unmap; GstMemoryUnmapFunction unmap;
GstMemoryFreeFunction free; GstMemoryFreeFunction free;
GstMemoryCopyFunction copy; GstMemoryCopyFunction copy;
GstMemorySubFunction sub; GstMemoryShareFunction share;
GstMemoryIsSpanFunction is_span; GstMemoryIsSpanFunction is_span;
}; };
@ -119,7 +118,7 @@ void gst_memory_unref (GstMemory *mem);
/* getting/setting memory properties */ /* getting/setting memory properties */
gsize gst_memory_get_sizes (GstMemory *mem, gsize *maxsize); gsize gst_memory_get_sizes (GstMemory *mem, gsize *maxsize);
void gst_memory_trim (GstMemory *mem, gsize offset, gsize size); void gst_memory_resize (GstMemory *mem, gsize offset, gsize size);
/* retriveing data */ /* retriveing data */
gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize, gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize,
@ -128,10 +127,11 @@ gboolean gst_memory_unmap (GstMemory *mem, gpointer data, gsize size);
/* copy and subregions */ /* copy and subregions */
GstMemory * gst_memory_copy (GstMemory *mem, gsize offset, gsize size); GstMemory * gst_memory_copy (GstMemory *mem, gsize offset, gsize size);
GstMemory * gst_memory_sub (GstMemory *mem, gsize offset, gsize size); GstMemory * gst_memory_share (GstMemory *mem, gsize offset, gsize size);
/* span memory */ /* span memory */
gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset); gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset);
GstMemory * gst_memory_span (GstMemory **mem1, gsize len1, gsize offset, GstMemory * gst_memory_span (GstMemory **mem1, gsize len1, gsize offset,
GstMemory **mem2, gsize len2, gsize size); GstMemory **mem2, gsize len2, gsize size);

View file

@ -716,9 +716,9 @@ gst_adapter_take_buffer (GstAdapter * adapter, gsize nbytes)
buffer = gst_buffer_ref (cur); buffer = gst_buffer_ref (cur);
goto done; goto done;
} else if (hsize >= nbytes + skip) { } else if (hsize >= nbytes + skip) {
GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer", GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via region copy",
nbytes); nbytes);
buffer = gst_buffer_create_sub (cur, skip, nbytes); buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, nbytes);
goto done; goto done;
} }
@ -728,7 +728,7 @@ gst_adapter_take_buffer (GstAdapter * adapter, gsize nbytes)
if (gst_buffer_get_size (cur) >= nbytes + skip) { if (gst_buffer_get_size (cur) >= nbytes + skip) {
GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer", GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer",
nbytes); nbytes);
buffer = gst_buffer_create_sub (cur, skip, nbytes); buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, nbytes);
goto done; goto done;
} }
} }

View file

@ -1598,9 +1598,9 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
if (setcaps || copymeta) { if (setcaps || copymeta) {
GST_DEBUG_OBJECT (trans, "setcaps %d, copymeta %d", setcaps, copymeta); GST_DEBUG_OBJECT (trans, "setcaps %d, copymeta %d", setcaps, copymeta);
if (!gst_buffer_is_writable (*out_buf)) { if (!gst_buffer_is_writable (*out_buf)) {
GST_DEBUG_OBJECT (trans, "buffer metadata %p not writable", *out_buf); GST_DEBUG_OBJECT (trans, "buffer %p not writable", *out_buf);
if (in_buf == *out_buf) if (in_buf == *out_buf)
*out_buf = gst_buffer_create_sub (in_buf, 0, insize); *out_buf = gst_buffer_copy (in_buf);
else else
*out_buf = gst_buffer_make_writable (*out_buf); *out_buf = gst_buffer_make_writable (*out_buf);
} }

View file

@ -923,7 +923,8 @@ gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data,
if (data->pos == 0 && readsize == bufsize) if (data->pos == 0 && readsize == bufsize)
return gst_buffer_ref (buffer); return gst_buffer_ref (buffer);
else else
return gst_buffer_create_sub (buffer, data->pos, readsize); return gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, data->pos,
readsize);
} }
/** /**

View file

@ -341,7 +341,7 @@ gst_capsfilter_prepare_buf (GstBaseTransform * trans, GstBuffer * input,
gst_buffer_ref (input); gst_buffer_ref (input);
} else { } else {
GST_DEBUG_OBJECT (trans, "Creating sub-buffer and setting caps"); GST_DEBUG_OBJECT (trans, "Creating sub-buffer and setting caps");
*buf = gst_buffer_create_sub (input, 0, gst_buffer_get_size (input)); *buf = gst_buffer_copy (input);
gst_buffer_set_caps (*buf, caps); gst_buffer_set_caps (*buf, caps);
} }
} else { } else {
@ -373,7 +373,7 @@ gst_capsfilter_prepare_buf (GstBaseTransform * trans, GstBuffer * input,
*buf = input; *buf = input;
} else { } else {
GST_DEBUG_OBJECT (trans, "Creating sub-buffer and setting caps"); GST_DEBUG_OBJECT (trans, "Creating sub-buffer and setting caps");
*buf = gst_buffer_create_sub (input, 0, gst_buffer_get_size (input)); *buf = gst_buffer_copy (input);
} }
GST_BUFFER_CAPS (*buf) = out_caps; GST_BUFFER_CAPS (*buf) = out_caps;

View file

@ -741,7 +741,9 @@ gst_fake_src_create_buffer (GstFakeSrc * src, gsize * bufsize)
} }
/* see if it's large enough */ /* see if it's large enough */
if ((src->parentsize - src->parentoffset) >= size) { if ((src->parentsize - src->parentoffset) >= size) {
buf = gst_buffer_create_sub (src->parent, src->parentoffset, size); buf =
gst_buffer_copy_region (src->parent, GST_BUFFER_COPY_ALL,
src->parentoffset, size);
src->parentoffset += size; src->parentoffset += size;
} else { } else {
/* the parent is useless now */ /* the parent is useless now */

View file

@ -98,8 +98,8 @@ GST_START_TEST (test_subbuffer)
GST_BUFFER_OFFSET (buffer) = 3; GST_BUFFER_OFFSET (buffer) = 3;
GST_BUFFER_OFFSET_END (buffer) = 4; GST_BUFFER_OFFSET_END (buffer) = 4;
sub = gst_buffer_create_sub (buffer, 1, 2); sub = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 1, 2);
fail_if (sub == NULL, "create_sub of buffer returned NULL"); fail_if (sub == NULL, "copy region of buffer returned NULL");
sdata = gst_buffer_map (sub, &ssize, NULL, GST_MAP_READ); sdata = gst_buffer_map (sub, &ssize, NULL, GST_MAP_READ);
fail_unless (ssize == 2, "subbuffer has wrong size"); fail_unless (ssize == 2, "subbuffer has wrong size");
@ -116,8 +116,8 @@ GST_START_TEST (test_subbuffer)
gst_buffer_unref (sub); gst_buffer_unref (sub);
/* create a subbuffer of size 0 */ /* create a subbuffer of size 0 */
sub = gst_buffer_create_sub (buffer, 1, 0); sub = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 1, 0);
fail_if (sub == NULL, "create_sub of buffer returned NULL"); fail_if (sub == NULL, "copy_region of buffer returned NULL");
sdata = gst_buffer_map (sub, &ssize, NULL, GST_MAP_READ); sdata = gst_buffer_map (sub, &ssize, NULL, GST_MAP_READ);
fail_unless (ssize == 0, "subbuffer has wrong size"); fail_unless (ssize == 0, "subbuffer has wrong size");
fail_unless (memcmp (data + 1, sdata, 0) == 0, fail_unless (memcmp (data + 1, sdata, 0) == 0,
@ -128,8 +128,8 @@ GST_START_TEST (test_subbuffer)
/* test if metadata is coppied, not a complete buffer copy so only the /* test if metadata is coppied, not a complete buffer copy so only the
* timestamp and offset fields are copied. */ * timestamp and offset fields are copied. */
sub = gst_buffer_create_sub (buffer, 0, 1); sub = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, 1);
fail_if (sub == NULL, "create_sub of buffer returned NULL"); fail_if (sub == NULL, "copy_region of buffer returned NULL");
fail_unless (gst_buffer_get_size (sub) == 1, "subbuffer has wrong size"); fail_unless (gst_buffer_get_size (sub) == 1, "subbuffer has wrong size");
fail_unless (GST_BUFFER_TIMESTAMP (sub) == 1, fail_unless (GST_BUFFER_TIMESTAMP (sub) == 1,
"subbuffer has wrong timestamp"); "subbuffer has wrong timestamp");
@ -141,8 +141,8 @@ GST_START_TEST (test_subbuffer)
/* test if metadata is coppied, a complete buffer is copied so all the timing /* test if metadata is coppied, a complete buffer is copied so all the timing
* fields should be copied. */ * fields should be copied. */
sub = gst_buffer_create_sub (buffer, 0, 4); sub = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, 4);
fail_if (sub == NULL, "create_sub of buffer returned NULL"); fail_if (sub == NULL, "copy_region of buffer returned NULL");
fail_unless (gst_buffer_get_size (sub) == 4, "subbuffer has wrong size"); fail_unless (gst_buffer_get_size (sub) == 4, "subbuffer has wrong size");
fail_unless (GST_BUFFER_TIMESTAMP (sub) == 1, fail_unless (GST_BUFFER_TIMESTAMP (sub) == 1,
"subbuffer has wrong timestamp"); "subbuffer has wrong timestamp");
@ -166,11 +166,11 @@ GST_START_TEST (test_is_span_fast)
buffer = gst_buffer_new_and_alloc (4); buffer = gst_buffer_new_and_alloc (4);
sub1 = gst_buffer_create_sub (buffer, 0, 2); sub1 = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, 2);
fail_if (sub1 == NULL, "create_sub of buffer returned NULL"); fail_if (sub1 == NULL, "copy_region of buffer returned NULL");
sub2 = gst_buffer_create_sub (buffer, 2, 2); sub2 = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 2, 2);
fail_if (sub2 == NULL, "create_sub of buffer returned NULL"); fail_if (sub2 == NULL, "copy_region of buffer returned NULL");
fail_if (gst_buffer_is_span_fast (buffer, sub2) == TRUE, fail_if (gst_buffer_is_span_fast (buffer, sub2) == TRUE,
"a parent buffer can't be span_fasted"); "a parent buffer can't be span_fasted");
@ -206,11 +206,11 @@ GST_START_TEST (test_span)
ASSERT_CRITICAL (gst_buffer_span (NULL, 1, buffer, 2)); ASSERT_CRITICAL (gst_buffer_span (NULL, 1, buffer, 2));
ASSERT_CRITICAL (gst_buffer_span (buffer, 0, buffer, 10)); ASSERT_CRITICAL (gst_buffer_span (buffer, 0, buffer, 10));
sub1 = gst_buffer_create_sub (buffer, 0, 2); sub1 = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, 2);
fail_if (sub1 == NULL, "create_sub of buffer returned NULL"); fail_if (sub1 == NULL, "copy_region of buffer returned NULL");
sub2 = gst_buffer_create_sub (buffer, 2, 2); sub2 = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 2, 2);
fail_if (sub2 == NULL, "create_sub of buffer returned NULL"); fail_if (sub2 == NULL, "copy_region of buffer returned NULL");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 1); ASSERT_BUFFER_REFCOUNT (buffer, "parent", 1);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1); ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
@ -339,7 +339,7 @@ GST_START_TEST (test_subbuffer_make_writable)
/* create sub-buffer of read-only buffer and make it writable */ /* create sub-buffer of read-only buffer and make it writable */
buf = create_read_only_buffer (); buf = create_read_only_buffer ();
sub_buf = gst_buffer_create_sub (buf, 0, 8); sub_buf = gst_buffer_copy_region (buf, GST_BUFFER_COPY_ALL, 0, 8);
data = gst_buffer_map (sub_buf, &size, NULL, GST_MAP_WRITE); data = gst_buffer_map (sub_buf, &size, NULL, GST_MAP_WRITE);
fail_if (data == NULL); fail_if (data == NULL);

View file

@ -157,7 +157,7 @@ GST_START_TEST (test_meta_test)
gst_buffer_unref (copy); gst_buffer_unref (copy);
/* make subbuffer */ /* make subbuffer */
subbuf = gst_buffer_create_sub (buffer, 0, 1); subbuf = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, 1);
/* get metadata of the buffer */ /* get metadata of the buffer */
meta = GST_META_TEST_GET (subbuf); meta = GST_META_TEST_GET (subbuf);
fail_if (meta == NULL); fail_if (meta == NULL);
@ -168,7 +168,7 @@ GST_START_TEST (test_meta_test)
gst_buffer_unref (subbuf); gst_buffer_unref (subbuf);
/* make another subbuffer */ /* make another subbuffer */
subbuf = gst_buffer_create_sub (buffer, 1, 3); subbuf = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 1, 3);
/* get metadata of the buffer */ /* get metadata of the buffer */
meta = GST_META_TEST_GET (subbuf); meta = GST_META_TEST_GET (subbuf);
fail_if (meta == NULL); fail_if (meta == NULL);

View file

@ -231,13 +231,13 @@ GST_START_TEST (test_take3)
fail_unless (size == 100); fail_unless (size == 100);
/* set up and push subbuffers */ /* set up and push subbuffers */
buffer2 = gst_buffer_create_sub (buffer, 0, 25); buffer2 = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, 25);
gst_adapter_push (adapter, buffer2); gst_adapter_push (adapter, buffer2);
buffer2 = gst_buffer_create_sub (buffer, 25, 25); buffer2 = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 25, 25);
gst_adapter_push (adapter, buffer2); gst_adapter_push (adapter, buffer2);
buffer2 = gst_buffer_create_sub (buffer, 50, 25); buffer2 = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 50, 25);
gst_adapter_push (adapter, buffer2); gst_adapter_push (adapter, buffer2);
buffer2 = gst_buffer_create_sub (buffer, 75, 25); buffer2 = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 75, 25);
gst_adapter_push (adapter, buffer2); gst_adapter_push (adapter, buffer2);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);

View file

@ -92,7 +92,7 @@ EXPORTS
gst_buffer_add_meta gst_buffer_add_meta
gst_buffer_copy_flags_get_type gst_buffer_copy_flags_get_type
gst_buffer_copy_into gst_buffer_copy_into
gst_buffer_create_sub gst_buffer_copy_region
gst_buffer_extract gst_buffer_extract
gst_buffer_fill gst_buffer_fill
gst_buffer_flag_get_type gst_buffer_flag_get_type
@ -138,10 +138,10 @@ EXPORTS
gst_buffer_pool_set_config gst_buffer_pool_set_config
gst_buffer_remove_memory_range gst_buffer_remove_memory_range
gst_buffer_remove_meta gst_buffer_remove_meta
gst_buffer_resize
gst_buffer_set_caps gst_buffer_set_caps
gst_buffer_span gst_buffer_span
gst_buffer_take_memory gst_buffer_take_memory
gst_buffer_trim
gst_buffer_unmap gst_buffer_unmap
gst_buffering_mode_get_type gst_buffering_mode_get_type
gst_bus_add_signal_watch gst_bus_add_signal_watch
@ -540,8 +540,8 @@ EXPORTS
gst_memory_new_wrapped gst_memory_new_wrapped
gst_memory_ref gst_memory_ref
gst_memory_register gst_memory_register
gst_memory_sub gst_memory_resize
gst_memory_trim gst_memory_share
gst_memory_unmap gst_memory_unmap
gst_memory_unref gst_memory_unref
gst_message_get_seqnum gst_message_get_seqnum