audio: hal: Use the elapsed time only if last_write_time_us is valid am: 3927e17c7c am: 7175625057
am: 1d2aa02da6
Change-Id: I57ec98a68d0124196e5a6210a7698bb26f63531b
diff --git a/hal/Android.mk b/hal/Android.mk
index f3d2798..c2801db 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -152,6 +152,8 @@
LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS += -Werror
+
include $(BUILD_SHARED_LIBRARY)
endif
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 0a5bccb..98821d2 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2200,39 +2200,18 @@
#ifdef NO_AUDIO_OUT
static ssize_t out_write_for_no_output(struct audio_stream_out *stream,
- const void *buffer, size_t bytes)
+ const void *buffer __unused, size_t bytes)
{
struct stream_out *out = (struct stream_out *)stream;
- struct timespec t = { .tv_sec = 0, .tv_nsec = 0 };
- int64_t now;
- int64_t elapsed_time_since_last_write = 0;
- int64_t sleep_time;
- clock_gettime(CLOCK_MONOTONIC, &t);
- now = (t.tv_sec * 1000000000LL + t.tv_nsec) / 1000;
-
+ /* No Output device supported other than BT for playback.
+ * Sleep for the amount of buffer duration
+ */
lock_output_stream(out);
- if (out->last_write_time_us)
- elapsed_time_since_last_write = now - out->last_write_time_us;
- sleep_time = bytes * 1000000LL / audio_stream_out_frame_size(stream) /
- out_get_sample_rate(&stream->common) - elapsed_time_since_last_write;
- if (sleep_time > 0) {
- usleep(sleep_time);
- } else {
- // we don't sleep when we exit standby (this is typical for a real alsa buffer).
- sleep_time = 0;
- }
- out->last_write_time_us = now + sleep_time;
+ usleep(bytes * 1000000 / audio_stream_out_frame_size(
+ (const struct audio_stream_out *)&out->stream) /
+ out_get_sample_rate(&out->stream.common));
pthread_mutex_unlock(&out->lock);
- // last_write_time_us is an approximation of when the (simulated) alsa
- // buffer is believed completely full. The usleep above waits for more space
- // in the buffer, but by the end of the sleep the buffer is considered
- // topped-off.
- //
- // On the subsequent out_write(), we measure the elapsed time spent in
- // the mixer. This is subtracted from the sleep estimate based on frames,
- // thereby accounting for drain in the alsa buffer during mixing.
- // This is a crude approximation; we don't handle underruns precisely.
return bytes;
}
#endif
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 2cf72e1..798d954 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -210,8 +210,6 @@
card_status_t card_status;
struct error_log error_log;
-
- int64_t last_write_time_us;
};
struct stream_in {
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 4995bd8..f7953cc 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -969,7 +969,7 @@
ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
__func__, LIB_ACDB_LOADER);
- my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
+ my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
"acdb_loader_send_audio_cal_v3");
if (!my_data->acdb_send_audio_cal_v3)
ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
@@ -1073,7 +1073,7 @@
{
struct platform_data *my_data = (struct platform_data *)platform;
- if (platform == NULL || device_name == NULL) {
+ if (platform == NULL) {
ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
strlcpy(device_name, platform_get_snd_device_name(snd_device),
DEVICE_NAME_MAX_SIZE);
@@ -1095,7 +1095,7 @@
bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev __unused,
struct audio_usecase *usecase __unused,
- snd_device_t snd_device)
+ snd_device_t snd_device __unused)
{
return false;
}
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index 7b76df3..eafb64a 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -1099,7 +1099,8 @@
snd_device_t snd_device,
char *device_name)
{
- device_name = platform_get_snd_device_name(snd_device);
+ strlcpy(device_name, platform_get_snd_device_name(snd_device),
+ DEVICE_NAME_MAX_SIZE);
return 0;
}
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 9d4abec..26d78c1 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1366,9 +1366,10 @@
{
struct platform_data *my_data = (struct platform_data *)platform;
- if (platform == NULL || device_name == NULL) {
+ if (platform == NULL) {
ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
- device_name = platform_get_snd_device_name(snd_device);
+ strlcpy(device_name, platform_get_snd_device_name(snd_device),
+ DEVICE_NAME_MAX_SIZE);
} else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
if (operator_specific_device_table[snd_device] != NULL) {
strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
@@ -1527,8 +1528,8 @@
return ret;
}
-int platform_get_default_app_type_v2(void *platform, usecase_type_t type __unused,
- int *app_type)
+int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
+ int *app_type __unused)
{
ALOGE("%s: Not implemented", __func__);
return -ENOSYS;
@@ -2160,10 +2161,10 @@
} else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
(my_data->source_mic_type & SOURCE_DUAL_MIC)) {
snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
- } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
+ } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
(my_data->source_mic_type & SOURCE_THREE_MIC)) {
snd_device = SND_DEVICE_IN_THREE_MIC;
- } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
+ } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
(my_data->source_mic_type & SOURCE_QUAD_MIC)) {
snd_device = SND_DEVICE_IN_QUAD_MIC;
}
@@ -2190,10 +2191,10 @@
(channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
(my_data->source_mic_type & SOURCE_DUAL_MIC)) {
snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
- } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
+ } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
(my_data->source_mic_type & SOURCE_THREE_MIC)) {
snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
- } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
+ } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
(my_data->source_mic_type & SOURCE_QUAD_MIC)) {
snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
} else {
@@ -2281,10 +2282,10 @@
!(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
- (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
+ channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
snd_device = SND_DEVICE_IN_QUAD_MIC;
} else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
- (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
+ channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
snd_device = SND_DEVICE_IN_THREE_MIC;
} else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
channel_count == 2) {
@@ -2626,7 +2627,8 @@
}
bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
- struct audio_usecase *usecase, snd_device_t snd_device)
+ struct audio_usecase *usecase __unused,
+ snd_device_t snd_device __unused)
{
enum pcm_format in_pcm_format = PCM_FORMAT_S16_LE;
diff --git a/hal/platform_api.h b/hal/platform_api.h
index ebbe9d2..83554b0 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -28,6 +28,7 @@
};
enum card_status_t;
+struct audio_usecase;
enum usecase_type_t;
void *platform_init(struct audio_device *adev);
diff --git a/post_proc/bundle.c b/post_proc/bundle.c
index df327ab..73b9ae5 100644
--- a/post_proc/bundle.c
+++ b/post_proc/bundle.c
@@ -244,7 +244,7 @@
__attribute__ ((visibility ("default")))
int offload_effects_bundle_hal_stop_output(audio_io_handle_t output, int pcm_id)
{
- int ret;
+ int ret = 0;
struct listnode *node;
struct listnode *fx_node;
output_context_t *out_ctxt;
@@ -750,11 +750,11 @@
__attribute__ ((visibility ("default")))
audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
- tag : AUDIO_EFFECT_LIBRARY_TAG,
- version : EFFECT_LIBRARY_API_VERSION,
- name : "Offload Effects Bundle Library",
- implementor : "The Android Open Source Project",
- create_effect : effect_lib_create,
- release_effect : effect_lib_release,
- get_descriptor : effect_lib_get_descriptor,
+ .tag = AUDIO_EFFECT_LIBRARY_TAG,
+ .version = EFFECT_LIBRARY_API_VERSION,
+ .name = "Offload Effects Bundle Library",
+ .implementor = "The Android Open Source Project",
+ .create_effect = effect_lib_create,
+ .release_effect = effect_lib_release,
+ .get_descriptor = effect_lib_get_descriptor,
};
diff --git a/post_proc/equalizer.c b/post_proc/equalizer.c
index 1cd40d2..c3a438f 100644
--- a/post_proc/equalizer.c
+++ b/post_proc/equalizer.c
@@ -183,7 +183,7 @@
int equalizer_get_num_presets(equalizer_context_t *context __unused)
{
- ALOGV("%s: presets_num: %d", __func__,
+ ALOGV("%s: presets_num: %zu", __func__,
sizeof(equalizer_preset_names)/sizeof(char *));
return sizeof(equalizer_preset_names)/sizeof(char *);
}
diff --git a/post_proc/volume_listener.c b/post_proc/volume_listener.c
index 4a48a25..2858e04 100644
--- a/post_proc/volume_listener.c
+++ b/post_proc/volume_listener.c
@@ -18,6 +18,7 @@
//#define LOG_NDEBUG 0
#include <stdlib.h>
#include <dlfcn.h>
+#include <math.h>
#include <cutils/list.h>
#include <cutils/log.h>
@@ -229,7 +230,7 @@
{
// iterate through list and make decision to set new gain dep cal level for speaker device
// 1. find all usecase active on speaker
- // 2. find average of left and right for each usecase
+ // 2. find energy sum for each usecase
// 3. find the highest of all the active usecase
// 4. if new value is different than the current value then load new calibration
@@ -243,15 +244,22 @@
ALOGV("%s ==> Start ...", __func__);
- // select the highest volume on speaker device
+ float sum_energy = 0.0;
+ bool sum_energy_used = false;
+ float temp_vol = 0;
+ // compute energy sum for the active speaker device (pick loudest of both channels)
list_for_each(node, &vol_effect_list) {
context = node_to_item(node, struct vol_listener_context_s, effect_list_node);
if ((context->state == VOL_LISTENER_STATE_ACTIVE) &&
- (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER) &&
- (new_vol < (context->left_vol + context->right_vol) / 2)) {
- new_vol = (context->left_vol + context->right_vol) / 2;
+ (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER)) {
+ sum_energy_used = true;
+ temp_vol = fmax(context->left_vol, context->right_vol);
+ sum_energy += temp_vol * temp_vol;
}
}
+ if (sum_energy_used) {
+ new_vol = fmin(sqrt(sum_energy), 1.0);
+ }
if (new_vol != current_vol) {
ALOGV("%s:: Change in decision :: current volume is %f new volume is %f",
@@ -358,7 +366,9 @@
ALOGE("%s: EFFECT_CMD_INIT: %s, sending -EINVAL", __func__,
(p_reply_data == NULL) ? "p_reply_data is NULL" :
"*reply_size != sizeof(int)");
- return -EINVAL;
+ android_errorWriteLog(0x534e4554, "32669549");
+ status = -EINVAL;
+ goto exit;
}
*(int *)p_reply_data = 0;
break;
@@ -367,7 +377,9 @@
ALOGV("%s :: cmd called EFFECT_CMD_SET_CONFIG", __func__);
if (p_cmd_data == NULL || cmd_size != sizeof(effect_config_t)
|| p_reply_data == NULL || reply_size == NULL || *reply_size != sizeof(int)) {
- return -EINVAL;
+ android_errorWriteLog(0x534e4554, "32669549");
+ status = -EINVAL;
+ goto exit;
}
context->config = *(effect_config_t *)p_cmd_data;
*(int *)p_reply_data = 0;
@@ -391,7 +403,9 @@
ALOGE("%s: EFFECT_CMD_OFFLOAD: %s, sending -EINVAL", __func__,
(p_reply_data == NULL) ? "p_reply_data is NULL" :
"*reply_size != sizeof(int)");
- return -EINVAL;
+ android_errorWriteLog(0x534e4554, "32669549");
+ status = -EINVAL;
+ goto exit;
}
*(int *)p_reply_data = 0;
break;
diff --git a/visualizer/offload_visualizer.c b/visualizer/offload_visualizer.c
index c56ebff..4d1373f 100644
--- a/visualizer/offload_visualizer.c
+++ b/visualizer/offload_visualizer.c
@@ -81,11 +81,11 @@
effect_ops_t ops;
};
-typedef struct output_context_s {
+struct output_context_s {
struct listnode outputs_list_node; /* node in active_outputs_list */
audio_io_handle_t handle; /* io handle */
struct listnode effects_list; /* list of effects attached to this output */
-} output_context_t;
+};
/* maximum time since last capture buffer update before resetting capture buffer. This means
@@ -427,7 +427,7 @@
__attribute__ ((visibility ("default")))
int visualizer_hal_start_output(audio_io_handle_t output, int pcm_id) {
- int ret;
+ int ret = 0;
struct listnode *node;
ALOGV("%s output %d pcm_id %d", __func__, output, pcm_id);
@@ -473,7 +473,7 @@
__attribute__ ((visibility ("default")))
int visualizer_hal_stop_output(audio_io_handle_t output, int pcm_id) {
- int ret;
+ int ret = 0;
struct listnode *node;
struct listnode *fx_node;
output_context_t *out_ctxt;