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

Commit 81ccb8fe authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "prevent preempting overlapping sound trigger audio streams" into oc-dr1-dev

parents 5f1b1e7c 2b864648
Loading
Loading
Loading
Loading
+46 −1
Original line number Diff line number Diff line
@@ -1815,6 +1815,40 @@ bool AudioPolicyManager::isConcurentCaptureAllowed(const sp<AudioInputDescriptor
    return true;
}

// FIXME: remove when concurrent capture is ready. This is a hack to work around bug b/63083537.
bool AudioPolicyManager::soundTriggerSupportsConcurrentCapture() {
    if (!mHasComputedSoundTriggerSupportsConcurrentCapture) {
        bool soundTriggerSupportsConcurrentCapture = false;
        unsigned int numModules = 0;
        struct sound_trigger_module_descriptor* nModules = NULL;

        status_t status = SoundTrigger::listModules(nModules, &numModules);
        if (status == NO_ERROR && numModules != 0) {
            nModules = (struct sound_trigger_module_descriptor*) calloc(
                    numModules, sizeof(struct sound_trigger_module_descriptor));
            if (nModules == NULL) {
              // We failed to malloc the buffer, so just say no for now, and hope that we have more
              // ram the next time this function is called.
              ALOGE("Failed to allocate buffer for module descriptors");
              return false;
            }

            status = SoundTrigger::listModules(nModules, &numModules);
            if (status == NO_ERROR) {
                soundTriggerSupportsConcurrentCapture = true;
                for (size_t i = 0; i < numModules; ++i) {
                    soundTriggerSupportsConcurrentCapture &=
                            nModules[i].properties.concurrent_capture;
                }
            }
            free(nModules);
        }
        mSoundTriggerSupportsConcurrentCapture = soundTriggerSupportsConcurrentCapture;
        mHasComputedSoundTriggerSupportsConcurrentCapture = true;
    }
    return mSoundTriggerSupportsConcurrentCapture;
}


status_t AudioPolicyManager::startInput(audio_io_handle_t input,
                                        audio_session_t session,
@@ -1887,6 +1921,12 @@ status_t AudioPolicyManager::startInput(audio_io_handle_t input,
            }
        }

        // We only need to check if the sound trigger session supports concurrent capture if the
        // input is also a sound trigger input. Otherwise, we should preempt any hotword stream
        // that's running.
        const bool allowConcurrentWithSoundTrigger =
            inputDesc->isSoundTrigger() ? soundTriggerSupportsConcurrentCapture() : false;

        // if capture is allowed, preempt currently active HOTWORD captures
        for (size_t i = 0; i < activeInputs.size(); i++) {
            sp<AudioInputDescriptor> activeDesc = activeInputs[i];
@@ -1895,6 +1935,10 @@ status_t AudioPolicyManager::startInput(audio_io_handle_t input,
                continue;
            }

            if (allowConcurrentWithSoundTrigger && activeDesc->isSoundTrigger()) {
                continue;
            }

            audio_source_t activeSource = activeDesc->inputSource(true);
            if (activeSource == AUDIO_SOURCE_HOTWORD) {
                AudioSessionCollection activeSessions =
@@ -3491,7 +3535,8 @@ AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterfa
    mBeaconMuted(false),
    mTtsOutputAvailable(false),
    mMasterMono(false),
    mMusicEffectOutput(AUDIO_IO_HANDLE_NONE)
    mMusicEffectOutput(AUDIO_IO_HANDLE_NONE),
    mHasComputedSoundTriggerSupportsConcurrentCapture(false)
{
    mUidCached = getuid();
    mpClientInterface = clientInterface;
+4 −0
Original line number Diff line number Diff line
@@ -671,6 +671,10 @@ private:
            param.addInt(String8(AudioParameter::keyMonoOutput), (int)mMasterMono);
            mpClientInterface->setParameters(output, param.toString());
        }

        bool soundTriggerSupportsConcurrentCapture();
        bool mSoundTriggerSupportsConcurrentCapture;
        bool mHasComputedSoundTriggerSupportsConcurrentCapture;
};

};