buffer: add _append_region function

Make a gst_buffer_append_region() function that allows you to append a memory
region from one buffer to another. This is a more general version of
gst_buffer_append().
This commit is contained in:
Wim Taymans 2012-06-28 11:02:19 +02:00
parent d7fdf75e13
commit 4c6228224f
4 changed files with 23 additions and 15 deletions

View file

@ -236,6 +236,7 @@ gst_buffer_make_writable
gst_buffer_replace
gst_buffer_append
gst_buffer_append_region
gst_buffer_get_meta
gst_buffer_add_meta

View file

@ -1614,8 +1614,23 @@ gst_buffer_copy_region (GstBuffer * buffer, GstBufferCopyFlags flags,
* Returns: (transfer full): the new #GstBuffer that contains the memory
* of the two source buffers.
*/
/**
* 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.
*/
GstBuffer *
gst_buffer_append (GstBuffer * buf1, GstBuffer * buf2)
gst_buffer_append_region (GstBuffer * buf1, GstBuffer * buf2, gssize offset,
gssize size)
{
gsize i, len;
@ -1625,6 +1640,8 @@ gst_buffer_append (GstBuffer * buf1, GstBuffer * buf2)
buf1 = gst_buffer_make_writable (buf1);
buf2 = gst_buffer_make_writable (buf2);
gst_buffer_resize (buf2, offset, size);
len = GST_BUFFER_MEM_LEN (buf2);
for (i = 0; i < len; i++) {
GstMemory *mem;
@ -1634,18 +1651,6 @@ gst_buffer_append (GstBuffer * buf1, GstBuffer * buf2)
_memory_add (buf1, -1, mem);
}
/* we can calculate the duration too. Also make sure we're not messing
* with invalid DURATIONS */
if (GST_BUFFER_DURATION_IS_VALID (buf1) &&
GST_BUFFER_DURATION_IS_VALID (buf2)) {
/* add duration */
GST_BUFFER_DURATION (buf1) += GST_BUFFER_DURATION (buf2);
}
if (GST_BUFFER_OFFSET_END_IS_VALID (buf2)) {
/* set offset_end */
GST_BUFFER_OFFSET_END (buf1) = GST_BUFFER_OFFSET_END (buf2);
}
GST_BUFFER_MEM_LEN (buf2) = 0;
gst_buffer_unref (buf2);

View file

@ -476,7 +476,9 @@ GstBuffer* gst_buffer_copy_region (GstBuffer *parent, GstBufferCop
gsize offset, gsize size);
/* append two buffers */
GstBuffer* gst_buffer_append (GstBuffer *buf1, GstBuffer *buf2);
GstBuffer* gst_buffer_append_region (GstBuffer *buf1, GstBuffer *buf2,
gssize offset, gssize size);
#define gst_buffer_append(b1,b2) gst_buffer_append_region ((b1), (b2), 0, -1)
/* metadata */
#include <gst/gstmeta.h>

View file

@ -89,7 +89,7 @@ EXPORTS
gst_bin_remove_many
gst_bitmask_get_type
gst_buffer_add_meta
gst_buffer_append
gst_buffer_append_region
gst_buffer_copy_flags_get_type
gst_buffer_copy_into
gst_buffer_copy_region