From b24869714aed385f04d282f854aaec7e69428cce Mon Sep 17 00:00:00 2001 From: Andre Date: Mon, 27 Mar 2006 01:17:16 +0200 Subject: [PATCH] audiod: switch from ringbuffer to statically allocated array This patch also fixes a minor bug where audiod would send empty status lines or lines containing only a colon (only happens if para_server status is paused). --- audiod.c | 59 ++++++++++++++++++++++++++-------------------------- configure.ac | 2 +- stat.c | 1 - 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/audiod.c b/audiod.c index 9e001c67..c9a0ff7f 100644 --- a/audiod.c +++ b/audiod.c @@ -28,7 +28,6 @@ #include "filter.h" #include "grab_client.cmdline.h" #include "grab_client.h" -#include "ringbuffer.h" #include "error.h" #include "audiod.h" @@ -131,9 +130,7 @@ static int playing, current_decoder = -1, sa_time_diff_sign = 1, audiod_socket = -1; static char *af_status, /* the audio format announced in server status */ *socket_name, *hostname; -/** how many status items to remember */ -#define RINGBUFFER_SIZE 32 -static void *stat_item_ringbuf; +static char *stat_item_values[NUM_STAT_ITEMS]; static FILE *logfile; static const struct timeval restart_delay = {0, 300 * 1000}; @@ -302,9 +299,11 @@ static char *get_time_string(struct timeval *newest_stime) struct timeval now, diff, adj_stream_start, tmp; int total = 0, use_server_time = 1; - if (!playing) - return make_message("%s:", length_seconds? - "" : status_item_list[SI_PLAY_TIME]); + if (!playing) { + if (length_seconds) + return NULL; + return make_message("%s:", status_item_list[SI_PLAY_TIME]); + } if (audiod_status == AUDIOD_OFF) goto out; if (sa_time_diff_sign > 0) @@ -370,12 +369,13 @@ static char *audiod_status_string(void) decoder_flags[MAX_STREAM_SLOTS] = '\0'; time_string = get_time_string(newest_stime); uptime_string = uptime_str(); - ret = make_message("%s:%s\n%s:%s\n%s:%s\n%s", + ret = make_message("%s:%s\n%s:%s\n%s:%s", status_item_list[SI_AUDIOD_UPTIME], uptime_string, status_item_list[SI_DECODER_FLAGS], decoder_flags, status_item_list[SI_AUDIOD_STATUS], audiod_status == AUDIOD_ON? - "on" : (audiod_status == AUDIOD_OFF? "off": "sb"), - time_string); + "on" : (audiod_status == AUDIOD_OFF? "off": "sb")); + if (time_string) + ret = make_message("%s\n%s", ret, time_string); free(uptime_string); free(decoder_flags); free(time_string); @@ -546,7 +546,6 @@ static int decoder_running(int format) static void close_stat_pipe(void) { - char *msg; int i; if (stat_pipe < 0) @@ -556,17 +555,18 @@ static void close_stat_pipe(void) del_close_on_fork_list(stat_pipe); stat_pipe = -1; kill_all_decoders(); - for (i = 0; i < RINGBUFFER_SIZE; i++) - free(ringbuffer_add(stat_item_ringbuf, para_strdup(NULL))); + for (i = 0; i < NUM_STAT_ITEMS; i++) { + free(stat_item_values[i]); + stat_item_values[i] = NULL; + } dump_empty_status(); length_seconds = 0; offset_seconds = 0; audiod_status_dump(); playing = 0; - msg = make_message("%s:no connection to para_server\n", + stat_item_values[SI_STATUS_BAR] = make_message("%s:no connection to para_server\n", status_item_list[SI_STATUS_BAR]); - free(ringbuffer_add(stat_item_ringbuf, msg)); - stat_client_write(msg); + stat_client_write(stat_item_values[SI_STATUS_BAR]); } static void __noreturn clean_exit(int status, const char *msg) @@ -796,11 +796,14 @@ static void check_stat_line(char *line) if (!line) return; - free(ringbuffer_add(stat_item_ringbuf, para_strdup(line))); - stat_client_write(line); itemnum = stat_line_valid(line); - if (itemnum < 0) + if (itemnum < 0) { + PARA_WARNING_LOG("invalid status line: %s\n", line); return; + } + stat_client_write(line); + free(stat_item_values[itemnum]); + stat_item_values[itemnum] = para_strdup(line); ilen = strlen(status_item_list[itemnum]); switch (itemnum) { case SI_STATUS: @@ -1183,7 +1186,7 @@ static int dump_commands(int fd) /* * command handlers don't close their fd on errors (ret < 0) so that * its caller can send an error message. Otherwise (ret >= 0) it's up - * to each individual command to close the fd if necessary. + * to each individual command to close the fd if necessary. */ static int com_help(int fd, int argc, char **argv) @@ -1224,16 +1227,13 @@ out: static int com_stat(int fd, __unused int argc, __unused char **argv) { int i, ret; - char *buf = audiod_status_string(); + char *buf = make_message("%s\n", audiod_status_string()); - buf = para_strcat(buf, "\n"); - for (i = RINGBUFFER_SIZE - 1; i >= 0; i--) { - char *tmp, *line = ringbuffer_get(stat_item_ringbuf, i); - if (!line) - continue; - tmp = make_message("%s\n", line); - buf = para_strcat(buf, tmp); - free(tmp); + for (i = 0; i < NUM_STAT_ITEMS; i++) { + char *tmp, *v = stat_item_values[i]; + tmp = make_message("%s%s%s", buf, v? v : "", v? "\n" : ""); + free(buf); + buf = tmp; } ret = client_write(fd, buf); if (ret > 0) @@ -1597,7 +1597,6 @@ int __noreturn main(int argc, char *argv[]) set_initial_status(); FOR_EACH_SLOT(i) clear_slot(i); - stat_item_ringbuf = ringbuffer_new(RINGBUFFER_SIZE); init_grabbing(); setup_signal_handling(); if (conf.daemon_given) diff --git a/configure.ac b/configure.ac index 7c1cfc98..f95a1682 100644 --- a/configure.ac +++ b/configure.ac @@ -68,7 +68,7 @@ filter_ldflags="" audiod_cmdline_objs="audiod.cmdline grab_client.cmdline compress_filter.cmdline http_recv.cmdline dccp_recv.cmdline" audiod_errlist_objs="audiod exec close_on_fork signal string daemon stat net - time grab_client filter_chain wav compress http_recv dccp dccp_recv recv_common ringbuffer" + time grab_client filter_chain wav compress http_recv dccp dccp_recv recv_common" audiod_ldflags="" server_cmdline_objs="server.cmdline" diff --git a/stat.c b/stat.c index 4259956f..ac5fe8c8 100644 --- a/stat.c +++ b/stat.c @@ -195,7 +195,6 @@ void dump_empty_status(void) free(empty_items); empty_items = tmp; } -// PARA_DEBUG_LOG("%s: empty items: %s\n", __func__, empty_items); stat_client_write(empty_items); free(empty_items); } -- 2.39.5