[gst-cvs] CVS: gstreamer/libs/bytestream gstbytestream.c,1.2,1.3 gstbytestream.h,1.2,1.3

Wim Taymans wtay at users.sourceforge.net
Sun Oct 21 12:15:14 PDT 2001


Update of /cvsroot/gstreamer/gstreamer/libs/bytestream
In directory usw-pr-cvs1:/tmp/cvs-serv11956

Modified Files:
	gstbytestream.c gstbytestream.h 
Log Message:
Applied vishnus patch:
* 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.[A


Index: gstbytestream.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/libs/bytestream/gstbytestream.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- gstbytestream.c	2001/10/17 10:21:25	1.2
+++ gstbytestream.c	2001/10/21 19:14:48	1.3
@@ -118,6 +118,10 @@
 
   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 @@
   // 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 @@
   // 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 @@
   // 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);
@@ -309,21 +316,33 @@
 gboolean
 gst_bytestream_flush (GstByteStream * bs, guint32 len)
 {
-  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)
+{
+  GstBuffer *headbuf;
+
+  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 @@
 
     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
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- gstbytestream.h	2001/10/17 10:21:25	1.2
+++ gstbytestream.h	2001/10/21 19:14:48	1.3
@@ -47,6 +47,7 @@
 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-commits mailing list