Fix stream grabbing.
[paraslash.git] / audiod.c
index db7ae8a52bed1a7b40a8d2f307a901119ef79091..79dd6156e1a509c09cdad01990a577546dc9ff26 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -541,6 +541,29 @@ static int receiver_running(int format)
        return ret;
 }
 
+struct btr_node *audiod_get_btr_root(void)
+{
+       int i, newest_slot = -1;
+       struct timeval newest_rstime = {0, 0};
+
+       FOR_EACH_SLOT(i) {
+               struct slot_info *s = &slot[i];
+               struct timeval rstime;
+               if (!s->receiver_node)
+                       continue;
+               if (s->receiver_node->task.error < 0)
+                       continue;
+               btr_get_node_start(s->receiver_node->btrn, &rstime);
+               if (newest_slot >= 0 && tv_diff(&rstime, &newest_rstime, NULL) < 0)
+                       continue;
+               newest_rstime = rstime;
+               newest_slot = i;
+       }
+       if (newest_slot == -1)
+               return NULL;
+       return slot[newest_slot].receiver_node->btrn;
+}
+
 /* returns slot num on success. */
 static int open_current_receiver(struct sched *s)
 {
@@ -562,11 +585,8 @@ static int open_current_receiver(struct sched *s)
                 * this period begins to avoid restarting the receiver that
                 * belongs to the file just completed.
                 */
-               PARA_CRIT_LOG("->>>>>>>>>>>>>>>>>> no delay\n");
-               if (stat_task->server_stream_start.tv_sec != 0) {
-                       PARA_CRIT_LOG("->>>>>>>>>>>>>>>>>><delay\n");
+               if (stat_task->server_stream_start.tv_sec != 0)
                        return -1;
-               }
        }
        if (tv_diff(now, &afi[cafn].restart_barrier, &diff) < 0) {
                /* avoid busy loop */
@@ -1055,6 +1075,7 @@ static void start_stop_decoders(struct sched *s)
        if (a->num_filters)
                open_filters(sl);
        open_writers(sl);
+       activate_grab_clients();
        btr_log_tree(sl->receiver_node->btrn, LL_NOTICE);
        s->timeout.tv_sec = 0;
        s->timeout.tv_usec = 1;