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;
}
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
/* 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 */
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.
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 */
* 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);
*/
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);
/* <private> */
gpointer _gst_reserved[GST_PADDING];
GType gst_type_find_get_type (void);
/* typefind function interface */
-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_simple (GstTypeFind * find,
- guint probability,
- const char * media_type,
- const char * fieldname, ...);
+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_simple (GstTypeFind * find,
+ guint probability,
+ const char * media_type,
+ const char * fieldname, ...);
guint64 gst_type_find_get_length (GstTypeFind * find);
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;
}
gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
{
GstBuffer *result;
+ gsize size1, size2;
+
+ size1 = gst_buffer_get_size (buf1);
+ size2 = gst_buffer_get_size (buf2);
- result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
+ result = gst_buffer_span (buf1, 0, buf2, size1 + size2);
gst_buffer_unref (buf1);
gst_buffer_unref (buf2);
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 *
{
guint8 *data;
gint i;
- gint size;
+ gsize size;
gchar *string;
GstBuffer *buffer;
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++) {
}
string[size * 2] = 0;
+ gst_buffer_unmap (buffer, data, size);
+
return string;
}
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;
data[i] = (guint8) strtoul (ts, NULL, 16);
}
+ gst_buffer_unmap (buffer, data, size);
gst_value_take_buffer (dest, buffer);
wrong_char:
{
gst_buffer_unref (buffer);
+ gst_buffer_unmap (buffer, data, size);
return FALSE;
}
}
/* 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
GstClockTime timestamp;
guint64 distance;
- guint scan_offset;
+ gsize scan_offset;
GSList *scan_entry;
+
+ gpointer cdata;
+ gsize csize;
};
#define _do_init(thing) \
/* 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 */
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;
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;
}
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. */
* 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)
/* 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;
/* 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
* @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);
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 */
}
/**
+ * 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
* @dest: (out caller-allocates) (array length=size): the memory to copy into
* 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);
* 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;
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");
/* 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 */
}
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);
/* 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 */
* #NULL if @nbytes bytes are not available
*/
guint8 *
-gst_adapter_take (GstAdapter * adapter, guint nbytes)
+gst_adapter_take (GstAdapter * adapter, gsize nbytes)
{
guint8 *data;
* 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);
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) {
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);
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);
* 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);
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);
*
* Returns: number of bytes available in @adapter
*/
-guint
+gsize
gst_adapter_available (GstAdapter * adapter)
{
g_return_val_if_fail (GST_IS_ADAPTER (adapter), 0);
* 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);
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);
*
* 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);
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 */
if (G_LIKELY (skip + i >= 3)) {
if (G_LIKELY (value))
*value = state;
+ gst_buffer_unmap (buf, odata, osize);
return offset + skip + i - 3;
}
}
/* 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;
}
*
* 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);
/*< 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;
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
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);
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)
/* upstream caps and size suggestions */
GstCaps *sink_suggest;
- guint size_suggest;
+ gsize size_suggest;
gboolean suggest_pending;
gboolean reconfigure;
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,
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;
{
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:
}
static void
-compute_upstream_suggestion (GstBaseTransform * trans, guint expsize,
+compute_upstream_suggestion (GstBaseTransform * trans, gsize expsize,
GstCaps * caps)
{
GstCaps *othercaps;
* 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");
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;
*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 {
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);
/* 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 */
/* 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;
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);
* 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");
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;
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);
}
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);
*/
static gboolean
gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
- guint * size)
+ gsize * size)
{
gboolean res = FALSE;
GstBaseTransformClass *bclass;
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);
GstClockTime running_time;
GstClockTime timestamp;
GstCaps *incaps;
+ gsize insize;
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
}
}
+ 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
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 {
*/
void
gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
- guint size)
+ gsize size)
{
g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
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;
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);
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
}
/**
- * 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
*/
}
/**
- * 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
* @pos: The new position in bits
} 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);
*/
#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
}
/**
- * 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
*/
}
/**
- * 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
* @pos: The new position in bytes
} 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);
*/
#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)
}
/**
- * 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.
- *
- * <note>@buffer must be writable</note>
- *
- * 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
*
}
/**
- * 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.
- *
- * <note>@buffer must be writable</note>
- *
- * 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
*
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;
}
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);
}
/* 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);
}
/**
- * 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
* @data: the data to use
if ((buffer = data->buffer) == NULL)
return NULL;
- bufsize = GST_BUFFER_SIZE (buffer);
+ bufsize = gst_buffer_get_size (buffer);
readsize = MIN (size, bufsize - data->pos);
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;
}
{
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);
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);
/* 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,
* 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;
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;
/* 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
/* 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:
{
typedef struct
{
- guint8 *data; /* buffer data */
- guint size;
+ const guint8 *data; /* buffer data */
+ gsize size;
guint best_probability;
GstCaps *caps;
GstTypeFindFactory *factory; /* for logging */
* 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;
}
/**
- * 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
* 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
*
* 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;
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;
}
/**
+ * 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)
* @extension: an extension
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);
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);
}
{
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);
/* 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));
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);
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 {
*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;
}
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);
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;
{
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;
}
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;
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;
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;
}
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:
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 {
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 !");
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;
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;
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);
GST_LOG_OBJECT (src, "post handoff emit");
}
- src->bytes_sent += GST_BUFFER_SIZE (buf);
+ src->bytes_sent += size;
*ret = buf;
return GST_FLOW_OK;
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
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
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)) {
}
/* 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
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
fdsink->fd, g_strerror (errno)));
}
}
+ gst_buffer_unmap (buffer, data, size);
return GST_FLOW_ERROR;
}
}
gssize readbytes;
guint blocksize;
GstClockTime timeout;
+ guint8 *data;
+ gsize maxsize;
#ifndef HAVE_WIN32
gboolean try_again;
/* 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;
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.");
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;
}
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);
filesink->current_pos += size;
}
+ gst_buffer_unmap (buffer, data, size);
return GST_FLOW_OK;
("%s", g_strerror (errno)));
}
}
+ gst_buffer_unmap (buffer, data, size);
return GST_FLOW_ERROR;
}
}
{
int ret;
GstBuffer *buf;
+ guint8 *data;
+ gsize size;
if (G_UNLIKELY (src->read_position != offset)) {
off_t res;
}
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;
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;
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;
}
{
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;
}
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];
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);
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);
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) {
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)
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);
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
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;
/* 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);
"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 */
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
/* 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);
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;
read_error:
{
GST_DEBUG_OBJECT (queue, "we have a read error");
+ gst_buffer_unmap (buf, data, 0);
gst_buffer_unref (buf);
return read_return;
}
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;
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));
queue->cur_level.bytes, QUEUE_MAX_BYTES (queue));
GST_QUEUE2_SIGNAL_ADD (queue);
- };
+ }
+
+ gst_buffer_unmap (buffer, odata, osize);
return TRUE;
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:
("%s", g_strerror (errno)));
}
}
+ gst_buffer_unmap (buffer, odata, osize);
return FALSE;
}
}
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)) {
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,
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)));
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);
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 };
typefind->min_probability = 1;
typefind->max_probability = GST_TYPE_FIND_MAXIMUM;
- typefind->store = NULL;
+ typefind->adapter = gst_adapter_new ();
}
static void
{
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) {
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 */
{
GstState state;
gboolean push_cached_buffers;
+ gsize avail;
+ GstBuffer *buffer;
gst_element_get_state (GST_ELEMENT (typefind), &state, NULL, 0);
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);
-
- 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);
- }
+ gst_buffer_set_caps (buffer, typefind->caps);
+ GST_OBJECT_UNLOCK (typefind);
- 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;
}
}
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;
}
(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:
/* 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 *
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;
}
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) {
+ 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;
+ }
+
+ 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)
+ goto low_probability;
+ GST_OBJECT_UNLOCK (typefind);
+
+ /* 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 "
- "(%u bytes)", GST_BUFFER_SIZE (typefind->store));
+ "(%" G_GSIZE_FORMAT " bytes)", avail);
GST_OBJECT_UNLOCK (typefind);
return GST_FLOW_OK;
}
-
- 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) {
+no_type_found:
+ {
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) {
+ }
+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);
- 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;
}
-
- /* found a type */
- if (probability < typefind->min_probability) {
+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_replace (&caps, NULL);
+ gst_caps_unref (caps);
- 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;
- }
+ 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;
}
- GST_OBJECT_UNLOCK (typefind);
-
- /* probability is good enough too, so let's make it known ... */
- 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;
}
static gboolean
#include <gst/gstinfo.h>
#include <gst/gstelement.h>
+#include <gst/base/gstadapter.h>
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))
GstCaps * caps;
guint mode;
- GstBuffer * store;
+ GstAdapter * adapter;
GList * cached_events;
GstCaps * force_caps;
* in 1000 byte blocks */
{25600000, 1000, 200}
};
+
static const gint n_tests = sizeof (param_sets) / sizeof (struct TestParams);
static gint ticks_per_sec;
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);
}
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);
}
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");