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

Commit 0e73a8c9 authored by François Gaffie's avatar François Gaffie Committed by Eric Laurent
Browse files

audio policy: improve sharing input logic to prevent temp unrouting



When a client is active on an input with a given input source, and
when another client is starting on the same input profile with same
source (so same priority), the first client input will be closed.

If the client is using AudioRecord, it will recover by restoreRecord,
and hence (re) started in the same input as the preemptor. Input
will now be "reused" (and not "closed") as the current client was set
as the preemptor.

Bug: 303079083
Test: atest audiopolicy_tests:AudioPolicyManagerInputPreemptionTest
Flag: com.android.media.audioserver.fix_input_sharing_logic

Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@ampere.cars>
(cherry picked from https://android-review.googlesource.com/q/commit:2a68ef65fa01aa737bc528f7d4329f5d1909b2b1)
Merged-In: I68ef45833fd04886b80c6f7610043e6ba37036cd
Change-Id: I68ef45833fd04886b80c6f7610043e6ba37036cd
parent 4a546956
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -3230,7 +3230,8 @@ audio_io_handle_t AudioPolicyManager::getInputForDevice(const sp<DeviceDescripto
            //  - Preempt and input if:
            //     - It has only strictly lower priority use cases than the new client
            //     - It has equal priority use cases than the new client, was not
            //     opened thanks to preemption or has been active since opened.
            //     opened thanks to preemption, is not routed to the same device than the device to
            //     consider or has been active since opened.
            //  - Order the preemption candidates by inactive first and priority second
            sp<AudioInputDescriptor> closeCandidate;
            int leastCloseRank = INT_MAX;
@@ -3248,7 +3249,7 @@ audio_io_handle_t AudioPolicyManager::getInputForDevice(const sp<DeviceDescripto
                int topPrio = source_priority(topPrioClient->source());
                if (topPrio < source_priority(attributes.source)
                      || (topPrio == source_priority(attributes.source)
                          && !desc->isPreemptor())) {
                          && !(desc->isPreemptor() || desc->getDevice() == device))) {
                    int closeRank = (desc->isActive() ? sCloseActive : 0) + topPrio;
                    if (closeRank < leastCloseRank) {
                        leastCloseRank = closeRank;
+28 −0
Original line number Diff line number Diff line
@@ -4684,6 +4684,34 @@ TEST_F_WITH_FLAGS(
    EXPECT_EQ(input1, input2);
}

TEST_F_WITH_FLAGS(
        AudioPolicyManagerInputPreemptionTest,
        SameDeviceAndSourceReusesInput,
        REQUIRES_FLAGS_ENABLED(
        ACONFIG_FLAG(com::android::media::audioserver, fix_input_sharing_logic))
) {
    mClient->resetInputApiCallsCounters();

    audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER;
    attr.source = AUDIO_SOURCE_VOICE_RECOGNITION;
    audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE;
    audio_io_handle_t input1 = AUDIO_PORT_HANDLE_NONE;
    ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input1, TEST_SESSION_ID, 1, &selectedDeviceId,
                                            AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO,
                                            k48000SamplingRate));

    EXPECT_EQ(1, mClient->getOpenInputCallsCount());

    audio_io_handle_t input2 = AUDIO_PORT_HANDLE_NONE;
    ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input2, OTHER_SESSION_ID, 1, &selectedDeviceId,
                                            AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO,
                                            k48000SamplingRate));

    EXPECT_EQ(1, mClient->getOpenInputCallsCount());
    EXPECT_EQ(0, mClient->getCloseInputCallsCount());
    EXPECT_EQ(input1, input2);
}

TEST_F_WITH_FLAGS(
        AudioPolicyManagerInputPreemptionTest,
        LesserPriorityReusesInput,