diff options
| author | Luca Stefani <luca.stefani.ge1@gmail.com> | 2016-02-28 21:38:42 +0100 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-03-22 14:16:13 -0700 |
| commit | df326e39061edf8be18553aea047fbba9440be16 (patch) | |
| tree | 6d478ca7007912f9422be8c16df0f790cade31ee | |
| parent | 5232764bb67c66e86d958c61bcd615e3dde22c6c (diff) | |
| download | hardware_qcom_audio-stable/cm-13.0-caf-8916-ZNH2KB.tar.gz hardware_qcom_audio-stable/cm-13.0-caf-8916-ZNH2KB.tar.bz2 hardware_qcom_audio-stable/cm-13.0-caf-8916-ZNH2KB.zip | |
audio: msm8916: Squashed audio amp commitsstable/cm-13.0-caf-8916-ZNH2KB
commit e821aba3b7603328f5b54877ae49c968db9f041e
Author: Scott Mertz <scott@cyngn.com>
Date: Fri Sep 11 12:13:08 2015 -0700
hal: notify amplifier of parameter changes
Change-Id: Iecc020c0347ae7c43d27183186e06dcefef7a0dd
commit 338f1b9c00aaa3830b44f030c255f974e781519a
Author: Dan Pasanen <dan.pasanen@gmail.com>
Date: Mon Aug 10 19:55:39 2015 -0500
hal: only open the amplifier once
Change-Id: Ie9bbff74123e90b71e95809a84dcb3bbe9ba82fe
commit d79e906e7d34369a2444bc6827bfb0fb57dc2c55
Author: Dan Pasanen <dan.pasanen@gmail.com>
Date: Mon Aug 10 19:47:43 2015 -0500
hal: enable amplifier earlier
Change-Id: Id876e8f836e3ce1ee5f8186ca9c0e6ef5f37182c
commit dfa41b007c557c30c87842d67c3089b624b45253
Author: Ethan Chen <intervigil@gmail.com>
Date: Fri Jul 3 21:35:30 2015 -0700
hal: Notify amplifier of device enable/disable
Change-Id: Ice808c9b55a9e3bc8bafe5ca3ff555377d38dd8f
commit 44448ed866ca8d1fbcce558504151e8f1ea9e480
Author: Ethan Chen <intervigil@gmail.com>
Date: Sun Jun 7 12:32:08 2015 -0700
hal: Convert libaudioamp to audio_amplifier HAL
Change-Id: I1d0f63a46989d1792d7a5e08d2bdb6344ebafa31
commit cb832553f11b79acc16772bd3f930a9d38f748c5
Author: Scott Mertz <scott@cyngn.com>
Date: Sat Jun 6 13:46:03 2015 -0700
audio: add amplifier stream start/standby operations
Change-Id: I5de7ad7a0467e7cf822c9c0870a755c03d05e884
commit 1437a75bee9d016dc58e10220cd69ae4c1454f24
Author: Daniel Hillenbrand <codeworkx@cyanogenmod.org>
Date: Thu May 23 10:10:00 2013 +0530
hal: Support the audio amplifier hook
* Original legacy HAL commit:
Ib236598a5888b2af19bcfb81e285f644a0e84c0d
* Example: http://review.cyanogenmod.org/38221
Change-Id: Ic944a9f7059c78b79322dae9c787cdd8bb029cff
Change-Id: I4ea9556a327b31ad2a39f182b8ac7114693f2ac6
| -rw-r--r-- | hal/Android.mk | 2 | ||||
| -rw-r--r-- | hal/audio_hw.c | 158 | ||||
| -rw-r--r-- | hal/audio_hw.h | 2 |
3 files changed, 162 insertions, 0 deletions
diff --git a/hal/Android.mk b/hal/Android.mk index 03e0d1c9..aa355471 100644 --- a/hal/Android.mk +++ b/hal/Android.mk @@ -232,6 +232,7 @@ endif LOCAL_SHARED_LIBRARIES := \ liblog \ libcutils \ + libhardware \ libtinyalsa \ libtinycompress \ libaudioroute \ @@ -243,6 +244,7 @@ LOCAL_C_INCLUDES += \ external/tinyalsa/include \ external/tinycompress/include \ external/expat/lib \ + hardware/libhardware/include \ $(call include-path-for, audio-route) \ $(call include-path-for, audio-effects) \ $(LOCAL_PATH)/$(AUDIO_PLATFORM) \ diff --git a/hal/audio_hw.c b/hal/audio_hw.c index 43c8baab..7560fbec 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -232,6 +232,133 @@ static unsigned int audio_device_ref_count; static int set_voice_volume_l(struct audio_device *adev, float volume); +static amplifier_device_t * get_amplifier_device(void) +{ + if (adev) + return adev->amp; + + return NULL; +} + +static int amplifier_open(void) +{ + int rc; + amplifier_module_t *module; + + rc = hw_get_module(AMPLIFIER_HARDWARE_MODULE_ID, + (const hw_module_t **) &module); + if (rc) { + ALOGV("%s: Failed to obtain reference to amplifier module: %s\n", + __func__, strerror(-rc)); + return -ENODEV; + } + + rc = amplifier_device_open((const hw_module_t *) module, &adev->amp); + if (rc) { + ALOGV("%s: Failed to open amplifier hardware device: %s\n", + __func__, strerror(-rc)); + return -ENODEV; + } + + return 0; +} + +static int amplifier_set_input_devices(uint32_t devices) +{ + amplifier_device_t *amp = get_amplifier_device(); + if (amp && amp->set_input_devices) + return amp->set_input_devices(amp, devices); + + return 0; +} + +static int amplifier_set_output_devices(uint32_t devices) +{ + amplifier_device_t *amp = get_amplifier_device(); + if (amp && amp->set_output_devices) + return amp->set_output_devices(amp, devices); + + return 0; +} + +static int amplifier_enable_devices(uint32_t devices, bool enable) +{ + amplifier_device_t *amp = get_amplifier_device(); + bool is_output = devices < SND_DEVICE_OUT_END; + + if (amp && amp->enable_output_devices && is_output) + return amp->enable_output_devices(amp, devices, enable); + + if (amp && amp->enable_input_devices && !is_output) + return amp->enable_input_devices(amp, devices, enable); + + return 0; +} + +static int amplifier_set_mode(audio_mode_t mode) +{ + amplifier_device_t *amp = get_amplifier_device(); + if (amp && amp->set_mode) + return amp->set_mode(amp, mode); + + return 0; +} + +static int amplifier_output_stream_start(struct audio_stream_out *stream, + bool offload) +{ + amplifier_device_t *amp = get_amplifier_device(); + if (amp && amp->output_stream_start) + return amp->output_stream_start(amp, stream, offload); + + return 0; +} + +static int amplifier_input_stream_start(struct audio_stream_in *stream) +{ + amplifier_device_t *amp = get_amplifier_device(); + if (amp && amp->input_stream_start) + return amp->input_stream_start(amp, stream); + + return 0; +} + +static int amplifier_output_stream_standby(struct audio_stream_out *stream) +{ + amplifier_device_t *amp = get_amplifier_device(); + if (amp && amp->output_stream_standby) + return amp->output_stream_standby(amp, stream); + + return 0; +} + +static int amplifier_input_stream_standby(struct audio_stream_in *stream) +{ + amplifier_device_t *amp = get_amplifier_device(); + if (amp && amp->input_stream_standby) + return amp->input_stream_standby(amp, stream); + + return 0; +} + +static int amplifier_set_parameters(struct str_parms *parms) +{ + amplifier_device_t *amp = get_amplifier_device(); + if (amp && amp->set_parameters) + return amp->set_parameters(amp, parms); + + return 0; +} + +static int amplifier_close(void) +{ + amplifier_device_t *amp = get_amplifier_device(); + if (amp) + amplifier_device_close(amp); + + return 0; +} + static int check_and_set_gapless_mode(struct audio_device *adev) { @@ -504,6 +631,7 @@ int enable_snd_device(struct audio_device *adev, return -EINVAL; } audio_extn_dev_arbi_acquire(snd_device); + amplifier_enable_devices(snd_device, true); audio_route_apply_and_update_path(adev->audio_route, device_name); } return 0; @@ -552,6 +680,7 @@ int disable_snd_device(struct audio_device *adev, audio_extn_spkr_prot_stop_processing(snd_device); } else { audio_route_reset_and_update_path(adev->audio_route, device_name); + amplifier_enable_devices(snd_device, false); audio_extn_dev_arbi_release(snd_device); } @@ -939,6 +1068,10 @@ int select_devices(struct audio_device *adev, audio_usecase_t uc_id) enable_audio_route(adev, usecase); + /* Rely on amplifier_set_devices to distinguish between in/out devices */ + amplifier_set_input_devices(in_snd_device); + amplifier_set_output_devices(out_snd_device); + /* Applicable only on the targets that has external modem. * Enable device command should be sent to modem only after * enabling voice call mixer controls @@ -1715,7 +1848,11 @@ static int out_standby(struct audio_stream *stream) lock_output_stream(out); if (!out->standby) { pthread_mutex_lock(&adev->lock); + + amplifier_output_stream_standby((struct audio_stream_out *) stream); + out->standby = true; + if (!is_offload_usecase(out->usecase)) { if (out->pcm) { pcm_close(out->pcm); @@ -2024,6 +2161,11 @@ static ssize_t out_write(struct audio_stream_out *stream, const void *buffer, ret = voice_extn_compress_voip_start_output_stream(out); else ret = start_output_stream(out); + + if (ret == 0) + amplifier_output_stream_start(stream, + is_offload_usecase(out->usecase)); + pthread_mutex_unlock(&adev->lock); /* ToDo: If use case is compress offload should return 0 */ if (ret != 0) { @@ -2380,6 +2522,9 @@ static int in_standby(struct audio_stream *stream) if (!in->standby) { pthread_mutex_lock(&adev->lock); + + amplifier_input_stream_standby((struct audio_stream_in *) stream); + in->standby = true; if (in->pcm) { pcm_close(in->pcm); @@ -2517,6 +2662,10 @@ 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 == 0) + amplifier_input_stream_start(stream); + pthread_mutex_unlock(&adev->lock); if (ret != 0) { goto exit; @@ -3095,6 +3244,7 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) } audio_extn_set_parameters(adev, parms); + amplifier_set_parameters(parms); done: str_parms_destroy(parms); @@ -3193,6 +3343,8 @@ static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) pthread_mutex_lock(&adev->lock); if (adev->mode != mode) { ALOGD("%s: mode %d\n", __func__, mode); + if (amplifier_set_mode(mode) != 0) + ALOGE("Failed setting amplifier mode"); adev->mode = mode; if ((mode == AUDIO_MODE_NORMAL || mode == AUDIO_MODE_IN_COMMUNICATION) && voice_is_in_call(adev)) { @@ -3546,6 +3698,8 @@ static int adev_close(hw_device_t *device) pthread_mutex_lock(&adev_init_lock); if ((--audio_device_ref_count) == 0) { + if (amplifier_close() != 0) + ALOGE("Amplifier close failed"); audio_extn_sound_trigger_deinit(adev); audio_extn_listen_deinit(adev); audio_extn_utils_release_streams_output_cfg_list(&adev->streams_output_cfg_list); @@ -3697,6 +3851,10 @@ static int adev_open(const hw_module_t *module, const char *name, adev->bt_wb_speech_enabled = false; audio_extn_ds2_enable(adev); + + if (amplifier_open() != 0) + ALOGE("Amplifier initialization failed"); + *device = &adev->device.common; audio_extn_utils_update_streams_output_cfg_list(adev->platform, adev->mixer, diff --git a/hal/audio_hw.h b/hal/audio_hw.h index c0b1bd24..c4acf0c7 100644 --- a/hal/audio_hw.h +++ b/hal/audio_hw.h @@ -21,6 +21,7 @@ #define QCOM_AUDIO_HW_H #include <cutils/list.h> +#include <hardware/audio_amplifier.h> #include <hardware/audio.h> #include <tinyalsa/asoundlib.h> #include <tinycompress/tinycompress.h> @@ -308,6 +309,7 @@ struct audio_device { * or other capabilities are present for the device corresponding to that usecase. */ struct pcm_params *use_case_table[AUDIO_USECASE_MAX]; + amplifier_device_t *amp; }; int select_devices(struct audio_device *adev, |
