Speed up open_current_receiver().
authorAndre Noll <maan@systemlinux.org>
Sun, 10 Feb 2008 11:49:29 +0000 (12:49 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 10 Feb 2008 11:49:29 +0000 (12:49 +0100)
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.

audiod.c
audiod.h

index df725f96f216afe425e12ec14f0a7a9beba4178b..701f827848b112b735e3fa16cae371934200e8a8 100644 (file)
--- 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");
 }
 
index 0068177950ebc1dbfe0fe58f5074d04afcb6fa6a..c6746d20972e4abe865404a1785e419021322a4a 100644 (file)
--- 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;