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

Commit ccd149ce authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

APM: Avoid calling 'setOutputDevices' after adding output for HIDL

Legacy systems suffer from user-perceivable audio dropouts
during device switching. Since forcing of the patches is only
necessary on AIDL HALs, skip the call to 'setOutputDevices'
on previous versions. Since prior to AIDL HAL introduction
all major SoC vendors used legacy HAL version below '3', a check
for the primay HAL version should suffice.

Bug: 363105967
Test: atest audiopolicy_tests
Change-Id: I5daa8bb62f1073398e25a8f7da5c5ada93962a92
parent 6413b8bf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ private:
class HwModuleCollection : public Vector<sp<HwModule> >
{
public:
    sp<HwModule> getModuleFromHandle(audio_module_handle_t handle) const;
    sp<HwModule> getModuleFromName(const char *name) const;

    /**
+10 −0
Original line number Diff line number Diff line
@@ -283,6 +283,16 @@ void HwModule::dump(String8 *dst, int spaces) const
    dumpAudioRouteVector(mRoutes, dst, spaces);
}

sp<HwModule> HwModuleCollection::getModuleFromHandle(audio_module_handle_t handle) const
{
    for (const auto& module : *this) {
        if (module->getHandle() == handle) {
            return module;
        }
    }
    return nullptr;
}

sp <HwModule> HwModuleCollection::getModuleFromName(const char *name) const
{
    for (const auto& module : *this) {
+10 −10
Original line number Diff line number Diff line
@@ -1637,11 +1637,11 @@ status_t AudioPolicyManager::openDirectOutput(audio_stream_type_t stream,
    outputDesc->mDirectClientSession = session;

    addOutput(*output, outputDesc);
    setOutputDevices(__func__, outputDesc,
                     devices,
                     true,
                     0,
                     NULL);
    // The version check is essentially to avoid making this call in the case of the HIDL HAL.
    if (auto hwModule = mHwModules.getModuleFromHandle(mPrimaryModuleHandle); hwModule &&
            hwModule->getHalVersionMajor() >= 3) {
        setOutputDevices(__func__, outputDesc, devices, true, 0, NULL);
    }
    mPreviousOutputs = mOutputs;
    ALOGV("%s returns new direct output %d", __func__, *output);
    mpClientInterface->onAudioPortListUpdate();
@@ -8873,11 +8873,11 @@ sp<SwAudioOutputDescriptor> AudioPolicyManager::openOutputWithProfileAndDevice(
    }

    addOutput(output, desc);
    setOutputDevices(__func__, desc,
                     devices,
                     true,
                     0,
                     NULL);
    // The version check is essentially to avoid making this call in the case of the HIDL HAL.
    if (auto hwModule = mHwModules.getModuleFromHandle(mPrimaryModuleHandle); hwModule &&
            hwModule->getHalVersionMajor() >= 3) {
        setOutputDevices(__func__, desc, devices, true, 0, NULL);
    }
    sp<DeviceDescriptor> speaker = mAvailableOutputDevices.getDevice(
            AUDIO_DEVICE_OUT_SPEAKER, String8(""), AUDIO_FORMAT_DEFAULT);

+4 −1
Original line number Diff line number Diff line
@@ -498,6 +498,9 @@ INSTANTIATE_TEST_CASE_P(
void AudioPolicyManagerTestMsd::SetUpManagerConfig() {
    // TODO: Consider using Serializer to load part of the config from a string.
    ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTest::SetUpManagerConfig());
    mConfig->getHwModules().getModuleFromName(
            AUDIO_HARDWARE_MODULE_ID_PRIMARY)->setHalVersion(3, 0);

    mMsdOutputDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_BUS);
    sp<AudioProfile> pcmOutputProfile = new AudioProfile(
            AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, k48000SamplingRate);
@@ -529,7 +532,7 @@ void AudioPolicyManagerTestMsd::SetUpManagerConfig() {
                addOutputProfile(spdifOutputProfile);
    }

    sp<HwModule> msdModule = new HwModule(AUDIO_HARDWARE_MODULE_ID_MSD, 2 /*halVersionMajor*/);
    sp<HwModule> msdModule = new HwModule(AUDIO_HARDWARE_MODULE_ID_MSD, 3 /*halVersionMajor*/);
    HwModuleCollection modules = mConfig->getHwModules();
    modules.add(msdModule);
    mConfig->setHwModules(modules);