Switch audiod over to the buffer tree API.
[paraslash.git] / buffer_tree.c
index 23599b834a26e31adda87ecdb49da7238b0d1d10..1be2037f5a7f3b9a2eb231debebdcf0be0ecedba 100644 (file)
@@ -6,6 +6,7 @@
 #include "string.h"
 #include "buffer_tree.h"
 #include "error.h"
+#include "sched.h"
 
 
 struct btr_buffer {
@@ -29,6 +30,8 @@ struct btr_node {
        struct list_head node;
        /* The children nodes of this btr node are linked together in a list. */
        struct list_head children;
+       /* Time of first data transfer. */
+       struct timeval start;
        /**
         * The input queue is a list of references to btr buffers. Each item on
         * the list represents an input buffer which has not been completely
@@ -58,6 +61,8 @@ struct btr_node *btr_new_node(const char *name, struct btr_node *parent,
        btrn->parent = parent;
        btrn->execute = handler;
        btrn->context = context;
+       btrn->start.tv_sec = 0;
+       btrn->start.tv_usec = 0;
        if (parent)
                list_add_tail(&btrn->node, &parent->children);
        INIT_LIST_HEAD(&btrn->children);
@@ -106,12 +111,16 @@ static void add_btrb_to_children(struct btr_buffer *btrb,
 {
        struct btr_node *ch;
 
+       if (btrn->start.tv_sec == 0)
+               btrn->start = *now;
        FOR_EACH_CHILD(ch, btrn) {
                struct btr_buffer_reference *br = para_malloc(sizeof(*br));
                br->btrb = btrb;
                br->consumed = consumed;
                list_add_tail(&br->node, &ch->input_queue);
                btrb->refcount++;
+               if (ch->start.tv_sec == 0)
+                       ch->start = *now;
        }
 }
 
@@ -353,8 +362,8 @@ static int merge_input(struct btr_node *btrn)
        }
        /* make a new btrb that combines the two buffers and a br to it. */
        sz = szs[0] + szs[1];
-       //PARA_CRIT_LOG("merging input buffers: (%zu, %zu) -> %zu\n",
-       //      szs[0], szs[1], sz);
+       PARA_DEBUG_LOG("merging input buffers: (%zu, %zu) -> %zu\n",
+               szs[0], szs[1], sz);
        buf = para_malloc(sz);
        /* TODO: Avoid this memcopy by introducing btr buffer pool. */
        memcpy(buf, bufs[0], szs[0]);
@@ -379,6 +388,7 @@ void btr_merge(struct btr_node *btrn, size_t dest_size)
                size_t len = btr_next_buffer(btrn, &buf);
                if (len >= dest_size)
                        return;
+               PARA_DEBUG_LOG("input size = %zu < %zu = dest\n", len, dest_size);
                if (merge_input(btrn) < 2)
                        return;
        }
@@ -434,3 +444,8 @@ int btr_node_status(struct btr_node *btrn, size_t min_iqs,
        }
        return 1;
 }
+
+void btr_get_node_start(struct btr_node *btrn, struct timeval *tv)
+{
+       *tv = btrn->start;
+}