mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-07-06 22:56:07 +00:00
Added buffer shrinking.
Original commit message from CVS: Added buffer shrinking.
This commit is contained in:
parent
ed5460e787
commit
2f4462aa0f
|
@ -58,11 +58,13 @@ gst_bytestream_destroy (GstByteStream *bs)
|
||||||
g_free (bs);
|
g_free (bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
GstBuffer*
|
static inline guint64
|
||||||
gst_bytestream_peek (GstByteStream *bs, guint64 len)
|
gst_bytestream_fill (GstByteStream *bs, guint64 len)
|
||||||
{
|
{
|
||||||
GstBuffer *buf;
|
GstBuffer *buf;
|
||||||
|
|
||||||
|
g_print ("fill %08llx %08llx\n", len, bs->pos);
|
||||||
|
|
||||||
while ((bs->index + len) > bs->size) {
|
while ((bs->index + len) > bs->size) {
|
||||||
buf = gst_pad_pull (bs->pad);
|
buf = gst_pad_pull (bs->pad);
|
||||||
|
|
||||||
|
@ -75,6 +77,40 @@ gst_bytestream_peek (GstByteStream *bs, guint64 len)
|
||||||
bs->size = GST_BUFFER_SIZE (bs->buffer);
|
bs->size = GST_BUFFER_SIZE (bs->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
gst_bytestream_shrink (GstByteStream *bs, guint64 len)
|
||||||
|
{
|
||||||
|
GstBuffer *newbuf;
|
||||||
|
|
||||||
|
bs->index += len;
|
||||||
|
bs->pos += len;
|
||||||
|
|
||||||
|
if ((GST_BUFFER_SIZE (bs->buffer) - bs->index) > 1024 * 1024) {
|
||||||
|
g_print ("shrink%08llx %08llx, %08llx\n", len, bs->pos,
|
||||||
|
GST_BUFFER_SIZE (bs->buffer) - bs->index);
|
||||||
|
|
||||||
|
newbuf = gst_buffer_create_sub (bs->buffer, bs->index,
|
||||||
|
GST_BUFFER_SIZE (bs->buffer) - bs->index);
|
||||||
|
bs->size = GST_BUFFER_SIZE (newbuf);
|
||||||
|
gst_buffer_unref (bs->buffer);
|
||||||
|
bs->index = 0;
|
||||||
|
|
||||||
|
bs->buffer = newbuf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GstBuffer*
|
||||||
|
gst_bytestream_peek (GstByteStream *bs, guint64 len)
|
||||||
|
{
|
||||||
|
GstBuffer *buf;
|
||||||
|
|
||||||
|
g_print ("peek %08llx %08llx\n", len, bs->pos);
|
||||||
|
|
||||||
|
len = gst_bytestream_fill (bs, len);
|
||||||
|
|
||||||
buf = gst_buffer_create_sub (bs->buffer, bs->index, len);
|
buf = gst_buffer_create_sub (bs->buffer, bs->index, len);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -85,9 +121,11 @@ gst_bytestream_read (GstByteStream *bs, guint64 len)
|
||||||
{
|
{
|
||||||
GstBuffer *buf;
|
GstBuffer *buf;
|
||||||
|
|
||||||
|
g_print ("read %08llx %08llx\n", len, bs->pos);
|
||||||
|
|
||||||
buf = gst_bytestream_peek (bs, len);
|
buf = gst_bytestream_peek (bs, len);
|
||||||
bs->index += len;
|
|
||||||
bs->pos += len;
|
gst_bytestream_shrink (bs, GST_BUFFER_SIZE (buf));
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -98,11 +136,19 @@ gst_bytestream_seek (GstByteStream *bs, guint64 offset)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint
|
gint64
|
||||||
gst_bytestream_flush (GstByteStream *bs, guint64 len)
|
gst_bytestream_flush (GstByteStream *bs, guint64 len)
|
||||||
{
|
{
|
||||||
|
guint64 outlen;
|
||||||
|
|
||||||
|
g_print ("flush %08llx %08llx\n", len, bs->pos);
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
return GST_BUFFER_SIZE (gst_bytestream_read (bs, len));
|
outlen = gst_bytestream_fill (bs, len);
|
||||||
|
|
||||||
|
gst_bytestream_shrink (bs, outlen);
|
||||||
|
|
||||||
|
return outlen;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ void gst_bytestream_destroy (GstByteStream *bs);
|
||||||
GstBuffer* gst_bytestream_peek (GstByteStream *bs, guint64 len);
|
GstBuffer* gst_bytestream_peek (GstByteStream *bs, guint64 len);
|
||||||
GstBuffer* gst_bytestream_read (GstByteStream *bs, guint64 len);
|
GstBuffer* gst_bytestream_read (GstByteStream *bs, guint64 len);
|
||||||
gboolean gst_bytestream_seek (GstByteStream *bs, guint64 offset);
|
gboolean gst_bytestream_seek (GstByteStream *bs, guint64 offset);
|
||||||
gint gst_bytestream_flush (GstByteStream *bs, guint64 len);
|
gint64 gst_bytestream_flush (GstByteStream *bs, guint64 len);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in a new issue