// save a copy of the opened output descriptors before any output is opened or closed
// by checkOutputsForDevice(). This will be needed by checkOutputForAllStrategies()
mPreviousOutputs = mOutputs;
+ String8 paramStr;
switch (state)
{
// handle output device connection
}
ALOGV("setDeviceConnectionState() connecting device %x", device);
- if (checkOutputsForDevice(device, state, outputs) != NO_ERROR) {
+ if (mHasA2dp && audio_is_a2dp_device(device)) {
+ // handle A2DP device connection
+ AudioParameter param;
+ param.add(String8(AUDIO_PARAMETER_A2DP_SINK_ADDRESS), String8(device_address));
+ paramStr = param.toString();
+ } else if (mHasUsb && audio_is_usb_device(device)) {
+ // handle USB device connection
+ paramStr = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
+ }
+
+ if (checkOutputsForDevice(device, state, outputs, paramStr) != NO_ERROR) {
return INVALID_OPERATION;
}
ALOGV("setDeviceConnectionState() checkOutputsForDevice() returned %d outputs",
// register new device as available
mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices | device);
- if (!outputs.isEmpty()) {
- String8 paramStr;
- if (mHasA2dp && audio_is_a2dp_device(device)) {
- // handle A2DP device connection
- AudioParameter param;
- param.add(String8(AUDIO_PARAMETER_A2DP_SINK_ADDRESS), String8(device_address));
- paramStr = param.toString();
- mA2dpDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
- mA2dpSuspended = false;
- } else if (audio_is_bluetooth_sco_device(device)) {
- // handle SCO device connection
- mScoDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
- } else if (mHasUsb && audio_is_usb_device(device)) {
- // handle USB device connection
- mUsbCardAndDevice = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
- paramStr = mUsbCardAndDevice;
- }
- // not currently handling multiple simultaneous submixes: ignoring remote submix
- // case and address
- if (!paramStr.isEmpty()) {
- for (size_t i = 0; i < outputs.size(); i++) {
- mpClientInterface->setParameters(outputs[i], paramStr);
- }
- }
+ if (mHasA2dp && audio_is_a2dp_device(device)) {
+ // handle A2DP device connection
+ mA2dpDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
+ mA2dpSuspended = false;
+ } else if (audio_is_bluetooth_sco_device(device)) {
+ // handle SCO device connection
+ mScoDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
+ } else if (mHasUsb && audio_is_usb_device(device)) {
+ // handle USB device connection
+ mUsbCardAndDevice = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
}
+
break;
// handle output device disconnection
case AudioSystem::DEVICE_STATE_UNAVAILABLE: {
// remove device from available output devices
mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~device);
- checkOutputsForDevice(device, state, outputs);
+ checkOutputsForDevice(device, state, outputs, paramStr);
if (mHasA2dp && audio_is_a2dp_device(device)) {
// handle A2DP device disconnection
mA2dpDeviceAddress = "";
AudioPolicyManagerBase::IOProfile *AudioPolicyManagerBase::getProfileForDirectOutput(
audio_devices_t device,
uint32_t samplingRate,
- uint32_t format,
- uint32_t channelMask,
+ audio_format_t format,
+ audio_channel_mask_t channelMask,
audio_output_flags_t flags)
{
for (size_t i = 0; i < mHwModules.size(); i++) {
audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type stream,
uint32_t samplingRate,
- uint32_t format,
- uint32_t channelMask,
+ audio_format_t format,
+ audio_channel_mask_t channelMask,
AudioSystem::output_flags flags,
const audio_offload_info_t *offloadInfo)
{
outputDesc = new AudioOutputDescriptor(profile);
outputDesc->mDevice = device;
outputDesc->mSamplingRate = samplingRate;
- outputDesc->mFormat = (audio_format_t)format;
- outputDesc->mChannelMask = (audio_channel_mask_t)channelMask;
+ outputDesc->mFormat = format;
+ outputDesc->mChannelMask = channelMask;
outputDesc->mLatency = 0;
outputDesc->mFlags =(audio_output_flags_t) (outputDesc->mFlags | flags);
outputDesc->mRefCount[stream] = 0;
// only accept an output with the requested parameters
if (output == 0 ||
(samplingRate != 0 && samplingRate != outputDesc->mSamplingRate) ||
- (format != 0 && format != outputDesc->mFormat) ||
+ (format != AUDIO_FORMAT_DEFAULT && format != outputDesc->mFormat) ||
(channelMask != 0 && channelMask != outputDesc->mChannelMask)) {
ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d,"
"format %d %d, channelMask %04x %04x", output, samplingRate,
// open a non direct output
// for non direct outputs, only PCM is supported
- if (audio_is_linear_pcm((audio_format_t)format)) {
+ if (audio_is_linear_pcm(format)) {
// get which output is suitable for the specified stream. The actual
// routing change will happen when startOutput() will be called
SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs);
ALOGV("startOutput() output %d, stream %d, session %d", output, stream, session);
ssize_t index = mOutputs.indexOfKey(output);
if (index < 0) {
- ALOGW("startOutput() unknow output %d", output);
+ ALOGW("startOutput() unknown output %d", output);
return BAD_VALUE;
}
ALOGV("stopOutput() output %d, stream %d, session %d", output, stream, session);
ssize_t index = mOutputs.indexOfKey(output);
if (index < 0) {
- ALOGW("stopOutput() unknow output %d", output);
+ ALOGW("stopOutput() unknown output %d", output);
return BAD_VALUE;
}
audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource,
uint32_t samplingRate,
- uint32_t format,
- uint32_t channelMask,
+ audio_format_t format,
+ audio_channel_mask_t channelMask,
AudioSystem::audio_in_acoustics acoustics)
{
audio_io_handle_t input = 0;
// adapt channel selection to input source
switch(inputSource) {
case AUDIO_SOURCE_VOICE_UPLINK:
- channelMask = AudioSystem::CHANNEL_IN_VOICE_UPLINK;
+ channelMask = AUDIO_CHANNEL_IN_VOICE_UPLINK;
break;
case AUDIO_SOURCE_VOICE_DOWNLINK:
- channelMask = AudioSystem::CHANNEL_IN_VOICE_DNLINK;
+ channelMask = AUDIO_CHANNEL_IN_VOICE_DNLINK;
break;
case AUDIO_SOURCE_VOICE_CALL:
- channelMask = (AudioSystem::CHANNEL_IN_VOICE_UPLINK | AudioSystem::CHANNEL_IN_VOICE_DNLINK);
+ channelMask = AUDIO_CHANNEL_IN_VOICE_UPLINK | AUDIO_CHANNEL_IN_VOICE_DNLINK;
break;
default:
break;
format,
channelMask);
if (profile == NULL) {
- ALOGW("getInput() could not find profile for device %04x, samplingRate %d, format %d,"
+ ALOGW("getInput() could not find profile for device %04x, samplingRate %d, format %d, "
"channelMask %04x",
device, samplingRate, format, channelMask);
return 0;
inputDesc->mInputSource = inputSource;
inputDesc->mDevice = device;
inputDesc->mSamplingRate = samplingRate;
- inputDesc->mFormat = (audio_format_t)format;
- inputDesc->mChannelMask = (audio_channel_mask_t)channelMask;
+ inputDesc->mFormat = format;
+ inputDesc->mChannelMask = channelMask;
inputDesc->mRefCount = 0;
input = mpClientInterface->openInput(profile->mModule->mHandle,
&inputDesc->mDevice,
(samplingRate != inputDesc->mSamplingRate) ||
(format != inputDesc->mFormat) ||
(channelMask != inputDesc->mChannelMask)) {
- ALOGV("getInput() failed opening input: samplingRate %d, format %d, channelMask %d",
+ ALOGI("getInput() failed opening input: samplingRate %d, format %d, channelMask %x",
samplingRate, format, channelMask);
if (input != 0) {
mpClientInterface->closeInput(input);
ALOGV("startInput() input %d", input);
ssize_t index = mInputs.indexOfKey(input);
if (index < 0) {
- ALOGW("startInput() unknow input %d", input);
+ ALOGW("startInput() unknown input %d", input);
return BAD_VALUE;
}
AudioInputDescriptor *inputDesc = mInputs.valueAt(index);
stopInput(activeInput);
releaseInput(activeInput);
} else {
- ALOGW("startInput() input %d failed: other input already started..", input);
+ ALOGW("startInput() input %d failed: other input already started", input);
return INVALID_OPERATION;
}
}
ALOGV("stopInput() input %d", input);
ssize_t index = mInputs.indexOfKey(input);
if (index < 0) {
- ALOGW("stopInput() unknow input %d", input);
+ ALOGW("stopInput() unknown input %d", input);
return BAD_VALUE;
}
AudioInputDescriptor *inputDesc = mInputs.valueAt(index);
status_t AudioPolicyManagerBase::checkOutputsForDevice(audio_devices_t device,
AudioSystem::device_connection_state state,
- SortedVector<audio_io_handle_t>& outputs)
+ SortedVector<audio_io_handle_t>& outputs,
+ const String8 paramStr)
{
AudioOutputDescriptor *desc;
continue;
}
- ALOGV("opening output for device %08x", device);
+ ALOGV("opening output for device %08x with params %s", device, paramStr.string());
desc = new AudioOutputDescriptor(profile);
desc->mDevice = device;
audio_offload_info_t offloadInfo = AUDIO_INFO_INITIALIZER;
desc->mFlags,
&offloadInfo);
if (output != 0) {
+ if (!paramStr.isEmpty()) {
+ mpClientInterface->setParameters(output, paramStr);
+ }
+
if (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) {
String8 reply;
char *value;
loadSamplingRates(value + 1, profile);
}
}
- if (profile->mFormats[0] == 0) {
+ if (profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) {
reply = mpClientInterface->getParameters(output,
String8(AUDIO_PARAMETER_STREAM_SUP_FORMATS));
ALOGV("checkOutputsForDevice() direct output sup formats %s",
}
if (((profile->mSamplingRates[0] == 0) &&
(profile->mSamplingRates.size() < 2)) ||
- ((profile->mFormats[0] == 0) &&
+ ((profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) &&
(profile->mFormats.size() < 2)) ||
- ((profile->mFormats[0] == 0) &&
+ ((profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) &&
(profile->mChannelMasks.size() < 2))) {
ALOGW("checkOutputsForDevice() direct output missing param");
mpClientInterface->closeOutput(output);
profile->mSamplingRates.clear();
profile->mSamplingRates.add(0);
}
- if (profile->mFormats[0] == 0) {
+ if (profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) {
profile->mFormats.clear();
- profile->mFormats.add((audio_format_t)0);
+ profile->mFormats.add(AUDIO_FORMAT_DEFAULT);
}
if (profile->mChannelMasks[0] == 0) {
profile->mChannelMasks.clear();
- profile->mChannelMasks.add((audio_channel_mask_t)0);
+ profile->mChannelMasks.add(0);
}
}
}
AudioPolicyManagerBase::IOProfile *AudioPolicyManagerBase::getInputProfile(audio_devices_t device,
uint32_t samplingRate,
- uint32_t format,
- uint32_t channelMask)
+ audio_format_t format,
+ audio_channel_mask_t channelMask)
{
// Choose an input profile based on the requested capture parameters: select the first available
// profile supporting all requested parameters.
{
IOProfile *profile = mHwModules[i]->mInputProfiles[j];
if (profile->isCompatibleProfile(device, samplingRate, format,
- channelMask,(audio_output_flags_t)0)) {
+ channelMask, AUDIO_OUTPUT_FLAG_NONE)) {
return profile;
}
}
AudioPolicyManagerBase::AudioOutputDescriptor::AudioOutputDescriptor(
const IOProfile *profile)
- : mId(0), mSamplingRate(0), mFormat((audio_format_t)0),
- mChannelMask((audio_channel_mask_t)0), mLatency(0),
+ : mId(0), mSamplingRate(0), mFormat(AUDIO_FORMAT_DEFAULT),
+ mChannelMask(0), mLatency(0),
mFlags((audio_output_flags_t)0), mDevice(AUDIO_DEVICE_NONE),
mOutput1(0), mOutput2(0), mProfile(profile), mDirectOpenCount(0)
{
// --- AudioInputDescriptor class implementation
AudioPolicyManagerBase::AudioInputDescriptor::AudioInputDescriptor(const IOProfile *profile)
- : mSamplingRate(0), mFormat((audio_format_t)0), mChannelMask((audio_channel_mask_t)0),
+ : mSamplingRate(0), mFormat(AUDIO_FORMAT_DEFAULT), mChannelMask(0),
mDevice(AUDIO_DEVICE_NONE), mRefCount(0),
mInputSource(0), mProfile(profile)
{
result.append(buffer);
write(fd, result.string(), result.size());
if (mOutputProfiles.size()) {
- write(fd, " - outputs:\n", sizeof(" - outputs:\n"));
+ write(fd, " - outputs:\n", strlen(" - outputs:\n"));
for (size_t i = 0; i < mOutputProfiles.size(); i++) {
snprintf(buffer, SIZE, " output %d:\n", i);
write(fd, buffer, strlen(buffer));
}
}
if (mInputProfiles.size()) {
- write(fd, " - inputs:\n", sizeof(" - inputs:\n"));
+ write(fd, " - inputs:\n", strlen(" - inputs:\n"));
for (size_t i = 0; i < mInputProfiles.size(); i++) {
snprintf(buffer, SIZE, " input %d:\n", i);
write(fd, buffer, strlen(buffer));
// get a valid a match
bool AudioPolicyManagerBase::IOProfile::isCompatibleProfile(audio_devices_t device,
uint32_t samplingRate,
- uint32_t format,
- uint32_t channelMask,
+ audio_format_t format,
+ audio_channel_mask_t channelMask,
audio_output_flags_t flags) const
{
- if (samplingRate == 0 || format == 0 || channelMask == 0) {
+ if (samplingRate == 0 || !audio_is_valid_format(format) || channelMask == 0) {
return false;
}
// by convention, "0' in the first entry in mFormats indicates the supported formats
// should be read from the output stream after it is opened for the first time
if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0) {
- profile->mFormats.add((audio_format_t)0);
+ profile->mFormats.add(AUDIO_FORMAT_DEFAULT);
return;
}
audio_format_t format = (audio_format_t)stringToEnum(sFormatNameToEnumTable,
ARRAY_SIZE(sFormatNameToEnumTable),
str);
- if (format != 0) {
+ if (format != AUDIO_FORMAT_DEFAULT) {
profile->mFormats.add(format);
}
str = strtok(NULL, "|");
ALOGV("loadInChannels() %s", name);
if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0) {
- profile->mChannelMasks.add((audio_channel_mask_t)0);
+ profile->mChannelMasks.add(0);
return;
}
// by convention, "0' in the first entry in mChannelMasks indicates the supported channel
// masks should be read from the output stream after it is opened for the first time
if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0) {
- profile->mChannelMasks.add((audio_channel_mask_t)0);
+ profile->mChannelMasks.add(0);
return;
}
return 0;
}
-int update_ctrl_interface(const char *config_file) {
-
- int srcfd, destfd;
- int nread;
- char ifc[PROPERTY_VALUE_MAX];
- char *pbuf;
- char *sptr;
- struct stat sb;
- int ret;
-
- if (stat(config_file, &sb) != 0)
- return -1;
-
- pbuf = malloc(sb.st_size + PROPERTY_VALUE_MAX);
- if (!pbuf)
- return 0;
- srcfd = TEMP_FAILURE_RETRY(open(config_file, O_RDONLY));
- if (srcfd < 0) {
- ALOGE("Cannot open \"%s\": %s", config_file, strerror(errno));
- free(pbuf);
- return 0;
- }
- nread = TEMP_FAILURE_RETRY(read(srcfd, pbuf, sb.st_size));
- close(srcfd);
- if (nread < 0) {
- ALOGE("Cannot read \"%s\": %s", config_file, strerror(errno));
- free(pbuf);
- return 0;
- }
-
- if (!strcmp(config_file, SUPP_CONFIG_FILE)) {
- property_get("wifi.interface", ifc, WIFI_TEST_INTERFACE);
- } else {
- strcpy(ifc, CONTROL_IFACE_PATH);
- }
- /* Assume file is invalid to begin with */
- ret = -1;
- /*
- * if there is a "ctrl_interface=<value>" entry, re-write it ONLY if it is
- * NOT a directory. The non-directory value option is an Android add-on
- * that allows the control interface to be exchanged through an environment
- * variable (initialized by the "init" program when it starts a service
- * with a "socket" option).
- *
- * The <value> is deemed to be a directory if the "DIR=" form is used or
- * the value begins with "/".
- */
- if ((sptr = strstr(pbuf, "ctrl_interface="))) {
- ret = 0;
- if ((!strstr(pbuf, "ctrl_interface=DIR=")) &&
- (!strstr(pbuf, "ctrl_interface=/"))) {
- char *iptr = sptr + strlen("ctrl_interface=");
- int ilen = 0;
- int mlen = strlen(ifc);
- int nwrite;
- if (strncmp(ifc, iptr, mlen) != 0) {
- ALOGE("ctrl_interface != %s", ifc);
- while (((ilen + (iptr - pbuf)) < nread) && (iptr[ilen] != '\n'))
- ilen++;
- mlen = ((ilen >= mlen) ? ilen : mlen) + 1;
- memmove(iptr + mlen, iptr + ilen + 1, nread - (iptr + ilen + 1 - pbuf));
- memset(iptr, '\n', mlen);
- memcpy(iptr, ifc, strlen(ifc));
- destfd = TEMP_FAILURE_RETRY(open(config_file, O_RDWR, 0660));
- if (destfd < 0) {
- ALOGE("Cannot update \"%s\": %s", config_file, strerror(errno));
- free(pbuf);
- return -1;
- }
- TEMP_FAILURE_RETRY(write(destfd, pbuf, nread + mlen - ilen -1));
- close(destfd);
- }
- }
- }
- free(pbuf);
- return ret;
-}
-
int ensure_config_file_exists(const char *config_file)
{
char buf[2048];
ALOGE("Cannot set RW to \"%s\": %s", config_file, strerror(errno));
return -1;
}
- /* return if we were able to update control interface properly */
- if (update_ctrl_interface(config_file) >=0) {
- return 0;
- } else {
- /* This handles the scenario where the file had bad data
- * for some reason. We continue and recreate the file.
- */
- }
+ return 0;
} else if (errno != ENOENT) {
ALOGE("Cannot access \"%s\": %s", config_file, strerror(errno));
return -1;
unlink(config_file);
return -1;
}
- return update_ctrl_interface(config_file);
+ return 0;
}
int wifi_start_supplicant(int p2p_supported)