Lines Matching refs:ar

82     struct audio_route *ar;  member
121 static inline struct mixer_ctl *index_to_ctl(struct audio_route *ar, in index_to_ctl() argument
124 return ar->mixer_state[ctl_index].ctl; in index_to_ctl()
128 static void path_print(struct audio_route *ar, struct mixer_path *path)
135 struct mixer_ctl *ctl = index_to_ctl(ar, path->setting[i].ctl_index);
152 static void path_free(struct audio_route *ar) in path_free() argument
156 for (i = 0; i < ar->num_mixer_paths; i++) { in path_free()
157 free(ar->mixer_path[i].name); in path_free()
158 if (ar->mixer_path[i].setting) { in path_free()
160 for (j = 0; j < ar->mixer_path[i].length; j++) { in path_free()
161 free(ar->mixer_path[i].setting[j].value.ptr); in path_free()
163 free(ar->mixer_path[i].setting); in path_free()
164 ar->mixer_path[i].size = 0; in path_free()
165 ar->mixer_path[i].length = 0; in path_free()
166 ar->mixer_path[i].setting = NULL; in path_free()
169 free(ar->mixer_path); in path_free()
170 ar->mixer_path = NULL; in path_free()
171 ar->mixer_path_size = 0; in path_free()
172 ar->num_mixer_paths = 0; in path_free()
175 static struct mixer_path *path_get_by_name(struct audio_route *ar, in path_get_by_name() argument
180 for (i = 0; i < ar->num_mixer_paths; i++) in path_get_by_name()
181 if (strcmp(ar->mixer_path[i].name, name) == 0) in path_get_by_name()
182 return &ar->mixer_path[i]; in path_get_by_name()
187 static struct mixer_path *path_create(struct audio_route *ar, const char *name) in path_create() argument
191 if (path_get_by_name(ar, name)) { in path_create()
197 if (ar->mixer_path_size <= ar->num_mixer_paths) { in path_create()
198 if (ar->mixer_path_size == 0) in path_create()
199 ar->mixer_path_size = INITIAL_MIXER_PATH_SIZE; in path_create()
201 ar->mixer_path_size *= 2; in path_create()
203 new_mixer_path = realloc(ar->mixer_path, ar->mixer_path_size * in path_create()
209 ar->mixer_path = new_mixer_path; in path_create()
214 ar->mixer_path[ar->num_mixer_paths].name = strdup(name); in path_create()
215 ar->mixer_path[ar->num_mixer_paths].size = 0; in path_create()
216 ar->mixer_path[ar->num_mixer_paths].length = 0; in path_create()
217 ar->mixer_path[ar->num_mixer_paths].setting = NULL; in path_create()
220 return &ar->mixer_path[ar->num_mixer_paths++]; in path_create()
263 static int path_add_setting(struct audio_route *ar, struct mixer_path *path, in path_add_setting() argument
269 struct mixer_ctl *ctl = index_to_ctl(ar, setting->ctl_index); in path_add_setting()
299 static int path_add_value(struct audio_route *ar, struct mixer_path *path, in path_add_value() argument
308 ctl = index_to_ctl(ar, mixer_value->ctl_index); in path_add_value()
369 static int path_add_path(struct audio_route *ar, struct mixer_path *path, in path_add_path() argument
375 if (path_add_setting(ar, path, &sub_path->setting[i]) < 0) in path_add_path()
381 static int path_apply(struct audio_route *ar, struct mixer_path *path) in path_apply() argument
391 ctl = index_to_ctl(ar, ctl_index); in path_apply()
396 memcpy(ar->mixer_state[ctl_index].new_value.ptr, path->setting[i].value.ptr, in path_apply()
403 static int path_reset(struct audio_route *ar, struct mixer_path *path) in path_reset() argument
413 ctl = index_to_ctl(ar, ctl_index); in path_reset()
419 memcpy(ar->mixer_state[ctl_index].new_value.ptr, in path_reset()
420 ar->mixer_state[ctl_index].reset_value.ptr, in path_reset()
421 ar->mixer_state[ctl_index].num_values * value_sz); in path_reset()
459 struct audio_route *ar = state->ar; in start_tag() local
485 state->path = path_create(ar, (char *)attr_name); in start_tag()
490 struct mixer_path *sub_path = path_get_by_name(ar, attr_name); in start_tag()
494 path_add_path(ar, state->path, sub_path); in start_tag()
502 ctl = mixer_get_ctl_by_name(ar->mixer, attr_name); in start_tag()
525 for (ctl_index = 0; ctl_index < ar->num_mixer_ctls; ctl_index++) { in start_tag()
526 if (ar->mixer_state[ctl_index].ctl == ctl) in start_tag()
539 if (id < ar->mixer_state[ctl_index].num_values) in start_tag()
541 ar->mixer_state[ctl_index].new_value.bytes[id] = value; in start_tag()
543 ar->mixer_state[ctl_index].new_value.enumerated[id] = value; in start_tag()
545 ar->mixer_state[ctl_index].new_value.integer[id] = value; in start_tag()
551 for (i = 0; i < ar->mixer_state[ctl_index].num_values; i++) in start_tag()
553 ar->mixer_state[ctl_index].new_value.bytes[i] = value; in start_tag()
555 ar->mixer_state[ctl_index].new_value.enumerated[i] = value; in start_tag()
557 ar->mixer_state[ctl_index].new_value.integer[i] = value; in start_tag()
569 path_add_value(ar, state->path, &mixer_value); in start_tag()
585 static int alloc_mixer_state(struct audio_route *ar) in alloc_mixer_state() argument
592 ar->num_mixer_ctls = mixer_get_num_ctls(ar->mixer); in alloc_mixer_state()
593 ar->mixer_state = calloc(ar->num_mixer_ctls, sizeof(struct mixer_state)); in alloc_mixer_state()
594 if (!ar->mixer_state) in alloc_mixer_state()
597 for (i = 0; i < ar->num_mixer_ctls; i++) { in alloc_mixer_state()
598 ctl = mixer_get_ctl(ar->mixer, i); in alloc_mixer_state()
601 ar->mixer_state[i].ctl = ctl; in alloc_mixer_state()
602 ar->mixer_state[i].num_values = num_values; in alloc_mixer_state()
603 ar->mixer_state[i].active_count = 0; in alloc_mixer_state()
612 ar->mixer_state[i].old_value.ptr = calloc(num_values, value_sz); in alloc_mixer_state()
613 ar->mixer_state[i].new_value.ptr = calloc(num_values, value_sz); in alloc_mixer_state()
614 ar->mixer_state[i].reset_value.ptr = calloc(num_values, value_sz); in alloc_mixer_state()
617 ar->mixer_state[i].old_value.enumerated[0] = mixer_ctl_get_value(ctl, 0); in alloc_mixer_state()
619 mixer_ctl_get_array(ctl, ar->mixer_state[i].old_value.ptr, num_values); in alloc_mixer_state()
621 memcpy(ar->mixer_state[i].new_value.ptr, ar->mixer_state[i].old_value.ptr, in alloc_mixer_state()
628 static void free_mixer_state(struct audio_route *ar) in free_mixer_state() argument
633 for (i = 0; i < ar->num_mixer_ctls; i++) { in free_mixer_state()
634 type = mixer_ctl_get_type(ar->mixer_state[i].ctl); in free_mixer_state()
638 free(ar->mixer_state[i].old_value.ptr); in free_mixer_state()
639 free(ar->mixer_state[i].new_value.ptr); in free_mixer_state()
640 free(ar->mixer_state[i].reset_value.ptr); in free_mixer_state()
643 free(ar->mixer_state); in free_mixer_state()
644 ar->mixer_state = NULL; in free_mixer_state()
648 int audio_route_update_mixer(struct audio_route *ar) in audio_route_update_mixer() argument
654 for (i = 0; i < ar->num_mixer_ctls; i++) { in audio_route_update_mixer()
655 unsigned int num_values = ar->mixer_state[i].num_values; in audio_route_update_mixer()
658 ctl = ar->mixer_state[i].ctl; in audio_route_update_mixer()
669 … if (ar->mixer_state[i].old_value.bytes[j] != ar->mixer_state[i].new_value.bytes[j]) { in audio_route_update_mixer()
676 if (ar->mixer_state[i].old_value.enumerated[j] in audio_route_update_mixer()
677 != ar->mixer_state[i].new_value.enumerated[j]) { in audio_route_update_mixer()
684 … if (ar->mixer_state[i].old_value.integer[j] != ar->mixer_state[i].new_value.integer[j]) { in audio_route_update_mixer()
692 mixer_ctl_set_value(ctl, 0, ar->mixer_state[i].new_value.enumerated[0]); in audio_route_update_mixer()
694 mixer_ctl_set_array(ctl, ar->mixer_state[i].new_value.ptr, num_values); in audio_route_update_mixer()
697 memcpy(ar->mixer_state[i].old_value.ptr, ar->mixer_state[i].new_value.ptr, in audio_route_update_mixer()
706 static void save_mixer_state(struct audio_route *ar) in save_mixer_state() argument
711 for (i = 0; i < ar->num_mixer_ctls; i++) { in save_mixer_state()
712 type = mixer_ctl_get_type(ar->mixer_state[i].ctl); in save_mixer_state()
717 memcpy(ar->mixer_state[i].reset_value.ptr, ar->mixer_state[i].new_value.ptr, in save_mixer_state()
718 ar->mixer_state[i].num_values * value_sz); in save_mixer_state()
723 void audio_route_reset(struct audio_route *ar) in audio_route_reset() argument
729 for (i = 0; i < ar->num_mixer_ctls; i++) { in audio_route_reset()
730 type = mixer_ctl_get_type(ar->mixer_state[i].ctl); in audio_route_reset()
735 memcpy(ar->mixer_state[i].new_value.ptr, ar->mixer_state[i].reset_value.ptr, in audio_route_reset()
736 ar->mixer_state[i].num_values * value_sz); in audio_route_reset()
741 int audio_route_apply_path(struct audio_route *ar, const char *name) in audio_route_apply_path() argument
745 if (!ar) { in audio_route_apply_path()
750 path = path_get_by_name(ar, name); in audio_route_apply_path()
756 path_apply(ar, path); in audio_route_apply_path()
762 int audio_route_reset_path(struct audio_route *ar, const char *name) in audio_route_reset_path() argument
766 if (!ar) { in audio_route_reset_path()
771 path = path_get_by_name(ar, name); in audio_route_reset_path()
777 path_reset(ar, path); in audio_route_reset_path()
786 static int audio_route_update_path(struct audio_route *ar, const char *name, bool reverse) in audio_route_update_path() argument
791 if (!ar) { in audio_route_update_path()
796 path = path_get_by_name(ar, name); in audio_route_update_path()
808 struct mixer_state * ms = &ar->mixer_state[ctl_index]; in audio_route_update_path()
871 int audio_route_apply_and_update_path(struct audio_route *ar, const char *name) in audio_route_apply_and_update_path() argument
873 if (audio_route_apply_path(ar, name) < 0) { in audio_route_apply_and_update_path()
876 return audio_route_update_path(ar, name, false /*reverse*/); in audio_route_apply_and_update_path()
879 int audio_route_reset_and_update_path(struct audio_route *ar, const char *name) in audio_route_reset_and_update_path() argument
881 if (audio_route_reset_path(ar, name) < 0) { in audio_route_reset_and_update_path()
884 return audio_route_update_path(ar, name, true /*reverse*/); in audio_route_reset_and_update_path()
894 struct audio_route *ar; in audio_route_init() local
896 ar = calloc(1, sizeof(struct audio_route)); in audio_route_init()
897 if (!ar) in audio_route_init()
900 ar->mixer = mixer_open(card); in audio_route_init()
901 if (!ar->mixer) { in audio_route_init()
906 ar->mixer_path = NULL; in audio_route_init()
907 ar->mixer_path_size = 0; in audio_route_init()
908 ar->num_mixer_paths = 0; in audio_route_init()
911 if (alloc_mixer_state(ar) < 0) in audio_route_init()
932 state.ar = ar; in audio_route_init()
957 audio_route_update_mixer(ar); in audio_route_init()
958 save_mixer_state(ar); in audio_route_init()
962 return ar; in audio_route_init()
965 path_free(ar); in audio_route_init()
970 free_mixer_state(ar); in audio_route_init()
972 mixer_close(ar->mixer); in audio_route_init()
974 free(ar); in audio_route_init()
975 ar = NULL; in audio_route_init()
980 void audio_route_free(struct audio_route *ar) in audio_route_free() argument
982 free_mixer_state(ar); in audio_route_free()
983 mixer_close(ar->mixer); in audio_route_free()
984 path_free(ar); in audio_route_free()
985 free(ar); in audio_route_free()