added peek_bytes, please note comments in gstbstest.c

Original commit message from CVS:
added peek_bytes, please note comments in gstbstest.c
This commit is contained in:
Erik Walthinsen 2001-09-21 06:39:22 +00:00
parent 48c1d9cc8e
commit ff191d4b7b
3 changed files with 58 additions and 1 deletions

View file

@ -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;i<identity->count;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

View file

@ -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)
{

View file

@ -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__ */