Revert "audio policy: add open and active count for IO profiles"
Bug: 70319466
This reverts commit f05fc9061254a3329bf0a3b40e27cac87b51b4cc.
diff --git a/services/audiopolicy/common/managerdefinitions/include/IOProfile.h b/services/audiopolicy/common/managerdefinitions/include/IOProfile.h
index 118f0d2..ec04ef7 100644
--- a/services/audiopolicy/common/managerdefinitions/include/IOProfile.h
+++ b/services/audiopolicy/common/managerdefinitions/include/IOProfile.h
@@ -34,11 +34,7 @@
{
public:
IOProfile(const String8 &name, audio_port_role_t role)
- : AudioPort(name, AUDIO_PORT_TYPE_MIX, role),
- maxOpenCount((role == AUDIO_PORT_ROLE_SOURCE) ? 1 : 0),
- curOpenCount(0),
- maxActiveCount(1),
- curActiveCount(0) {}
+ : AudioPort(name, AUDIO_PORT_TYPE_MIX, role) {}
// For a Profile aka MixPort, tag name and name are equivalent.
virtual const String8 getTagName() const { return getName(); }
@@ -107,34 +103,6 @@
const DeviceVector &getSupportedDevices() const { return mSupportedDevices; }
- bool canOpenNewIo() {
- if (maxOpenCount == 0 || curOpenCount < maxOpenCount) {
- return true;
- }
- return false;
- }
-
- bool canStartNewIo() {
- if (maxActiveCount == 0 || curActiveCount < maxActiveCount) {
- return true;
- }
- return false;
- }
-
- // Maximum number of input or output streams that can be simultaneously opened for this profile.
- // By convention 0 means no limit. To respect legacy behavior, initialized to 1 for output
- // profiles and 0 for input profiles
- uint32_t maxOpenCount;
- // Number of streams currently opened for this profile.
- uint32_t curOpenCount;
- // Maximum number of input or output streams that can be simultaneously active for this profile.
- // By convention 0 means no limit. To respect legacy behavior, initialized to 0 for output
- // profiles and 1 for input profiles
- uint32_t maxActiveCount;
- // Number of streams currently active for this profile. This is not the number of active clients
- // (AudioTrack or AudioRecord) but the number of active HAL streams.
- uint32_t curActiveCount;
-
private:
DeviceVector mSupportedDevices; // supported devices: this input/output can be routed from/to
};
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioInputDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioInputDescriptor.cpp
index 737872d..624e688 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioInputDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioInputDescriptor.cpp
@@ -236,7 +236,6 @@
mFormat = lConfig.format;
mId = AudioPort::getNextUniqueId();
mIoHandle = *input;
- mProfile->curOpenCount++;
}
return status;
@@ -247,10 +246,6 @@
{
if (mIoHandle != AUDIO_IO_HANDLE_NONE) {
mClientInterface->closeInput(mIoHandle);
- LOG_ALWAYS_FATAL_IF(mProfile->curOpenCount < 1, "%s profile open count %u",
- __FUNCTION__, mProfile->curOpenCount);
- mProfile->curOpenCount--;
- mIoHandle = AUDIO_IO_HANDLE_NONE;
}
}
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
index be5a1c1..f96c5bc 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
@@ -444,7 +444,6 @@
mFormat = lConfig.format;
mId = AudioPort::getNextUniqueId();
mIoHandle = *output;
- mProfile->curOpenCount++;
}
return status;
@@ -459,11 +458,6 @@
mClientInterface->setParameters(mIoHandle, param.toString());
mClientInterface->closeOutput(mIoHandle);
-
- LOG_ALWAYS_FATAL_IF(mProfile->curOpenCount < 1, "%s profile open count %u",
- __FUNCTION__, mProfile->curOpenCount);
- mProfile->curOpenCount--;
- mIoHandle = AUDIO_IO_HANDLE_NONE;
}
}
diff --git a/services/audiopolicy/common/managerdefinitions/src/IOProfile.cpp b/services/audiopolicy/common/managerdefinitions/src/IOProfile.cpp
index fc89672..74ef4ec 100644
--- a/services/audiopolicy/common/managerdefinitions/src/IOProfile.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/IOProfile.cpp
@@ -122,16 +122,6 @@
result.append("\n");
write(fd, result.string(), result.size());
mSupportedDevices.dump(fd, String8("Supported"), 4, false);
-
- result.clear();
- snprintf(buffer, SIZE, "\n - maxOpenCount: %u - curOpenCount: %u\n",
- maxOpenCount, curOpenCount);
- result.append(buffer);
- snprintf(buffer, SIZE, " - maxActiveCount: %u - curActiveCount: %u\n",
- maxActiveCount, curActiveCount);
- result.append(buffer);
-
- write(fd, result.string(), result.size());
}
void IOProfile::log()
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 7e5da7e..bfefbf8 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -923,29 +923,37 @@
}
if (profile != 0) {
+ sp<SwAudioOutputDescriptor> outputDesc = NULL;
+
for (size_t i = 0; i < mOutputs.size(); i++) {
sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
if (!desc->isDuplicated() && (profile == desc->mProfile)) {
+ outputDesc = desc;
// reuse direct output if currently open by the same client
// and configured with same parameters
- if ((config->sample_rate == desc->mSamplingRate) &&
- audio_formats_match(config->format, desc->mFormat) &&
- (config->channel_mask == desc->mChannelMask) &&
- (session == desc->mDirectClientSession)) {
- desc->mDirectOpenCount++;
- ALOGV("getOutputForDevice() reusing direct output %d for session %d",
- mOutputs.keyAt(i), session);
- return mOutputs.keyAt(i);
+ if ((config->sample_rate == outputDesc->mSamplingRate) &&
+ audio_formats_match(config->format, outputDesc->mFormat) &&
+ (config->channel_mask == outputDesc->mChannelMask)) {
+ if (session == outputDesc->mDirectClientSession) {
+ outputDesc->mDirectOpenCount++;
+ ALOGV("getOutputForDevice() reusing direct output %d for session %d",
+ mOutputs.keyAt(i), session);
+ return mOutputs.keyAt(i);
+ } else {
+ ALOGV("getOutputForDevice() do not reuse direct output because"
+ "current client (%d) is not the same as requesting client (%d)",
+ outputDesc->mDirectClientSession, session);
+ goto non_direct_output;
+ }
}
}
}
-
- if (!profile->canOpenNewIo()) {
- goto non_direct_output;
+ // close direct output if currently open and configured with different parameters
+ if (outputDesc != NULL) {
+ closeOutput(outputDesc->mIoHandle);
}
- sp<SwAudioOutputDescriptor> outputDesc =
- new SwAudioOutputDescriptor(profile, mpClientInterface);
+ outputDesc = new SwAudioOutputDescriptor(profile, mpClientInterface);
status = outputDesc->open(config, device, String8(""), stream, flags, &output);
// only accept an output with the requested parameters
@@ -1103,13 +1111,6 @@
sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(index);
- if (!outputDesc->isActive()) {
- if (!outputDesc->mProfile->canStartNewIo()) {
- return INVALID_OPERATION;
- }
- outputDesc->mProfile->curActiveCount++;
- }
-
// Routing?
mOutputRoutes.incRouteActivity(session);
@@ -1137,12 +1138,6 @@
if (status != NO_ERROR) {
mOutputRoutes.decRouteActivity(session);
- if (!outputDesc->isActive()) {
- LOG_ALWAYS_FATAL_IF(outputDesc->mProfile->curActiveCount < 1,
- "%s invalid profile active count %u",
- __FUNCTION__, outputDesc->mProfile->curActiveCount);
- outputDesc->mProfile->curActiveCount--;
- }
return status;
}
// Automatically enable the remote submix input when output is started on a re routing mix
@@ -1331,15 +1326,7 @@
}
}
- status_t status = stopSource(outputDesc, stream, forceDeviceUpdate);
-
- if (status == NO_ERROR && !outputDesc->isActive()) {
- LOG_ALWAYS_FATAL_IF(outputDesc->mProfile->curActiveCount < 1,
- "%s invalid profile active count %u",
- __FUNCTION__, outputDesc->mProfile->curActiveCount);
- outputDesc->mProfile->curActiveCount--;
- }
- return status;
+ return stopSource(outputDesc, stream, forceDeviceUpdate);
}
status_t AudioPolicyManager::stopSource(const sp<AudioOutputDescriptor>& outputDesc,
@@ -1725,10 +1712,6 @@
}
#endif
- if (!profile->canOpenNewIo()) {
- return AUDIO_IO_HANDLE_NONE;
- }
-
sp<AudioInputDescriptor> inputDesc = new AudioInputDescriptor(profile, mpClientInterface);
audio_config_t lConfig = AUDIO_CONFIG_INITIALIZER;
@@ -1966,13 +1949,6 @@
setInputDevice(input, device, true /* force */);
if (inputDesc->getAudioSessionCount(true/*activeOnly*/) == 1) {
- if (!inputDesc->mProfile->canStartNewIo()) {
- mInputRoutes.decRouteActivity(session);
- audioSession->changeActiveCount(-1);
- return INVALID_OPERATION;
- }
- inputDesc->mProfile->curActiveCount++;
-
// if input maps to a dynamic policy with an activity listener, notify of state change
if ((inputDesc->mPolicyMix != NULL)
&& ((inputDesc->mPolicyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0)) {
@@ -2042,11 +2018,6 @@
if (inputDesc->isActive()) {
setInputDevice(input, getNewInputDevice(inputDesc), false /* force */);
} else {
- LOG_ALWAYS_FATAL_IF(inputDesc->mProfile->curActiveCount < 1,
- "%s invalid profile active count %u",
- __FUNCTION__, inputDesc->mProfile->curActiveCount);
- inputDesc->mProfile->curActiveCount--;
-
// if input maps to a dynamic policy with an activity listener, notify of state change
if ((inputDesc->mPolicyMix != NULL)
&& ((inputDesc->mPolicyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0)) {
@@ -3593,12 +3564,6 @@
{
const sp<IOProfile> outProfile = hwModule->mOutputProfiles[j];
- if (!outProfile->canOpenNewIo()) {
- ALOGE("Invalid Output profile max open count %u for profile %s",
- outProfile->maxOpenCount, outProfile->getTagName().c_str());
- continue;
- }
-
if (!outProfile->hasSupportedDevices()) {
ALOGW("Output profile contains no device on module %s", hwModule->getName());
continue;
@@ -3662,12 +3627,6 @@
{
const sp<IOProfile> inProfile = hwModule->mInputProfiles[j];
- if (!inProfile->canOpenNewIo()) {
- ALOGE("Invalid Input profile max open count %u for profile %s",
- inProfile->maxOpenCount, inProfile->getTagName().c_str());
- continue;
- }
-
if (!inProfile->hasSupportedDevices()) {
ALOGW("Input profile contains no device on module %s", hwModule->getName());
continue;
@@ -3874,12 +3833,6 @@
continue;
}
- if (!profile->canOpenNewIo()) {
- ALOGW("Max Output number %u already opened for this profile %s",
- profile->maxOpenCount, profile->getTagName().c_str());
- continue;
- }
-
ALOGV("opening output for device %08x with params %s profile %p name %s",
device, address.string(), profile.get(), profile->getName().string());
desc = new SwAudioOutputDescriptor(profile, mpClientInterface);
@@ -4080,7 +4033,6 @@
for (ssize_t profile_index = 0; profile_index < (ssize_t)profiles.size(); profile_index++) {
sp<IOProfile> profile = profiles[profile_index];
-
// nothing to do if one input is already opened for this profile
size_t input_index;
for (input_index = 0; input_index < mInputs.size(); input_index++) {
@@ -4096,12 +4048,6 @@
continue;
}
- if (!profile->canOpenNewIo()) {
- ALOGW("Max Input number %u already opened for this profile %s",
- profile->maxOpenCount, profile->getTagName().c_str());
- continue;
- }
-
desc = new AudioInputDescriptor(profile, mpClientInterface);
audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
status_t status = desc->open(nullptr,