[gst-devel] bytestream #1

vishnu at pobox.com vishnu at pobox.com
Sat Oct 20 09:04:14 CEST 2001


The attached patch to bytestream does:

* Check all return codes and reliably return NULL if no more data is
available.

* Split _flush into _flush/_flush_fast.  This is partly to make the code
self-documenting -- the flush in gst_bytestream_read cannot fail.  Also,
this is a slight optimization.

This patch is a prerequisite for a subsequent event handling patch.

-- 
Victory to the Divine Mother!!   ... after all,
  http://sahajayoga.org                http://why-compete.org
-------------- next part --------------
Index: gstbytestream.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/libs/bytestream/gstbytestream.c,v
retrieving revision 1.2
diff -u -p -r1.2 gstbytestream.c
--- gstbytestream.c	2001/10/17 10:21:25	1.2
+++ gstbytestream.c	2001/10/20 15:59:01
@@ -118,6 +118,10 @@ gst_bytestream_get_next_buf (GstByteStre
 
   bs_print ("get_next_buf: pulling buffer\n");
   nextbuf = gst_pad_pull (bs->pad);
+
+  if (!nextbuf)
+    return FALSE;
+
   bs_print ("get_next_buf: got buffer of %d bytes\n", GST_BUFFER_SIZE (nextbuf));
 
   // first see if there are any buffers in the list at all
@@ -175,7 +179,8 @@ gst_bytestream_fill_bytes (GstByteStream
   // as long as we don't have enough, we get more buffers
   while (bs->listavail < len) {
     bs_print ("fill_bytes: there are %d bytes in the list, we need %d\n", bs->listavail, len);
-    gst_bytestream_get_next_buf (bs);
+    if (!gst_bytestream_get_next_buf (bs))
+      return FALSE;
   }
 
   return TRUE;
@@ -195,7 +200,8 @@ gst_bytestream_peek (GstByteStream * bs,
   // make sure we have enough
   bs_print ("peek: there are %d bytes in the list\n", bs->listavail);
   if (len > bs->listavail) {
-    gst_bytestream_fill_bytes (bs, len);
+    if (!gst_bytestream_fill_bytes (bs, len))
+      return NULL;
     bs_print ("peek: there are now %d bytes in the list\n", bs->listavail);
   }
   bs_status (bs);
@@ -243,7 +249,8 @@ gst_bytestream_peek_bytes (GstByteStream
   // make sure we have enough
   bs_print ("peek_bytes: there are %d bytes in the list\n", bs->listavail);
   if (len > bs->listavail) {
-    gst_bytestream_fill_bytes (bs, len);
+    if (!gst_bytestream_fill_bytes (bs, len))
+      return NULL;
     bs_print ("peek_bytes: there are now %d bytes in the list\n", bs->listavail);
   }
   bs_status (bs);
@@ -312,18 +319,30 @@ gst_bytestream_flush (GstByteStream * bs
   GstBuffer *headbuf;
 
   bs_print ("flush: flushing %d bytes\n", len);
-  if (bs->assembled) {
-    g_free (bs->assembled);
-    bs->assembled = NULL;
-  }
 
   // make sure we have enough
   bs_print ("flush: there are %d bytes in the list\n", bs->listavail);
   if (len > bs->listavail) {
-    gst_bytestream_fill_bytes (bs, len);
+    if (!gst_bytestream_fill_bytes (bs, len))
+      return FALSE;
     bs_print ("flush: there are now %d bytes in the list\n", bs->listavail);
   }
 
+  gst_bytestream_flush_fast (bs, len);
+
+  return TRUE;
+}
+
+void
+gst_bytestream_flush_fast (GstByteStream * bs, guint32 len)
+{
+  g_assert (len <= bs->listavail);
+
+  if (bs->assembled) {
+    g_free (bs->assembled);
+    bs->assembled = NULL;
+  }
+
   // repeat until we've flushed enough data
   while (len > 0) {
     headbuf = GST_BUFFER (bs->buflist->data);
@@ -364,15 +383,17 @@ gst_bytestream_flush (GstByteStream * bs
 
     bs_print ("flush: bottom of while(), len is now %d\n", len);
   }
-
-  return TRUE;
 }
 
 GstBuffer *
 gst_bytestream_read (GstByteStream * bs, guint32 len)
 {
   GstBuffer *buf = gst_bytestream_peek (bs, len);
-  gst_bytestream_flush (bs, len);
+  if (!buf)
+    return NULL;
+
+  gst_bytestream_flush_fast (bs, len);
+
   return buf;
 }
 
Index: gstbytestream.h
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/libs/bytestream/gstbytestream.h,v
retrieving revision 1.2
diff -u -p -r1.2 gstbytestream.h
--- gstbytestream.h	2001/10/17 10:21:25	1.2
+++ gstbytestream.h	2001/10/20 15:59:01
@@ -47,6 +47,7 @@ GstBuffer*		gst_bytestream_read		(GstByt
 GstBuffer*		gst_bytestream_peek		(GstByteStream *bs, guint32 len);
 guint8*			gst_bytestream_peek_bytes	(GstByteStream *bs, guint32 len);
 gboolean		gst_bytestream_flush		(GstByteStream *bs, guint32 len);
+void                    gst_bytestream_flush_fast       (GstByteStream * bs, guint32 len);
 
 void 			gst_bytestream_print_status	(GstByteStream *bs);
 


More information about the gstreamer-devel mailing list