buffer: fix remaining unit tests

This commit is contained in:
Wim Taymans 2011-03-24 21:18:52 +01:00
parent f35847a094
commit beac9c4a95
12 changed files with 98 additions and 134 deletions

View file

@ -175,7 +175,7 @@ _gst_buffer_initialize (void)
* @src: a source #GstBuffer
* @flags: flags indicating what metadata fields should be copied.
* @offset: offset to copy from
* @trim: bytes to trim from end
* @size: total size to copy
*
* Copies the information from @src into @dest.
*
@ -183,9 +183,10 @@ _gst_buffer_initialize (void)
*/
void
gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
GstBufferCopyFlags flags, gsize offset, gsize trim)
GstBufferCopyFlags flags, gsize offset, gsize size)
{
GstMetaItem *walk;
gsize bufsize;
g_return_if_fail (dest != NULL);
g_return_if_fail (src != NULL);
@ -194,6 +195,11 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
if (G_UNLIKELY (dest == src))
return;
bufsize = gst_buffer_get_size (src);
if (size == -1)
size = bufsize - offset;
g_return_if_fail (bufsize >= offset + size);
#if GST_VERSION_NANO == 1
/* we enable this extra debugging in git versions only for now */
g_warn_if_fail (gst_buffer_is_writable (dest));
@ -216,7 +222,7 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
if (offset == 0) {
GST_BUFFER_TIMESTAMP (dest) = GST_BUFFER_TIMESTAMP (src);
GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
if (trim == 0) {
if (size == gst_buffer_get_size (src)) {
GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
}
@ -241,31 +247,36 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
for (i = 0; i < len; i++) {
GstMemory *mem, *dmem;
gsize size;
gsize msize;
mem = g_ptr_array_index (sarr, i);
msize = gst_memory_get_sizes (mem, NULL);
if (i + 1 == len) {
/* last chunk */
size = gst_memory_get_sizes (mem, NULL);
dmem = gst_memory_sub (mem, offset, size - offset - trim);
dmem = gst_memory_sub (mem, offset, size);
} else if (offset) {
size = gst_memory_get_sizes (mem, NULL);
dmem = gst_memory_sub (mem, offset, size - offset);
offset = 0;
if (msize > offset) {
dmem = gst_memory_sub (mem, offset, msize - offset);
offset = 0;
} else {
offset -= msize;
dmem = NULL;
}
} else
dmem = gst_memory_ref (mem);
g_ptr_array_add (darr, dmem);
if (dmem)
g_ptr_array_add (darr, dmem);
}
}
for (walk = src->priv; walk; walk = walk->next) {
GstMeta *meta = &walk->meta;
const GstMetaInfo *info = meta->info;
GstMetaTransformData data = { GST_META_TRANSFORM_COPY };
if (info->transform_func)
info->transform_func (dest, meta, (GstBuffer *) src, &data);
if (info->copy_func)
info->copy_func (dest, meta, (GstBuffer *) src, offset, size);
}
}
@ -280,7 +291,7 @@ _gst_buffer_copy (GstBuffer * buffer)
copy = gst_buffer_new ();
/* we simply copy everything from our parent */
gst_buffer_copy_into (copy, buffer, GST_BUFFER_COPY_ALL, 0, 0);
gst_buffer_copy_into (copy, buffer, GST_BUFFER_COPY_ALL, 0, -1);
return copy;
}
@ -696,14 +707,16 @@ gst_buffer_extract (GstBuffer * buffer, gsize offset, gpointer dest, gsize size)
mem = g_ptr_array_index (arr, i);
data = gst_memory_map (mem, &ssize, NULL, GST_MAP_READ);
tocopy = MIN (ssize, size);
if (tocopy > offset) {
memcpy (ptr, data + offset, tocopy - offset);
if (ssize > offset) {
/* we have enough */
tocopy = MIN (ssize - offset, size);
memcpy (ptr, data + offset, tocopy);
size -= tocopy;
ptr += tocopy;
offset = 0;
} else {
offset -= tocopy;
/* offset past buffer, skip */
offset -= ssize;
}
gst_memory_unmap (mem, data, ssize);
}
@ -802,8 +815,7 @@ gst_buffer_create_sub (GstBuffer * buffer, gsize offset, gsize size)
GST_CAT_LOG (GST_CAT_BUFFER, "new subbuffer %p of %p", subbuffer, buffer);
gst_buffer_copy_into (subbuffer, buffer, GST_BUFFER_COPY_ALL, offset,
bufsize - (size + offset));
gst_buffer_copy_into (subbuffer, buffer, GST_BUFFER_COPY_ALL, offset, size);
return subbuffer;
}

