mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-07 07:55:41 +00:00
Make bytestream functions return a GstBuffer so that we can do proper refcounting.
Original commit message from CVS: Make bytestream functions return a GstBuffer so that we can do proper refcounting. Added first optimisations.
This commit is contained in:
parent
3557396a0a
commit
55c2704ced
2 changed files with 29 additions and 43 deletions
|
@ -24,6 +24,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <gst/gstinfo.h>
|
||||||
#include "gstbytestream.h"
|
#include "gstbytestream.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,16 +35,16 @@
|
||||||
*
|
*
|
||||||
* Returns: a new #GstByteStream object
|
* Returns: a new #GstByteStream object
|
||||||
*/
|
*/
|
||||||
GstByteStream *
|
GstByteStream*
|
||||||
gst_bytestream_new (GstPad * pad)
|
gst_bytestream_new (GstPad *pad)
|
||||||
{
|
{
|
||||||
GstByteStream *bs = g_new (GstByteStream, 1);
|
GstByteStream *bs = g_new (GstByteStream, 1);
|
||||||
|
|
||||||
bs->pad = pad;
|
bs->pad = pad;
|
||||||
bs->data = NULL;
|
bs->buffer = NULL;
|
||||||
bs->size = 0;
|
|
||||||
bs->index = 0;
|
bs->index = 0;
|
||||||
bs->pos = 0;
|
bs->pos = 0;
|
||||||
|
bs->size = 0;
|
||||||
|
|
||||||
return bs;
|
return bs;
|
||||||
}
|
}
|
||||||
|
@ -51,55 +52,44 @@ gst_bytestream_new (GstPad * pad)
|
||||||
void
|
void
|
||||||
gst_bytestream_destroy (GstByteStream *bs)
|
gst_bytestream_destroy (GstByteStream *bs)
|
||||||
{
|
{
|
||||||
if (bs->data) {
|
if (bs->buffer) {
|
||||||
g_free (bs->data);
|
gst_buffer_unref (bs->buffer);
|
||||||
}
|
}
|
||||||
g_free (bs);
|
g_free (bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint64
|
GstBuffer*
|
||||||
gst_bytestream_bytes_fill (GstByteStream *bs, guint64 len)
|
gst_bytestream_bytes_peek (GstByteStream *bs, guint64 len)
|
||||||
{
|
{
|
||||||
size_t oldlen;
|
|
||||||
GstBuffer *buf;
|
GstBuffer *buf;
|
||||||
|
|
||||||
while ((bs->index + len) > bs->size) {
|
while ((bs->index + len) > bs->size) {
|
||||||
buf = gst_pad_pull (bs->pad);
|
buf = gst_pad_pull (bs->pad);
|
||||||
oldlen = bs->size - bs->index;
|
|
||||||
memmove (bs->data, bs->data + bs->index, oldlen);
|
if (!bs->buffer) {
|
||||||
bs->size = oldlen + GST_BUFFER_SIZE (buf);
|
bs->buffer = buf;
|
||||||
bs->index = 0;
|
|
||||||
bs->data = realloc (bs->data, bs->size);
|
|
||||||
if (!bs->data) {
|
|
||||||
fprintf (stderr, "realloc failed: d:%p s:%llu\n", bs->data, bs->size);
|
|
||||||
}
|
}
|
||||||
memcpy (bs->data + oldlen, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
else {
|
||||||
|
bs->buffer = gst_buffer_merge (bs->buffer, buf);
|
||||||
|
}
|
||||||
|
bs->size = GST_BUFFER_SIZE (bs->buffer);
|
||||||
}
|
}
|
||||||
g_assert ((bs->index + len) <= bs->size);
|
|
||||||
|
|
||||||
return len;
|
buf = gst_buffer_create_sub (bs->buffer, bs->index, len);
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint
|
GstBuffer*
|
||||||
gst_bytestream_bytes_peek (GstByteStream *bs, guint8 **buf, guint64 len)
|
gst_bytestream_bytes_read (GstByteStream *bs, guint64 len)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (len > 0, 0);
|
GstBuffer *buf;
|
||||||
g_return_val_if_fail (buf, 0);
|
|
||||||
|
|
||||||
gst_bytestream_bytes_fill (bs, len);
|
buf = gst_bytestream_bytes_peek (bs, len);
|
||||||
*buf = bs->data + bs->index;
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
gint
|
|
||||||
gst_bytestream_bytes_read (GstByteStream *bs, guint8 **buf, guint64 len)
|
|
||||||
{
|
|
||||||
len = gst_bytestream_bytes_peek (bs, buf, len);
|
|
||||||
bs->index += len;
|
bs->index += len;
|
||||||
bs->pos += len;
|
bs->pos += len;
|
||||||
|
|
||||||
return len;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
@ -111,12 +101,8 @@ gst_bytestream_bytes_seek (GstByteStream *bs, guint64 offset)
|
||||||
gint
|
gint
|
||||||
gst_bytestream_bytes_flush (GstByteStream *bs, guint64 len)
|
gst_bytestream_bytes_flush (GstByteStream *bs, guint64 len)
|
||||||
{
|
{
|
||||||
guint8 *buf;
|
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
len = gst_bytestream_bytes_read (bs, &buf, len);
|
return GST_BUFFER_SIZE (gst_bytestream_bytes_read (bs, len));
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,17 +35,17 @@ typedef struct _GstByteStream GstByteStream;
|
||||||
struct _GstByteStream
|
struct _GstByteStream
|
||||||
{
|
{
|
||||||
GstPad *pad;
|
GstPad *pad;
|
||||||
guint8 *data;
|
GstBuffer *buffer;
|
||||||
guint64 size;
|
|
||||||
guint64 index;
|
guint64 index;
|
||||||
guint64 pos;
|
guint64 pos;
|
||||||
|
guint64 size;
|
||||||
};
|
};
|
||||||
|
|
||||||
GstByteStream* gst_bytestream_new (GstPad *pad);
|
GstByteStream* gst_bytestream_new (GstPad *pad);
|
||||||
void gst_bytestream_destroy (GstByteStream *bs);
|
void gst_bytestream_destroy (GstByteStream *bs);
|
||||||
|
|
||||||
gint gst_bytestream_bytes_peek (GstByteStream *bs, guint8 **buf, guint64 len);
|
GstBuffer* gst_bytestream_bytes_peek (GstByteStream *bs, guint64 len);
|
||||||
gint gst_bytestream_bytes_read (GstByteStream *bs, guint8 **buf, guint64 len);
|
GstBuffer* gst_bytestream_bytes_read (GstByteStream *bs, guint64 len);
|
||||||
gboolean gst_bytestream_bytes_seek (GstByteStream *bs, guint64 offset);
|
gboolean gst_bytestream_bytes_seek (GstByteStream *bs, guint64 offset);
|
||||||
gint gst_bytestream_bytes_flush (GstByteStream *bs, guint64 len);
|
gint gst_bytestream_bytes_flush (GstByteStream *bs, guint64 len);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue