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

Commit ac3a690c authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: reduce mute time when invalidating tracks

Replace fixed 2 seconds mute time in checkOutputForStrategy() by
a variable time based on actual maximum output latency.

Also fix problem where src outputs where queried from mOutputs list
instead of from mPreviousOutputs.

Bug: 70632415
Test: manual connections/disconnection of BT A2DP and USB headset
Change-Id: I3a9ea915a134d95a2dc5abea2fbfe6152f147e80
parent 2c82a511
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -4382,14 +4382,23 @@ void AudioPolicyManager::checkOutputForStrategy(routing_strategy strategy)
    }

    if (!vectorsEqual(srcOutputs,dstOutputs)) {
        // get maximum latency of all source outputs to determine the minimum mute time guaranteeing
        // audio from invalidated tracks will be rendered when unmuting
        uint32_t maxLatency = 0;
        for (audio_io_handle_t srcOut : srcOutputs) {
            sp<SwAudioOutputDescriptor> desc = mPreviousOutputs.valueFor(srcOut);
            if (desc != 0 && maxLatency < desc->latency()) {
                maxLatency = desc->latency();
            }
        }
        ALOGV("checkOutputForStrategy() strategy %d, moving from output %d to output %d",
              strategy, srcOutputs[0], dstOutputs[0]);
        // mute strategy while moving tracks from one output to another
        for (audio_io_handle_t srcOut : srcOutputs) {
            sp<SwAudioOutputDescriptor> desc = mOutputs.valueFor(srcOut);
            if (isStrategyActive(desc, strategy)) {
            sp<SwAudioOutputDescriptor> desc = mPreviousOutputs.valueFor(srcOut);
            if (desc != 0 && isStrategyActive(desc, strategy)) {
                setStrategyMute(strategy, true, desc);
                setStrategyMute(strategy, false, desc, MUTE_TIME_MS, newDevice);
                setStrategyMute(strategy, false, desc, maxLatency * LATENCY_MUTE_FACTOR, newDevice);
            }
            sp<AudioSourceDescriptor> source =
                    getSourceForStrategyOnOutput(srcOut, strategy);
+4 −0
Original line number Diff line number Diff line
@@ -67,6 +67,10 @@ namespace android {
// is switched
#define MUTE_TIME_MS 2000

// multiplication factor applied to output latency when calculating a safe mute delay when
// invalidating tracks
#define LATENCY_MUTE_FACTOR 4

#define NUM_TEST_OUTPUTS 5

#define NUM_VOL_CURVE_KNEES 2