View file

@ -429,7 +429,7 @@ typedef enum {
/* copies memory or metadata into newly allocated buffer */
void gst_buffer_copy_into (GstBuffer *dest, GstBuffer *src,
GstBufferCopyFlags flags,
gsize offset, gsize trim);
gsize offset, gsize size);
/**
* gst_buffer_is_writable:

View file

@ -836,9 +836,9 @@ GstBuffer *
gst_buffer_list_iterator_merge_group (const GstBufferListIterator * it)
{
GList *tmp;
gsize size, bsize;
gsize size;
GstBuffer *buf;
guint8 *dest, *ptr, *bdata;
guint8 *dest, *ptr;
g_return_val_if_fail (it != NULL, NULL);
@ -861,19 +861,18 @@ gst_buffer_list_iterator_merge_group (const GstBufferListIterator * it)
/* copy metadata from the next buffer after the implicit cursor */
gst_buffer_copy_into (buf, GST_BUFFER_CAST (it->next->data),
GST_BUFFER_COPY_METADATA, 0, 0);
GST_BUFFER_COPY_METADATA, 0, -1);
/* copy data of all buffers before the next group start into the new buffer */
dest = ptr = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
tmp = it->next;
do {
if (tmp->data != STOLEN) {
GstBuffer *tbuf = GST_BUFFER_CAST (tmp->data);
gsize bsize;
bdata =
gst_buffer_map (GST_BUFFER_CAST (tmp->data), &bsize, NULL,
GST_MAP_READ);
memcpy (ptr, bdata, bsize);
gst_buffer_unmap (GST_BUFFER_CAST (tmp->data), bdata, bsize);
bsize = gst_buffer_get_size (tbuf);
gst_buffer_extract (tbuf, 0, ptr, bsize);
ptr += bsize;
}
tmp = g_list_next (tmp);

View file

@ -54,6 +54,7 @@ _gst_meta_init (void)
const GstMetaInfo *
gst_meta_register (const gchar * api, const gchar * impl, gsize size,
GstMetaInitFunction init_func, GstMetaFreeFunction free_func,
GstMetaCopyFunction copy_func,
GstMetaTransformFunction transform_func,
GstMetaSerializeFunction serialize_func,
GstMetaDeserializeFunction deserialize_func)
@ -70,6 +71,7 @@ gst_meta_register (const gchar * api, const gchar * impl, gsize size,
info->size = size;
info->init_func = init_func;
info->free_func = free_func;
info->copy_func = copy_func;
info->transform_func = transform_func;
info->serialize_func = serialize_func;
info->deserialize_func = deserialize_func;
@ -109,26 +111,15 @@ gst_meta_get_info (const gchar * impl)
/* Timing metadata */
static void
meta_timing_transform (GstBuffer * transbuf, GstMetaTiming * meta,
GstBuffer * buffer, GstMetaTransformData * data)
meta_timing_copy (GstBuffer * copybuf, GstMetaTiming * meta,
GstBuffer * buffer, gsize offset, gsize size)
{
GstMetaTiming *timing;
guint offset;
guint size;
if (data->type == GST_META_TRANSFORM_TRIM) {
GstMetaTransformSubbuffer *subdata = (GstMetaTransformSubbuffer *) data;
offset = subdata->offset;
size = subdata->size;
} else {
offset = 0;
size = gst_buffer_get_size (buffer);
}
GST_DEBUG ("trans called from buffer %p to %p, meta %p, %u-%u", buffer,
transbuf, meta, offset, size);
copybuf, meta, offset, size);
timing = gst_buffer_add_meta_timing (transbuf);
timing = gst_buffer_add_meta_timing (copybuf);
if (offset == 0) {
/* same offset, copy timestamps */
timing->pts = meta->pts;
@ -158,7 +149,8 @@ gst_meta_timing_get_info (void)
sizeof (GstMetaTiming),
(GstMetaInitFunction) NULL,
(GstMetaFreeFunction) NULL,
(GstMetaTransformFunction) meta_timing_transform,
(GstMetaCopyFunction) meta_timing_copy,
(GstMetaTransformFunction) NULL,
(GstMetaSerializeFunction) NULL, (GstMetaDeserializeFunction) NULL);
}
return meta_info;

View file

@ -64,51 +64,8 @@ typedef gboolean (*GstMetaInitFunction) (GstMeta *meta, gpointer params, GstBuff
*/
typedef void (*GstMetaFreeFunction) (GstMeta *meta, GstBuffer *buffer);
/**
* GstMetaTransformType:
* @GST_META_TRANSFORM_NONE: invalid transform type
* @GST_META_TRANSFORM_COPY: copy transform
* @GST_META_TRANSFORM_MAKE_WRITABLE: make writable type
* @GST_META_TRANSFORM_TRIM: trim buffer
* @GST_META_TRANSFORM_CUSTOM: start of custom transform types
*
* Different default transform types.
*/
typedef enum {
GST_META_TRANSFORM_NONE = 0,
GST_META_TRANSFORM_COPY,
GST_META_TRANSFORM_MAKE_WRITABLE,
GST_META_TRANSFORM_TRIM,
GST_META_TRANSFORM_CUSTOM = 256
} GstMetaTransformType;
/**
* GstMetaTransformData:
* @type: a #GstMetaTransformType
*
* Common structure that should be put as the first field in the type specific
* structure for the #GstMetaTransformFunction. It contains the type of the
* transform that should be performed.
*/
typedef struct {
GstMetaTransformType type;
} GstMetaTransformData;
/**
* GstMetaTransformSubbuffer:
* @data: parent #GstMetaTransformData
* @offset: the offset of the subbuffer
* @size: the new size of the subbuffer
*
* The subbuffer specific extra info.
*/
typedef struct {
GstMetaTransformData data;
gsize offset;
gsize size;
} GstMetaTransformSubbuffer;
typedef void (*GstMetaCopyFunction) (GstBuffer *dest, GstMeta *meta,
GstBuffer *buffer, gsize offset, gsize size);
/**
* GstMetaTransformFunction:
* @transbuf: a #GstBuffer
@ -122,12 +79,9 @@ typedef struct {
*
* Implementations should check the type of the transform @data and parse
* additional type specific field that should be used to perform the transform.
*
* If @data is NULL, the metadata should be shallow copied. This is done when
* gst_buffer_make_metadata_writable() is called.
*/
typedef void (*GstMetaTransformFunction) (GstBuffer *transbuf, GstMeta *meta,
GstBuffer *buffer, GstMetaTransformData *data);
GstBuffer *buffer, gpointer data);
/**
* GstMetaSerializeFunction:
@ -149,6 +103,7 @@ typedef gboolean (*GstMetaDeserializeFunction) (GstMeta *meta,
* @size: size of the metadata
* @init_func: function for initializing the metadata
* @free_func: function for freeing the metadata
* @copy_func: function for copying the metadata
* @transform_func: function for transforming the metadata
* @serialize_func: function for serializing
* @deserialize_func: function for deserializing
@ -163,6 +118,7 @@ struct _GstMetaInfo {
GstMetaInitFunction init_func;
GstMetaFreeFunction free_func;
GstMetaCopyFunction copy_func;
GstMetaTransformFunction transform_func;
GstMetaSerializeFunction serialize_func;
GstMetaDeserializeFunction deserialize_func;
@ -174,6 +130,7 @@ const GstMetaInfo * gst_meta_register (const gchar *api, const gchar *im
gsize size,
GstMetaInitFunction init_func,
GstMetaFreeFunction free_func,
GstMetaCopyFunction copy_func,
GstMetaTransformFunction transform_func,
GstMetaSerializeFunction serialize_func,
GstMetaDeserializeFunction deserialize_func);

View file

@ -269,6 +269,7 @@ copy_into_unchecked (GstAdapter * adapter, guint8 * dest, gsize skip,
}
/* copy partial buffer */
csize = MIN (bsize - skip, size);
GST_DEBUG ("%u %u %u", bsize, skip, csize);
gst_buffer_extract (buf, skip, dest, csize);
size -= csize;
dest += csize;
@ -623,7 +624,6 @@ gst_adapter_take_internal (GstAdapter * adapter, gsize nbytes)
}
if (tocopy) {
/* copy the remaining data */
GST_LOG_OBJECT (adapter, "copying %u bytes", tocopy);
copy_into_unchecked (adapter, toreuse + data, toreuse + adapter->skip,
tocopy);
}

