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

Commit 730b9265 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Make AudioPolicyManager::getInputForDevice prefer profile match on input fast flag

Bug: 77292903
Test: log name of selected profile
Change-Id: Idad75627f399f01f353d49d5fd78d7cdb2953d60
parent c4b259a5
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -55,7 +55,9 @@ public:
                             audio_format_t *updatedFormat,
                             audio_channel_mask_t channelMask,
                             audio_channel_mask_t *updatedChannelMask,
                             uint32_t flags) const;
                             // FIXME parameter type
                             uint32_t flags,
                             bool exactMatchRequiredForInputFlags = false) const;

    void dump(int fd);
    void log();
+4 −2
Original line number Diff line number Diff line
@@ -35,7 +35,9 @@ bool IOProfile::isCompatibleProfile(audio_devices_t device,
                                    audio_format_t *updatedFormat,
                                    audio_channel_mask_t channelMask,
                                    audio_channel_mask_t *updatedChannelMask,
                                    uint32_t flags) const
                                    // FIXME type punning here
                                    uint32_t flags,
                                    bool exactMatchRequiredForInputFlags) const
{
    const bool isPlaybackThread =
            getType() == AUDIO_PORT_TYPE_MIX && getRole() == AUDIO_PORT_ROLE_SOURCE;
@@ -90,7 +92,7 @@ bool IOProfile::isCompatibleProfile(audio_devices_t device,
    // An existing normal stream is compatible with a fast track request,
    // but the fast request will be denied by AudioFlinger and converted to normal track.
    if (isRecordThread && ((getFlags() ^ flags) &
            ~AUDIO_INPUT_FLAG_FAST)) {
            ~(exactMatchRequiredForInputFlags ? AUDIO_INPUT_FLAG_NONE : AUDIO_INPUT_FLAG_FAST))) {
        return false;
    }

+32 −6
Original line number Diff line number Diff line
@@ -1602,10 +1602,11 @@ audio_io_handle_t AudioPolicyManager::getInputForDevice(audio_devices_t device,
    // sampling rate and flags may be updated by getInputProfile
    uint32_t profileSamplingRate = (config->sample_rate == 0) ?
            SAMPLE_RATE_HZ_DEFAULT : config->sample_rate;
    audio_format_t profileFormat = config->format;
    audio_format_t profileFormat;
    audio_channel_mask_t profileChannelMask = config->channel_mask;
    audio_input_flags_t profileFlags = flags;
    for (;;) {
        profileFormat = config->format; // reset each time through loop, in case it is updated
        profile = getInputProfile(device, address,
                                  profileSamplingRate, profileFormat, profileChannelMask,
                                  profileFlags);
@@ -5057,20 +5058,45 @@ sp<IOProfile> AudioPolicyManager::getInputProfile(audio_devices_t device,
    // TODO: perhaps isCompatibleProfile should return a "matching" score so we can return
    // the best matching profile, not the first one.

    sp<IOProfile> firstInexact;
    uint32_t updatedSamplingRate = 0;
    audio_format_t updatedFormat = AUDIO_FORMAT_INVALID;
    audio_channel_mask_t updatedChannelMask = AUDIO_CHANNEL_INVALID;
    for (const auto& hwModule : mHwModules) {
        for (const auto& profile : hwModule->getInputProfiles()) {
            // profile->log();
            //updatedFormat = format;
            if (profile->isCompatibleProfile(device, address, samplingRate,
                                             &samplingRate  /*updatedSamplingRate*/,
                                             format,
                                             &format /*updatedFormat*/,
                                             &format,       /*updatedFormat*/
                                             channelMask,
                                             &channelMask   /*updatedChannelMask*/,
                                             (audio_output_flags_t) flags)) {

                                             // FIXME ugly cast
                                             (audio_output_flags_t) flags,
                                             true /*exactMatchRequiredForInputFlags*/)) {
                return profile;
            }
            if (firstInexact == nullptr && profile->isCompatibleProfile(device, address,
                                             samplingRate,
                                             &updatedSamplingRate,
                                             format,
                                             &updatedFormat,
                                             channelMask,
                                             &updatedChannelMask,
                                             // FIXME ugly cast
                                             (audio_output_flags_t) flags,
                                             false /*exactMatchRequiredForInputFlags*/)) {
                firstInexact = profile;
            }

        }
    }
    if (firstInexact != nullptr) {
        samplingRate = updatedSamplingRate;
        format = updatedFormat;
        channelMask = updatedChannelMask;
        return firstInexact;
    }
    return NULL;
}