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:
* @pad: the pad to attach the bytestream to
GstByteStream *bs = g_new (GstByteStream, 1);
bs->pad = pad;
- bs->event = NULL;
- bs->buflist = NULL;
- bs->headbufavail = 0;
- bs->listavail = 0;
- bs->assembled = NULL;
- bs->offset = 0LL;
- bs->in_seek = FALSE;
+ gst_bytestream_init (bs);
return bs;
}
void
gst_bytestream_destroy (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);
- if (bs->assembled)
- g_free (bs->assembled);
+ gst_bytestream_exit (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:
*
* The fundamental structure is a singly-linked list of buffers. The
bs_print ("peek_bytes: asking for %d bytes", len);
if (bs->assembled) {
+ if (bs->assembled_len >= len) {
+ *data = bs->assembled;
+ return len;
+ }
g_free (bs->assembled);
bs->assembled = NULL;
}
/* we keep state of assembled pieces */
guint8 *assembled;
- guint32 assembled_len;
+ guint32 assembled_len; /* only valid when assembled != NULL */
/* this is needed for gst_bytestream_tell */
guint64 offset;
GstByteStream* gst_bytestream_new (GstPad *pad);
void gst_bytestream_destroy (GstByteStream *bs);
+void gst_bytestream_reset (GstByteStream *bs);
guint32 gst_bytestream_read (GstByteStream *bs, GstBuffer** buf, guint32 len);
guint64 gst_bytestream_tell (GstByteStream *bs);
guint64 gst_bytestream_length (GstByteStream *bs);