View file

@ -233,7 +233,7 @@ GST_START_TEST (test_pull)
/* compare with previously read data */
data2 = gst_buffer_map (buffer2, &size2, NULL, GST_MAP_READ);
fail_unless (memcmp (data1, data2, 50) == 0);
fail_unless (memcmp (data1 + 50, data2, 50) == 0);
gst_buffer_unmap (buffer2, data2, size2);
gst_buffer_unmap (buffer1, data1, size1);

View file

@ -80,26 +80,15 @@ test_free_func (GstMetaTest * meta, GstBuffer * buffer)
}
static void
test_transform_func (GstBuffer * transbuf, GstMetaTest * meta,
GstBuffer * buffer, GstMetaTransformData * data)
test_copy_func (GstBuffer * copybuf, GstMetaTest * meta,
GstBuffer * buffer, gsize offset, gsize size)
{
GstMetaTest *test;
guint offset;
guint size;
if (data->type == GST_META_TRANSFORM_TRIM) {
GstMetaTransformSubbuffer *subdata = (GstMetaTransformSubbuffer *) data;
offset = subdata->offset;
size = subdata->size;
} else {
offset = 0;
size = gst_buffer_get_size (buffer);
}
GST_DEBUG ("copy called from buffer %p to %p, meta %p, %u-%u", buffer,
copybuf, meta, offset, size);
GST_DEBUG ("trans called from buffer %p to %p, meta %p, %u-%u", buffer,
transbuf, meta, offset, size);
test = GST_META_TEST_ADD (transbuf);
test = GST_META_TEST_ADD (copybuf);
if (offset == 0) {
/* same offset, copy timestamps */
test->pts = meta->pts;
@ -129,7 +118,8 @@ gst_meta_test_get_info (void)
sizeof (GstMetaTest),
(GstMetaInitFunction) test_init_func,
(GstMetaFreeFunction) test_free_func,
(GstMetaTransformFunction) test_transform_func, NULL, NULL);
(GstMetaCopyFunction) test_copy_func,
(GstMetaTransformFunction) NULL, NULL, NULL);
}
return meta_test_info;
}

