Added gst_bytestream_get_timestamp() call to get timestamp of data at the front of...
authorDavid I. Lehn <dlehn@users.sourceforge.net>
Fri, 10 May 2002 08:16:18 +0000 (08:16 +0000)
committerDavid I. Lehn <dlehn@users.sourceforge.net>
Fri, 10 May 2002 08:16:18 +0000 (08:16 +0000)
Original commit message from CVS:
Added gst_bytestream_get_timestamp() call to get timestamp of data at
the front of the stream.  If no data in stream, loads 1 byte to get a
new buffer and uses its timestamp.

Does nothing to handle readers that try to read data lengths that span
buffers with multiple timestamps.

_get_timestamp() now used when creating new buffers.

libs/gst/bytestream/bytestream.c
libs/gst/bytestream/bytestream.h

index 4660329..9803756 100644 (file)
@@ -236,6 +236,7 @@ gst_bytestream_peek (GstByteStream * bs, guint32 len)
     retbuf = gst_buffer_new ();
     GST_BUFFER_SIZE (retbuf) = len;
     GST_BUFFER_DATA (retbuf) = gst_bytestream_assemble (bs, len);
+    GST_BUFFER_TIMESTAMP (retbuf) = gst_bytestream_get_timestamp (bs);
     if (GST_BUFFER_OFFSET (headbuf) != -1)
       GST_BUFFER_OFFSET (retbuf) = GST_BUFFER_OFFSET (headbuf) + (GST_BUFFER_SIZE (headbuf) - bs->headbufavail);
   }
@@ -465,6 +466,39 @@ gst_bytestream_get_status (GstByteStream *bs,
     }
 }
 
+/**
+ * gst_bytestream_get_timestamp
+ * @bs: a bytestream
+ *
+ * Get the timestamp of the first data in the bytestream.  If no data
+ * exists 1 byte is read to load a new buffer.
+ *
+ * This function will not check input buffer boundries.  It is  possible
+ * the next read could span two or more input buffers with different
+ * timestamps.
+ */
+guint64
+gst_bytestream_get_timestamp (GstByteStream *bs)
+{
+  GstBuffer *headbuf;
+
+  g_return_val_if_fail (bs != NULL, 0);
+
+  bs_print ("get_timestamp: asking for %d bytes\n", len);
+
+  /* make sure we have a buffer */
+  if (bs->listavail == 0) {
+    bs_print ("gst_timestamp: fetching a buffer\n");
+    if (!gst_bytestream_fill_bytes (bs, 1))
+      return 0;
+  }
+
+  /* extract the head buffer */
+  headbuf = GST_BUFFER (bs->buflist->data);
+
+  return GST_BUFFER_TIMESTAMP (headbuf);
+}
+
 void
 gst_bytestream_print_status (GstByteStream * bs)
 {
index ab4c9fe..b92405e 100644 (file)
@@ -53,6 +53,7 @@ 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_get_status      (GstByteStream *bs, guint32 *avail_out, GstEvent **event_out);
+guint64                        gst_bytestream_get_timestamp    (GstByteStream *bs);
 
 void                   gst_bytestream_print_status     (GstByteStream *bs);