Loading hal/Android.mk +2 −6 Original line number Original line Diff line number Diff line Loading @@ -131,22 +131,18 @@ endif LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \ liblog \ liblog \ libcutils \ libcutils \ libhardware \ libtinyalsa \ libtinyalsa \ libtinycompress \ libtinycompress \ libaudioroute \ libaudioroute \ libdl \ libdl \ libexpat libexpat ifneq ($(BOARD_AUDIO_AMPLIFIER),) LOCAL_CFLAGS += -DUSES_AUDIO_AMPLIFIER LOCAL_SHARED_LIBRARIES += libaudioamp LOCAL_C_INCLUDES += $(BOARD_AUDIO_AMPLIFIER) endif LOCAL_C_INCLUDES += \ LOCAL_C_INCLUDES += \ external/tinyalsa/include \ external/tinyalsa/include \ external/tinycompress/include \ external/tinycompress/include \ external/expat/lib \ external/expat/lib \ hardware/libhardware/include \ $(call include-path-for, audio-route) \ $(call include-path-for, audio-route) \ $(call include-path-for, audio-effects) \ $(call include-path-for, audio-effects) \ $(LOCAL_PATH)/$(AUDIO_PLATFORM) \ $(LOCAL_PATH)/$(AUDIO_PLATFORM) \ Loading hal/audio_hw.c +126 −15 Original line number Original line Diff line number Diff line Loading @@ -55,10 +55,6 @@ #include "sound/compress_params.h" #include "sound/compress_params.h" #include "sound/asound.h" #include "sound/asound.h" #ifdef USES_AUDIO_AMPLIFIER #include <audio_amplifier.h> #endif #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4 #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4 /* ToDo: Check and update a proper value in msec */ /* ToDo: Check and update a proper value in msec */ #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 96 #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 96 Loading Loading @@ -205,6 +201,116 @@ static unsigned int audio_device_ref_count; static int set_voice_volume_l(struct audio_device *adev, float volume); 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) { static int check_and_set_gapless_mode(struct audio_device *adev) { Loading Loading @@ -817,12 +923,9 @@ int select_devices(struct audio_device *adev, audio_usecase_t uc_id) enable_audio_route(adev, usecase); enable_audio_route(adev, usecase); #ifdef USES_AUDIO_AMPLIFIER /* Rely on amplifier_set_devices to distinguish between in/out devices */ /* Rely on amplifier_set_devices to distinguish between in/out devices */ amplifier_set_devices(in_snd_device); amplifier_set_input_devices(in_snd_device); amplifier_set_devices(out_snd_device); amplifier_set_output_devices(out_snd_device); #endif /* Applicable only on the targets that has external modem. /* Applicable only on the targets that has external modem. * Enable device command should be sent to modem only after * Enable device command should be sent to modem only after Loading Loading @@ -1514,6 +1617,9 @@ static int out_standby(struct audio_stream *stream) lock_output_stream(out); lock_output_stream(out); if (!out->standby) { if (!out->standby) { pthread_mutex_lock(&adev->lock); pthread_mutex_lock(&adev->lock); amplifier_output_stream_standby((struct audio_stream_out *) stream); out->standby = true; out->standby = true; if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) { if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) { if (out->pcm) { if (out->pcm) { Loading Loading @@ -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); ret = voice_extn_compress_voip_start_output_stream(out); else else ret = start_output_stream(out); ret = start_output_stream(out); if (ret == 0) amplifier_output_stream_start(stream, false); pthread_mutex_unlock(&adev->lock); pthread_mutex_unlock(&adev->lock); /* ToDo: If use case is compress offload should return 0 */ /* ToDo: If use case is compress offload should return 0 */ if (ret != 0) { if (ret != 0) { Loading Loading @@ -2151,6 +2261,9 @@ static int in_standby(struct audio_stream *stream) lock_input_stream(in); lock_input_stream(in); if (!in->standby) { if (!in->standby) { pthread_mutex_lock(&adev->lock); pthread_mutex_lock(&adev->lock); amplifier_input_stream_standby((struct audio_stream_in *) stream); in->standby = true; in->standby = true; if (in->pcm) { if (in->pcm) { pcm_close(in->pcm); pcm_close(in->pcm); Loading Loading @@ -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); ret = voice_extn_compress_voip_start_input_stream(in); else else ret = start_input_stream(in); ret = start_input_stream(in); if (ret == 0) amplifier_input_stream_start(stream); pthread_mutex_unlock(&adev->lock); pthread_mutex_unlock(&adev->lock); if (ret != 0) { if (ret != 0) { goto exit; goto exit; Loading Loading @@ -2911,10 +3028,8 @@ static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) pthread_mutex_lock(&adev->lock); pthread_mutex_lock(&adev->lock); if (adev->mode != mode) { if (adev->mode != mode) { ALOGD("%s mode %d\n", __func__, mode); ALOGD("%s mode %d\n", __func__, mode); #ifdef USES_AUDIO_AMPLIFIER if (amplifier_set_mode(mode) != 0) if (amplifier_set_mode(mode) != 0) ALOGE("Failed setting amplifier mode"); ALOGE("Failed setting amplifier mode"); #endif adev->mode = mode; adev->mode = mode; } } pthread_mutex_unlock(&adev->lock); pthread_mutex_unlock(&adev->lock); Loading Loading @@ -3128,10 +3243,8 @@ static int adev_close(hw_device_t *device) pthread_mutex_lock(&adev_init_lock); pthread_mutex_lock(&adev_init_lock); if ((--audio_device_ref_count) == 0) { if ((--audio_device_ref_count) == 0) { #ifdef USES_AUDIO_AMPLIFIER if (amplifier_close() != 0) if (amplifier_close() != 0) ALOGE("Amplifier close failed"); ALOGE("Amplifier close failed"); #endif audio_extn_listen_deinit(adev); audio_extn_listen_deinit(adev); audio_route_free(adev->audio_route); audio_route_free(adev->audio_route); free(adev->snd_dev_ref_cnt); free(adev->snd_dev_ref_cnt); Loading Loading @@ -3274,10 +3387,8 @@ static int adev_open(const hw_module_t *module, const char *name, *device = &adev->device.common; *device = &adev->device.common; #ifdef USES_AUDIO_AMPLIFIER if (amplifier_open() != 0) if (amplifier_open() != 0) ALOGE("Amplifier initialization failed"); ALOGE("Amplifier initialization failed"); #endif audio_device_ref_count++; audio_device_ref_count++; Loading hal/audio_hw.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <stdlib.h> #include <stdlib.h> #include <cutils/list.h> #include <cutils/list.h> #include <hardware/audio.h> #include <hardware/audio.h> #include <hardware/audio_amplifier.h> #include <tinyalsa/asoundlib.h> #include <tinyalsa/asoundlib.h> #include <tinycompress/tinycompress.h> #include <tinycompress/tinycompress.h> Loading Loading @@ -261,6 +262,7 @@ struct audio_device { int (*offload_effects_stop_output)(audio_io_handle_t, int); int (*offload_effects_stop_output)(audio_io_handle_t, int); struct sound_card_status snd_card_status; struct sound_card_status snd_card_status; amplifier_device_t *amp; }; }; int select_devices(struct audio_device *adev, int select_devices(struct audio_device *adev, Loading Loading
hal/Android.mk +2 −6 Original line number Original line Diff line number Diff line Loading @@ -131,22 +131,18 @@ endif LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \ liblog \ liblog \ libcutils \ libcutils \ libhardware \ libtinyalsa \ libtinyalsa \ libtinycompress \ libtinycompress \ libaudioroute \ libaudioroute \ libdl \ libdl \ libexpat libexpat ifneq ($(BOARD_AUDIO_AMPLIFIER),) LOCAL_CFLAGS += -DUSES_AUDIO_AMPLIFIER LOCAL_SHARED_LIBRARIES += libaudioamp LOCAL_C_INCLUDES += $(BOARD_AUDIO_AMPLIFIER) endif LOCAL_C_INCLUDES += \ LOCAL_C_INCLUDES += \ external/tinyalsa/include \ external/tinyalsa/include \ external/tinycompress/include \ external/tinycompress/include \ external/expat/lib \ external/expat/lib \ hardware/libhardware/include \ $(call include-path-for, audio-route) \ $(call include-path-for, audio-route) \ $(call include-path-for, audio-effects) \ $(call include-path-for, audio-effects) \ $(LOCAL_PATH)/$(AUDIO_PLATFORM) \ $(LOCAL_PATH)/$(AUDIO_PLATFORM) \ Loading
hal/audio_hw.c +126 −15 Original line number Original line Diff line number Diff line Loading @@ -55,10 +55,6 @@ #include "sound/compress_params.h" #include "sound/compress_params.h" #include "sound/asound.h" #include "sound/asound.h" #ifdef USES_AUDIO_AMPLIFIER #include <audio_amplifier.h> #endif #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4 #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4 /* ToDo: Check and update a proper value in msec */ /* ToDo: Check and update a proper value in msec */ #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 96 #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 96 Loading Loading @@ -205,6 +201,116 @@ static unsigned int audio_device_ref_count; static int set_voice_volume_l(struct audio_device *adev, float volume); 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) { static int check_and_set_gapless_mode(struct audio_device *adev) { Loading Loading @@ -817,12 +923,9 @@ int select_devices(struct audio_device *adev, audio_usecase_t uc_id) enable_audio_route(adev, usecase); enable_audio_route(adev, usecase); #ifdef USES_AUDIO_AMPLIFIER /* Rely on amplifier_set_devices to distinguish between in/out devices */ /* Rely on amplifier_set_devices to distinguish between in/out devices */ amplifier_set_devices(in_snd_device); amplifier_set_input_devices(in_snd_device); amplifier_set_devices(out_snd_device); amplifier_set_output_devices(out_snd_device); #endif /* Applicable only on the targets that has external modem. /* Applicable only on the targets that has external modem. * Enable device command should be sent to modem only after * Enable device command should be sent to modem only after Loading Loading @@ -1514,6 +1617,9 @@ static int out_standby(struct audio_stream *stream) lock_output_stream(out); lock_output_stream(out); if (!out->standby) { if (!out->standby) { pthread_mutex_lock(&adev->lock); pthread_mutex_lock(&adev->lock); amplifier_output_stream_standby((struct audio_stream_out *) stream); out->standby = true; out->standby = true; if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) { if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) { if (out->pcm) { if (out->pcm) { Loading Loading @@ -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); ret = voice_extn_compress_voip_start_output_stream(out); else else ret = start_output_stream(out); ret = start_output_stream(out); if (ret == 0) amplifier_output_stream_start(stream, false); pthread_mutex_unlock(&adev->lock); pthread_mutex_unlock(&adev->lock); /* ToDo: If use case is compress offload should return 0 */ /* ToDo: If use case is compress offload should return 0 */ if (ret != 0) { if (ret != 0) { Loading Loading @@ -2151,6 +2261,9 @@ static int in_standby(struct audio_stream *stream) lock_input_stream(in); lock_input_stream(in); if (!in->standby) { if (!in->standby) { pthread_mutex_lock(&adev->lock); pthread_mutex_lock(&adev->lock); amplifier_input_stream_standby((struct audio_stream_in *) stream); in->standby = true; in->standby = true; if (in->pcm) { if (in->pcm) { pcm_close(in->pcm); pcm_close(in->pcm); Loading Loading @@ -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); ret = voice_extn_compress_voip_start_input_stream(in); else else ret = start_input_stream(in); ret = start_input_stream(in); if (ret == 0) amplifier_input_stream_start(stream); pthread_mutex_unlock(&adev->lock); pthread_mutex_unlock(&adev->lock); if (ret != 0) { if (ret != 0) { goto exit; goto exit; Loading Loading @@ -2911,10 +3028,8 @@ static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) pthread_mutex_lock(&adev->lock); pthread_mutex_lock(&adev->lock); if (adev->mode != mode) { if (adev->mode != mode) { ALOGD("%s mode %d\n", __func__, mode); ALOGD("%s mode %d\n", __func__, mode); #ifdef USES_AUDIO_AMPLIFIER if (amplifier_set_mode(mode) != 0) if (amplifier_set_mode(mode) != 0) ALOGE("Failed setting amplifier mode"); ALOGE("Failed setting amplifier mode"); #endif adev->mode = mode; adev->mode = mode; } } pthread_mutex_unlock(&adev->lock); pthread_mutex_unlock(&adev->lock); Loading Loading @@ -3128,10 +3243,8 @@ static int adev_close(hw_device_t *device) pthread_mutex_lock(&adev_init_lock); pthread_mutex_lock(&adev_init_lock); if ((--audio_device_ref_count) == 0) { if ((--audio_device_ref_count) == 0) { #ifdef USES_AUDIO_AMPLIFIER if (amplifier_close() != 0) if (amplifier_close() != 0) ALOGE("Amplifier close failed"); ALOGE("Amplifier close failed"); #endif audio_extn_listen_deinit(adev); audio_extn_listen_deinit(adev); audio_route_free(adev->audio_route); audio_route_free(adev->audio_route); free(adev->snd_dev_ref_cnt); free(adev->snd_dev_ref_cnt); Loading Loading @@ -3274,10 +3387,8 @@ static int adev_open(const hw_module_t *module, const char *name, *device = &adev->device.common; *device = &adev->device.common; #ifdef USES_AUDIO_AMPLIFIER if (amplifier_open() != 0) if (amplifier_open() != 0) ALOGE("Amplifier initialization failed"); ALOGE("Amplifier initialization failed"); #endif audio_device_ref_count++; audio_device_ref_count++; Loading
hal/audio_hw.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <stdlib.h> #include <stdlib.h> #include <cutils/list.h> #include <cutils/list.h> #include <hardware/audio.h> #include <hardware/audio.h> #include <hardware/audio_amplifier.h> #include <tinyalsa/asoundlib.h> #include <tinyalsa/asoundlib.h> #include <tinycompress/tinycompress.h> #include <tinycompress/tinycompress.h> Loading Loading @@ -261,6 +262,7 @@ struct audio_device { int (*offload_effects_stop_output)(audio_io_handle_t, int); int (*offload_effects_stop_output)(audio_io_handle_t, int); struct sound_card_status snd_card_status; struct sound_card_status snd_card_status; amplifier_device_t *amp; }; }; int select_devices(struct audio_device *adev, int select_devices(struct audio_device *adev, Loading