summaryrefslogtreecommitdiff
path: root/stat.c
diff options
context:
space:
mode:
authorAndre Noll <maan@tuebingen.mpg.de>2026-11-27 22:44:01 +0100
committerAndre Noll <maan@tuebingen.mpg.de>2026-11-27 22:44:01 +0100
commit7c8ebfeb9bf9153763fbc744fb990469f402e733 (patch)
tree11450b4814233f69af5a4e182fda378492b2fd0f /stat.c
parent089b2df7df2a0f4b6eea33cdaca506e111ec0fa8 (diff)
parent1acc099bdede18c1452de8fc2e691d7f6ebf57a1 (diff)
Merge topic branch t/status_items into pupu
Revamp the status items. ------------------------ First step towards getting rid of the status items which depend on the current time. * t/status_items: f f New status item: writer_start time. audiod: Move the global afi struct into struct status_task. audiod: Make the status task struct local. audiod: Don't dump status items from command context. audiod: Replace server_stream start slot info fields. gui: Fix return value of colorful_blackness_print_status_items().
Diffstat (limited to 'stat.c')
-rw-r--r--stat.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/stat.c b/stat.c
index 4550a77a..77003fca 100644
--- a/stat.c
+++ b/stat.c
@@ -8,6 +8,7 @@
#include "para.h"
#include "error.h"
#include "string.h"
+#include "sched.h"
/** The minimal length of a status item buffer. */
#define MIN_STAT_ITEM_LEN 9 /* 5 + 2 + 2, e.g. '0005 00:\n' */
@@ -110,3 +111,74 @@ parse_error:
PARA_ERROR_LOG("status item parse error\n");
return mask;
}
+
+/*
+ * This function can go to gui_theme.c once the play_time status item has
+ * been disabled.
+ */
+
+/*
+ * Compute the play time based on information of the current slot.
+ *
+ * Compute a string of the form "0:07 [3:33] (3%/3:40)". If there is a writer
+ * in any slot, use its start time. If audiod operates in standby mode,
+ * fall back to an approximation that is based on the status items only and
+ * prefix the returned string with "~".
+ *
+ * Returns a string as described above on success, the empty string if no
+ * stream is currently announced or if para_audiod is running in "off" mode,
+ * NULL if the stream is currently paused or repositioned. The memory for
+ * the returned string is allocated on the heap and must be freed by the caller.
+ */
+__malloc char *make_time_string(struct timeval *sss, struct timeval *wstime,
+ char **items)
+{
+ int length, seconds, offset;
+ struct timeval tmp;
+ char *si_seconds = items[SI_seconds_total],
+ *si_flags = items[SI_status_flags],
+ *si_offset = items[SI_offset];
+
+ if (!sss || !si_seconds || !si_flags || !si_offset)
+ return para_strdup(NULL);
+ length = atoi(items[SI_seconds_total]);
+ if (sss->tv_sec == 0 || length == 0) { /* no stream */
+ if (strchr(items[SI_status_flags], 'P'))
+ return NULL; /* repositioning or about to change file */
+ if (length > 0) { /* paused */
+ seconds = atoi(items[SI_offset]);
+ goto out;
+ }
+ return para_strdup(NULL); /* stopped */
+ }
+ offset = atoi(items[SI_offset]);
+ if (!wstime) {
+ struct timeval diff;
+ tv_diff(now, sss, &diff);
+ seconds = diff.tv_sec + offset;
+ goto out;
+ }
+ if (wstime->tv_sec == 0)
+ return NULL;
+ seconds = offset;
+ /* check if audiod was started in the middle of the stream */
+ if (tv_diff(wstime, sss, &tmp) > 0 && tv2ms(&tmp) > 2000) {
+ tv_diff(now, sss, &tmp); /* assume it was */
+ } else
+ tv_diff(now, wstime, &tmp);
+ seconds += tmp.tv_sec + (tmp.tv_usec + 500 * 1000) / 1000 / 1000;
+out:
+ seconds = PARA_MIN(seconds, length);
+ seconds = PARA_MAX(seconds, 0);
+ return make_message(
+ "%s%d:%02d [%d:%02d] (%d%%/%d:%02d)",
+ wstime? "" : "~",
+ seconds / 60,
+ seconds % 60,
+ (length - seconds) / 60,
+ (length - seconds) % 60,
+ length? (seconds * 100 + length / 2) / length : 0,
+ length / 60,
+ length % 60
+ );
+}