Add metadata copy functions. Fixes #393099.

Original commit message from CVS:
* docs/gst/gstreamer-sections.txt:
* gst/gstbuffer.c: (gst_buffer_copy_metadata), (_gst_buffer_copy):
* gst/gstbuffer.h:
Add metadata copy functions. Fixes #393099.
* gst/gstutils.c: (gst_buffer_stamp):
* libs/gst/base/gstbasetransform.c:
(gst_base_transform_prepare_output_buffer):
Use new metadata copy functions.
This commit is contained in:
Wim Taymans 2007-03-09 16:30:38 +00:00
parent 3a151c24d1
commit db43de1985
6 changed files with 111 additions and 32 deletions

View file

@ -1,3 +1,15 @@
2007-03-09 Wim Taymans <wim@fluendo.com>
* docs/gst/gstreamer-sections.txt:
* gst/gstbuffer.c: (gst_buffer_copy_metadata), (_gst_buffer_copy):
* gst/gstbuffer.h:
Add metadata copy functions. Fixes #393099.
* gst/gstutils.c: (gst_buffer_stamp):
* libs/gst/base/gstbasetransform.c:
(gst_base_transform_prepare_output_buffer):
Use new metadata copy functions.
2007-03-09 Thomas Vander Stichele <thomas at apestaart dot org>
* plugins/elements/gstidentity.c: (gst_identity_class_init),

View file

@ -128,12 +128,12 @@ gst_bus_sync_reply_get_type
GstBusPrivate
</SECTION>
<SECTION>
<FILE>gstbuffer</FILE>
<TITLE>GstBuffer</TITLE>
GstBuffer
GstBufferFlag
GstBufferCopyFlags
GST_BUFFER_FLAGS
GST_BUFFER_FLAG_IS_SET
GST_BUFFER_FLAG_SET
@ -163,6 +163,9 @@ gst_buffer_unref
gst_buffer_set_data
gst_buffer_copy
GST_BUFFER_COPY_ALL
gst_buffer_copy_metadata
gst_buffer_is_writable
gst_buffer_make_writable
gst_buffer_is_metadata_writable
@ -189,10 +192,12 @@ GST_IS_BUFFER
GST_IS_BUFFER_CLASS
GST_TYPE_BUFFER
GST_TYPE_BUFFER_FLAG
GST_TYPE_BUFFER_COPY_FLAGS
GST_BUFFER_CAST
<SUBSECTION Private>
gst_buffer_get_type
gst_buffer_flag_get_type
gst_buffer_copy_flags_get_type
</SECTION>

View file

@ -192,42 +192,75 @@ gst_buffer_finalize (GstBuffer * buffer)
gst_caps_replace (&GST_BUFFER_CAPS (buffer), NULL);
}
/**
* gst_buffer_copy_metadata:
* @dest: a destination #GstBuffer
* @src: a source #GstBuffer
* @flags: flags indicating what metadata fields should be copied.
*
* Copies the metadata from @src into @dest. The data, size and mallocdata
* fields are not copied.
*
* @flags indicate which fields will be copied. Use #GST_BUFFER_COPY_ALL to copy
* all the metadata fields.
*
* This function is typically called from a custom buffer copy function after
* creating @dest and setting the data, size, mallocdata.
*
* Since: 0.10.13
*/
void
gst_buffer_copy_metadata (GstBuffer * dest, const GstBuffer * src,
GstBufferCopyFlags flags)
{
g_return_if_fail (dest != NULL);
g_return_if_fail (src != NULL);
GST_CAT_LOG (GST_CAT_BUFFER, "copy %p to %p", src, dest);
if (flags & GST_BUFFER_COPY_FLAGS) {
guint mask;
/* copy relevant flags */
mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS |
GST_BUFFER_FLAG_DELTA_UNIT | GST_BUFFER_FLAG_DISCONT |
GST_BUFFER_FLAG_GAP;
GST_MINI_OBJECT_FLAGS (dest) |= GST_MINI_OBJECT_FLAGS (src) & mask;
}
if (flags & GST_BUFFER_COPY_TIMESTAMPS) {
GST_BUFFER_TIMESTAMP (dest) = GST_BUFFER_TIMESTAMP (src);
GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
}
if (flags & GST_BUFFER_COPY_CAPS) {
if (GST_BUFFER_CAPS (src))
GST_BUFFER_CAPS (dest) = gst_caps_ref (GST_BUFFER_CAPS (src));
else
GST_BUFFER_CAPS (dest) = NULL;
}
}
static GstBuffer *
_gst_buffer_copy (GstBuffer * buffer)
{
GstBuffer *copy;
guint mask;
g_return_val_if_fail (buffer != NULL, NULL);
/* create a fresh new buffer */
copy = gst_buffer_new ();
GST_CAT_LOG (GST_CAT_BUFFER, "copy %p to %p", buffer, copy);
/* copy relevant flags */
mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS |
GST_BUFFER_FLAG_DELTA_UNIT | GST_BUFFER_FLAG_DISCONT |
GST_BUFFER_FLAG_GAP;
GST_MINI_OBJECT_FLAGS (copy) |= GST_MINI_OBJECT_FLAGS (buffer) & mask;
/* we simply copy everything from our parent */
copy->data = g_memdup (buffer->data, buffer->size);
/* make sure it gets freed (even if the parent is subclassed, we return a
normal buffer) */
copy->malloc_data = copy->data;
copy->size = buffer->size;
GST_BUFFER_TIMESTAMP (copy) = GST_BUFFER_TIMESTAMP (buffer);
GST_BUFFER_DURATION (copy) = GST_BUFFER_DURATION (buffer);
GST_BUFFER_OFFSET (copy) = GST_BUFFER_OFFSET (buffer);
GST_BUFFER_OFFSET_END (copy) = GST_BUFFER_OFFSET_END (buffer);
if (GST_BUFFER_CAPS (buffer))
GST_BUFFER_CAPS (copy) = gst_caps_ref (GST_BUFFER_CAPS (buffer));
else
GST_BUFFER_CAPS (copy) = NULL;
gst_buffer_copy_metadata (copy, buffer, GST_BUFFER_COPY_ALL);
return copy;
}

