X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=audio_route%2Faudio_route.c;h=700af61f558750844bf1710d8f78f655e115abdb;hb=0e2475f63a27c9868bbf22ddbb13c36f7766d44f;hp=89b076bb032e2dcbee6b312a3da58c475070a726;hpb=7180e89fd297601e45660457c1ed2d358eb20626;p=android-x86%2Fsystem-media.git diff --git a/audio_route/audio_route.c b/audio_route/audio_route.c index 89b076bb..700af61f 100644 --- a/audio_route/audio_route.c +++ b/audio_route/audio_route.c @@ -155,8 +155,14 @@ static void path_free(struct audio_route *ar) for (i = 0; i < ar->num_mixer_paths; i++) { free(ar->mixer_path[i].name); if (ar->mixer_path[i].setting) { - free(ar->mixer_path[i].setting->value.ptr); + size_t j; + for (j = 0; j < ar->mixer_path[i].length; j++) { + free(ar->mixer_path[i].setting[j].value.ptr); + } free(ar->mixer_path[i].setting); + ar->mixer_path[i].size = 0; + ar->mixer_path[i].length = 0; + ar->mixer_path[i].setting = NULL; } } free(ar->mixer_path); @@ -378,6 +384,7 @@ static int path_apply(struct audio_route *ar, struct mixer_path *path) struct mixer_ctl *ctl; enum mixer_ctl_type type; + ALOGD("Apply path: %s", path->name != NULL ? path->name : "none"); for (i = 0; i < path->length; i++) { ctl_index = path->setting[i].ctl_index; ctl = index_to_ctl(ar, ctl_index); @@ -399,6 +406,7 @@ static int path_reset(struct audio_route *ar, struct mixer_path *path) struct mixer_ctl *ctl; enum mixer_ctl_type type; + ALOGV("Reset path: %s", path->name != NULL ? path->name : "none"); for (i = 0; i < path->length; i++) { ctl_index = path->setting[i].ctl_index; ctl = index_to_ctl(ar, ctl_index); @@ -474,12 +482,14 @@ static void start_tag(void *data, const XML_Char *tag_name, if (state->level == 1) { /* top level path: create and stash the path */ state->path = path_create(ar, (char *)attr_name); + if (state->path == NULL) + ALOGE("path created failed, please check the path if existed"); } else { /* nested path */ struct mixer_path *sub_path = path_get_by_name(ar, attr_name); if (!sub_path) { ALOGE("unable to find sub path '%s'", attr_name); - } else { + } else if (state->path != NULL) { path_add_path(ar, state->path, sub_path); } } @@ -554,7 +564,8 @@ static void start_tag(void *data, const XML_Char *tag_name, mixer_value.index = atoi((char *)attr_id); else mixer_value.index = -1; - path_add_value(ar, state->path, &mixer_value); + if (state->path != NULL) + path_add_value(ar, state->path, &mixer_value); } } @@ -773,7 +784,6 @@ int audio_route_reset_path(struct audio_route *ar, const char *name) static int audio_route_update_path(struct audio_route *ar, const char *name, bool reverse) { struct mixer_path *path; - int32_t i, end; unsigned int j; if (!ar) { @@ -787,14 +797,12 @@ static int audio_route_update_path(struct audio_route *ar, const char *name, boo return -1; } - i = reverse ? (path->length - 1) : 0; - end = reverse ? -1 : (int32_t)path->length; - while (i != end) { + for (size_t i = 0; i < path->length; ++i) { unsigned int ctl_index; enum mixer_ctl_type type; - ctl_index = path->setting[i].ctl_index; + ctl_index = path->setting[reverse ? path->length - 1 - i : i].ctl_index; struct mixer_state * ms = &ar->mixer_state[ctl_index]; @@ -825,8 +833,6 @@ static int audio_route_update_path(struct audio_route *ar, const char *name, boo break; } } - - i = reverse ? (i - 1) : (i + 1); } return 0; }