- added support for _reset so PLAYING -> READY -> PLAYING can easily be done without destroying a bytestream first

Original commit message from CVS:
- added support for _reset so PLAYING -> READY -> PLAYING can easily be done without destroying a bytestream first
- minor performace improvement on data request (hope it doesn't break anything - if it does revert the changes to gst_bytestream_peek_bytes
This commit is contained in:
Benjamin Otte 2003-03-19 21:16:04 +00:00
parent 38a25af608
commit d5caf284b3
2 changed files with 44 additions and 22 deletions

View file

@ -52,6 +52,34 @@
static guint8 *gst_bytestream_assemble (GstByteStream * bs, guint32 len); static guint8 *gst_bytestream_assemble (GstByteStream * bs, guint32 len);
static inline void
gst_bytestream_init (GstByteStream *bs)
{
bs->event = NULL;
bs->buflist = NULL;
bs->headbufavail = 0;
bs->listavail = 0;
bs->assembled = NULL;
bs->offset = 0LL;
bs->in_seek = FALSE;
}
static inline void
gst_bytestream_exit (GstByteStream *bs)
{
GSList *walk;
if (bs->event)
gst_event_unref (bs->event);
walk = bs->buflist;
while (walk) {
gst_buffer_unref (GST_BUFFER (walk->data));
walk = g_slist_next (walk);
}
g_slist_free (bs->buflist);
g_free (bs->assembled);
}
/** /**
* gst_bytestream_new: * gst_bytestream_new:
* @pad: the pad to attach the bytestream to * @pad: the pad to attach the bytestream to
@ -66,13 +94,7 @@ gst_bytestream_new (GstPad * pad)
GstByteStream *bs = g_new (GstByteStream, 1); GstByteStream *bs = g_new (GstByteStream, 1);
bs->pad = pad; bs->pad = pad;
bs->event = NULL; gst_bytestream_init (bs);
bs->buflist = NULL;
bs->headbufavail = 0;
bs->listavail = 0;
bs->assembled = NULL;
bs->offset = 0LL;
bs->in_seek = FALSE;
return bs; return bs;
} }
@ -86,22 +108,17 @@ gst_bytestream_new (GstPad * pad)
void void
gst_bytestream_destroy (GstByteStream * bs) gst_bytestream_destroy (GstByteStream * bs)
{ {
GSList *walk; gst_bytestream_exit (bs);
if (bs->event)
gst_event_unref (bs->event);
walk = bs->buflist;
while (walk) {
gst_buffer_unref (GST_BUFFER (walk->data));
walk = g_slist_next (walk);
}
g_slist_free (bs->buflist);
if (bs->assembled)
g_free (bs->assembled);
g_free (bs); g_free (bs);
} }
void
gst_bytestream_reset (GstByteStream *bs)
{
/* free all data */
gst_bytestream_exit (bs);
/* reset data to clean state */
gst_bytestream_init (bs);
}
/* HOW THIS WORKS: /* HOW THIS WORKS:
* *
* The fundamental structure is a singly-linked list of buffers. The * The fundamental structure is a singly-linked list of buffers. The
@ -328,6 +345,10 @@ gst_bytestream_peek_bytes (GstByteStream *bs, guint8** data, guint32 len)
bs_print ("peek_bytes: asking for %d bytes", len); bs_print ("peek_bytes: asking for %d bytes", len);
if (bs->assembled) { if (bs->assembled) {
if (bs->assembled_len >= len) {
*data = bs->assembled;
return len;
}
g_free (bs->assembled); g_free (bs->assembled);
bs->assembled = NULL; bs->assembled = NULL;
} }

View file

@ -37,7 +37,7 @@ struct _GstByteStream {
/* we keep state of assembled pieces */ /* we keep state of assembled pieces */
guint8 *assembled; guint8 *assembled;
guint32 assembled_len; guint32 assembled_len; /* only valid when assembled != NULL */
/* this is needed for gst_bytestream_tell */ /* this is needed for gst_bytestream_tell */
guint64 offset; guint64 offset;
@ -50,6 +50,7 @@ struct _GstByteStream {
GstByteStream* gst_bytestream_new (GstPad *pad); GstByteStream* gst_bytestream_new (GstPad *pad);
void gst_bytestream_destroy (GstByteStream *bs); void gst_bytestream_destroy (GstByteStream *bs);
void gst_bytestream_reset (GstByteStream *bs);
guint32 gst_bytestream_read (GstByteStream *bs, GstBuffer** buf, guint32 len); guint32 gst_bytestream_read (GstByteStream *bs, GstBuffer** buf, guint32 len);
guint64 gst_bytestream_tell (GstByteStream *bs); guint64 gst_bytestream_tell (GstByteStream *bs);
guint64 gst_bytestream_length (GstByteStream *bs); guint64 gst_bytestream_length (GstByteStream *bs);