View file

@ -424,6 +424,7 @@ buffer_compare (GstBuffer * buf, const gchar * str, gsize size)
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_READ);
res = memcmp (data, str, size) == 0;
GST_DEBUG ("%s <-> %s: %d", (gchar *) data, str, res);
gst_buffer_unmap (buf, data, size);
return res;
@ -476,12 +477,12 @@ GST_START_TEST (test_push_buffer_list_compat)
fail_unless_equals_int (g_list_length (buffers), 2);
buffer = GST_BUFFER (buffers->data);
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
fail_unless (buffer_compare (buffer, "ListGroup", 9) == 0);
fail_unless (buffer_compare (buffer, "ListGroup", 9));
gst_buffer_unref (buffer);
buffers = g_list_delete_link (buffers, buffers);
buffer = GST_BUFFER (buffers->data);
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
fail_unless (buffer_compare (buffer, "AnotherListGroup", 16) == 0);
fail_unless (buffer_compare (buffer, "AnotherListGroup", 16));
gst_buffer_unref (buffer);
buffers = g_list_delete_link (buffers, buffers);
fail_unless (buffers == NULL);

View file

@ -125,8 +125,6 @@ GST_START_TEST (test_peek1)
avail = gst_adapter_available_fast (adapter);
fail_if (avail != 0);
gst_buffer_unmap (buffer, (gpointer) bufdata, 0);
/* silly clear just for fun */
gst_adapter_clear (adapter);
@ -260,8 +258,6 @@ GST_START_TEST (test_take3)
/* the data should be the same */
fail_unless (data == data2);
gst_buffer_unmap (buffer, data, size);
gst_buffer_unmap (buffer2, data2, size2);
gst_buffer_unref (buffer2);
g_object_unref (adapter);
@ -309,8 +305,10 @@ GST_START_TEST (test_take_order)
adapter = create_and_fill_adapter ();
while (gst_adapter_available (adapter) >= sizeof (guint32)) {
guint8 *data = gst_adapter_take (adapter, sizeof (guint32));
guint32 val = GST_READ_UINT32_LE (data);
fail_unless (GST_READ_UINT32_LE (data) == i);
GST_DEBUG ("val %8u", val);
fail_unless (val == i);
i++;
g_free (data);
}

View file

