audiod: Avoid to report 100% time at startup.
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 22 Dec 2015 22:28:46 +0000 (22:28 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 26 Mar 2016 22:16:22 +0000 (22:16 +0000)
This teaches get_time_string() to handle the case of zero values for
sss and wstime. These happen to be zero for a short time period when
para_server is changing its audio file.

audiod.c

index 8b9422bc322b8c989a9f04456dd1d50253f68e5d..94afa1cf16fb9d9e7271ef6e5904085ef443589c 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -309,7 +309,7 @@ static int get_play_time_slot_num(void)
  */
 char *get_time_string(void)
 {
-       int ret, seconds = 0, length;
+       int ret, seconds = 0, length = stat_task->length_seconds;
        struct timeval *tmp, sum, sss, /* server stream start */
                rstime, /* receiver start time */
                wstime, /* writer start time */
@@ -321,8 +321,10 @@ char *get_time_string(void)
 
        if (audiod_status == AUDIOD_OFF)
                goto empty;
-       if (!(stat_task->vss_status & VSS_STATUS_FLAG_PLAYING)) {
-               if (stat_task->length_seconds) /* paused */
+       if (stat_task->server_stream_start.tv_sec == 0) {
+               if (stat_task->vss_status & VSS_STATUS_FLAG_PLAYING)
+                       goto out; /* server is about to change file */
+               if (length > 0) /* paused */
                        return NULL;
                goto empty; /* stopped */
        }
@@ -331,7 +333,6 @@ char *get_time_string(void)
         * 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 && s->wns[0].btrn) { /* writer active in this slot */
                btr_get_node_start(s->wns[0].btrn, &wstime);
@@ -350,7 +351,7 @@ char *get_time_string(void)
                tv_diff(tmp, &stat_task->sa_time_diff, &sss);
        else
                tv_add(tmp, &stat_task->sa_time_diff, &sss);
-       if (!s || !s->wns || !s->wns[0].btrn) {
+       if (!s || !s->wns || !s->wns[0].btrn || wstime.tv_sec == 0) {
                struct timeval diff;
                tv_diff(now, &sss, &diff);
                seconds = diff.tv_sec + stat_task->offset_seconds;