- va_list argp;
- FILE *outfd;
- struct tm *tm;
- time_t t1;
- char str[MAXLINE] = "";
- static char *hostname;
-
- if (ll < conf.loglevel_arg)
- return;
- if (!hostname)
- hostname = para_hostname();
- outfd = logfile? logfile : stderr;
- time(&t1);
- tm = localtime(&t1);
- strftime(str, MAXLINE, "%b %d %H:%M:%S", tm);
- fprintf(outfd, "%s %s ", str, hostname);
- if (conf.loglevel_arg <= INFO)
- fprintf(outfd, "%i ", ll);
- va_start(argp, fmt);
- vfprintf(outfd, fmt, argp);
- va_end(argp);
+ int ret, seconds = 0, length;
+ struct timeval *tmp, sum, sss, /* server stream start */
+ rstime, /* receiver start time */
+ wstime, /* writer start time */
+ wtime, /* now - writer start */
+ rskip; /* receiver start - sss */
+ struct slot_info *s = slot_num < 0? NULL : &slot[slot_num];
+ char *msg;
+
+ if (audiod_status == AUDIOD_OFF)
+ goto empty;
+ if (!(stat_task->vss_status & VSS_STATUS_FLAG_PLAYING)) {
+ if (stat_task->length_seconds) /* paused */
+ return NULL;
+ goto empty; /* stopped */
+ }
+ if (audiod_status == AUDIOD_ON && !s)
+ goto empty;
+ /*
+ * Valid status items and playing, set length and tmp to the stream
+ * start. We use the slot info and fall back to the info from current
+ * status items if no slot info is available.
+ */
+ length = stat_task->length_seconds;
+ tmp = &stat_task->server_stream_start;
+ if (s && s->wns) { /* writer active in this slot */
+ btr_get_node_start(s->wns[0].btrn, &wstime);
+ if (wstime.tv_sec != 0) { /* writer wrote something */
+ if (s->server_stream_start.tv_sec == 0) {
+ /* copy status info to slot */
+ s->server_stream_start = stat_task->server_stream_start;
+ s->offset_seconds = stat_task->offset_seconds;
+ s->seconds_total = stat_task->length_seconds;
+ }
+ length = s->seconds_total;
+ tmp = &s->server_stream_start;
+ }
+ }
+ if (stat_task->sa_time_diff_sign > 0)
+ tv_diff(tmp, &stat_task->sa_time_diff, &sss);
+ else
+ tv_add(tmp, &stat_task->sa_time_diff, &sss);
+ if (!s || !s->wns) {
+ struct timeval diff;
+ tv_diff(now, &sss, &diff);
+ seconds = diff.tv_sec + stat_task->offset_seconds;
+ goto out;
+ }
+ tv_diff(now, &wstime, &wtime);
+ //PARA_CRIT_LOG("offset %d\n", s->offset_seconds);
+ seconds = s->offset_seconds;
+ btr_get_node_start(s->receiver_node->btrn, &rstime);
+ ret = tv_diff(&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);
+ msg = make_message(
+ "%s%d:%02d [%d:%02d] (%d%%/%d:%02d)",
+ s? "" : "~",
+ seconds / 60,
+ seconds % 60,
+ (length - seconds) / 60,
+ (length - seconds) % 60,
+ length? (seconds * 100 + length / 2) / length : 0,
+ length / 60,
+ length % 60
+ );
+ PARA_DEBUG_LOG("slot %d: %s\n", slot_num, msg);
+ return msg;
+empty:
+ return para_strdup(NULL);
+}
+
+static int want_colors(void)
+{
+ if (conf.color_arg == color_arg_no)
+ return 0;
+ if (conf.color_arg == color_arg_yes)
+ return 1;
+ if (conf.logfile_given)
+ return 0;
+ return isatty(STDERR_FILENO);