From: Andre Noll Date: Sun, 10 Feb 2008 11:49:29 +0000 (+0100) Subject: Speed up open_current_receiver(). X-Git-Tag: v0.3.1~27 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=d9de75ccdc85fd9bf90c6eb9a1b42dfdd84afd32;p=paraslash.git Speed up open_current_receiver(). To my surprise, this function showed up in the profiling info. This is due to the fact that the old code was parsing the FORMAT status item in audiod_pre_select() which gets called on each iteration of the sheduler. However, this status item gets only modified on audio file change. So parse the status item string only once, when we receive it, and store the current audio format number in the new field of struct status_task. --- diff --git a/audiod.c b/audiod.c index df725f96..701f8278 100644 --- a/audiod.c +++ b/audiod.c @@ -431,23 +431,18 @@ static int receiver_running(int format) static int open_current_receiver(struct sched *s) { - int i; struct timeval diff; - char *audio_format = stat_task->stat_item_values[SI_FORMAT]; + int cafn = stat_task->current_audio_format_num; - if (!audio_format || !stat_task->pcd) - return 0; - i = get_audio_format_num(audio_format + strlen( - status_item_list[SI_FORMAT]) + 1); - if (i < 0) + if (cafn < 0 || !stat_task->pcd) return 0; - if (receiver_running(i)) + if (receiver_running(cafn)) return 0; - if (tv_diff(now, &afi[i].restart_barrier, &diff) < 0) { + if (tv_diff(now, &afi[cafn].restart_barrier, &diff) < 0) { s->timeout = diff; return 0; } - return open_receiver(i) < 0? 0 : 1; + return open_receiver(cafn) < 0? 0 : 1; } static unsigned compute_time_diff(const struct timeval *status_time) @@ -551,6 +546,9 @@ static int check_stat_line(char *line, __a_unused void *data) if (stat_task->clock_diff_count) stat_task->clock_diff_count--; break; + case SI_FORMAT: + stat_task->current_audio_format_num = get_audio_format_num( + line + ilen + 1); } return 1; } @@ -1089,6 +1087,7 @@ static void init_status_task(struct status_task *st) st->task.private_data = st; st->sa_time_diff_sign = 1; st->clock_diff_count = conf.clock_diff_count_arg; + st->current_audio_format_num = -1; sprintf(st->task.status, "status task"); } diff --git a/audiod.h b/audiod.h index 00681779..c6746d20 100644 --- a/audiod.h +++ b/audiod.h @@ -99,6 +99,8 @@ struct status_task { unsigned clock_diff_count; /** when to start the next check for clock difference */ struct timeval clock_diff_barrier; + /** Number of the audio format as announced by para_server. */ + int current_audio_format_num; }; extern struct status_task *stat_task;