static status_t s_open(alsa_handle_t *handle, uint32_t devices, int mode) { // Close off previously opened device. // It would be nice to determine if the underlying device actually // changes, but we might be recovering from an error or manipulating // mixer settings (see asound.conf). // s_close(handle); LOGD("open called for devices %08x in mode %d...", devices, mode); const char *stream = streamName(handle); const char *devName = deviceName(handle, devices, mode); int err; for (;;) { // The PCM stream is opened in blocking mode, per ALSA defaults. The // AudioFlinger seems to assume blocking mode too, so asynchronous mode // should not be used. err = snd_pcm_open(&handle->handle, devName, direction(handle), SND_PCM_ASYNC); if (err == 0) break; // See if there is a less specific name we can try. // Note: We are changing the contents of a const char * here. char *tail = strrchr(devName, '_'); if (!tail) break; *tail = 0; } if (err < 0) { // None of the Android defined audio devices exist. Open a generic one. devName = "default"; err = snd_pcm_open(&handle->handle, devName, direction(handle), 0); } if (err < 0) { LOGE("Failed to Initialize any ALSA %s device: %s", stream, strerror(err)); return NO_INIT; } err = setHardwareParams(handle); if (err == NO_ERROR) err = setSoftwareParams(handle); LOGI("Initialized ALSA %s device %s", stream, devName); handle->curDev = devices; handle->curMode = mode; return err; }
static status_t s_open(alsa_handle_t *handle, uint32_t devices, int mode) { // Close off previously opened device. // It would be nice to determine if the underlying device actually // changes, but we might be recovering from an error or manipulating // mixer settings (see asound.conf). // ALOGD("open called for devices %08x in mode %d...", devices, mode); if( devices == 0 ){ return BAD_VALUE; } s_close(handle); pthread_mutex_lock(&handle->mLock); const char *stream = streamName(handle); const char *devName = deviceName(handle, devices, mode); int err,card; char prop[20],dev_Name[20],card_name[32]; ALOGD("input handle: %s, devName = %s \n", (char*)handle->modPrivate, devName); #if 1 if ((direction(handle) == SND_PCM_STREAM_CAPTURE)/*||(direction(handle) == SND_PCM_STREAM_PLAYBACK)*/){ card = getDeviceNum(direction(handle), card_name); ALOGD("card : %d\n", card); if(card >= 0){ // sprintf(dev_Name,"plug:SLAVE='hw:%d,0'",card); sprintf(dev_Name, "hw:%d", card); devName = dev_Name; } // if we want usb-audio, but returned builtin-audio, return error. // audiopolicymanager should try next card ALOGD("card name: %s\n", card_name); ALOGD("devName: %s\n", devName); if(strncmp(card_name,"AML", 3) == 0 && strcmp((char*)handle->modPrivate, "usb-audio") == 0){ pthread_mutex_unlock(&handle->mLock); ALOGD("You are request usb-audio with usb's params, but returned builtin-audio card\n"); return NO_INIT; } } if(direction(handle) == SND_PCM_STREAM_PLAYBACK){ card = snd_card_get_aml_card(); ALOGD("SND_PCM_STREAM_PLAYBACK card : %d\n", card); sprintf(dev_Name, "hw:%d", card); devName = dev_Name; } #else if(direction(handle) == SND_PCM_STREAM_CAPTURE){ sprintf(dev_Name, "hw:0"); devName = dev_Name; } #endif for (;;) { // The PCM stream is opened in blocking mode, per ALSA defaults. The // AudioFlinger seems to assume blocking mode too, so asynchronous mode // should not be used. ALOGD("---- devName = %s \n", devName); err = snd_pcm_open(&handle->handle, devName, direction(handle), SND_PCM_ASYNC); if (err == 0) break; // See if there is a less specific name we can try. // Note: We are changing the contents of a const char * here. char *tail = strrchr(devName, '_'); if (!tail) break; *tail = 0; } if (err < 0) { // None of the Android defined audio devices exist. Open a generic one. devName = "default"; ALOGD("-r-- devName = %s \n", devName); err = snd_pcm_open(&handle->handle, devName, direction(handle), 0); } if (err < 0) { ALOGE("Failed to Initialize any ALSA %s device: %s", stream, strerror(err)); pthread_mutex_unlock(&handle->mLock); return NO_INIT; } err = setHardwareParams(handle); if (err == NO_ERROR) err = setSoftwareParams(handle); ALOGI("Initialized ALSA %s device %s", stream, devName); handle->curDev = devices; handle->curMode = mode; pthread_mutex_unlock(&handle->mLock); return err; }