static void tinymix_detail_control(struct mixer *mixer, const char *control, int print_all) { struct mixer_ctl *ctl; enum mixer_ctl_type type; unsigned int num_values; unsigned int i; int min, max; if (isdigit(control[0])) ctl = mixer_get_ctl(mixer, atoi(control)); else ctl = mixer_get_ctl_by_name(mixer, control); if (!ctl) { fprintf(stderr, "Invalid mixer control\n"); return; } type = mixer_ctl_get_type(ctl); num_values = mixer_ctl_get_num_values(ctl); if (print_all) printf("%s:", mixer_ctl_get_name(ctl)); for (i = 0; i < num_values; i++) { switch (type) { case MIXER_CTL_TYPE_INT: printf(" %d", mixer_ctl_get_value(ctl, i)); break; case MIXER_CTL_TYPE_BOOL: printf(" %s", mixer_ctl_get_value(ctl, i) ? "On" : "Off"); break; case MIXER_CTL_TYPE_ENUM: tinymix_print_enum(ctl, print_all); break; case MIXER_CTL_TYPE_BYTE: printf(" 0x%02x", mixer_ctl_get_value(ctl, i)); break; default: printf(" unknown"); break; }; } if (print_all) { if (type == MIXER_CTL_TYPE_INT) { min = mixer_ctl_get_range_min(ctl); max = mixer_ctl_get_range_max(ctl); printf(" (range %d->%d)", min, max); } } printf("\n"); }
static void tinymix_detail_control(struct mixer *mixer, unsigned int id, int print_all) { struct mixer_ctl *ctl; enum mixer_ctl_type type; unsigned int num_values; char buffer[256]; unsigned int i; int min, max; if (id >= mixer_get_num_ctls(mixer)) { fprintf(stderr, "Invalid mixer control\n"); return; } ctl = mixer_get_ctl(mixer, id); mixer_ctl_get_name(ctl, buffer, sizeof(buffer)); type = mixer_ctl_get_type(ctl); num_values = mixer_ctl_get_num_values(ctl); if (print_all) printf("%s:", buffer); for (i = 0; i < num_values; i++) { switch (type) { case MIXER_CTL_TYPE_INT: printf(" %d", mixer_ctl_get_value(ctl, i)); break; case MIXER_CTL_TYPE_BOOL: printf(" %s", mixer_ctl_get_value(ctl, i) ? "On" : "Off"); break; case MIXER_CTL_TYPE_ENUM: tinymix_print_enum(ctl, print_all); break; case MIXER_CTL_TYPE_BYTE: printf(" 0x%02x", mixer_ctl_get_value(ctl, i)); break; default: printf(" unknown"); break; }; } if (print_all) { if (type == MIXER_CTL_TYPE_INT) { min = mixer_ctl_get_range_min(ctl); max = mixer_ctl_get_range_max(ctl); printf(" (range %d->%d)", min, max); } } printf("\n"); }
int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id) { if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER)) return -EINVAL; return int_to_percent(&ctl->info, mixer_ctl_get_value(ctl, id)); }
size_t actlstr(char *buf, size_t n, char *ch, struct mixer *mx) { size_t ret; char *status; struct mixer_ctl *ctl; if (!(ctl = mixer_get_ctl_by_name(mx, ch))) { mixer_close(mx); die("couldn't find mixer ctl '%s'\n", ch); } switch (mixer_ctl_get_type(ctl)) { case MIXER_CTL_TYPE_INT: if ((ret = snprintf(buf, n, "%d%%", mixer_ctl_get_percent(ctl, 0))) > n) ret = n; break; case MIXER_CTL_TYPE_BOOL: status = mixer_ctl_get_value(ctl, 0) ? "On" : "Off"; ret = stpncpy(buf, status, n) - buf; break; default: mixer_close(mx); die("unsupported ctl type '%s'\n", mixer_ctl_get_type_string(ctl)); }; return ret; }
bool TinyAmixerControlValue::readControl(struct mixer_ctl *mixerControl, size_t elementCount, std::string &error) { uint32_t elementNumber; // Read element // Go through all elements for (elementNumber = 0; elementNumber < elementCount; elementNumber++) { int32_t value; if ((value = mixer_ctl_get_value(mixerControl, elementNumber)) < 0) { error = "Failed to read value in mixer control: " + getControlName(); return false; } if (isDebugEnabled()) { info() << "Reading alsa element " << getControlName() << ", index " << elementNumber << " with value " << value; } toBlackboard(value); } return true; }
static int alloc_mixer_state(struct audio_route *ar) { unsigned int i; unsigned int j; if (!ar) { ALOGE("%s: invalid audio_route", __func__); return -1; } ar->num_mixer_ctls = mixer_get_num_ctls(ar->mixer); ar->mixer_state = malloc(ar->num_mixer_ctls * sizeof(struct mixer_state)); if (!ar->mixer_state) return -1; for (i = 0; i < ar->num_mixer_ctls; i++) { ar->mixer_state[i].ctl = mixer_get_ctl(ar->mixer, i); ar->mixer_state[i].ctl_vals = mixer_ctl_get_num_values(ar->mixer_state[i].ctl); ar->mixer_state[i].ignored = 0; if (ar->mixer_state[i].ctl_vals > MAX_CTL_VALS) { ar->mixer_state[i].ctl_vals = MAX_CTL_VALS; } for (j = 0; j < ar->mixer_state[i].ctl_vals; j++) { ar->mixer_state[i].old_value[j] = mixer_ctl_get_value(ar->mixer_state[i].ctl, j); ar->mixer_state[i].new_value[j] = ar->mixer_state[i].old_value[j]; } } return 0; }
static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all) { unsigned int num_enums; unsigned int i; const char *string; num_enums = mixer_ctl_get_num_enums(ctl); for (i = 0; i < num_enums; i++) { string = mixer_ctl_get_enum_string(ctl, i); if (print_all) printf("\t%s%s", mixer_ctl_get_value(ctl, 0) == (int)i ? ">" : "", string); else if (mixer_ctl_get_value(ctl, 0) == (int)i) printf(" %-s", string); } }
static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all) { unsigned int num_enums; char buffer[256]; unsigned int i; num_enums = mixer_ctl_get_num_enums(ctl); for (i = 0; i < num_enums; i++) { mixer_ctl_get_enum_string(ctl, i, buffer, sizeof(buffer)); if (print_all) printf("\t%s%s", mixer_ctl_get_value(ctl, 0) == (int)i ? ">" : "", buffer); else if (mixer_ctl_get_value(ctl, 0) == (int)i) printf(" %-s", buffer); } }
/* saves the current state of the mixer, for resetting all controls */ static void save_mixer_state(struct audio_route *ar) { unsigned int i; for (i = 0; i < ar->num_mixer_ctls; i++) { /* only get value 0, assume multiple ctl values are the same */ ar->mixer_state[i].reset_value = mixer_ctl_get_value(ar->mixer_state[i].ctl, 0); } }
/* saves the current state of the mixer, for resetting all controls */ static void save_mixer_state(struct audio_route *ar) { unsigned int i; if (!ar) { ALOGE("%s: invalid audio_route", __FUNCTION__); return; } for (i = 0; i < ar->num_mixer_ctls; i++) { /* only get value 0, assume multiple ctl values are the same */ ar->mixer_state[i].reset_value = mixer_ctl_get_value(ar->mixer_state[i].ctl, 0); } }
/* saves the current state of the mixer, for resetting all controls */ static void save_mixer_state(struct audio_route *ar) { unsigned int i; unsigned int j; if (!ar) { ALOGE("%s: invalid audio_route", __func__); return; } for (i = 0; i < ar->num_mixer_ctls; i++) { for (j = 0; j < ar->mixer_state[i].ctl_vals; j++) { ar->mixer_state[i].reset_value[j] = mixer_ctl_get_value(ar->mixer_state[i].ctl, j); } } }
/// Speaker over current test int AudioFtm::Audio_READ_SPK_OC_STA(void) { ALOGD("%s()", __FUNCTION__); struct mixer_ctl *ctl; int retval, dValue; ctl = mixer_get_ctl_by_name(mMixer, "Audio_Speaker_OC_Falg"); if (NULL == ctl) { ALOGD("[%s] [%d]", __FUNCTION__, __LINE__); return true; //true means SPK OC fail } dValue = mixer_ctl_get_value(ctl, 0); ALOGD("-%s() value [0x%x]", __FUNCTION__, dValue); return dValue; }
static void tinymix_print_enum(struct mixer_ctl *ctl) { unsigned int num_enums; unsigned int i; unsigned int value; const char *string; num_enums = mixer_ctl_get_num_enums(ctl); value = mixer_ctl_get_value(ctl, 0); for (i = 0; i < num_enums; i++) { string = mixer_ctl_get_enum_string(ctl, i); printf("%s%s, ", value == i ? "> " : "", string); } }
static int alloc_mixer_state(struct audio_route *ar) { unsigned int i; unsigned int j; unsigned int num_values; struct mixer_ctl *ctl; bool linked; ar->num_mixer_ctls = mixer_get_num_ctls(ar->mixer); ar->mixer_state = malloc(ar->num_mixer_ctls * sizeof(struct mixer_state)); if (!ar->mixer_state) return -1; for (i = 0; i < ar->num_mixer_ctls; i++) { ctl = mixer_get_ctl(ar->mixer, i); num_values = mixer_ctl_get_num_values(ctl); ar->mixer_state[i].old_value = malloc(num_values * sizeof(int)); ar->mixer_state[i].new_value = malloc(num_values * sizeof(int)); ar->mixer_state[i].reset_value = malloc(num_values * sizeof(int)); /* * Get all mixer values for controls with multiple values. If all * values are the same, set the linked flag. */ linked = true; for (j = 0; j < num_values; j++) { ar->mixer_state[i].old_value[j] = mixer_ctl_get_value(ctl, j); ar->mixer_state[i].new_value[j] = ar->mixer_state[i].old_value[j]; /* * If the next value is different from the last, set linked to * false. */ if ((j > 0) && (ar->mixer_state[i].old_value[j - 1] != ar->mixer_state[i].old_value[j])) { linked = false; } } ar->mixer_state[i].ctl = ctl; ar->mixer_state[i].old_linked = linked; ar->mixer_state[i].new_linked = linked; ar->mixer_state[i].num_values = num_values; } return 0; }
static int alloc_mixer_state(struct audio_route *ar) { unsigned int i; ar->num_mixer_ctls = mixer_get_num_ctls(ar->mixer); ar->mixer_state = malloc(ar->num_mixer_ctls * sizeof(struct mixer_state)); if (!ar->mixer_state) return -1; for (i = 0; i < ar->num_mixer_ctls; i++) { ar->mixer_state[i].ctl = mixer_get_ctl(ar->mixer, i); /* only get value 0, assume multiple ctl values are the same */ ar->mixer_state[i].old_value = mixer_ctl_get_value(ar->mixer_state[i].ctl, 0); ar->mixer_state[i].new_value = ar->mixer_state[i].old_value; } return 0; }
bool AudioFtm::ReadAuxadcData(int channel, int *value) { struct mixer_ctl *ctl; int retval, dValue; channel = 0x001B; //AUX_SPK_THR_I_AP include mt_pmic.h ALOGD("+%s() channel [0x%x] (force to replace)", __FUNCTION__, channel); ctl = mixer_get_ctl_by_name(mMixer, "Audio AUXADC Data"); if (NULL == ctl || NULL == value) { ALOGD("[%s] [%d]", __FUNCTION__, __LINE__); return false; } retval = mixer_ctl_set_value(ctl, 0, channel); usleep(1000); dValue = mixer_ctl_get_value(ctl, 0); *value = dValue; ALOGD("-%s() value [0x%x]", __FUNCTION__, dValue); return false; }
int write_percentage(int argc, char **argv) { int nMixer = -1, nControl = -1; int location = -1, value = -1; if (argc == 6) { nMixer = atoi(argv[2]); nControl = atoi(argv[3]); location = atoi(argv[4]); value = atoi(argv[5]); } if (argc != 6 || nMixer < 0 || nMixer > 7 || nControl < 0 || location < 0) { printf("Usage: ainfo write-percentage <card number> <control number> <location> <value>\n" "where <card number> is between 0 and 7\n" "<control number> is the control to be written\n" "<location> is the location to be written\n" "<value> is the value to be written\n"); return 0; } mixer *m = mixer_open(nMixer); if (m == NULL) { printf("Unable to open card #%d\n", nMixer); return 0; } mixer_ctl *c = mixer_get_ctl(m, nControl); if (c == NULL) { printf("Unable to open control #%d\n", nControl); return 0; } char name[64], type[64]; mixer_ctl_get_name(c, name, sizeof(name)); mixer_ctl_set_percent(c, location, value); printf("Control: %s\nPercent: %d\nValue: %d\n", name, mixer_ctl_get_percent(c, location), mixer_ctl_get_value(c, location)); return 0; }
static int alloc_mixer_state(struct audio_route *ar) { unsigned int i; unsigned int j; unsigned int num_values; struct mixer_ctl *ctl; enum mixer_ctl_type type; ar->num_mixer_ctls = mixer_get_num_ctls(ar->mixer); ar->mixer_state = malloc(ar->num_mixer_ctls * sizeof(struct mixer_state)); if (!ar->mixer_state) return -1; for (i = 0; i < ar->num_mixer_ctls; i++) { ctl = mixer_get_ctl(ar->mixer, i); num_values = mixer_ctl_get_num_values(ctl); ar->mixer_state[i].ctl = ctl; ar->mixer_state[i].num_values = num_values; /* Skip unsupported types that are not supported yet in XML */ type = mixer_ctl_get_type(ctl); if ((type != MIXER_CTL_TYPE_BOOL) && (type != MIXER_CTL_TYPE_INT) && (type != MIXER_CTL_TYPE_ENUM)) continue; ar->mixer_state[i].old_value = malloc(num_values * sizeof(int)); ar->mixer_state[i].new_value = malloc(num_values * sizeof(int)); ar->mixer_state[i].reset_value = malloc(num_values * sizeof(int)); if (type == MIXER_CTL_TYPE_ENUM) ar->mixer_state[i].old_value[0] = mixer_ctl_get_value(ctl, 0); else mixer_ctl_get_array(ctl, ar->mixer_state[i].old_value, num_values); memcpy(ar->mixer_state[i].new_value, ar->mixer_state[i].old_value, num_values * sizeof(int)); } return 0; }
static void set_headphone_volume(struct mixer_ctl *reg, int volume) { int i = 0; int val=0; val = mixer_ctl_get_value(reg, 0); if(val == volume){ //ALOGV("volume equal"); return; } if(val >volume){ for(i=val; i>=volume; i--){ mixer_ctl_set_value(reg, 0, i); usleep(5000); } } else { for(i=val; i<=volume; i++){ mixer_ctl_set_value(reg, 0, i); usleep(5000); } } }
static int set_phone_path(struct codec_client *client, int path) { int ret = -1; int earpiece_on=0, headset_on=0, headphone_on=0, bt_on=0, speaker_on=0; int pa_should_on=0; headset_on = path & AUDIO_DEVICE_OUT_WIRED_HEADSET; // hp4p headphone_on = path & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; // hp3p speaker_on = path & AUDIO_DEVICE_OUT_SPEAKER; earpiece_on = path & AUDIO_DEVICE_OUT_EARPIECE; bt_on = path & AUDIO_DEVICE_OUT_ALL_SCO; ALOGV("mode= phone mode 4, devices is 0x%x, ****LINE:%d,FUNC:%s", path, __LINE__,__FUNCTION__); #if 0 if(!wake_lock){ grabPartialWakeLock(); wake_lock=true; } if(last_path_is_bt){ last_path_is_bt = false; plan_two_stop_bt_voice(); #if 1 if(mixer_ctl_get_value(client->mixer_ctls->audio_adc_phone_in, 0) == 1 ){ ALOGV("mode= phone audio_adc_phone_in=1"); mixer_ctl_set_value(client->mixer_ctls->audio_adc_phone_in, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_dac_phone_out, 0, 0); } #endif } if (g_is_bp_thread_running == false){ plan_two_start_voice(); g_is_bp_thread_running = true; } #endif if(mixer_ctl_get_value(client->mixer_ctls->audio_linein_in,0)){ mixer_ctl_set_value(client->mixer_ctls->audio_linein_in, 0, 0); //turn off fm } #if 1 if(earpiece_on && (no_earpiece == 0)) { mixer_ctl_set_value(client->mixer_ctls->audio_digital_headset_mic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_digital_main_mic, 0, 1); mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "earpiece");// "spk" : "headset"); ALOGV("in earpiece ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else if(speaker_on || (earpiece_on && (no_earpiece == 1))) { mixer_ctl_set_value(client->mixer_ctls->audio_digital_headset_mic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_digital_main_mic, 0, 1); mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "spk");// "spk" : "headset"); ALOGV("in speaker pa ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else if (headphone_on) { //no mic hp3p mixer_ctl_set_value(client->mixer_ctls->audio_digital_headset_mic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_digital_main_mic, 0, 1); mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "headset");// "spk" : "headset"); ALOGV("in wire head with no mic ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else if (headset_on) { //mic // hp4p mixer_ctl_set_value(client->mixer_ctls->audio_digital_main_mic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_digital_headset_mic, 0, 1); mixer_ctl_set_enum_by_string(client->mixer_ctls->audio_spk_headset_switch, "headset");// "spk" : "headset"); ALOGV("in wire head with mic ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else if (bt_on) { if (g_is_bp_thread_running == true){ plan_two_stop_voice(); g_is_bp_thread_running = false; } mixer_ctl_set_value(client->mixer_ctls->audio_digital_main_mic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_digital_headset_mic, 0, 0); #if 0 // for a23 ALOGV("in bluetooth ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); mixer_ctl_set_value(client->mixer_ctls->audio_adc_phone_in, 0, 1); mixer_ctl_set_value(client->mixer_ctls->audio_dac_phone_out, 0, 1); plan_two_start_bt_voice(client->vol_array->up_pcm_gain); last_path_is_bt = true; //property_set(BLUETOOTH_VOICE, "on"); //adev->bluetooth_voice = true; #endif } #endif return 0; }
static void tinymix_detail_control(struct mixer *mixer, const char *control) { struct mixer_ctl *ctl; enum mixer_ctl_type type; unsigned int num_values; unsigned int i; int min, max; int ret; char *buf = NULL; unsigned int tlv_header_size = 0; if (isdigit(control[0])) ctl = mixer_get_ctl(mixer, atoi(control)); else ctl = mixer_get_ctl_by_name(mixer, control); if (!ctl) { fprintf(stderr, "Invalid mixer control\n"); return; } type = mixer_ctl_get_type(ctl); num_values = mixer_ctl_get_num_values(ctl); if ((type == MIXER_CTL_TYPE_BYTE) && (num_values > 0)) { if (mixer_ctl_is_access_tlv_rw(ctl) != 0) { tlv_header_size = TLV_HEADER_SIZE; } buf = calloc(1, num_values + tlv_header_size); if (buf == NULL) { fprintf(stderr, "Failed to alloc mem for bytes %u\n", num_values); return; } ret = mixer_ctl_get_array(ctl, buf, num_values + tlv_header_size); if (ret < 0) { fprintf(stderr, "Failed to mixer_ctl_get_array\n"); free(buf); return; } } for (i = 0; i < num_values; i++) { switch (type) { case MIXER_CTL_TYPE_INT: printf("%d", mixer_ctl_get_value(ctl, i)); break; case MIXER_CTL_TYPE_BOOL: printf("%s", mixer_ctl_get_value(ctl, i) ? "On" : "Off"); break; case MIXER_CTL_TYPE_ENUM: tinymix_print_enum(ctl); break; case MIXER_CTL_TYPE_BYTE: /* skip printing TLV header if exists */ printf(" %02x", buf[i + tlv_header_size]); break; default: printf("unknown"); break; }; if ((i + 1) < num_values) { printf(", "); } } if (type == MIXER_CTL_TYPE_INT) { min = mixer_ctl_get_range_min(ctl); max = mixer_ctl_get_range_max(ctl); printf(" (range %d->%d)", min, max); } free(buf); }
static int set_phone_path(struct codec_client *client, int path) { int ret = -1; int earpiece_on=0, headset_on=0, headphone_on=0, bt_on=0, speaker_on=0; int pa_should_on=0; headset_on = path & AUDIO_DEVICE_OUT_WIRED_HEADSET; // hp4p headphone_on = path & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; // hp3p speaker_on = path & AUDIO_DEVICE_OUT_SPEAKER; earpiece_on = path & AUDIO_DEVICE_OUT_EARPIECE; bt_on = path & AUDIO_DEVICE_OUT_ALL_SCO; ALOGV("mode= phone mode 4, devices is 0x%x, ****LINE:%d,FUNC:%s", path, __LINE__,__FUNCTION__); in_call = true; if(last_path_is_bt){ plan_one_stop_bt_voice(); if (bluetooth_in_record == true){ plan_one_stop_bt_record(); bluetooth_in_record = false; } last_path_is_bt = false; if(mixer_ctl_get_value(client->mixer_ctls->audio_adc_phone_in, 0) == 1 ){ mixer_ctl_set_value(client->mixer_ctls->audio_adc_phone_in, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_dac_phone_out, 0, 0); } } if (is_in_record){ client->record_ops->set_record_source(!bt_on); } if(mixer_ctl_get_value(client->mixer_ctls->audio_linein_in,0)){ mixer_ctl_set_value(client->mixer_ctls->audio_linein_in, 0, 0); //turn off fm } if (bt_on){ mixer_ctl_set_value(client->mixer_ctls->audio_phone_in, 0,0); } else { mixer_ctl_set_value(client->mixer_ctls->audio_phone_in, 0,1); } #if 1 mixer_ctl_set_value(client->mixer_ctls->audio_phone_out, 0,1); if(earpiece_on && (no_earpiece == 0)){ mixer_ctl_set_value(client->mixer_ctls->audio_speaker_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_headphone_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_earpiece_out, 0, 1); mixer_ctl_set_value(client->mixer_ctls->audio_phone_headset_mic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_phone_main_mic, 0, 1); ALOGV("in earpiece ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else if(speaker_on || (earpiece_on && (no_earpiece == 1))) { mixer_ctl_set_value(client->mixer_ctls->audio_earpiece_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_headphone_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_speaker_out, 0, 1); mixer_ctl_set_value(client->mixer_ctls->audio_phone_headset_mic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_phone_main_mic, 0, 1); ALOGV("in speaker pa ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else if (headphone_on) { //no mic hp3p mixer_ctl_set_value(client->mixer_ctls->audio_earpiece_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_speaker_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_headphone_out, 0, 1); mixer_ctl_set_value(client->mixer_ctls->audio_phone_headset_mic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_phone_main_mic, 0, 1); ALOGV("in wire head with no mic ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else if (headset_on) { //mic // hp4p mixer_ctl_set_value(client->mixer_ctls->audio_earpiece_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_speaker_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_headphone_out, 0, 1); mixer_ctl_set_value(client->mixer_ctls->audio_phone_main_mic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_phone_headset_mic, 0, 1); ALOGV("in wire head with mic ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); } else if (bt_on) { if(!wake_lock){ grabPartialWakeLock(); wake_lock=true; } mixer_ctl_set_value(client->mixer_ctls->audio_earpiece_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_headphone_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_speaker_out, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_phone_main_mic, 0, 0); mixer_ctl_set_value(client->mixer_ctls->audio_phone_headset_mic, 0, 0); ALOGV("in bluetooth ****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__); mixer_ctl_set_value(client->mixer_ctls->audio_adc_phone_in, 0, 1); mixer_ctl_set_value(client->mixer_ctls->audio_dac_phone_out, 0, 1); plan_one_start_bt_voice(client->vol_array->up_pcm_gain); last_path_is_bt = true; if (is_in_record && (bluetooth_in_record == false)){ plan_one_start_bt_record(); bluetooth_in_record = true; } } #endif return 0; }
int mixer_cache_populate(struct audio_tool_mixer_cache *cache, struct mixer *mixer) { struct mixer_ctl *ctl; struct audio_tool_mixer_control_info *cur; const char* name; size_t count, n, v; int tmp; if (!cache) return EINVAL; if (!mixer) return EINVAL; if (cache->ctrls) free(cache->ctrls); count = mixer_get_num_ctls(mixer); cache->count = count; if (count) { cache->ctrls = calloc(count, sizeof(struct audio_tool_mixer_control_info)); if (! cache->ctrls) return -ENOMEM; } for (n = 0, cur = cache->ctrls ; n < count ; ++n, ++cur) { ctl = mixer_get_ctl(mixer, n); if (!ctl) return ENODEV; name = mixer_ctl_get_name(ctl); if (!name) return ENODEV; cur->id = n; cur->type = mixer_ctl_get_type(ctl); strcpy(cur->name, name); cur->num_values = mixer_ctl_get_num_values(ctl); if (cur->num_values > MAX_NUM_VALUES) cur->num_values = MAX_NUM_VALUES; for (v = 0 ; v < cur->num_values ; ++v) { switch (cur->type) { case MIXER_CTL_TYPE_BOOL: case MIXER_CTL_TYPE_INT: cur->value.integer[v] = mixer_ctl_get_value(ctl, v); break; case MIXER_CTL_TYPE_ENUM: tmp = mixer_ctl_get_value(ctl, v); name = mixer_ctl_get_enum_string(ctl, tmp); // null value names were causing seg fault here if (name) strcpy(cur->value.enumerated[v], name); else printf("Skipping ENUM due to null setting for %s\n", cur->name); break; case MIXER_CTL_TYPE_BYTE: cur->value.byte[v] = mixer_ctl_get_value(ctl, v); break; case MIXER_CTL_TYPE_INT64: cur->value.integer64[v] = mixer_ctl_get_value(ctl, v); break; default: (void)0; } } } return 0; }
bool HDMIAudioCaps::loadCaps(int ALSADeviceID) { bool ret = false; struct mixer* mixer = NULL; struct mixer_ctl* ctrls[kCtrlCount] = {NULL}; int tmp, mode_cnt; Mutex::Autolock _l(mLock); ALOGE("%s: start", __func__); reset_l(); // Open the mixer for the chosen ALSA device if (NULL == (mixer = mixer_open(ALSADeviceID))) { ALOGE("%s: mixer_open(%d) failed", __func__, ALSADeviceID); goto bailout; } // Gather handles to all of the controls we will need in order to enumerate // the audio capabilities of this HDMI link. No need to free/release these // later, they are just pointers into the tinyalsa mixer structure itself. for (size_t i = 0; i < kCtrlCount; ++i) { ctrls[i] = mixer_get_ctl_by_name(mixer, kCtrlNames[i]); if (NULL == ctrls[i]) { ALOGE("%s: mixer_get_ctrl_by_name(%s) failed", __func__, kCtrlNames[i]); goto bailout; } } // Start by checking to see if this HDMI connection supports even basic // audio. If it does not, there is no point in proceeding. if ((tmp = mixer_ctl_get_value(ctrls[kBasicAudNdx], 0)) <= 0) { ALOGI("%s: Basic audio not supported by attached device", __func__); goto bailout; } // Looks like we support basic audio. Get a count of the available // non-basic modes. mBasicAudioSupported = true; if ((mode_cnt = mixer_ctl_get_value(ctrls[kModeCntNdx], 0)) < 0) goto bailout; // Fetch the speaker allocation data block, if available. if ((tmp = mixer_ctl_get_value(ctrls[kSpeakerAlloc], 0)) < 0) goto bailout; mSpeakerAlloc = static_cast<uint16_t>(tmp); ALOGI("%s: Speaker Allocation Map for attached device is: 0x%hx", __func__, mSpeakerAlloc); // If there are no non-basic modes available, then we are done. Be sure to // flag this as a successful operation. if (!mode_cnt) { ret = true; goto bailout; } // Now enumerate the non-basic modes. Any errors at this point in time // should indicate that the HDMI cable was unplugged and we should just // abort with an empty set of audio capabilities. for (int i = 0; i < mode_cnt; ++i) { Mode m; // Pick the mode we want to fetch info for. if (mixer_ctl_set_value(ctrls[kModeSelNdx], 0, i) < 0) goto bailout; // Now fetch the common fields. if ((tmp = mixer_ctl_get_value(ctrls[kFmtNdx], 0)) < 0) goto bailout; m.fmt = static_cast<AudFormat>(tmp); ALOGI("Got mode %d from ALSA driver.", m.fmt); if ((tmp = mixer_ctl_get_value(ctrls[kMaxChCntNdx], 0)) < 0) goto bailout; m.max_ch = static_cast<uint32_t>(tmp); if ((tmp = mixer_ctl_get_value(ctrls[kSampRateNdx], 0)) < 0) goto bailout; m.sr_bitmask = static_cast<uint32_t>(tmp); // Now for the mode dependent fields. Only LPCM has the bits-per-sample // mask. Only AC3 through ATRAC have the compressed bitrate field. m.bps_bitmask = 0; m.comp_bitrate = 0; if (m.fmt == kFmtLPCM) { if ((tmp = mixer_ctl_get_value(ctrls[kBPSNdx], 0)) < 0) goto bailout; m.bps_bitmask = static_cast<uint32_t>(tmp); } else if ((m.fmt >= kFmtAC3) && (m.fmt <= kFmtATRAC)) { // FIXME ATRAC is not last format!? if ((tmp = mixer_ctl_get_value(ctrls[kMaxCompBRNdx], 0)) < 0) goto bailout; m.comp_bitrate = static_cast<uint32_t>(tmp); } // Finally, sanity check the info. If it passes, add it to the vector // of available modes. if (sanityCheckMode(m)) { ALOGI("Passed sanity check for mode %d from ALSA driver.", m.fmt); mModes.add(m); } } // Looks like we managed to enumerate all of the modes before someone // unplugged the HDMI cable. Signal success and get out. ret = true; bailout: if (NULL != mixer) mixer_close(mixer); if (!ret) reset_l(); return ret; }
static void tinymix_detail_control(struct mixer *mixer, const char *control, int print_all) { struct mixer_ctl *ctl; enum mixer_ctl_type type; unsigned int num_values; unsigned int i; int min, max; int ret; char buf[512] = { 0 }; size_t len; if (isdigit(control[0])) ctl = mixer_get_ctl(mixer, atoi(control)); else ctl = mixer_get_ctl_by_name(mixer, control); if (!ctl) { fprintf(stderr, "Invalid mixer control\n"); return; } type = mixer_ctl_get_type(ctl); num_values = mixer_ctl_get_num_values(ctl); if (type == MIXER_CTL_TYPE_BYTE) { len = num_values; if (len > sizeof(buf)) { fprintf(stderr, "Truncating get to %zu bytes\n", sizeof(buf)); len = sizeof(buf); } ret = mixer_ctl_get_array(ctl, buf, len); if (ret < 0) { fprintf(stderr, "Failed to mixer_ctl_get_array\n"); return; } } if (print_all) printf("%s:", mixer_ctl_get_name(ctl)); for (i = 0; i < num_values; i++) { switch (type) { case MIXER_CTL_TYPE_INT: printf(" %d", mixer_ctl_get_value(ctl, i)); break; case MIXER_CTL_TYPE_BOOL: printf(" %s", mixer_ctl_get_value(ctl, i) ? "On" : "Off"); break; case MIXER_CTL_TYPE_ENUM: tinymix_print_enum(ctl, print_all); break; case MIXER_CTL_TYPE_BYTE: printf("%02x", buf[i]); break; default: printf(" unknown"); break; }; } if (print_all) { if (type == MIXER_CTL_TYPE_INT) { min = mixer_ctl_get_range_min(ctl); max = mixer_ctl_get_range_max(ctl); printf(" (range %d->%d)", min, max); } } printf("\n"); }
static void tinymix_detail_control(struct mixer *mixer, const char *control, int print_all) { struct mixer_ctl *ctl; enum mixer_ctl_type type; unsigned int num_values; unsigned int i; int min, max; int ret; char *buf = NULL; if (isdigit(control[0])) ctl = mixer_get_ctl(mixer, atoi(control)); else ctl = mixer_get_ctl_by_name(mixer, control); if (!ctl) { fprintf(stderr, "Invalid mixer control\n"); return; } type = mixer_ctl_get_type(ctl); num_values = mixer_ctl_get_num_values(ctl); if ((type == MIXER_CTL_TYPE_BYTE) && (num_values > 0)) { buf = calloc(1, num_values); if (buf == NULL) { fprintf(stderr, "Failed to alloc mem for bytes %d\n", num_values); return; } ret = mixer_ctl_get_array(ctl, buf, num_values); if (ret < 0) { fprintf(stderr, "Failed to mixer_ctl_get_array\n"); free(buf); return; } } if (print_all) printf("%s:", mixer_ctl_get_name(ctl)); for (i = 0; i < num_values; i++) { switch (type) { case MIXER_CTL_TYPE_INT: printf(" %d", mixer_ctl_get_value(ctl, i)); break; case MIXER_CTL_TYPE_BOOL: printf(" %s", mixer_ctl_get_value(ctl, i) ? "On" : "Off"); break; case MIXER_CTL_TYPE_ENUM: tinymix_print_enum(ctl, print_all); break; case MIXER_CTL_TYPE_BYTE: printf("%02x", buf[i]); break; default: printf(" unknown"); break; }; } if (print_all) { if (type == MIXER_CTL_TYPE_INT) { min = mixer_ctl_get_range_min(ctl); max = mixer_ctl_get_range_max(ctl); printf(" (range %d->%d)", min, max); } } free(buf); printf("\n"); }