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

Commit 199f1894 authored by Carter Hsu's avatar Carter Hsu Committed by Andy Hung
Browse files

AudioPolicyManager: improve selectOutput functional flag matching



Prefer outputs with fewer unmatched functional flags.
Avoids assigning the audio stream to the VoIP output when
 - Primary output: 24, 32 or float
 - VoIP output: 16 bit

Bug: 200293124
Test: build pass
Signed-off-by: default avatarCarter Hsu <carterhsu@google.com>
Change-Id: I79d7429e9ef9c6fa02a7e7ba5f8e221ed81af423
parent 5973463b
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -1702,6 +1702,8 @@ audio_io_handle_t AudioPolicyManager::selectOutput(const SortedVector<audio_io_h
    // The priority is as follows:
    // 1: the output supporting haptic playback when requesting haptic playback
    // 2: the output with the highest number of requested functional flags
    //    with tiebreak preferring the minimum number of extra functional flags
    //    (see b/200293124, the incorrect selection of AUDIO_OUTPUT_FLAG_VOIP_RX).
    // 3: the output supporting the exact channel mask
    // 4: the output with a higher channel count than requested
    // 5: the output with a higher sampling rate than requested
@@ -1743,7 +1745,12 @@ audio_io_handle_t AudioPolicyManager::selectOutput(const SortedVector<audio_io_h
        }

        // functional flags match
        currentMatchCriteria[1] = popcount(outputDesc->mFlags & functionalFlags);
        const int matchingFunctionalFlags =
                __builtin_popcount(outputDesc->mFlags & functionalFlags);
        const int totalFunctionalFlags =
                __builtin_popcount(outputDesc->mFlags & kFunctionalFlags);
        // Prefer matching functional flags, but subtract unnecessary functional flags.
        currentMatchCriteria[1] = 100 * (matchingFunctionalFlags + 1) - totalFunctionalFlags;

        // channel mask and channel count match
        uint32_t outputChannelCount = audio_channel_count_from_out_mask(