From d82c8bd2aff0f10425da24c1b20043f3fd081dab Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 21 Mar 2011 18:13:55 +0100 Subject: [PATCH] memory: port code to new buffer data API --- docs/manual/advanced-dataaccess.xml | 25 ++- gst/gstbuffer.c | 35 +++- gst/gstbuffer.h | 3 + gst/gsttypefind.c | 2 +- gst/gsttypefind.h | 36 ++-- gst/gstutils.c | 12 +- gst/gstvalue.c | 46 +++-- libs/gst/base/gstadapter.c | 170 ++++++++++------ libs/gst/base/gstadapter.h | 33 +-- libs/gst/base/gstbasesink.c | 2 +- libs/gst/base/gstbasesrc.c | 2 +- libs/gst/base/gstbasetransform.c | 73 ++++--- libs/gst/base/gstbasetransform.h | 12 +- libs/gst/base/gstbitreader.c | 44 +--- libs/gst/base/gstbitreader.h | 15 -- libs/gst/base/gstbytereader.c | 44 +--- libs/gst/base/gstbytereader.h | 16 -- libs/gst/base/gstbytewriter.c | 61 +----- libs/gst/base/gstbytewriter.h | 2 - libs/gst/base/gstcollectpads.c | 55 +---- libs/gst/base/gstcollectpads.h | 2 - libs/gst/base/gsttypefindhelper.c | 93 +++++++-- libs/gst/base/gsttypefindhelper.h | 4 + libs/gst/check/gstcheck.c | 25 ++- libs/gst/dataprotocol/dataprotocol.c | 10 +- plugins/elements/gstcapsfilter.c | 4 +- plugins/elements/gstfakesink.c | 18 +- plugins/elements/gstfakesrc.c | 67 +++--- plugins/elements/gstfdsink.c | 26 ++- plugins/elements/gstfdsrc.c | 21 +- plugins/elements/gstfilesink.c | 7 +- plugins/elements/gstfilesrc.c | 24 ++- plugins/elements/gstidentity.c | 67 +++--- plugins/elements/gstmultiqueue.c | 2 +- plugins/elements/gstqueue.c | 6 +- plugins/elements/gstqueue2.c | 28 ++- plugins/elements/gsttee.c | 6 +- plugins/elements/gsttypefindelement.c | 283 ++++++++++++++------------ plugins/elements/gsttypefindelement.h | 5 +- tests/examples/adapter/adapter_test.c | 12 +- tools/gst-launch.c | 4 +- 41 files changed, 737 insertions(+), 665 deletions(-) diff --git a/docs/manual/advanced-dataaccess.xml b/docs/manual/advanced-dataaccess.xml index 0db6e3cdb1..60d1f7233e 100644 --- a/docs/manual/advanced-dataaccess.xml +++ b/docs/manual/advanced-dataaccess.xml @@ -56,17 +56,23 @@ cb_have_data (GstPad *pad, gpointer u_data) { gint x, y; - guint16 *data = (guint16 *) GST_BUFFER_DATA (buffer), t; + guint16 *data, *ptr, t; + gsize size; + + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE); + ptr = data; /* invert data */ for (y = 0; y < 288; y++) { for (x = 0; x < 384 / 2; x++) { - t = data[384 - 1 - x]; - data[384 - 1 - x] = data[x]; - data[x] = t; + t = ptr[384 - 1 - x]; + ptr[384 - 1 - x] = ptr[x]; + ptr[x] = t; } - data += 384; + ptr += 384; } + gst_buffer_unmap (buffer, data, size); + return TRUE; } @@ -282,11 +288,16 @@ cb_handoff (GstElement *fakesrc, gpointer user_data) { static gboolean white = FALSE; + gpointer data; + gsize size; + + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE); /* this makes the image black/white */ - memset (GST_BUFFER_DATA (buffer), white ? 0xff : 0x0, - GST_BUFFER_SIZE (buffer)); + memset (data, white ? 0xff : 0x0, size); white = !white; + + gst_buffer_unmap (buffer, data, size); } gint diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index e0192f2cbc..3e9c39646a 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -313,9 +313,10 @@ _gst_buffer_free (GstBuffer * buffer) /* call free_func if any */ if (info->free_func) info->free_func (meta, buffer); - /* and free the slice */ + next = walk->next; - g_slice_free (GstMetaItem, walk); + /* and free the slice */ + g_slice_free1 (ITEM_SIZE (info), walk); } /* free our data, unrefs the memory too */ @@ -525,6 +526,36 @@ gst_buffer_unmap (GstBuffer * buffer, gpointer data, gsize size) return result; } +void +gst_buffer_extract (GstBuffer * buffer, gsize offset, gpointer dest, gsize size) +{ + GPtrArray *arr = (GPtrArray *) buffer->memory; + gsize i, len; + guint8 *ptr = dest; + + len = arr->len; + + for (i = 0; i < len && size > 0; i++) { + guint8 *data; + gsize ssize, tocopy; + GstMemory *mem; + + 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); + size -= tocopy; + ptr += tocopy; + offset = 0; + } else { + offset -= tocopy; + } + gst_memory_unmap (mem, data, ssize); + } +} + /** * gst_buffer_get_caps: * @buffer: a #GstBuffer. diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h index 420c8fb60d..552cae1bf0 100644 --- a/gst/gstbuffer.h +++ b/gst/gstbuffer.h @@ -302,6 +302,9 @@ void gst_buffer_take_memory (GstBuffer *buffer, GstMemory *mem); GstMemory * gst_buffer_peek_memory (GstBuffer *buffer, guint idx); void gst_buffer_remove_memory (GstBuffer *buffer, guint idx); +void gst_buffer_extract (GstBuffer *buffer, gsize offset, + gpointer dest, gsize size); + gsize gst_buffer_get_size (GstBuffer *buffer); /* getting memory */ diff --git a/gst/gsttypefind.c b/gst/gsttypefind.c index e4254e19a7..62867a5a1b 100644 --- a/gst/gsttypefind.c +++ b/gst/gsttypefind.c @@ -127,7 +127,7 @@ gst_type_find_register (GstPlugin * plugin, const gchar * name, guint rank, * Returns: (transfer none) (array length=size): the requested data, or NULL * if that data is not available. */ -guint8 * +const guint8 * gst_type_find_peek (GstTypeFind * find, gint64 offset, guint size) { g_return_val_if_fail (find->peek != NULL, NULL); diff --git a/gst/gsttypefind.h b/gst/gsttypefind.h index 6e1f049786..036148c7a1 100644 --- a/gst/gsttypefind.h +++ b/gst/gsttypefind.h @@ -72,18 +72,18 @@ typedef enum { */ struct _GstTypeFind { /* private to the caller of the typefind function */ - guint8 * (* peek) (gpointer data, - gint64 offset, - guint size); + const guint8 * (* peek) (gpointer data, + gint64 offset, + guint size); - void (* suggest) (gpointer data, - guint probability, - const GstCaps * caps); + void (* suggest) (gpointer data, + guint probability, + const GstCaps * caps); - gpointer data; + gpointer data; /* optional */ - guint64 (* get_length) (gpointer data); + guint64 (* get_length) (gpointer data); /* */ gpointer _gst_reserved[GST_PADDING]; @@ -92,18 +92,18 @@ struct _GstTypeFind { GType gst_type_find_get_type (void); /* typefind function interface */ -guint8 * gst_type_find_peek (GstTypeFind * find, - gint64 offset, - guint size); +const guint8 * gst_type_find_peek (GstTypeFind * find, + gint64 offset, + guint size); -void gst_type_find_suggest (GstTypeFind * find, - guint probability, - const GstCaps * caps); +void gst_type_find_suggest (GstTypeFind * find, + guint probability, + const GstCaps * caps); -void gst_type_find_suggest_simple (GstTypeFind * find, - guint probability, - const char * media_type, - const char * fieldname, ...); +void gst_type_find_suggest_simple (GstTypeFind * find, + guint probability, + const char * media_type, + const char * fieldname, ...); guint64 gst_type_find_get_length (GstTypeFind * find); diff --git a/gst/gstutils.c b/gst/gstutils.c index d42b5d1497..a674e7121a 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -2678,9 +2678,13 @@ GstBuffer * gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2) { GstBuffer *result; + gsize size1, size2; + + size1 = gst_buffer_get_size (buf1); + size2 = gst_buffer_get_size (buf2); /* we're just a specific case of the more general gst_buffer_span() */ - result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size); + result = gst_buffer_span (buf1, 0, buf2, size1 + size2); return result; } @@ -2708,8 +2712,12 @@ GstBuffer * gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2) { GstBuffer *result; + gsize size1, size2; - result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size); + size1 = gst_buffer_get_size (buf1); + size2 = gst_buffer_get_size (buf2); + + result = gst_buffer_span (buf1, 0, buf2, size1 + size2); gst_buffer_unref (buf1); gst_buffer_unref (buf2); diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 10fe5a9902..a61d4d961a 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -1720,20 +1720,33 @@ gst_value_deserialize_structure (GValue * dest, const gchar * s) static gint gst_value_compare_buffer (const GValue * value1, const GValue * value2) { - GstBuffer *buf1 = GST_BUFFER_CAST (g_value_get_boxed (value1)); - GstBuffer *buf2 = GST_BUFFER_CAST (g_value_get_boxed (value2)); + GstBuffer *buf1 = gst_value_get_buffer (value1); + GstBuffer *buf2 = gst_value_get_buffer (value2); + gsize size1, size2; + gpointer data1, data2; + gint result = GST_VALUE_UNORDERED; - if (GST_BUFFER_SIZE (buf1) != GST_BUFFER_SIZE (buf2)) + size1 = gst_buffer_get_size (buf1); + size2 = gst_buffer_get_size (buf2); + + if (size1 != size2) return GST_VALUE_UNORDERED; - if (GST_BUFFER_SIZE (buf1) == 0) - return GST_VALUE_EQUAL; - g_assert (GST_BUFFER_DATA (buf1)); - g_assert (GST_BUFFER_DATA (buf2)); - if (memcmp (GST_BUFFER_DATA (buf1), GST_BUFFER_DATA (buf2), - GST_BUFFER_SIZE (buf1)) == 0) + + if (size1 == 0) return GST_VALUE_EQUAL; - return GST_VALUE_UNORDERED; + data1 = gst_buffer_map (buf1, &size1, NULL, GST_MAP_READ); + data2 = gst_buffer_map (buf2, &size2, NULL, GST_MAP_READ); + g_assert (data1); + g_assert (data2); + + if (memcmp (data1, data2, size1) == 0) + result = GST_VALUE_EQUAL; + + gst_buffer_unmap (buf2, data2, size2); + gst_buffer_unmap (buf1, data1, size1); + + return result; } static gchar * @@ -1741,7 +1754,7 @@ gst_value_serialize_buffer (const GValue * value) { guint8 *data; gint i; - gint size; + gsize size; gchar *string; GstBuffer *buffer; @@ -1749,8 +1762,7 @@ gst_value_serialize_buffer (const GValue * value) if (buffer == NULL) return NULL; - data = GST_BUFFER_DATA (buffer); - size = GST_BUFFER_SIZE (buffer); + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); string = g_malloc (size * 2 + 1); for (i = 0; i < size; i++) { @@ -1758,6 +1770,8 @@ gst_value_serialize_buffer (const GValue * value) } string[size * 2] = 0; + gst_buffer_unmap (buffer, data, size); + return string; } @@ -1769,13 +1783,15 @@ gst_value_deserialize_buffer (GValue * dest, const gchar * s) gchar ts[3]; guint8 *data; gint i; + gsize size; len = strlen (s); if (len & 1) goto wrong_length; buffer = gst_buffer_new_and_alloc (len / 2); - data = GST_BUFFER_DATA (buffer); + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE); + for (i = 0; i < len / 2; i++) { if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1])) goto wrong_char; @@ -1786,6 +1802,7 @@ gst_value_deserialize_buffer (GValue * dest, const gchar * s) data[i] = (guint8) strtoul (ts, NULL, 16); } + gst_buffer_unmap (buffer, data, size); gst_value_take_buffer (dest, buffer); @@ -1799,6 +1816,7 @@ wrong_length: wrong_char: { gst_buffer_unref (buffer); + gst_buffer_unmap (buffer, data, size); return FALSE; } } diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c index 75944a902a..898cc1d487 100644 --- a/libs/gst/base/gstadapter.c +++ b/libs/gst/base/gstadapter.c @@ -116,6 +116,8 @@ /* default size for the assembled data buffer */ #define DEFAULT_SIZE 4096 +static void gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush); + GST_DEBUG_CATEGORY_STATIC (gst_adapter_debug); #define GST_CAT_DEFAULT gst_adapter_debug @@ -127,8 +129,11 @@ struct _GstAdapterPrivate GstClockTime timestamp; guint64 distance; - guint scan_offset; + gsize scan_offset; GSList *scan_entry; + + gpointer cdata; + gsize csize; }; #define _do_init(thing) \ @@ -239,12 +244,12 @@ update_timestamp (GstAdapter * adapter, GstBuffer * buf) /* copy data into @dest, skipping @skip bytes from the head buffers */ static void -copy_into_unchecked (GstAdapter * adapter, guint8 * dest, guint skip, - guint size) +copy_into_unchecked (GstAdapter * adapter, guint8 * dest, gsize skip, + gsize size) { GSList *g; GstBuffer *buf; - guint bsize, csize; + gsize bsize, csize; /* first step, do skipping */ /* we might well be copying where we were scanning */ @@ -255,16 +260,16 @@ copy_into_unchecked (GstAdapter * adapter, guint8 * dest, guint skip, g = adapter->buflist; } buf = g->data; - bsize = GST_BUFFER_SIZE (buf); + bsize = gst_buffer_get_size (buf); while (G_UNLIKELY (skip >= bsize)) { skip -= bsize; g = g_slist_next (g); buf = g->data; - bsize = GST_BUFFER_SIZE (buf); + bsize = gst_buffer_get_size (buf); } /* copy partial buffer */ csize = MIN (bsize - skip, size); - memcpy (dest, GST_BUFFER_DATA (buf) + skip, csize); + gst_buffer_extract (buf, skip, dest, csize); size -= csize; dest += csize; @@ -272,10 +277,10 @@ copy_into_unchecked (GstAdapter * adapter, guint8 * dest, guint skip, while (size > 0) { g = g_slist_next (g); buf = g->data; - bsize = GST_BUFFER_SIZE (buf); + bsize = gst_buffer_get_size (buf); if (G_LIKELY (bsize > 0)) { csize = MIN (bsize, size); - memcpy (dest, GST_BUFFER_DATA (buf), csize); + gst_buffer_extract (buf, 0, dest, csize); size -= csize; dest += csize; } @@ -293,12 +298,12 @@ copy_into_unchecked (GstAdapter * adapter, guint8 * dest, guint skip, void gst_adapter_push (GstAdapter * adapter, GstBuffer * buf) { - guint size; + gsize size; g_return_if_fail (GST_IS_ADAPTER (adapter)); g_return_if_fail (GST_IS_BUFFER (buf)); - size = GST_BUFFER_SIZE (buf); + size = gst_buffer_get_size (buf); adapter->size += size; /* Note: merging buffers at this point is premature. */ @@ -322,11 +327,12 @@ gst_adapter_push (GstAdapter * adapter, GstBuffer * buf) * Returns TRUE if it managed to merge anything. */ static gboolean -gst_adapter_try_to_merge_up (GstAdapter * adapter, guint size) +gst_adapter_try_to_merge_up (GstAdapter * adapter, gsize size) { GstBuffer *cur, *head; GSList *g; gboolean ret = FALSE; + gsize hsize; g = adapter->buflist; if (g == NULL) @@ -338,8 +344,9 @@ gst_adapter_try_to_merge_up (GstAdapter * adapter, guint size) /* How large do we want our head buffer? The requested size, plus whatever's * been skipped already */ size += adapter->skip; + hsize = gst_buffer_get_size (head); - while (g != NULL && GST_BUFFER_SIZE (head) < size) { + while (g != NULL && hsize < size) { cur = g->data; if (!gst_buffer_is_span_fast (head, cur)) return ret; @@ -347,9 +354,10 @@ gst_adapter_try_to_merge_up (GstAdapter * adapter, guint size) /* Merge the head buffer and the next in line */ GST_LOG_OBJECT (adapter, "Merging buffers of size %u & %u in search of target %u", - GST_BUFFER_SIZE (head), GST_BUFFER_SIZE (cur), size); + hsize, gst_buffer_get_size (cur), size); head = gst_buffer_join (head, cur); + hsize = gst_buffer_get_size (head); ret = TRUE; /* Delete the front list item, and store our new buffer in the 2nd list @@ -390,11 +398,11 @@ gst_adapter_try_to_merge_up (GstAdapter * adapter, guint size) * @size bytes of data, or NULL */ const guint8 * -gst_adapter_peek (GstAdapter * adapter, guint size) +gst_adapter_map (GstAdapter * adapter, gsize size) { GstBuffer *cur; - guint skip; - guint toreuse, tocopy; + gsize skip, csize; + gsize toreuse, tocopy; guint8 *data; g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL); @@ -410,20 +418,20 @@ gst_adapter_peek (GstAdapter * adapter, guint size) if (adapter->assembled_len >= size) return adapter->assembled_data; - /* our head buffer has enough data left, return it */ - cur = adapter->buflist->data; - skip = adapter->skip; - if (GST_BUFFER_SIZE (cur) >= size + skip) - return GST_BUFFER_DATA (cur) + skip; - - /* We may be able to efficiently merge buffers in our pool to - * gather a big enough chunk to return it from the head buffer directly */ - if (gst_adapter_try_to_merge_up (adapter, size)) { - /* Merged something! Check if there's enough avail now */ + do { cur = adapter->buflist->data; - if (GST_BUFFER_SIZE (cur) >= size + skip) - return GST_BUFFER_DATA (cur) + skip; - } + skip = adapter->skip; + + csize = gst_buffer_get_size (cur); + if (csize >= size + skip) { + data = gst_buffer_map (cur, &csize, NULL, GST_META_MAP_READ); + adapter->priv->cdata = data; + adapter->priv->csize = csize; + return data + skip; + } + /* We may be able to efficiently merge buffers in our pool to + * gather a big enough chunk to return it from the head buffer directly */ + } while (gst_adapter_try_to_merge_up (adapter, size)); /* see how much data we can reuse from the assembled memory and how much * we need to copy */ @@ -457,6 +465,29 @@ gst_adapter_peek (GstAdapter * adapter, guint size) return adapter->assembled_data; } +/** + * gst_adapter_unmap: + * @adapter: a #GstAdapter + * @flush: the amount of bytes to flush + * + * Releases the memory obtained with the last gst_adapter_map() and flushes + * @size bytes from the adapter. + */ +void +gst_adapter_unmap (GstAdapter * adapter, gsize flush) +{ + g_return_if_fail (GST_IS_ADAPTER (adapter)); + + if (adapter->priv->cdata) { + GstBuffer *cur = adapter->buflist->data; + gst_buffer_unmap (cur, adapter->priv->cdata, adapter->priv->csize); + adapter->priv->cdata = NULL; + } + + if (flush) + gst_adapter_flush_unchecked (adapter, flush); +} + /** * gst_adapter_copy: * @adapter: a #GstAdapter @@ -474,7 +505,7 @@ gst_adapter_peek (GstAdapter * adapter, guint size) * Since: 0.10.12 */ void -gst_adapter_copy (GstAdapter * adapter, guint8 * dest, guint offset, guint size) +gst_adapter_copy (GstAdapter * adapter, guint8 * dest, gsize offset, gsize size) { g_return_if_fail (GST_IS_ADAPTER (adapter)); g_return_if_fail (size > 0); @@ -494,10 +525,10 @@ gst_adapter_copy (GstAdapter * adapter, guint8 * dest, guint offset, guint size) * See also: gst_adapter_peek(). */ static void -gst_adapter_flush_unchecked (GstAdapter * adapter, guint flush) +gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush) { GstBuffer *cur; - guint size; + gsize size; GstAdapterPrivate *priv; GSList *g; @@ -516,7 +547,7 @@ gst_adapter_flush_unchecked (GstAdapter * adapter, guint flush) g = adapter->buflist; cur = g->data; - size = GST_BUFFER_SIZE (cur); + size = gst_buffer_get_size (cur); while (flush >= size) { /* can skip whole buffer */ GST_LOG_OBJECT (adapter, "flushing out head buffer"); @@ -534,7 +565,7 @@ gst_adapter_flush_unchecked (GstAdapter * adapter, guint flush) /* there is a new head buffer, update the timestamp */ cur = g->data; update_timestamp (adapter, cur); - size = GST_BUFFER_SIZE (cur); + size = gst_buffer_get_size (cur); } adapter->buflist = g; /* account for the remaining bytes */ @@ -546,7 +577,7 @@ gst_adapter_flush_unchecked (GstAdapter * adapter, guint flush) } void -gst_adapter_flush (GstAdapter * adapter, guint flush) +gst_adapter_flush (GstAdapter * adapter, gsize flush) { g_return_if_fail (GST_IS_ADAPTER (adapter)); g_return_if_fail (flush <= adapter->size); @@ -560,10 +591,10 @@ gst_adapter_flush (GstAdapter * adapter, guint flush) /* internal function, nbytes should be flushed after calling this function */ static guint8 * -gst_adapter_take_internal (GstAdapter * adapter, guint nbytes) +gst_adapter_take_internal (GstAdapter * adapter, gsize nbytes) { guint8 *data; - guint toreuse, tocopy; + gsize toreuse, tocopy; /* see how much data we can reuse from the assembled memory and how much * we need to copy */ @@ -615,7 +646,7 @@ gst_adapter_take_internal (GstAdapter * adapter, guint nbytes) * #NULL if @nbytes bytes are not available */ guint8 * -gst_adapter_take (GstAdapter * adapter, guint nbytes) +gst_adapter_take (GstAdapter * adapter, gsize nbytes) { guint8 *data; @@ -656,11 +687,11 @@ gst_adapter_take (GstAdapter * adapter, guint nbytes) * Since: 0.10.6 */ GstBuffer * -gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes) +gst_adapter_take_buffer (GstAdapter * adapter, gsize nbytes) { GstBuffer *buffer; GstBuffer *cur; - guint hsize, skip; + gsize hsize, skip; guint8 *data; g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL); @@ -676,7 +707,7 @@ gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes) cur = adapter->buflist->data; skip = adapter->skip; - hsize = GST_BUFFER_SIZE (cur); + hsize = gst_buffer_get_size (cur); /* our head buffer has enough data left, return it */ if (skip == 0 && hsize == nbytes) { @@ -694,7 +725,7 @@ gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes) if (gst_adapter_try_to_merge_up (adapter, nbytes)) { /* Merged something, let's try again for sub-buffering */ cur = adapter->buflist->data; - if (GST_BUFFER_SIZE (cur) >= nbytes + skip) { + if (gst_buffer_get_size (cur) >= nbytes + skip) { GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer", nbytes); buffer = gst_buffer_create_sub (cur, skip, nbytes); @@ -705,9 +736,8 @@ gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes) data = gst_adapter_take_internal (adapter, nbytes); buffer = gst_buffer_new (); - GST_BUFFER_SIZE (buffer) = nbytes; - GST_BUFFER_DATA (buffer) = data; - GST_BUFFER_MALLOCDATA (buffer) = data; + gst_buffer_take_memory (buffer, gst_memory_new_wrapped (data, g_free, nbytes, + 0, nbytes)); done: gst_adapter_flush_unchecked (adapter, nbytes); @@ -735,11 +765,11 @@ done: * Since: 0.10.31 */ GList * -gst_adapter_take_list (GstAdapter * adapter, guint nbytes) +gst_adapter_take_list (GstAdapter * adapter, gsize nbytes) { GList *result = NULL, *tail = NULL; GstBuffer *cur; - guint hsize, skip; + gsize hsize, skip; g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL); g_return_val_if_fail (nbytes <= adapter->size, NULL); @@ -749,7 +779,7 @@ gst_adapter_take_list (GstAdapter * adapter, guint nbytes) while (nbytes > 0) { cur = adapter->buflist->data; skip = adapter->skip; - hsize = MIN (nbytes, GST_BUFFER_SIZE (cur) - skip); + hsize = MIN (nbytes, gst_buffer_get_size (cur) - skip); cur = gst_adapter_take_buffer (adapter, hsize); @@ -774,7 +804,7 @@ gst_adapter_take_list (GstAdapter * adapter, guint nbytes) * * Returns: number of bytes available in @adapter */ -guint +gsize gst_adapter_available (GstAdapter * adapter) { g_return_val_if_fail (GST_IS_ADAPTER (adapter), 0); @@ -793,11 +823,11 @@ gst_adapter_available (GstAdapter * adapter) * Returns: number of bytes that are available in @adapter without expensive * operations */ -guint +gsize gst_adapter_available_fast (GstAdapter * adapter) { GstBuffer *cur; - guint size; + gsize size; GSList *g; g_return_val_if_fail (GST_IS_ADAPTER (adapter), 0); @@ -814,7 +844,7 @@ gst_adapter_available_fast (GstAdapter * adapter) g = adapter->buflist; while (TRUE) { cur = g->data; - size = GST_BUFFER_SIZE (cur); + size = gst_buffer_get_size (cur); if (size != 0) break; g = g_slist_next (g); @@ -878,14 +908,14 @@ gst_adapter_prev_timestamp (GstAdapter * adapter, guint64 * distance) * * Since: 0.10.30 */ -guint +gsize gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask, - guint32 pattern, guint offset, guint size, guint32 * value) + guint32 pattern, gsize offset, gsize size, guint32 * value) { GSList *g; - guint skip, bsize, i; + gsize skip, bsize, osize, i; guint32 state; - guint8 *bdata; + guint8 *bdata, *odata; GstBuffer *buf; g_return_val_if_fail (size > 0, -1); @@ -909,18 +939,20 @@ gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask, adapter->priv->scan_entry = NULL; } buf = g->data; - bsize = GST_BUFFER_SIZE (buf); + bsize = gst_buffer_get_size (buf); while (G_UNLIKELY (skip >= bsize)) { skip -= bsize; g = g_slist_next (g); adapter->priv->scan_offset += bsize; adapter->priv->scan_entry = g; buf = g->data; - bsize = GST_BUFFER_SIZE (buf); + bsize = gst_buffer_get_size (buf); } /* get the data now */ - bsize -= skip; - bdata = GST_BUFFER_DATA (buf) + skip; + odata = gst_buffer_map (buf, &osize, NULL, GST_MAP_READ); + + bdata = odata + skip; + bsize = osize - skip; skip = 0; /* set the state to something that does not match */ @@ -937,6 +969,7 @@ gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask, if (G_LIKELY (skip + i >= 3)) { if (G_LIKELY (value)) *value = state; + gst_buffer_unmap (buf, odata, osize); return offset + skip + i - 3; } } @@ -948,13 +981,18 @@ gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask, /* nothing found yet, go to next buffer */ skip += bsize; g = g_slist_next (g); - adapter->priv->scan_offset += GST_BUFFER_SIZE (buf); + adapter->priv->scan_offset += osize; adapter->priv->scan_entry = g; + gst_buffer_unmap (buf, odata, osize); buf = g->data; - bsize = GST_BUFFER_SIZE (buf); - bdata = GST_BUFFER_DATA (buf); + + odata = gst_buffer_map (buf, &osize, NULL, GST_MAP_READ); + bsize = osize; + bdata = odata; } while (TRUE); + gst_buffer_unmap (buf, odata, osize); + /* nothing found */ return -1; } @@ -1005,9 +1043,9 @@ gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask, * * Since: 0.10.24 */ -guint +gsize gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask, - guint32 pattern, guint offset, guint size) + guint32 pattern, gsize offset, gsize size) { return gst_adapter_masked_scan_uint32_peek (adapter, mask, pattern, offset, size, NULL); diff --git a/libs/gst/base/gstadapter.h b/libs/gst/base/gstadapter.h index 290dfbec63..aa6730b6c2 100644 --- a/libs/gst/base/gstadapter.h +++ b/libs/gst/base/gstadapter.h @@ -53,13 +53,13 @@ struct _GstAdapter { /*< private >*/ GSList * buflist; GSList * buflist_end; - guint size; - guint skip; + gsize size; + gsize skip; /* we keep state of assembled pieces */ guint8 * assembled_data; - guint assembled_size; - guint assembled_len; + gsize assembled_size; + gsize assembled_len; GstAdapterPrivate *priv; @@ -79,23 +79,24 @@ GstAdapter * gst_adapter_new (void); void gst_adapter_clear (GstAdapter *adapter); void gst_adapter_push (GstAdapter *adapter, GstBuffer* buf); -const guint8 * gst_adapter_peek (GstAdapter *adapter, guint size); +const guint8 * gst_adapter_map (GstAdapter *adapter, gsize size); +void gst_adapter_unmap (GstAdapter *adapter, gsize flush); void gst_adapter_copy (GstAdapter *adapter, guint8 *dest, - guint offset, guint size); -void gst_adapter_flush (GstAdapter *adapter, guint flush); -guint8* gst_adapter_take (GstAdapter *adapter, guint nbytes); -GstBuffer* gst_adapter_take_buffer (GstAdapter *adapter, guint nbytes); -GList* gst_adapter_take_list (GstAdapter *adapter, guint nbytes); -guint gst_adapter_available (GstAdapter *adapter); -guint gst_adapter_available_fast (GstAdapter *adapter); + gsize offset, gsize size); +void gst_adapter_flush (GstAdapter *adapter, gsize flush); +guint8* gst_adapter_take (GstAdapter *adapter, gsize nbytes); +GstBuffer* gst_adapter_take_buffer (GstAdapter *adapter, gsize nbytes); +GList* gst_adapter_take_list (GstAdapter *adapter, gsize nbytes); +gsize gst_adapter_available (GstAdapter *adapter); +gsize gst_adapter_available_fast (GstAdapter *adapter); GstClockTime gst_adapter_prev_timestamp (GstAdapter *adapter, guint64 *distance); -guint gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask, - guint32 pattern, guint offset, guint size); +gsize gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask, + guint32 pattern, gsize offset, gsize size); -guint gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask, - guint32 pattern, guint offset, guint size, guint32 * value); +gsize gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask, + guint32 pattern, gsize offset, gsize size, guint32 * value); G_END_DECLS diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index 8676c61e5f..ebd1d06dc6 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -4088,7 +4088,7 @@ gst_base_sink_loop (GstPad * pad) if (G_UNLIKELY (buf == NULL)) goto no_buffer; - offset += GST_BUFFER_SIZE (buf); + offset += gst_buffer_get_size (buf); gst_segment_set_last_stop (&basesink->segment, GST_FORMAT_BYTES, offset); diff --git a/libs/gst/base/gstbasesrc.c b/libs/gst/base/gstbasesrc.c index e678549dcf..174ebe3690 100644 --- a/libs/gst/base/gstbasesrc.c +++ b/libs/gst/base/gstbasesrc.c @@ -2435,7 +2435,7 @@ gst_base_src_loop (GstPad * pad) switch (src->segment.format) { case GST_FORMAT_BYTES: { - guint bufsize = GST_BUFFER_SIZE (buf); + guint bufsize = gst_buffer_get_size (buf); /* we subtracted above for negative rates */ if (src->segment.rate >= 0.0) diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c index 43e9b47dab..8d7bafaeb5 100644 --- a/libs/gst/base/gstbasetransform.c +++ b/libs/gst/base/gstbasetransform.c @@ -271,7 +271,7 @@ struct _GstBaseTransformPrivate /* upstream caps and size suggestions */ GstCaps *sink_suggest; - guint size_suggest; + gsize size_suggest; gboolean suggest_pending; gboolean reconfigure; @@ -329,7 +329,7 @@ static gboolean gst_base_transform_sink_activate_push (GstPad * pad, static gboolean gst_base_transform_activate (GstBaseTransform * trans, gboolean active); static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans, - GstCaps * caps, guint * size); + GstCaps * caps, gsize * size); static gboolean gst_base_transform_src_event (GstPad * pad, GstEvent * event); static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans, @@ -566,9 +566,9 @@ gst_base_transform_transform_caps (GstBaseTransform * trans, static gboolean gst_base_transform_transform_size (GstBaseTransform * trans, GstPadDirection direction, GstCaps * caps, - guint size, GstCaps * othercaps, guint * othersize) + gsize size, GstCaps * othercaps, gsize * othersize) { - guint inunitsize, outunitsize, units; + gsize inunitsize, outunitsize, units; GstBaseTransformClass *klass; gboolean ret; @@ -628,8 +628,8 @@ no_multiple: { GST_DEBUG_OBJECT (trans, "Size %u is not a multiple of unit size %u", size, inunitsize); - g_warning ("%s: size %u is not a multiple of unit size %u", - GST_ELEMENT_NAME (trans), size, inunitsize); + g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %" + G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize); return FALSE; } no_out_size: @@ -1272,7 +1272,7 @@ gst_base_transform_query_type (GstPad * pad) } static void -compute_upstream_suggestion (GstBaseTransform * trans, guint expsize, +compute_upstream_suggestion (GstBaseTransform * trans, gsize expsize, GstCaps * caps) { GstCaps *othercaps; @@ -1290,7 +1290,7 @@ compute_upstream_suggestion (GstBaseTransform * trans, guint expsize, * because it should have checked if we could handle these caps. We can * simply ignore these caps and produce a buffer with our original caps. */ } else { - guint size_suggest; + gsize size_suggest; GST_DEBUG_OBJECT (trans, "getting size of suggestion"); @@ -1331,7 +1331,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, GstBaseTransformClass *bclass; GstBaseTransformPrivate *priv; GstFlowReturn ret = GST_FLOW_OK; - guint outsize, newsize, expsize; + gsize insize, outsize, newsize, expsize; gboolean discard, setcaps, copymeta; GstCaps *incaps, *oldcaps, *newcaps, *outcaps; @@ -1341,13 +1341,15 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, *out_buf = NULL; + insize = gst_buffer_get_size (in_buf); + /* figure out how to allocate a buffer based on the current configuration */ if (trans->passthrough) { GST_DEBUG_OBJECT (trans, "doing passthrough alloc"); /* passthrough, we don't really need to call pad alloc but we still need to * in order to get upstream negotiation. The output size is the same as the * input size. */ - outsize = GST_BUFFER_SIZE (in_buf); + outsize = insize; /* we always alloc and discard here */ discard = TRUE; } else { @@ -1357,7 +1359,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, if (want_in_place) { GST_DEBUG_OBJECT (trans, "doing inplace alloc"); /* we alloc a buffer of the same size as the input */ - outsize = GST_BUFFER_SIZE (in_buf); + outsize = insize; /* only discard it when the input was not writable, otherwise, we reuse * the input buffer. */ discard = gst_buffer_is_writable (in_buf); @@ -1367,8 +1369,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, /* copy transform, figure out the output size */ if (!gst_base_transform_transform_size (trans, GST_PAD_SINK, GST_PAD_CAPS (trans->sinkpad), - GST_BUFFER_SIZE (in_buf), GST_PAD_CAPS (trans->srcpad), - &outsize)) { + insize, GST_PAD_CAPS (trans->srcpad), &outsize)) { goto unknown_size; } /* never discard this buffer, we need it for storing the output */ @@ -1427,7 +1428,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, /* check if we got different caps on this new output buffer */ newcaps = GST_BUFFER_CAPS (*out_buf); - newsize = GST_BUFFER_SIZE (*out_buf); + newsize = gst_buffer_get_size (*out_buf); if (newcaps && !gst_caps_is_equal (newcaps, oldcaps)) { GstCaps *othercaps; @@ -1446,7 +1447,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, GST_DEBUG_OBJECT (trans, "cannot perform transform on current buffer"); gst_base_transform_transform_size (trans, - GST_PAD_SINK, incaps, GST_BUFFER_SIZE (in_buf), newcaps, &expsize); + GST_PAD_SINK, incaps, insize, newcaps, &expsize); compute_upstream_suggestion (trans, expsize, newcaps); @@ -1471,7 +1472,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, * expected size here, we will check the size if we are going to use the * buffer later on. */ gst_base_transform_transform_size (trans, - GST_PAD_SINK, incaps, GST_BUFFER_SIZE (in_buf), newcaps, &expsize); + GST_PAD_SINK, incaps, insize, newcaps, &expsize); if (can_convert) { GST_DEBUG_OBJECT (trans, "reconfigure transform for current buffer"); @@ -1537,8 +1538,8 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, outsize); /* no valid buffer yet, make one, metadata is writable */ *out_buf = gst_buffer_new_and_alloc (outsize); - gst_buffer_copy_metadata (*out_buf, in_buf, - GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS); + gst_buffer_copy_into (*out_buf, in_buf, + GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, 0); } else { GST_DEBUG_OBJECT (trans, "reuse input buffer"); *out_buf = in_buf; @@ -1598,7 +1599,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, if (!gst_buffer_is_metadata_writable (*out_buf)) { GST_DEBUG_OBJECT (trans, "buffer metadata %p not writable", *out_buf); if (in_buf == *out_buf) - *out_buf = gst_buffer_create_sub (in_buf, 0, GST_BUFFER_SIZE (in_buf)); + *out_buf = gst_buffer_create_sub (in_buf, 0, insize); else *out_buf = gst_buffer_make_metadata_writable (*out_buf); } @@ -1606,8 +1607,8 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, if (setcaps) gst_buffer_set_caps (*out_buf, outcaps); if (copymeta) - gst_buffer_copy_metadata (*out_buf, in_buf, - GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS); + gst_buffer_copy_into (*out_buf, in_buf, + GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, 0); /* clear the GAP flag when the subclass does not understand it */ if (!trans->priv->gap_aware) GST_BUFFER_FLAG_UNSET (*out_buf, GST_BUFFER_FLAG_GAP); @@ -1654,7 +1655,7 @@ failed_configure: */ static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps, - guint * size) + gsize * size) { gboolean res = FALSE; GstBaseTransformClass *bclass; @@ -1711,7 +1712,7 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size, GstFlowReturn res; gboolean proxy, suggest, same_caps; GstCaps *sink_suggest = NULL; - guint size_suggest; + gsize size_suggest; trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad)); klass = GST_BASE_TRANSFORM_GET_CLASS (trans); @@ -2139,6 +2140,7 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf, GstClockTime running_time; GstClockTime timestamp; GstCaps *incaps; + gsize insize; bclass = GST_BASE_TRANSFORM_GET_CLASS (trans); @@ -2158,13 +2160,16 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf, } } + insize = gst_buffer_get_size (inbuf); + if (GST_BUFFER_OFFSET_IS_VALID (inbuf)) - GST_DEBUG_OBJECT (trans, "handling buffer %p of size %d and offset %" - G_GUINT64_FORMAT, inbuf, GST_BUFFER_SIZE (inbuf), - GST_BUFFER_OFFSET (inbuf)); + GST_DEBUG_OBJECT (trans, + "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %" + G_GUINT64_FORMAT, inbuf, insize, GST_BUFFER_OFFSET (inbuf)); else - GST_DEBUG_OBJECT (trans, "handling buffer %p of size %d and offset NONE", - inbuf, GST_BUFFER_SIZE (inbuf)); + GST_DEBUG_OBJECT (trans, + "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf, + insize); /* Don't allow buffer handling before negotiation, except in passthrough mode * or if the class doesn't implement a set_caps function (in which case it doesn't @@ -2266,16 +2271,20 @@ no_qos: if (inbuf != *outbuf) { guint8 *indata, *outdata; + gsize insize, outsize; /* Different buffer. The data can still be the same when we are dealing * with subbuffers of the same buffer. Note that because of the FIXME in * prepare_output_buffer() we have decreased the refcounts of inbuf and * outbuf to keep them writable */ - indata = GST_BUFFER_DATA (inbuf); - outdata = GST_BUFFER_DATA (*outbuf); + indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ); + outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE); if (indata != outdata) - memcpy (outdata, indata, GST_BUFFER_SIZE (inbuf)); + memcpy (outdata, indata, insize); + + gst_buffer_unmap (inbuf, indata, insize); + gst_buffer_unmap (*outbuf, outdata, outsize); } ret = bclass->transform_ip (trans, *outbuf); } else { @@ -2828,7 +2837,7 @@ gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware) */ void gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps, - guint size) + gsize size) { g_return_if_fail (GST_IS_BASE_TRANSFORM (trans)); diff --git a/libs/gst/base/gstbasetransform.h b/libs/gst/base/gstbasetransform.h index 85cf508e94..eaa56d3287 100644 --- a/libs/gst/base/gstbasetransform.h +++ b/libs/gst/base/gstbasetransform.h @@ -119,9 +119,9 @@ struct _GstBaseTransform { gboolean always_in_place; GstCaps *cache_caps1; - guint cache_caps1_size; + gsize cache_caps1_size; GstCaps *cache_caps2; - guint cache_caps2_size; + gsize cache_caps2_size; gboolean have_same_caps; gboolean delay_configure; @@ -218,11 +218,11 @@ struct _GstBaseTransformClass { gboolean (*transform_size) (GstBaseTransform *trans, GstPadDirection direction, - GstCaps *caps, guint size, - GstCaps *othercaps, guint *othersize); + GstCaps *caps, gsize size, + GstCaps *othercaps, gsize *othersize); gboolean (*get_unit_size) (GstBaseTransform *trans, GstCaps *caps, - guint *size); + gsize *size); gboolean (*start) (GstBaseTransform *trans); gboolean (*stop) (GstBaseTransform *trans); @@ -266,7 +266,7 @@ void gst_base_transform_set_gap_aware (GstBaseTransform *trans, gboolean gap_aware); void gst_base_transform_suggest (GstBaseTransform *trans, - GstCaps *caps, guint size); + GstCaps *caps, gsize size); void gst_base_transform_reconfigure (GstBaseTransform *trans); G_END_DECLS diff --git a/libs/gst/base/gstbitreader.c b/libs/gst/base/gstbitreader.c index a4393992cb..ee369cb509 100644 --- a/libs/gst/base/gstbitreader.c +++ b/libs/gst/base/gstbitreader.c @@ -60,34 +60,12 @@ gst_bit_reader_new (const guint8 * data, guint size) return ret; } -/** - * gst_bit_reader_new_from_buffer: - * @buffer: Buffer from which the #GstBitReader should read - * - * Create a new #GstBitReader instance, which will read from the - * #GstBuffer @buffer. - * - * Free-function: gst_bit_reader_free - * - * Returns: (transfer full): a new #GstBitReader instance - * - * Since: 0.10.22 - */ -GstBitReader * -gst_bit_reader_new_from_buffer (const GstBuffer * buffer) -{ - g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL); - - return gst_bit_reader_new (GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer)); -} - /** * gst_bit_reader_free: * @reader: (in) (transfer full): a #GstBitReader instance * * Frees a #GstBitReader instance, which was previously allocated by - * gst_bit_reader_new() or gst_bit_reader_new_from_buffer(). + * gst_bit_reader_new(). * * Since: 0.10.22 */ @@ -120,26 +98,6 @@ gst_bit_reader_init (GstBitReader * reader, const guint8 * data, guint size) reader->byte = reader->bit = 0; } -/** - * gst_bit_reader_init_from_buffer: - * @reader: a #GstBitReader instance - * @buffer: (transfer none): Buffer from which the #GstBitReader should read - * - * Initializes a #GstBitReader instance to read from @buffer. This function - * can be called on already initialized instances. - * - * Since: 0.10.22 - */ -void -gst_bit_reader_init_from_buffer (GstBitReader * reader, - const GstBuffer * buffer) -{ - g_return_if_fail (GST_IS_BUFFER (buffer)); - - gst_bit_reader_init (reader, GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer)); -} - /** * gst_bit_reader_set_pos: * @reader: a #GstBitReader instance diff --git a/libs/gst/base/gstbitreader.h b/libs/gst/base/gstbitreader.h index b5c3935e7e..e42e3bfd9e 100644 --- a/libs/gst/base/gstbitreader.h +++ b/libs/gst/base/gstbitreader.h @@ -47,11 +47,9 @@ typedef struct { } GstBitReader; GstBitReader * gst_bit_reader_new (const guint8 *data, guint size); -GstBitReader * gst_bit_reader_new_from_buffer (const GstBuffer *buffer); void gst_bit_reader_free (GstBitReader *reader); void gst_bit_reader_init (GstBitReader *reader, const guint8 *data, guint size); -void gst_bit_reader_init_from_buffer (GstBitReader *reader, const GstBuffer *buffer); gboolean gst_bit_reader_set_pos (GstBitReader *reader, guint pos); @@ -87,19 +85,6 @@ gboolean gst_bit_reader_peek_bits_uint64 (const GstBitReader *reader, guint64 *v */ #define GST_BIT_READER_INIT(data, size) {data, size, 0, 0} -/** - * GST_BIT_READER_INIT_FROM_BUFFER: - * @buffer: Buffer from which the #GstBitReader should read - * - * A #GstBitReader must be initialized with this macro, before it can be - * used. This macro can used be to initialize a variable, but it cannot - * be assigned to a variable. In that case you have to use - * gst_bit_reader_init(). - * - * Since: 0.10.22 - */ -#define GST_BIT_READER_INIT_FROM_BUFFER(buffer) {GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer), 0, 0} - /* Unchecked variants */ static inline void diff --git a/libs/gst/base/gstbytereader.c b/libs/gst/base/gstbytereader.c index e0cc7237f1..97da6ec4b4 100644 --- a/libs/gst/base/gstbytereader.c +++ b/libs/gst/base/gstbytereader.c @@ -66,34 +66,12 @@ gst_byte_reader_new (const guint8 * data, guint size) return ret; } -/** - * gst_byte_reader_new_from_buffer: - * @buffer: (transfer none): Buffer from which the #GstByteReader should read - * - * Create a new #GstByteReader instance, which will read from the - * #GstBuffer @buffer. - * - * Free-function: gst_byte_reader_free - * - * Returns: (transfer full): a new #GstByteReader instance - * - * Since: 0.10.22 - */ -GstByteReader * -gst_byte_reader_new_from_buffer (const GstBuffer * buffer) -{ - g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL); - - return gst_byte_reader_new (GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer)); -} - /** * gst_byte_reader_free: * @reader: (in) (transfer full): a #GstByteReader instance * * Frees a #GstByteReader instance, which was previously allocated by - * gst_byte_reader_new() or gst_byte_reader_new_from_buffer(). + * gst_byte_reader_new(). * * Since: 0.10.22 */ @@ -127,26 +105,6 @@ gst_byte_reader_init (GstByteReader * reader, const guint8 * data, guint size) reader->byte = 0; } -/** - * gst_byte_reader_init_from_buffer: - * @reader: a #GstByteReader instance - * @buffer: (transfer none): Buffer from which the #GstByteReader should read - * - * Initializes a #GstByteReader instance to read from @buffer. This function - * can be called on already initialized instances. - * - * Since: 0.10.22 - */ -void -gst_byte_reader_init_from_buffer (GstByteReader * reader, - const GstBuffer * buffer) -{ - g_return_if_fail (GST_IS_BUFFER (buffer)); - - gst_byte_reader_init (reader, GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer)); -} - /** * gst_byte_reader_set_pos: * @reader: a #GstByteReader instance diff --git a/libs/gst/base/gstbytereader.h b/libs/gst/base/gstbytereader.h index f25c3b54ef..440c80321a 100644 --- a/libs/gst/base/gstbytereader.h +++ b/libs/gst/base/gstbytereader.h @@ -44,11 +44,9 @@ typedef struct { } GstByteReader; GstByteReader * gst_byte_reader_new (const guint8 *data, guint size); -GstByteReader * gst_byte_reader_new_from_buffer (const GstBuffer *buffer); void gst_byte_reader_free (GstByteReader *reader); void gst_byte_reader_init (GstByteReader *reader, const guint8 *data, guint size); -void gst_byte_reader_init_from_buffer (GstByteReader *reader, const GstBuffer *buffer); gboolean gst_byte_reader_set_pos (GstByteReader *reader, guint pos); @@ -154,20 +152,6 @@ guint gst_byte_reader_masked_scan_uint32 (const GstByteReader * reader, */ #define GST_BYTE_READER_INIT(data, size) {data, size, 0} -/** - * GST_BYTE_READER_INIT_FROM_BUFFER: - * @buffer: Buffer from which the #GstByteReader should read - * - * A #GstByteReader must be initialized with this macro, before it can be - * used. This macro can used be to initialize a variable, but it cannot - * be assigned to a variable. In that case you have to use - * gst_byte_reader_init(). - * - * Since: 0.10.22 - */ -#define GST_BYTE_READER_INIT_FROM_BUFFER(buffer) {GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer), 0} - - /* unchecked variants */ static inline void gst_byte_reader_skip_unchecked (GstByteReader * reader, guint nbytes) diff --git a/libs/gst/base/gstbytewriter.c b/libs/gst/base/gstbytewriter.c index 25564f7d97..d59c22e835 100644 --- a/libs/gst/base/gstbytewriter.c +++ b/libs/gst/base/gstbytewriter.c @@ -115,33 +115,6 @@ gst_byte_writer_new_with_data (guint8 * data, guint size, gboolean initialized) return ret; } -/** - * gst_byte_writer_new_with_buffer: - * @buffer: Buffer used for writing - * @initialized: If %TRUE the complete data can be read from the beginning - * - * Creates a new #GstByteWriter instance with the given - * buffer. If @initialized is %TRUE it is possible to - * read the complete buffer from the #GstByteWriter from the beginning. - * - * @buffer must be writable - * - * Free-function: gst_byte_writer_free - * - * Returns: (transfer full): a new #GstByteWriter instance - * - * Since: 0.10.26 - */ -GstByteWriter * -gst_byte_writer_new_with_buffer (GstBuffer * buffer, gboolean initialized) -{ - g_return_val_if_fail (GST_IS_BUFFER (buffer) - && gst_buffer_is_writable (buffer), NULL); - - return gst_byte_writer_new_with_data (GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer), initialized); -} - /** * gst_byte_writer_init: * @writer: #GstByteWriter instance @@ -213,30 +186,6 @@ gst_byte_writer_init_with_data (GstByteWriter * writer, guint8 * data, writer->owned = FALSE; } -/** - * gst_byte_writer_init_with_buffer: - * @writer: #GstByteWriter instance - * @buffer: (transfer none): Buffer used for writing - * @initialized: If %TRUE the complete data can be read from the beginning - * - * Initializes @writer with the given - * buffer. If @initialized is %TRUE it is possible to - * read the complete buffer from the #GstByteWriter from the beginning. - * - * @buffer must be writable - * - * Since: 0.10.26 - */ -void -gst_byte_writer_init_with_buffer (GstByteWriter * writer, GstBuffer * buffer, - gboolean initialized) -{ - g_return_if_fail (GST_IS_BUFFER (buffer) && gst_buffer_is_writable (buffer)); - - gst_byte_writer_init_with_data (writer, GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer), initialized); -} - /** * gst_byte_writer_reset: * @writer: #GstByteWriter instance @@ -301,13 +250,17 @@ GstBuffer * gst_byte_writer_reset_and_get_buffer (GstByteWriter * writer) { GstBuffer *buffer; + gpointer data; + gsize size; g_return_val_if_fail (writer != NULL, NULL); + size = writer->parent.size; + data = gst_byte_writer_reset_and_get_data (writer); + buffer = gst_buffer_new (); - GST_BUFFER_SIZE (buffer) = writer->parent.size; - GST_BUFFER_MALLOCDATA (buffer) = gst_byte_writer_reset_and_get_data (writer); - GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer); + gst_buffer_take_memory (buffer, gst_memory_new_wrapped (data, g_free, size, 0, + size)); return buffer; } diff --git a/libs/gst/base/gstbytewriter.h b/libs/gst/base/gstbytewriter.h index 186480d6cd..9f369bed10 100644 --- a/libs/gst/base/gstbytewriter.h +++ b/libs/gst/base/gstbytewriter.h @@ -51,12 +51,10 @@ typedef struct { GstByteWriter * gst_byte_writer_new (void); GstByteWriter * gst_byte_writer_new_with_size (guint size, gboolean fixed); GstByteWriter * gst_byte_writer_new_with_data (guint8 *data, guint size, gboolean initialized); -GstByteWriter * gst_byte_writer_new_with_buffer (GstBuffer *buffer, gboolean initialized); void gst_byte_writer_init (GstByteWriter *writer); void gst_byte_writer_init_with_size (GstByteWriter *writer, guint size, gboolean fixed); void gst_byte_writer_init_with_data (GstByteWriter *writer, guint8 *data, guint size, gboolean initialized); -void gst_byte_writer_init_with_buffer (GstByteWriter *writer, GstBuffer *buffer, gboolean initialized); void gst_byte_writer_free (GstByteWriter *writer); guint8 * gst_byte_writer_free_and_get_data (GstByteWriter *writer); diff --git a/libs/gst/base/gstcollectpads.c b/libs/gst/base/gstcollectpads.c index 8d0aa14d96..e9a89e6d97 100644 --- a/libs/gst/base/gstcollectpads.c +++ b/libs/gst/base/gstcollectpads.c @@ -861,7 +861,7 @@ gst_collect_pads_available (GstCollectPads * pads) } /* this is the size left of the buffer */ - size = GST_BUFFER_SIZE (buffer) - pdata->pos; + size = gst_buffer_get_size (buffer) - pdata->pos; GST_DEBUG ("pad %s:%s has %d bytes left", GST_DEBUG_PAD_NAME (pdata->pad), size); @@ -881,48 +881,6 @@ not_filled: } } -/** - * gst_collect_pads_read: - * @pads: the collectspads to query - * @data: the data to use - * @bytes: (out) (transfer none) (array length=size): a pointer to a byte array - * @size: the number of bytes to read - * - * Get a pointer in @bytes where @size bytes can be read from the - * given pad @data. - * - * This function should be called with @pads LOCK held, such as - * in the callback. - * - * Returns: The number of bytes available for consumption in the - * memory pointed to by @bytes. This can be less than @size and - * is 0 if the pad is end-of-stream. - * - * MT safe. - */ -guint -gst_collect_pads_read (GstCollectPads * pads, GstCollectData * data, - guint8 ** bytes, guint size) -{ - guint readsize; - GstBuffer *buffer; - - g_return_val_if_fail (pads != NULL, 0); - g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), 0); - g_return_val_if_fail (data != NULL, 0); - g_return_val_if_fail (bytes != NULL, 0); - - /* no buffer, must be EOS */ - if ((buffer = data->buffer) == NULL) - return 0; - - readsize = MIN (size, GST_BUFFER_SIZE (buffer) - data->pos); - - *bytes = GST_BUFFER_DATA (buffer) + data->pos; - - return readsize; -} - /** * gst_collect_pads_read_buffer: * @pads: the collectspads to query @@ -958,7 +916,7 @@ gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data, if ((buffer = data->buffer) == NULL) return NULL; - bufsize = GST_BUFFER_SIZE (buffer); + bufsize = gst_buffer_get_size (buffer); readsize = MIN (size, bufsize - data->pos); @@ -996,7 +954,7 @@ gst_collect_pads_take_buffer (GstCollectPads * pads, GstCollectData * data, GstBuffer *buffer = gst_collect_pads_read_buffer (pads, data, size); if (buffer) { - gst_collect_pads_flush (pads, data, GST_BUFFER_SIZE (buffer)); + gst_collect_pads_flush (pads, data, gst_buffer_get_size (buffer)); } return buffer; } @@ -1023,6 +981,7 @@ gst_collect_pads_flush (GstCollectPads * pads, GstCollectData * data, { guint flushsize; GstBuffer *buffer; + gsize bsize; g_return_val_if_fail (pads != NULL, 0); g_return_val_if_fail (GST_IS_COLLECT_PADS (pads), 0); @@ -1032,14 +991,16 @@ gst_collect_pads_flush (GstCollectPads * pads, GstCollectData * data, if ((buffer = data->buffer) == NULL) return 0; + bsize = gst_buffer_get_size (buffer); + /* this is what we can flush at max */ - flushsize = MIN (size, GST_BUFFER_SIZE (buffer) - data->pos); + flushsize = MIN (size, bsize - data->pos); data->pos += size; GST_LOG_OBJECT (pads, "Flushing %d bytes, requested %u", flushsize, size); - if (data->pos >= GST_BUFFER_SIZE (buffer)) + if (data->pos >= bsize) /* _clear will also reset data->pos to 0 */ gst_collect_pads_clear (pads, data); diff --git a/libs/gst/base/gstcollectpads.h b/libs/gst/base/gstcollectpads.h index 939c2f63a3..ba6761eebe 100644 --- a/libs/gst/base/gstcollectpads.h +++ b/libs/gst/base/gstcollectpads.h @@ -209,8 +209,6 @@ GstBuffer* gst_collect_pads_pop (GstCollectPads *pads, GstCollec /* get collected bytes */ guint gst_collect_pads_available (GstCollectPads *pads); -guint gst_collect_pads_read (GstCollectPads *pads, GstCollectData *data, - guint8 **bytes, guint size); GstBuffer * gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data, guint size); GstBuffer * gst_collect_pads_take_buffer (GstCollectPads * pads, GstCollectData * data, diff --git a/libs/gst/base/gsttypefindhelper.c b/libs/gst/base/gsttypefindhelper.c index 8695b92917..1cfffb760e 100644 --- a/libs/gst/base/gsttypefindhelper.c +++ b/libs/gst/base/gsttypefindhelper.c @@ -70,14 +70,14 @@ typedef struct * Returns: address of the data or %NULL if buffer does not cover the * requested range. */ -static guint8 * +static const guint8 * helper_find_peek (gpointer data, gint64 offset, guint size) { GstTypeFindHelper *helper; GstBuffer *buffer; GstFlowReturn ret; GSList *insert_pos = NULL; - guint buf_size; + gsize buf_size; guint64 buf_offset; GstCaps *caps; @@ -103,14 +103,19 @@ helper_find_peek (gpointer data, gint64 offset, guint size) for (walk = helper->buffers; walk; walk = walk->next) { GstBuffer *buf = GST_BUFFER_CAST (walk->data); guint64 buf_offset = GST_BUFFER_OFFSET (buf); - guint buf_size = GST_BUFFER_SIZE (buf); + guint buf_size = gst_buffer_get_size (buf); /* buffers are kept sorted by end offset (highest first) in the list, so * at this point we save the current position and stop searching if * we're after the searched end offset */ if (buf_offset <= offset) { if ((offset + size) < (buf_offset + buf_size)) { - return GST_BUFFER_DATA (buf) + (offset - buf_offset); + guint8 *data; + + /* FIXME, unmap after usage */ + data = gst_buffer_map (buf, NULL, NULL, GST_MAP_READ); + + return data + (offset - buf_offset); } } else if (offset + size >= buf_offset + buf_size) { insert_pos = walk; @@ -147,7 +152,7 @@ helper_find_peek (gpointer data, gint64 offset, guint size) /* getrange might silently return shortened buffers at the end of a file, * we must, however, always return either the full requested data or NULL */ buf_offset = GST_BUFFER_OFFSET (buffer); - buf_size = GST_BUFFER_SIZE (buffer); + buf_size = gst_buffer_get_size (buffer); if ((buf_offset != -1 && buf_offset != offset) || buf_size < size) { GST_DEBUG ("droping short buffer: %" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT @@ -164,10 +169,12 @@ helper_find_peek (gpointer data, gint64 offset, guint size) /* if insert_pos is not set, our offset is bigger than the largest offset * we have so far; since we keep the list sorted with highest offsets * first, we need to prepend the buffer to the list */ - helper->last_offset = GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer); + helper->last_offset = GST_BUFFER_OFFSET (buffer) + buf_size; helper->buffers = g_slist_prepend (helper->buffers, buffer); } - return GST_BUFFER_DATA (buffer); + + /* FIXME, unmap */ + return gst_buffer_map (buffer, NULL, NULL, GST_MAP_READ); error: { @@ -406,8 +413,8 @@ gst_type_find_helper (GstPad * src, guint64 size) typedef struct { - guint8 *data; /* buffer data */ - guint size; + const guint8 *data; /* buffer data */ + gsize size; guint best_probability; GstCaps *caps; GstTypeFindFactory *factory; /* for logging */ @@ -425,7 +432,7 @@ typedef struct * Returns: address inside the buffer or %NULL if buffer does not cover the * requested range. */ -static guint8 * +static const guint8 * buf_helper_find_peek (gpointer data, gint64 off, guint size) { GstTypeFindBufHelper *helper; @@ -477,14 +484,15 @@ buf_helper_find_suggest (gpointer data, guint probability, const GstCaps * caps) } /** - * gst_type_find_helper_for_buffer: + * gst_type_find_helper_for_data: * @obj: object doing the typefinding, or NULL (used for logging) - * @buf: (in) (transfer none): a #GstBuffer with data to typefind + * @data: (in) (transfer none): a pointer with data to typefind + * @size: (in) (transfer none): the size of @data * @prob: (out) (allow-none): location to store the probability of the found * caps, or #NULL * - * Tries to find what type of data is contained in the given #GstBuffer, the - * assumption being that the buffer represents the beginning of the stream or + * Tries to find what type of data is contained in the given @data, the + * assumption being that the data represents the beginning of the stream or * file. * * All available typefinders will be called on the data in order of rank. If @@ -492,7 +500,7 @@ buf_helper_find_suggest (gpointer data, guint probability, const GstCaps * caps) * typefinding is stopped immediately and the found caps will be returned * right away. Otherwise, all available typefind functions will the tried, * and the caps with the highest probability will be returned, or #NULL if - * the content of the buffer could not be identified. + * the content of @data could not be identified. * * Free-function: gst_caps_unref * @@ -501,7 +509,7 @@ buf_helper_find_suggest (gpointer data, guint probability, const GstCaps * caps) * with gst_caps_unref(). */ GstCaps * -gst_type_find_helper_for_buffer (GstObject * obj, GstBuffer * buf, +gst_type_find_helper_for_data (GstObject * obj, const guint8 * data, gsize size, GstTypeFindProbability * prob) { GstTypeFindBufHelper helper; @@ -509,13 +517,10 @@ gst_type_find_helper_for_buffer (GstObject * obj, GstBuffer * buf, GList *l, *type_list; GstCaps *result = NULL; - g_return_val_if_fail (buf != NULL, NULL); - g_return_val_if_fail (GST_IS_BUFFER (buf), NULL); - g_return_val_if_fail (GST_BUFFER_OFFSET (buf) == 0 || - GST_BUFFER_OFFSET (buf) == GST_BUFFER_OFFSET_NONE, NULL); + g_return_val_if_fail (data != NULL, NULL); - helper.data = GST_BUFFER_DATA (buf); - helper.size = GST_BUFFER_SIZE (buf); + helper.data = data; + helper.size = size; helper.best_probability = 0; helper.caps = NULL; helper.obj = obj; @@ -550,6 +555,50 @@ gst_type_find_helper_for_buffer (GstObject * obj, GstBuffer * buf, return result; } +/** + * gst_type_find_helper_for_buffer: + * @obj: object doing the typefinding, or NULL (used for logging) + * @buf: (in) (transfer none): a #GstBuffer with data to typefind + * @prob: (out) (allow-none): location to store the probability of the found + * caps, or #NULL + * + * Tries to find what type of data is contained in the given #GstBuffer, the + * assumption being that the buffer represents the beginning of the stream or + * file. + * + * All available typefinders will be called on the data in order of rank. If + * a typefinding function returns a probability of #GST_TYPE_FIND_MAXIMUM, + * typefinding is stopped immediately and the found caps will be returned + * right away. Otherwise, all available typefind functions will the tried, + * and the caps with the highest probability will be returned, or #NULL if + * the content of the buffer could not be identified. + * + * Free-function: gst_caps_unref + * + * Returns: (transfer full): the #GstCaps corresponding to the data, or #NULL + * if no type could be found. The caller should free the caps returned + * with gst_caps_unref(). + */ +GstCaps * +gst_type_find_helper_for_buffer (GstObject * obj, GstBuffer * buf, + GstTypeFindProbability * prob) +{ + GstCaps *result; + guint8 *data; + gsize size; + + g_return_val_if_fail (buf != NULL, NULL); + g_return_val_if_fail (GST_IS_BUFFER (buf), NULL); + g_return_val_if_fail (GST_BUFFER_OFFSET (buf) == 0 || + GST_BUFFER_OFFSET (buf) == GST_BUFFER_OFFSET_NONE, NULL); + + data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); + result = gst_type_find_helper_for_data (obj, data, size, prob); + gst_buffer_unmap (buf, data, size); + + return result; +} + /** * gst_type_find_helper_for_extension: * @obj: (allow-none): object doing the typefinding, or NULL (used for logging) diff --git a/libs/gst/base/gsttypefindhelper.h b/libs/gst/base/gsttypefindhelper.h index b6ad5173dd..052bc198b4 100644 --- a/libs/gst/base/gsttypefindhelper.h +++ b/libs/gst/base/gsttypefindhelper.h @@ -30,6 +30,10 @@ G_BEGIN_DECLS GstCaps * gst_type_find_helper (GstPad *src, guint64 size); +GstCaps * gst_type_find_helper_for_data (GstObject *obj, + const guint8 *data, + gsize size, + GstTypeFindProbability *prob); GstCaps * gst_type_find_helper_for_buffer (GstObject *obj, GstBuffer *buf, GstTypeFindProbability *prob); diff --git a/libs/gst/check/gstcheck.c b/libs/gst/check/gstcheck.c index c4370a3ae9..ca8e0f3e91 100644 --- a/libs/gst/check/gstcheck.c +++ b/libs/gst/check/gstcheck.c @@ -471,22 +471,31 @@ gst_check_element_push_buffer_list (const gchar * element_name, while (buffers != NULL) { GstBuffer *new = GST_BUFFER (buffers->data); GstBuffer *orig = GST_BUFFER (buffer_out->data); + gsize newsize, origsize; + guint8 *newdata, *origdata; + + newdata = gst_buffer_map (new, &newsize, NULL, GST_MAP_READ); + origdata = gst_buffer_map (orig, &origsize, NULL, GST_MAP_READ); GST_LOG ("orig buffer: size %u, caps %" GST_PTR_FORMAT, - GST_BUFFER_SIZE (orig), GST_BUFFER_CAPS (orig)); + origsize, GST_BUFFER_CAPS (orig)); GST_LOG ("new buffer: size %u, caps %" GST_PTR_FORMAT, - GST_BUFFER_SIZE (new), GST_BUFFER_CAPS (new)); - GST_MEMDUMP ("orig buffer", GST_BUFFER_DATA (orig), GST_BUFFER_SIZE (orig)); - GST_MEMDUMP ("new buffer", GST_BUFFER_DATA (new), GST_BUFFER_SIZE (new)); + newsize, GST_BUFFER_CAPS (new)); + GST_MEMDUMP ("orig buffer", origdata, origsize); + GST_MEMDUMP ("new buffer", newdata, newsize); /* remove the buffers */ buffers = g_list_remove (buffers, new); buffer_out = g_list_remove (buffer_out, orig); - fail_unless (GST_BUFFER_SIZE (orig) == GST_BUFFER_SIZE (new), - "size of the buffers are not the same"); - fail_unless (memcmp (GST_BUFFER_DATA (orig), GST_BUFFER_DATA (new), - GST_BUFFER_SIZE (new)) == 0, "data is not the same"); + + fail_unless (origsize == newsize, "size of the buffers are not the same"); + fail_unless (memcmp (origdata, newdata, newsize) == 0, + "data is not the same"); gst_check_caps_equal (GST_BUFFER_CAPS (orig), GST_BUFFER_CAPS (new)); + + gst_buffer_unmap (orig, origdata, origsize); + gst_buffer_unmap (new, newdata, newsize); + gst_buffer_unref (new); gst_buffer_unref (orig); } diff --git a/libs/gst/dataprotocol/dataprotocol.c b/libs/gst/dataprotocol/dataprotocol.c index 2cecd6bf3e..728b3f5480 100644 --- a/libs/gst/dataprotocol/dataprotocol.c +++ b/libs/gst/dataprotocol/dataprotocol.c @@ -131,6 +131,8 @@ gst_dp_header_from_buffer_any (const GstBuffer * buffer, GstDPHeaderFlag flags, { guint8 *h; guint16 flags_mask; + guint8 *data; + gsize size; g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); g_return_val_if_fail (length, FALSE); @@ -142,8 +144,10 @@ gst_dp_header_from_buffer_any (const GstBuffer * buffer, GstDPHeaderFlag flags, /* version, flags, type */ GST_DP_INIT_HEADER (h, version, flags, GST_DP_PAYLOAD_BUFFER); + data = gst_buffer_map ((GstBuffer *) buffer, &size, NULL, GST_MAP_READ); + /* buffer properties */ - GST_WRITE_UINT32_BE (h + 6, GST_BUFFER_SIZE (buffer)); + GST_WRITE_UINT32_BE (h + 6, size); GST_WRITE_UINT64_BE (h + 10, GST_BUFFER_TIMESTAMP (buffer)); GST_WRITE_UINT64_BE (h + 18, GST_BUFFER_DURATION (buffer)); GST_WRITE_UINT64_BE (h + 26, GST_BUFFER_OFFSET (buffer)); @@ -157,7 +161,9 @@ gst_dp_header_from_buffer_any (const GstBuffer * buffer, GstDPHeaderFlag flags, GST_WRITE_UINT16_BE (h + 42, GST_BUFFER_FLAGS (buffer) & flags_mask); - GST_DP_SET_CRC (h, flags, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); + GST_DP_SET_CRC (h, flags, data, size); + + gst_buffer_unmap ((GstBuffer *) buffer, data, size); GST_LOG ("created header from buffer:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); diff --git a/plugins/elements/gstcapsfilter.c b/plugins/elements/gstcapsfilter.c index a144611377..6286ddc28f 100644 --- a/plugins/elements/gstcapsfilter.c +++ b/plugins/elements/gstcapsfilter.c @@ -341,7 +341,7 @@ gst_capsfilter_prepare_buf (GstBaseTransform * trans, GstBuffer * input, gst_buffer_ref (input); } else { GST_DEBUG_OBJECT (trans, "Creating sub-buffer and setting caps"); - *buf = gst_buffer_create_sub (input, 0, GST_BUFFER_SIZE (input)); + *buf = gst_buffer_create_sub (input, 0, gst_buffer_get_size (input)); gst_buffer_set_caps (*buf, caps); } } else { @@ -373,7 +373,7 @@ gst_capsfilter_prepare_buf (GstBaseTransform * trans, GstBuffer * input, *buf = input; } else { GST_DEBUG_OBJECT (trans, "Creating sub-buffer and setting caps"); - *buf = gst_buffer_create_sub (input, 0, GST_BUFFER_SIZE (input)); + *buf = gst_buffer_create_sub (input, 0, gst_buffer_get_size (input)); } GST_BUFFER_CAPS (*buf) = out_caps; diff --git a/plugins/elements/gstfakesink.c b/plugins/elements/gstfakesink.c index b703c61f16..94ed3459ce 100644 --- a/plugins/elements/gstfakesink.c +++ b/plugins/elements/gstfakesink.c @@ -521,11 +521,12 @@ gst_fake_sink_render (GstBaseSink * bsink, GstBuffer * buf) } sink->last_message = - g_strdup_printf ("chain ******* < (%5d bytes, timestamp: %s" - ", duration: %s, offset: %" G_GINT64_FORMAT ", offset_end: %" - G_GINT64_FORMAT ", flags: %d %s) %p", GST_BUFFER_SIZE (buf), ts_str, - dur_str, GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf), - GST_MINI_OBJECT_CAST (buf)->flags, flag_str, buf); + g_strdup_printf ("chain ******* < (%5" G_GSIZE_FORMAT + " bytes, timestamp: %s" ", duration: %s, offset: %" G_GINT64_FORMAT + ", offset_end: %" G_GINT64_FORMAT ", flags: %d %s) %p", + gst_buffer_get_size (buf), ts_str, dur_str, GST_BUFFER_OFFSET (buf), + GST_BUFFER_OFFSET_END (buf), GST_MINI_OBJECT_CAST (buf)->flags, + flag_str, buf); GST_OBJECT_UNLOCK (sink); gst_fake_sink_notify_last_message (sink); @@ -535,7 +536,12 @@ gst_fake_sink_render (GstBaseSink * bsink, GstBuffer * buf) bsink->sinkpad); if (sink->dump) { - gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); + guint8 *data; + gsize size; + + data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); + gst_util_dump_mem (data, size); + gst_buffer_unmap (buf, data, size); } if (sink->num_buffers_left == 0) goto eos; diff --git a/plugins/elements/gstfakesrc.c b/plugins/elements/gstfakesrc.c index f7cecc8685..74dbc9b6f3 100644 --- a/plugins/elements/gstfakesrc.c +++ b/plugins/elements/gstfakesrc.c @@ -465,10 +465,7 @@ gst_fake_src_alloc_parent (GstFakeSrc * src) { GstBuffer *buf; - buf = gst_buffer_new (); - GST_BUFFER_DATA (buf) = g_malloc (src->parentsize); - GST_BUFFER_MALLOCDATA (buf) = GST_BUFFER_DATA (buf); - GST_BUFFER_SIZE (buf) = src->parentsize; + buf = gst_buffer_new_and_alloc (src->parentsize); src->parent = buf; src->parentoffset = 0; @@ -629,21 +626,21 @@ gst_fake_src_get_property (GObject * object, guint prop_id, GValue * value, } static void -gst_fake_src_prepare_buffer (GstFakeSrc * src, GstBuffer * buf) +gst_fake_src_prepare_buffer (GstFakeSrc * src, guint8 * data, gsize size) { - if (GST_BUFFER_SIZE (buf) == 0) + if (size == 0) return; switch (src->filltype) { case FAKE_SRC_FILLTYPE_ZERO: - memset (GST_BUFFER_DATA (buf), 0, GST_BUFFER_SIZE (buf)); + memset (data, 0, size); break; case FAKE_SRC_FILLTYPE_RANDOM: { gint i; - guint8 *ptr = GST_BUFFER_DATA (buf); + guint8 *ptr = data; - for (i = GST_BUFFER_SIZE (buf); i; i--) { + for (i = size; i; i--) { *ptr++ = g_random_int_range (0, 256); } break; @@ -653,9 +650,9 @@ gst_fake_src_prepare_buffer (GstFakeSrc * src, GstBuffer * buf) case FAKE_SRC_FILLTYPE_PATTERN_CONT: { gint i; - guint8 *ptr = GST_BUFFER_DATA (buf); + guint8 *ptr = data; - for (i = GST_BUFFER_SIZE (buf); i; i--) { + for (i = size; i; i--) { *ptr++ = src->pattern_byte++; } break; @@ -670,29 +667,32 @@ static GstBuffer * gst_fake_src_alloc_buffer (GstFakeSrc * src, guint size) { GstBuffer *buf; + gpointer data; + gboolean do_prepare = FALSE; buf = gst_buffer_new (); - GST_BUFFER_SIZE (buf) = size; if (size != 0) { switch (src->filltype) { case FAKE_SRC_FILLTYPE_NOTHING: - GST_BUFFER_DATA (buf) = g_malloc (size); - GST_BUFFER_MALLOCDATA (buf) = GST_BUFFER_DATA (buf); + data = g_malloc (size); break; case FAKE_SRC_FILLTYPE_ZERO: - GST_BUFFER_DATA (buf) = g_malloc0 (size); - GST_BUFFER_MALLOCDATA (buf) = GST_BUFFER_DATA (buf); + data = g_malloc0 (size); break; case FAKE_SRC_FILLTYPE_RANDOM: case FAKE_SRC_FILLTYPE_PATTERN: case FAKE_SRC_FILLTYPE_PATTERN_CONT: default: - GST_BUFFER_DATA (buf) = g_malloc (size); - GST_BUFFER_MALLOCDATA (buf) = GST_BUFFER_DATA (buf); - gst_fake_src_prepare_buffer (src, buf); + data = g_malloc (size); + do_prepare = TRUE; break; } + if (do_prepare) + gst_fake_src_prepare_buffer (src, data, size); + + gst_buffer_take_memory (buf, gst_memory_new_wrapped (data, g_free, size, 0, + size)); } return buf; @@ -720,11 +720,14 @@ gst_fake_src_get_size (GstFakeSrc * src) } static GstBuffer * -gst_fake_src_create_buffer (GstFakeSrc * src) +gst_fake_src_create_buffer (GstFakeSrc * src, gsize * bufsize) { GstBuffer *buf; - guint size = gst_fake_src_get_size (src); + gsize size = gst_fake_src_get_size (src); gboolean dump = src->dump; + guint8 *data; + + *bufsize = size; switch (src->data) { case FAKE_SRC_DATA_ALLOCATE: @@ -737,7 +740,7 @@ gst_fake_src_create_buffer (GstFakeSrc * src) g_assert (src->parent); } /* see if it's large enough */ - if ((GST_BUFFER_SIZE (src->parent) - src->parentoffset) >= size) { + if ((src->parentsize - src->parentoffset) >= size) { buf = gst_buffer_create_sub (src->parent, src->parentoffset, size); src->parentoffset += size; } else { @@ -745,9 +748,11 @@ gst_fake_src_create_buffer (GstFakeSrc * src) gst_buffer_unref (src->parent); src->parent = NULL; /* try again (this will allocate a new parent) */ - return gst_fake_src_create_buffer (src); + return gst_fake_src_create_buffer (src, bufsize); } - gst_fake_src_prepare_buffer (src, buf); + data = gst_buffer_map (buf, &size, NULL, GST_MAP_WRITE); + gst_fake_src_prepare_buffer (src, data, size); + gst_buffer_unmap (buf, data, size); break; default: g_warning ("fakesrc: dunno how to allocate buffers !"); @@ -755,7 +760,9 @@ gst_fake_src_create_buffer (GstFakeSrc * src) break; } if (dump) { - gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); + data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); + gst_util_dump_mem (data, size); + gst_buffer_unmap (buf, data, size); } return buf; @@ -795,17 +802,17 @@ gst_fake_src_create (GstBaseSrc * basesrc, guint64 offset, guint length, GstFakeSrc *src; GstBuffer *buf; GstClockTime time; + gsize size; src = GST_FAKE_SRC (basesrc); - buf = gst_fake_src_create_buffer (src); + buf = gst_fake_src_create_buffer (src, &size); GST_BUFFER_OFFSET (buf) = src->buffer_count++; if (src->datarate > 0) { time = (src->bytes_sent * GST_SECOND) / src->datarate; - GST_BUFFER_DURATION (buf) = - GST_BUFFER_SIZE (buf) * GST_SECOND / src->datarate; + GST_BUFFER_DURATION (buf) = size * GST_SECOND / src->datarate; } else if (gst_base_src_is_live (basesrc)) { GstClock *clock; @@ -848,7 +855,7 @@ gst_fake_src_create (GstBaseSrc * basesrc, guint64 offset, guint length, src->last_message = g_strdup_printf ("get ******* > (%5d bytes, timestamp: %s" ", duration: %s, offset: %" G_GINT64_FORMAT ", offset_end: %" - G_GINT64_FORMAT ", flags: %d) %p", GST_BUFFER_SIZE (buf), ts_str, + G_GINT64_FORMAT ", flags: %d) %p", (gint) size, ts_str, dur_str, GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf), GST_MINI_OBJECT_CAST (buf)->flags, buf); GST_OBJECT_UNLOCK (src); @@ -867,7 +874,7 @@ gst_fake_src_create (GstBaseSrc * basesrc, guint64 offset, guint length, GST_LOG_OBJECT (src, "post handoff emit"); } - src->bytes_sent += GST_BUFFER_SIZE (buf); + src->bytes_sent += size; *ret = buf; return GST_FLOW_OK; diff --git a/plugins/elements/gstfdsink.c b/plugins/elements/gstfdsink.c index 6383d2a99c..1ff46bd12f 100644 --- a/plugins/elements/gstfdsink.c +++ b/plugins/elements/gstfdsink.c @@ -231,8 +231,8 @@ static GstFlowReturn gst_fd_sink_render (GstBaseSink * sink, GstBuffer * buffer) { GstFdSink *fdsink; - guint8 *data; - guint size; + guint8 *data, *ptr; + gsize size, left; gint written; #ifndef HAVE_WIN32 @@ -243,8 +243,10 @@ gst_fd_sink_render (GstBaseSink * sink, GstBuffer * buffer) g_return_val_if_fail (fdsink->fd >= 0, GST_FLOW_ERROR); - data = GST_BUFFER_DATA (buffer); - size = GST_BUFFER_SIZE (buffer); + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); + + ptr = data; + left = size; again: #ifndef HAVE_WIN32 @@ -265,7 +267,7 @@ again: GST_DEBUG_OBJECT (fdsink, "writing %d bytes to file descriptor %d", size, fdsink->fd); - written = write (fdsink->fd, data, size); + written = write (fdsink->fd, ptr, left); /* check for errors */ if (G_UNLIKELY (written < 0)) { @@ -278,17 +280,20 @@ again: } /* all is fine when we get here */ - size -= written; - data += written; + left -= written; + ptr += written; fdsink->bytes_written += written; fdsink->current_pos += written; - GST_DEBUG_OBJECT (fdsink, "wrote %d bytes, %d left", written, size); + GST_DEBUG_OBJECT (fdsink, "wrote %d bytes, %" G_GSIZE_FORMAT " left", written, + left); /* short write, select and try to write the remainder */ - if (G_UNLIKELY (size > 0)) + if (G_UNLIKELY (left > 0)) goto again; + gst_buffer_unmap (buffer, data, size); + return GST_FLOW_OK; #ifndef HAVE_WIN32 @@ -297,11 +302,13 @@ select_error: GST_ELEMENT_ERROR (fdsink, RESOURCE, READ, (NULL), ("select on file descriptor: %s.", g_strerror (errno))); GST_DEBUG_OBJECT (fdsink, "Error during select"); + gst_buffer_unmap (buffer, data, size); return GST_FLOW_ERROR; } stopped: { GST_DEBUG_OBJECT (fdsink, "Select stopped"); + gst_buffer_unmap (buffer, data, size); return GST_FLOW_WRONG_STATE; } #endif @@ -318,6 +325,7 @@ write_error: fdsink->fd, g_strerror (errno))); } } + gst_buffer_unmap (buffer, data, size); return GST_FLOW_ERROR; } } diff --git a/plugins/elements/gstfdsrc.c b/plugins/elements/gstfdsrc.c index 6d7f0f9cea..8180ae5dfd 100644 --- a/plugins/elements/gstfdsrc.c +++ b/plugins/elements/gstfdsrc.c @@ -406,6 +406,8 @@ gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) gssize readbytes; guint blocksize; GstClockTime timeout; + guint8 *data; + gsize maxsize; #ifndef HAVE_WIN32 gboolean try_again; @@ -454,24 +456,25 @@ gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) /* create the buffer */ buf = gst_buffer_try_new_and_alloc (blocksize); - if (G_UNLIKELY (buf == NULL)) { - GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", blocksize); - return GST_FLOW_ERROR; - } + if (G_UNLIKELY (buf == NULL)) + goto alloc_failed; + + data = gst_buffer_map (buf, NULL, &maxsize, GST_MAP_WRITE); do { - readbytes = read (src->fd, GST_BUFFER_DATA (buf), blocksize); + readbytes = read (src->fd, data, blocksize); GST_LOG_OBJECT (src, "read %" G_GSSIZE_FORMAT, readbytes); } while (readbytes == -1 && errno == EINTR); /* retry if interrupted */ if (readbytes < 0) goto read_error; + gst_buffer_unmap (buf, data, readbytes); + if (readbytes == 0) goto eos; GST_BUFFER_OFFSET (buf) = src->curoffset; - GST_BUFFER_SIZE (buf) = readbytes; GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE; src->curoffset += readbytes; @@ -497,6 +500,11 @@ stopped: return GST_FLOW_WRONG_STATE; } #endif +alloc_failed: + { + GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", blocksize); + return GST_FLOW_ERROR; + } eos: { GST_DEBUG_OBJECT (psrc, "Read 0 bytes. EOS."); @@ -508,6 +516,7 @@ read_error: GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("read on file descriptor: %s.", g_strerror (errno))); GST_DEBUG_OBJECT (psrc, "Error reading from fd"); + gst_buffer_unmap (buf, data, 0); gst_buffer_unref (buf); return GST_FLOW_ERROR; } diff --git a/plugins/elements/gstfilesink.c b/plugins/elements/gstfilesink.c index d5fa283298..78f78e1208 100644 --- a/plugins/elements/gstfilesink.c +++ b/plugins/elements/gstfilesink.c @@ -640,13 +640,12 @@ static GstFlowReturn gst_file_sink_render (GstBaseSink * sink, GstBuffer * buffer) { GstFileSink *filesink; - guint size; + gsize size; guint8 *data; filesink = GST_FILE_SINK (sink); - size = GST_BUFFER_SIZE (buffer); - data = GST_BUFFER_DATA (buffer); + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); GST_DEBUG_OBJECT (filesink, "writing %u bytes at %" G_GUINT64_FORMAT, size, filesink->current_pos); @@ -657,6 +656,7 @@ gst_file_sink_render (GstBaseSink * sink, GstBuffer * buffer) filesink->current_pos += size; } + gst_buffer_unmap (buffer, data, size); return GST_FLOW_OK; @@ -673,6 +673,7 @@ handle_error: ("%s", g_strerror (errno))); } } + gst_buffer_unmap (buffer, data, size); return GST_FLOW_ERROR; } } diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c index e3466093af..a834037aba 100644 --- a/plugins/elements/gstfilesrc.c +++ b/plugins/elements/gstfilesrc.c @@ -801,6 +801,8 @@ gst_file_src_create_read (GstFileSrc * src, guint64 offset, guint length, { int ret; GstBuffer *buf; + guint8 *data; + gsize size; if (G_UNLIKELY (src->read_position != offset)) { off_t res; @@ -813,16 +815,16 @@ gst_file_src_create_read (GstFileSrc * src, guint64 offset, guint length, } buf = gst_buffer_try_new_and_alloc (length); - if (G_UNLIKELY (buf == NULL && length > 0)) { - GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", length); - return GST_FLOW_ERROR; - } + if (G_UNLIKELY (buf == NULL && length > 0)) + goto alloc_failed; /* No need to read anything if length is 0 */ if (length > 0) { + data = gst_buffer_map (buf, &size, NULL, GST_MAP_WRITE); + GST_LOG_OBJECT (src, "Reading %d bytes at offset 0x%" G_GINT64_MODIFIER "x", length, offset); - ret = read (src->fd, GST_BUFFER_DATA (buf), length); + ret = read (src->fd, data, length); if (G_UNLIKELY (ret < 0)) goto could_not_read; @@ -835,7 +837,9 @@ gst_file_src_create_read (GstFileSrc * src, guint64 offset, guint length, goto eos; length = ret; - GST_BUFFER_SIZE (buf) = length; + + gst_buffer_unmap (buf, data, length); + GST_BUFFER_OFFSET (buf) = offset; GST_BUFFER_OFFSET_END (buf) = offset + length; @@ -852,9 +856,15 @@ seek_failed: GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM); return GST_FLOW_ERROR; } +alloc_failed: + { + GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", length); + return GST_FLOW_ERROR; + } could_not_read: { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM); + gst_buffer_unmap (buf, data, 0); gst_buffer_unref (buf); return GST_FLOW_ERROR; } @@ -862,12 +872,14 @@ unexpected_eos: { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("unexpected end of file.")); + gst_buffer_unmap (buf, data, 0); gst_buffer_unref (buf); return GST_FLOW_ERROR; } eos: { GST_DEBUG ("non-regular file hits EOS"); + gst_buffer_unmap (buf, data, 0); gst_buffer_unref (buf); return GST_FLOW_UNEXPECTED; } diff --git a/plugins/elements/gstidentity.c b/plugins/elements/gstidentity.c index 7aa2562f5a..c8dbc106be 100644 --- a/plugins/elements/gstidentity.c +++ b/plugins/elements/gstidentity.c @@ -560,7 +560,7 @@ print_pretty_time (gchar * ts_str, gsize ts_str_len, GstClockTime ts) static void gst_identity_update_last_message_for_buffer (GstIdentity * identity, - const gchar * action, GstBuffer * buf) + const gchar * action, GstBuffer * buf, gsize size) { gchar ts_str[64], dur_str[64]; @@ -568,14 +568,13 @@ gst_identity_update_last_message_for_buffer (GstIdentity * identity, g_free (identity->last_message); identity->last_message = g_strdup_printf ("%s ******* (%s:%s)i " - "(%u bytes, timestamp: %s, duration: %s, offset: %" G_GINT64_FORMAT ", " - "offset_end: % " G_GINT64_FORMAT ", flags: %d) %p", action, - GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad), - GST_BUFFER_SIZE (buf), - print_pretty_time (ts_str, sizeof (ts_str), GST_BUFFER_TIMESTAMP (buf)), - print_pretty_time (dur_str, sizeof (dur_str), GST_BUFFER_DURATION (buf)), - GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf), - GST_BUFFER_FLAGS (buf), buf); + "(%" G_GSIZE_FORMAT " bytes, timestamp: %s, duration: %s, offset: %" + G_GINT64_FORMAT ", " "offset_end: % " G_GINT64_FORMAT ", flags: %d) %p", + action, GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad), + size, print_pretty_time (ts_str, sizeof (ts_str), + GST_BUFFER_TIMESTAMP (buf)), print_pretty_time (dur_str, + sizeof (dur_str), GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf), + GST_BUFFER_OFFSET_END (buf), GST_BUFFER_FLAGS (buf), buf); GST_OBJECT_UNLOCK (identity); @@ -588,6 +587,10 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) GstFlowReturn ret = GST_FLOW_OK; GstIdentity *identity = GST_IDENTITY (trans); GstClockTime runtimestamp = G_GINT64_CONSTANT (0); + guint8 *data; + gsize size; + + data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); if (identity->check_perfect) gst_identity_check_perfect (identity, buf); @@ -604,29 +607,21 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) if (identity->error_after >= 0) { identity->error_after--; - if (identity->error_after == 0) { - GST_ELEMENT_ERROR (identity, CORE, FAILED, - (_("Failed after iterations as requested.")), (NULL)); - return GST_FLOW_ERROR; - } + if (identity->error_after == 0) + goto error_after; } if (identity->drop_probability > 0.0) { - if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability) { - if (!identity->silent) { - gst_identity_update_last_message_for_buffer (identity, "dropping", buf); - } - /* return DROPPED to basetransform. */ - return GST_BASE_TRANSFORM_FLOW_DROPPED; - } + if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability) + goto dropped; } if (identity->dump) { - gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); + gst_util_dump_mem (data, size); } if (!identity->silent) { - gst_identity_update_last_message_for_buffer (identity, "chain", buf); + gst_identity_update_last_message_for_buffer (identity, "chain", buf, size); } if (identity->datarate > 0) { @@ -634,8 +629,7 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) GST_SECOND, identity->datarate); GST_BUFFER_TIMESTAMP (buf) = time; - GST_BUFFER_DURATION (buf) = - GST_BUFFER_SIZE (buf) * GST_SECOND / identity->datarate; + GST_BUFFER_DURATION (buf) = size * GST_SECOND / identity->datarate; } if (identity->signal_handoffs) @@ -673,7 +667,7 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) GST_OBJECT_UNLOCK (identity); } - identity->offset += GST_BUFFER_SIZE (buf); + identity->offset += size; if (identity->sleep_time && ret == GST_FLOW_OK) g_usleep (identity->sleep_time); @@ -685,7 +679,28 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE; } + gst_buffer_unmap (buf, data, size); + return ret; + + /* ERRORS */ +error_after: + { + GST_ELEMENT_ERROR (identity, CORE, FAILED, + (_("Failed after iterations as requested.")), (NULL)); + gst_buffer_unmap (buf, data, size); + return GST_FLOW_ERROR; + } +dropped: + { + if (!identity->silent) { + gst_identity_update_last_message_for_buffer (identity, "dropping", buf, + size); + } + gst_buffer_unmap (buf, data, size); + /* return DROPPED to basetransform. */ + return GST_BASE_TRANSFORM_FLOW_DROPPED; + } } static void diff --git a/plugins/elements/gstmultiqueue.c b/plugins/elements/gstmultiqueue.c index f21a2aa6db..0adf6a3b40 100644 --- a/plugins/elements/gstmultiqueue.c +++ b/plugins/elements/gstmultiqueue.c @@ -981,7 +981,7 @@ gst_multi_queue_buffer_item_new (GstMiniObject * object, guint32 curid) item->destroy = (GDestroyNotify) gst_multi_queue_item_destroy; item->posid = curid; - item->size = GST_BUFFER_SIZE (object); + item->size = gst_buffer_get_size (GST_BUFFER_CAST (object)); item->duration = GST_BUFFER_DURATION (object); if (item->duration == GST_CLOCK_TIME_NONE) item->duration = 0; diff --git a/plugins/elements/gstqueue.c b/plugins/elements/gstqueue.c index a641dfeb56..9bd3c3d8fd 100644 --- a/plugins/elements/gstqueue.c +++ b/plugins/elements/gstqueue.c @@ -687,7 +687,7 @@ gst_queue_locked_enqueue_buffer (GstQueue * queue, gpointer item) /* add buffer to the statistics */ queue->cur_level.buffers++; - queue->cur_level.bytes += GST_BUFFER_SIZE (buffer); + queue->cur_level.bytes += gst_buffer_get_size (buffer); apply_buffer (queue, buffer, &queue->sink_segment, TRUE, TRUE); g_queue_push_tail (queue->queue, item); @@ -745,7 +745,7 @@ gst_queue_locked_dequeue (GstQueue * queue, gboolean * is_buffer) "retrieved buffer %p from queue", buffer); queue->cur_level.buffers--; - queue->cur_level.bytes -= GST_BUFFER_SIZE (buffer); + queue->cur_level.bytes -= gst_buffer_get_size (buffer); apply_buffer (queue, buffer, &queue->src_segment, TRUE, FALSE); /* if the queue is empty now, update the other side */ @@ -952,7 +952,7 @@ gst_queue_chain (GstPad * pad, GstBuffer * buffer) GST_CAT_LOG_OBJECT (queue_dataflow, queue, "received buffer %p of size %d, time %" GST_TIME_FORMAT ", duration %" - GST_TIME_FORMAT, buffer, GST_BUFFER_SIZE (buffer), + GST_TIME_FORMAT, buffer, gst_buffer_get_size (buffer), GST_TIME_ARGS (timestamp), GST_TIME_ARGS (duration)); /* We make space available if we're "full" according to whatever diff --git a/plugins/elements/gstqueue2.c b/plugins/elements/gstqueue2.c index ab55cbbc22..d90a1536b7 100644 --- a/plugins/elements/gstqueue2.c +++ b/plugins/elements/gstqueue2.c @@ -1167,7 +1167,7 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length, /* allocate the output buffer of the requested size */ buf = gst_buffer_new_and_alloc (length); - data = GST_BUFFER_DATA (buf); + data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE); GST_DEBUG_OBJECT (queue, "Reading %u bytes from %" G_GUINT64_FORMAT, length, offset); @@ -1279,7 +1279,8 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length, GST_DEBUG_OBJECT (queue, "%u bytes left to read", remaining); } - GST_BUFFER_SIZE (buf) = length; + gst_buffer_unmap (buf, data, length); + GST_BUFFER_OFFSET (buf) = offset; GST_BUFFER_OFFSET_END (buf) = offset + length; @@ -1296,6 +1297,7 @@ out_flushing: read_error: { GST_DEBUG_OBJECT (queue, "we have a read error"); + gst_buffer_unmap (buf, data, 0); gst_buffer_unref (buf); return read_return; } @@ -1521,8 +1523,9 @@ out_flushing: static gboolean gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer) { - guint8 *data, *ring_buffer; + guint8 *odata, *data, *ring_buffer; guint size, rb_size; + gsize osize; guint64 writing_pos, new_writing_pos; GstQueue2Range *range, *prev, *next; @@ -1533,8 +1536,10 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer) ring_buffer = queue->ring_buffer; rb_size = queue->ring_buffer_max_size; - size = GST_BUFFER_SIZE (buffer); - data = GST_BUFFER_DATA (buffer); + odata = gst_buffer_map (buffer, &osize, NULL, GST_MAP_READ); + + size = osize; + data = odata; GST_DEBUG_OBJECT (queue, "Writing %u bytes to %" G_GUINT64_FORMAT, size, GST_BUFFER_OFFSET (buffer)); @@ -1756,7 +1761,9 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer) queue->cur_level.bytes, QUEUE_MAX_BYTES (queue)); GST_QUEUE2_SIGNAL_ADD (queue); - }; + } + + gst_buffer_unmap (buffer, odata, osize); return TRUE; @@ -1764,12 +1771,14 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer) out_flushing: { GST_DEBUG_OBJECT (queue, "we are flushing"); + gst_buffer_unmap (buffer, odata, osize); /* FIXME - GST_FLOW_UNEXPECTED ? */ return FALSE; } seek_failed: { GST_ELEMENT_ERROR (queue, RESOURCE, SEEK, (NULL), GST_ERROR_SYSTEM); + gst_buffer_unmap (buffer, odata, osize); return FALSE; } handle_error: @@ -1785,6 +1794,7 @@ handle_error: ("%s", g_strerror (errno))); } } + gst_buffer_unmap (buffer, odata, osize); return FALSE; } } @@ -1798,7 +1808,7 @@ gst_queue2_locked_enqueue (GstQueue2 * queue, gpointer item, gboolean isbuffer) guint size; buffer = GST_BUFFER_CAST (item); - size = GST_BUFFER_SIZE (buffer); + size = gst_buffer_get_size (buffer); /* add buffer to the statistics */ if (QUEUE_IS_USING_QUEUE (queue)) { @@ -1905,7 +1915,7 @@ gst_queue2_locked_dequeue (GstQueue2 * queue, gboolean * is_buffer) guint size; buffer = GST_BUFFER_CAST (item); - size = GST_BUFFER_SIZE (buffer); + size = gst_buffer_get_size (buffer); *is_buffer = TRUE; GST_CAT_LOG_OBJECT (queue_dataflow, queue, @@ -2136,7 +2146,7 @@ gst_queue2_chain (GstPad * pad, GstBuffer * buffer) GST_CAT_LOG_OBJECT (queue_dataflow, queue, "received buffer %p of size %d, time %" GST_TIME_FORMAT ", duration %" - GST_TIME_FORMAT, buffer, GST_BUFFER_SIZE (buffer), + GST_TIME_FORMAT, buffer, gst_buffer_get_size (buffer), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), GST_TIME_ARGS (GST_BUFFER_DURATION (buffer))); diff --git a/plugins/elements/gsttee.c b/plugins/elements/gsttee.c index 54700774e1..ef80db4755 100644 --- a/plugins/elements/gsttee.c +++ b/plugins/elements/gsttee.c @@ -641,9 +641,9 @@ gst_tee_do_message (GstTee * tee, GstPad * pad, gpointer data, gboolean is_list) GST_DEBUG_PAD_NAME (pad), data); } else { tee->last_message = - g_strdup_printf ("chain ******* (%s:%s)t (%d bytes, %" - G_GUINT64_FORMAT ") %p", GST_DEBUG_PAD_NAME (pad), - GST_BUFFER_SIZE (data), GST_BUFFER_TIMESTAMP (data), data); + g_strdup_printf ("chain ******* (%s:%s)t (%" G_GSIZE_FORMAT + " bytes, %" G_GUINT64_FORMAT ") %p", GST_DEBUG_PAD_NAME (pad), + gst_buffer_get_size (data), GST_BUFFER_TIMESTAMP (data), data); } GST_OBJECT_UNLOCK (tee); diff --git a/plugins/elements/gsttypefindelement.c b/plugins/elements/gsttypefindelement.c index 1f776d8526..03e66fa639 100644 --- a/plugins/elements/gsttypefindelement.c +++ b/plugins/elements/gsttypefindelement.c @@ -160,9 +160,10 @@ static gboolean gst_type_find_element_activate (GstPad * pad); static gboolean gst_type_find_element_activate_src_pull (GstPad * pad, gboolean active); static GstFlowReturn -gst_type_find_element_chain_do_typefinding (GstTypeFindElement * typefind); -static void -gst_type_find_element_send_cached_events (GstTypeFindElement * typefind); +gst_type_find_element_chain_do_typefinding (GstTypeFindElement * typefind, + gboolean check_avail); +static void gst_type_find_element_send_cached_events (GstTypeFindElement * + typefind); static guint gst_type_find_element_signals[LAST_SIGNAL] = { 0 }; @@ -295,7 +296,7 @@ gst_type_find_element_init (GstTypeFindElement * typefind, typefind->min_probability = 1; typefind->max_probability = GST_TYPE_FIND_MAXIMUM; - typefind->store = NULL; + typefind->adapter = gst_adapter_new (); } static void @@ -303,9 +304,9 @@ gst_type_find_element_dispose (GObject * object) { GstTypeFindElement *typefind = GST_TYPE_FIND_ELEMENT (object); - if (typefind->store) { - gst_buffer_unref (typefind->store); - typefind->store = NULL; + if (typefind->adapter) { + g_object_unref (typefind->adapter); + typefind->adapter = NULL; } if (typefind->force_caps) { @@ -398,18 +399,13 @@ gst_type_find_handle_src_query (GstPad * pad, GstQuery * query) gint64 peer_pos; GstFormat format; - GST_OBJECT_LOCK (typefind); - if (typefind->store == NULL) { - GST_OBJECT_UNLOCK (typefind); - goto out; - } - gst_query_parse_position (query, &format, &peer_pos); + GST_OBJECT_LOCK (typefind); /* FIXME: this code assumes that there's no discont in the queue */ switch (format) { case GST_FORMAT_BYTES: - peer_pos -= GST_BUFFER_SIZE (typefind->store); + peer_pos -= gst_adapter_available (typefind->adapter); break; default: /* FIXME */ @@ -476,6 +472,8 @@ stop_typefinding (GstTypeFindElement * typefind) { GstState state; gboolean push_cached_buffers; + gsize avail; + GstBuffer *buffer; gst_element_get_state (GST_ELEMENT (typefind), &state, NULL, 0); @@ -485,46 +483,52 @@ stop_typefinding (GstTypeFindElement * typefind) push_cached_buffers ? " and pushing cached buffers" : ""); GST_OBJECT_LOCK (typefind); - if (typefind->store) { - GstBuffer *store; + avail = gst_adapter_available (typefind->adapter); + if (avail == 0) + goto no_data; - store = gst_buffer_make_metadata_writable (typefind->store); - typefind->store = NULL; - gst_buffer_set_caps (store, typefind->caps); - GST_OBJECT_UNLOCK (typefind); + buffer = gst_adapter_take_buffer (typefind->adapter, avail); + buffer = gst_buffer_make_metadata_writable (buffer); - if (!push_cached_buffers) { - gst_buffer_unref (store); - } else { - GstPad *peer = gst_pad_get_peer (typefind->src); + gst_buffer_set_caps (buffer, typefind->caps); + GST_OBJECT_UNLOCK (typefind); - typefind->mode = MODE_NORMAL; - - /* make sure the user gets a meaningful error message in this case, - * which is not a core bug or bug of any kind (as the default error - * message emitted by gstpad.c otherwise would make you think) */ - if (peer && GST_PAD_CHAINFUNC (peer) == NULL) { - GST_DEBUG_OBJECT (typefind, "upstream only supports push mode, while " - "downstream element only works in pull mode, erroring out"); - GST_ELEMENT_ERROR (typefind, STREAM, FAILED, - ("%s cannot work in push mode. The operation is not supported " - "with this source element or protocol.", - G_OBJECT_TYPE_NAME (GST_PAD_PARENT (peer))), - ("Downstream pad %s:%s has no chainfunction, and the upstream " - "element does not support pull mode", - GST_DEBUG_PAD_NAME (peer))); - typefind->mode = MODE_ERROR; /* make the chain function error out */ - gst_buffer_unref (store); - } else { - gst_type_find_element_send_cached_events (typefind); - gst_pad_push (typefind->src, store); - } - - if (peer) - gst_object_unref (peer); - } + if (!push_cached_buffers) { + gst_buffer_unref (buffer); } else { + GstPad *peer = gst_pad_get_peer (typefind->src); + + typefind->mode = MODE_NORMAL; + + /* make sure the user gets a meaningful error message in this case, + * which is not a core bug or bug of any kind (as the default error + * message emitted by gstpad.c otherwise would make you think) */ + if (peer && GST_PAD_CHAINFUNC (peer) == NULL) { + GST_DEBUG_OBJECT (typefind, "upstream only supports push mode, while " + "downstream element only works in pull mode, erroring out"); + GST_ELEMENT_ERROR (typefind, STREAM, FAILED, + ("%s cannot work in push mode. The operation is not supported " + "with this source element or protocol.", + G_OBJECT_TYPE_NAME (GST_PAD_PARENT (peer))), + ("Downstream pad %s:%s has no chainfunction, and the upstream " + "element does not support pull mode", GST_DEBUG_PAD_NAME (peer))); + typefind->mode = MODE_ERROR; /* make the chain function error out */ + gst_buffer_unref (buffer); + } else { + gst_type_find_element_send_cached_events (typefind); + gst_pad_push (typefind->src, buffer); + } + if (peer) + gst_object_unref (peer); + } + return; + + /* ERRORS */ +no_data: + { + GST_DEBUG_OBJECT (typefind, "we have no data to typefind"); GST_OBJECT_UNLOCK (typefind); + return; } } @@ -540,37 +544,11 @@ gst_type_find_element_handle_event (GstPad * pad, GstEvent * event) switch (typefind->mode) { case MODE_TYPEFIND: switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_EOS:{ - GstTypeFindProbability prob = 0; - GstCaps *caps = NULL; - + case GST_EVENT_EOS: + { GST_INFO_OBJECT (typefind, "Got EOS and no type found yet"); + gst_type_find_element_chain_do_typefinding (typefind, FALSE); - /* we might not have started typefinding yet because there was not - * enough data so far; just give it a shot now and see what we get */ - GST_OBJECT_LOCK (typefind); - if (typefind->store) { - caps = gst_type_find_helper_for_buffer (GST_OBJECT (typefind), - typefind->store, &prob); - GST_OBJECT_UNLOCK (typefind); - - if (caps && prob >= typefind->min_probability) { - g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], - 0, prob, caps); - } else { - GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, - (NULL), (NULL)); - } - gst_caps_replace (&caps, NULL); - } else { - GST_OBJECT_UNLOCK (typefind); - /* keep message in sync with the one in the pad activate function */ - GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, - (_("Stream contains no data.")), - ("Can't typefind empty stream")); - } - - stop_typefinding (typefind); res = gst_pad_push_event (typefind->src, event); break; } @@ -580,7 +558,7 @@ gst_type_find_element_handle_event (GstPad * pad, GstEvent * event) (GFunc) gst_mini_object_unref, NULL); g_list_free (typefind->cached_events); typefind->cached_events = NULL; - gst_buffer_replace (&typefind->store, NULL); + gst_adapter_clear (typefind->adapter); GST_OBJECT_UNLOCK (typefind); /* fall through */ case GST_EVENT_FLUSH_START: @@ -644,28 +622,36 @@ gst_type_find_element_setcaps (GstPad * pad, GstCaps * caps) /* Shortcircuit typefinding if we get caps */ if (typefind->mode == MODE_TYPEFIND) { + GstBuffer *buffer; + gsize avail; + GST_DEBUG_OBJECT (typefind, "Skipping typefinding, using caps from " "upstream buffer: %" GST_PTR_FORMAT, caps); typefind->mode = MODE_NORMAL; gst_type_find_element_send_cached_events (typefind); GST_OBJECT_LOCK (typefind); - if (typefind->store) { - GstBuffer *store; + avail = gst_adapter_available (typefind->adapter); + if (avail == 0) + goto no_data; - store = gst_buffer_make_metadata_writable (typefind->store); - typefind->store = NULL; - gst_buffer_set_caps (store, typefind->caps); - GST_OBJECT_UNLOCK (typefind); + buffer = gst_adapter_take_buffer (typefind->adapter, avail); + buffer = gst_buffer_make_metadata_writable (buffer); + gst_buffer_set_caps (buffer, typefind->caps); + GST_OBJECT_UNLOCK (typefind); - GST_DEBUG_OBJECT (typefind, "Pushing store: %d", GST_BUFFER_SIZE (store)); - gst_pad_push (typefind->src, store); - } else { - GST_OBJECT_UNLOCK (typefind); - } + GST_DEBUG_OBJECT (typefind, "Pushing buffer: %d", avail); + gst_pad_push (typefind->src, buffer); } return TRUE; + +no_data: + { + GST_DEBUG_OBJECT (typefind, "no data to push"); + GST_OBJECT_UNLOCK (typefind); + return TRUE; + } } static gchar * @@ -769,15 +755,13 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer) buffer = gst_buffer_make_metadata_writable (buffer); gst_buffer_set_caps (buffer, typefind->caps); return gst_pad_push (typefind->src, buffer); - case MODE_TYPEFIND:{ + case MODE_TYPEFIND: + { GST_OBJECT_LOCK (typefind); - if (typefind->store) - typefind->store = gst_buffer_join (typefind->store, buffer); - else - typefind->store = buffer; + gst_adapter_push (typefind->adapter, buffer); GST_OBJECT_UNLOCK (typefind); - res = gst_type_find_element_chain_do_typefinding (typefind); + res = gst_type_find_element_chain_do_typefinding (typefind, TRUE); if (typefind->mode == MODE_ERROR) res = GST_FLOW_ERROR; @@ -793,62 +777,93 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer) } static GstFlowReturn -gst_type_find_element_chain_do_typefinding (GstTypeFindElement * typefind) +gst_type_find_element_chain_do_typefinding (GstTypeFindElement * typefind, + gboolean check_avail) { GstTypeFindProbability probability; GstCaps *caps; + gsize avail; + const guint8 *data; + gboolean have_min, have_max; GST_OBJECT_LOCK (typefind); - if (GST_BUFFER_SIZE (typefind->store) < TYPE_FIND_MIN_SIZE) { - GST_DEBUG_OBJECT (typefind, "not enough data for typefinding yet " - "(%u bytes)", GST_BUFFER_SIZE (typefind->store)); - GST_OBJECT_UNLOCK (typefind); - return GST_FLOW_OK; + avail = gst_adapter_available (typefind->adapter); + + if (check_avail) { + have_min = avail >= TYPE_FIND_MIN_SIZE; + have_max = avail >= TYPE_FIND_MAX_SIZE; + } else { + have_min = TRUE; + have_max = TRUE; } - caps = gst_type_find_helper_for_buffer (GST_OBJECT (typefind), - typefind->store, &probability); - if (caps == NULL && GST_BUFFER_SIZE (typefind->store) > TYPE_FIND_MAX_SIZE) { - GST_OBJECT_UNLOCK (typefind); - GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, (NULL), (NULL)); - stop_typefinding (typefind); - return GST_FLOW_ERROR; - } else if (caps == NULL) { - GST_OBJECT_UNLOCK (typefind); - GST_DEBUG_OBJECT (typefind, "no caps found with %u bytes of data, " - "waiting for more data", GST_BUFFER_SIZE (typefind->store)); - return GST_FLOW_OK; - } + if (!have_min) + goto not_enough_data; + + /* map all available data */ + data = gst_adapter_map (typefind->adapter, avail); + caps = gst_type_find_helper_for_data (GST_OBJECT (typefind), + data, avail, &probability); + gst_adapter_unmap (typefind->adapter, 0); + + if (caps == NULL && have_max) + goto no_type_found; + else if (caps == NULL) + goto wait_for_data; /* found a type */ - if (probability < typefind->min_probability) { - GST_DEBUG_OBJECT (typefind, "found caps %" GST_PTR_FORMAT ", but " - "probability is %u which is lower than the required minimum of %u", - caps, probability, typefind->min_probability); - - gst_caps_replace (&caps, NULL); - - if (GST_BUFFER_SIZE (typefind->store) >= TYPE_FIND_MAX_SIZE) { - GST_OBJECT_UNLOCK (typefind); - GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, (NULL), (NULL)); - stop_typefinding (typefind); - return GST_FLOW_ERROR; - } - - GST_OBJECT_UNLOCK (typefind); - GST_DEBUG_OBJECT (typefind, "waiting for more data to try again"); - return GST_FLOW_OK; - } + if (probability < typefind->min_probability) + goto low_probability; GST_OBJECT_UNLOCK (typefind); - /* probability is good enough too, so let's make it known ... */ + /* probability is good enough too, so let's make it known ... emiting this + * signal calls our object handler which sets the caps. */ g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, probability, caps); /* .. and send out the accumulated data */ stop_typefinding (typefind); gst_caps_unref (caps); + return GST_FLOW_OK; + +not_enough_data: + { + GST_DEBUG_OBJECT (typefind, "not enough data for typefinding yet " + "(%" G_GSIZE_FORMAT " bytes)", avail); + GST_OBJECT_UNLOCK (typefind); + return GST_FLOW_OK; + } +no_type_found: + { + GST_OBJECT_UNLOCK (typefind); + GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, (NULL), (NULL)); + stop_typefinding (typefind); + return GST_FLOW_ERROR; + } +wait_for_data: + { + GST_DEBUG_OBJECT (typefind, + "no caps found with %" G_GSIZE_FORMAT " bytes of data, " + "waiting for more data", avail); + GST_OBJECT_UNLOCK (typefind); + return GST_FLOW_OK; + } +low_probability: + { + GST_DEBUG_OBJECT (typefind, "found caps %" GST_PTR_FORMAT ", but " + "probability is %u which is lower than the required minimum of %u", + caps, probability, typefind->min_probability); + + gst_caps_unref (caps); + + if (have_max) + goto no_type_found; + + GST_OBJECT_UNLOCK (typefind); + GST_DEBUG_OBJECT (typefind, "waiting for more data to try again"); + return GST_FLOW_OK; + } } static gboolean diff --git a/plugins/elements/gsttypefindelement.h b/plugins/elements/gsttypefindelement.h index dbce72f7b0..5c34758eac 100644 --- a/plugins/elements/gsttypefindelement.h +++ b/plugins/elements/gsttypefindelement.h @@ -25,11 +25,10 @@ #include #include +#include G_BEGIN_DECLS - - #define GST_TYPE_TYPE_FIND_ELEMENT (gst_type_find_element_get_type ()) #define GST_TYPE_FIND_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_TYPE_FIND_ELEMENT, GstTypeFindElement)) #define GST_IS_TYPE_FIND_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TYPE_FIND_ELEMENT)) @@ -56,7 +55,7 @@ struct _GstTypeFindElement { GstCaps * caps; guint mode; - GstBuffer * store; + GstAdapter * adapter; GList * cached_events; GstCaps * force_caps; diff --git a/tests/examples/adapter/adapter_test.c b/tests/examples/adapter/adapter_test.c index a0781317b1..3bb5b4b565 100644 --- a/tests/examples/adapter/adapter_test.c +++ b/tests/examples/adapter/adapter_test.c @@ -28,6 +28,7 @@ static struct TestParams param_sets[] = { * in 1000 byte blocks */ {25600000, 1000, 200} }; + static const gint n_tests = sizeof (param_sets) / sizeof (struct TestParams); static gint ticks_per_sec; @@ -45,7 +46,10 @@ run_test_take (struct TestParams *params) for (i = 0; i < ntimes; i++) { buf = gst_buffer_new_and_alloc (params->write_size); - memset (GST_BUFFER_DATA (buf), 0, params->write_size); + + data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE); + memset (data, 0, params->write_size); + gst_buffer_unmap (buf, data, params->write_size); gst_adapter_push (adapter, buf); } @@ -70,10 +74,14 @@ run_test_take_buffer (struct TestParams *params) GstBuffer *buf; int i; gint ntimes = params->tot_size / params->write_size; + guint8 *data; for (i = 0; i < ntimes; i++) { buf = gst_buffer_new_and_alloc (params->write_size); - memset (GST_BUFFER_DATA (buf), 0, params->write_size); + + data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE); + memset (data, 0, params->write_size); + gst_buffer_unmap (buf, data, params->write_size); gst_adapter_push (adapter, buf); } diff --git a/tools/gst-launch.c b/tools/gst-launch.c index eb37b43233..823bbe4792 100644 --- a/tools/gst-launch.c +++ b/tools/gst-launch.c @@ -370,8 +370,8 @@ print_tag (const GstTagList * list, const gchar * tag, gpointer unused) caps_str = GST_BUFFER_CAPS (img) ? gst_caps_to_string (GST_BUFFER_CAPS (img)) : g_strdup ("unknown"); - str = g_strdup_printf ("buffer of %u bytes, type: %s", - GST_BUFFER_SIZE (img), caps_str); + str = g_strdup_printf ("buffer of %" G_GSIZE_FORMAT " bytes, type: %s", + gst_buffer_get_size (img), caps_str); g_free (caps_str); } else { str = g_strdup ("NULL buffer");