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

Commit 82b0b6c9 authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge "Check audio profile by config mask"

parents 6cad6869 7a098c5e
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -84,12 +84,7 @@ public:
    bool hasDynamicAudioProfile() const { return mProfiles.hasDynamicProfile(); }

    // searches for an exact match
    status_t checkExactAudioProfile(uint32_t samplingRate,
                                    audio_channel_mask_t channelMask,
                                    audio_format_t format) const
    {
        return mProfiles.checkExactProfile(samplingRate, channelMask, format);
    }
    virtual status_t checkExactAudioProfile(const struct audio_port_config *config) const;

    // searches for a compatible match, currently implemented for input
    // parameters are input|output, returned value is the best match.
+21 −7
Original line number Diff line number Diff line
@@ -137,6 +137,26 @@ void AudioPort::importAudioPort(const sp<AudioPort>& port, bool force __unused)
    }
}

status_t AudioPort::checkExactAudioProfile(const struct audio_port_config *config) const
{
    status_t status = NO_ERROR;
    auto config_mask = config->config_mask;
    if (config_mask & AUDIO_PORT_CONFIG_GAIN) {
        config_mask &= ~AUDIO_PORT_CONFIG_GAIN;
        status = checkGain(&config->gain, config->gain.index);
        if (status != NO_ERROR) {
            return status;
        }
    }
    if (config_mask != 0) {
        // TODO should we check sample_rate / channel_mask / format separately?
        status = mProfiles.checkExactProfile(config->sample_rate,
                                             config->channel_mask,
                                             config->format);
    }
    return status;
}

void AudioPort::pickSamplingRate(uint32_t &pickedRate,const SampleRateVector &samplingRates) const
{
    pickedRate = 0;
@@ -388,9 +408,7 @@ status_t AudioPortConfig::applyAudioPortConfig(const struct audio_port_config *c
        status = NO_INIT;
        goto exit;
    }
    status = audioport->checkExactAudioProfile(config->sample_rate,
                                               config->channel_mask,
                                               config->format);
    status = audioport->checkExactAudioProfile(config);
    if (status != NO_ERROR) {
        goto exit;
    }
@@ -404,10 +422,6 @@ status_t AudioPortConfig::applyAudioPortConfig(const struct audio_port_config *c
        mFormat = config->format;
    }
    if (config->config_mask & AUDIO_PORT_CONFIG_GAIN) {
        status = audioport->checkGain(&config->gain, config->gain.index);
        if (status != NO_ERROR) {
            goto exit;
        }
        mGain = config->gain;
    }

+7 −1
Original line number Diff line number Diff line
@@ -71,7 +71,13 @@ bool IOProfile::isCompatibleProfile(audio_devices_t device,
            return false;
        }
    } else {
        if (checkExactAudioProfile(samplingRate, channelMask, format) != NO_ERROR) {
        const struct audio_port_config config = {
            .config_mask = AUDIO_PORT_CONFIG_ALL & ~AUDIO_PORT_CONFIG_GAIN,
            .sample_rate = samplingRate,
            .channel_mask = channelMask,
            .format = format,
        };
        if (checkExactAudioProfile(&config) != NO_ERROR) {
            return false;
        }
    }