* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2017 Christopher N. Hesse <raymanfx@gmail.com>
* Copyright (C) 2017 Andreas Schneider <asn@cryptomilk.org>
+ * Copyright (C) 2018 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
.devices = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
};
-#ifdef SOUND_CAPTURE_HOTWORD_DEVICE
-static struct pcm_device_profile pcm_device_hotword_streaming = {
- .config = {
- .channels = 1,
- .rate = 16000,
- .period_size = CAPTURE_PERIOD_SIZE,
- .period_count = CAPTURE_PERIOD_COUNT,
- .format = PCM_FORMAT_S16_LE,
- .start_threshold = CAPTURE_START_THRESHOLD,
- .stop_threshold = 0,
- .silence_threshold = 0,
- .avail_min = 0,
- },
- .card = SOUND_CARD,
- .id = SOUND_CAPTURE_HOTWORD_DEVICE,
- .type = PCM_HOTWORD_STREAMING,
- .devices = AUDIO_DEVICE_IN_BUILTIN_MIC|AUDIO_DEVICE_IN_WIRED_HEADSET|AUDIO_DEVICE_IN_BACK_MIC
-};
-#endif
-
static struct pcm_device_profile * const pcm_devices[] = {
&pcm_device_playback,
&pcm_device_capture,
&pcm_device_capture_sco,
#ifdef SOUND_CAPTURE_LOOPBACK_AEC_DEVICE
&pcm_device_capture_loopback_aec,
-#endif
-#ifdef SOUND_CAPTURE_HOTWORD_DEVICE
- &pcm_device_hotword_streaming,
#endif
NULL,
};
[USECASE_AUDIO_PLAYBACK_OFFLOAD] = "compress-offload-playback",
[USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "playback deep-buffer",
[USECASE_AUDIO_CAPTURE] = "capture",
- [USECASE_AUDIO_CAPTURE_HOTWORD] = "capture-hotword",
[USECASE_VOICE_CALL] = "voice-call",
};
ALOGV("%s: usecase(%d)", __func__, uc_id);
- if (uc_id == USECASE_AUDIO_CAPTURE_HOTWORD)
- return 0;
-
usecase = get_usecase_from_type(adev, PCM_CAPTURE|VOICE_CALL);
if (usecase != NULL) {
active_input = (struct stream_in *)usecase->stream;
pcm_device->pcm_profile->config.channels,pcm_device->pcm_profile->config.rate,
pcm_device->pcm_profile->config.format, pcm_device->pcm_profile->config.period_size);
- if (pcm_profile->type == PCM_HOTWORD_STREAMING) {
- if (!adev->sound_trigger_open_for_streaming) {
- ALOGE("%s: No handle to sound trigger HAL", __func__);
- ret = -EIO;
- goto error_open;
- }
- pcm_device->pcm = NULL;
- pcm_device->sound_trigger_handle = adev->sound_trigger_open_for_streaming();
- if (pcm_device->sound_trigger_handle <= 0) {
- ALOGE("%s: Failed to open DSP for streaming", __func__);
- ret = -EIO;
- goto error_open;
- }
- ALOGV("Opened DSP successfully");
- } else {
- pcm_device->sound_trigger_handle = 0;
- pcm_device->pcm = pcm_open(pcm_device->pcm_profile->card, pcm_device->pcm_profile->id,
+ pcm_device->pcm = pcm_open(pcm_device->pcm_profile->card, pcm_device->pcm_profile->id,
PCM_IN | PCM_MONOTONIC, &pcm_device->pcm_profile->config);
- if (pcm_device->pcm && !pcm_is_ready(pcm_device->pcm)) {
- ALOGE("%s: %s", __func__, pcm_get_error(pcm_device->pcm));
- pcm_close(pcm_device->pcm);
- pcm_device->pcm = NULL;
- ret = -EIO;
- goto error_open;
- }
+ if (pcm_device->pcm && !pcm_is_ready(pcm_device->pcm)) {
+ ALOGE("%s: %s", __func__, pcm_get_error(pcm_device->pcm));
+ pcm_close(pcm_device->pcm);
+ pcm_device->pcm = NULL;
+ ret = -EIO;
+ goto error_open;
}
skip_pcm_handling:
{
struct pcm_device *pcm_device;
struct listnode *node;
- struct audio_device *adev = out->dev;
list_for_each(node, &out->pcm_dev_list) {
pcm_device = node_to_item(node, struct pcm_device, stream_list_node);
- if (pcm_device->sound_trigger_handle > 0) {
- adev->sound_trigger_close_for_streaming(pcm_device->sound_trigger_handle);
- pcm_device->sound_trigger_handle = 0;
- }
if (pcm_device->pcm) {
pcm_close(pcm_device->pcm);
pcm_device->pcm = NULL;
{
struct pcm_device *pcm_device;
struct listnode *node;
- struct audio_device *adev = in->dev;
list_for_each(node, &in->pcm_dev_list) {
pcm_device = node_to_item(node, struct pcm_device, stream_list_node);
if (pcm_device->pcm)
pcm_close(pcm_device->pcm);
pcm_device->pcm = NULL;
- if (pcm_device->sound_trigger_handle > 0)
- adev->sound_trigger_close_for_streaming(pcm_device->sound_trigger_handle);
- pcm_device->sound_trigger_handle = 0;
}
}
return 0;
return 0;
}
-static ssize_t read_bytes_from_dsp(struct stream_in *in, void* buffer,
- size_t bytes)
-{
- struct pcm_device *pcm_device;
- struct audio_device *adev = in->dev;
-
- pcm_device = node_to_item(list_head(&in->pcm_dev_list),
- struct pcm_device, stream_list_node);
-
- if (pcm_device->sound_trigger_handle > 0)
- return adev->sound_trigger_read_samples(pcm_device->sound_trigger_handle, buffer, bytes);
- else
- return 0;
-}
-
static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
size_t bytes)
{
false_alarm:
if (!list_empty(&in->pcm_dev_list)) {
- if (in->usecase == USECASE_AUDIO_CAPTURE_HOTWORD) {
- bytes = read_bytes_from_dsp(in, buffer, bytes);
- if (bytes > 0)
- read_and_process_successful = true;
- } else {
- /*
- * Read PCM and:
- * - resample if needed
- * - process if pre-processors are attached
- * - discard unwanted channels
- */
- frames = read_and_process_frames(in, buffer, frames_rq);
- if (frames >= 0)
- read_and_process_successful = true;
- }
+ /*
+ * Read PCM and:
+ * - resample if needed
+ * - process if pre-processors are attached
+ * - discard unwanted channels
+ */
+ frames = read_and_process_frames(in, buffer, frames_rq);
+ if (frames >= 0)
+ read_and_process_successful = true;
}
/*
audio_channel_count_from_in_mask(config->channel_mask)) != 0)
return -EINVAL;
- usecase_type_t usecase_type = source == AUDIO_SOURCE_HOTWORD ?
- PCM_HOTWORD_STREAMING : flags & AUDIO_INPUT_FLAG_FAST ?
+ usecase_type_t usecase_type = flags & AUDIO_INPUT_FLAG_FAST ?
PCM_CAPTURE_LOW_LATENCY : PCM_CAPTURE;
pcm_profile = get_pcm_device(usecase_type, devices);
if (pcm_profile == NULL && usecase_type == PCM_CAPTURE_LOW_LATENCY) {
in->config = pcm_profile->config;
/* Update config params with the requested sample rate and channels */
- if (source == AUDIO_SOURCE_HOTWORD) {
- in->usecase = USECASE_AUDIO_CAPTURE_HOTWORD;
- } else {
- in->usecase = USECASE_AUDIO_CAPTURE;
- }
+ in->usecase = USECASE_AUDIO_CAPTURE;
in->usecase_type = usecase_type;
pthread_mutex_init(&in->lock, (const pthread_mutexattr_t *) NULL);
}
}
- if (access(SOUND_TRIGGER_HAL_LIBRARY_PATH, R_OK) == 0) {
- adev->sound_trigger_lib = dlopen(SOUND_TRIGGER_HAL_LIBRARY_PATH, RTLD_NOW);
- if (adev->sound_trigger_lib == NULL) {
- ALOGE("%s: DLOPEN failed for %s", __func__, SOUND_TRIGGER_HAL_LIBRARY_PATH);
- } else {
- ALOGV("%s: DLOPEN successful for %s", __func__, SOUND_TRIGGER_HAL_LIBRARY_PATH);
- adev->sound_trigger_open_for_streaming =
- (int (*)(void))dlsym(adev->sound_trigger_lib,
- "sound_trigger_open_for_streaming");
- adev->sound_trigger_read_samples =
- (size_t (*)(int, void *, size_t))dlsym(adev->sound_trigger_lib,
- "sound_trigger_read_samples");
- adev->sound_trigger_close_for_streaming =
- (int (*)(int))dlsym(adev->sound_trigger_lib,
- "sound_trigger_close_for_streaming");
- if (!adev->sound_trigger_open_for_streaming ||
- !adev->sound_trigger_read_samples ||
- !adev->sound_trigger_close_for_streaming) {
-
- ALOGE("%s: Error grabbing functions in %s", __func__, SOUND_TRIGGER_HAL_LIBRARY_PATH);
- adev->sound_trigger_open_for_streaming = 0;
- adev->sound_trigger_read_samples = 0;
- adev->sound_trigger_close_for_streaming = 0;
- }
- }
- }
-
adev->voice.session = voice_session_init(adev);
if (adev->voice.session == NULL) {
ALOGE("%s: Failed to initialize voice session data", __func__);