diff --git a/libs/bytestream/gstbstest.c b/libs/bytestream/gstbstest.c index 4774d2453a..47445be1cf 100644 --- a/libs/bytestream/gstbstest.c +++ b/libs/bytestream/gstbstest.c @@ -181,6 +181,7 @@ gst_identity_loop (GstElement *element) identity = GST_IDENTITY (element); +/* THIS IS THE BUFFER BASED ONE do { // g_print("\n"); @@ -197,6 +198,23 @@ gst_identity_loop (GstElement *element) exit(1); } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element)); +*/ + +/* THIS IS THE BYTE BASED ONE*/ + do { + for (i=0;icount;i++) { + buf = gst_buffer_new(); + // note that this is dangerous, as it does *NOT* refcount the data, it can go away!!! + GST_BUFFER_DATA(buf) = gst_bytestream2_peek_bytes(identity->bs,identity->byte_size); + GST_BUFFER_SIZE(buf) = identity->byte_size; + GST_BUFFER_FLAG_SET(buf,GST_BUFFER_DONTFREE); + gst_pad_push(identity->srcpad,buf); + gst_bytestream2_flush(identity->bs,identity->byte_size); + } + + exit(1); + } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element)); +/**/ } static void diff --git a/libs/bytestream/gstbytestream2.c b/libs/bytestream/gstbytestream2.c index d3887b8b46..897cde5304 100644 --- a/libs/bytestream/gstbytestream2.c +++ b/libs/bytestream/gstbytestream2.c @@ -176,6 +176,44 @@ gst_bytestream2_peek (GstByteStream2 *bs, guint32 len) { return retbuf; } +guint8 * +gst_bytestream2_peek_bytes (GstByteStream2 *bs, guint32 len) { + GstBuffer *headbuf; + guint8 *data = NULL; + + g_return_val_if_fail(bs != NULL, NULL); + g_return_val_if_fail(len > 0, NULL); + + bs_print("peek_bytes: asking for %d bytes\n",len); + + // make sure we have enough + bs_print("peek_bytes: there are %d bytes in the list\n",bs->listavail); + if (len > bs->listavail) { + gst_bytestream2_fill_bytes(bs,len); + bs_print("peek_bytes: there are now %d bytes in the list\n",bs->listavail); + } + gst_bytestream2_print_status(bs); + + // extract the head buffer + headbuf = GST_BUFFER(bs->buflist->data); + + // if the requested bytes are in the current buffer + bs_print("peek_bytes: headbufavail is %d\n",bs->headbufavail); + if (len <= bs->headbufavail) { + bs_print("peek_bytes: there are enough bytes in headbuf (need %d, have %d)\n",len,bs->headbufavail); + // create a sub-buffer of the headbuf + data = GST_BUFFER_DATA(headbuf) + (GST_BUFFER_SIZE(headbuf) - bs->headbufavail); + + // otherwise we need to figure out how to assemble one + } else { + bs_print("peek_bytes: current buffer is not big enough for len %d\n",len); + + data = gst_bytestream2_assemble(bs,len); + } + + return data; +} + guint8 * gst_bytestream2_assemble(GstByteStream2 *bs, guint32 len) { diff --git a/libs/bytestream/gstbytestream2.h b/libs/bytestream/gstbytestream2.h index 11fcaa135d..e8eae270d5 100644 --- a/libs/bytestream/gstbytestream2.h +++ b/libs/bytestream/gstbytestream2.h @@ -21,8 +21,9 @@ GstByteStream2 * gst_bytestream2_new (GstPad *pad); GstBuffer * gst_bytestream2_read (GstByteStream2 *bs, guint32 len); GstBuffer * gst_bytestream2_peek (GstByteStream2 *bs, guint32 len); -gboolean gst_bytestream2_flush (GstByteStream2 *bs, guint32 len); guint8 * gst_bytestream2_peek_bytes (GstByteStream2 *bs, guint32 len); +gboolean gst_bytestream2_flush (GstByteStream2 *bs, guint32 len); + void gst_bytestream2_print_status(GstByteStream2 *bs); #endif /* __GST_BYTESTREAM2_H__ */