2000-12-28 22:12:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstbuffer.c: Buffer operations
|
2000-01-30 09:03:00 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2000-01-30 09:03:00 +00:00
|
|
|
*/
|
2005-10-15 16:01:57 +00:00
|
|
|
|
2005-08-23 11:53:58 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstbuffer
|
2012-03-28 16:12:23 +00:00
|
|
|
* @short_description: Data-passing buffer type
|
|
|
|
* @see_also: #GstPad, #GstMiniObject, #GstMemory, #GstMeta, #GstBufferPool
|
2005-08-23 11:53:58 +00:00
|
|
|
*
|
2012-03-28 16:12:23 +00:00
|
|
|
* Buffers are the basic unit of data transfer in GStreamer. They contain the
|
|
|
|
* timing and offset along with other arbitrary metadata that is associated
|
|
|
|
* with the #GstMemory blocks that the buffer contains.
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
|
|
|
* Buffers are usually created with gst_buffer_new(). After a buffer has been
|
2011-11-08 12:13:55 +00:00
|
|
|
* created one will typically allocate memory for it and add it to the buffer.
|
|
|
|
* The following example creates a buffer that can hold a given video frame
|
|
|
|
* with a given width, height and bits per plane.
|
2014-02-27 17:06:56 +00:00
|
|
|
* |[
|
2005-08-23 11:53:58 +00:00
|
|
|
* GstBuffer *buffer;
|
2011-11-08 12:13:55 +00:00
|
|
|
* GstMemory *memory;
|
2005-08-23 11:53:58 +00:00
|
|
|
* gint size, width, height, bpp;
|
|
|
|
* ...
|
|
|
|
* size = width * height * bpp;
|
|
|
|
* buffer = gst_buffer_new ();
|
2012-03-15 12:28:28 +00:00
|
|
|
* memory = gst_allocator_alloc (NULL, size, NULL);
|
2012-03-30 16:04:51 +00:00
|
|
|
* gst_buffer_insert_memory (buffer, -1, memory);
|
2005-08-23 11:53:58 +00:00
|
|
|
* ...
|
2014-02-27 17:06:56 +00:00
|
|
|
* ]|
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
2014-02-27 17:06:56 +00:00
|
|
|
* Alternatively, use gst_buffer_new_allocate() to create a buffer with
|
|
|
|
* preallocated data of a given size.
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
2011-11-08 12:13:55 +00:00
|
|
|
* Buffers can contain a list of #GstMemory objects. You can retrieve how many
|
|
|
|
* memory objects with gst_buffer_n_memory() and you can get a pointer
|
|
|
|
* to memory with gst_buffer_peek_memory()
|
2006-06-06 08:50:40 +00:00
|
|
|
*
|
2011-10-28 10:15:44 +00:00
|
|
|
* A buffer will usually have timestamps, and a duration, but neither of these
|
2006-06-06 08:50:40 +00:00
|
|
|
* are guaranteed (they may be set to #GST_CLOCK_TIME_NONE). Whenever a
|
2011-10-28 10:15:44 +00:00
|
|
|
* meaningful value can be given for these, they should be set. The timestamps
|
2006-06-06 08:50:40 +00:00
|
|
|
* and duration are measured in nanoseconds (they are #GstClockTime values).
|
|
|
|
*
|
2012-03-28 16:12:23 +00:00
|
|
|
* The buffer DTS refers to the timestamp when the buffer should be decoded and
|
|
|
|
* is usually monotonically increasing. The buffer PTS refers to the timestamp when
|
|
|
|
* the buffer content should be presented to the user and is not always
|
|
|
|
* monotonically increasing.
|
|
|
|
*
|
2005-10-28 17:01:14 +00:00
|
|
|
* A buffer can also have one or both of a start and an end offset. These are
|
|
|
|
* media-type specific. For video buffers, the start offset will generally be
|
2006-06-06 08:50:40 +00:00
|
|
|
* the frame number. For audio buffers, it will be the number of samples
|
|
|
|
* produced so far. For compressed data, it could be the byte offset in a
|
2005-10-28 17:01:14 +00:00
|
|
|
* source or destination file. Likewise, the end offset will be the offset of
|
|
|
|
* the end of the buffer. These can only be meaningfully interpreted if you
|
2013-12-07 14:38:19 +00:00
|
|
|
* know the media type of the buffer (the preceding CAPS event). Either or both
|
2005-11-09 18:10:53 +00:00
|
|
|
* can be set to #GST_BUFFER_OFFSET_NONE.
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
2005-08-23 11:53:58 +00:00
|
|
|
* gst_buffer_ref() is used to increase the refcount of a buffer. This must be
|
|
|
|
* done when you want to keep a handle to the buffer after pushing it to the
|
2012-03-28 16:12:23 +00:00
|
|
|
* next element. The buffer refcount determines the writability of the buffer, a
|
|
|
|
* buffer is only writable when the refcount is exactly 1, i.e. when the caller
|
|
|
|
* has the only reference to the buffer.
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
2005-08-23 11:53:58 +00:00
|
|
|
* To efficiently create a smaller buffer out of an existing one, you can
|
2012-03-28 16:12:23 +00:00
|
|
|
* use gst_buffer_copy_region(). This method tries to share the memory objects
|
|
|
|
* between the two buffers.
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
2011-03-30 14:47:55 +00:00
|
|
|
* If a plug-in wants to modify the buffer data or metadata in-place, it should
|
|
|
|
* first obtain a buffer that is safe to modify by using
|
|
|
|
* gst_buffer_make_writable(). This function is optimized so that a copy will
|
|
|
|
* only be made when it is necessary.
|
2006-01-17 12:14:20 +00:00
|
|
|
*
|
2005-10-15 16:01:57 +00:00
|
|
|
* Several flags of the buffer can be set and unset with the
|
|
|
|
* GST_BUFFER_FLAG_SET() and GST_BUFFER_FLAG_UNSET() macros. Use
|
2013-11-30 13:52:40 +00:00
|
|
|
* GST_BUFFER_FLAG_IS_SET() to test if a certain #GstBufferFlags flag is set.
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
2005-10-15 16:01:57 +00:00
|
|
|
* Buffers can be efficiently merged into a larger buffer with
|
2012-03-28 10:44:44 +00:00
|
|
|
* gst_buffer_append(). Copying of memory will only be done when absolutely
|
|
|
|
* needed.
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
2012-03-28 16:12:23 +00:00
|
|
|
* Arbitrary extra metadata can be set on a buffer with gst_buffer_add_meta().
|
|
|
|
* Metadata can be retrieved with gst_buffer_get_meta(). See also #GstMeta
|
|
|
|
*
|
2005-08-23 11:53:58 +00:00
|
|
|
* An element should either unref the buffer or push it out on a src pad
|
|
|
|
* using gst_pad_push() (see #GstPad).
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
2005-10-28 17:01:14 +00:00
|
|
|
* Buffers are usually freed by unreffing them with gst_buffer_unref(). When
|
2012-03-28 16:12:23 +00:00
|
|
|
* the refcount drops to 0, any memory and metadata pointed to by the buffer is
|
|
|
|
* unreffed as well. Buffers allocated from a #GstBufferPool will be returned to
|
|
|
|
* the pool when the refcount drops to 0.
|
2005-08-23 11:53:58 +00:00
|
|
|
*/
|
2000-12-28 22:12:02 +00:00
|
|
|
#include "gst_private.h"
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2010-03-04 08:44:52 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
2000-12-15 01:57:34 +00:00
|
|
|
#include "gstbuffer.h"
|
2011-02-22 11:35:45 +00:00
|
|
|
#include "gstbufferpool.h"
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gstinfo.h"
|
2005-04-24 22:49:45 +00:00
|
|
|
#include "gstutils.h"
|
2010-03-03 09:31:26 +00:00
|
|
|
#include "gstversion.h"
|
2001-10-17 10:21:27 +00:00
|
|
|
|
2010-11-02 12:31:25 +00:00
|
|
|
GType _gst_buffer_type = 0;
|
2006-07-26 10:39:58 +00:00
|
|
|
|
2011-02-25 12:15:25 +00:00
|
|
|
typedef struct _GstMetaItem GstMetaItem;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2011-02-25 12:15:25 +00:00
|
|
|
struct _GstMetaItem
|
2009-12-17 11:34:42 +00:00
|
|
|
{
|
2011-02-25 12:15:25 +00:00
|
|
|
GstMetaItem *next;
|
|
|
|
GstMeta meta;
|
2009-12-17 11:34:42 +00:00
|
|
|
};
|
2011-03-29 11:51:25 +00:00
|
|
|
#define ITEM_SIZE(info) ((info)->size + sizeof (GstMetaItem))
|
|
|
|
|
|
|
|
#define GST_BUFFER_MEM_MAX 16
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2012-06-14 15:11:11 +00:00
|
|
|
#define GST_BUFFER_SLICE_SIZE(b) (((GstBufferImpl *)(b))->slice_size)
|
2011-03-29 11:51:25 +00:00
|
|
|
#define GST_BUFFER_MEM_LEN(b) (((GstBufferImpl *)(b))->len)
|
|
|
|
#define GST_BUFFER_MEM_ARRAY(b) (((GstBufferImpl *)(b))->mem)
|
|
|
|
#define GST_BUFFER_MEM_PTR(b,i) (((GstBufferImpl *)(b))->mem[i])
|
2011-06-10 14:47:29 +00:00
|
|
|
#define GST_BUFFER_BUFMEM(b) (((GstBufferImpl *)(b))->bufmem)
|
2011-03-29 11:51:25 +00:00
|
|
|
#define GST_BUFFER_META(b) (((GstBufferImpl *)(b))->item)
|
2011-03-29 09:31:30 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstBuffer buffer;
|
|
|
|
|
2012-06-14 15:11:11 +00:00
|
|
|
gsize slice_size;
|
|
|
|
|
2011-03-30 11:04:34 +00:00
|
|
|
/* the memory blocks */
|
2011-03-29 11:51:25 +00:00
|
|
|
guint len;
|
|
|
|
GstMemory *mem[GST_BUFFER_MEM_MAX];
|
|
|
|
|
2011-06-10 14:47:29 +00:00
|
|
|
/* memory of the buffer when allocated from 1 chunk */
|
|
|
|
GstMemory *bufmem;
|
|
|
|
|
2011-03-30 11:04:34 +00:00
|
|
|
/* FIXME, make metadata allocation more efficient by using part of the
|
|
|
|
* GstBufferImpl */
|
2011-03-29 09:31:30 +00:00
|
|
|
GstMetaItem *item;
|
|
|
|
} GstBufferImpl;
|
|
|
|
|
2012-03-28 13:12:05 +00:00
|
|
|
|
|
|
|
static gboolean
|
2012-03-28 14:44:34 +00:00
|
|
|
_is_span (GstMemory ** mem, gsize len, gsize * poffset, GstMemory ** parent)
|
2012-03-28 13:12:05 +00:00
|
|
|
{
|
|
|
|
GstMemory *mcur, *mprv;
|
|
|
|
gboolean have_offset = FALSE;
|
2012-03-28 14:44:34 +00:00
|
|
|
gsize i;
|
2012-03-28 13:12:05 +00:00
|
|
|
|
|
|
|
mcur = mprv = NULL;
|
2012-03-28 14:44:34 +00:00
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (mcur)
|
|
|
|
mprv = mcur;
|
|
|
|
mcur = mem[i];
|
|
|
|
|
|
|
|
if (mprv && mcur) {
|
|
|
|
gsize poffs;
|
|
|
|
|
|
|
|
/* check if memory is contiguous */
|
|
|
|
if (!gst_memory_is_span (mprv, mcur, &poffs))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!have_offset) {
|
|
|
|
if (poffset)
|
|
|
|
*poffset = poffs;
|
|
|
|
if (parent)
|
|
|
|
*parent = mprv->parent;
|
|
|
|
|
|
|
|
have_offset = TRUE;
|
2012-03-28 13:12:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return have_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstMemory *
|
2012-03-30 16:04:51 +00:00
|
|
|
_get_merged_memory (GstBuffer * buffer, guint idx, guint length)
|
2012-03-28 13:12:05 +00:00
|
|
|
{
|
2013-02-24 08:33:03 +00:00
|
|
|
GstMemory **mem, *result = NULL;
|
2012-03-28 13:12:05 +00:00
|
|
|
|
2012-07-04 15:02:09 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER, "buffer %p, idx %u, length %u", buffer, idx,
|
|
|
|
length);
|
2012-07-03 10:23:36 +00:00
|
|
|
|
2012-03-28 14:44:34 +00:00
|
|
|
mem = GST_BUFFER_MEM_ARRAY (buffer);
|
|
|
|
|
2012-03-30 16:04:51 +00:00
|
|
|
if (G_UNLIKELY (length == 0)) {
|
2012-03-28 14:44:34 +00:00
|
|
|
result = NULL;
|
2012-03-30 16:04:51 +00:00
|
|
|
} else if (G_LIKELY (length == 1)) {
|
|
|
|
result = gst_memory_ref (mem[idx]);
|
2012-03-28 13:12:05 +00:00
|
|
|
} else {
|
2012-03-28 14:44:34 +00:00
|
|
|
GstMemory *parent = NULL;
|
2012-03-29 13:18:33 +00:00
|
|
|
gsize size, poffset = 0;
|
2012-03-28 13:12:05 +00:00
|
|
|
|
2013-06-19 06:36:22 +00:00
|
|
|
size = gst_buffer_get_sizes_range (buffer, idx, length, NULL, NULL);
|
2012-03-28 13:12:05 +00:00
|
|
|
|
2012-03-30 16:04:51 +00:00
|
|
|
if (G_UNLIKELY (_is_span (mem + idx, length, &poffset, &parent))) {
|
2013-02-24 08:33:03 +00:00
|
|
|
if (!GST_MEMORY_IS_NO_SHARE (parent))
|
|
|
|
result = gst_memory_share (parent, poffset, size);
|
|
|
|
if (!result) {
|
2012-03-28 14:44:34 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "copy for merge %p", parent);
|
|
|
|
result = gst_memory_copy (parent, poffset, size);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gsize i, tocopy, left;
|
|
|
|
GstMapInfo sinfo, dinfo;
|
|
|
|
guint8 *ptr;
|
|
|
|
|
|
|
|
result = gst_allocator_alloc (NULL, size, NULL);
|
|
|
|
gst_memory_map (result, &dinfo, GST_MAP_WRITE);
|
2012-03-28 13:12:05 +00:00
|
|
|
|
2012-03-28 14:44:34 +00:00
|
|
|
ptr = dinfo.data;
|
|
|
|
left = size;
|
2012-03-28 13:12:05 +00:00
|
|
|
|
2013-06-19 06:36:22 +00:00
|
|
|
for (i = idx; i < (idx + length) && left > 0; i++) {
|
2012-03-28 14:44:34 +00:00
|
|
|
gst_memory_map (mem[i], &sinfo, GST_MAP_READ);
|
2012-03-28 13:12:05 +00:00
|
|
|
tocopy = MIN (sinfo.size, left);
|
|
|
|
GST_CAT_DEBUG (GST_CAT_PERFORMANCE,
|
2012-04-14 08:23:49 +00:00
|
|
|
"memcpy %" G_GSIZE_FORMAT " bytes for merge %p from memory %p",
|
|
|
|
tocopy, result, mem[i]);
|
2012-03-28 13:12:05 +00:00
|
|
|
memcpy (ptr, (guint8 *) sinfo.data, tocopy);
|
|
|
|
left -= tocopy;
|
|
|
|
ptr += tocopy;
|
2012-03-28 14:44:34 +00:00
|
|
|
gst_memory_unmap (mem[i], &sinfo);
|
2012-03-28 13:12:05 +00:00
|
|
|
}
|
2012-03-28 14:44:34 +00:00
|
|
|
gst_memory_unmap (result, &dinfo);
|
2012-03-28 13:12:05 +00:00
|
|
|
}
|
2012-02-13 15:33:00 +00:00
|
|
|
}
|
2012-03-28 14:44:34 +00:00
|
|
|
return result;
|
2012-02-13 15:33:00 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 17:17:55 +00:00
|
|
|
static void
|
2012-03-30 16:04:51 +00:00
|
|
|
_replace_memory (GstBuffer * buffer, guint len, guint idx, guint length,
|
|
|
|
GstMemory * mem)
|
2011-03-29 17:17:55 +00:00
|
|
|
{
|
2012-03-30 16:04:51 +00:00
|
|
|
gsize end, i;
|
2012-02-13 15:33:00 +00:00
|
|
|
|
2012-03-30 16:04:51 +00:00
|
|
|
end = idx + length;
|
2012-07-03 10:18:02 +00:00
|
|
|
|
2012-07-04 15:02:09 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER,
|
|
|
|
"buffer %p replace %u-%" G_GSIZE_FORMAT " with memory %p", buffer, idx,
|
|
|
|
end, mem);
|
2012-03-28 14:44:34 +00:00
|
|
|
|
2012-02-13 15:33:00 +00:00
|
|
|
/* unref old memory */
|
2012-07-03 10:18:02 +00:00
|
|
|
for (i = idx; i < end; i++) {
|
2012-07-04 14:38:15 +00:00
|
|
|
GstMemory *old = GST_BUFFER_MEM_PTR (buffer, i);
|
|
|
|
|
|
|
|
gst_memory_unlock (old, GST_LOCK_FLAG_EXCLUSIVE);
|
|
|
|
gst_memory_unref (old);
|
2012-07-03 10:18:02 +00:00
|
|
|
}
|
2012-03-30 16:04:51 +00:00
|
|
|
|
2012-04-01 10:01:34 +00:00
|
|
|
if (mem != NULL) {
|
|
|
|
/* replace with single memory */
|
2012-07-03 10:18:02 +00:00
|
|
|
gst_memory_lock (mem, GST_LOCK_FLAG_EXCLUSIVE);
|
2012-04-01 10:01:34 +00:00
|
|
|
GST_BUFFER_MEM_PTR (buffer, idx) = mem;
|
|
|
|
idx++;
|
|
|
|
length--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end < len) {
|
2013-11-21 15:04:04 +00:00
|
|
|
memmove (&GST_BUFFER_MEM_PTR (buffer, idx),
|
2012-03-30 16:04:51 +00:00
|
|
|
&GST_BUFFER_MEM_PTR (buffer, end), (len - end) * sizeof (gpointer));
|
|
|
|
}
|
2012-04-01 10:01:34 +00:00
|
|
|
GST_BUFFER_MEM_LEN (buffer) = len - length;
|
2014-03-07 20:43:44 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
|
2011-03-29 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-01 14:23:37 +00:00
|
|
|
/* transfer full for return and transfer none for @mem */
|
|
|
|
static inline GstMemory *
|
|
|
|
_memory_get_exclusive_reference (GstMemory * mem)
|
|
|
|
{
|
|
|
|
GstMemory *ret = NULL;
|
|
|
|
|
|
|
|
if (gst_memory_lock (mem, GST_LOCK_FLAG_EXCLUSIVE)) {
|
|
|
|
ret = gst_memory_ref (mem);
|
|
|
|
} else {
|
|
|
|
/* we cannot take another exclusive lock as the memory is already
|
|
|
|
* locked WRITE + EXCLUSIVE according to part-miniobject.txt */
|
|
|
|
ret = gst_memory_copy (mem, 0, -1);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
if (!gst_memory_lock (ret, GST_LOCK_FLAG_EXCLUSIVE)) {
|
|
|
|
gst_memory_unref (ret);
|
|
|
|
ret = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
GST_CAT_WARNING (GST_CAT_BUFFER, "Failed to acquire an exclusive lock for "
|
|
|
|
"memory %p", mem);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
static inline void
|
2015-06-01 14:23:37 +00:00
|
|
|
_memory_add (GstBuffer * buffer, gint idx, GstMemory * mem)
|
2011-03-29 11:51:25 +00:00
|
|
|
{
|
2011-06-13 14:31:53 +00:00
|
|
|
guint i, len = GST_BUFFER_MEM_LEN (buffer);
|
2011-03-29 14:52:21 +00:00
|
|
|
|
2015-06-01 14:23:37 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER, "buffer %p, idx %d, mem %p", buffer, idx, mem);
|
2012-07-03 10:23:36 +00:00
|
|
|
|
2011-03-29 14:52:21 +00:00
|
|
|
if (G_UNLIKELY (len >= GST_BUFFER_MEM_MAX)) {
|
2011-04-11 08:20:10 +00:00
|
|
|
/* too many buffer, span them. */
|
|
|
|
/* FIXME, there is room for improvement here: We could only try to merge
|
|
|
|
* 2 buffers to make some room. If we can't efficiently merge 2 buffers we
|
|
|
|
* could try to only merge the two smallest buffers to avoid memcpy, etc. */
|
2012-02-02 11:07:28 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "memory array overflow in buffer %p",
|
|
|
|
buffer);
|
2012-03-30 16:04:51 +00:00
|
|
|
_replace_memory (buffer, len, 0, len, _get_merged_memory (buffer, 0, len));
|
2011-03-29 14:52:21 +00:00
|
|
|
/* we now have 1 single spanned buffer */
|
|
|
|
len = 1;
|
|
|
|
}
|
2011-06-13 14:31:53 +00:00
|
|
|
|
|
|
|
if (idx == -1)
|
|
|
|
idx = len;
|
|
|
|
|
|
|
|
for (i = len; i > idx; i--) {
|
|
|
|
/* move buffers to insert, FIXME, we need to insert first and then merge */
|
|
|
|
GST_BUFFER_MEM_PTR (buffer, i) = GST_BUFFER_MEM_PTR (buffer, i - 1);
|
|
|
|
}
|
|
|
|
/* and insert the new buffer */
|
|
|
|
GST_BUFFER_MEM_PTR (buffer, idx) = mem;
|
2011-03-29 11:51:25 +00:00
|
|
|
GST_BUFFER_MEM_LEN (buffer) = len + 1;
|
2014-02-27 13:35:09 +00:00
|
|
|
|
2014-03-07 20:43:44 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
|
2011-03-29 11:51:25 +00:00
|
|
|
}
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2011-08-29 15:06:18 +00:00
|
|
|
GST_DEFINE_MINI_OBJECT_TYPE (GstBuffer, gst_buffer);
|
2011-08-29 13:34:30 +00:00
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
void
|
2011-08-29 11:27:26 +00:00
|
|
|
_priv_gst_buffer_initialize (void)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2011-08-29 13:34:30 +00:00
|
|
|
_gst_buffer_type = gst_buffer_get_type ();
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
|
|
|
|
2013-04-11 13:31:01 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_get_max_memory:
|
|
|
|
*
|
|
|
|
* Get the maximum amount of memory blocks that a buffer can hold. This is a
|
|
|
|
* compile time constant that can be queried with the function.
|
|
|
|
*
|
|
|
|
* When more memory blocks are added, existing memory blocks will be merged
|
|
|
|
* together to make room for the new block.
|
|
|
|
*
|
|
|
|
* Returns: the maximum amount of memory blocks that a buffer can hold.
|
|
|
|
*
|
2013-11-16 12:24:56 +00:00
|
|
|
* Since: 1.2
|
2013-04-11 13:31:01 +00:00
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_buffer_get_max_memory (void)
|
|
|
|
{
|
|
|
|
return GST_BUFFER_MEM_MAX;
|
|
|
|
}
|
|
|
|
|
2007-03-09 16:30:38 +00:00
|
|
|
/**
|
2011-03-21 12:07:42 +00:00
|
|
|
* gst_buffer_copy_into:
|
2007-03-09 16:30:38 +00:00
|
|
|
* @dest: a destination #GstBuffer
|
|
|
|
* @src: a source #GstBuffer
|
|
|
|
* @flags: flags indicating what metadata fields should be copied.
|
2011-03-21 12:07:42 +00:00
|
|
|
* @offset: offset to copy from
|
2011-08-05 08:59:42 +00:00
|
|
|
* @size: total size to copy. If -1, all data is copied.
|
2007-03-09 16:30:38 +00:00
|
|
|
*
|
2011-03-21 12:07:42 +00:00
|
|
|
* Copies the information from @src into @dest.
|
2007-03-09 16:30:38 +00:00
|
|
|
*
|
2012-03-28 13:08:44 +00:00
|
|
|
* If @dest already contains memory and @flags contains GST_BUFFER_COPY_MEMORY,
|
|
|
|
* the memory from @src will be appended to @dest.
|
|
|
|
*
|
2011-03-21 12:07:42 +00:00
|
|
|
* @flags indicate which fields will be copied.
|
2013-02-27 09:09:56 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if the copying succeeded, %FALSE otherwise.
|
2007-03-09 16:30:38 +00:00
|
|
|
*/
|
2013-02-27 09:09:56 +00:00
|
|
|
gboolean
|
2011-03-21 12:07:42 +00:00
|
|
|
gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
|
2011-03-24 20:18:52 +00:00
|
|
|
GstBufferCopyFlags flags, gsize offset, gsize size)
|
2007-03-09 16:30:38 +00:00
|
|
|
{
|
2011-02-25 12:15:25 +00:00
|
|
|
GstMetaItem *walk;
|
2011-03-24 20:18:52 +00:00
|
|
|
gsize bufsize;
|
2012-03-02 11:45:23 +00:00
|
|
|
gboolean region = FALSE;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2013-02-27 09:09:56 +00:00
|
|
|
g_return_val_if_fail (dest != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (src != NULL, FALSE);
|
2007-03-09 16:30:38 +00:00
|
|
|
|
2009-05-27 14:17:31 +00:00
|
|
|
/* nothing to copy if the buffers are the same */
|
|
|
|
if (G_UNLIKELY (dest == src))
|
2013-02-27 09:09:56 +00:00
|
|
|
return TRUE;
|
2009-05-27 14:17:31 +00:00
|
|
|
|
2013-02-27 09:09:56 +00:00
|
|
|
g_return_val_if_fail (gst_buffer_is_writable (dest), FALSE);
|
2011-03-29 14:52:21 +00:00
|
|
|
|
2011-03-24 20:18:52 +00:00
|
|
|
bufsize = gst_buffer_get_size (src);
|
2013-02-27 09:09:56 +00:00
|
|
|
g_return_val_if_fail (bufsize >= offset, FALSE);
|
2012-03-02 11:45:23 +00:00
|
|
|
if (offset > 0)
|
|
|
|
region = TRUE;
|
2011-03-24 20:18:52 +00:00
|
|
|
if (size == -1)
|
|
|
|
size = bufsize - offset;
|
2012-03-02 11:45:23 +00:00
|
|
|
if (size < bufsize)
|
|
|
|
region = TRUE;
|
2013-02-27 09:09:56 +00:00
|
|
|
g_return_val_if_fail (bufsize >= offset + size, FALSE);
|
2009-08-06 16:47:32 +00:00
|
|
|
|
2011-03-28 17:19:44 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER, "copy %p to %p, offset %" G_GSIZE_FORMAT
|
|
|
|
"-%" G_GSIZE_FORMAT "/%" G_GSIZE_FORMAT, src, dest, offset, size,
|
|
|
|
bufsize);
|
2007-03-09 16:30:38 +00:00
|
|
|
|
|
|
|
if (flags & GST_BUFFER_COPY_FLAGS) {
|
2011-08-25 14:20:21 +00:00
|
|
|
/* copy flags */
|
2014-08-26 18:14:40 +00:00
|
|
|
guint flags_mask = ~GST_BUFFER_FLAG_TAG_MEMORY;
|
|
|
|
|
|
|
|
GST_MINI_OBJECT_FLAGS (dest) =
|
|
|
|
(GST_MINI_OBJECT_FLAGS (src) & flags_mask) |
|
|
|
|
(GST_MINI_OBJECT_FLAGS (dest) & ~flags_mask);
|
2007-03-09 16:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & GST_BUFFER_COPY_TIMESTAMPS) {
|
2011-03-21 12:07:42 +00:00
|
|
|
if (offset == 0) {
|
2011-10-28 10:15:44 +00:00
|
|
|
GST_BUFFER_PTS (dest) = GST_BUFFER_PTS (src);
|
|
|
|
GST_BUFFER_DTS (dest) = GST_BUFFER_DTS (src);
|
2011-03-21 12:07:42 +00:00
|
|
|
GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
|
2011-03-28 17:19:44 +00:00
|
|
|
if (size == bufsize) {
|
2011-03-21 12:07:42 +00:00
|
|
|
GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
|
|
|
|
GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-28 10:15:44 +00:00
|
|
|
GST_BUFFER_PTS (dest) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_DTS (dest) = GST_CLOCK_TIME_NONE;
|
2011-03-21 12:07:42 +00:00
|
|
|
GST_BUFFER_DURATION (dest) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET_NONE;
|
|
|
|
GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_NONE;
|
|
|
|
}
|
2007-03-09 16:30:38 +00:00
|
|
|
}
|
2011-05-05 08:37:19 +00:00
|
|
|
|
2011-03-21 12:07:42 +00:00
|
|
|
if (flags & GST_BUFFER_COPY_MEMORY) {
|
2013-02-27 09:09:56 +00:00
|
|
|
gsize skip, left, len, dest_len, i, bsize;
|
2013-02-16 13:59:02 +00:00
|
|
|
gboolean deep;
|
|
|
|
|
|
|
|
deep = flags & GST_BUFFER_COPY_DEEP;
|
2011-03-21 12:07:42 +00:00
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (src);
|
2013-02-27 09:09:56 +00:00
|
|
|
dest_len = GST_BUFFER_MEM_LEN (dest);
|
2011-03-29 09:07:36 +00:00
|
|
|
left = size;
|
2011-04-07 14:02:43 +00:00
|
|
|
skip = offset;
|
2011-03-21 12:07:42 +00:00
|
|
|
|
2011-03-30 14:47:55 +00:00
|
|
|
/* copy and make regions of the memory */
|
2011-03-29 09:07:36 +00:00
|
|
|
for (i = 0; i < len && left > 0; i++) {
|
2013-03-03 11:06:36 +00:00
|
|
|
GstMemory *mem = GST_BUFFER_MEM_PTR (src, i);
|
|
|
|
|
2011-07-11 14:17:57 +00:00
|
|
|
bsize = gst_memory_get_sizes (mem, NULL, NULL);
|
2011-03-29 09:07:36 +00:00
|
|
|
|
2011-04-07 14:02:43 +00:00
|
|
|
if (bsize <= skip) {
|
2011-03-29 09:07:36 +00:00
|
|
|
/* don't copy buffer */
|
2011-04-07 14:02:43 +00:00
|
|
|
skip -= bsize;
|
2011-03-29 09:07:36 +00:00
|
|
|
} else {
|
2013-03-03 11:06:36 +00:00
|
|
|
GstMemory *newmem = NULL;
|
2011-03-29 09:07:36 +00:00
|
|
|
gsize tocopy;
|
|
|
|
|
2011-04-07 14:02:43 +00:00
|
|
|
tocopy = MIN (bsize - skip, left);
|
2013-02-24 08:33:03 +00:00
|
|
|
|
2013-02-26 08:08:49 +00:00
|
|
|
if (tocopy < bsize && !deep && !GST_MEMORY_IS_NO_SHARE (mem)) {
|
2013-02-24 08:33:03 +00:00
|
|
|
/* we need to clip something */
|
2013-03-03 11:06:36 +00:00
|
|
|
newmem = gst_memory_share (mem, skip, tocopy);
|
2015-06-01 14:23:37 +00:00
|
|
|
if (newmem) {
|
|
|
|
gst_memory_lock (newmem, GST_LOCK_FLAG_EXCLUSIVE);
|
2013-03-03 11:06:36 +00:00
|
|
|
skip = 0;
|
2015-06-01 14:23:37 +00:00
|
|
|
}
|
2013-02-24 08:33:03 +00:00
|
|
|
}
|
|
|
|
|
2013-03-03 11:06:36 +00:00
|
|
|
if (deep || GST_MEMORY_IS_NO_SHARE (mem) || (!newmem && tocopy < bsize)) {
|
2013-02-16 13:59:02 +00:00
|
|
|
/* deep copy or we're not allowed to share this memory
|
|
|
|
* between buffers, always copy then */
|
2013-03-03 11:06:36 +00:00
|
|
|
newmem = gst_memory_copy (mem, skip, tocopy);
|
2015-06-01 14:23:37 +00:00
|
|
|
if (newmem) {
|
|
|
|
gst_memory_lock (newmem, GST_LOCK_FLAG_EXCLUSIVE);
|
|
|
|
skip = 0;
|
|
|
|
}
|
2013-03-03 11:06:36 +00:00
|
|
|
} else if (!newmem) {
|
2015-06-01 14:23:37 +00:00
|
|
|
newmem = _memory_get_exclusive_reference (mem);
|
2011-03-24 20:18:52 +00:00
|
|
|
}
|
2013-02-24 08:33:03 +00:00
|
|
|
|
2013-03-03 11:06:36 +00:00
|
|
|
if (!newmem) {
|
2013-02-27 09:09:56 +00:00
|
|
|
gst_buffer_remove_memory_range (dest, dest_len, -1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-02-24 08:33:03 +00:00
|
|
|
|
2015-06-01 14:23:37 +00:00
|
|
|
_memory_add (dest, -1, newmem);
|
2011-03-29 09:07:36 +00:00
|
|
|
left -= tocopy;
|
|
|
|
}
|
2011-03-21 12:07:42 +00:00
|
|
|
}
|
2011-03-29 15:17:46 +00:00
|
|
|
if (flags & GST_BUFFER_COPY_MERGE) {
|
2013-02-27 09:09:56 +00:00
|
|
|
GstMemory *mem;
|
|
|
|
|
2012-03-30 16:04:51 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (dest);
|
2013-02-27 09:09:56 +00:00
|
|
|
mem = _get_merged_memory (dest, 0, len);
|
|
|
|
if (!mem) {
|
|
|
|
gst_buffer_remove_memory_range (dest, dest_len, -1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
_replace_memory (dest, len, 0, len, mem);
|
2011-03-29 15:17:46 +00:00
|
|
|
}
|
2011-03-21 12:07:42 +00:00
|
|
|
}
|
|
|
|
|
2011-12-01 14:34:06 +00:00
|
|
|
if (flags & GST_BUFFER_COPY_META) {
|
2015-06-02 14:12:36 +00:00
|
|
|
/* NOTE: GstGLSyncMeta copying relies on the meta
|
|
|
|
* being copied now, after the buffer data,
|
|
|
|
* so this has to happen last */
|
2011-12-01 14:34:06 +00:00
|
|
|
for (walk = GST_BUFFER_META (src); walk; walk = walk->next) {
|
|
|
|
GstMeta *meta = &walk->meta;
|
|
|
|
const GstMetaInfo *info = meta->info;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2012-02-24 09:23:27 +00:00
|
|
|
if (info->transform_func) {
|
|
|
|
GstMetaTransformCopy copy_data;
|
|
|
|
|
2012-03-02 11:45:23 +00:00
|
|
|
copy_data.region = region;
|
2012-02-24 09:23:27 +00:00
|
|
|
copy_data.offset = offset;
|
|
|
|
copy_data.size = size;
|
|
|
|
|
2015-04-20 07:23:43 +00:00
|
|
|
if (!info->transform_func (dest, meta, src,
|
|
|
|
_gst_meta_transform_copy, ©_data)) {
|
|
|
|
GST_CAT_ERROR (GST_CAT_BUFFER,
|
|
|
|
"failed to copy meta %p of API type %s", meta,
|
|
|
|
g_type_name (info->api));
|
|
|
|
}
|
2012-02-24 09:23:27 +00:00
|
|
|
}
|
2011-12-01 14:34:06 +00:00
|
|
|
}
|
2009-12-17 11:34:42 +00:00
|
|
|
}
|
2013-02-27 09:09:56 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2007-03-09 16:30:38 +00:00
|
|
|
}
|
|
|
|
|
check/Makefile.am: remove GstData checks
Original commit message from CVS:
* check/Makefile.am: remove GstData checks
* check/gst-libs/gdp.c: (START_TEST): fix for API changes
* gst/Makefile.am: add miniobject, remove data
* gst/gst.h: add miniobject, remove data
* gst/gstdata.c: remove
* gst/gstdata.h: remove
* gst/gstdata_private.h: remove
* gst/gsttypes.h: remove GstEvent and GstMessage
* gst/gstelement.c: (gst_element_post_message): fix for API changes
* gst/gstmarshal.list: change BOXED -> OBJECT
Implement GstMiniObject.
* gst/gstminiobject.c:
* gst/gstminiobject.h:
Modify to be subclasses of GstMiniObject.
* gst/gstbuffer.c: (_gst_buffer_initialize), (gst_buffer_get_type),
(gst_buffer_class_init), (gst_buffer_finalize), (_gst_buffer_copy),
(gst_buffer_init), (gst_buffer_new), (gst_buffer_new_and_alloc),
(gst_subbuffer_get_type), (gst_subbuffer_init),
(gst_buffer_create_sub), (gst_buffer_is_span_fast),
(gst_buffer_span):
* gst/gstbuffer.h:
* gst/gstevent.c: (_gst_event_initialize), (gst_event_get_type),
(gst_event_class_init), (gst_event_init), (gst_event_finalize),
(_gst_event_copy), (gst_event_new):
* gst/gstevent.h:
* gst/gstmessage.c: (_gst_message_initialize),
(gst_message_get_type), (gst_message_class_init),
(gst_message_init), (gst_message_finalize), (_gst_message_copy),
(gst_message_new), (gst_message_new_error),
(gst_message_new_warning), (gst_message_new_tag),
(gst_message_new_state_changed), (gst_message_new_application):
* gst/gstmessage.h:
* gst/gstprobe.c: (gst_probe_perform),
(gst_probe_dispatcher_dispatch):
* gst/gstprobe.h:
* gst/gstquery.c: (_gst_query_initialize), (gst_query_get_type),
(gst_query_class_init), (gst_query_finalize), (gst_query_init),
(_gst_query_copy), (gst_query_new):
Update elements for GstData -> GstMiniObject changes
* gst/gstquery.h:
* gst/gstqueue.c: (gst_queue_finalize), (gst_queue_locked_flush),
(gst_queue_chain), (gst_queue_loop):
* gst/elements/gstbufferstore.c:
(gst_buffer_store_add_buffer_func),
(gst_buffer_store_cleared_func), (gst_buffer_store_get_buffer):
* gst/elements/gstfakesink.c: (gst_fakesink_class_init),
(gst_fakesink_render):
* gst/elements/gstfakesrc.c: (gst_fakesrc_class_init):
* gst/elements/gstfilesrc.c: (gst_mmap_buffer_get_type),
(gst_mmap_buffer_class_init), (gst_mmap_buffer_init),
(gst_mmap_buffer_finalize), (gst_filesrc_map_region),
(gst_filesrc_create_read):
* gst/elements/gstidentity.c: (gst_identity_class_init):
* gst/elements/gsttypefindelement.c:
(gst_type_find_element_src_event), (free_entry_buffers),
(gst_type_find_element_handle_event):
* libs/gst/dataprotocol/dataprotocol.c:
(gst_dp_header_from_buffer):
* libs/gst/dataprotocol/dataprotocol.h:
* libs/gst/dataprotocol/dp-private.h:
2005-05-16 20:21:55 +00:00
|
|
|
static GstBuffer *
|
2015-03-14 13:37:09 +00:00
|
|
|
gst_buffer_copy_with_flags (const GstBuffer * buffer, GstBufferCopyFlags flags)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2002-07-08 19:22:02 +00:00
|
|
|
GstBuffer *copy;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-11-22 23:15:14 +00:00
|
|
|
g_return_val_if_fail (buffer != NULL, NULL);
|
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
/* create a fresh new buffer */
|
check/Makefile.am: remove GstData checks
Original commit message from CVS:
* check/Makefile.am: remove GstData checks
* check/gst-libs/gdp.c: (START_TEST): fix for API changes
* gst/Makefile.am: add miniobject, remove data
* gst/gst.h: add miniobject, remove data
* gst/gstdata.c: remove
* gst/gstdata.h: remove
* gst/gstdata_private.h: remove
* gst/gsttypes.h: remove GstEvent and GstMessage
* gst/gstelement.c: (gst_element_post_message): fix for API changes
* gst/gstmarshal.list: change BOXED -> OBJECT
Implement GstMiniObject.
* gst/gstminiobject.c:
* gst/gstminiobject.h:
Modify to be subclasses of GstMiniObject.
* gst/gstbuffer.c: (_gst_buffer_initialize), (gst_buffer_get_type),
(gst_buffer_class_init), (gst_buffer_finalize), (_gst_buffer_copy),
(gst_buffer_init), (gst_buffer_new), (gst_buffer_new_and_alloc),
(gst_subbuffer_get_type), (gst_subbuffer_init),
(gst_buffer_create_sub), (gst_buffer_is_span_fast),
(gst_buffer_span):
* gst/gstbuffer.h:
* gst/gstevent.c: (_gst_event_initialize), (gst_event_get_type),
(gst_event_class_init), (gst_event_init), (gst_event_finalize),
(_gst_event_copy), (gst_event_new):
* gst/gstevent.h:
* gst/gstmessage.c: (_gst_message_initialize),
(gst_message_get_type), (gst_message_class_init),
(gst_message_init), (gst_message_finalize), (_gst_message_copy),
(gst_message_new), (gst_message_new_error),
(gst_message_new_warning), (gst_message_new_tag),
(gst_message_new_state_changed), (gst_message_new_application):
* gst/gstmessage.h:
* gst/gstprobe.c: (gst_probe_perform),
(gst_probe_dispatcher_dispatch):
* gst/gstprobe.h:
* gst/gstquery.c: (_gst_query_initialize), (gst_query_get_type),
(gst_query_class_init), (gst_query_finalize), (gst_query_init),
(_gst_query_copy), (gst_query_new):
Update elements for GstData -> GstMiniObject changes
* gst/gstquery.h:
* gst/gstqueue.c: (gst_queue_finalize), (gst_queue_locked_flush),
(gst_queue_chain), (gst_queue_loop):
* gst/elements/gstbufferstore.c:
(gst_buffer_store_add_buffer_func),
(gst_buffer_store_cleared_func), (gst_buffer_store_get_buffer):
* gst/elements/gstfakesink.c: (gst_fakesink_class_init),
(gst_fakesink_render):
* gst/elements/gstfakesrc.c: (gst_fakesrc_class_init):
* gst/elements/gstfilesrc.c: (gst_mmap_buffer_get_type),
(gst_mmap_buffer_class_init), (gst_mmap_buffer_init),
(gst_mmap_buffer_finalize), (gst_filesrc_map_region),
(gst_filesrc_create_read):
* gst/elements/gstidentity.c: (gst_identity_class_init):
* gst/elements/gsttypefindelement.c:
(gst_type_find_element_src_event), (free_entry_buffers),
(gst_type_find_element_handle_event):
* libs/gst/dataprotocol/dataprotocol.c:
(gst_dp_header_from_buffer):
* libs/gst/dataprotocol/dataprotocol.h:
* libs/gst/dataprotocol/dp-private.h:
2005-05-16 20:21:55 +00:00
|
|
|
copy = gst_buffer_new ();
|
2003-05-06 21:03:34 +00:00
|
|
|
|
2015-03-13 18:35:01 +00:00
|
|
|
/* copy what the 'flags' want from our parent */
|
|
|
|
/* FIXME why we can't pass const to gst_buffer_copy_into() ? */
|
|
|
|
if (!gst_buffer_copy_into (copy, (GstBuffer *) buffer, flags, 0, -1))
|
2013-02-27 09:09:56 +00:00
|
|
|
gst_buffer_replace (©, NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2014-03-24 15:11:30 +00:00
|
|
|
if (copy)
|
|
|
|
GST_BUFFER_FLAG_UNSET (copy, GST_BUFFER_FLAG_TAG_MEMORY);
|
2014-02-27 13:35:09 +00:00
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
return copy;
|
|
|
|
}
|
2001-10-17 10:21:27 +00:00
|
|
|
|
2015-03-13 18:35:01 +00:00
|
|
|
static GstBuffer *
|
|
|
|
_gst_buffer_copy (const GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
return gst_buffer_copy_with_flags (buffer, GST_BUFFER_COPY_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_copy_deep:
|
|
|
|
* @buf: a #GstBuffer.
|
|
|
|
*
|
|
|
|
* Create a copy of the given buffer. This will make a newly allocated
|
|
|
|
* copy of the data the source buffer contains.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new copy of @buf.
|
|
|
|
*/
|
|
|
|
GstBuffer *
|
|
|
|
gst_buffer_copy_deep (const GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
return gst_buffer_copy_with_flags (buffer,
|
|
|
|
GST_BUFFER_COPY_ALL | GST_BUFFER_COPY_DEEP);
|
|
|
|
}
|
|
|
|
|
2011-03-02 10:57:06 +00:00
|
|
|
/* the default dispose function revives the buffer and returns it to the
|
|
|
|
* pool when there is a pool */
|
2011-07-25 10:53:10 +00:00
|
|
|
static gboolean
|
2011-03-02 10:57:06 +00:00
|
|
|
_gst_buffer_dispose (GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstBufferPool *pool;
|
|
|
|
|
2011-07-25 10:53:10 +00:00
|
|
|
/* no pool, do free */
|
|
|
|
if ((pool = buffer->pool) == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* keep the buffer alive */
|
|
|
|
gst_buffer_ref (buffer);
|
|
|
|
/* return the buffer to the pool */
|
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER, "release %p to pool %p", buffer, pool);
|
|
|
|
gst_buffer_pool_release_buffer (pool, buffer);
|
|
|
|
|
|
|
|
return FALSE;
|
2011-03-02 10:57:06 +00:00
|
|
|
}
|
|
|
|
|
check/Makefile.am: remove GstData checks
Original commit message from CVS:
* check/Makefile.am: remove GstData checks
* check/gst-libs/gdp.c: (START_TEST): fix for API changes
* gst/Makefile.am: add miniobject, remove data
* gst/gst.h: add miniobject, remove data
* gst/gstdata.c: remove
* gst/gstdata.h: remove
* gst/gstdata_private.h: remove
* gst/gsttypes.h: remove GstEvent and GstMessage
* gst/gstelement.c: (gst_element_post_message): fix for API changes
* gst/gstmarshal.list: change BOXED -> OBJECT
Implement GstMiniObject.
* gst/gstminiobject.c:
* gst/gstminiobject.h:
Modify to be subclasses of GstMiniObject.
* gst/gstbuffer.c: (_gst_buffer_initialize), (gst_buffer_get_type),
(gst_buffer_class_init), (gst_buffer_finalize), (_gst_buffer_copy),
(gst_buffer_init), (gst_buffer_new), (gst_buffer_new_and_alloc),
(gst_subbuffer_get_type), (gst_subbuffer_init),
(gst_buffer_create_sub), (gst_buffer_is_span_fast),
(gst_buffer_span):
* gst/gstbuffer.h:
* gst/gstevent.c: (_gst_event_initialize), (gst_event_get_type),
(gst_event_class_init), (gst_event_init), (gst_event_finalize),
(_gst_event_copy), (gst_event_new):
* gst/gstevent.h:
* gst/gstmessage.c: (_gst_message_initialize),
(gst_message_get_type), (gst_message_class_init),
(gst_message_init), (gst_message_finalize), (_gst_message_copy),
(gst_message_new), (gst_message_new_error),
(gst_message_new_warning), (gst_message_new_tag),
(gst_message_new_state_changed), (gst_message_new_application):
* gst/gstmessage.h:
* gst/gstprobe.c: (gst_probe_perform),
(gst_probe_dispatcher_dispatch):
* gst/gstprobe.h:
* gst/gstquery.c: (_gst_query_initialize), (gst_query_get_type),
(gst_query_class_init), (gst_query_finalize), (gst_query_init),
(_gst_query_copy), (gst_query_new):
Update elements for GstData -> GstMiniObject changes
* gst/gstquery.h:
* gst/gstqueue.c: (gst_queue_finalize), (gst_queue_locked_flush),
(gst_queue_chain), (gst_queue_loop):
* gst/elements/gstbufferstore.c:
(gst_buffer_store_add_buffer_func),
(gst_buffer_store_cleared_func), (gst_buffer_store_get_buffer):
* gst/elements/gstfakesink.c: (gst_fakesink_class_init),
(gst_fakesink_render):
* gst/elements/gstfakesrc.c: (gst_fakesrc_class_init):
* gst/elements/gstfilesrc.c: (gst_mmap_buffer_get_type),
(gst_mmap_buffer_class_init), (gst_mmap_buffer_init),
(gst_mmap_buffer_finalize), (gst_filesrc_map_region),
(gst_filesrc_create_read):
* gst/elements/gstidentity.c: (gst_identity_class_init):
* gst/elements/gsttypefindelement.c:
(gst_type_find_element_src_event), (free_entry_buffers),
(gst_type_find_element_handle_event):
* libs/gst/dataprotocol/dataprotocol.c:
(gst_dp_header_from_buffer):
* libs/gst/dataprotocol/dataprotocol.h:
* libs/gst/dataprotocol/dp-private.h:
2005-05-16 20:21:55 +00:00
|
|
|
static void
|
2009-12-02 20:21:48 +00:00
|
|
|
_gst_buffer_free (GstBuffer * buffer)
|
2004-04-05 18:39:01 +00:00
|
|
|
{
|
2011-02-25 12:15:25 +00:00
|
|
|
GstMetaItem *walk, *next;
|
2011-03-29 11:51:25 +00:00
|
|
|
guint i, len;
|
|
|
|
gsize msize;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2009-12-02 20:21:48 +00:00
|
|
|
g_return_if_fail (buffer != NULL);
|
|
|
|
|
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER, "finalize %p", buffer);
|
2004-04-05 18:39:01 +00:00
|
|
|
|
2009-12-17 11:34:42 +00:00
|
|
|
/* free metadata */
|
2011-03-29 09:31:30 +00:00
|
|
|
for (walk = GST_BUFFER_META (buffer); walk; walk = next) {
|
2011-02-25 12:15:25 +00:00
|
|
|
GstMeta *meta = &walk->meta;
|
|
|
|
const GstMetaInfo *info = meta->info;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
|
|
|
/* call free_func if any */
|
|
|
|
if (info->free_func)
|
|
|
|
info->free_func (meta, buffer);
|
2011-03-21 17:13:55 +00:00
|
|
|
|
2010-11-15 10:49:24 +00:00
|
|
|
next = walk->next;
|
2011-03-21 17:13:55 +00:00
|
|
|
/* and free the slice */
|
|
|
|
g_slice_free1 (ITEM_SIZE (info), walk);
|
2009-12-17 11:34:42 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
/* get the size, when unreffing the memory, we could also unref the buffer
|
|
|
|
* itself */
|
2012-06-14 15:11:11 +00:00
|
|
|
msize = GST_BUFFER_SLICE_SIZE (buffer);
|
2011-03-29 11:51:25 +00:00
|
|
|
|
|
|
|
/* free our memory */
|
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2012-07-03 10:18:02 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
gst_memory_unlock (GST_BUFFER_MEM_PTR (buffer, i), GST_LOCK_FLAG_EXCLUSIVE);
|
2011-03-29 11:51:25 +00:00
|
|
|
gst_memory_unref (GST_BUFFER_MEM_PTR (buffer, i));
|
2012-07-03 10:18:02 +00:00
|
|
|
}
|
2011-03-21 08:51:53 +00:00
|
|
|
|
2011-06-10 11:40:57 +00:00
|
|
|
/* we set msize to 0 when the buffer is part of the memory block */
|
2012-08-04 12:37:32 +00:00
|
|
|
if (msize) {
|
|
|
|
#ifdef USE_POISONING
|
|
|
|
memset (buffer, 0xff, msize);
|
|
|
|
#endif
|
2011-03-29 11:51:25 +00:00
|
|
|
g_slice_free1 (msize, buffer);
|
2012-08-04 12:37:32 +00:00
|
|
|
} else {
|
2011-06-10 14:47:29 +00:00
|
|
|
gst_memory_unref (GST_BUFFER_BUFMEM (buffer));
|
2012-08-04 12:37:32 +00:00
|
|
|
}
|
2011-02-23 15:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-29 09:31:30 +00:00
|
|
|
gst_buffer_init (GstBufferImpl * buffer, gsize size)
|
2011-02-23 15:48:00 +00:00
|
|
|
{
|
2012-07-04 14:38:15 +00:00
|
|
|
gst_mini_object_init (GST_MINI_OBJECT_CAST (buffer), 0, _gst_buffer_type,
|
2012-06-23 18:56:12 +00:00
|
|
|
(GstMiniObjectCopyFunction) _gst_buffer_copy,
|
|
|
|
(GstMiniObjectDisposeFunction) _gst_buffer_dispose,
|
|
|
|
(GstMiniObjectFreeFunction) _gst_buffer_free);
|
2011-02-23 15:48:00 +00:00
|
|
|
|
2012-06-14 15:11:11 +00:00
|
|
|
GST_BUFFER_SLICE_SIZE (buffer) = size;
|
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
GST_BUFFER (buffer)->pool = NULL;
|
2011-10-28 10:15:44 +00:00
|
|
|
GST_BUFFER_PTS (buffer) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_DTS (buffer) = GST_CLOCK_TIME_NONE;
|
2011-02-23 15:48:00 +00:00
|
|
|
GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
|
|
|
|
GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
|
2011-03-21 08:51:53 +00:00
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
GST_BUFFER_MEM_LEN (buffer) = 0;
|
|
|
|
GST_BUFFER_META (buffer) = NULL;
|
2004-04-05 18:39:01 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 10:55:35 +00:00
|
|
|
/**
|
2002-07-08 19:22:02 +00:00
|
|
|
* gst_buffer_new:
|
2000-08-14 10:55:35 +00:00
|
|
|
*
|
2002-07-08 19:22:02 +00:00
|
|
|
* Creates a newly allocated buffer without any data.
|
2000-08-14 10:55:35 +00:00
|
|
|
*
|
2005-03-07 18:27:42 +00:00
|
|
|
* MT safe.
|
2010-12-07 18:35:04 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new #GstBuffer.
|
2000-08-14 10:55:35 +00:00
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstBuffer *
|
2002-07-08 19:22:02 +00:00
|
|
|
gst_buffer_new (void)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2011-03-29 09:31:30 +00:00
|
|
|
GstBufferImpl *newbuf;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
newbuf = g_slice_new (GstBufferImpl);
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER, "new %p", newbuf);
|
2000-08-14 10:55:35 +00:00
|
|
|
|
2011-03-29 09:31:30 +00:00
|
|
|
gst_buffer_init (newbuf, sizeof (GstBufferImpl));
|
2009-12-02 20:21:48 +00:00
|
|
|
|
2011-03-29 09:31:30 +00:00
|
|
|
return GST_BUFFER_CAST (newbuf);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-03-27 19:53:43 +00:00
|
|
|
/**
|
2011-06-10 11:40:57 +00:00
|
|
|
* gst_buffer_new_allocate:
|
2014-05-29 21:54:34 +00:00
|
|
|
* @allocator: (transfer none) (allow-none): the #GstAllocator to use, or %NULL to use the
|
2011-11-11 01:47:30 +00:00
|
|
|
* default allocator
|
2011-01-22 14:33:58 +00:00
|
|
|
* @size: the size in bytes of the new buffer's data.
|
2012-03-15 12:28:28 +00:00
|
|
|
* @params: (transfer none) (allow-none): optional parameters
|
2011-06-10 11:40:57 +00:00
|
|
|
*
|
|
|
|
* Tries to create a newly allocated buffer with data of the given size and
|
2012-03-15 12:28:28 +00:00
|
|
|
* extra parameters from @allocator. If the requested amount of memory can't be
|
2014-05-29 21:54:34 +00:00
|
|
|
* allocated, %NULL will be returned. The allocated buffer memory is not cleared.
|
2011-06-10 11:40:57 +00:00
|
|
|
*
|
2014-05-29 21:54:34 +00:00
|
|
|
* When @allocator is %NULL, the default memory allocator will be used.
|
2002-07-08 19:22:02 +00:00
|
|
|
*
|
2011-03-24 10:49:46 +00:00
|
|
|
* Note that when @size == 0, the buffer will not have memory associated with it.
|
2007-04-26 10:00:49 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*
|
2014-06-11 22:21:34 +00:00
|
|
|
* Returns: (transfer full) (nullable): a new #GstBuffer, or %NULL if
|
|
|
|
* the memory couldn't be allocated.
|
2007-04-26 10:00:49 +00:00
|
|
|
*/
|
|
|
|
GstBuffer *
|
2012-03-15 12:28:28 +00:00
|
|
|
gst_buffer_new_allocate (GstAllocator * allocator, gsize size,
|
|
|
|
GstAllocationParams * params)
|
2007-04-26 10:00:49 +00:00
|
|
|
{
|
|
|
|
GstBuffer *newbuf;
|
2011-03-21 08:51:53 +00:00
|
|
|
GstMemory *mem;
|
2011-03-29 11:51:25 +00:00
|
|
|
#if 0
|
|
|
|
guint8 *data;
|
|
|
|
gsize asize;
|
|
|
|
#endif
|
2010-03-04 08:44:52 +00:00
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
#if 1
|
2011-03-23 19:52:27 +00:00
|
|
|
if (size > 0) {
|
2012-03-15 12:28:28 +00:00
|
|
|
mem = gst_allocator_alloc (allocator, size, params);
|
2011-03-23 19:52:27 +00:00
|
|
|
if (G_UNLIKELY (mem == NULL))
|
|
|
|
goto no_memory;
|
|
|
|
} else {
|
|
|
|
mem = NULL;
|
2007-04-26 10:00:49 +00:00
|
|
|
}
|
2011-03-21 12:07:42 +00:00
|
|
|
|
|
|
|
newbuf = gst_buffer_new ();
|
2011-03-23 19:52:27 +00:00
|
|
|
|
2015-06-01 14:23:37 +00:00
|
|
|
if (mem != NULL) {
|
|
|
|
gst_memory_lock (mem, GST_LOCK_FLAG_EXCLUSIVE);
|
|
|
|
_memory_add (newbuf, -1, mem);
|
|
|
|
}
|
2007-04-26 10:00:49 +00:00
|
|
|
|
2011-08-10 09:01:58 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER,
|
|
|
|
"new buffer %p of size %" G_GSIZE_FORMAT " from allocator %p", newbuf,
|
2011-06-13 10:04:28 +00:00
|
|
|
size, allocator);
|
2011-03-29 11:51:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
asize = sizeof (GstBufferImpl) + size;
|
|
|
|
data = g_slice_alloc (asize);
|
|
|
|
if (G_UNLIKELY (data == NULL))
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
newbuf = GST_BUFFER_CAST (data);
|
|
|
|
|
|
|
|
gst_buffer_init ((GstBufferImpl *) data, asize);
|
|
|
|
if (size > 0) {
|
|
|
|
mem = gst_memory_new_wrapped (0, data + sizeof (GstBufferImpl), NULL,
|
|
|
|
size, 0, size);
|
2012-07-03 10:18:02 +00:00
|
|
|
_memory_add (newbuf, -1, mem, TRUE);
|
2011-03-29 11:51:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
2011-06-10 14:47:29 +00:00
|
|
|
/* allocate memory and buffer, it might be interesting to do this but there
|
|
|
|
* are many complications. We need to keep the memory mapped to access the
|
|
|
|
* buffer fields and the memory for the buffer might be just very slow. We
|
|
|
|
* also need to do some more magic to get the alignment right. */
|
2011-03-29 11:51:25 +00:00
|
|
|
asize = sizeof (GstBufferImpl) + size;
|
2011-06-22 09:42:46 +00:00
|
|
|
mem = gst_allocator_alloc (allocator, asize, align);
|
2011-03-29 11:51:25 +00:00
|
|
|
if (G_UNLIKELY (mem == NULL))
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
/* map the data part and init the buffer in it, set the buffer size to 0 so
|
|
|
|
* that a finalize won't free the buffer */
|
|
|
|
data = gst_memory_map (mem, &asize, NULL, GST_MAP_WRITE);
|
|
|
|
gst_buffer_init ((GstBufferImpl *) data, 0);
|
2012-01-19 08:12:05 +00:00
|
|
|
gst_memory_unmap (mem);
|
2011-03-29 11:51:25 +00:00
|
|
|
|
|
|
|
/* strip off the buffer */
|
2011-03-30 14:47:55 +00:00
|
|
|
gst_memory_resize (mem, sizeof (GstBufferImpl), size);
|
2011-03-29 11:51:25 +00:00
|
|
|
|
|
|
|
newbuf = GST_BUFFER_CAST (data);
|
2011-06-10 14:47:29 +00:00
|
|
|
GST_BUFFER_BUFMEM (newbuf) = mem;
|
2011-03-29 11:51:25 +00:00
|
|
|
|
|
|
|
if (size > 0)
|
2012-07-03 10:18:02 +00:00
|
|
|
_memory_add (newbuf, -1, gst_memory_ref (mem), TRUE);
|
2011-03-29 11:51:25 +00:00
|
|
|
#endif
|
2014-03-07 20:43:44 +00:00
|
|
|
GST_BUFFER_FLAG_UNSET (newbuf, GST_BUFFER_FLAG_TAG_MEMORY);
|
2011-03-29 11:51:25 +00:00
|
|
|
|
|
|
|
return newbuf;
|
2011-03-23 19:52:27 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_memory:
|
|
|
|
{
|
2011-08-10 09:01:58 +00:00
|
|
|
GST_CAT_WARNING (GST_CAT_BUFFER,
|
|
|
|
"failed to allocate %" G_GSIZE_FORMAT " bytes", size);
|
2011-03-23 19:52:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2011-07-11 12:40:07 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_new_wrapped_full:
|
2012-03-20 09:20:29 +00:00
|
|
|
* @flags: #GstMemoryFlags
|
2013-03-26 23:22:18 +00:00
|
|
|
* @data: (array length=size) (element-type guint8) (transfer none): data to wrap
|
2012-03-20 09:20:29 +00:00
|
|
|
* @maxsize: allocated size of @data
|
|
|
|
* @offset: offset in @data
|
|
|
|
* @size: size of valid data
|
2013-03-26 23:22:18 +00:00
|
|
|
* @user_data: (allow-none): user_data
|
|
|
|
* @notify: (allow-none) (scope async) (closure user_data): called with @user_data when the memory is freed
|
2011-07-11 12:40:07 +00:00
|
|
|
*
|
2012-03-20 09:20:29 +00:00
|
|
|
* Allocate a new buffer that wraps the given memory. @data must point to
|
|
|
|
* @maxsize of memory, the wrapped buffer will have the region from @offset and
|
|
|
|
* @size visible.
|
2011-07-11 12:40:07 +00:00
|
|
|
*
|
2012-03-20 09:20:29 +00:00
|
|
|
* When the buffer is destroyed, @notify will be called with @user_data.
|
|
|
|
*
|
|
|
|
* The prefix/padding must be filled with 0 if @flags contains
|
|
|
|
* #GST_MEMORY_FLAG_ZERO_PREFIXED and #GST_MEMORY_FLAG_ZERO_PADDED respectively.
|
2011-07-11 12:40:07 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new #GstBuffer
|
|
|
|
*/
|
|
|
|
GstBuffer *
|
2012-03-20 09:20:29 +00:00
|
|
|
gst_buffer_new_wrapped_full (GstMemoryFlags flags, gpointer data,
|
|
|
|
gsize maxsize, gsize offset, gsize size, gpointer user_data,
|
|
|
|
GDestroyNotify notify)
|
2011-07-11 12:40:07 +00:00
|
|
|
{
|
2013-05-29 15:20:34 +00:00
|
|
|
GstMemory *mem;
|
2011-07-11 12:40:07 +00:00
|
|
|
GstBuffer *newbuf;
|
|
|
|
|
|
|
|
newbuf = gst_buffer_new ();
|
2013-05-29 15:20:34 +00:00
|
|
|
mem =
|
|
|
|
gst_memory_new_wrapped (flags, data, maxsize, offset, size, user_data,
|
|
|
|
notify);
|
2015-06-01 14:23:37 +00:00
|
|
|
gst_memory_lock (mem, GST_LOCK_FLAG_EXCLUSIVE);
|
|
|
|
_memory_add (newbuf, -1, mem);
|
2014-03-07 20:43:44 +00:00
|
|
|
GST_BUFFER_FLAG_UNSET (newbuf, GST_BUFFER_FLAG_TAG_MEMORY);
|
2011-07-11 12:40:07 +00:00
|
|
|
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_new_wrapped:
|
2013-03-26 23:22:18 +00:00
|
|
|
* @data: (array length=size) (element-type guint8) (transfer full): data to wrap
|
2011-07-11 12:40:07 +00:00
|
|
|
* @size: allocated size of @data
|
|
|
|
*
|
2011-10-04 16:55:09 +00:00
|
|
|
* Creates a new buffer that wraps the given @data. The memory will be freed
|
|
|
|
* with g_free and will be marked writable.
|
2011-07-11 12:40:07 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new #GstBuffer
|
|
|
|
*/
|
|
|
|
GstBuffer *
|
|
|
|
gst_buffer_new_wrapped (gpointer data, gsize size)
|
|
|
|
{
|
2012-03-20 09:20:29 +00:00
|
|
|
return gst_buffer_new_wrapped_full (0, data, size, 0, size, data, g_free);
|
2011-07-11 12:40:07 +00:00
|
|
|
}
|
|
|
|
|
2011-03-24 10:49:46 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_n_memory:
|
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
*
|
2013-04-11 13:31:01 +00:00
|
|
|
* Get the amount of memory blocks that this buffer has. This amount is never
|
|
|
|
* larger than what gst_buffer_get_max_memory() returns.
|
2011-03-24 10:49:46 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): the amount of memory block in this buffer.
|
|
|
|
*/
|
2011-03-21 08:51:53 +00:00
|
|
|
guint
|
|
|
|
gst_buffer_n_memory (GstBuffer * buffer)
|
|
|
|
{
|
2011-03-23 19:52:27 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
|
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
return GST_BUFFER_MEM_LEN (buffer);
|
2011-03-21 08:51:53 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_prepend_memory:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @mem: (transfer full): a #GstMemory.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Prepend the memory block @mem to @buffer. This function takes
|
|
|
|
* ownership of @mem and thus doesn't increase its refcount.
|
2013-04-11 13:31:01 +00:00
|
|
|
*
|
|
|
|
* This function is identical to gst_buffer_insert_memory() with an index of 0.
|
|
|
|
* See gst_buffer_insert_memory() for more details.
|
2012-06-15 10:55:20 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
void
|
|
|
|
gst_buffer_prepend_memory (GstBuffer * buffer, GstMemory * mem)
|
|
|
|
{
|
|
|
|
gst_buffer_insert_memory (buffer, 0, mem);
|
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_append_memory:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @mem: (transfer full): a #GstMemory.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Append the memory block @mem to @buffer. This function takes
|
|
|
|
* ownership of @mem and thus doesn't increase its refcount.
|
2013-04-11 13:31:01 +00:00
|
|
|
*
|
|
|
|
* This function is identical to gst_buffer_insert_memory() with an index of -1.
|
|
|
|
* See gst_buffer_insert_memory() for more details.
|
2012-06-15 10:55:20 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
void
|
|
|
|
gst_buffer_append_memory (GstBuffer * buffer, GstMemory * mem)
|
|
|
|
{
|
|
|
|
gst_buffer_insert_memory (buffer, -1, mem);
|
|
|
|
}
|
|
|
|
|
2011-03-24 10:49:46 +00:00
|
|
|
/**
|
2012-03-30 16:04:51 +00:00
|
|
|
* gst_buffer_insert_memory:
|
2011-03-24 10:49:46 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
2011-07-06 14:13:30 +00:00
|
|
|
* @idx: the index to add the memory at, or -1 to append it to the end
|
2011-09-26 18:47:35 +00:00
|
|
|
* @mem: (transfer full): a #GstMemory.
|
2011-03-24 10:49:46 +00:00
|
|
|
*
|
2012-03-30 16:04:51 +00:00
|
|
|
* Insert the memory block @mem to @buffer at @idx. This function takes ownership
|
2011-07-06 14:13:30 +00:00
|
|
|
* of @mem and thus doesn't increase its refcount.
|
2013-04-11 13:31:01 +00:00
|
|
|
*
|
|
|
|
* Only gst_buffer_get_max_memory() can be added to a buffer. If more memory is
|
|
|
|
* added, existing memory blocks will automatically be merged to make room for
|
|
|
|
* the new memory.
|
2011-03-24 10:49:46 +00:00
|
|
|
*/
|
2011-03-21 08:51:53 +00:00
|
|
|
void
|
2012-03-30 16:04:51 +00:00
|
|
|
gst_buffer_insert_memory (GstBuffer * buffer, gint idx, GstMemory * mem)
|
2011-03-21 08:51:53 +00:00
|
|
|
{
|
2015-06-01 14:23:37 +00:00
|
|
|
GstMemory *tmp;
|
|
|
|
|
2011-03-23 19:52:27 +00:00
|
|
|
g_return_if_fail (GST_IS_BUFFER (buffer));
|
|
|
|
g_return_if_fail (gst_buffer_is_writable (buffer));
|
|
|
|
g_return_if_fail (mem != NULL);
|
2011-07-06 14:13:30 +00:00
|
|
|
g_return_if_fail (idx == -1 ||
|
|
|
|
(idx >= 0 && idx <= GST_BUFFER_MEM_LEN (buffer)));
|
2011-03-23 19:52:27 +00:00
|
|
|
|
2015-06-01 14:23:37 +00:00
|
|
|
tmp = _memory_get_exclusive_reference (mem);
|
|
|
|
g_return_if_fail (tmp != NULL);
|
|
|
|
gst_memory_unref (mem);
|
|
|
|
_memory_add (buffer, idx, tmp);
|
2011-03-21 08:51:53 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 16:57:57 +00:00
|
|
|
static GstMemory *
|
2012-02-13 15:33:00 +00:00
|
|
|
_get_mapped (GstBuffer * buffer, guint idx, GstMapInfo * info,
|
|
|
|
GstMapFlags flags)
|
2011-04-06 16:57:57 +00:00
|
|
|
{
|
2012-02-13 15:33:00 +00:00
|
|
|
GstMemory *mem, *mapped;
|
2011-04-06 16:57:57 +00:00
|
|
|
|
2012-07-03 10:38:55 +00:00
|
|
|
mem = gst_memory_ref (GST_BUFFER_MEM_PTR (buffer, idx));
|
2011-04-06 16:57:57 +00:00
|
|
|
|
2012-02-13 15:33:00 +00:00
|
|
|
mapped = gst_memory_make_mapped (mem, info, flags);
|
|
|
|
|
2012-07-03 10:18:02 +00:00
|
|
|
if (mapped != mem) {
|
|
|
|
/* memory changed, lock new memory */
|
|
|
|
gst_memory_lock (mapped, GST_LOCK_FLAG_EXCLUSIVE);
|
2012-02-13 15:33:00 +00:00
|
|
|
GST_BUFFER_MEM_PTR (buffer, idx) = mapped;
|
2012-07-03 10:18:02 +00:00
|
|
|
/* unlock old memory */
|
|
|
|
gst_memory_unlock (mem, GST_LOCK_FLAG_EXCLUSIVE);
|
2014-03-07 20:43:44 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
|
2011-04-06 16:57:57 +00:00
|
|
|
}
|
2012-07-03 10:38:55 +00:00
|
|
|
gst_memory_unref (mem);
|
|
|
|
|
|
|
|
return mapped;
|
2011-04-06 16:57:57 +00:00
|
|
|
}
|
|
|
|
|
2012-03-31 15:10:35 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_peek_memory:
|
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @idx: an index
|
|
|
|
*
|
|
|
|
* Get the memory block at @idx in @buffer. The memory block stays valid until
|
|
|
|
* the memory block in @buffer is removed, replaced or merged, typically with
|
|
|
|
* any call that modifies the memory in @buffer.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the #GstMemory at @idx.
|
|
|
|
*/
|
|
|
|
GstMemory *
|
|
|
|
gst_buffer_peek_memory (GstBuffer * buffer, guint idx)
|
|
|
|
{
|
|
|
|
guint len;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
|
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
|
|
|
g_return_val_if_fail (idx < len, NULL);
|
|
|
|
|
|
|
|
return GST_BUFFER_MEM_PTR (buffer, idx);
|
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_get_memory:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @idx: an index
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Get the memory block at index @idx in @buffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): a #GstMemory that contains the data of the
|
|
|
|
* memory block at @idx. Use gst_memory_unref () after usage.
|
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
GstMemory *
|
|
|
|
gst_buffer_get_memory (GstBuffer * buffer, guint idx)
|
|
|
|
{
|
|
|
|
return gst_buffer_get_memory_range (buffer, idx, 1);
|
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_get_all_memory:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
|
|
|
* Get all the memory block in @buffer. The memory blocks will be merged
|
|
|
|
* into one large #GstMemory.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a #GstMemory that contains the merged memory.
|
|
|
|
* Use gst_memory_unref () after usage.
|
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
GstMemory *
|
|
|
|
gst_buffer_get_all_memory (GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
return gst_buffer_get_memory_range (buffer, 0, -1);
|
|
|
|
}
|
|
|
|
|
2011-03-24 10:49:46 +00:00
|
|
|
/**
|
2012-03-30 16:04:51 +00:00
|
|
|
* gst_buffer_get_memory_range:
|
2011-03-24 10:49:46 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @idx: an index
|
2012-03-30 16:04:51 +00:00
|
|
|
* @length: a length
|
|
|
|
*
|
|
|
|
* Get @length memory blocks in @buffer starting at @idx. The memory blocks will
|
|
|
|
* be merged into one large #GstMemory.
|
2011-09-26 18:47:35 +00:00
|
|
|
*
|
2012-03-30 16:04:51 +00:00
|
|
|
* If @length is -1, all memory starting from @idx is merged.
|
2011-03-24 10:49:46 +00:00
|
|
|
*
|
2012-03-30 16:04:51 +00:00
|
|
|
* Returns: (transfer full): a #GstMemory that contains the merged data of @length
|
|
|
|
* blocks starting at @idx. Use gst_memory_unref () after usage.
|
2011-03-24 10:49:46 +00:00
|
|
|
*/
|
2011-03-21 08:51:53 +00:00
|
|
|
GstMemory *
|
2012-03-30 16:04:51 +00:00
|
|
|
gst_buffer_get_memory_range (GstBuffer * buffer, guint idx, gint length)
|
2011-03-21 08:51:53 +00:00
|
|
|
{
|
2012-03-30 16:04:51 +00:00
|
|
|
guint len;
|
|
|
|
|
2012-07-04 15:02:09 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_BUFFER, "idx %u, length %d", idx, length);
|
2011-03-23 19:52:27 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
|
2012-03-30 16:04:51 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2012-04-12 09:53:00 +00:00
|
|
|
g_return_val_if_fail ((len == 0 && idx == 0 && length == -1) ||
|
|
|
|
(length == -1 && idx < len) || (length > 0 && length + idx <= len), NULL);
|
2012-03-30 16:04:51 +00:00
|
|
|
|
|
|
|
if (length == -1)
|
|
|
|
length = len - idx;
|
|
|
|
|
|
|
|
return _get_merged_memory (buffer, idx, length);
|
2012-02-13 15:33:00 +00:00
|
|
|
}
|
2011-03-29 17:17:55 +00:00
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_replace_memory:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @idx: an index
|
|
|
|
* @mem: (transfer full): a #GstMemory
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Replaces the memory block at index @idx in @buffer with @mem.
|
2012-06-15 10:55:20 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
void
|
|
|
|
gst_buffer_replace_memory (GstBuffer * buffer, guint idx, GstMemory * mem)
|
|
|
|
{
|
|
|
|
gst_buffer_replace_memory_range (buffer, idx, 1, mem);
|
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_replace_all_memory:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @mem: (transfer full): a #GstMemory
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Replaces all memory in @buffer with @mem.
|
2012-06-15 10:55:20 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
void
|
|
|
|
gst_buffer_replace_all_memory (GstBuffer * buffer, GstMemory * mem)
|
|
|
|
{
|
|
|
|
gst_buffer_replace_memory_range (buffer, 0, -1, mem);
|
|
|
|
}
|
|
|
|
|
2012-02-13 15:33:00 +00:00
|
|
|
/**
|
2012-03-30 16:04:51 +00:00
|
|
|
* gst_buffer_replace_memory_range:
|
2012-02-13 15:33:00 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @idx: an index
|
2012-03-30 16:04:51 +00:00
|
|
|
* @length: a length should not be 0
|
2012-02-13 15:33:00 +00:00
|
|
|
* @mem: (transfer full): a #GstMemory
|
|
|
|
*
|
2012-03-30 16:04:51 +00:00
|
|
|
* Replaces @length memory blocks in @buffer starting at @idx with @mem.
|
|
|
|
*
|
|
|
|
* If @length is -1, all memory starting from @idx will be removed and
|
|
|
|
* replaced with @mem.
|
2012-02-13 15:33:00 +00:00
|
|
|
*
|
|
|
|
* @buffer should be writable.
|
|
|
|
*/
|
|
|
|
void
|
2012-03-30 16:04:51 +00:00
|
|
|
gst_buffer_replace_memory_range (GstBuffer * buffer, guint idx, gint length,
|
|
|
|
GstMemory * mem)
|
2012-02-13 15:33:00 +00:00
|
|
|
{
|
2012-03-30 16:04:51 +00:00
|
|
|
guint len;
|
|
|
|
|
2012-02-13 15:33:00 +00:00
|
|
|
g_return_if_fail (GST_IS_BUFFER (buffer));
|
|
|
|
g_return_if_fail (gst_buffer_is_writable (buffer));
|
2012-07-04 14:38:15 +00:00
|
|
|
|
2012-07-17 10:50:24 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_BUFFER, "idx %u, length %d, %p", idx, length, mem);
|
|
|
|
|
2012-03-30 16:04:51 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2012-04-12 09:53:00 +00:00
|
|
|
g_return_if_fail ((len == 0 && idx == 0 && length == -1) ||
|
|
|
|
(length == -1 && idx < len) || (length > 0 && length + idx <= len));
|
2011-03-21 08:51:53 +00:00
|
|
|
|
2012-03-30 16:04:51 +00:00
|
|
|
if (length == -1)
|
|
|
|
length = len - idx;
|
2011-03-29 17:17:55 +00:00
|
|
|
|
2012-03-30 16:04:51 +00:00
|
|
|
_replace_memory (buffer, len, idx, length, mem);
|
2011-03-21 08:51:53 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_remove_memory:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @idx: an index
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
|
|
|
* Remove the memory block in @b at index @i.
|
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
void
|
|
|
|
gst_buffer_remove_memory (GstBuffer * buffer, guint idx)
|
|
|
|
{
|
|
|
|
gst_buffer_remove_memory_range (buffer, idx, 1);
|
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_remove_all_memory:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Remove all the memory blocks in @buffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
void
|
|
|
|
gst_buffer_remove_all_memory (GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
gst_buffer_remove_memory_range (buffer, 0, -1);
|
|
|
|
}
|
|
|
|
|
2011-03-24 10:49:46 +00:00
|
|
|
/**
|
2011-03-29 09:07:36 +00:00
|
|
|
* gst_buffer_remove_memory_range:
|
2011-03-24 10:49:46 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @idx: an index
|
2011-03-29 09:07:36 +00:00
|
|
|
* @length: a length
|
2011-03-24 10:49:46 +00:00
|
|
|
*
|
2012-03-30 16:04:51 +00:00
|
|
|
* Remove @length memory blocks in @buffer starting from @idx.
|
2011-03-29 09:07:36 +00:00
|
|
|
*
|
|
|
|
* @length can be -1, in which case all memory starting from @idx is removed.
|
2011-03-24 10:49:46 +00:00
|
|
|
*/
|
2011-03-21 08:51:53 +00:00
|
|
|
void
|
2012-02-13 15:33:00 +00:00
|
|
|
gst_buffer_remove_memory_range (GstBuffer * buffer, guint idx, gint length)
|
2011-03-21 08:51:53 +00:00
|
|
|
{
|
2012-04-01 10:01:34 +00:00
|
|
|
guint len;
|
2011-03-23 19:52:27 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_BUFFER (buffer));
|
|
|
|
g_return_if_fail (gst_buffer_is_writable (buffer));
|
2011-03-29 11:51:25 +00:00
|
|
|
|
2012-07-17 10:50:24 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_BUFFER, "idx %u, length %d", idx, length);
|
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2012-04-12 09:53:00 +00:00
|
|
|
g_return_if_fail ((len == 0 && idx == 0 && length == -1) ||
|
|
|
|
(length == -1 && idx < len) || length + idx <= len);
|
2012-02-13 15:33:00 +00:00
|
|
|
|
|
|
|
if (length == -1)
|
2011-03-29 11:51:25 +00:00
|
|
|
length = len - idx;
|
|
|
|
|
2012-04-01 10:01:34 +00:00
|
|
|
_replace_memory (buffer, len, idx, length, NULL);
|
2011-03-21 08:51:53 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 09:42:52 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_find_memory:
|
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @offset: an offset
|
|
|
|
* @size: a size
|
|
|
|
* @idx: (out): pointer to index
|
|
|
|
* @length: (out): pointer to length
|
|
|
|
* @skip: (out): pointer to skip
|
|
|
|
*
|
|
|
|
* Find the memory blocks that span @size bytes starting from @offset
|
|
|
|
* in @buffer.
|
|
|
|
*
|
|
|
|
* When this function returns %TRUE, @idx will contain the index of the first
|
2014-09-22 13:27:05 +00:00
|
|
|
* memory block where the byte for @offset can be found and @length contains the
|
2012-04-01 09:42:52 +00:00
|
|
|
* number of memory blocks containing the @size remaining bytes. @skip contains
|
2014-09-22 13:27:05 +00:00
|
|
|
* the number of bytes to skip in the memory block at @idx to get to the byte
|
2012-04-01 09:42:52 +00:00
|
|
|
* for @offset.
|
|
|
|
*
|
|
|
|
* @size can be -1 to get all the memory blocks after @idx.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE when @size bytes starting from @offset could be found in
|
|
|
|
* @buffer and @idx, @length and @skip will be filled.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_buffer_find_memory (GstBuffer * buffer, gsize offset, gsize size,
|
|
|
|
guint * idx, guint * length, gsize * skip)
|
|
|
|
{
|
|
|
|
guint i, len, found;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
|
|
|
g_return_val_if_fail (idx != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (length != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (skip != NULL, FALSE);
|
|
|
|
|
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
GstMemory *mem;
|
|
|
|
gsize s;
|
|
|
|
|
|
|
|
mem = GST_BUFFER_MEM_PTR (buffer, i);
|
|
|
|
s = gst_memory_get_sizes (mem, NULL, NULL);
|
|
|
|
|
|
|
|
if (s <= offset) {
|
|
|
|
/* block before offset, or empty block, skip */
|
|
|
|
offset -= s;
|
|
|
|
} else {
|
|
|
|
/* block after offset */
|
|
|
|
if (found == 0) {
|
|
|
|
/* first block, remember index and offset */
|
|
|
|
*idx = i;
|
|
|
|
*skip = offset;
|
|
|
|
if (size == -1) {
|
|
|
|
/* return remaining blocks */
|
|
|
|
*length = len - i;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
s -= offset;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
/* count the amount of found bytes */
|
|
|
|
found += s;
|
|
|
|
if (found >= size) {
|
|
|
|
/* we have enough bytes */
|
|
|
|
*length = i - *idx + 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-27 15:39:50 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_is_memory_range_writable:
|
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @idx: an index
|
|
|
|
* @length: a length should not be 0
|
|
|
|
*
|
|
|
|
* Check if @length memory blocks in @buffer starting from @idx are writable.
|
|
|
|
*
|
|
|
|
* @length can be -1 to check all the memory blocks after @idx.
|
|
|
|
*
|
|
|
|
* Note that this function does not check if @buffer is writable, use
|
|
|
|
* gst_buffer_is_writable() to check that if needed.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the memory range is writable
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_buffer_is_memory_range_writable (GstBuffer * buffer, guint idx, gint length)
|
|
|
|
{
|
|
|
|
guint i, len;
|
|
|
|
|
2014-02-27 17:27:37 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
2014-02-27 15:39:50 +00:00
|
|
|
|
|
|
|
GST_CAT_DEBUG (GST_CAT_BUFFER, "idx %u, length %d", idx, length);
|
|
|
|
|
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2014-02-27 17:27:37 +00:00
|
|
|
g_return_val_if_fail ((len == 0 && idx == 0 && length == -1) ||
|
|
|
|
(length == -1 && idx < len) || (length > 0 && length + idx <= len),
|
|
|
|
FALSE);
|
2014-02-27 15:39:50 +00:00
|
|
|
|
|
|
|
if (length == -1)
|
2014-04-11 11:45:21 +00:00
|
|
|
len -= idx;
|
|
|
|
else
|
|
|
|
len = length;
|
2014-02-27 15:39:50 +00:00
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
2014-04-11 11:45:21 +00:00
|
|
|
if (!gst_memory_is_writable (GST_BUFFER_MEM_PTR (buffer, i + idx)))
|
2014-02-27 15:39:50 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_is_all_memory_writable:
|
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
*
|
|
|
|
* Check if all memory blocks in @buffer are writable.
|
|
|
|
*
|
|
|
|
* Note that this function does not check if @buffer is writable, use
|
|
|
|
* gst_buffer_is_writable() to check that if needed.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if all memory blocks in @buffer are writable
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_buffer_is_all_memory_writable (GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
return gst_buffer_is_memory_range_writable (buffer, 0, -1);
|
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_get_sizes:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
2014-06-11 23:06:19 +00:00
|
|
|
* @offset: (out) (allow-none): a pointer to the offset
|
|
|
|
* @maxsize: (out) (allow-none): a pointer to the maxsize
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
|
|
|
* Get the total size of the memory blocks in @b.
|
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* When not %NULL, @offset will contain the offset of the data in the
|
|
|
|
* first memory block in @buffer and @maxsize will contain the sum of
|
|
|
|
* the size and @offset and the amount of extra padding on the last
|
|
|
|
* memory block. @offset and @maxsize can be used to resize the
|
|
|
|
* buffer memory blocks with gst_buffer_resize().
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Returns: total size of the memory blocks in @buffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
gsize
|
|
|
|
gst_buffer_get_sizes (GstBuffer * buffer, gsize * offset, gsize * maxsize)
|
|
|
|
{
|
|
|
|
return gst_buffer_get_sizes_range (buffer, 0, -1, offset, maxsize);
|
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_get_size:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Get the total size of the memory blocks in @buffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Returns: total size of the memory blocks in @buffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
gsize
|
|
|
|
gst_buffer_get_size (GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
return gst_buffer_get_sizes_range (buffer, 0, -1, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2011-03-24 10:49:46 +00:00
|
|
|
/**
|
2012-04-03 14:44:58 +00:00
|
|
|
* gst_buffer_get_sizes_range:
|
2011-03-24 10:49:46 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
2012-04-03 14:44:58 +00:00
|
|
|
* @idx: an index
|
|
|
|
* @length: a length
|
2014-06-11 23:06:19 +00:00
|
|
|
* @offset: (out) (allow-none): a pointer to the offset
|
|
|
|
* @maxsize: (out) (allow-none): a pointer to the maxsize
|
2011-03-24 10:49:46 +00:00
|
|
|
*
|
2012-04-03 14:44:58 +00:00
|
|
|
* Get the total size of @length memory blocks stating from @idx in @buffer.
|
2011-03-24 10:49:46 +00:00
|
|
|
*
|
2012-04-03 14:44:58 +00:00
|
|
|
* When not %NULL, @offset will contain the offset of the data in the
|
|
|
|
* memory block in @buffer at @idx and @maxsize will contain the sum of the size
|
|
|
|
* and @offset and the amount of extra padding on the memory block at @idx +
|
|
|
|
* @length -1.
|
|
|
|
* @offset and @maxsize can be used to resize the buffer memory blocks with
|
|
|
|
* gst_buffer_resize_range().
|
2011-07-11 14:17:57 +00:00
|
|
|
*
|
2012-06-15 10:55:20 +00:00
|
|
|
* Returns: total size of @length memory blocks starting at @idx in @buffer.
|
2011-03-24 10:49:46 +00:00
|
|
|
*/
|
2011-03-21 08:51:53 +00:00
|
|
|
gsize
|
2012-04-03 14:44:58 +00:00
|
|
|
gst_buffer_get_sizes_range (GstBuffer * buffer, guint idx, gint length,
|
|
|
|
gsize * offset, gsize * maxsize)
|
2011-03-21 08:51:53 +00:00
|
|
|
{
|
2011-07-11 16:00:52 +00:00
|
|
|
guint len;
|
|
|
|
gsize size;
|
|
|
|
GstMemory *mem;
|
2011-03-21 08:51:53 +00:00
|
|
|
|
2011-03-23 19:52:27 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
|
2011-03-29 11:51:25 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2012-04-12 09:53:00 +00:00
|
|
|
g_return_val_if_fail ((len == 0 && idx == 0 && length == -1) ||
|
|
|
|
(length == -1 && idx < len) || (length + idx <= len), 0);
|
2011-03-21 08:51:53 +00:00
|
|
|
|
2012-04-03 14:44:58 +00:00
|
|
|
if (length == -1)
|
|
|
|
length = len - idx;
|
|
|
|
|
|
|
|
if (G_LIKELY (length == 1)) {
|
2011-07-11 16:00:52 +00:00
|
|
|
/* common case */
|
2012-04-03 14:44:58 +00:00
|
|
|
mem = GST_BUFFER_MEM_PTR (buffer, idx);
|
2011-07-11 16:00:52 +00:00
|
|
|
size = gst_memory_get_sizes (mem, offset, maxsize);
|
|
|
|
} else {
|
2012-04-03 14:44:58 +00:00
|
|
|
guint i, end;
|
2011-07-11 16:00:52 +00:00
|
|
|
gsize extra, offs;
|
|
|
|
|
2012-04-03 14:44:58 +00:00
|
|
|
end = idx + length;
|
2011-07-11 16:00:52 +00:00
|
|
|
size = offs = extra = 0;
|
2012-04-03 14:44:58 +00:00
|
|
|
for (i = idx; i < end; i++) {
|
2011-07-11 16:00:52 +00:00
|
|
|
gsize s, o, ms;
|
|
|
|
|
|
|
|
mem = GST_BUFFER_MEM_PTR (buffer, i);
|
|
|
|
s = gst_memory_get_sizes (mem, &o, &ms);
|
|
|
|
|
2011-07-12 11:40:35 +00:00
|
|
|
if (s) {
|
|
|
|
if (size == 0)
|
|
|
|
/* first size, take accumulated data before as the offset */
|
|
|
|
offs = extra + o;
|
|
|
|
/* add sizes */
|
|
|
|
size += s;
|
|
|
|
/* save the amount of data after this block */
|
2011-07-11 16:00:52 +00:00
|
|
|
extra = ms - (o + s);
|
2011-07-12 11:40:35 +00:00
|
|
|
} else {
|
|
|
|
/* empty block, add as extra */
|
|
|
|
extra += ms;
|
|
|
|
}
|
2011-07-11 16:00:52 +00:00
|
|
|
}
|
|
|
|
if (offset)
|
|
|
|
*offset = offs;
|
|
|
|
if (maxsize)
|
|
|
|
*maxsize = offs + size + extra;
|
2011-03-21 08:51:53 +00:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_resize:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
2013-12-07 14:38:19 +00:00
|
|
|
* @offset: the offset adjustment
|
2012-07-31 04:46:18 +00:00
|
|
|
* @size: the new size or -1 to just adjust the offset
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Set the offset and total size of the memory blocks in @buffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
void
|
|
|
|
gst_buffer_resize (GstBuffer * buffer, gssize offset, gssize size)
|
|
|
|
{
|
|
|
|
gst_buffer_resize_range (buffer, 0, -1, offset, size);
|
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_set_size:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @size: the new size
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-07-31 04:46:18 +00:00
|
|
|
* Set the total size of the memory blocks in @buffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
void
|
|
|
|
gst_buffer_set_size (GstBuffer * buffer, gssize size)
|
|
|
|
{
|
|
|
|
gst_buffer_resize_range (buffer, 0, -1, 0, size);
|
|
|
|
}
|
|
|
|
|
2011-03-28 14:40:24 +00:00
|
|
|
/**
|
2012-04-03 14:44:58 +00:00
|
|
|
* gst_buffer_resize_range:
|
2011-03-28 14:40:24 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
2012-04-03 14:44:58 +00:00
|
|
|
* @idx: an index
|
|
|
|
* @length: a length
|
2013-12-07 14:38:19 +00:00
|
|
|
* @offset: the offset adjustment
|
2011-11-11 01:47:30 +00:00
|
|
|
* @size: the new size or -1 to just adjust the offset
|
2011-03-28 14:40:24 +00:00
|
|
|
*
|
2012-04-03 14:44:58 +00:00
|
|
|
* Set the total size of the @length memory blocks starting at @idx in
|
|
|
|
* @buffer
|
2013-02-27 09:09:56 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if resizing succeeded, %FALSE otherwise.
|
2011-03-28 14:40:24 +00:00
|
|
|
*/
|
2013-02-27 09:09:56 +00:00
|
|
|
gboolean
|
2012-04-03 14:44:58 +00:00
|
|
|
gst_buffer_resize_range (GstBuffer * buffer, guint idx, gint length,
|
|
|
|
gssize offset, gssize size)
|
2011-03-28 14:40:24 +00:00
|
|
|
{
|
2012-04-03 14:44:58 +00:00
|
|
|
guint i, len, end;
|
2011-07-11 14:17:57 +00:00
|
|
|
gsize bsize, bufsize, bufoffs, bufmax;
|
2011-03-28 14:40:24 +00:00
|
|
|
|
2013-02-27 09:09:56 +00:00
|
|
|
g_return_val_if_fail (gst_buffer_is_writable (buffer), FALSE);
|
|
|
|
g_return_val_if_fail (size >= -1, FALSE);
|
|
|
|
|
2012-04-03 14:44:58 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2013-02-27 09:09:56 +00:00
|
|
|
g_return_val_if_fail ((len == 0 && idx == 0 && length == -1) ||
|
|
|
|
(length == -1 && idx < len) || (length + idx <= len), FALSE);
|
2012-04-03 14:44:58 +00:00
|
|
|
|
|
|
|
if (length == -1)
|
|
|
|
length = len - idx;
|
2011-03-28 14:40:24 +00:00
|
|
|
|
2012-04-03 14:44:58 +00:00
|
|
|
bufsize = gst_buffer_get_sizes_range (buffer, idx, length, &bufoffs, &bufmax);
|
2011-07-11 14:17:57 +00:00
|
|
|
|
2011-11-11 09:00:35 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER, "trim %p %" G_GSSIZE_FORMAT "-%" G_GSSIZE_FORMAT
|
|
|
|
" size:%" G_GSIZE_FORMAT " offs:%" G_GSIZE_FORMAT " max:%"
|
2011-11-11 01:47:30 +00:00
|
|
|
G_GSIZE_FORMAT, buffer, offset, size, bufsize, bufoffs, bufmax);
|
2011-07-12 10:00:58 +00:00
|
|
|
|
2011-07-11 14:42:56 +00:00
|
|
|
/* we can't go back further than the current offset or past the end of the
|
|
|
|
* buffer */
|
2013-02-27 09:09:56 +00:00
|
|
|
g_return_val_if_fail ((offset < 0 && bufoffs >= -offset) || (offset >= 0
|
|
|
|
&& bufoffs + offset <= bufmax), FALSE);
|
2011-07-11 14:42:56 +00:00
|
|
|
if (size == -1) {
|
2013-02-27 09:09:56 +00:00
|
|
|
g_return_val_if_fail (bufsize >= offset, FALSE);
|
2011-03-29 14:52:21 +00:00
|
|
|
size = bufsize - offset;
|
2011-07-11 14:42:56 +00:00
|
|
|
}
|
2013-02-27 09:09:56 +00:00
|
|
|
g_return_val_if_fail (bufmax >= bufoffs + offset + size, FALSE);
|
2011-03-29 14:52:21 +00:00
|
|
|
|
2012-03-09 15:14:02 +00:00
|
|
|
/* no change */
|
|
|
|
if (offset == 0 && size == bufsize)
|
2013-02-27 09:09:56 +00:00
|
|
|
return TRUE;
|
2012-03-09 15:14:02 +00:00
|
|
|
|
2012-04-03 14:44:58 +00:00
|
|
|
end = idx + length;
|
2011-03-28 14:40:24 +00:00
|
|
|
/* copy and trim */
|
2012-04-03 14:44:58 +00:00
|
|
|
for (i = idx; i < end; i++) {
|
2012-07-03 11:46:40 +00:00
|
|
|
GstMemory *mem;
|
2011-07-12 12:07:57 +00:00
|
|
|
gsize left, noffs;
|
|
|
|
|
|
|
|
mem = GST_BUFFER_MEM_PTR (buffer, i);
|
2011-07-11 14:17:57 +00:00
|
|
|
bsize = gst_memory_get_sizes (mem, NULL, NULL);
|
2011-03-28 14:40:24 +00:00
|
|
|
|
2011-07-12 12:07:57 +00:00
|
|
|
noffs = 0;
|
|
|
|
/* last buffer always gets resized to the remaining size */
|
2012-04-03 14:44:58 +00:00
|
|
|
if (i + 1 == end)
|
2011-07-12 12:07:57 +00:00
|
|
|
left = size;
|
|
|
|
/* shrink buffers before the offset */
|
|
|
|
else if ((gssize) bsize <= offset) {
|
|
|
|
left = 0;
|
|
|
|
noffs = offset - bsize;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
/* clip other buffers */
|
|
|
|
else
|
|
|
|
left = MIN (bsize - offset, size);
|
|
|
|
|
|
|
|
if (offset != 0 || left != bsize) {
|
2012-07-04 14:38:15 +00:00
|
|
|
if (gst_memory_is_writable (mem)) {
|
2011-07-12 12:07:57 +00:00
|
|
|
gst_memory_resize (mem, offset, left);
|
|
|
|
} else {
|
2013-02-24 08:33:03 +00:00
|
|
|
GstMemory *newmem = NULL;
|
2011-04-07 14:02:43 +00:00
|
|
|
|
2013-02-24 08:33:03 +00:00
|
|
|
if (!GST_MEMORY_IS_NO_SHARE (mem))
|
2012-07-03 11:46:40 +00:00
|
|
|
newmem = gst_memory_share (mem, offset, left);
|
2011-04-07 14:02:43 +00:00
|
|
|
|
2013-02-24 08:33:03 +00:00
|
|
|
if (!newmem)
|
|
|
|
newmem = gst_memory_copy (mem, offset, left);
|
|
|
|
|
2013-02-27 09:09:56 +00:00
|
|
|
if (newmem == NULL)
|
|
|
|
return FALSE;
|
2013-02-24 08:33:03 +00:00
|
|
|
|
2012-07-03 11:46:40 +00:00
|
|
|
gst_memory_lock (newmem, GST_LOCK_FLAG_EXCLUSIVE);
|
|
|
|
GST_BUFFER_MEM_PTR (buffer, i) = newmem;
|
|
|
|
gst_memory_unlock (mem, GST_LOCK_FLAG_EXCLUSIVE);
|
2011-07-12 12:07:57 +00:00
|
|
|
gst_memory_unref (mem);
|
2014-02-27 13:35:09 +00:00
|
|
|
|
2014-03-26 19:56:08 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
|
2011-03-28 14:40:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-03 11:46:40 +00:00
|
|
|
|
2011-07-12 12:07:57 +00:00
|
|
|
offset = noffs;
|
|
|
|
size -= left;
|
2011-03-28 14:40:24 +00:00
|
|
|
}
|
2013-02-27 09:09:56 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2011-03-28 14:40:24 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 10:55:20 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_map:
|
2012-07-31 04:46:18 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @info: (out): info about the mapping
|
|
|
|
* @flags: flags for the mapping
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-08-11 21:19:32 +00:00
|
|
|
* This function fills @info with the #GstMapInfo of all merged memory
|
2012-07-31 04:46:18 +00:00
|
|
|
* blocks in @buffer.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
|
|
|
* @flags describe the desired access of the memory. When @flags is
|
|
|
|
* #GST_MAP_WRITE, @buffer should be writable (as returned from
|
|
|
|
* gst_buffer_is_writable()).
|
|
|
|
*
|
|
|
|
* When @buffer is writable but the memory isn't, a writable copy will
|
2012-07-31 04:46:18 +00:00
|
|
|
* automatically be created and returned. The readonly copy of the
|
|
|
|
* buffer memory will then also be replaced with this writable copy.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-08-11 21:19:32 +00:00
|
|
|
* The memory in @info should be unmapped with gst_buffer_unmap() after
|
2012-07-31 04:46:18 +00:00
|
|
|
* usage.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-08-11 21:19:32 +00:00
|
|
|
* Returns: %TRUE if the map succeeded and @info contains valid data.
|
2012-06-15 10:55:20 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
gboolean
|
|
|
|
gst_buffer_map (GstBuffer * buffer, GstMapInfo * info, GstMapFlags flags)
|
|
|
|
{
|
|
|
|
return gst_buffer_map_range (buffer, 0, -1, info, flags);
|
|
|
|
}
|
|
|
|
|
2011-03-24 10:49:46 +00:00
|
|
|
/**
|
2012-03-30 16:04:51 +00:00
|
|
|
* gst_buffer_map_range:
|
2011-03-24 10:49:46 +00:00
|
|
|
* @buffer: a #GstBuffer.
|
2012-03-30 16:04:51 +00:00
|
|
|
* @idx: an index
|
|
|
|
* @length: a length
|
2012-01-20 13:23:57 +00:00
|
|
|
* @info: (out): info about the mapping
|
2011-03-24 10:49:46 +00:00
|
|
|
* @flags: flags for the mapping
|
|
|
|
*
|
2012-03-30 16:04:51 +00:00
|
|
|
* This function fills @info with the #GstMapInfo of @length merged memory blocks
|
|
|
|
* starting at @idx in @buffer. When @length is -1, all memory blocks starting
|
|
|
|
* from @idx are merged and mapped.
|
2012-06-15 10:55:20 +00:00
|
|
|
*
|
2012-01-20 13:23:57 +00:00
|
|
|
* @flags describe the desired access of the memory. When @flags is
|
|
|
|
* #GST_MAP_WRITE, @buffer should be writable (as returned from
|
|
|
|
* gst_buffer_is_writable()).
|
2011-03-24 10:49:46 +00:00
|
|
|
*
|
|
|
|
* When @buffer is writable but the memory isn't, a writable copy will
|
|
|
|
* automatically be created and returned. The readonly copy of the buffer memory
|
|
|
|
* will then also be replaced with this writable copy.
|
|
|
|
*
|
2012-03-09 15:14:02 +00:00
|
|
|
* The memory in @info should be unmapped with gst_buffer_unmap() after usage.
|
|
|
|
*
|
2012-06-15 10:55:20 +00:00
|
|
|
* Returns: %TRUE if the map succeeded and @info contains valid
|
2012-01-20 13:23:57 +00:00
|
|
|
* data.
|
2011-03-24 10:49:46 +00:00
|
|
|
*/
|
2012-01-20 13:23:57 +00:00
|
|
|
gboolean
|
2012-03-30 16:04:51 +00:00
|
|
|
gst_buffer_map_range (GstBuffer * buffer, guint idx, gint length,
|
|
|
|
GstMapInfo * info, GstMapFlags flags)
|
2011-03-21 08:51:53 +00:00
|
|
|
{
|
2012-03-09 15:14:02 +00:00
|
|
|
GstMemory *mem, *nmem;
|
2012-03-30 16:04:51 +00:00
|
|
|
gboolean write, writable;
|
|
|
|
gsize len;
|
2011-03-21 12:07:42 +00:00
|
|
|
|
2012-01-20 13:23:57 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
2012-03-30 16:04:51 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2012-04-12 09:53:00 +00:00
|
|
|
g_return_val_if_fail ((len == 0 && idx == 0 && length == -1) ||
|
|
|
|
(length == -1 && idx < len) || (length > 0
|
2012-03-30 16:04:51 +00:00
|
|
|
&& length + idx <= len), FALSE);
|
2011-03-23 19:52:27 +00:00
|
|
|
|
2012-07-04 15:02:09 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER, "buffer %p, idx %u, length %d, flags %04x",
|
|
|
|
buffer, idx, length, flags);
|
2012-07-03 10:23:36 +00:00
|
|
|
|
2011-03-29 17:17:55 +00:00
|
|
|
write = (flags & GST_MAP_WRITE) != 0;
|
|
|
|
writable = gst_buffer_is_writable (buffer);
|
2011-03-21 12:07:42 +00:00
|
|
|
|
2011-03-29 17:17:55 +00:00
|
|
|
/* check if we can write when asked for write access */
|
|
|
|
if (G_UNLIKELY (write && !writable))
|
2011-03-23 19:52:27 +00:00
|
|
|
goto not_writable;
|
|
|
|
|
2012-03-30 16:04:51 +00:00
|
|
|
if (length == -1)
|
|
|
|
length = len - idx;
|
|
|
|
|
|
|
|
mem = _get_merged_memory (buffer, idx, length);
|
2012-01-20 13:56:49 +00:00
|
|
|
if (G_UNLIKELY (mem == NULL))
|
2012-01-20 13:23:57 +00:00
|
|
|
goto no_memory;
|
2011-03-23 19:52:27 +00:00
|
|
|
|
2012-01-20 13:23:57 +00:00
|
|
|
/* now try to map */
|
2012-03-09 15:14:02 +00:00
|
|
|
nmem = gst_memory_make_mapped (mem, info, flags);
|
|
|
|
if (G_UNLIKELY (nmem == NULL))
|
2012-01-20 13:56:49 +00:00
|
|
|
goto cannot_map;
|
2011-03-29 17:17:55 +00:00
|
|
|
|
2012-03-09 15:14:02 +00:00
|
|
|
/* if we merged or when the map returned a different memory, we try to replace
|
|
|
|
* the memory in the buffer */
|
2012-03-30 16:04:51 +00:00
|
|
|
if (G_UNLIKELY (length > 1 || nmem != mem)) {
|
2012-03-09 15:14:02 +00:00
|
|
|
/* if the buffer is writable, replace the memory */
|
|
|
|
if (writable) {
|
2012-03-30 16:04:51 +00:00
|
|
|
_replace_memory (buffer, len, idx, length, gst_memory_ref (nmem));
|
2012-03-09 15:14:02 +00:00
|
|
|
} else {
|
2012-03-30 16:04:51 +00:00
|
|
|
if (len > 1) {
|
2012-03-09 15:14:02 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_PERFORMANCE,
|
|
|
|
"temporary mapping for memory %p in buffer %p", nmem, buffer);
|
|
|
|
}
|
2012-02-13 15:33:00 +00:00
|
|
|
}
|
2012-02-02 11:07:28 +00:00
|
|
|
}
|
2012-01-20 13:23:57 +00:00
|
|
|
return TRUE;
|
2011-03-23 19:52:27 +00:00
|
|
|
|
|
|
|
/* ERROR */
|
|
|
|
not_writable:
|
|
|
|
{
|
2012-02-06 08:46:47 +00:00
|
|
|
GST_WARNING_OBJECT (buffer, "write map requested on non-writable buffer");
|
2012-01-20 13:23:57 +00:00
|
|
|
g_critical ("write map requested on non-writable buffer");
|
2014-04-16 17:49:56 +00:00
|
|
|
memset (info, 0, sizeof (GstMapInfo));
|
2012-01-20 13:23:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_memory:
|
|
|
|
{
|
|
|
|
/* empty buffer, we need to return NULL */
|
|
|
|
GST_DEBUG_OBJECT (buffer, "can't get buffer memory");
|
2014-04-16 17:49:56 +00:00
|
|
|
memset (info, 0, sizeof (GstMapInfo));
|
2012-01-20 13:23:57 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
cannot_map:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (buffer, "cannot map memory");
|
2014-04-16 17:49:56 +00:00
|
|
|
memset (info, 0, sizeof (GstMapInfo));
|
2012-01-20 13:23:57 +00:00
|
|
|
return FALSE;
|
2011-03-23 19:52:27 +00:00
|
|
|
}
|
2011-03-21 08:51:53 +00:00
|
|
|
}
|
|
|
|
|
2011-03-24 10:49:46 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_unmap:
|
|
|
|
* @buffer: a #GstBuffer.
|
2012-01-20 13:23:57 +00:00
|
|
|
* @info: a #GstMapInfo
|
2011-03-24 10:49:46 +00:00
|
|
|
*
|
2012-01-20 13:23:57 +00:00
|
|
|
* Release the memory previously mapped with gst_buffer_map().
|
2011-03-24 10:49:46 +00:00
|
|
|
*/
|
2012-01-20 13:23:57 +00:00
|
|
|
void
|
|
|
|
gst_buffer_unmap (GstBuffer * buffer, GstMapInfo * info)
|
2011-03-21 08:51:53 +00:00
|
|
|
{
|
2012-01-20 13:23:57 +00:00
|
|
|
g_return_if_fail (GST_IS_BUFFER (buffer));
|
|
|
|
g_return_if_fail (info != NULL);
|
2011-03-21 12:07:42 +00:00
|
|
|
|
2012-03-09 15:14:02 +00:00
|
|
|
/* we need to check for NULL, it is possible that we tried to map a buffer
|
|
|
|
* without memory and we should be able to unmap that fine */
|
|
|
|
if (G_LIKELY (info->memory)) {
|
2012-01-20 13:23:57 +00:00
|
|
|
gst_memory_unmap (info->memory, info);
|
|
|
|
gst_memory_unref (info->memory);
|
2011-03-21 12:07:42 +00:00
|
|
|
}
|
2011-03-21 08:51:53 +00:00
|
|
|
}
|
|
|
|
|
2011-03-28 08:28:02 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_fill:
|
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @offset: the offset to fill
|
2013-03-26 23:22:18 +00:00
|
|
|
* @src: (array length=size) (element-type guint8): the source address
|
2011-03-28 08:28:02 +00:00
|
|
|
* @size: the size to fill
|
|
|
|
*
|
2011-06-09 09:13:55 +00:00
|
|
|
* Copy @size bytes from @src to @buffer at @offset.
|
2011-08-16 16:29:29 +00:00
|
|
|
*
|
|
|
|
* Returns: The amount of bytes copied. This value can be lower than @size
|
|
|
|
* when @buffer did not contain enough data.
|
2011-03-28 08:28:02 +00:00
|
|
|
*/
|
2011-08-16 16:29:29 +00:00
|
|
|
gsize
|
2011-03-28 13:52:17 +00:00
|
|
|
gst_buffer_fill (GstBuffer * buffer, gsize offset, gconstpointer src,
|
|
|
|
gsize size)
|
2011-03-28 08:28:02 +00:00
|
|
|
{
|
2011-08-16 16:29:29 +00:00
|
|
|
gsize i, len, left;
|
2011-03-28 13:52:17 +00:00
|
|
|
const guint8 *ptr = src;
|
2011-03-28 08:28:02 +00:00
|
|
|
|
2011-08-16 16:29:29 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
|
|
|
|
g_return_val_if_fail (gst_buffer_is_writable (buffer), 0);
|
2013-05-08 09:25:36 +00:00
|
|
|
g_return_val_if_fail (src != NULL || size == 0, 0);
|
2011-03-29 09:31:30 +00:00
|
|
|
|
2012-07-04 15:02:09 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER,
|
|
|
|
"buffer %p, offset %" G_GSIZE_FORMAT ", size %" G_GSIZE_FORMAT, buffer,
|
|
|
|
offset, size);
|
2012-07-03 10:23:36 +00:00
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2011-08-16 16:29:29 +00:00
|
|
|
left = size;
|
2011-03-28 08:28:02 +00:00
|
|
|
|
2011-08-16 16:29:29 +00:00
|
|
|
for (i = 0; i < len && left > 0; i++) {
|
2012-01-20 13:23:57 +00:00
|
|
|
GstMapInfo info;
|
|
|
|
gsize tocopy;
|
2011-03-28 08:28:02 +00:00
|
|
|
GstMemory *mem;
|
|
|
|
|
2012-02-13 15:33:00 +00:00
|
|
|
mem = _get_mapped (buffer, i, &info, GST_MAP_WRITE);
|
2012-01-20 13:23:57 +00:00
|
|
|
if (info.size > offset) {
|
2011-03-28 08:28:02 +00:00
|
|
|
/* we have enough */
|
2012-01-20 13:23:57 +00:00
|
|
|
tocopy = MIN (info.size - offset, left);
|
|
|
|
memcpy ((guint8 *) info.data + offset, ptr, tocopy);
|
2011-08-16 16:29:29 +00:00
|
|
|
left -= tocopy;
|
2011-03-28 08:28:02 +00:00
|
|
|
ptr += tocopy;
|
|
|
|
offset = 0;
|
|
|
|
} else {
|
|
|
|
/* offset past buffer, skip */
|
2012-01-20 13:23:57 +00:00
|
|
|
offset -= info.size;
|
2011-03-28 08:28:02 +00:00
|
|
|
}
|
2012-01-20 13:23:57 +00:00
|
|
|
gst_memory_unmap (mem, &info);
|
2011-03-28 08:28:02 +00:00
|
|
|
}
|
2011-08-16 16:29:29 +00:00
|
|
|
return size - left;
|
2011-03-28 08:28:02 +00:00
|
|
|
}
|
|
|
|
|
2011-03-24 10:49:46 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_extract:
|
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @offset: the offset to extract
|
|
|
|
* @dest: the destination address
|
|
|
|
* @size: the size to extract
|
|
|
|
*
|
|
|
|
* Copy @size bytes starting from @offset in @buffer to @dest.
|
2011-08-16 16:29:29 +00:00
|
|
|
*
|
|
|
|
* Returns: The amount of bytes extracted. This value can be lower than @size
|
|
|
|
* when @buffer did not contain enough data.
|
2011-03-24 10:49:46 +00:00
|
|
|
*/
|
2011-08-16 16:29:29 +00:00
|
|
|
gsize
|
2011-03-21 17:13:55 +00:00
|
|
|
gst_buffer_extract (GstBuffer * buffer, gsize offset, gpointer dest, gsize size)
|
|
|
|
{
|
2011-08-16 16:29:29 +00:00
|
|
|
gsize i, len, left;
|
2011-03-21 17:13:55 +00:00
|
|
|
guint8 *ptr = dest;
|
|
|
|
|
2011-08-16 16:29:29 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
|
|
|
|
g_return_val_if_fail (dest != NULL, 0);
|
2011-03-29 09:31:30 +00:00
|
|
|
|
2012-07-04 15:02:09 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER,
|
|
|
|
"buffer %p, offset %" G_GSIZE_FORMAT ", size %" G_GSIZE_FORMAT, buffer,
|
|
|
|
offset, size);
|
2012-07-03 10:23:36 +00:00
|
|
|
|
2011-03-29 11:51:25 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2011-08-16 16:29:29 +00:00
|
|
|
left = size;
|
2011-03-21 17:13:55 +00:00
|
|
|
|
2011-08-16 16:29:29 +00:00
|
|
|
for (i = 0; i < len && left > 0; i++) {
|
2012-01-20 13:23:57 +00:00
|
|
|
GstMapInfo info;
|
|
|
|
gsize tocopy;
|
2011-03-21 17:13:55 +00:00
|
|
|
GstMemory *mem;
|
|
|
|
|
2012-02-13 15:33:00 +00:00
|
|
|
mem = _get_mapped (buffer, i, &info, GST_MAP_READ);
|
2012-01-20 13:23:57 +00:00
|
|
|
if (info.size > offset) {
|
2011-03-24 20:18:52 +00:00
|
|
|
/* we have enough */
|
2012-01-20 13:23:57 +00:00
|
|
|
tocopy = MIN (info.size - offset, left);
|
|
|
|
memcpy (ptr, (guint8 *) info.data + offset, tocopy);
|
2011-08-16 16:29:29 +00:00
|
|
|
left -= tocopy;
|
2011-03-21 17:13:55 +00:00
|
|
|
ptr += tocopy;
|
|
|
|
offset = 0;
|
|
|
|
} else {
|
2011-03-24 20:18:52 +00:00
|
|
|
/* offset past buffer, skip */
|
2012-01-20 13:23:57 +00:00
|
|
|
offset -= info.size;
|
2011-03-21 17:13:55 +00:00
|
|
|
}
|
2012-01-20 13:23:57 +00:00
|
|
|
gst_memory_unmap (mem, &info);
|
2011-03-21 17:13:55 +00:00
|
|
|
}
|
2011-08-16 16:29:29 +00:00
|
|
|
return size - left;
|
2011-03-21 17:13:55 +00:00
|
|
|
}
|
|
|
|
|
2011-04-19 16:57:43 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_memcmp:
|
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @offset: the offset in @buffer
|
2013-03-26 23:22:18 +00:00
|
|
|
* @mem: (array length=size) (element-type guint8): the memory to compare
|
2011-04-19 16:57:43 +00:00
|
|
|
* @size: the size to compare
|
|
|
|
*
|
|
|
|
* Compare @size bytes starting from @offset in @buffer with the memory in @mem.
|
2011-06-13 14:31:53 +00:00
|
|
|
*
|
|
|
|
* Returns: 0 if the memory is equal.
|
2011-04-19 16:57:43 +00:00
|
|
|
*/
|
|
|
|
gint
|
|
|
|
gst_buffer_memcmp (GstBuffer * buffer, gsize offset, gconstpointer mem,
|
|
|
|
gsize size)
|
|
|
|
{
|
|
|
|
gsize i, len;
|
|
|
|
const guint8 *ptr = mem;
|
|
|
|
gint res = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
|
|
|
|
g_return_val_if_fail (mem != NULL, 0);
|
|
|
|
|
2012-07-04 15:02:09 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER,
|
|
|
|
"buffer %p, offset %" G_GSIZE_FORMAT ", size %" G_GSIZE_FORMAT, buffer,
|
|
|
|
offset, size);
|
2012-07-03 10:23:36 +00:00
|
|
|
|
2013-08-19 18:55:22 +00:00
|
|
|
if (G_UNLIKELY (gst_buffer_get_size (buffer) < offset + size))
|
|
|
|
return -1;
|
|
|
|
|
2011-04-19 16:57:43 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
|
|
|
|
|
|
|
for (i = 0; i < len && size > 0 && res == 0; i++) {
|
2012-01-20 13:23:57 +00:00
|
|
|
GstMapInfo info;
|
|
|
|
gsize tocmp;
|
2011-04-19 16:57:43 +00:00
|
|
|
GstMemory *mem;
|
|
|
|
|
2012-02-13 15:33:00 +00:00
|
|
|
mem = _get_mapped (buffer, i, &info, GST_MAP_READ);
|
2012-01-20 13:23:57 +00:00
|
|
|
if (info.size > offset) {
|
2011-04-19 16:57:43 +00:00
|
|
|
/* we have enough */
|
2012-01-20 13:23:57 +00:00
|
|
|
tocmp = MIN (info.size - offset, size);
|
|
|
|
res = memcmp (ptr, (guint8 *) info.data + offset, tocmp);
|
2011-04-19 16:57:43 +00:00
|
|
|
size -= tocmp;
|
|
|
|
ptr += tocmp;
|
|
|
|
offset = 0;
|
|
|
|
} else {
|
|
|
|
/* offset past buffer, skip */
|
2012-01-20 13:23:57 +00:00
|
|
|
offset -= info.size;
|
2011-04-19 16:57:43 +00:00
|
|
|
}
|
2012-01-20 13:23:57 +00:00
|
|
|
gst_memory_unmap (mem, &info);
|
2011-04-19 16:57:43 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-07-06 14:08:56 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_memset:
|
|
|
|
* @buffer: a #GstBuffer.
|
|
|
|
* @offset: the offset in @buffer
|
|
|
|
* @val: the value to set
|
|
|
|
* @size: the size to set
|
|
|
|
*
|
|
|
|
* Fill @buf with @size bytes with @val starting from @offset.
|
2011-08-16 16:29:29 +00:00
|
|
|
*
|
|
|
|
* Returns: The amount of bytes filled. This value can be lower than @size
|
|
|
|
* when @buffer did not contain enough data.
|
2011-07-06 14:08:56 +00:00
|
|
|
*/
|
2011-08-16 16:29:29 +00:00
|
|
|
gsize
|
2011-07-06 14:08:56 +00:00
|
|
|
gst_buffer_memset (GstBuffer * buffer, gsize offset, guint8 val, gsize size)
|
|
|
|
{
|
2011-08-16 16:29:29 +00:00
|
|
|
gsize i, len, left;
|
2011-07-06 14:08:56 +00:00
|
|
|
|
2011-08-16 16:29:29 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
|
|
|
|
g_return_val_if_fail (gst_buffer_is_writable (buffer), 0);
|
2011-07-06 14:08:56 +00:00
|
|
|
|
2012-07-04 15:02:09 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER,
|
|
|
|
"buffer %p, offset %" G_GSIZE_FORMAT ", val %02x, size %" G_GSIZE_FORMAT,
|
|
|
|
buffer, offset, val, size);
|
2012-07-03 10:23:36 +00:00
|
|
|
|
2011-07-06 14:08:56 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buffer);
|
2011-08-16 16:29:29 +00:00
|
|
|
left = size;
|
2011-07-06 14:08:56 +00:00
|
|
|
|
2011-08-16 16:29:29 +00:00
|
|
|
for (i = 0; i < len && left > 0; i++) {
|
2012-01-20 13:23:57 +00:00
|
|
|
GstMapInfo info;
|
|
|
|
gsize toset;
|
2011-07-06 14:08:56 +00:00
|
|
|
GstMemory *mem;
|
|
|
|
|
2012-02-13 15:33:00 +00:00
|
|
|
mem = _get_mapped (buffer, i, &info, GST_MAP_WRITE);
|
2012-01-20 13:23:57 +00:00
|
|
|
if (info.size > offset) {
|
2011-07-06 14:08:56 +00:00
|
|
|
/* we have enough */
|
2012-01-20 13:23:57 +00:00
|
|
|
toset = MIN (info.size - offset, left);
|
|
|
|
memset ((guint8 *) info.data + offset, val, toset);
|
2011-08-16 16:29:29 +00:00
|
|
|
left -= toset;
|
2011-07-06 14:08:56 +00:00
|
|
|
offset = 0;
|
|
|
|
} else {
|
|
|
|
/* offset past buffer, skip */
|
2012-01-20 13:23:57 +00:00
|
|
|
offset -= info.size;
|
2011-07-06 14:08:56 +00:00
|
|
|
}
|
2012-01-20 13:23:57 +00:00
|
|
|
gst_memory_unmap (mem, &info);
|
2011-07-06 14:08:56 +00:00
|
|
|
}
|
2011-08-16 16:29:29 +00:00
|
|
|
return size - left;
|
2011-07-06 14:08:56 +00:00
|
|
|
}
|
|
|
|
|
2000-03-27 19:53:43 +00:00
|
|
|
/**
|
2011-03-30 14:47:55 +00:00
|
|
|
* gst_buffer_copy_region:
|
2005-10-28 17:01:14 +00:00
|
|
|
* @parent: a #GstBuffer.
|
2011-06-19 16:15:19 +00:00
|
|
|
* @flags: the #GstBufferCopyFlags
|
2011-05-05 08:37:19 +00:00
|
|
|
* @offset: the offset into parent #GstBuffer at which the new sub-buffer
|
2005-10-28 17:01:14 +00:00
|
|
|
* begins.
|
2015-01-29 11:10:18 +00:00
|
|
|
* @size: the size of the new #GstBuffer sub-buffer, in bytes. If -1, all
|
|
|
|
* data is copied.
|
2000-03-27 19:53:43 +00:00
|
|
|
*
|
2005-11-09 18:10:53 +00:00
|
|
|
* Creates a sub-buffer from @parent at @offset and @size.
|
2002-07-08 19:22:02 +00:00
|
|
|
* This sub-buffer uses the actual memory space of the parent buffer.
|
2005-10-28 17:01:14 +00:00
|
|
|
* This function will copy the offset and timestamp fields when the
|
2011-05-05 08:37:19 +00:00
|
|
|
* offset is 0. If not, they will be set to #GST_CLOCK_TIME_NONE and
|
2006-08-21 09:30:04 +00:00
|
|
|
* #GST_BUFFER_OFFSET_NONE.
|
|
|
|
* If @offset equals 0 and @size equals the total size of @buffer, the
|
|
|
|
* duration and offset end fields are also copied. If not they will be set
|
|
|
|
* to #GST_CLOCK_TIME_NONE and #GST_BUFFER_OFFSET_NONE.
|
2005-08-14 22:29:07 +00:00
|
|
|
*
|
2005-03-07 18:27:42 +00:00
|
|
|
* MT safe.
|
2010-12-07 18:35:04 +00:00
|
|
|
*
|
2014-05-29 21:54:34 +00:00
|
|
|
* Returns: (transfer full): the new #GstBuffer or %NULL if the arguments were
|
2010-12-07 18:35:04 +00:00
|
|
|
* invalid.
|
2000-03-27 19:53:43 +00:00
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstBuffer *
|
2011-03-30 14:47:55 +00:00
|
|
|
gst_buffer_copy_region (GstBuffer * buffer, GstBufferCopyFlags flags,
|
|
|
|
gsize offset, gsize size)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2011-03-30 14:47:55 +00:00
|
|
|
GstBuffer *copy;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
check/Makefile.am: remove GstData checks
Original commit message from CVS:
* check/Makefile.am: remove GstData checks
* check/gst-libs/gdp.c: (START_TEST): fix for API changes
* gst/Makefile.am: add miniobject, remove data
* gst/gst.h: add miniobject, remove data
* gst/gstdata.c: remove
* gst/gstdata.h: remove
* gst/gstdata_private.h: remove
* gst/gsttypes.h: remove GstEvent and GstMessage
* gst/gstelement.c: (gst_element_post_message): fix for API changes
* gst/gstmarshal.list: change BOXED -> OBJECT
Implement GstMiniObject.
* gst/gstminiobject.c:
* gst/gstminiobject.h:
Modify to be subclasses of GstMiniObject.
* gst/gstbuffer.c: (_gst_buffer_initialize), (gst_buffer_get_type),
(gst_buffer_class_init), (gst_buffer_finalize), (_gst_buffer_copy),
(gst_buffer_init), (gst_buffer_new), (gst_buffer_new_and_alloc),
(gst_subbuffer_get_type), (gst_subbuffer_init),
(gst_buffer_create_sub), (gst_buffer_is_span_fast),
(gst_buffer_span):
* gst/gstbuffer.h:
* gst/gstevent.c: (_gst_event_initialize), (gst_event_get_type),
(gst_event_class_init), (gst_event_init), (gst_event_finalize),
(_gst_event_copy), (gst_event_new):
* gst/gstevent.h:
* gst/gstmessage.c: (_gst_message_initialize),
(gst_message_get_type), (gst_message_class_init),
(gst_message_init), (gst_message_finalize), (_gst_message_copy),
(gst_message_new), (gst_message_new_error),
(gst_message_new_warning), (gst_message_new_tag),
(gst_message_new_state_changed), (gst_message_new_application):
* gst/gstmessage.h:
* gst/gstprobe.c: (gst_probe_perform),
(gst_probe_dispatcher_dispatch):
* gst/gstprobe.h:
* gst/gstquery.c: (_gst_query_initialize), (gst_query_get_type),
(gst_query_class_init), (gst_query_finalize), (gst_query_init),
(_gst_query_copy), (gst_query_new):
Update elements for GstData -> GstMiniObject changes
* gst/gstquery.h:
* gst/gstqueue.c: (gst_queue_finalize), (gst_queue_locked_flush),
(gst_queue_chain), (gst_queue_loop):
* gst/elements/gstbufferstore.c:
(gst_buffer_store_add_buffer_func),
(gst_buffer_store_cleared_func), (gst_buffer_store_get_buffer):
* gst/elements/gstfakesink.c: (gst_fakesink_class_init),
(gst_fakesink_render):
* gst/elements/gstfakesrc.c: (gst_fakesrc_class_init):
* gst/elements/gstfilesrc.c: (gst_mmap_buffer_get_type),
(gst_mmap_buffer_class_init), (gst_mmap_buffer_init),
(gst_mmap_buffer_finalize), (gst_filesrc_map_region),
(gst_filesrc_create_read):
* gst/elements/gstidentity.c: (gst_identity_class_init):
* gst/elements/gsttypefindelement.c:
(gst_type_find_element_src_event), (free_entry_buffers),
(gst_type_find_element_handle_event):
* libs/gst/dataprotocol/dataprotocol.c:
(gst_dp_header_from_buffer):
* libs/gst/dataprotocol/dataprotocol.h:
* libs/gst/dataprotocol/dp-private.h:
2005-05-16 20:21:55 +00:00
|
|
|
g_return_val_if_fail (buffer != NULL, NULL);
|
2002-07-08 19:22:02 +00:00
|
|
|
|
|
|
|
/* create the new buffer */
|
2011-03-30 14:47:55 +00:00
|
|
|
copy = gst_buffer_new ();
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2011-03-30 14:47:55 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_BUFFER, "new region copy %p of %p %" G_GSIZE_FORMAT
|
|
|
|
"-%" G_GSIZE_FORMAT, copy, buffer, offset, size);
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2013-02-27 09:09:56 +00:00
|
|
|
if (!gst_buffer_copy_into (copy, buffer, flags, offset, size))
|
|
|
|
gst_buffer_replace (©, NULL);
|
2011-03-08 16:58:49 +00:00
|
|
|
|
2011-03-30 14:47:55 +00:00
|
|
|
return copy;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2001-10-21 18:00:31 +00:00
|
|
|
/**
|
2012-03-28 10:44:44 +00:00
|
|
|
* gst_buffer_append:
|
|
|
|
* @buf1: (transfer full): the first source #GstBuffer to append.
|
|
|
|
* @buf2: (transfer full): the second source #GstBuffer to append.
|
2001-09-10 19:46:01 +00:00
|
|
|
*
|
2012-03-28 10:44:44 +00:00
|
|
|
* Append all the memory from @buf2 to @buf1. The result buffer will contain a
|
|
|
|
* concatenation of the memory of @buf1 and @buf2.
|
2001-09-10 19:46:01 +00:00
|
|
|
*
|
2012-03-28 10:44:44 +00:00
|
|
|
* Returns: (transfer full): the new #GstBuffer that contains the memory
|
|
|
|
* of the two source buffers.
|
2001-09-04 04:34:32 +00:00
|
|
|
*/
|
2012-07-31 04:46:18 +00:00
|
|
|
GstBuffer *
|
|
|
|
gst_buffer_append (GstBuffer * buf1, GstBuffer * buf2)
|
|
|
|
{
|
|
|
|
return gst_buffer_append_region (buf1, buf2, 0, -1);
|
|
|
|
}
|
|
|
|
|
2012-06-28 09:02:19 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_append_region:
|
|
|
|
* @buf1: (transfer full): the first source #GstBuffer to append.
|
|
|
|
* @buf2: (transfer full): the second source #GstBuffer to append.
|
|
|
|
* @offset: the offset in @buf2
|
|
|
|
* @size: the size or -1 of @buf2
|
|
|
|
*
|
|
|
|
* Append @size bytes at @offset from @buf2 to @buf1. The result buffer will
|
|
|
|
* contain a concatenation of the memory of @buf1 and the requested region of
|
|
|
|
* @buf2.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new #GstBuffer that contains the memory
|
|
|
|
* of the two source buffers.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstBuffer *
|
2012-06-28 09:02:19 +00:00
|
|
|
gst_buffer_append_region (GstBuffer * buf1, GstBuffer * buf2, gssize offset,
|
|
|
|
gssize size)
|
2001-08-11 08:25:05 +00:00
|
|
|
{
|
2012-03-28 10:44:44 +00:00
|
|
|
gsize i, len;
|
2001-08-11 08:25:05 +00:00
|
|
|
|
2011-03-29 09:31:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buf1), NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buf2), NULL);
|
2001-08-11 08:25:05 +00:00
|
|
|
|
2012-03-28 10:44:44 +00:00
|
|
|
buf1 = gst_buffer_make_writable (buf1);
|
|
|
|
buf2 = gst_buffer_make_writable (buf2);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2012-06-28 09:02:19 +00:00
|
|
|
gst_buffer_resize (buf2, offset, size);
|
|
|
|
|
2012-03-28 10:44:44 +00:00
|
|
|
len = GST_BUFFER_MEM_LEN (buf2);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
GstMemory *mem;
|
2011-03-21 12:07:42 +00:00
|
|
|
|
2012-03-28 10:44:44 +00:00
|
|
|
mem = GST_BUFFER_MEM_PTR (buf2, i);
|
|
|
|
GST_BUFFER_MEM_PTR (buf2, i) = NULL;
|
2015-06-01 14:23:37 +00:00
|
|
|
_memory_add (buf1, -1, mem);
|
2001-10-17 10:21:27 +00:00
|
|
|
}
|
2012-03-28 10:44:44 +00:00
|
|
|
|
2012-03-28 14:39:54 +00:00
|
|
|
GST_BUFFER_MEM_LEN (buf2) = 0;
|
2014-03-07 20:43:44 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buf2, GST_BUFFER_FLAG_TAG_MEMORY);
|
2012-03-28 14:39:54 +00:00
|
|
|
gst_buffer_unref (buf2);
|
|
|
|
|
2012-03-28 10:44:44 +00:00
|
|
|
return buf1;
|
2001-08-11 08:25:05 +00:00
|
|
|
}
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2011-02-25 12:15:25 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_get_meta:
|
|
|
|
* @buffer: a #GstBuffer
|
2012-02-29 16:20:23 +00:00
|
|
|
* @api: the #GType of an API
|
2011-02-25 12:15:25 +00:00
|
|
|
*
|
2014-09-22 16:27:31 +00:00
|
|
|
* Get the metadata for @api on buffer. When there is no such metadata, %NULL is
|
|
|
|
* returned. If multiple metadata with the given @api are attached to this
|
|
|
|
* buffer only the first one is returned. To handle multiple metadata with a
|
|
|
|
* given API use gst_buffer_iterate_meta() or gst_buffer_foreach_meta() instead
|
|
|
|
* and check the meta->info.api member for the API type.
|
2011-02-25 12:15:25 +00:00
|
|
|
*
|
2014-06-11 22:21:34 +00:00
|
|
|
* Returns: (transfer none) (nullable): the metadata for @api on
|
|
|
|
* @buffer.
|
2011-02-25 12:15:25 +00:00
|
|
|
*/
|
|
|
|
GstMeta *
|
2012-02-29 16:20:23 +00:00
|
|
|
gst_buffer_get_meta (GstBuffer * buffer, GType api)
|
2011-02-25 12:15:25 +00:00
|
|
|
{
|
|
|
|
GstMetaItem *item;
|
2011-02-27 18:40:45 +00:00
|
|
|
GstMeta *result = NULL;
|
2011-02-25 12:15:25 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (buffer != NULL, NULL);
|
2012-02-29 16:20:23 +00:00
|
|
|
g_return_val_if_fail (api != 0, NULL);
|
2011-02-25 12:15:25 +00:00
|
|
|
|
2011-02-26 17:14:36 +00:00
|
|
|
/* find GstMeta of the requested API */
|
2011-03-29 09:31:30 +00:00
|
|
|
for (item = GST_BUFFER_META (buffer); item; item = item->next) {
|
2011-02-27 18:40:45 +00:00
|
|
|
GstMeta *meta = &item->meta;
|
2012-02-29 16:20:23 +00:00
|
|
|
if (meta->info->api == api) {
|
2011-02-26 17:14:36 +00:00
|
|
|
result = meta;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-02-27 18:40:45 +00:00
|
|
|
return result;
|
|
|
|
}
|
2011-02-25 12:15:25 +00:00
|
|
|
|
2011-02-27 18:40:45 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_add_meta:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @info: a #GstMetaInfo
|
|
|
|
* @params: params for @info
|
|
|
|
*
|
|
|
|
* Add metadata for @info to @buffer using the parameters in @params.
|
|
|
|
*
|
2011-11-10 12:53:33 +00:00
|
|
|
* Returns: (transfer none): the metadata for the api in @info on @buffer.
|
2011-02-27 18:40:45 +00:00
|
|
|
*/
|
|
|
|
GstMeta *
|
|
|
|
gst_buffer_add_meta (GstBuffer * buffer, const GstMetaInfo * info,
|
|
|
|
gpointer params)
|
|
|
|
{
|
|
|
|
GstMetaItem *item;
|
|
|
|
GstMeta *result = NULL;
|
|
|
|
gsize size;
|
|
|
|
|
|
|
|
g_return_val_if_fail (buffer != NULL, NULL);
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2012-03-27 12:59:06 +00:00
|
|
|
g_return_val_if_fail (gst_buffer_is_writable (buffer), NULL);
|
2011-02-27 18:40:45 +00:00
|
|
|
|
|
|
|
/* create a new slice */
|
|
|
|
size = ITEM_SIZE (info);
|
|
|
|
item = g_slice_alloc (size);
|
|
|
|
result = &item->meta;
|
|
|
|
result->info = info;
|
2011-12-22 14:52:08 +00:00
|
|
|
result->flags = GST_META_FLAG_NONE;
|
|
|
|
|
|
|
|
GST_CAT_DEBUG (GST_CAT_BUFFER,
|
|
|
|
"alloc metadata %p (%s) of size %" G_GSIZE_FORMAT, result,
|
|
|
|
g_type_name (info->type), info->size);
|
2011-02-27 18:40:45 +00:00
|
|
|
|
|
|
|
/* call the init_func when needed */
|
|
|
|
if (info->init_func)
|
|
|
|
if (!info->init_func (result, params, buffer))
|
|
|
|
goto init_failed;
|
|
|
|
|
|
|
|
/* and add to the list of metadata */
|
2011-03-29 09:31:30 +00:00
|
|
|
item->next = GST_BUFFER_META (buffer);
|
|
|
|
GST_BUFFER_META (buffer) = item;
|
2011-02-25 12:15:25 +00:00
|
|
|
|
2009-12-17 11:34:42 +00:00
|
|
|
return result;
|
2011-02-27 18:40:45 +00:00
|
|
|
|
|
|
|
init_failed:
|
|
|
|
{
|
|
|
|
g_slice_free1 (size, item);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-17 11:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_remove_meta:
|
|
|
|
* @buffer: a #GstBuffer
|
2011-03-30 17:01:13 +00:00
|
|
|
* @meta: a #GstMeta
|
2009-12-17 11:34:42 +00:00
|
|
|
*
|
2011-03-30 17:01:13 +00:00
|
|
|
* Remove the metadata for @meta on @buffer.
|
2009-12-17 11:34:42 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if the metadata existed and was removed, %FALSE if no such
|
|
|
|
* metadata was on @buffer.
|
|
|
|
*/
|
|
|
|
gboolean
|
2011-02-25 12:15:25 +00:00
|
|
|
gst_buffer_remove_meta (GstBuffer * buffer, GstMeta * meta)
|
2009-12-17 11:34:42 +00:00
|
|
|
{
|
2011-02-25 12:15:25 +00:00
|
|
|
GstMetaItem *walk, *prev;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (buffer != NULL, FALSE);
|
2011-02-25 12:15:25 +00:00
|
|
|
g_return_val_if_fail (meta != NULL, FALSE);
|
2012-03-27 12:59:06 +00:00
|
|
|
g_return_val_if_fail (gst_buffer_is_writable (buffer), FALSE);
|
2012-04-17 13:37:27 +00:00
|
|
|
g_return_val_if_fail (!GST_META_FLAG_IS_SET (meta, GST_META_FLAG_LOCKED),
|
|
|
|
FALSE);
|
2009-12-17 11:34:42 +00:00
|
|
|
|
|
|
|
/* find the metadata and delete */
|
2011-03-29 09:31:30 +00:00
|
|
|
prev = GST_BUFFER_META (buffer);
|
2009-12-17 11:34:42 +00:00
|
|
|
for (walk = prev; walk; walk = walk->next) {
|
2011-02-25 12:15:25 +00:00
|
|
|
GstMeta *m = &walk->meta;
|
|
|
|
if (m == meta) {
|
|
|
|
const GstMetaInfo *info = meta->info;
|
|
|
|
|
2009-12-17 11:34:42 +00:00
|
|
|
/* remove from list */
|
2011-03-29 09:31:30 +00:00
|
|
|
if (GST_BUFFER_META (buffer) == walk)
|
|
|
|
GST_BUFFER_META (buffer) = walk->next;
|
2009-12-17 11:34:42 +00:00
|
|
|
else
|
|
|
|
prev->next = walk->next;
|
|
|
|
/* call free_func if any */
|
|
|
|
if (info->free_func)
|
2011-02-25 12:15:25 +00:00
|
|
|
info->free_func (m, buffer);
|
|
|
|
|
2009-12-17 11:34:42 +00:00
|
|
|
/* and free the slice */
|
2011-02-25 12:15:25 +00:00
|
|
|
g_slice_free1 (ITEM_SIZE (info), walk);
|
2009-12-17 11:34:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = walk;
|
|
|
|
}
|
|
|
|
return walk != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_iterate_meta:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @state: an opaque state pointer
|
|
|
|
*
|
2011-02-25 12:15:25 +00:00
|
|
|
* Retrieve the next #GstMeta after @current. If @state points
|
2009-12-17 11:34:42 +00:00
|
|
|
* to %NULL, the first metadata is returned.
|
|
|
|
*
|
2013-12-07 14:38:19 +00:00
|
|
|
* @state will be updated with an opaque state pointer
|
2009-12-17 11:34:42 +00:00
|
|
|
*
|
2014-06-11 22:21:34 +00:00
|
|
|
* Returns: (transfer none) (nullable): The next #GstMeta or %NULL
|
|
|
|
* when there are no more items.
|
2009-12-17 11:34:42 +00:00
|
|
|
*/
|
2011-02-25 12:15:25 +00:00
|
|
|
GstMeta *
|
2009-12-17 11:34:42 +00:00
|
|
|
gst_buffer_iterate_meta (GstBuffer * buffer, gpointer * state)
|
|
|
|
{
|
2011-02-25 12:15:25 +00:00
|
|
|
GstMetaItem **meta;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (buffer != NULL, NULL);
|
|
|
|
g_return_val_if_fail (state != NULL, NULL);
|
|
|
|
|
2011-02-25 12:15:25 +00:00
|
|
|
meta = (GstMetaItem **) state;
|
2009-12-17 11:34:42 +00:00
|
|
|
if (*meta == NULL)
|
|
|
|
/* state NULL, move to first item */
|
2011-03-29 09:31:30 +00:00
|
|
|
*meta = GST_BUFFER_META (buffer);
|
2009-12-17 11:34:42 +00:00
|
|
|
else
|
|
|
|
/* state !NULL, move to next item in list */
|
|
|
|
*meta = (*meta)->next;
|
|
|
|
|
|
|
|
if (*meta)
|
|
|
|
return &(*meta)->meta;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-22 14:54:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_foreach_meta:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @func: (scope call): a #GstBufferForeachMetaFunc to call
|
|
|
|
* @user_data: (closure): user data passed to @func
|
|
|
|
*
|
|
|
|
* Call @func with @user_data for each meta in @buffer.
|
|
|
|
*
|
|
|
|
* @func can modify the passed meta pointer or its contents. The return value
|
|
|
|
* of @func define if this function returns or if the remaining metadata items
|
|
|
|
* in the buffer should be skipped.
|
2012-07-17 10:57:59 +00:00
|
|
|
*
|
|
|
|
* Returns: %FALSE when @func returned %FALSE for one of the metadata.
|
2011-12-22 14:54:03 +00:00
|
|
|
*/
|
2012-07-17 10:57:59 +00:00
|
|
|
gboolean
|
2011-12-22 14:54:03 +00:00
|
|
|
gst_buffer_foreach_meta (GstBuffer * buffer, GstBufferForeachMetaFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GstMetaItem *walk, *prev, *next;
|
2012-07-17 10:57:59 +00:00
|
|
|
gboolean res = TRUE;
|
2011-12-22 14:54:03 +00:00
|
|
|
|
2012-07-17 10:57:59 +00:00
|
|
|
g_return_val_if_fail (buffer != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (func != NULL, FALSE);
|
2011-12-22 14:54:03 +00:00
|
|
|
|
|
|
|
/* find the metadata and delete */
|
|
|
|
prev = GST_BUFFER_META (buffer);
|
|
|
|
for (walk = prev; walk; walk = next) {
|
|
|
|
GstMeta *m, *new;
|
|
|
|
|
|
|
|
m = new = &walk->meta;
|
|
|
|
next = walk->next;
|
|
|
|
|
|
|
|
res = func (buffer, &new, user_data);
|
|
|
|
|
|
|
|
if (new == NULL) {
|
|
|
|
const GstMetaInfo *info = m->info;
|
|
|
|
|
|
|
|
GST_CAT_DEBUG (GST_CAT_BUFFER, "remove metadata %p (%s)", m,
|
|
|
|
g_type_name (info->type));
|
|
|
|
|
2012-07-17 10:57:59 +00:00
|
|
|
g_return_val_if_fail (gst_buffer_is_writable (buffer), FALSE);
|
|
|
|
g_return_val_if_fail (!GST_META_FLAG_IS_SET (m, GST_META_FLAG_LOCKED),
|
|
|
|
FALSE);
|
2012-03-27 12:59:06 +00:00
|
|
|
|
2011-12-22 14:54:03 +00:00
|
|
|
/* remove from list */
|
|
|
|
if (GST_BUFFER_META (buffer) == walk)
|
|
|
|
GST_BUFFER_META (buffer) = next;
|
|
|
|
else
|
|
|
|
prev->next = next;
|
|
|
|
|
|
|
|
/* call free_func if any */
|
|
|
|
if (info->free_func)
|
|
|
|
info->free_func (m, buffer);
|
|
|
|
|
|
|
|
/* and free the slice */
|
|
|
|
g_slice_free1 (ITEM_SIZE (info), walk);
|
|
|
|
}
|
|
|
|
if (!res)
|
|
|
|
break;
|
|
|
|
}
|
2012-07-17 10:57:59 +00:00
|
|
|
return res;
|
2011-12-22 14:54:03 +00:00
|
|
|
}
|
2013-03-26 23:22:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_extract_dup:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @offset: the offset to extract
|
|
|
|
* @size: the size to extract
|
|
|
|
* @dest: (array length=dest_size) (element-type guint8) (out): A pointer where
|
|
|
|
* the destination array will be written.
|
|
|
|
* @dest_size: (out): A location where the size of @dest can be written
|
|
|
|
*
|
|
|
|
* Extracts a copy of at most @size bytes the data at @offset into a #GBytes.
|
|
|
|
* @dest must be freed using g_free() when done.
|
|
|
|
*
|
2013-08-18 09:48:40 +00:00
|
|
|
* Since: 1.0.10
|
2013-03-26 23:22:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_buffer_extract_dup (GstBuffer * buffer, gsize offset, gsize size,
|
|
|
|
gpointer * dest, gsize * dest_size)
|
|
|
|
{
|
|
|
|
gsize real_size;
|
|
|
|
|
|
|
|
real_size = gst_buffer_get_size (buffer);
|
|
|
|
|
|
|
|
*dest = g_malloc (MIN (real_size - offset, size));
|
|
|
|
|
|
|
|
*dest_size = gst_buffer_extract (buffer, offset, *dest, size);
|
|
|
|
}
|