Add additional info to AudioPort for enum/selection API.
Add "device name" member to AudioPort.
Moved unique device ID from DevicePort to AudioPort.
Straighten out confusion between "name" and "address"
Created string constants for Intent "extra" data keys.
Combine card/address data into "address" at sender.Add additional info to AudioPort for enum/selection API.
Change-Id: I1be308e12b09cd0ead9a3e9fbc9c385462299fb5
diff --git a/services/audiopolicy/AudioPolicyInterface.h b/services/audiopolicy/AudioPolicyInterface.h
index 4508fa7..116d0d6 100644
--- a/services/audiopolicy/AudioPolicyInterface.h
+++ b/services/audiopolicy/AudioPolicyInterface.h
@@ -75,7 +75,8 @@
// indicate a change in device connection status
virtual status_t setDeviceConnectionState(audio_devices_t device,
audio_policy_dev_state_t state,
- const char *device_address) = 0;
+ const char *device_address,
+ const char *device_name) = 0;
// retrieve a device connection status
virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
const char *device_address) = 0;
diff --git a/services/audiopolicy/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/AudioPolicyInterfaceImpl.cpp
index a45dbb3..e9ff8389 100644
--- a/services/audiopolicy/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/AudioPolicyInterfaceImpl.cpp
@@ -28,7 +28,8 @@
status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device,
audio_policy_dev_state_t state,
- const char *device_address)
+ const char *device_address,
+ const char *device_name)
{
if (mAudioPolicyManager == NULL) {
return NO_INIT;
@@ -46,8 +47,8 @@
ALOGV("setDeviceConnectionState()");
Mutex::Autolock _l(mLock);
- return mAudioPolicyManager->setDeviceConnectionState(device,
- state, device_address);
+ return mAudioPolicyManager->setDeviceConnectionState(device, state,
+ device_address, device_name);
}
audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState(
diff --git a/services/audiopolicy/AudioPolicyInterfaceImplLegacy.cpp b/services/audiopolicy/AudioPolicyInterfaceImplLegacy.cpp
index b8846c6..5a91192 100644
--- a/services/audiopolicy/AudioPolicyInterfaceImplLegacy.cpp
+++ b/services/audiopolicy/AudioPolicyInterfaceImplLegacy.cpp
@@ -33,7 +33,8 @@
status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device,
audio_policy_dev_state_t state,
- const char *device_address)
+ const char *device_address,
+ const char *device_name __unused)
{
if (mpAudioPolicy == NULL) {
return NO_INIT;
diff --git a/services/audiopolicy/AudioPolicyManager.cpp b/services/audiopolicy/AudioPolicyManager.cpp
index 7f27659..5a0c958 100644
--- a/services/audiopolicy/AudioPolicyManager.cpp
+++ b/services/audiopolicy/AudioPolicyManager.cpp
@@ -212,24 +212,28 @@
// ----------------------------------------------------------------------------
status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device,
- audio_policy_dev_state_t state,
- const char *device_address)
+ audio_policy_dev_state_t state,
+ const char *device_address,
+ const char *device_name)
{
- return setDeviceConnectionStateInt(device, state, device_address);
+ return setDeviceConnectionStateInt(device, state, device_address, device_name);
}
status_t AudioPolicyManager::setDeviceConnectionStateInt(audio_devices_t device,
audio_policy_dev_state_t state,
- const char *device_address)
+ const char *device_address,
+ const char *device_name)
{
- ALOGV("setDeviceConnectionState() device: %x, state %d, address %s",
- device, state, device_address != NULL ? device_address : "");
+ ALOGV("setDeviceConnectionStateInt() device: 0x%X, state %d, address %s name %s",
+- device, state, device_address, device_name);
// connect/disconnect only 1 device at a time
if (!audio_is_output_device(device) && !audio_is_input_device(device)) return BAD_VALUE;
sp<DeviceDescriptor> devDesc = getDeviceDescriptor(device, device_address);
+ String8 name = String8(device_name != NULL ? device_name : "");
+
// handle output devices
if (audio_is_output_device(device)) {
SortedVector <audio_io_handle_t> outputs;
@@ -259,8 +263,7 @@
mAvailableOutputDevices.remove(devDesc);
return INVALID_OPERATION;
}
- mAvailableOutputDevices[index]->mId = nextUniqueId();
- mAvailableOutputDevices[index]->mModule = module;
+ mAvailableOutputDevices[index]->attach(module);
} else {
return NO_MEMORY;
}
@@ -291,7 +294,7 @@
ALOGV("setDeviceConnectionState() disconnecting output device %x", device);
- // Set Disconnect to HALs
+ // Send Disconnect to HALs
AudioParameter param = AudioParameter(devDesc->mAddress);
param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device);
mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
@@ -377,8 +380,7 @@
index = mAvailableInputDevices.add(devDesc);
if (index >= 0) {
- mAvailableInputDevices[index]->mId = nextUniqueId();
- mAvailableInputDevices[index]->mModule = module;
+ mAvailableInputDevices[index]->attach(module);
} else {
return NO_MEMORY;
}
@@ -1322,7 +1324,8 @@
outputDesc->mPolicyMix->mMixType == MIX_TYPE_RECORDERS) {
setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX,
AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
- outputDesc->mPolicyMix->mRegistrationId);
+ outputDesc->mPolicyMix->mRegistrationId,
+ "remote-submix");
}
// force reevaluating accessibility routing when ringtone or alarm starts
@@ -1371,7 +1374,8 @@
outputDesc->mPolicyMix->mMixType == MIX_TYPE_RECORDERS) {
setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX,
AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
- outputDesc->mPolicyMix->mRegistrationId);
+ outputDesc->mPolicyMix->mRegistrationId,
+ "remote-submix");
}
outputDesc->mStopTime[stream] = systemTime();
@@ -1672,7 +1676,7 @@
if (address != "") {
setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX,
AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
- address);
+ address, "remote-submix");
}
}
}
@@ -1720,7 +1724,7 @@
if (address != "") {
setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX,
AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
- address);
+ address, "remote-submix");
}
}
@@ -2177,11 +2181,11 @@
if (mixes[i].mMixType == MIX_TYPE_PLAYERS) {
setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX,
AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
- address.string());
+ address.string(), "remote-submix");
} else {
setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX,
AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
- address.string());
+ address.string(), "remote-submix");
}
}
return NO_ERROR;
@@ -2219,7 +2223,7 @@
{
setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX,
AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
- address.string());
+ address.string(), "remote-submix");
}
if (getDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, address.string()) ==
@@ -2227,7 +2231,7 @@
{
setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX,
AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
- address.string());
+ address.string(), "remote-submix");
}
module->removeOutputProfile(address);
module->removeInputProfile(address);
@@ -3042,6 +3046,8 @@
return android_atomic_inc(&mAudioPortGeneration);
}
+int32_t volatile AudioPolicyManager::mNextUniqueId = 1;
+
AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterface)
:
#ifdef AUDIO_POLICY_TEST
@@ -3052,7 +3058,7 @@
mLimitRingtoneVolume(false), mLastVoiceVolume(-1.0f),
mTotalEffectsCpuLoad(0), mTotalEffectsMemory(0),
mA2dpSuspended(false),
- mSpeakerDrcEnabled(false), mNextUniqueId(1),
+ mSpeakerDrcEnabled(false),
mAudioPortGeneration(1),
mBeaconMuteRefCount(0),
mBeaconPlayingRefCount(0),
@@ -3065,7 +3071,7 @@
mForceUse[i] = AUDIO_POLICY_FORCE_NONE;
}
- mDefaultOutputDevice = new DeviceDescriptor(String8(""), AUDIO_DEVICE_OUT_SPEAKER);
+ mDefaultOutputDevice = new DeviceDescriptor(String8("Speaker"), AUDIO_DEVICE_OUT_SPEAKER);
if (loadAudioPolicyConfig(AUDIO_POLICY_VENDOR_CONFIG_FILE) != NO_ERROR) {
if (loadAudioPolicyConfig(AUDIO_POLICY_CONFIG_FILE) != NO_ERROR) {
ALOGE("could not load audio policy configuration file, setting defaults");
@@ -3148,9 +3154,8 @@
ssize_t index =
mAvailableOutputDevices.indexOf(outProfile->mSupportedDevices[k]);
// give a valid ID to an attached device once confirmed it is reachable
- if ((index >= 0) && (mAvailableOutputDevices[index]->mId == 0)) {
- mAvailableOutputDevices[index]->mId = nextUniqueId();
- mAvailableOutputDevices[index]->mModule = mHwModules[i];
+ if (index >= 0 && !mAvailableOutputDevices[index]->isAttached()) {
+ mAvailableOutputDevices[index]->attach(mHwModules[i]);
}
}
if (mPrimaryOutput == 0 &&
@@ -3217,9 +3222,8 @@
ssize_t index =
mAvailableInputDevices.indexOf(inProfile->mSupportedDevices[k]);
// give a valid ID to an attached device once confirmed it is reachable
- if ((index >= 0) && (mAvailableInputDevices[index]->mId == 0)) {
- mAvailableInputDevices[index]->mId = nextUniqueId();
- mAvailableInputDevices[index]->mModule = mHwModules[i];
+ if (index >= 0 && !mAvailableInputDevices[index]->isAttached()) {
+ mAvailableInputDevices[index]->attach(mHwModules[i]);
}
}
mpClientInterface->closeInput(input);
@@ -3232,7 +3236,7 @@
}
// make sure all attached devices have been allocated a unique ID
for (size_t i = 0; i < mAvailableOutputDevices.size();) {
- if (mAvailableOutputDevices[i]->mId == 0) {
+ if (!mAvailableOutputDevices[i]->isAttached()) {
ALOGW("Input device %08x unreachable", mAvailableOutputDevices[i]->mDeviceType);
mAvailableOutputDevices.remove(mAvailableOutputDevices[i]);
continue;
@@ -3240,7 +3244,7 @@
i++;
}
for (size_t i = 0; i < mAvailableInputDevices.size();) {
- if (mAvailableInputDevices[i]->mId == 0) {
+ if (!mAvailableInputDevices[i]->isAttached()) {
ALOGW("Input device %08x unreachable", mAvailableInputDevices[i]->mDeviceType);
mAvailableInputDevices.remove(mAvailableInputDevices[i]);
continue;
@@ -6409,7 +6413,7 @@
profile->mChannelMasks.add(config->channel_mask);
profile->mFormats.add(config->format);
- sp<DeviceDescriptor> devDesc = new DeviceDescriptor(String8(""), device);
+ sp<DeviceDescriptor> devDesc = new DeviceDescriptor(name, device);
devDesc->mAddress = address;
profile->mSupportedDevices.add(devDesc);
@@ -6439,7 +6443,7 @@
profile->mChannelMasks.add(config->channel_mask);
profile->mFormats.add(config->format);
- sp<DeviceDescriptor> devDesc = new DeviceDescriptor(String8(""), device);
+ sp<DeviceDescriptor> devDesc = new DeviceDescriptor(name, device);
devDesc->mAddress = address;
profile->mSupportedDevices.add(devDesc);
@@ -6505,16 +6509,22 @@
AudioPolicyManager::AudioPort::AudioPort(const String8& name, audio_port_type_t type,
audio_port_role_t role, const sp<HwModule>& module) :
- mName(name), mType(type), mRole(role), mModule(module), mFlags(0)
+ mName(name), mType(type), mRole(role), mModule(module), mFlags(0), mId(0)
{
mUseInChannelMask = ((type == AUDIO_PORT_TYPE_DEVICE) && (role == AUDIO_PORT_ROLE_SOURCE)) ||
((type == AUDIO_PORT_TYPE_MIX) && (role == AUDIO_PORT_ROLE_SINK));
}
+void AudioPolicyManager::AudioPort::attach(const sp<HwModule>& module) {
+ mId = AudioPolicyManager::nextUniqueId();
+ mModule = module;
+}
+
void AudioPolicyManager::AudioPort::toAudioPort(struct audio_port *port) const
{
port->role = mRole;
port->type = mType;
+ strlcpy(port->name, mName, AUDIO_PORT_MAX_NAME_LEN);
unsigned int i;
for (i = 0; i < mSamplingRates.size() && i < AUDIO_PORT_MAX_SAMPLING_RATES; i++) {
if (mSamplingRates[i] != 0) {
@@ -7473,13 +7483,14 @@
// --- DeviceDescriptor implementation
+String8 AudioPolicyManager::DeviceDescriptor::emptyNameStr = String8("");
AudioPolicyManager::DeviceDescriptor::DeviceDescriptor(const String8& name, audio_devices_t type) :
AudioPort(name, AUDIO_PORT_TYPE_DEVICE,
audio_is_output_device(type) ? AUDIO_PORT_ROLE_SINK :
AUDIO_PORT_ROLE_SOURCE,
NULL),
- mDeviceType(type), mAddress(""), mId(0)
+ mDeviceType(type), mAddress("")
{
}
@@ -7566,7 +7577,7 @@
uint32_t i = 31 - __builtin_clz(types);
uint32_t type = 1 << i;
types &= ~type;
- add(new DeviceDescriptor(String8(""), type | role_bit));
+ add(new DeviceDescriptor(String8("device_type"), type | role_bit));
}
}
@@ -7580,7 +7591,7 @@
ARRAY_SIZE(sDeviceNameToEnumTable),
devName);
if (type != AUDIO_DEVICE_NONE) {
- sp<DeviceDescriptor> dev = new DeviceDescriptor(String8(""), type);
+ sp<DeviceDescriptor> dev = new DeviceDescriptor(String8(name), type);
if (type == AUDIO_DEVICE_IN_REMOTE_SUBMIX ||
type == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ) {
dev->mAddress = String8("0");
@@ -7622,8 +7633,7 @@
{
sp<DeviceDescriptor> device;
for (size_t i = 0; i < size(); i++) {
- ALOGV("DeviceVector::getDeviceFromId(%d) itemAt(%zu)->mId %d", id, i, itemAt(i)->mId);
- if (itemAt(i)->mId == id) {
+ if (itemAt(i)->getHandle() == id) {
device = itemAt(i);
break;
}
@@ -7683,13 +7693,17 @@
}
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;
- dstConfig->ext.device.hw_module = mModule->mHandle;
+
+ //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 != NULL ? mModule->mHandle : NULL;
strncpy(dstConfig->ext.device.address, mAddress.string(), AUDIO_DEVICE_MAX_ADDRESS_LEN);
}
@@ -7928,7 +7942,7 @@
ARRAY_SIZE(sDeviceNameToEnumTable),
(char *)node->value);
if (device != AUDIO_DEVICE_NONE) {
- mDefaultOutputDevice = new DeviceDescriptor(String8(""), device);
+ mDefaultOutputDevice = new DeviceDescriptor(String8("default-output"), device);
} else {
ALOGW("loadGlobalConfig() default device not specified");
}
@@ -7979,8 +7993,8 @@
{
sp<HwModule> module;
sp<IOProfile> profile;
- sp<DeviceDescriptor> defaultInputDevice = new DeviceDescriptor(String8(""),
- AUDIO_DEVICE_IN_BUILTIN_MIC);
+ sp<DeviceDescriptor> defaultInputDevice =
+ new DeviceDescriptor(String8("builtin-mic"), AUDIO_DEVICE_IN_BUILTIN_MIC);
mAvailableOutputDevices.add(mDefaultOutputDevice);
mAvailableInputDevices.add(defaultInputDevice);
diff --git a/services/audiopolicy/AudioPolicyManager.h b/services/audiopolicy/AudioPolicyManager.h
index cbdafa6..3e3c662 100644
--- a/services/audiopolicy/AudioPolicyManager.h
+++ b/services/audiopolicy/AudioPolicyManager.h
@@ -73,7 +73,8 @@
// AudioPolicyInterface
virtual status_t setDeviceConnectionState(audio_devices_t device,
audio_policy_dev_state_t state,
- const char *device_address);
+ const char *device_address,
+ const char *device_name);
virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
const char *device_address);
virtual void setPhoneState(audio_mode_t state);
@@ -252,6 +253,11 @@
audio_port_role_t role, const sp<HwModule>& module);
virtual ~AudioPort() {}
+ audio_port_handle_t getHandle() { return mId; }
+
+ void attach(const sp<HwModule>& module);
+ bool isAttached() { return mId != 0; }
+
virtual void toAudioPort(struct audio_port *port) const;
void importAudioPort(const sp<AudioPort> port);
@@ -301,6 +307,12 @@
sp<HwModule> mModule; // audio HW module exposing this I/O stream
uint32_t mFlags; // attribute flags (e.g primary output,
// direct output...).
+
+ protected:
+ //TODO - clarify the role of mId in this case, both an "attached" indicator
+ // and a unique ID for identifying a port to the (upcoming) selection API,
+ // and its relationship to the mId in AudioOutputDescriptor and AudioInputDescriptor.
+ audio_port_handle_t mId;
};
class AudioPortConfig: public virtual RefBase
@@ -358,7 +370,8 @@
audio_devices_t mDeviceType;
String8 mAddress;
- audio_port_handle_t mId;
+
+ static String8 emptyNameStr;
};
class DeviceVector : public SortedVector< sp<DeviceDescriptor> >
@@ -832,7 +845,7 @@
// to boost soft sounds, used to adjust volume curves accordingly
Vector < sp<HwModule> > mHwModules;
- volatile int32_t mNextUniqueId;
+ static volatile int32_t mNextUniqueId;
volatile int32_t mAudioPortGeneration;
DefaultKeyedVector<audio_patch_handle_t, sp<AudioPatch> > mAudioPatches;
@@ -882,7 +895,7 @@
static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
int indexInUi);
static bool isVirtualInputDevice(audio_devices_t device);
- uint32_t nextUniqueId();
+ static uint32_t nextUniqueId();
uint32_t nextAudioPortGeneration();
private:
// updates device caching and output for streams that can influence the
@@ -928,10 +941,10 @@
// Called by setDeviceConnectionState().
status_t setDeviceConnectionStateInt(audio_devices_t device,
audio_policy_dev_state_t state,
- const char *device_address);
+ const char *device_address,
+ const char *device_name);
sp<DeviceDescriptor> getDeviceDescriptor(const audio_devices_t device,
const char *device_address);
-
};
};
diff --git a/services/audiopolicy/AudioPolicyService.h b/services/audiopolicy/AudioPolicyService.h
index 80284a4..7c2b59d 100644
--- a/services/audiopolicy/AudioPolicyService.h
+++ b/services/audiopolicy/AudioPolicyService.h
@@ -61,7 +61,8 @@
virtual status_t setDeviceConnectionState(audio_devices_t device,
audio_policy_dev_state_t state,
- const char *device_address);
+ const char *device_address,
+ const char *device_name);
virtual audio_policy_dev_state_t getDeviceConnectionState(
audio_devices_t device,
const char *device_address);