X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audiod.c;h=76f07e8c635e28ad5de2a513fb863e9397dbc785;hp=7afff93e263630da1a3692b7ca4b9f28c50fa973;hb=074c45e88bca5e9d12d7905efb918843b5372e04;hpb=d20b524267f4c0594e0246643853db8cba68fa10 diff --git a/audiod.c b/audiod.c index 7afff93e..76f07e8c 100644 --- a/audiod.c +++ b/audiod.c @@ -66,6 +66,9 @@ struct audio_format_info { struct slot_info slot[MAX_STREAM_SLOTS]; +/** The array of status items sent by para_server. */ +char *stat_item_values[NUM_STAT_ITEMS]; + /** * the current mode of operation of which can be changed by the on/off/cycle * commands. It is either, AUDIOD_OFF, AUDIOD_ON or AUDIOD_STANDBY. @@ -91,7 +94,7 @@ static struct status_task status_task_struct; * * \sa struct status_task */ -struct status_task *stat_task = &status_task_struct; +static struct status_task *stat_task = &status_task_struct; static struct timeval initial_delay_barrier; /** @@ -128,6 +131,55 @@ int get_audio_format_num(char *name) return -E_UNSUPPORTED_AUDIO_FORMAT; } +char *get_time_string(struct timeval *newest_stime) +{ + struct timeval diff, adj_stream_start, tmp; + int total = 0, use_server_time = 1, + length_seconds = stat_task->length_seconds; + + if (!stat_task->playing) { + if (length_seconds) + return NULL; + return make_message("%s:\n", status_item_list[SI_PLAY_TIME]); + } + 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); + 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_diff(now, &tmp, &diff); + total = diff.tv_sec + stat_task->offset_seconds; + if (total > length_seconds) + total = length_seconds; + if (total < 0) + total = 0; +out: + 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 + ); +} + /** * the log function of para_audiod * @@ -467,8 +519,8 @@ static int check_stat_line(char *line, __a_unused void *data) tmp = make_message("%s\n", line); stat_client_write(tmp, itemnum); free(tmp); - free(stat_task->stat_item_values[itemnum]); - stat_task->stat_item_values[itemnum] = para_strdup(line); + free(stat_item_values[itemnum]); + stat_item_values[itemnum] = para_strdup(line); ilen = strlen(status_item_list[itemnum]); switch (itemnum) { case SI_STATUS: @@ -814,18 +866,18 @@ static void close_stat_pipe(void) client_close(stat_task->ct); stat_task->ct = NULL; FOR_EACH_STATUS_ITEM(i) { - free(stat_task->stat_item_values[i]); - stat_task->stat_item_values[i] = NULL; + free(stat_item_values[i]); + stat_item_values[i] = NULL; } dump_empty_status(); stat_task->length_seconds = 0; stat_task->offset_seconds = 0; audiod_status_dump(); stat_task->playing = 0; - stat_task->stat_item_values[SI_BASENAME] = make_message( + stat_item_values[SI_BASENAME] = make_message( "%s: no connection to para_server\n", status_item_list[SI_BASENAME]); - stat_client_write(stat_task->stat_item_values[SI_BASENAME], + stat_client_write(stat_item_values[SI_BASENAME], SI_BASENAME); }