* Boston, MA 02111-1307, USA.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gst/gstinfo.h>
#include "bytestream.h"
-/* #define BS_DEBUG */
-
-#ifdef G_HAVE_ISO_VARARGS
-
-#ifdef BS_DEBUG
-# define bs_print(...) GST_DEBUG (GST_CAT_BUFFER, __VA_ARGS__)
-# define bs_status(bs) gst_bytestream_print_status(bs)
-#else
-# define bs_print(...)
-# define bs_status(bs)
-#endif
-
-#elif defined(G_HAVE_GNUC_VARARGS)
-
-#ifdef BS_DEBUG
-# define bs_print(format,args...) GST_DEBUG (GST_CAT_BUFFER, format, ## args)
-# define bs_status(bs) gst_bytestream_print_status(bs)
-#else
-# define bs_print(format,args...)
-# define bs_status(bs)
-#endif
-
-#endif
+GST_DEBUG_CATEGORY_STATIC(debug_bs);
+#define GST_CAT_DEFAULT debug_bs
static guint8 *gst_bytestream_assemble (GstByteStream * bs, guint32 len);
{
GstByteStream *bs = g_new (GstByteStream, 1);
+ GST_DEBUG_CATEGORY_INIT (debug_bs, "bytestream", 0, "bytestream library");
+
bs->pad = pad;
gst_bytestream_init (bs);
if (bs->event)
return FALSE;
- bs_print ("get_next_buf: pulling buffer");
+ GST_DEBUG ("get_next_buf: pulling buffer");
nextbuf = gst_pad_pull (bs->pad);
if (!nextbuf)
if (GST_BUFFER_TIMESTAMP_IS_VALID (nextbuf))
bs->last_ts = GST_BUFFER_TIMESTAMP (nextbuf);
- bs_print ("get_next_buf: got buffer of %d bytes", GST_BUFFER_SIZE (nextbuf));
+ GST_DEBUG ("get_next_buf: got buffer of %d bytes", GST_BUFFER_SIZE (nextbuf));
/* first see if there are any buffers in the list at all */
if (bs->buflist) {
- bs_print ("gst_next_buf: there is at least one buffer in the list");
+ GST_DEBUG ("gst_next_buf: there is at least one buffer in the list");
/* now find the end of the list */
end = g_slist_last (bs->buflist);
/* get the buffer that's there */
/* see if we can marge cheaply */
if (gst_buffer_is_span_fast (lastbuf, nextbuf)) {
- bs_print ("get_next_buf: merging new buffer with last buf on list");
+ GST_DEBUG ("get_next_buf: merging new buffer with last buf on list");
/* it is, let's merge them (this is really an append, but...) */
end->data = gst_buffer_merge (lastbuf, nextbuf);
/* add to the length of the list */
/* if we can't, we just append this buffer */
}
else {
- bs_print ("get_next_buf: adding new buffer to the end of the list");
+ GST_DEBUG ("get_next_buf: adding new buffer to the end of the list");
end = g_slist_append (end, nextbuf);
/* also need to increment length of list and buffer count */
bs->listavail += GST_BUFFER_SIZE (nextbuf);
/* if there are no buffers in the list */
}
else {
- bs_print ("get_next_buf: buflist is empty, adding new buffer to list");
+ GST_DEBUG ("get_next_buf: buflist is empty, adding new buffer to list");
/* put this on the end of the list */
bs->buflist = g_slist_append (bs->buflist, nextbuf);
/* and increment the number of bytes in the list */
{
/* 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", bs->listavail, len);
+ GST_DEBUG ("fill_bytes: there are %d bytes in the list, we need %d", bs->listavail, len);
if (!gst_bytestream_get_next_buf (bs))
return FALSE;
}
g_return_val_if_fail (bs != NULL, 0);
g_return_val_if_fail (len > 0, 0);
- bs_print ("peek: asking for %d bytes", len);
+ GST_DEBUG ("peek: asking for %d bytes", len);
/* make sure we have enough */
- bs_print ("peek: there are %d bytes in the list", bs->listavail);
+ GST_DEBUG ("peek: there are %d bytes in the list", bs->listavail);
if (len > bs->listavail) {
if (!gst_bytestream_fill_bytes (bs, len)) {
/* we must have an event coming up */
return 0;
}
}
- bs_print ("peek: there are now %d bytes in the list", bs->listavail);
+ GST_DEBUG ("peek: there are now %d bytes in the list", bs->listavail);
}
- bs_status (bs);
+ gst_bytestream_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: headbufavail is %d", bs->headbufavail);
+ GST_DEBUG ("peek: headbufavail is %d", bs->headbufavail);
if (len <= bs->headbufavail) {
- bs_print ("peek: there are enough bytes in headbuf (need %d, have %d)", len, bs->headbufavail);
+ GST_DEBUG ("peek: there are enough bytes in headbuf (need %d, have %d)", len, bs->headbufavail);
/* create a sub-buffer of the headbuf */
retbuf = gst_buffer_create_sub (headbuf, GST_BUFFER_SIZE (headbuf) - bs->headbufavail, len);
GST_BUFFER_OFFSET (retbuf) = GST_BUFFER_OFFSET (headbuf) + GST_BUFFER_SIZE (headbuf) - bs->headbufavail;
}
/* otherwise we need to figure out how to assemble one */
else {
- bs_print ("peek: current buffer is not big enough for len %d", len);
+ GST_DEBUG ("peek: current buffer is not big enough for len %d", len);
retbuf = gst_buffer_new ();
GST_BUFFER_SIZE (retbuf) = len;
g_return_val_if_fail (bs != NULL, 0);
g_return_val_if_fail (len > 0, 0);
- bs_print ("peek_bytes: asking for %d bytes", len);
+ GST_DEBUG ("peek_bytes: asking for %d bytes", len);
if (bs->assembled) {
if (bs->assembled_len >= len) {
*data = bs->assembled;
}
/* make sure we have enough */
- bs_print ("peek_bytes: there are %d bytes in the list", bs->listavail);
+ GST_DEBUG ("peek_bytes: there are %d bytes in the list", bs->listavail);
if (len > bs->listavail) {
if (!gst_bytestream_fill_bytes (bs, len)){
/* we must have an event coming up */
return 0;
}
}
- bs_print ("peek_bytes: there are now %d bytes in the list", bs->listavail);
+ GST_DEBUG ("peek_bytes: there are now %d bytes in the list", bs->listavail);
}
- bs_status (bs);
+ gst_bytestream_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", bs->headbufavail);
+ GST_DEBUG ("peek_bytes: headbufavail is %d", bs->headbufavail);
if (len <= bs->headbufavail) {
- bs_print ("peek_bytes: there are enough bytes in headbuf (need %d, have %d)", len, bs->headbufavail);
+ GST_DEBUG ("peek_bytes: there are enough bytes in headbuf (need %d, have %d)", 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", len);
+ GST_DEBUG ("peek_bytes: current buffer is not big enough for len %d", len);
*data = gst_bytestream_assemble (bs, len);
bs->assembled = *data;
/* copy the data from the curbuf */
buf = GST_BUFFER (bs->buflist->data);
- bs_print ("assemble: copying %d bytes from curbuf at %d to *data", bs->headbufavail,
+ GST_DEBUG ("assemble: copying %d bytes from curbuf at %d to *data", bs->headbufavail,
GST_BUFFER_SIZE (buf) - bs->headbufavail);
memcpy (data, GST_BUFFER_DATA (buf) + GST_BUFFER_SIZE (buf) - bs->headbufavail, bs->headbufavail);
copied += bs->headbufavail;
while (copied < len) {
buf = GST_BUFFER (walk->data);
if (GST_BUFFER_SIZE (buf) < (len - copied)) {
- bs_print ("assemble: copying %d bytes from buf to output offset %d", GST_BUFFER_SIZE (buf), copied);
+ GST_DEBUG ("assemble: copying %d bytes from buf to output offset %d", GST_BUFFER_SIZE (buf), copied);
memcpy (data + copied, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
copied += GST_BUFFER_SIZE (buf);
}
else {
- bs_print ("assemble: copying %d bytes from buf to output offset %d", len - copied, copied);
+ GST_DEBUG ("assemble: copying %d bytes from buf to output offset %d", len - copied, copied);
memcpy (data + copied, GST_BUFFER_DATA (buf), len - copied);
copied = len;
}
gboolean
gst_bytestream_flush (GstByteStream *bs, guint32 len)
{
- bs_print ("flush: flushing %d bytes", len);
+ GST_DEBUG ("flush: flushing %d bytes", len);
if (len == 0)
return TRUE;
/* make sure we have enough */
- bs_print ("flush: there are %d bytes in the list", bs->listavail);
+ GST_DEBUG ("flush: there are %d bytes in the list", bs->listavail);
if (len > bs->listavail) {
if (!gst_bytestream_fill_bytes (bs, len)) {
return FALSE;
}
- bs_print ("flush: there are now %d bytes in the list", bs->listavail);
+ GST_DEBUG ("flush: there are now %d bytes in the list", bs->listavail);
}
gst_bytestream_flush_fast (bs, len);
while (len > 0) {
headbuf = GST_BUFFER (bs->buflist->data);
- bs_print ("flush: analyzing buffer that's %d bytes long, offset %llu", GST_BUFFER_SIZE (headbuf),
+ GST_DEBUG ("flush: analyzing buffer that's %d bytes long, offset %llu", GST_BUFFER_SIZE (headbuf),
GST_BUFFER_OFFSET (headbuf));
/* if there's enough to complete the flush */
if (bs->headbufavail > len) {
/* just trim it off */
- bs_print ("flush: trimming %d bytes off end of headbuf", len);
+ GST_DEBUG ("flush: trimming %d bytes off end of headbuf", len);
bs->headbufavail -= len;
bs->listavail -= len;
len = 0;
/* otherwise we have to trim the whole buffer */
}
else {
- bs_print ("flush: removing head buffer completely");
+ GST_DEBUG ("flush: removing head buffer completely");
/* remove it from the list */
bs->buflist = g_slist_delete_link (bs->buflist, bs->buflist);
/* trim it from the avail size */
/* record the new headbufavail */
if (bs->buflist) {
bs->headbufavail = GST_BUFFER_SIZE (GST_BUFFER (bs->buflist->data));
- bs_print ("flush: next headbuf is %d bytes", bs->headbufavail);
+ GST_DEBUG ("flush: next headbuf is %d bytes", bs->headbufavail);
}
else {
- bs_print ("flush: no more bytes at all");
+ GST_DEBUG ("flush: no more bytes at all");
}
}
- bs_print ("flush: bottom of while(), len is now %d", len);
+ GST_DEBUG ("flush: bottom of while(), len is now %d", len);
}
}
peer = GST_RPAD_PEER (bs->pad);
- bs_print ("bs: send event\n");
+ GST_DEBUG ("bs: send event\n");
if (gst_pad_send_event (GST_PAD (peer), gst_event_new_seek (
GST_FORMAT_BYTES |
(method & GST_SEEK_METHOD_MASK) |
return TRUE;
}
- bs_print ("bs: send event failed\n");
+ GST_DEBUG ("bs: send event failed\n");
return FALSE;
}
g_return_val_if_fail (bs != NULL, 0);
- bs_print ("get_timestamp: getting timestamp");
+ GST_DEBUG ("get_timestamp: getting timestamp");
/* make sure we have a buffer */
if (bs->listavail == 0) {
- bs_print ("gst_timestamp: fetching a buffer");
+ GST_DEBUG ("gst_timestamp: fetching a buffer");
if (!gst_bytestream_fill_bytes (bs, 1))
return 0;
}
GSList *walk;
GstBuffer *buf;
- bs_print ("STATUS: head buffer has %d bytes available", bs->headbufavail);
- bs_print ("STATUS: list has %d bytes available", bs->listavail);
+ GST_DEBUG ("STATUS: head buffer has %d bytes available", bs->headbufavail);
+ GST_DEBUG ("STATUS: list has %d bytes available", bs->listavail);
walk = bs->buflist;
while (walk) {
buf = GST_BUFFER (walk->data);
walk = g_slist_next (walk);
- bs_print ("STATUS: buffer starts at %llu and is %d bytes long",
+ GST_DEBUG ("STATUS: buffer starts at %llu and is %d bytes long",
GST_BUFFER_OFFSET (buf), GST_BUFFER_SIZE (buf));
}
}