@ -5,15 +5,16 @@ EXPORTS
gst_adapter_copy
gst_adapter_flush
gst_adapter_get_type
gst_adapter_map
gst_adapter_masked_scan_uint32
gst_adapter_masked_scan_uint32_peek
gst_adapter_new
gst_adapter_peek
gst_adapter_prev_timestamp
gst_adapter_push
gst_adapter_take
gst_adapter_take_buffer
gst_adapter_take_list
gst_adapter_unmap
gst_base_sink_do_preroll
gst_base_sink_get_blocksize
gst_base_sink_get_last_buffer
@ -71,9 +72,7 @@ EXPORTS
gst_bit_reader_get_remaining
gst_bit_reader_get_size
gst_bit_reader_init
gst_bit_reader_init_from_buffer
gst_bit_reader_new
gst_bit_reader_new_from_buffer
gst_bit_reader_peek_bits_uint16
gst_bit_reader_peek_bits_uint32
gst_bit_reader_peek_bits_uint64
@ -114,10 +113,8 @@ EXPORTS
gst_byte_reader_get_uint64_le
gst_byte_reader_get_uint8
gst_byte_reader_init
gst_byte_reader_init_from_buffer
gst_byte_reader_masked_scan_uint32
gst_byte_reader_new
gst_byte_reader_new_from_buffer
gst_byte_reader_peek_data
gst_byte_reader_peek_float32_be
gst_byte_reader_peek_float32_le
@ -154,11 +151,9 @@ EXPORTS
gst_byte_writer_free_and_get_data
gst_byte_writer_get_remaining
gst_byte_writer_init
gst_byte_writer_init_with_buffer
gst_byte_writer_init_with_data
gst_byte_writer_init_with_size
gst_byte_writer_new
gst_byte_writer_new_with_buffer
gst_byte_writer_new_with_data
gst_byte_writer_new_with_size
gst_byte_writer_put_data
@ -201,7 +196,6 @@ EXPORTS
gst_collect_pads_new
gst_collect_pads_peek
gst_collect_pads_pop
gst_collect_pads_read
gst_collect_pads_read_buffer
gst_collect_pads_remove_pad
gst_collect_pads_set_clip_function
@ -225,6 +219,7 @@ EXPORTS
gst_push_src_get_type
gst_type_find_helper
gst_type_find_helper_for_buffer
gst_type_find_helper_for_data
gst_type_find_helper_for_extension
gst_type_find_helper_get_range
gst_type_find_helper_get_range_ext

View file

@ -90,14 +90,14 @@ EXPORTS
gst_bin_remove
gst_bin_remove_many
gst_buffer_add_meta
gst_buffer_add_meta_memory
gst_buffer_copy_flags_get_type
gst_buffer_copy_metadata
gst_buffer_copy_into
gst_buffer_create_sub
gst_buffer_extract
gst_buffer_flag_get_type
gst_buffer_get_caps
gst_buffer_get_meta
gst_buffer_is_metadata_writable
gst_buffer_get_size
gst_buffer_is_span_fast
gst_buffer_iterate_meta
gst_buffer_join
@ -119,10 +119,12 @@ EXPORTS
gst_buffer_list_iterator_take
gst_buffer_list_n_groups
gst_buffer_list_new
gst_buffer_make_metadata_writable
gst_buffer_map
gst_buffer_merge
gst_buffer_n_memory
gst_buffer_new
gst_buffer_new_and_alloc
gst_buffer_peek_memory
gst_buffer_pool_acquire_buffer
gst_buffer_pool_config_get
gst_buffer_pool_config_set
@ -133,10 +135,13 @@ EXPORTS
gst_buffer_pool_release_buffer
gst_buffer_pool_set_active
gst_buffer_pool_set_config
gst_buffer_remove_memory
gst_buffer_remove_meta
gst_buffer_set_caps
gst_buffer_span
gst_buffer_take_memory
gst_buffer_try_new_and_alloc
gst_buffer_unmap
gst_buffering_mode_get_type
gst_bus_add_signal_watch
gst_bus_add_signal_watch_full
@ -504,6 +509,7 @@ EXPORTS
gst_iterator_resync
gst_library_error_get_type
gst_library_error_quark
gst_map_flags_get_type
gst_marshal_BOOLEAN__BOXED
gst_marshal_BOOLEAN__POINTER
gst_marshal_BOOLEAN__VOID
@ -521,6 +527,22 @@ EXPORTS
gst_marshal_VOID__OBJECT_STRING
gst_marshal_VOID__POINTER_OBJECT
gst_marshal_VOID__UINT_BOXED
gst_memory_copy
gst_memory_extract
gst_memory_flags_get_type
gst_memory_get_sizes
gst_memory_is_span
gst_memory_map
gst_memory_new_alloc
gst_memory_new_copy
gst_memory_new_wrapped
gst_memory_ref
gst_memory_register
gst_memory_span
gst_memory_sub
gst_memory_trim
gst_memory_unmap
gst_memory_unref
gst_message_get_seqnum
gst_message_get_stream_status_object
gst_message_get_structure
@ -586,8 +608,6 @@ EXPORTS
gst_message_type_get_type
gst_message_type_to_quark
gst_meta_get_info
gst_meta_map_flags_get_type
gst_meta_memory_get_info
gst_meta_register
gst_meta_timing_get_info
gst_mini_object_copy