Lines Matching defs:ar
81 struct audio_route *ar;
120 static inline struct mixer_ctl *index_to_ctl(struct audio_route *ar,
123 return ar->mixer_state[ctl_index].ctl;
127 static void path_print(struct audio_route *ar, struct mixer_path *path)
134 struct mixer_ctl *ctl = index_to_ctl(ar, path->setting[i].ctl_index);
151 static void path_free(struct audio_route *ar)
155 for (i = 0; i < ar->num_mixer_paths; i++) {
156 if (ar->mixer_path[i].name)
157 free(ar->mixer_path[i].name);
158 if (ar->mixer_path[i].setting) {
159 if (ar->mixer_path[i].setting->value.ptr)
160 free(ar->mixer_path[i].setting->value.ptr);
161 free(ar->mixer_path[i].setting);
164 free(ar->mixer_path);
165 ar->mixer_path = NULL;
166 ar->mixer_path_size = 0;
169 static struct mixer_path *path_get_by_name(struct audio_route *ar,
174 for (i = 0; i < ar->num_mixer_paths; i++)
175 if (strcmp(ar->mixer_path[i].name, name) == 0)
176 return &ar->mixer_path[i];
181 static struct mixer_path *path_create(struct audio_route *ar, const char *name)
185 if (path_get_by_name(ar, name)) {
191 if (ar->mixer_path_size <= ar->num_mixer_paths) {
192 if (ar->mixer_path_size == 0)
193 ar->mixer_path_size = INITIAL_MIXER_PATH_SIZE;
195 ar->mixer_path_size *= 2;
197 new_mixer_path = realloc(ar->mixer_path, ar->mixer_path_size *
203 ar->mixer_path = new_mixer_path;
208 ar->mixer_path[ar->num_mixer_paths].name = strdup(name);
209 ar->mixer_path[ar->num_mixer_paths].size = 0;
210 ar->mixer_path[ar->num_mixer_paths].length = 0;
211 ar->mixer_path[ar->num_mixer_paths].setting = NULL;
214 return &ar->mixer_path[ar->num_mixer_paths++];
257 static int path_add_setting(struct audio_route *ar, struct mixer_path *path,
263 struct mixer_ctl *ctl = index_to_ctl(ar, setting->ctl_index);
293 static int path_add_value(struct audio_route *ar, struct mixer_path *path,
302 ctl = index_to_ctl(ar, mixer_value->ctl_index);
363 static int path_add_path(struct audio_route *ar, struct mixer_path *path,
369 if (path_add_setting(ar, path, &sub_path->setting[i]) < 0)
375 static int path_apply(struct audio_route *ar, struct mixer_path *path)
384 ctl = index_to_ctl(ar, ctl_index);
389 memcpy(ar->mixer_state[ctl_index].new_value.ptr, path->setting[i].value.ptr,
396 static int path_reset(struct audio_route *ar, struct mixer_path *path)
405 ctl = index_to_ctl(ar, ctl_index);
411 memcpy(ar->mixer_state[ctl_index].new_value.ptr,
412 ar->mixer_state[ctl_index].reset_value.ptr,
413 ar->mixer_state[ctl_index].num_values * value_sz);
440 struct audio_route *ar = state->ar;
466 state->path = path_create(ar, (char *)attr_name);
469 struct mixer_path *sub_path = path_get_by_name(ar, attr_name);
470 path_add_path(ar, state->path, sub_path);
477 ctl = mixer_get_ctl_by_name(ar->mixer, attr_name);
500 for (ctl_index = 0; ctl_index < ar->num_mixer_ctls; ctl_index++) {
501 if (ar->mixer_state[ctl_index].ctl == ctl)
514 if (id < ar->mixer_state[ctl_index].num_values)
516 ar->mixer_state[ctl_index].new_value.bytes[id] = value;
518 ar->mixer_state[ctl_index].new_value.enumerated[id] = value;
520 ar->mixer_state[ctl_index].new_value.integer[id] = value;
526 for (i = 0; i < ar->mixer_state[ctl_index].num_values; i++)
528 ar->mixer_state[ctl_index].new_value.bytes[i] = value;
530 ar->mixer_state[ctl_index].new_value.enumerated[i] = value;
532 ar->mixer_state[ctl_index].new_value.integer[i] = value;
543 path_add_value(ar, state->path, &mixer_value);
559 static int alloc_mixer_state(struct audio_route *ar)
566 ar->num_mixer_ctls = mixer_get_num_ctls(ar->mixer);
567 ar->mixer_state = calloc(ar->num_mixer_ctls, sizeof(struct mixer_state));
568 if (!ar->mixer_state)
571 for (i = 0; i < ar->num_mixer_ctls; i++) {
572 ctl = mixer_get_ctl(ar->mixer, i);
575 ar->mixer_state[i].ctl = ctl;
576 ar->mixer_state[i].num_values = num_values;
585 ar->mixer_state[i].old_value.ptr = calloc(num_values, value_sz);
586 ar->mixer_state[i].new_value.ptr = calloc(num_values, value_sz);
587 ar->mixer_state[i].reset_value.ptr = calloc(num_values, value_sz);
590 ar->mixer_state[i].old_value.enumerated[0] = mixer_ctl_get_value(ctl, 0);
592 mixer_ctl_get_array(ctl, ar->mixer_state[i].old_value.ptr, num_values);
594 memcpy(ar->mixer_state[i].new_value.ptr, ar->mixer_state[i].old_value.ptr,
601 static void free_mixer_state(struct audio_route *ar)
606 for (i = 0; i < ar->num_mixer_ctls; i++) {
607 type = mixer_ctl_get_type(ar->mixer_state[i].ctl);
611 free(ar->mixer_state[i].old_value.ptr);
612 free(ar->mixer_state[i].new_value.ptr);
613 free(ar->mixer_state[i].reset_value.ptr);
616 free(ar->mixer_state);
617 ar->mixer_state = NULL;
621 int audio_route_update_mixer(struct audio_route *ar)
627 for (i = 0; i < ar->num_mixer_ctls; i++) {
628 unsigned int num_values = ar->mixer_state[i].num_values;
631 ctl = ar->mixer_state[i].ctl;
642 if (ar->mixer_state[i].old_value.bytes[j] != ar->mixer_state[i].new_value.bytes[j]) {
649 if (ar->mixer_state[i].old_value.enumerated[j]
650 != ar->mixer_state[i].new_value.enumerated[j]) {
657 if (ar->mixer_state[i].old_value.integer[j] != ar->mixer_state[i].new_value.integer[j]) {
665 mixer_ctl_set_value(ctl, 0, ar->mixer_state[i].new_value.enumerated[0]);
667 mixer_ctl_set_array(ctl, ar->mixer_state[i].new_value.ptr, num_values);
670 memcpy(ar->mixer_state[i].old_value.ptr, ar->mixer_state[i].new_value.ptr,
679 static void save_mixer_state(struct audio_route *ar)
684 for (i = 0; i < ar->num_mixer_ctls; i++) {
685 type = mixer_ctl_get_type(ar->mixer_state[i].ctl);
690 memcpy(ar->mixer_state[i].reset_value.ptr, ar->mixer_state[i].new_value.ptr,
691 ar->mixer_state[i].num_values * value_sz);
696 void audio_route_reset(struct audio_route *ar)
702 for (i = 0; i < ar->num_mixer_ctls; i++) {
703 type = mixer_ctl_get_type(ar->mixer_state[i].ctl);
708 memcpy(ar->mixer_state[i].new_value.ptr, ar->mixer_state[i].reset_value.ptr,
709 ar->mixer_state[i].num_values * value_sz);
714 int audio_route_apply_path(struct audio_route *ar, const char *name)
718 if (!ar) {
723 path = path_get_by_name(ar, name);
729 path_apply(ar, path);
735 int audio_route_reset_path(struct audio_route *ar, const char *name)
739 if (!ar) {
744 path = path_get_by_name(ar, name);
750 path_reset(ar, path);
759 static int audio_route_update_path(struct audio_route *ar, const char *name, bool reverse)
765 if (!ar) {
770 path = path_get_by_name(ar, name);
785 struct mixer_state * ms = &ar->mixer_state[ctl_index];
820 int audio_route_apply_and_update_path(struct audio_route *ar, const char *name)
822 if (audio_route_apply_path(ar, name) < 0) {
825 return audio_route_update_path(ar, name, false /*reverse*/);
828 int audio_route_reset_and_update_path(struct audio_route *ar, const char *name)
830 if (audio_route_reset_path(ar, name) < 0) {
833 return audio_route_update_path(ar, name, true /*reverse*/);
843 struct audio_route *ar;
845 ar = calloc(1, sizeof(struct audio_route));
846 if (!ar)
849 ar->mixer = mixer_open(card);
850 if (!ar->mixer) {
855 ar->mixer_path = NULL;
856 ar->mixer_path_size = 0;
857 ar->num_mixer_paths = 0;
860 if (alloc_mixer_state(ar) < 0)
881 state.ar = ar;
906 audio_route_update_mixer(ar);
907 save_mixer_state(ar);
911 return ar;
914 path_free(ar);
919 free_mixer_state(ar);
921 mixer_close(ar->mixer);
923 free(ar);
924 ar = NULL;
929 void audio_route_free(struct audio_route *ar)
931 free_mixer_state(ar);
932 mixer_close(ar->mixer);
933 path_free(ar);
934 free(ar);