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

Commit f605036c authored by Quinn Male's avatar Quinn Male
Browse files

hal: Mute other active streams while voice recognition is active

In order to protect voice recognition data from other clients
in audio record concurrency usecases, mute all active non voice
recognition input streams.

Change-Id: I1002726699902952c8b8568d57aa1cb6dfc2ad2b
parent a5ec6113
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -358,8 +358,6 @@ int audio_extn_sound_trigger_read(struct stream_in *in, void *buffer,
        ALOGE(" %s: Sound trigger is not active", __func__);
        goto exit;
    }
    if(in->standby)
        in->standby = false;

    pthread_mutex_lock(&st_dev->lock);
    st_info = get_sound_trigger_info(in->capture_handle);
+22 −4
Original line number Diff line number Diff line
@@ -5608,6 +5608,7 @@ static int in_standby(struct audio_stream *stream)
    if (!in->standby && in->is_st_session) {
        ALOGD("%s: sound trigger pcm stop lab", __func__);
        audio_extn_sound_trigger_stop_lab(in);
        adev->num_va_sessions--;
        in->standby = 1;
    }

@@ -5640,6 +5641,10 @@ static int in_standby(struct audio_stream *stream)
            platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE);
            status = stop_input_stream(in);
        }

        if (in->source == AUDIO_SOURCE_VOICE_RECOGNITION)
            adev->num_va_sessions--;

        pthread_mutex_unlock(&adev->lock);
    }
    pthread_mutex_unlock(&in->lock);
@@ -5889,6 +5894,10 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
        ALOGVV(" %s: reading on st session bytes=%zu", __func__, bytes);
        /* Read from sound trigger HAL */
        audio_extn_sound_trigger_read(in, buffer, bytes);
        if (in->standby) {
            adev->num_va_sessions++;
            in->standby = 0;
        }
        pthread_mutex_unlock(&in->lock);
        return bytes;
    }
@@ -5904,6 +5913,8 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
            ret = voice_extn_compress_voip_start_input_stream(in);
        else
            ret = start_input_stream(in);
        if (!ret && in->source == AUDIO_SOURCE_VOICE_RECOGNITION)
            adev->num_va_sessions++;
        pthread_mutex_unlock(&adev->lock);
        if (ret != 0) {
            goto exit;
@@ -5952,11 +5963,18 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
    release_in_focus(in);

    /*
     * Instead of writing zeroes here, we could trust the hardware
     * to always provide zeroes when muted.
     * Instead of writing zeroes here, we could trust the hardware to always
     * provide zeroes when muted. This is also muted with voice recognition
     * usecases so that other clients do not have access to voice recognition
     * data.
     */
    if (ret == 0 && voice_get_mic_mute(adev) && !voice_is_in_call_rec_stream(in) &&
            in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY)
    if ((ret == 0 && voice_get_mic_mute(adev) &&
         !voice_is_in_call_rec_stream(in) &&
         in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY) ||
        (adev->num_va_sessions &&
         in->source != AUDIO_SOURCE_VOICE_RECOGNITION &&
         property_get_bool("persist.vendor.audio.va_concurrency_mute_enabled",
            false)))
        memset(buffer, 0, bytes);

exit:
+1 −0
Original line number Diff line number Diff line
@@ -517,6 +517,7 @@ struct audio_device {
    bool enable_hfp;
    bool mic_muted;
    bool enable_voicerx;
    unsigned int num_va_sessions;

    int snd_card;
    card_status_t card_status;