summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEthan Chen <intervigil@gmail.com>2015-06-07 12:26:14 -0700
committerMatt Mower <mowerm@gmail.com>2016-06-21 12:31:28 -0500
commit1170162aa152bf5461b54cd51d75e03701a1cbe9 (patch)
treec8de367c88f1fca9dbf4ac2a6502769975eace86
parentdbf1e5fdda000da4a20d74c5d08257a986bc0e59 (diff)
downloadhardware_qcom_audio-1170162aa152bf5461b54cd51d75e03701a1cbe9.tar.gz
hardware_qcom_audio-1170162aa152bf5461b54cd51d75e03701a1cbe9.tar.bz2
hardware_qcom_audio-1170162aa152bf5461b54cd51d75e03701a1cbe9.zip
hal: Convert libaudioamp to audio_amplifier HAL
Change-Id: I5113923e3cc1989f2272ea439735492c9ce4d8a3
-rw-r--r--hal/Android.mk8
-rw-r--r--hal/audio_hw.c141
-rw-r--r--hal/audio_hw.h2
3 files changed, 130 insertions, 21 deletions
diff --git a/hal/Android.mk b/hal/Android.mk
index 71bae54a..1394a337 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -131,22 +131,18 @@ endif
LOCAL_SHARED_LIBRARIES := \
liblog \
libcutils \
+ libhardware \
libtinyalsa \
libtinycompress \
libaudioroute \
libdl \
libexpat
-ifneq ($(BOARD_AUDIO_AMPLIFIER),)
- LOCAL_CFLAGS += -DUSES_AUDIO_AMPLIFIER
- LOCAL_SHARED_LIBRARIES += libaudioamp
- LOCAL_C_INCLUDES += $(BOARD_AUDIO_AMPLIFIER)
-endif
-
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 d8aa8609..0b4a279a 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -55,10 +55,6 @@
#include "sound/compress_params.h"
#include "sound/asound.h"
-#ifdef USES_AUDIO_AMPLIFIER
-#include <audio_amplifier.h>
-#endif
-
#define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4
/* ToDo: Check and update a proper value in msec */
#define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 96
@@ -205,6 +201,116 @@ 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)
+{
+ int rc;
+ amplifier_module_t *module;
+
+ if (adev->amp)
+ return adev->amp;
+
+ 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 NULL;
+ }
+
+ 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 NULL;
+ }
+
+ return adev->amp;
+}
+
+static int amplifier_open(void)
+{
+ amplifier_device_t *amp = get_amplifier_device();
+
+ if (!amp) {
+ 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_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_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) {
@@ -817,12 +923,9 @@ int select_devices(struct audio_device *adev, audio_usecase_t uc_id)
enable_audio_route(adev, usecase);
-#ifdef USES_AUDIO_AMPLIFIER
/* Rely on amplifier_set_devices to distinguish between in/out devices */
- amplifier_set_devices(in_snd_device);
- amplifier_set_devices(out_snd_device);
-#endif
-
+ 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
@@ -1514,6 +1617,9 @@ 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 (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) {
if (out->pcm) {
@@ -1828,6 +1934,10 @@ 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, false);
+
pthread_mutex_unlock(&adev->lock);
/* ToDo: If use case is compress offload should return 0 */
if (ret != 0) {
@@ -2151,6 +2261,9 @@ static int in_standby(struct audio_stream *stream)
lock_input_stream(in);
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);
@@ -2284,6 +2397,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;
@@ -2911,10 +3028,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);
-#ifdef USES_AUDIO_AMPLIFIER
if (amplifier_set_mode(mode) != 0)
ALOGE("Failed setting amplifier mode");
-#endif
adev->mode = mode;
}
pthread_mutex_unlock(&adev->lock);
@@ -3128,10 +3243,8 @@ static int adev_close(hw_device_t *device)
pthread_mutex_lock(&adev_init_lock);
if ((--audio_device_ref_count) == 0) {
-#ifdef USES_AUDIO_AMPLIFIER
if (amplifier_close() != 0)
ALOGE("Amplifier close failed");
-#endif
audio_extn_listen_deinit(adev);
audio_route_free(adev->audio_route);
free(adev->snd_dev_ref_cnt);
@@ -3274,10 +3387,8 @@ static int adev_open(const hw_module_t *module, const char *name,
*device = &adev->device.common;
-#ifdef USES_AUDIO_AMPLIFIER
if (amplifier_open() != 0)
ALOGE("Amplifier initialization failed");
-#endif
audio_device_ref_count++;
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 8b4b5f0d..b9a72e10 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <cutils/list.h>
#include <hardware/audio.h>
+#include <hardware/audio_amplifier.h>
#include <tinyalsa/asoundlib.h>
#include <tinycompress/tinycompress.h>
@@ -261,6 +262,7 @@ struct audio_device {
int (*offload_effects_stop_output)(audio_io_handle_t, int);
struct sound_card_status snd_card_status;
+ amplifier_device_t *amp;
};
int select_devices(struct audio_device *adev,