Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af304424 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "cherrypicker-L30200030004942263:N20300030077464683" into main

* changes:
  audiopolicy: Improve logging for device connection cases
  audiopolicy: skip opening mmap profile during new device connection
  audiopolicy: use profile flags during opening an input
parents 8c8da4bb 33173209
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -282,6 +282,11 @@ public:

    const AudioProfileVector& getSupportedProfiles() { return mSupportedProfiles; }

    /**
     * @brief checks if all devices in device vector are attached to the HwModule or not
     * @return true if all the devices in device vector are attached, otherwise false
     */
    bool areAllDevicesAttached() const;
    // Return a string to describe the DeviceVector. The sensitive information will only be
    // added to the string if `includeSensitiveInfo` is true.
    std::string toString(bool includeSensitiveInfo = false) const;
+10 −0
Original line number Diff line number Diff line
@@ -541,4 +541,14 @@ DeviceVector DeviceVector::filterForEngine() const
    return filteredDevices;
}

bool DeviceVector::areAllDevicesAttached() const
{
    for (const auto &device : *this) {
        if (!device->isAttached()) {
            return false;
        }
    }
    return true;
}

} // namespace android
+68 −27
Original line number Diff line number Diff line
@@ -375,6 +375,7 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(const sp<DeviceDescript
        checkLeBroadcastRoutes(wasLeUnicastActive, nullptr, 0);

        mpClientInterface->onAudioPortListUpdate();
        ALOGV("%s() completed for device: %s", __func__, device->toString().c_str());
        return NO_ERROR;
    }  // end if is output device

@@ -390,6 +391,8 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(const sp<DeviceDescript
                return INVALID_OPERATION;
            }

            ALOGV("%s() connecting device %s", __func__, device->toString().c_str());

            if (mAvailableInputDevices.add(device) < 0) {
                return NO_MEMORY;
            }
@@ -462,6 +465,7 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(const sp<DeviceDescript
        }

        mpClientInterface->onAudioPortListUpdate();
        ALOGV("%s() completed for device: %s", __func__, device->toString().c_str());
        return NO_ERROR;
    } // end if is input device

