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

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

Merge "Retain config for the cached profile." into main

parents 50f4ee24 5e02d2b1
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -8165,6 +8165,9 @@ sp<IOProfile> AudioPolicyManager::getInputProfile(const sp<DeviceDescriptor> &de

    for (;;) {
        sp<IOProfile> firstInexact = nullptr;
        uint32_t inexactSamplingRate = 0;
        audio_format_t inexactFormat = AUDIO_FORMAT_INVALID;
        audio_channel_mask_t inexactChannelMask = AUDIO_CHANNEL_INVALID;
        uint32_t updatedSamplingRate = 0;
        audio_format_t updatedFormat = AUDIO_FORMAT_INVALID;
        audio_channel_mask_t updatedChannelMask = AUDIO_CHANNEL_INVALID;
@@ -8202,14 +8205,17 @@ sp<IOProfile> AudioPolicyManager::getInputProfile(const sp<DeviceDescriptor> &de
                                false /*exactMatchRequiredForInputFlags*/)
                                != IOProfile::NO_MATCH) {
                    firstInexact = profile;
                    inexactSamplingRate = updatedSamplingRate;
                    inexactFormat = updatedFormat;
                    inexactChannelMask = updatedChannelMask;
                }
            }
        }

        if (firstInexact != nullptr) {
            samplingRate = updatedSamplingRate;
            format = updatedFormat;
            channelMask = updatedChannelMask;
            samplingRate = inexactSamplingRate;
            format = inexactFormat;
            channelMask = inexactChannelMask;
            return firstInexact;
        } else if (flags & AUDIO_INPUT_FLAG_RAW) {
            flags = (audio_input_flags_t) (flags & ~AUDIO_INPUT_FLAG_RAW); // retry
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ class AudioPolicyTestManager : public AudioPolicyManager {
    using AudioPolicyManager::setDeviceConnectionState;
    using AudioPolicyManager::deviceToAudioPort;
    using AudioPolicyManager::handleDeviceConfigChange;
    using AudioPolicyManager::getInputProfile;
    uint32_t getAudioPortGeneration() const { return mAudioPortGeneration; }
    HwModuleCollection getHwModules() const { return mHwModules; }
};
+27 −0
Original line number Diff line number Diff line
@@ -1244,6 +1244,33 @@ TEST_F(AudioPolicyManagerTestWithConfigurationFile, SetDeviceConnectionStateClos
    EXPECT_EQ(streamCountBefore, mClient->getOpenedInputsCount());
}

TEST_F(AudioPolicyManagerTestWithConfigurationFile, UpdateConfigFromInexactProfile) {
    const audio_format_t expectedFormat = AUDIO_FORMAT_PCM_16_BIT;
    const uint32_t expectedSampleRate = 48000;
    const audio_channel_mask_t expectedChannelMask = AUDIO_CHANNEL_IN_STEREO;
    const std::string expectedIOProfile = "primary input";

    auto devices = mManager->getAvailableInputDevices();
    sp<DeviceDescriptor> mic = nullptr;
    for (auto device : devices) {
        if (device->type() == AUDIO_DEVICE_IN_BUILTIN_MIC) {
            mic = device;
            break;
        }
    }
    EXPECT_NE(nullptr, mic);

    audio_format_t requestedFormat = AUDIO_FORMAT_PCM_16_BIT;
    uint32_t requestedSampleRate = 44100;
    audio_channel_mask_t requestedChannelMask = AUDIO_CHANNEL_IN_STEREO;
    auto profile = mManager->getInputProfile(
            mic, requestedSampleRate, requestedFormat, requestedChannelMask, AUDIO_INPUT_FLAG_NONE);
    EXPECT_EQ(expectedIOProfile, profile->getName());
    EXPECT_EQ(expectedFormat, requestedFormat);
    EXPECT_EQ(expectedSampleRate, requestedSampleRate);
    EXPECT_EQ(expectedChannelMask, requestedChannelMask);
}

class AudioPolicyManagerTestDynamicPolicy : public AudioPolicyManagerTestWithConfigurationFile {
protected:
    void TearDown() override;
+7 −0
Original line number Diff line number Diff line
@@ -66,6 +66,11 @@
                        channelMasks="AUDIO_CHANNEL_IN_STEREO"/>
                </mixPort>
                <mixPort name="hifi_input" role="sink" />
                <mixPort name="multiple_channels_input" role="sink">
                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                             samplingRates="48000"
                             channelMasks="AUDIO_CHANNEL_IN_5POINT1"/>
                </mixPort>
            </mixPorts>
            <devicePorts>
                <devicePort tagName="Speaker" type="AUDIO_DEVICE_OUT_SPEAKER" role="sink">
@@ -114,6 +119,8 @@
                    sources="BUS Device In"/>
                <route type="mix" sink="hifi_input"
                        sources="USB Device In" />
                <route type="mix" sink="multiple_channels_input"
                       sources="Built-In Mic" />
            </routes>
        </module>