X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audiod.c;h=3a2607defc2576b476628524102b5d8367985b89;hp=3f46acbcee062f71bd5a5d7e582262a5f26117ac;hb=2607a94854dbc9d9415887cb9fa954e9227c1c65;hpb=31233289bedbb596b98eadd411bc6aac54d4ed69 diff --git a/audiod.c b/audiod.c index 3f46acbc..3a2607de 100644 --- a/audiod.c +++ b/audiod.c @@ -172,53 +172,66 @@ int get_audio_format_num(char *name) return -E_UNSUPPORTED_AUDIO_FORMAT; } -char *get_time_string(struct timeval *newest_stime) +char *get_time_string(int slot_num) { - struct timeval diff, adj_stream_start, tmp; - int total = 0, use_server_time = 1, - length_seconds = stat_task->length_seconds; + int ret, seconds = 0, length; + struct timeval *tmp, sum, sss, /* server stream start */ + wtime, /* now - writer start */ + rskip; /* receiver start - sss */ + struct slot_info *s = slot_num < 0? NULL : &slot[slot_num]; + if (audiod_status == AUDIOD_OFF) + goto empty; if (!(stat_task->vss_status & VSS_STATUS_FLAG_PLAYING)) { - if (length_seconds) + if (stat_task->length_seconds) /* paused */ return NULL; - return make_message("%s:\n", status_item_list[SI_PLAY_TIME]); + goto empty; /* stopped */ + } + if (audiod_status == AUDIOD_ON && !s) + goto empty; + /* valid status items and playing */ + if (s) { /* writer active in this slot */ + length = s->seconds_total; + tmp = &s->server_stream_start; + } else { /* standby mode, rely on status items */ + length = stat_task->length_seconds; + tmp = &stat_task->server_stream_start; } - if (audiod_status == AUDIOD_OFF) - goto out; if (stat_task->sa_time_diff_sign > 0) - tv_diff(&stat_task->server_stream_start, &stat_task->sa_time_diff, - &adj_stream_start); + tv_diff(tmp, &stat_task->sa_time_diff, &sss); else - tv_add(&stat_task->server_stream_start, &stat_task->sa_time_diff, - &adj_stream_start); - tmp = adj_stream_start; - if (newest_stime && audiod_status == AUDIOD_ON) { - tv_diff(newest_stime, &adj_stream_start, &diff); - if (tv2ms(&diff) < 5000) { - tmp = *newest_stime; - use_server_time = 0; - } + tv_add(tmp, &stat_task->sa_time_diff, &sss); + if (!s) { + struct timeval diff; + tv_diff(now, &sss, &diff); + seconds = diff.tv_sec + stat_task->offset_seconds; + goto out; } - tv_diff(now, &tmp, &diff); - total = diff.tv_sec + stat_task->offset_seconds; - if (total > length_seconds) - total = length_seconds; - if (total < 0) - total = 0; + tv_diff(now, &s->wstime, &wtime); + seconds = s->offset_seconds; + ret = tv_diff(&s->rstime, &sss, &rskip); + if (ret > 0) { /* audiod was started in the middle of the stream */ + tv_add(&wtime, &rskip, &sum); + seconds += sum.tv_sec; + } else + seconds += wtime.tv_sec; out: + seconds = PARA_MIN(seconds, length); + seconds = PARA_MAX(seconds, 0); return make_message( "%s: %s%d:%02d [%d:%02d] (%d%%/%d:%02d)\n", status_item_list[SI_PLAY_TIME], - use_server_time? "~" : "", - total / 60, - total % 60, - (length_seconds - total) / 60, - (length_seconds - total) % 60, - length_seconds? (total * 100 + length_seconds / 2) / - length_seconds : 0, - length_seconds / 60, - length_seconds % 60 + s? "" : "~", + seconds / 60, + seconds % 60, + (length - seconds) / 60, + (length - seconds) % 60, + length? (seconds * 100 + length / 2) / length : 0, + length / 60, + length % 60 ); +empty: + return make_message("%s:\n", status_item_list[SI_PLAY_TIME]); } static int want_colors(void) @@ -429,6 +442,10 @@ static void open_writers(int slot_num) return; } s->wstime = *now; + s->server_stream_start = stat_task->server_stream_start.tv_sec? + stat_task->server_stream_start : *now; + s->offset_seconds = stat_task->offset_seconds; + s->seconds_total = stat_task->length_seconds; activate_inactive_grab_clients(slot_num, s->format, s->fc); } @@ -460,6 +477,7 @@ static int open_receiver(int format) audio_formats[s->format], a->receiver->name, slot_num); rn->task.pre_select = a->receiver->pre_select; rn->task.post_select = a->receiver->post_select; + s->rstime = *now; sprintf(rn->task.status, "%s receiver node", rn->receiver->name); register_task(&rn->task); ret = 1;