@@ -1592,7 +1596,7 @@ status_t AudioPolicyManager::openDirectOutput(audio_stream_type_t stream,
                (config->channel_mask == desc->getChannelMask()) &&
                (session == desc->mDirectClientSession)) {
                desc->mDirectOpenCount++;
                ALOGV("%s reusing direct output %d for session %d", __func__,
                ALOGI("%s reusing direct output %d for session %d", __func__,
                    mOutputs.keyAt(i), session);
                *output = mOutputs.keyAt(i);
                return NO_ERROR;
@@ -1602,17 +1606,23 @@ status_t AudioPolicyManager::openDirectOutput(audio_stream_type_t stream,

    if (!profile->canOpenNewIo()) {
        if (!com::android::media::audioserver::direct_track_reprioritization()) {
            ALOGW("%s profile %s can't open new output maxOpenCount reached", __func__,
                  profile->getName().c_str());
            return NAME_NOT_FOUND;
        } else if ((profile->getFlags() & AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) != 0) {
            // MMAP gracefully handles lack of an exclusive track resource by mixing
            // above the audio framework. For AAudio to know that the limit is reached,
            // return an error.
            ALOGW("%s profile %s can't open new mmap output maxOpenCount reached", __func__,
                  profile->getName().c_str());
            return NAME_NOT_FOUND;
        } else {
            // Close outputs on this profile, if available, to free resources for this request
            for (int i = 0; i < mOutputs.size() && !profile->canOpenNewIo(); i++) {
                const auto desc = mOutputs.valueAt(i);
                if (desc->mProfile == profile) {
                    ALOGV("%s closeOutput %d to prioritize session %d on profile %s", __func__,
                          desc->mIoHandle, session, profile->getName().c_str());
                    closeOutput(desc->mIoHandle);
                }
            }
@@ -1621,6 +1631,8 @@ status_t AudioPolicyManager::openDirectOutput(audio_stream_type_t stream,

    // Unable to close streams to find free resources for this request
    if (!profile->canOpenNewIo()) {
        ALOGW("%s profile %s can't open new output maxOpenCount reached", __func__,
              profile->getName().c_str());
        return NAME_NOT_FOUND;
    }

@@ -3539,8 +3551,8 @@ status_t AudioPolicyManager::setStreamVolumeIndex(audio_stream_type_t stream,
        ALOGW("%s: no group for stream %s, bailing out", __func__, toString(stream).c_str());
        return NO_ERROR;
    }
    ALOGV("%s: stream %s attributes=%s", __func__,
          toString(stream).c_str(), toString(attributes).c_str());
    ALOGV("%s: stream %s attributes=%s, index %d , device 0x%X", __func__,
          toString(stream).c_str(), toString(attributes).c_str(), index, device);
    return setVolumeIndexForAttributes(attributes, index, device);
}

@@ -3718,8 +3730,8 @@ status_t AudioPolicyManager::setVolumeCurveIndex(int index,
    bool hasVoice = hasVoiceStream(volumeCurves.getStreamTypes());
    if (((index < volumeCurves.getVolumeIndexMin()) && !(hasVoice && index == 0)) ||
            (index > volumeCurves.getVolumeIndexMax())) {
        ALOGD("%s: wrong index %d min=%d max=%d", __FUNCTION__, index,
              volumeCurves.getVolumeIndexMin(), volumeCurves.getVolumeIndexMax());
        ALOGE("%s: wrong index %d min=%d max=%d, device 0x%X", __FUNCTION__, index,
              volumeCurves.getVolumeIndexMin(), volumeCurves.getVolumeIndexMax(), device);
        return BAD_VALUE;
    }
    if (!audio_is_output_device(device)) {
@@ -6690,6 +6702,14 @@ void AudioPolicyManager::onNewAudioModulesAvailableInt(DeviceVector *newDevices)
            if (!mConfig->getOutputDevices().contains(supportedDevice)) {
                continue;
            }

            if (outProfile->isMmap() && !outProfile->hasDynamicAudioProfile()
                && availProfileDevices.areAllDevicesAttached()) {
                ALOGV("%s skip opening output for mmap profile %s", __func__,
                        outProfile->getTagName().c_str());
                continue;
            }

            sp<SwAudioOutputDescriptor> outputDesc = new SwAudioOutputDescriptor(outProfile,
                                                                                 mpClientInterface);
            audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
@@ -6749,6 +6769,14 @@ void AudioPolicyManager::onNewAudioModulesAvailableInt(DeviceVector *newDevices)
                    __func__, inProfile->getTagName().c_str());
                continue;
            }

            if (inProfile->isMmap() && !inProfile->hasDynamicAudioProfile()
                && availProfileDevices.areAllDevicesAttached()) {
                ALOGV("%s skip opening input for mmap profile %s", __func__,
                        inProfile->getTagName().c_str());
                continue;
            }

            sp<AudioInputDescriptor> inputDesc = new AudioInputDescriptor(
                    inProfile, mpClientInterface, false /*isPreemptor*/);

@@ -6756,12 +6784,12 @@ void AudioPolicyManager::onNewAudioModulesAvailableInt(DeviceVector *newDevices)
            status_t status = inputDesc->open(nullptr,
                                              availProfileDevices.itemAt(0),
                                              AUDIO_SOURCE_MIC,
                                              AUDIO_INPUT_FLAG_NONE,
                                              (audio_input_flags_t) inProfile->getFlags(),
                                              &input);
            if (status != NO_ERROR) {
                ALOGW("Cannot open input stream for device %s on hw module %s",
                      availProfileDevices.toString().c_str(),
                      hwModule->getName());
                ALOGW("%s: Cannot open input stream for device %s for profile %s on hw module %s",
                        __func__, availProfileDevices.toString().c_str(),
                        inProfile->getTagName().c_str(), hwModule->getName());
                continue;
            }
            for (const auto &device : availProfileDevices) {
@@ -6869,8 +6897,8 @@ status_t AudioPolicyManager::checkOutputsForDevice(const sp<DeviceDescriptor>& d
                sp<IOProfile> profile = hwModule->getOutputProfiles()[j];
                if (profile->supportsDevice(device)) {
                    profiles.add(profile);
                    ALOGV("checkOutputsForDevice(): adding profile %zu from module %s",
                          j, hwModule->getName());
                    ALOGV("%s(): adding profile %s from module %s",
                            __func__, profile->getTagName().c_str(), hwModule->getName());
                }
            }
        }
@@ -6903,7 +6931,11 @@ status_t AudioPolicyManager::checkOutputsForDevice(const sp<DeviceDescriptor>& d
            if (j != outputs.size()) {
                continue;
            }

            if (profile->isMmap() && !profile->hasDynamicAudioProfile()) {
                ALOGV("%s skip opening output for mmap profile %s",
                      __func__, profile->getTagName().c_str());
                continue;
            }
            if (!profile->canOpenNewIo()) {
                ALOGW("Max Output number %u already opened for this profile %s",
                      profile->maxOpenCount, profile->getTagName().c_str());
@@ -6964,9 +6996,8 @@ status_t AudioPolicyManager::checkOutputsForDevice(const sp<DeviceDescriptor>& d
                if (!profile->supportsDevice(device)) {
                    continue;
                }
                ALOGV("checkOutputsForDevice(): "
                        "clearing direct output profile %zu on module %s",
                        j, hwModule->getName());
                ALOGV("%s(): clearing direct output profile %s on module %s",
                        __func__, profile->getTagName().c_str(), hwModule->getName());
                profile->clearAudioProfiles();
                if (!profile->hasDynamicAudioProfile()) {
                    continue;
@@ -7021,8 +7052,8 @@ status_t AudioPolicyManager::checkInputsForDevice(const sp<DeviceDescriptor>& de

                if (profile->supportsDevice(device)) {
                    profiles.add(profile);
                    ALOGV("checkInputsForDevice(): adding profile %zu from module %s",
                          profile_index, hwModule->getName());
                    ALOGV("%s : adding profile %s from module %s", __func__,
                          profile->getTagName().c_str(), hwModule->getName());
                }
            }
        }
@@ -7054,15 +7085,22 @@ status_t AudioPolicyManager::checkInputsForDevice(const sp<DeviceDescriptor>& de
                continue;
            }

            if (profile->isMmap() && !profile->hasDynamicAudioProfile()) {
                ALOGV("%s skip opening input for mmap profile %s",
                      __func__, profile->getTagName().c_str());
                continue;
            }
            if (!profile->canOpenNewIo()) {
                ALOGW("Max Input number %u already opened for this profile %s",
                      profile->maxOpenCount, profile->getTagName().c_str());
                ALOGW("%s Max Input number %u already opened for this profile %s",
                      __func__, profile->maxOpenCount, profile->getTagName().c_str());
                continue;
            }

            desc = new AudioInputDescriptor(profile, mpClientInterface, false  /*isPreemptor*/);
            audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
            status = desc->open(nullptr, device, AUDIO_SOURCE_MIC, AUDIO_INPUT_FLAG_NONE, &input);
            ALOGV("%s opening input for profile %s", __func__, profile->getTagName().c_str());
            status = desc->open(nullptr, device, AUDIO_SOURCE_MIC,
                                (audio_input_flags_t) profile->getFlags(), &input);

            if (status == NO_ERROR) {
                const String8& address = String8(device->address().c_str());
@@ -7073,7 +7111,8 @@ status_t AudioPolicyManager::checkInputsForDevice(const sp<DeviceDescriptor>& de
                }
                updateAudioProfiles(device, input, profile);
                if (!profile->hasValidAudioProfile()) {
                    ALOGW("checkInputsForDevice() direct input missing param");
                    ALOGW("%s direct input missing param for profile %s", __func__,
                            profile->getTagName().c_str());
                    desc->close();
                    input = AUDIO_IO_HANDLE_NONE;
                }
@@ -7084,18 +7123,20 @@ status_t AudioPolicyManager::checkInputsForDevice(const sp<DeviceDescriptor>& de
            } // endif input != 0

            if (input == AUDIO_IO_HANDLE_NONE) {
                ALOGW("%s could not open input for device %s", __func__,
                       device->toString().c_str());
                ALOGW("%s could not open input for device %s on profile %s", __func__,
                       device->toString().c_str(), profile->getTagName().c_str());
                profiles.removeAt(profile_index);
                profile_index--;
            } else {
                if (audio_device_is_digital(device->type())) {
                    device->importAudioPortAndPickAudioProfile(profile);
                }
                ALOGV("checkInputsForDevice(): adding input %d", input);
                ALOGV("%s: adding input %d for profile %s", __func__,
                        input, profile->getTagName().c_str());

                if (checkCloseInput(desc)) {
                    ALOGV("%s closing input %d", __func__, input);
                    ALOGV("%s: closing input %d for profile %s", __func__,
                            input, profile->getTagName().c_str());
                    closeInput(input);
                }
            }
@@ -7114,8 +7155,8 @@ status_t AudioPolicyManager::checkInputsForDevice(const sp<DeviceDescriptor>& de
                 profile_index++) {
                sp<IOProfile> profile = hwModule->getInputProfiles()[profile_index];
                if (profile->supportsDevice(device)) {
                    ALOGV("checkInputsForDevice(): clearing direct input profile %zu on module %s",
                            profile_index, hwModule->getName());
                    ALOGV("%s: clearing direct input profile %s on module %s", __func__,
                            profile->getTagName().c_str(), hwModule->getName());
                    profile->clearAudioProfiles();
                }
            }