GST_DEBUG reorganization containing loads of stuff:
[platform/upstream/gstreamer.git] / libs / gst / bytestream / bytestream.c
index ce942cc..0de8bc2 100644 (file)
  * 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);
 
@@ -93,6 +76,8 @@ gst_bytestream_new (GstPad * pad)
 {
   GstByteStream *bs = g_new (GstByteStream, 1);
 
+  GST_DEBUG_CATEGORY_INIT (debug_bs, "bytestream", 0, "bytestream library");
+
   bs->pad = pad;
   gst_bytestream_init (bs);
 
@@ -164,7 +149,7 @@ gst_bytestream_get_next_buf (GstByteStream *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)
@@ -178,11 +163,11 @@ gst_bytestream_get_next_buf (GstByteStream *bs)
   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 */
@@ -190,7 +175,7 @@ gst_bytestream_get_next_buf (GstByteStream *bs)
 
     /* 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 */
@@ -207,7 +192,7 @@ gst_bytestream_get_next_buf (GstByteStream *bs)
       /* 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);
@@ -216,7 +201,7 @@ gst_bytestream_get_next_buf (GstByteStream *bs)
     /* 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 */
@@ -239,7 +224,7 @@ gst_bytestream_fill_bytes (GstByteStream *bs, guint32 len)
 {
   /* 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;
   }
@@ -269,10 +254,10 @@ gst_bytestream_peek (GstByteStream *bs, GstBuffer **buf, guint32 len)
   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 */
@@ -286,17 +271,17 @@ gst_bytestream_peek (GstByteStream *bs, GstBuffer **buf, guint32 len)
         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;
@@ -304,7 +289,7 @@ gst_bytestream_peek (GstByteStream *bs, GstBuffer **buf, guint32 len)
   }
   /* 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;
@@ -342,7 +327,7 @@ gst_bytestream_peek_bytes (GstByteStream *bs, guint8** data, guint32 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;
@@ -353,7 +338,7 @@ gst_bytestream_peek_bytes (GstByteStream *bs, guint8** data, guint32 len)
   }
 
   /* 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 */
@@ -367,24 +352,24 @@ gst_bytestream_peek_bytes (GstByteStream *bs, guint8** data, guint32 len)
         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;
@@ -404,7 +389,7 @@ gst_bytestream_assemble (GstByteStream *bs, guint32 len)
 
   /* 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;
@@ -414,12 +399,12 @@ gst_bytestream_assemble (GstByteStream *bs, guint32 len)
   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;
     }
@@ -445,18 +430,18 @@ gst_bytestream_assemble (GstByteStream *bs, guint32 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);
@@ -496,13 +481,13 @@ gst_bytestream_flush_fast (GstByteStream *bs, guint32 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;
@@ -510,7 +495,7 @@ gst_bytestream_flush_fast (GstByteStream *bs, guint32 len)
       /* 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 */
@@ -523,14 +508,14 @@ gst_bytestream_flush_fast (GstByteStream *bs, guint32 len)
       /* 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);
   }
 }
 
@@ -557,7 +542,7 @@ gst_bytestream_seek (GstByteStream *bs, gint64 offset, GstSeekType method)
   
   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) | 
@@ -572,7 +557,7 @@ gst_bytestream_seek (GstByteStream *bs, gint64 offset, GstSeekType method)
     
     return TRUE;
   }
-  bs_print ("bs: send event failed\n");
+  GST_DEBUG ("bs: send event failed\n");
   return FALSE;
 }
 
@@ -722,11 +707,11 @@ gst_bytestream_get_timestamp (GstByteStream *bs)
 
   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;
   }
@@ -750,14 +735,14 @@ gst_bytestream_print_status (GstByteStream * bs)
   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));
   }
 }