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

Commit 88a5ecf4 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi Committed by Automerger Merge Worker
Browse files

Merge "AudioPolicyManager volume init on invalid min/max" into tm-dev am: 5008953a

parents 01df3c81 5008953a
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ std::set<audio_error_callback> AudioSystem::gAudioErrorCallbacks;
dynamic_policy_callback AudioSystem::gDynPolicyCallback = NULL;
record_config_callback AudioSystem::gRecordConfigCallback = NULL;
routing_callback AudioSystem::gRoutingCallback = NULL;
vol_range_init_req_callback AudioSystem::gVolRangeInitReqCallback = NULL;

// Required to be held while calling into gSoundTriggerCaptureStateListener.
class CaptureStateListenerImpl;
@@ -781,6 +782,11 @@ status_t AudioSystem::AudioFlingerClient::removeAudioDeviceCallback(
    gRoutingCallback = cb;
}

/*static*/ void AudioSystem::setVolInitReqCallback(vol_range_init_req_callback cb) {
    Mutex::Autolock _l(gLock);
    gVolRangeInitReqCallback = cb;
}

// client singleton for AudioPolicyService binder interface
// protected by gLockAPS
sp<IAudioPolicyService> AudioSystem::gAudioPolicyService;
@@ -2574,6 +2580,19 @@ Status AudioSystem::AudioPolicyServiceClient::onRoutingUpdated() {
    return Status::ok();
}

Status AudioSystem::AudioPolicyServiceClient::onVolumeRangeInitRequest() {
    vol_range_init_req_callback cb = NULL;
    {
        Mutex::Autolock _l(AudioSystem::gLock);
        cb = gVolRangeInitReqCallback;
    }

    if (cb != NULL) {
        cb();
    }
    return Status::ok();
}

void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who __unused) {
    {
        Mutex::Autolock _l(mLock);
+3 −0
Original line number Diff line number Diff line
@@ -46,4 +46,7 @@ oneway interface IAudioPolicyServiceClient {
                                        AudioSource source);
     /** Notifies a change of audio routing */
     void onRoutingUpdated();
     /** Notifies a request for volume index ranges to be reset after they were observed as invalid
      */
     void onVolumeRangeInitRequest();
}
+4 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ typedef void (*record_config_callback)(int event,
                                       audio_patch_handle_t patchHandle,
                                       audio_source_t source);
typedef void (*routing_callback)();
typedef void (*vol_range_init_req_callback)();

class IAudioFlinger;
class String8;
@@ -154,6 +155,7 @@ public:
    static void setDynPolicyCallback(dynamic_policy_callback cb);
    static void setRecordConfigCallback(record_config_callback);
    static void setRoutingCallback(routing_callback cb);
    static void setVolInitReqCallback(vol_range_init_req_callback cb);

    // Sets the binder to use for accessing the AudioFlinger service. This enables the system server
    // to grant specific isolated processes access to the audio system. Currently used only for the
@@ -736,6 +738,7 @@ private:
                int32_t patchHandle,
                media::audio::common::AudioSource source) override;
        binder::Status onRoutingUpdated();
        binder::Status onVolumeRangeInitRequest();

    private:
        Mutex                               mLock;
@@ -763,6 +766,7 @@ private:
    static dynamic_policy_callback gDynPolicyCallback;
    static record_config_callback gRecordConfigCallback;
    static routing_callback gRoutingCallback;
    static vol_range_init_req_callback gVolRangeInitReqCallback;

    static size_t gInBuffSize;
    // previous parameters for recording buffer size queries
+4 −0
Original line number Diff line number Diff line
@@ -533,6 +533,10 @@ public:

    virtual void onRoutingUpdated() = 0;

    // Used to notify AudioService that an error was encountering when reading
    // the volume ranges, and that they should be re-initialized
    virtual void onVolumeRangeInitRequest() = 0;

    // Used to notify the sound trigger module that an audio capture is about to
    // take place. This should typically result in any active recognition
    // sessions to be preempted on modules that do not support sound trigger
+11 −2
Original line number Diff line number Diff line
@@ -2118,11 +2118,15 @@ status_t AudioPolicyManager::startSource(const sp<SwAudioOutputDescriptor>& outp

        // apply volume rules for current stream and device if necessary
        auto &curves = getVolumeCurves(client->attributes());
        checkAndSetVolume(curves, client->volumeSource(),
        if (NO_ERROR != checkAndSetVolume(curves, client->volumeSource(),
                          curves.getVolumeIndex(outputDesc->devices().types()),
                          outputDesc,
                          outputDesc->devices().types(), 0 /*delay*/,
                          outputDesc->useHwGain() /*force*/);
                          outputDesc->useHwGain() /*force*/)) {
            // request AudioService to reinitialize the volume curves asynchronously
            ALOGE("checkAndSetVolume failed, requesting volume range init");
            mpClientInterface->onVolumeRangeInitRequest();
        };

        // update the outputs if starting an output with a stream that can affect notification
        // routing
@@ -7290,6 +7294,11 @@ status_t AudioPolicyManager::checkAndSetVolume(IVolumeCurves &curves,
        deviceTypes = outputDesc->devices().types();
    }

    if (curves.getVolumeIndexMin() < 0 || curves.getVolumeIndexMax() < 0) {
        ALOGE("invalid volume index range");
        return BAD_VALUE;
    }

    float volumeDb = computeVolume(curves, volumeSource, index, deviceTypes);
    if (outputDesc->isFixedVolume(deviceTypes) ||
            // Force VoIP volume to max for bluetooth SCO device except if muted
Loading