View file

@ -338,6 +338,39 @@ gst_buffer_ref (GstBuffer * buf)
* copy of the data the source buffer contains.
*/
#define gst_buffer_copy(buf) GST_BUFFER_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CAST (buf)))
/**
* GstBufferCopyFlags:
* @GST_BUFFER_COPY_FLAGS: flag indicating that buffer flags should be copied
* @GST_BUFFER_COPY_TIMESTAMPS: flag indicating that buffer timestamp, duration,
* offset and offset_end should be copied
* @GST_BUFFER_COPY_CAPS: flag indicating that buffer caps should be copied
*
* A set of flags that can be provided to the gst_buffer_copy_metadata()
* function to specify which metadata fields should be copied.
*
* Since: 0.10.13
*/
typedef enum {
GST_BUFFER_COPY_FLAGS = (1 << 0),
GST_BUFFER_COPY_TIMESTAMPS = (1 << 1),
GST_BUFFER_COPY_CAPS = (1 << 2),
} GstBufferCopyFlags;
/**
* GST_BUFFER_COPY_ALL:
*
* Combination of all possible fields that can be copied with
* gst_buffer_copy_metadata().
*
* Since: 0.10.13
*/
#define GST_BUFFER_COPY_ALL (GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS | GST_BUFFER_COPY_CAPS)
/* copies metadata into newly allocated buffer */
void gst_buffer_copy_metadata (GstBuffer *dest, const GstBuffer *src,
GstBufferCopyFlags flags);
/**
* gst_buffer_is_writable:
* @buf: a #GstBuffer

View file

@ -2413,18 +2413,16 @@ gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
* Copies additional information (the timestamp, duration, and offset start
* and end) from one buffer to the other.
*
* This function does not copy any buffer flags or caps.
* This function does not copy any buffer flags or caps and is equivalent to
* gst_buffer_copy_metadata(@dest, @src, GST_BUFFER_COPY_TIMESTAMPS).
*
* Deprecated: use gst_buffer_copy_metadata() instead, it provides more
* control.
*/
void
gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
{
g_return_if_fail (dest != NULL);
g_return_if_fail (src != NULL);
GST_BUFFER_TIMESTAMP (dest) = GST_BUFFER_TIMESTAMP (src);
GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
gst_buffer_copy_metadata (dest, src, GST_BUFFER_COPY_TIMESTAMPS);
}
static gboolean

View file

@ -972,10 +972,8 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
if (copy_inbuf && gst_buffer_is_writable (*out_buf))
memcpy (GST_BUFFER_DATA (*out_buf), GST_BUFFER_DATA (in_buf), out_size);
gst_buffer_stamp (*out_buf, in_buf);
GST_BUFFER_FLAGS (*out_buf) |= GST_BUFFER_FLAGS (in_buf) &
(GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_DISCONT |
GST_BUFFER_FLAG_IN_CAPS | GST_BUFFER_FLAG_DELTA_UNIT);
gst_buffer_copy_metadata (*out_buf, in_buf,
GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
}
done: