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

Commit f480b47d authored by Eric Laurent's avatar Eric Laurent Committed by Automerger Merge Worker
Browse files

audio policy: fix BT SCO volume issue am: 31a428aa

parents 8db5fd97 31a428aa
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -102,9 +102,13 @@ public:
    void setVolume(float volumeDb) { mCurVolumeDb = volumeDb; }
    float getVolume() const { return mCurVolumeDb; }

    void setIsVoice(bool isVoice) { mIsVoice = isVoice; }
    bool isVoice() const { return mIsVoice; }

private:
    int mMuteCount = 0; /**< mute request counter */
    float mCurVolumeDb = NAN; /**< current volume in dB. */
    bool mIsVoice = false; /** true if this volume source is used for voice call volume */
};
/**
 * Note: volume activities shall be indexed by CurvesId if we want to allow multiple
@@ -162,7 +166,8 @@ public:
                           VolumeSource volumeSource, const StreamTypeVector &streams,
                           const DeviceTypeSet& deviceTypes,
                           uint32_t delayMs,
                           bool force);
                           bool force,
                           bool isVoiceVolSrc = false);

    /**
     * @brief setStopTime set the stop time due to the client stoppage or a re routing of this
@@ -222,17 +227,25 @@ public:
    {
        return mVolumeActivities[vs].decMuteCount();
    }
    void setCurVolume(VolumeSource vs, float volumeDb)
    void setCurVolume(VolumeSource vs, float volumeDb, bool isVoiceVolSrc)
    {
        // Even if not activity for this source registered, need to create anyway
        mVolumeActivities[vs].setVolume(volumeDb);
        mVolumeActivities[vs].setIsVoice(isVoiceVolSrc);
    }
    float getCurVolume(VolumeSource vs) const
    {
        return mVolumeActivities.find(vs) != std::end(mVolumeActivities) ?
                    mVolumeActivities.at(vs).getVolume() : NAN;
    }

    VolumeSource getVoiceSource() {
        for (const auto &iter : mVolumeActivities) {
            if (iter.second.isVoice()) {
                return iter.first;
            }
        }
        return VOLUME_SOURCE_NONE;
    }
    bool isStrategyActive(product_strategy_t ps, uint32_t inPastMs = 0, nsecs_t sysTime = 0) const
    {
        return mRoutingActivities.find(ps) != std::end(mRoutingActivities)?
@@ -381,7 +394,8 @@ public:
                           VolumeSource volumeSource, const StreamTypeVector &streams,
                           const DeviceTypeSet& device,
                           uint32_t delayMs,
                           bool force);
                           bool force,
                           bool isVoiceVolSrc = false);

    virtual void toAudioPortConfig(struct audio_port_config *dstConfig,
                           const struct audio_port_config *srcConfig = NULL) const;
@@ -484,7 +498,8 @@ public:
                           VolumeSource volumeSource, const StreamTypeVector &streams,
                           const DeviceTypeSet& deviceTypes,
                           uint32_t delayMs,
                           bool force);
                           bool force,
                           bool isVoiceVolSrc = false);

    virtual void toAudioPortConfig(struct audio_port_config *dstConfig,
                           const struct audio_port_config *srcConfig = NULL) const;
+13 −6
Original line number Diff line number Diff line
@@ -163,7 +163,8 @@ bool AudioOutputDescriptor::setVolume(float volumeDb, bool /*muted*/,
                                      const StreamTypeVector &/*streams*/,
                                      const DeviceTypeSet& deviceTypes,
                                      uint32_t delayMs,
                                      bool force)
                                      bool force,
                                      bool isVoiceVolSrc)
{

    if (!supportedDevices().containsDeviceAmongTypes(deviceTypes)) {
@@ -176,7 +177,7 @@ bool AudioOutputDescriptor::setVolume(float volumeDb, bool /*muted*/,
    // - the force flag is set
    if (volumeDb != getCurVolume(volumeSource) || force) {
        ALOGV("%s for volumeSrc %d, volume %f, delay %d", __func__, volumeSource, volumeDb, delayMs);
        setCurVolume(volumeSource, volumeDb);
        setCurVolume(volumeSource, volumeDb, isVoiceVolSrc);
        return true;
    }
    return false;
@@ -510,11 +511,12 @@ bool SwAudioOutputDescriptor::setVolume(float volumeDb, bool muted,
                                        VolumeSource vs, const StreamTypeVector &streamTypes,
                                        const DeviceTypeSet& deviceTypes,
                                        uint32_t delayMs,
                                        bool force)
                                        bool force,
                                        bool isVoiceVolSrc)
{
    StreamTypeVector streams = streamTypes;
    if (!AudioOutputDescriptor::setVolume(
            volumeDb, muted, vs, streamTypes, deviceTypes, delayMs, force)) {
            volumeDb, muted, vs, streamTypes, deviceTypes, delayMs, force, isVoiceVolSrc)) {
        return false;
    }
    if (streams.empty()) {
@@ -560,6 +562,10 @@ bool SwAudioOutputDescriptor::setVolume(float volumeDb, bool muted,
    float volumeAmpl = Volume::DbToAmpl(getCurVolume(vs));
    if (hasStream(streams, AUDIO_STREAM_BLUETOOTH_SCO)) {
        mClientInterface->setStreamVolume(AUDIO_STREAM_VOICE_CALL, volumeAmpl, mIoHandle, delayMs);
        VolumeSource callVolSrc = getVoiceSource();
        if (callVolSrc != VOLUME_SOURCE_NONE) {
            setCurVolume(callVolSrc, getCurVolume(vs), true);
        }
    }
    for (const auto &stream : streams) {
        ALOGV("%s output %d for volumeSource %d, volume %f, delay %d stream=%s", __func__,
@@ -788,10 +794,11 @@ bool HwAudioOutputDescriptor::setVolume(float volumeDb, bool muted,
                                        VolumeSource volumeSource, const StreamTypeVector &streams,
                                        const DeviceTypeSet& deviceTypes,
                                        uint32_t delayMs,
                                        bool force)
                                        bool force,
                                        bool isVoiceVolSrc)
{
    bool changed = AudioOutputDescriptor::setVolume(
            volumeDb, muted, volumeSource, streams, deviceTypes, delayMs, force);
            volumeDb, muted, volumeSource, streams, deviceTypes, delayMs, force, isVoiceVolSrc);

    if (changed) {
      // TODO: use gain controller on source device if any to adjust volume
+2 −2
Original line number Diff line number Diff line
@@ -7844,8 +7844,8 @@ status_t AudioPolicyManager::checkAndSetVolume(IVolumeCurves &curves,
        volumeDb = 0.0f;
    }
    const bool muted = (index == 0) && (volumeDb != 0.0f);
    outputDesc->setVolume(
            volumeDb, muted, volumeSource, curves.getStreamTypes(), deviceTypes, delayMs, force);
    outputDesc->setVolume(volumeDb, muted, volumeSource, curves.getStreamTypes(),
            deviceTypes, delayMs, force, isVoiceVolSrc);

    if (outputDesc == mPrimaryOutput && (isVoiceVolSrc || isBtScoVolSrc)) {
        float voiceVolume;