DeviceDescriptor::DeviceDescriptor(audio_devices_t type) : AudioPort(String8(""), AUDIO_PORT_TYPE_DEVICE, audio_is_output_device(type) ? AUDIO_PORT_ROLE_SINK : AUDIO_PORT_ROLE_SOURCE), mTag(""), mAddress(""), mDeviceType(type), mId(0) { }
status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device, audio_policy_dev_state_t state, const char *device_address) { if (mAudioPolicyManager == NULL) { return NO_INIT; } #ifdef MTK_AUDIO bool bSkipCheck = false; if (mHeadsetDetect!=NULL) { if (mHeadsetDetect->mCbkEnable == true) { bSkipCheck = true; } } if (false == bSkipCheck) { if (!settingsAllowed()) { return PERMISSION_DENIED; } } #else if (!settingsAllowed()) { return PERMISSION_DENIED; } #endif if (!audio_is_output_device(device) && !audio_is_input_device(device)) { return BAD_VALUE; } if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE && state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { return BAD_VALUE; } ALOGV("setDeviceConnectionState()"); Mutex::Autolock _l(mLock); #ifdef MTK_AUDIO //#ifdef MTK_HEADSET_DETECT if(!kHeadsetjavaStart && mHeadsetDetect!=NULL) { //if this function is called by other threads, headsetdetect can exit. if(!mHeadsetDetect->isCurrentThread()) { kHeadsetjavaStart = true; mHeadsetDetect->stop(); } } //#endif #endif return mAudioPolicyManager->setDeviceConnectionState(device, state, device_address); }
void DeviceDescriptor::toAudioPortConfig(struct audio_port_config *dstConfig, const struct audio_port_config *srcConfig) const { dstConfig->config_mask = AUDIO_PORT_CONFIG_CHANNEL_MASK|AUDIO_PORT_CONFIG_GAIN; if (srcConfig != NULL) { dstConfig->config_mask |= srcConfig->config_mask; } AudioPortConfig::toAudioPortConfig(dstConfig, srcConfig); dstConfig->id = mId; dstConfig->role = audio_is_output_device(mDeviceType) ? AUDIO_PORT_ROLE_SINK : AUDIO_PORT_ROLE_SOURCE; dstConfig->type = AUDIO_PORT_TYPE_DEVICE; dstConfig->ext.device.type = mDeviceType; //TODO Understand why this test is necessary. i.e. why at boot time does it crash // without the test? // This has been demonstrated to NOT be true (at start up) // ALOG_ASSERT(mModule != NULL); dstConfig->ext.device.hw_module = mModule != 0 ? mModule->mHandle : AUDIO_IO_HANDLE_NONE; strncpy(dstConfig->ext.device.address, mAddress.string(), AUDIO_DEVICE_MAX_ADDRESS_LEN); }
status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device, audio_policy_dev_state_t state, const char *device_address, const char *device_name) { if (mAudioPolicyManager == NULL) { return NO_INIT; } if (!settingsAllowed()) { return PERMISSION_DENIED; } if (!audio_is_output_device(device) && !audio_is_input_device(device)) { return BAD_VALUE; } if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE && state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { return BAD_VALUE; } ALOGV("setDeviceConnectionState()"); Mutex::Autolock _l(mLock); return mAudioPolicyManager->setDeviceConnectionState(device, state, device_address, device_name); }
static int audio_hw_set_parameters(struct audio_hw_device *dev, const char *kvpairs) { struct tinyalsa_audio_device *device; struct str_parms *parms; char value_string[32] = { 0 }; int value; int rc; ALOGD("%s(%p, %s)++", __func__, dev, kvpairs); if(dev == NULL || kvpairs == NULL) return -1; device = (struct tinyalsa_audio_device *) dev; if(device->mixer == NULL) return -1; parms = str_parms_create_str(kvpairs); if(parms == NULL) return -1; rc = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value_string, sizeof(value_string)); if(rc < 0) goto error_params; value = atoi(value_string); pthread_mutex_lock(&device->lock); if(audio_is_output_device((audio_devices_t) value)) { if(device->stream_out != NULL && device->stream_out->device_current != (audio_devices_t) value) { pthread_mutex_lock(&device->stream_out->lock); audio_out_set_route(device->stream_out, (audio_devices_t) value); pthread_mutex_unlock(&device->stream_out->lock); } if(device->ril_interface != NULL && device->ril_interface->device_current != (audio_devices_t) value) { audio_ril_interface_set_route(device->ril_interface, (audio_devices_t) value); } } else if(audio_is_input_device((audio_devices_t) value)) { if(device->stream_in != NULL && device->stream_in->device_current != (audio_devices_t) value) { pthread_mutex_lock(&device->stream_in->lock); audio_in_set_route(device->stream_in, (audio_devices_t) value); pthread_mutex_unlock(&device->stream_in->lock); } } pthread_mutex_unlock(&device->lock); str_parms_destroy(parms); ALOGD("%s(%p, %s)--", __func__, dev, kvpairs); return 0; error_params: str_parms_destroy(parms); ALOGD("%s(%p, %s)-- (PARAMETER ERROR)", __func__, dev, kvpairs); return -1; }