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

Commit c4106f73 authored by Simon Shields's avatar Simon Shields Committed by Dan Pasanen
Browse files

policy_hal: fix build with concurrent audio capture

This brings the policy HAL in line with fw/av commit
4b2fcd8abf90b1bd95539f9f4ef2ac39ce9e2df1 ("audio policy
for concurrent capture")

Change-Id: I52777565da44b57e2c67066e060e2ee64f8e4cfa
parent 343b7358
Loading
Loading
Loading
Loading
+65 −59
Original line number Diff line number Diff line
@@ -712,9 +712,10 @@ void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state)
        mvoice_call_state = state;
        if (prop_rec_enabled) {
            //Close all active inputs
            audio_io_handle_t activeInput = mInputs.getActiveInput();
            if (activeInput != 0) {
               sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput);
            Vector<sp <AudioInputDescriptor> > activeInputs = mInputs.getActiveInputs();
            for (size_t i = 0; i < activeInputs.size(); i++) {
                if (activeInputs[i] != 0) {
                    sp<AudioInputDescriptor> activeDesc = activeInputs[i];
                    switch(activeDesc->inputSource()) {
                        case AUDIO_SOURCE_VOICE_UPLINK:
                        case AUDIO_SOURCE_VOICE_DOWNLINK:
@@ -725,32 +726,35 @@ void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state)
                        case  AUDIO_SOURCE_VOICE_COMMUNICATION:
                             if(prop_voip_enabled) {
                                 ALOGD("voice_conc:CLOSING VoIP input source on call setup :%d ",activeDesc->inputSource());
                            AudioSessionCollection activeSessions = activeDesc->getActiveAudioSessions();
                                 AudioSessionCollection activeSessions = activeDesc->getAudioSessions(true /*activeOnly*/);
                                 audio_session_t activeSession = activeSessions.keyAt(0);
                            stopInput(activeInput, activeSession);
                            releaseInput(activeInput, activeSession);
                                 stopInput(activeDesc->mIoHandle, activeSession);
                                 releaseInput(activeDesc->mIoHandle, activeSession);
                             }
                        break;

                        default:
                            ALOGD("voice_conc:CLOSING input on call setup  for inputSource: %d",activeDesc->inputSource());
                       AudioSessionCollection activeSessions = activeDesc->getActiveAudioSessions();
                            AudioSessionCollection activeSessions = activeDesc->getAudioSessions(true /* activeOnly */);
                            audio_session_t activeSession = activeSessions.keyAt(0);
                       stopInput(activeInput, activeSession);
                       releaseInput(activeInput, activeSession);
                            stopInput(activeDesc->mIoHandle, activeSession);
                            releaseInput(activeDesc->mIoHandle, activeSession);
                        break;
                    }
                }
            }
        } else if (prop_voip_enabled) {
            audio_io_handle_t activeInput = mInputs.getActiveInput();
            if (activeInput != 0) {
                sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput);
            Vector<sp <AudioInputDescriptor> > activeInputs = mInputs.getActiveInputs();
            for (size_t i = 0; i < activeInputs.size(); i++) {
                if (activeInputs[i] != 0) {
                    sp<AudioInputDescriptor> activeDesc = activeInputs[i];
                    if (AUDIO_SOURCE_VOICE_COMMUNICATION == activeDesc->inputSource()) {
                        ALOGD("voice_conc:CLOSING VoIP on call setup : %d",activeDesc->inputSource());
                    AudioSessionCollection activeSessions = activeDesc->getActiveAudioSessions();
                        AudioSessionCollection activeSessions = activeDesc->getAudioSessions(true /* activeOnly */);
                        audio_session_t activeSession = activeSessions.keyAt(0);
                    stopInput(activeInput, activeSession);
                    releaseInput(activeInput, activeSession);
                        stopInput(activeDesc->mIoHandle, activeSession);
                        releaseInput(activeDesc->mIoHandle, activeSession);
                    }
                }
            }
        }
@@ -1916,29 +1920,31 @@ status_t AudioPolicyManagerCustom::startInput(audio_io_handle_t input,
    if (!is_virtual_input_device(inputDesc->mDevice)) {

        // for a non-virtual input device, check if there is another (non-virtual) active input
        audio_io_handle_t activeInput = mInputs.getActiveInput();
        if (activeInput != 0 && activeInput != input) {
        Vector<sp <AudioInputDescriptor> > activeInputs = mInputs.getActiveInputs();
        for (size_t i = 0; i < activeInputs.size(); i++) {
            if (activeInputs[i]->mIoHandle != 0 && activeInputs[i]->mIoHandle != input) {

                // If the already active input uses AUDIO_SOURCE_HOTWORD then it is closed,
                // otherwise the active input continues and the new input cannot be started.
            sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput);
                sp<AudioInputDescriptor> activeDesc = activeInputs[i];
                if ((activeDesc->inputSource() == AUDIO_SOURCE_HOTWORD) &&
                        !activeDesc->hasPreemptedSession(session)) {
                ALOGW("startInput(%d) preempting low-priority input %d", input, activeInput);
                    ALOGW("startInput(%d) preempting low-priority input %d", input, activeDesc->mIoHandle);
                    //FIXME: consider all active sessions
                AudioSessionCollection activeSessions = activeDesc->getActiveAudioSessions();
                    AudioSessionCollection activeSessions = activeDesc->getAudioSessions(true /* activeOnly */);
                    audio_session_t activeSession = activeSessions.keyAt(0);
                    SortedVector<audio_session_t> sessions =
                                               activeDesc->getPreemptedSessions();
                    sessions.add(activeSession);
                    inputDesc->setPreemptedSessions(sessions);
                stopInput(activeInput, activeSession);
                releaseInput(activeInput, activeSession);
                    stopInput(activeDesc->mIoHandle, activeSession);
                    releaseInput(activeDesc->mIoHandle, activeSession);
                } else {
                ALOGE("startInput(%d) failed: other input %d already started", input, activeInput);
                    ALOGE("startInput(%d) failed: other input %d already started", input, activeDesc->mIoHandle);
                    return INVALID_OPERATION;
                }
            }
        }
        // Do not allow capture if an active voice call is using a software patch and
        // the call TX source device is on the same HW module.
        // FIXME: would be better to refine to only inputs whose profile connects to the
@@ -2009,7 +2015,7 @@ status_t AudioPolicyManagerCustom::startInput(audio_io_handle_t input,

        // indicate active capture to sound trigger service if starting capture from a mic on
        // primary HW module
        audio_devices_t device = getNewInputDevice(input);
        audio_devices_t device = getNewInputDevice(inputDesc);
        audio_devices_t primaryInputDevices = availablePrimaryInputDevices();
        if (((device & primaryInputDevices & ~AUDIO_DEVICE_BIT_IN) != 0) &&
                mInputs.activeInputsCountOnDevices(primaryInputDevices) == 0) {