audio: Re-worked sound pre- and post-processing
authorBasil Gello <vasek.gello@gmail.com>
Mon, 21 May 2018 15:29:12 +0000 (18:29 +0300)
committerJan Altensen <info@stricted.net>
Tue, 5 Feb 2019 18:55:06 +0000 (19:55 +0100)
In order to activate proprietary sound pre- and post-processing,
the following parts of audio HAL were revised:

* Activated ENABLE_PREPROCESSING directive in Android.mk
* Removed unused variables and functions
* Re-written set_preprocessor_echo_delay() function

Change-Id: I868087f422764895df7d2bc6bbf4bbd76672b8e7

audio/Android.mk
audio/audio_hw.c
audio/compress_offload.c

index f369f7cd98acd56bc148959d6d7dba6fda614861..64ada4852d7152a48f5076e02f7bb0734e578952 100644 (file)
@@ -51,7 +51,7 @@ LOCAL_C_INCLUDES += \
        $(call include-path-for, audio-effects)
 
 LOCAL_CFLAGS := -Werror -Wall
-#LOCAL_CFLAGS += -DPREPROCESSING_ENABLED
+LOCAL_CFLAGS += -DPREPROCESSING_ENABLED
 
 LOCAL_MODULE := audio.primary.$(TARGET_BOOTLOADER_BOARD_NAME)
 
index 04955d6777e736cce5e984afc95c938db741d1bd..9413297a87e96d50364452e41268dc4c8b09a27d 100644 (file)
@@ -1144,46 +1144,6 @@ static ssize_t read_frames(struct stream_in *in, void *buffer, ssize_t frames);
 static int do_in_standby_l(struct stream_in *in);
 
 #ifdef PREPROCESSING_ENABLED
-static void get_capture_reference_delay(struct stream_in *in,
-                              size_t frames __unused,
-                              struct echo_reference_buffer *buffer)
-{
-    ALOGVV("%s: enter:)", __func__);
-
-    /* read frames available in kernel driver buffer */
-    unsigned int kernel_frames;
-    struct timespec tstamp;
-    long buf_delay;
-    long kernel_delay;
-    long delay_ns;
-    struct pcm_device *ref_device;
-    long rsmp_delay = 0;
-
-    ref_device = node_to_item(list_tail(&in->pcm_dev_list),
-                              struct pcm_device, stream_list_node);
-
-    if (pcm_get_htimestamp(ref_device->pcm, &kernel_frames, &tstamp) < 0) {
-        buffer->time_stamp.tv_sec  = 0;
-        buffer->time_stamp.tv_nsec = 0;
-        buffer->delay_ns           = 0;
-        ALOGW("read get_capture_reference_delay(): pcm_htimestamp error");
-        return;
-    }
-
-    /* adjust render time stamp with delay added by current driver buffer.
-    * Add the duration of current frame as we want the render time of the last
-    * sample being written. */
-
-    kernel_delay = (long)(((int64_t)kernel_frames * 1000000000) / ref_device->pcm_profile->config.rate);
-
-    buffer->time_stamp = tstamp;
-    buffer->delay_ns = kernel_delay;
-
-    ALOGVV("get_capture_reference_delay_time_stamp Secs: [%10ld], nSecs: [%9ld], kernel_frames: [%5d],"
-          " delay_ns: [%d] , frames:[%zd]",
-           buffer->time_stamp.tv_sec , buffer->time_stamp.tv_nsec, kernel_frames, buffer->delay_ns, frames);
-}
-
 static void get_capture_delay(struct stream_in *in,
                               size_t frames __unused,
                               struct echo_reference_buffer *buffer)
@@ -1280,12 +1240,13 @@ static int set_preprocessor_param(effect_handle_t handle,
                            effect_param_t *param)
 {
     uint32_t size = sizeof(int);
-    uint32_t psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) +
-                        param->vsize;
+    uint32_t bufsize = sizeof(effect_param_t) +
+        ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) +
+        param->vsize;
 
     int status = (*handle)->command(handle,
                                    EFFECT_CMD_SET_PARAM,
-                                   sizeof (effect_param_t) + psize,
+                                   bufsize,
                                    param,
                                    &size,
                                    &param->status);
@@ -1298,19 +1259,27 @@ static int set_preprocessor_param(effect_handle_t handle,
 static int set_preprocessor_echo_delay(effect_handle_t handle,
                                      int32_t delay_us)
 {
-    struct {
-        effect_param_t  param;
-        uint32_t        data_0;
-        int32_t         data_1;
-    } buf;
-    memset(&buf, 0, sizeof(buf));
+    const uint32_t param_size = sizeof(uint32_t);
+    const uint32_t value_size = sizeof(uint32_t);
+
+    const uint32_t param_padded_size =
+        ((param_size - 1) / sizeof(int) + 1) * sizeof(int);
+
+    const uint32_t bufsize = sizeof(effect_param_t) +
+        param_padded_size + value_size;
+
+    uint8_t buf[bufsize];
+    memset(&buf, 0, bufsize);
+
+    effect_param_t *effect_param = (effect_param_t *)&buf;
+
+    effect_param->psize = param_size;
+    effect_param->vsize = value_size;
 
-    buf.param.psize = sizeof(uint32_t);
-    buf.param.vsize = sizeof(uint32_t);
-    buf.data_0 = AEC_PARAM_ECHO_DELAY;
-    buf.data_1 = delay_us;
+    *(uint32_t *)&buf[sizeof(effect_param_t)] = AEC_PARAM_ECHO_DELAY;
+    *(int32_t *)&buf[sizeof(effect_param_t) + param_padded_size] = delay_us;
 
-    return set_preprocessor_param(handle, &buf.param);
+    return set_preprocessor_param(handle, effect_param);
 }
 
 static void push_echo_reference(struct stream_in *in, size_t frames)
@@ -1320,7 +1289,6 @@ static void push_echo_reference(struct stream_in *in, size_t frames)
      * in->ref_buf_frames is updated with frames available in in->ref_buf */
 
     int32_t delay_us = update_echo_reference(in, frames)/1000;
-    int32_t size_in_bytes = 0;
     int i;
     audio_buffer_t buf;
 
@@ -1413,7 +1381,6 @@ static int get_playback_delay(struct stream_out *out,
 {
     unsigned int kernel_frames;
     int status;
-    int primary_pcm = 0;
     struct pcm_device *pcm_device;
 
     pcm_device = node_to_item(list_head(&out->pcm_dev_list),
index 5ce865eb106c804df105a5592a2c7b36ebd4f512..fccc7db49df6adeb8e2d8ccdfab6080f43a0fa34 100644 (file)
@@ -291,12 +291,6 @@ ssize_t out_write_offload(struct audio_stream_out *stream, const void *buffer,
         out->offload_state = OFFLOAD_STATE_PLAYING;
     }
     pthread_mutex_unlock(&out->lock);
-#ifdef PREPROCESSING_ENABLED
-    if (in) {
-        /* This mutex was left locked iff in != NULL */
-        pthread_mutex_unlock(&adev->lock_inputs);
-    }
-#endif
 
     return ret;
 }