- va_list argp;
- FILE *outfd;
- struct tm *tm;
- time_t t1;
- char str[MAXLINE] = "";
- static char *hostname;
-
- if (ll < conf.loglevel_arg)
- return;
- if (!logfile && conf.daemon_given)
- 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 */
+ 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 (stat_task->length_seconds) /* paused */
+ return NULL;
+ 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 (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) {
+ struct timeval diff;
+ tv_diff(now, &sss, &diff);
+ seconds = diff.tv_sec + stat_task->offset_seconds;
+ goto out;
+ }
+ 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],
+ 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)
+{
+ 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);