int mcs_route_ctrl_set_path(struct mcs_route_ctrl_info * route_hdl, int acdb_id, int ena_flag, int * pcm_device) { char *p, array[100], *pmode; char en[] = "enable"; char dis[] = "disable"; int len = 0, found = 0, len2 = 0; struct mixer *mxr = NULL; struct mixer_ctl *ctl = 0; char *temp; int params, sublen, ret = 0; if (route_hdl == NULL) { ALOGE("Invalid MCS routing control handle."); return -EINVAL; } if (route_hdl->file_hdl == NULL) { ALOGE("Invalid configuration file handle."); return -EINVAL; } rewind(route_hdl->file_hdl); pmode = (ena_flag)?en:dis; /* Find the test case */ while((p = fgets(array, sizeof(array), route_hdl->file_hdl))) { if (strcasestr(p, ACDB_DEV_STR)) { if (atoi(&p[sizeof(ACDB_DEV_STR)-1]) == acdb_id) { found = 1; break; } } } if (!found) { ALOGE("Can't find ACDB ID %d from configuration file.", acdb_id); return -EACCES; } ALOGD("Found acdb_dev_id:%d %s", acdb_id, pmode); /* Find enable or disable commands*/ found = 0; while((p = fgets(array, sizeof(array), route_hdl->file_hdl))) { len = strnlen(p,sizeof(array)); p[len-1] = '\0'; len--; /* Comment added print comment */ if (!strncmp(&p[0], "#", 1)) { ALOGD("%s", p); } else if (strstr(p, "Rxdevice")) { temp = NULL; if ((temp = strstr(p,":"))) { sublen = temp - p; len = len - sublen - 1; temp++; temp[len] = '\0'; if (*temp >= '0' || *temp <= '9') *pcm_device = atoi(temp); else *pcm_device = -1; } } else if (strstr(p, "Txdevice")) { temp = NULL; if ((temp = strstr(p,":"))) { sublen = temp - p; len = len - sublen - 1; temp++; temp[len] = '\0'; if (*temp >= '0' || *temp <= '9') *pcm_device = atoi(temp); else *pcm_device = -1; } } else if (strstr(p, pmode)) { found = 1; break; } } if (!found) { ALOGE("Sequence for %s not found", pmode); return -1; } else { ALOGD("Sequence for %s found", pmode); } pmode = (!ena_flag)?en:dis; mxr = mixer_open(route_hdl->sndcard_num); if (!mxr) { ALOGE("Opening mixer control failed"); return -1; } while((p = fgets(array, sizeof(array), route_hdl->file_hdl))) { len = strnlen(p,sizeof(array)); p[len-1] = '\0'; len--; if (strstr(p, ACDB_DEV_STR) || strstr(p, pmode)) { break; } else { if (len) { char ctlname[100]; char ctlval[100]; temp = strstr(p,":"); if (temp) { sublen = temp - p; memcpy(ctlname, p, sublen); ctlname[sublen] = '\0'; ctl = get_ctl(mxr, ctlname); if (!ctl) { ALOGE("Failed to get %s\n", ctlname); break; } sublen = len - sublen; sublen--; temp++; memcpy(ctlval, temp, sublen); ctlval[sublen] = '\0'; int val = -1; while(sublen > 0) { if (*temp == ' ') { temp++; sublen--; }else if (*temp >= '0' && *temp <= '9') { val = atoi(temp); break; } else { val = 0; break; } } if (val < 0) { ALOGE("Invalid param for val"); return -EINVAL; } else if (!val) { ALOGD("Select %s %s", ctlname, ctlval); ret = mixer_ctl_select(ctl, ctlval); } else { ALOGD("Set %s %d", ctlname, val); ret = mixer_ctl_set(ctl, val); } } } } } mixer_close(mxr); return ret; }
AudioStreamOut* TinyAudioHardware::openOutputStream(uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status) { AutoMutex lock(mLock); LOGI("OPENOUT: %p\n", mOutput); // Currently we only allow one output stream, in future we should // support systems with multiple paths to the hardware. if (mOutput) { if (status) { *status = INVALID_OPERATION; } return 0; } // Hard code an output path for Speyside speakers for now mixer_ctl_set(mMixer, "DSP1RX", "AIF1"); mixer_ctl_set(mMixer, "DAC1L Mixer DSP1 Switch", 1); mixer_ctl_set(mMixer, "DAC1R Mixer DSP1 Switch", 1); mixer_ctl_set(mMixer, "DSP1 Playback Switch", 1); mixer_ctl_set(mMixer, "DSP1 Playback Volume", 96); mixer_ctl_set(mMixer, "DAC1 Switch", 1); mixer_ctl_set(mMixer, "DAC1 Volume", 96); mixer_ctl_set(mMixer, "DSP2RX", "AIF1"); mixer_ctl_set(mMixer, "DAC2L Mixer DSP1 Switch", 0); mixer_ctl_set(mMixer, "DAC2R Mixer DSP1 Switch", 0); mixer_ctl_set(mMixer, "DAC2L Mixer DSP2 Switch", 1); mixer_ctl_set(mMixer, "DAC2R Mixer DSP2 Switch", 1); mixer_ctl_set(mMixer, "DSP2 Playback Switch", 1); mixer_ctl_set(mMixer, "DSP2 Playback Volume", 96); mixer_ctl_set(mMixer, "DAC2 Switch", 1); mixer_ctl_set(mMixer, "DAC2 Volume", 96); mixer_ctl_set(mMixer, "DAC2 Sidetone", 24); mixer_ctl_set(mMixer, "Sub Speaker Switch", 1); mixer_ctl_set(mMixer, "Sub Speaker Volume", 57); mixer_ctl_set(mMixer, "Sub Speaker DC Volume", 3); mixer_ctl_set(mMixer, "Sub Speaker AC Volume", 3); mixer_ctl_set(mMixer, "Speaker Switch", 1); mixer_ctl_set(mMixer, "Output 2 Volume", 15); mixer_ctl_set(mMixer, "DSP1 EQ Mode", "Sub HPF"); mixer_ctl_set(mMixer, "DSP2 EQ Mode", "Sub LPF"); mixer_ctl_set(mMixer, "Sub IN1 Switch", 1); mixer_ctl_set(mMixer, "Sub IN2 Switch", 1); mixer_ctl_set(mMixer, "SPKL", "DAC1L"); mixer_ctl_set(mMixer, "SPKR", "DAC1R"); mixer_ctl_set(mMixer, "DSP1 EQ Switch", 1); mixer_ctl_set(mMixer, "DSP2 EQ Switch", 1); TinyAudioStreamOut* out = new TinyAudioStreamOut(); status_t lStatus = out->set(this, format, channels, sampleRate); if (status) { *status = lStatus; } if (lStatus == NO_ERROR) { mOutput = out; } else { delete out; } LOGI("OPENOUT DONE: %p %d\n", mOutput, lStatus); return mOutput; }