mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-27 02:30:35 +00:00
memory: more work on porting the unit tests
This commit is contained in:
parent
4a9a59df08
commit
1af328e785
11 changed files with 175 additions and 121 deletions
|
@ -665,6 +665,7 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
|
|||
g_log_set_handler (g_log_domain_gstreamer, llf, debug_log_handler, NULL);
|
||||
|
||||
_priv_gst_quarks_initialize ();
|
||||
_gst_memory_init ();
|
||||
_gst_format_initialize ();
|
||||
_gst_query_initialize ();
|
||||
_gst_caps_initialize ();
|
||||
|
|
|
@ -239,16 +239,23 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
|
|||
|
||||
len = sarr->len;
|
||||
|
||||
if (flags & GST_BUFFER_COPY_MEMORY_SHARE) {
|
||||
for (i = 0; i < len; i++) {
|
||||
GstMemory *mem = g_ptr_array_index (sarr, i);
|
||||
g_ptr_array_add (darr, gst_memory_ref (mem));
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < len; i++) {
|
||||
GstMemory *mem = g_ptr_array_index (sarr, i);
|
||||
g_ptr_array_add (darr, gst_memory_copy (mem));
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
GstMemory *mem, *dmem;
|
||||
gsize size;
|
||||
|
||||
mem = g_ptr_array_index (sarr, i);
|
||||
if (i + 1 == len) {
|
||||
/* last chunk */
|
||||
size = gst_memory_get_sizes (mem, NULL);
|
||||
dmem = gst_memory_sub (mem, offset, size - offset - trim);
|
||||
} else if (offset) {
|
||||
size = gst_memory_get_sizes (mem, NULL);
|
||||
dmem = gst_memory_sub (mem, offset, size - offset);
|
||||
offset = 0;
|
||||
} else
|
||||
dmem = gst_memory_ref (mem);
|
||||
|
||||
g_ptr_array_add (darr, dmem);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -654,7 +661,7 @@ gst_buffer_make_metadata_writable (GstBuffer * buf)
|
|||
ret = gst_buffer_new ();
|
||||
|
||||
/* we simply copy everything from our parent */
|
||||
gst_buffer_copy_into (ret, buf, GST_BUFFER_SHARE_ALL, 0, 0);
|
||||
gst_buffer_copy_into (ret, buf, GST_BUFFER_COPY_ALL, 0, 0);
|
||||
gst_buffer_unref (buf);
|
||||
}
|
||||
return ret;
|
||||
|
@ -698,7 +705,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_SHARE_ALL, offset,
|
||||
gst_buffer_copy_into (subbuffer, buffer, GST_BUFFER_COPY_ALL, offset,
|
||||
bufsize - (size + offset));
|
||||
|
||||
return subbuffer;
|
||||
|
|
|
@ -414,7 +414,6 @@ typedef enum {
|
|||
GST_BUFFER_COPY_CAPS = (1 << 2),
|
||||
GST_BUFFER_COPY_MEMORY = (1 << 3),
|
||||
GST_BUFFER_COPY_MEMORY_MERGE = (1 << 4),
|
||||
GST_BUFFER_COPY_MEMORY_SHARE = (1 << 5),
|
||||
} GstBufferCopyFlags;
|
||||
|
||||
#define GST_BUFFER_COPY_METADATA (GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS | GST_BUFFER_COPY_CAPS)
|
||||
|
@ -429,8 +428,6 @@ typedef enum {
|
|||
*/
|
||||
#define GST_BUFFER_COPY_ALL (GST_BUFFER_COPY_METADATA | GST_BUFFER_COPY_MEMORY)
|
||||
|
||||
#define GST_BUFFER_SHARE_ALL (GST_BUFFER_COPY_METADATA | GST_BUFFER_COPY_MEMORY | GST_BUFFER_COPY_MEMORY_SHARE)
|
||||
|
||||
/* copies memory or metadata into newly allocated buffer */
|
||||
void gst_buffer_copy_into (GstBuffer *dest, GstBuffer *src,
|
||||
GstBufferCopyFlags flags,
|
||||
|
|
|
@ -184,12 +184,12 @@ _default_mem_free (GstMemoryDefault * mem)
|
|||
}
|
||||
|
||||
static GstMemoryDefault *
|
||||
_default_mem_copy (GstMemoryDefault * mem)
|
||||
_default_mem_copy (GstMemoryDefault * mem, gsize offset, gsize size)
|
||||
{
|
||||
GstMemoryDefault *copy;
|
||||
|
||||
copy = _default_mem_new_block (mem->maxsize, 0, mem->offset, mem->size);
|
||||
memcpy (copy->data + copy->offset, mem->data, mem->maxsize);
|
||||
copy = _default_mem_new_block (mem->maxsize, 0, mem->offset + offset, size);
|
||||
memcpy (copy->data, mem->data, mem->maxsize);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
@ -242,16 +242,16 @@ _fallback_extract (GstMemory * mem, gsize offset, gpointer dest, gsize size)
|
|||
}
|
||||
|
||||
static GstMemory *
|
||||
_fallback_copy (GstMemory * mem)
|
||||
_fallback_copy (GstMemory * mem, gsize offset, gsize size)
|
||||
{
|
||||
GstMemoryDefault *copy;
|
||||
gpointer data;
|
||||
gsize size;
|
||||
guint8 *data;
|
||||
gsize msize;
|
||||
|
||||
data = gst_memory_map (mem, &size, NULL, GST_MAP_READ);
|
||||
data = gst_memory_map (mem, &msize, NULL, GST_MAP_READ);
|
||||
copy = _default_mem_new_block (size, 0, 0, size);
|
||||
memcpy (copy->data, data, size);
|
||||
gst_memory_unmap (mem, data, size);
|
||||
memcpy (copy->data, data + offset, size);
|
||||
gst_memory_unmap (mem, data, msize);
|
||||
|
||||
return (GstMemory *) copy;
|
||||
}
|
||||
|
@ -356,6 +356,7 @@ void
|
|||
gst_memory_unref (GstMemory * mem)
|
||||
{
|
||||
g_return_if_fail (mem != NULL);
|
||||
g_return_if_fail (mem->impl != NULL);
|
||||
|
||||
if (g_atomic_int_dec_and_test (&mem->refcount))
|
||||
mem->impl->info.free (mem);
|
||||
|
@ -387,11 +388,11 @@ gst_memory_unmap (GstMemory * mem, gpointer data, gsize size)
|
|||
}
|
||||
|
||||
GstMemory *
|
||||
gst_memory_copy (GstMemory * mem)
|
||||
gst_memory_copy (GstMemory * mem, gsize offset, gsize size)
|
||||
{
|
||||
g_return_val_if_fail (mem != NULL, NULL);
|
||||
|
||||
return mem->impl->info.copy (mem);
|
||||
return mem->impl->info.copy (mem, offset, size);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -74,7 +74,7 @@ typedef gpointer (*GstMemoryMapFunction) (GstMemory *mem, gsize *size, gsize
|
|||
typedef gboolean (*GstMemoryUnmapFunction) (GstMemory *mem, gpointer data, gsize size);
|
||||
|
||||
typedef void (*GstMemoryFreeFunction) (GstMemory *mem);
|
||||
typedef GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem);
|
||||
typedef GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem, gsize offset, gsize size);
|
||||
typedef void (*GstMemoryExtractFunction) (GstMemory *mem, gsize offset,
|
||||
gpointer dest, gsize size);
|
||||
typedef void (*GstMemoryTrimFunction) (GstMemory *mem, gsize offset, gsize size);
|
||||
|
@ -103,34 +103,38 @@ struct _GstMemoryInfo {
|
|||
|
||||
void _gst_memory_init (void);
|
||||
|
||||
GstMemory * gst_memory_ref (GstMemory *mem);
|
||||
void gst_memory_unref (GstMemory *mem);
|
||||
|
||||
gsize gst_memory_get_sizes (GstMemory *mem, gsize *maxsize);
|
||||
void gst_memory_trim (GstMemory *mem, gsize offset, gsize size);
|
||||
|
||||
gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize,
|
||||
GstMapFlags flags);
|
||||
gboolean gst_memory_unmap (GstMemory *mem, gpointer data, gsize size);
|
||||
|
||||
GstMemory * gst_memory_copy (GstMemory *mem);
|
||||
void gst_memory_extract (GstMemory *mem, gsize offset, gpointer dest,
|
||||
gsize size);
|
||||
GstMemory * gst_memory_sub (GstMemory *mem, gsize offset, gsize size);
|
||||
|
||||
gboolean gst_memory_is_span (GstMemory **mem1, gsize len1,
|
||||
GstMemory **mem2, gsize len2,
|
||||
GstMemory **parent, gsize *offset);
|
||||
GstMemory * gst_memory_span (GstMemory **mem1, gsize len1, gsize offset,
|
||||
GstMemory **mem2, gsize len2, gsize size);
|
||||
|
||||
|
||||
/* allocating memory blocks */
|
||||
GstMemory * gst_memory_new_wrapped (gpointer data, GFreeFunc free_func,
|
||||
gsize maxsize, gsize offset, gsize size);
|
||||
GstMemory * gst_memory_new_alloc (gsize maxsize, gsize align);
|
||||
GstMemory * gst_memory_new_copy (gsize maxsize, gsize align, gpointer data,
|
||||
gsize offset, gsize size);
|
||||
|
||||
/* refcounting */
|
||||
GstMemory * gst_memory_ref (GstMemory *mem);
|
||||
void gst_memory_unref (GstMemory *mem);
|
||||
|
||||
/* getting/setting memory properties */
|
||||
gsize gst_memory_get_sizes (GstMemory *mem, gsize *maxsize);
|
||||
void gst_memory_trim (GstMemory *mem, gsize offset, gsize size);
|
||||
|
||||
/* retriveing data */
|
||||
gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize,
|
||||
GstMapFlags flags);
|
||||
gboolean gst_memory_unmap (GstMemory *mem, gpointer data, gsize size);
|
||||
void gst_memory_extract (GstMemory *mem, gsize offset, gpointer dest,
|
||||
gsize size);
|
||||
/* copy and subregions */
|
||||
GstMemory * gst_memory_copy (GstMemory *mem, gsize offset, gsize size);
|
||||
GstMemory * gst_memory_sub (GstMemory *mem, gsize offset, gsize size);
|
||||
|
||||
/* memory arrays */
|
||||
gboolean gst_memory_is_span (GstMemory **mem1, gsize len1,
|
||||
GstMemory **mem2, gsize len2,
|
||||
GstMemory **parent, gsize *offset);
|
||||
GstMemory * gst_memory_span (GstMemory **mem1, gsize len1, gsize offset,
|
||||
GstMemory **mem2, gsize len2, gsize size);
|
||||
|
||||
|
||||
const GstMemoryImpl * gst_memory_register (const gchar *impl, const GstMemoryInfo *info);
|
||||
|
||||
|
|
|
@ -87,9 +87,11 @@ GST_START_TEST (test_subbuffer)
|
|||
/* check sizes, buffer starts out empty */
|
||||
data = gst_buffer_map (buffer, &size, &maxsize, GST_MAP_WRITE);
|
||||
fail_unless (size == 0, "buffer has wrong size");
|
||||
fail_unless (maxsize == 4, "buffer has wrong size");
|
||||
fail_unless (maxsize >= 4, "buffer has wrong size");
|
||||
memset (data, 0, 4);
|
||||
gst_buffer_unmap (buffer, data, 4);
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
/* set some metadata */
|
||||
GST_BUFFER_TIMESTAMP (buffer) = 1;
|
||||
GST_BUFFER_DURATION (buffer) = 2;
|
||||
|
|
|
@ -43,7 +43,8 @@ GST_START_TEST (test_peek1)
|
|||
|
||||
/* push single buffer in adapter */
|
||||
buffer = gst_buffer_new_and_alloc (512);
|
||||
bufdata = GST_BUFFER_DATA (buffer);
|
||||
|
||||
bufdata = gst_buffer_map (buffer, NULL, NULL, GST_MAP_READ);
|
||||
|
||||
fail_if (buffer == NULL);
|
||||
gst_adapter_push (adapter, buffer);
|
||||
|
@ -56,22 +57,25 @@ GST_START_TEST (test_peek1)
|
|||
fail_if (avail != 512);
|
||||
|
||||
/* should g_critical with NULL as result */
|
||||
ASSERT_CRITICAL (data1 = gst_adapter_peek (adapter, 0));
|
||||
ASSERT_CRITICAL (data1 = gst_adapter_map (adapter, 0));
|
||||
fail_if (data1 != NULL);
|
||||
|
||||
/* should return NULL as result */
|
||||
data1 = gst_adapter_peek (adapter, 513);
|
||||
data1 = gst_adapter_map (adapter, 513);
|
||||
fail_if (data1 != NULL);
|
||||
|
||||
/* this should work */
|
||||
data1 = gst_adapter_peek (adapter, 512);
|
||||
data1 = gst_adapter_map (adapter, 512);
|
||||
fail_if (data1 == NULL);
|
||||
/* it should point to the buffer data as well */
|
||||
fail_if (data1 != bufdata);
|
||||
data2 = gst_adapter_peek (adapter, 512);
|
||||
gst_adapter_unmap (adapter, 0);
|
||||
|
||||
data2 = gst_adapter_map (adapter, 512);
|
||||
fail_if (data2 == NULL);
|
||||
/* second peek should return the same pointer */
|
||||
fail_if (data2 != data1);
|
||||
gst_adapter_unmap (adapter, 0);
|
||||
|
||||
/* this should fail since we don't have that many bytes */
|
||||
ASSERT_CRITICAL (gst_adapter_flush (adapter, 513));
|
||||
|
@ -86,15 +90,16 @@ GST_START_TEST (test_peek1)
|
|||
fail_if (avail != 502);
|
||||
|
||||
/* should return NULL as result */
|
||||
data2 = gst_adapter_peek (adapter, 503);
|
||||
data2 = gst_adapter_map (adapter, 503);
|
||||
fail_if (data2 != NULL);
|
||||
|
||||
/* should work fine */
|
||||
data2 = gst_adapter_peek (adapter, 502);
|
||||
data2 = gst_adapter_map (adapter, 502);
|
||||
fail_if (data2 == NULL);
|
||||
/* peek should return the same old pointer + 10 */
|
||||
fail_if (data2 != data1 + 10);
|
||||
fail_if (data2 != bufdata + 10);
|
||||
gst_adapter_unmap (adapter, 0);
|
||||
|
||||
/* flush some more */
|
||||
gst_adapter_flush (adapter, 500);
|
||||
|
@ -105,10 +110,11 @@ GST_START_TEST (test_peek1)
|
|||
avail = gst_adapter_available_fast (adapter);
|
||||
fail_if (avail != 2);
|
||||
|
||||
data2 = gst_adapter_peek (adapter, 2);
|
||||
data2 = gst_adapter_map (adapter, 2);
|
||||
fail_if (data2 == NULL);
|
||||
fail_if (data2 != data1 + 510);
|
||||
fail_if (data2 != bufdata + 510);
|
||||
gst_adapter_unmap (adapter, 0);
|
||||
|
||||
/* flush some more */
|
||||
gst_adapter_flush (adapter, 2);
|
||||
|
@ -119,6 +125,8 @@ 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);
|
||||
|
||||
|
@ -153,16 +161,16 @@ GST_START_TEST (test_take1)
|
|||
GstBuffer *buffer, *buffer2;
|
||||
guint avail;
|
||||
guint8 *data, *data2;
|
||||
gsize size, size2;
|
||||
|
||||
adapter = gst_adapter_new ();
|
||||
fail_unless (adapter != NULL);
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (100);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_DATA (buffer) != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 100);
|
||||
|
||||
data = GST_BUFFER_DATA (buffer);
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (data != NULL);
|
||||
fail_unless (size == 100);
|
||||
|
||||
/* push in the adapter */
|
||||
gst_adapter_push (adapter, buffer);
|
||||
|
@ -173,9 +181,10 @@ GST_START_TEST (test_take1)
|
|||
/* take out buffer */
|
||||
buffer2 = gst_adapter_take_buffer (adapter, 100);
|
||||
fail_unless (buffer2 != NULL);
|
||||
fail_unless (GST_BUFFER_DATA (buffer2) != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer2) == 100);
|
||||
data2 = GST_BUFFER_DATA (buffer2);
|
||||
|
||||
data2 = gst_buffer_map (buffer2, &size2, NULL, GST_MAP_READ);
|
||||
fail_unless (data2 != NULL);
|
||||
fail_unless (size2 == 100);
|
||||
|
||||
avail = gst_adapter_available (adapter);
|
||||
fail_unless (avail == 0);
|
||||
|
@ -184,6 +193,9 @@ GST_START_TEST (test_take1)
|
|||
fail_unless (buffer == buffer2);
|
||||
fail_unless (data == data2);
|
||||
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer2, data2, size2);
|
||||
|
||||
gst_buffer_unref (buffer2);
|
||||
|
||||
g_object_unref (adapter);
|
||||
|
@ -209,16 +221,16 @@ GST_START_TEST (test_take3)
|
|||
GstBuffer *buffer, *buffer2;
|
||||
guint avail;
|
||||
guint8 *data, *data2;
|
||||
gsize size, size2;
|
||||
|
||||
adapter = gst_adapter_new ();
|
||||
fail_unless (adapter != NULL);
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (100);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_DATA (buffer) != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 100);
|
||||
|
||||
data = GST_BUFFER_DATA (buffer);
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (data != NULL);
|
||||
fail_unless (size == 100);
|
||||
|
||||
/* set up and push subbuffers */
|
||||
buffer2 = gst_buffer_create_sub (buffer, 0, 25);
|
||||
|
@ -238,9 +250,9 @@ GST_START_TEST (test_take3)
|
|||
/* take out buffer */
|
||||
buffer2 = gst_adapter_take_buffer (adapter, 100);
|
||||
fail_unless (buffer2 != NULL);
|
||||
fail_unless (GST_BUFFER_DATA (buffer2) != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer2) == 100);
|
||||
data2 = GST_BUFFER_DATA (buffer2);
|
||||
data2 = gst_buffer_map (buffer2, &size2, NULL, GST_MAP_READ);
|
||||
fail_unless (data2 != NULL);
|
||||
fail_unless (size2 == 100);
|
||||
|
||||
avail = gst_adapter_available (adapter);
|
||||
fail_unless (avail == 0);
|
||||
|
@ -248,6 +260,8 @@ 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);
|
||||
|
@ -265,16 +279,20 @@ create_and_fill_adapter (void)
|
|||
fail_unless (adapter != NULL);
|
||||
|
||||
for (i = 0; i < 10000; i += 4) {
|
||||
GstBuffer *buf = gst_buffer_new_and_alloc (sizeof (guint32) * 4);
|
||||
GstBuffer *buf;
|
||||
guint8 *data;
|
||||
|
||||
buf = gst_buffer_new_and_alloc (sizeof (guint32) * 4);
|
||||
fail_unless (buf != NULL);
|
||||
data = GST_BUFFER_DATA (buf);
|
||||
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
|
||||
for (j = 0; j < 4; j++) {
|
||||
GST_WRITE_UINT32_LE (data, i + j);
|
||||
data += sizeof (guint32);
|
||||
}
|
||||
gst_buffer_unmap (buf, data, sizeof (guint32) * 4);
|
||||
|
||||
gst_adapter_push (adapter, buf);
|
||||
}
|
||||
|
||||
|
@ -314,8 +332,13 @@ GST_START_TEST (test_take_buf_order)
|
|||
adapter = create_and_fill_adapter ();
|
||||
while (gst_adapter_available (adapter) >= sizeof (guint32)) {
|
||||
GstBuffer *buf = gst_adapter_take_buffer (adapter, sizeof (guint32));
|
||||
gpointer data;
|
||||
gsize size;
|
||||
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (GST_READ_UINT32_LE (data) == i);
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
|
||||
fail_unless (GST_READ_UINT32_LE (GST_BUFFER_DATA (buf)) == i);
|
||||
i++;
|
||||
|
||||
gst_buffer_unref (buf);
|
||||
|
@ -509,7 +532,7 @@ GST_START_TEST (test_timestamp)
|
|||
/* remove first buffer, timestamp of empty buffer is visible */
|
||||
buffer = gst_adapter_take_buffer (adapter, 99);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 99);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 99);
|
||||
gst_buffer_unref (buffer);
|
||||
avail = gst_adapter_available (adapter);
|
||||
fail_unless (avail == 100);
|
||||
|
@ -518,8 +541,10 @@ GST_START_TEST (test_timestamp)
|
|||
fail_unless (dist == 0);
|
||||
|
||||
/* remove empty buffer, timestamp still visible */
|
||||
cdata = gst_adapter_peek (adapter, 50);
|
||||
cdata = gst_adapter_map (adapter, 50);
|
||||
fail_unless (cdata != NULL);
|
||||
gst_adapter_unmap (adapter, 0);
|
||||
|
||||
data = gst_adapter_take (adapter, 50);
|
||||
fail_unless (data != NULL);
|
||||
g_free (data);
|
||||
|
@ -546,10 +571,12 @@ GST_START_TEST (test_scan)
|
|||
fail_unless (adapter != NULL);
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (100);
|
||||
data = GST_BUFFER_DATA (buffer);
|
||||
|
||||
data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
|
||||
/* fill with pattern */
|
||||
for (i = 0; i < 100; i++)
|
||||
data[i] = i;
|
||||
gst_buffer_unmap (buffer, data, 100);
|
||||
|
||||
gst_adapter_push (adapter, buffer);
|
||||
|
||||
|
@ -608,10 +635,12 @@ GST_START_TEST (test_scan)
|
|||
|
||||
/* add another buffer */
|
||||
buffer = gst_buffer_new_and_alloc (100);
|
||||
data = GST_BUFFER_DATA (buffer);
|
||||
|
||||
data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
|
||||
/* fill with pattern */
|
||||
for (i = 0; i < 100; i++)
|
||||
data[i] = i + 100;
|
||||
gst_buffer_unmap (buffer, data, 100);
|
||||
|
||||
gst_adapter_push (adapter, buffer);
|
||||
|
||||
|
@ -739,23 +768,26 @@ GST_START_TEST (test_take_list)
|
|||
while (gst_adapter_available (adapter) >= sizeof (guint32)) {
|
||||
GList *list, *walk;
|
||||
GstBuffer *buf;
|
||||
guint size;
|
||||
guint8 *data;
|
||||
gsize size, left;
|
||||
guint8 *data, *ptr;
|
||||
|
||||
list = gst_adapter_take_list (adapter, sizeof (guint32) * 5);
|
||||
fail_unless (list != NULL);
|
||||
|
||||
for (walk = list; walk; walk = g_list_next (walk)) {
|
||||
buf = walk->data;
|
||||
data = GST_BUFFER_DATA (buf);
|
||||
size = GST_BUFFER_SIZE (buf);
|
||||
|
||||
while (size > 0) {
|
||||
fail_unless (GST_READ_UINT32_LE (data) == i);
|
||||
ptr = data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
||||
|
||||
left = size;
|
||||
while (left > 0) {
|
||||
fail_unless (GST_READ_UINT32_LE (ptr) == i);
|
||||
i++;
|
||||
data += sizeof (guint32);
|
||||
size -= sizeof (guint32);
|
||||
ptr += sizeof (guint32);
|
||||
left -= sizeof (guint32);
|
||||
}
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
|
||||
gst_buffer_unref (buf);
|
||||
}
|
||||
g_list_free (list);
|
||||
|
|
|
@ -46,9 +46,10 @@ GST_START_TEST (test_initialization)
|
|||
GstBitReader reader = GST_BIT_READER_INIT (data, 4);
|
||||
GstBitReader *reader2;
|
||||
guint8 x = 0;
|
||||
guint8 *bdata;
|
||||
gsize bsize;
|
||||
|
||||
GST_BUFFER_DATA (buffer) = data;
|
||||
GST_BUFFER_SIZE (buffer) = 4;
|
||||
gst_buffer_take_memory (buffer, gst_memory_new_wrapped (data, NULL, 4, 0, 4));
|
||||
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (&reader, &x, 8));
|
||||
fail_unless_equals_int (x, 0x01);
|
||||
|
@ -63,11 +64,13 @@ GST_START_TEST (test_initialization)
|
|||
fail_unless (gst_bit_reader_get_bits_uint8 (&reader, &x, 8));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
|
||||
gst_bit_reader_init_from_buffer (&reader, buffer);
|
||||
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
||||
gst_bit_reader_init (&reader, bdata, bsize);
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (&reader, &x, 8));
|
||||
fail_unless_equals_int (x, 0x01);
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (&reader, &x, 8));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
gst_buffer_unmap (buffer, bdata, bsize);
|
||||
|
||||
reader2 = gst_bit_reader_new (data, 4);
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (reader2, &x, 8));
|
||||
|
@ -76,12 +79,14 @@ GST_START_TEST (test_initialization)
|
|||
fail_unless_equals_int (x, 0x02);
|
||||
gst_bit_reader_free (reader2);
|
||||
|
||||
reader2 = gst_bit_reader_new_from_buffer (buffer);
|
||||
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
||||
reader2 = gst_bit_reader_new (bdata, bsize);
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (reader2, &x, 8));
|
||||
fail_unless_equals_int (x, 0x01);
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (reader2, &x, 8));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
gst_bit_reader_free (reader2);
|
||||
gst_buffer_unmap (buffer, bdata, bsize);
|
||||
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
|
|
@ -46,9 +46,10 @@ GST_START_TEST (test_initialization)
|
|||
GstByteReader reader = GST_BYTE_READER_INIT (data, 4);
|
||||
GstByteReader *reader2;
|
||||
guint8 x = 0;
|
||||
guint8 *bdata;
|
||||
gsize bsize;
|
||||
|
||||
GST_BUFFER_DATA (buffer) = data;
|
||||
GST_BUFFER_SIZE (buffer) = 4;
|
||||
gst_buffer_take_memory (buffer, gst_memory_new_wrapped (data, NULL, 4, 0, 4));
|
||||
|
||||
fail_unless (gst_byte_reader_get_uint8 (&reader, &x));
|
||||
fail_unless_equals_int (x, 0x01);
|
||||
|
@ -63,11 +64,13 @@ GST_START_TEST (test_initialization)
|
|||
fail_unless (gst_byte_reader_get_uint8 (&reader, &x));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
|
||||
gst_byte_reader_init_from_buffer (&reader, buffer);
|
||||
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
||||
gst_byte_reader_init (&reader, bdata, bsize);
|
||||
fail_unless (gst_byte_reader_get_uint8 (&reader, &x));
|
||||
fail_unless_equals_int (x, 0x01);
|
||||
fail_unless (gst_byte_reader_get_uint8 (&reader, &x));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
gst_buffer_unmap (buffer, bdata, bsize);
|
||||
|
||||
reader2 = gst_byte_reader_new (data, 4);
|
||||
fail_unless (gst_byte_reader_get_uint8 (reader2, &x));
|
||||
|
@ -76,12 +79,14 @@ GST_START_TEST (test_initialization)
|
|||
fail_unless_equals_int (x, 0x02);
|
||||
gst_byte_reader_free (reader2);
|
||||
|
||||
reader2 = gst_byte_reader_new_from_buffer (buffer);
|
||||
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
||||
reader2 = gst_byte_reader_new (bdata, bsize);
|
||||
fail_unless (gst_byte_reader_get_uint8 (reader2, &x));
|
||||
fail_unless_equals_int (x, 0x01);
|
||||
fail_unless (gst_byte_reader_get_uint8 (reader2, &x));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
gst_byte_reader_free (reader2);
|
||||
gst_buffer_unmap (buffer, bdata, bsize);
|
||||
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
|
|
@ -69,8 +69,8 @@ static gboolean (*klass_set_caps) (GstBaseTransform * trans, GstCaps * incaps,
|
|||
static GstCaps *(*klass_transform_caps) (GstBaseTransform * trans,
|
||||
GstPadDirection direction, GstCaps * caps) = NULL;
|
||||
static gboolean (*klass_transform_size) (GstBaseTransform * trans,
|
||||
GstPadDirection direction, GstCaps * caps, guint size, GstCaps * othercaps,
|
||||
guint * othersize) = NULL;
|
||||
GstPadDirection direction, GstCaps * caps, gsize size, GstCaps * othercaps,
|
||||
gsize * othersize) = NULL;
|
||||
static gboolean klass_passthrough_on_same_caps = FALSE;
|
||||
|
||||
static GstStaticPadTemplate *sink_template = &gst_test_trans_sink_template;
|
||||
|
|
|
@ -85,7 +85,7 @@ GST_START_TEST (basetransform_chain_pt1)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
/* caps should not have been set */
|
||||
fail_unless (GST_BUFFER_CAPS (buffer) == NULL);
|
||||
|
||||
|
@ -104,7 +104,7 @@ GST_START_TEST (basetransform_chain_pt1)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 10);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 10);
|
||||
/* caps should not have been set */
|
||||
fail_unless (GST_BUFFER_CAPS (buffer) == NULL);
|
||||
|
||||
|
@ -194,7 +194,7 @@ GST_START_TEST (basetransform_chain_pt2)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), caps));
|
||||
|
||||
gst_buffer_unref (buffer);
|
||||
|
@ -230,7 +230,7 @@ GST_START_TEST (basetransform_chain_pt2)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 10);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 10);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), caps));
|
||||
|
||||
gst_buffer_unref (buffer);
|
||||
|
@ -312,7 +312,7 @@ GST_START_TEST (basetransform_chain_ip1)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
GST_DEBUG_OBJECT (trans, "buffer without caps extra ref, size 20");
|
||||
|
@ -337,7 +337,7 @@ GST_START_TEST (basetransform_chain_ip1)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
|
||||
/* output buffer has refcount 1 */
|
||||
fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (buffer) == 1);
|
||||
|
@ -400,7 +400,7 @@ GST_START_TEST (basetransform_chain_ip2)
|
|||
res = gst_pad_alloc_buffer (trans->srcpad, 0, 20, NULL, &buffer);
|
||||
fail_unless (res == GST_FLOW_OK);
|
||||
fail_unless (buffer_alloc_pt1_called == TRUE);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
fail_unless (GST_BUFFER_CAPS (buffer) == NULL);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
|
@ -413,7 +413,7 @@ GST_START_TEST (basetransform_chain_ip2)
|
|||
res = gst_pad_alloc_buffer (trans->srcpad, 0, 20, caps, &buffer);
|
||||
fail_unless (res == GST_FLOW_OK);
|
||||
fail_unless (buffer_alloc_pt1_called == TRUE);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
fail_unless (GST_BUFFER_CAPS (buffer) == caps);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
|
@ -453,7 +453,7 @@ GST_START_TEST (basetransform_chain_ip2)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), caps));
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
|
@ -488,7 +488,7 @@ GST_START_TEST (basetransform_chain_ip2)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), caps));
|
||||
|
||||
/* output buffer has refcount 1 */
|
||||
|
@ -570,7 +570,7 @@ transform_caps_ct1 (GstBaseTransform * trans, GstPadDirection dir,
|
|||
|
||||
static gboolean
|
||||
transform_size_ct1 (GstBaseTransform * trans, GstPadDirection direction,
|
||||
GstCaps * caps, guint size, GstCaps * othercaps, guint * othersize)
|
||||
GstCaps * caps, gsize size, GstCaps * othercaps, gsize * othersize)
|
||||
{
|
||||
if (direction == GST_PAD_SINK) {
|
||||
*othersize = size * 2;
|
||||
|
@ -695,7 +695,7 @@ GST_START_TEST (basetransform_chain_ct1)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 40);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 40);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), outcaps));
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
|
@ -721,7 +721,7 @@ GST_START_TEST (basetransform_chain_ct1)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 40);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 40);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), outcaps));
|
||||
|
||||
/* output buffer has refcount 1 */
|
||||
|
@ -738,7 +738,7 @@ GST_START_TEST (basetransform_chain_ct1)
|
|||
* currently still calls the pad alloc for no reason and then throws away the
|
||||
* buffer. */
|
||||
fail_unless (buffer_alloc_ct1_called == FALSE);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 10);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 10);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
/* with caps buffer */
|
||||
|
@ -827,7 +827,7 @@ transform_caps_ct2 (GstBaseTransform * trans, GstPadDirection dir,
|
|||
|
||||
static gboolean
|
||||
transform_size_ct2 (GstBaseTransform * trans, GstPadDirection direction,
|
||||
GstCaps * caps, guint size, GstCaps * othercaps, guint * othersize)
|
||||
GstCaps * caps, gsize size, GstCaps * othercaps, gsize * othersize)
|
||||
{
|
||||
if (gst_caps_is_equal (caps, othercaps)) {
|
||||
*othersize = size;
|
||||
|
@ -983,7 +983,7 @@ GST_START_TEST (basetransform_chain_ct2)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), incaps));
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
|
@ -1009,7 +1009,7 @@ GST_START_TEST (basetransform_chain_ct2)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), incaps));
|
||||
|
||||
/* output buffer has refcount 1 */
|
||||
|
@ -1024,7 +1024,7 @@ GST_START_TEST (basetransform_chain_ct2)
|
|||
res = gst_pad_alloc_buffer (trans->srcpad, 0, 10, incaps, &buffer);
|
||||
fail_unless (res == GST_FLOW_OK);
|
||||
fail_unless (buffer_alloc_ct2_called == TRUE);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 10);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 10);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
/* with caps buffer */
|
||||
|
@ -1140,7 +1140,7 @@ GST_START_TEST (basetransform_chain_ct3)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), incaps));
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
|
@ -1164,7 +1164,7 @@ GST_START_TEST (basetransform_chain_ct3)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), incaps));
|
||||
|
||||
/* output buffer has refcount 1 */
|
||||
|
@ -1179,7 +1179,7 @@ GST_START_TEST (basetransform_chain_ct3)
|
|||
res = gst_pad_alloc_buffer (trans->srcpad, 0, 10, incaps, &buffer);
|
||||
fail_unless (res == GST_FLOW_OK);
|
||||
fail_unless (buffer_alloc_ct2_called == TRUE);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 10);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 10);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
/* with caps buffer */
|
||||
|
@ -1226,7 +1226,7 @@ GST_START_TEST (basetransform_chain_ct3)
|
|||
GST_DEBUG_OBJECT (trans, "received caps %" GST_PTR_FORMAT,
|
||||
GST_BUFFER_CAPS (buffer));
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), outcaps));
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
|
||||
/* output buffer has refcount 1 */
|
||||
fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (buffer) == 1);
|
||||
|
@ -1244,7 +1244,7 @@ GST_START_TEST (basetransform_chain_ct3)
|
|||
fail_unless (buffer_alloc_ct2_called == TRUE);
|
||||
/* FIXME a buffer alloc should never set caps */
|
||||
fail_unless (set_caps_ct2_called == FALSE);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 10);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 10);
|
||||
/* FIXME, ideally we want to reuse these caps */
|
||||
fail_unless (GST_BUFFER_CAPS (buffer) == incaps);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), incaps));
|
||||
|
@ -1267,7 +1267,7 @@ GST_START_TEST (basetransform_chain_ct3)
|
|||
|
||||
buffer = gst_test_trans_pop (trans);
|
||||
fail_unless (buffer != NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 20);
|
||||
fail_unless (gst_buffer_get_size (buffer) == 20);
|
||||
fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), outcaps));
|
||||
|
||||
/* output buffer has refcount 1 */
|
||||
|
|
Loading…
Reference in a new issue