Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 1 | /* |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved. |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 3 | * Not a Contribution. |
| 4 | * |
| 5 | * Copyright (C) 2013 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
| 20 | #define LOG_TAG "audio_hw_ssr" |
| 21 | /*#define LOG_NDEBUG 0*/ |
| 22 | #define LOG_NDDEBUG 0 |
| 23 | |
| 24 | #include <errno.h> |
| 25 | #include <cutils/properties.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <dlfcn.h> |
| 28 | #include <cutils/str_parms.h> |
| 29 | #include <cutils/log.h> |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 30 | #include <pthread.h> |
| 31 | #include <cutils/sched_policy.h> |
| 32 | #include <sys/resource.h> |
| 33 | #include <system/thread_defs.h> |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 34 | |
| 35 | #include "audio_hw.h" |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 36 | #include "audio_extn.h" |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 37 | #include "platform.h" |
| 38 | #include "platform_api.h" |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 39 | #include "surround_rec_interface.h" |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 40 | |
| 41 | #ifdef SSR_ENABLED |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 42 | #define COEFF_ARRAY_SIZE 4 |
| 43 | #define FILT_SIZE ((512+1)* 6) /* # ((FFT bins)/2+1)*numOutputs */ |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 44 | #define SSR_CHANNEL_OUTPUT_NUM 6 |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 45 | #define SSR_PERIOD_SIZE 240 |
| 46 | |
| 47 | #define NUM_IN_BUFS 4 |
| 48 | #define NUM_OUT_BUFS 4 |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 49 | #define NUM_IN_CHANNELS 3 |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 50 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 51 | #define LIB_SURROUND_3MIC_PROC "libsurround_3mic_proc.so" |
| 52 | #define LIB_DRC "libdrc.so" |
| 53 | |
| 54 | #define AUDIO_PARAMETER_SSRMODE_ON "ssrOn" |
| 55 | |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 56 | |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 57 | typedef short Word16; |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 58 | typedef const get_param_data_t* (*surround_rec_get_get_param_data_t)(void); |
| 59 | typedef const set_param_data_t* (*surround_rec_get_set_param_data_t)(void); |
| 60 | typedef int (*surround_rec_init_t)(void **, int, int, int, int, const char *); |
| 61 | typedef void (*surround_rec_deinit_t)(void *); |
| 62 | typedef void (*surround_rec_process_t)(void *, const int16_t *, int16_t *); |
| 63 | |
| 64 | typedef int (*drc_init_t)(void **, int, int, const char *); |
| 65 | typedef void (*drc_deinit_t)(void *); |
| 66 | typedef int (*drc_process_t)(void *, const int16_t *, int16_t *); |
| 67 | |
| 68 | struct pcm_buffer { |
| 69 | void *data; |
| 70 | int length; |
| 71 | }; |
| 72 | |
| 73 | struct pcm_buffer_queue { |
| 74 | struct pcm_buffer_queue *next; |
| 75 | struct pcm_buffer buffer; |
| 76 | }; |
| 77 | |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 78 | struct ssr_module { |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 79 | int ssr_3mic; |
| 80 | int num_out_chan; |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 81 | FILE *fp_input; |
| 82 | FILE *fp_output; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 83 | void *surround_obj; |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 84 | Word16 *surround_raw_buffer; |
| 85 | int surround_raw_buffer_size; |
| 86 | bool is_ssr_enabled; |
| 87 | struct stream_in *in; |
| 88 | void *drc_obj; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 89 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 90 | |
| 91 | void *surround_rec_handle; |
| 92 | surround_rec_get_get_param_data_t surround_rec_get_get_param_data; |
| 93 | surround_rec_get_set_param_data_t surround_rec_get_set_param_data; |
| 94 | surround_rec_init_t surround_rec_init; |
| 95 | surround_rec_deinit_t surround_rec_deinit; |
| 96 | surround_rec_process_t surround_rec_process; |
| 97 | |
| 98 | void *drc_handle; |
| 99 | drc_init_t drc_init; |
| 100 | drc_deinit_t drc_deinit; |
| 101 | drc_process_t drc_process; |
| 102 | |
| 103 | pthread_t ssr_process_thread; |
| 104 | bool ssr_process_thread_started; |
| 105 | bool ssr_process_thread_stop; |
| 106 | struct pcm_buffer_queue in_buf_nodes[NUM_IN_BUFS]; |
| 107 | struct pcm_buffer_queue out_buf_nodes[NUM_OUT_BUFS]; |
| 108 | void *in_buf_data; |
| 109 | void *out_buf_data; |
| 110 | struct pcm_buffer_queue *out_buf_free; |
| 111 | struct pcm_buffer_queue *out_buf; |
| 112 | struct pcm_buffer_queue *in_buf_free; |
| 113 | struct pcm_buffer_queue *in_buf; |
| 114 | pthread_mutex_t ssr_process_lock; |
| 115 | pthread_cond_t cond_process; |
| 116 | pthread_cond_t cond_read; |
| 117 | bool is_ssr_mode_on; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 120 | static struct ssr_module ssrmod = { |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 121 | .fp_input = NULL, |
| 122 | .fp_output = NULL, |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 123 | .surround_obj = NULL, |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 124 | .surround_raw_buffer = NULL, |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 125 | .surround_raw_buffer_size = 0, |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 126 | .is_ssr_enabled = 0, |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 127 | .in = NULL, |
| 128 | .drc_obj = NULL, |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 129 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 130 | .surround_rec_handle = NULL, |
| 131 | .surround_rec_get_get_param_data = NULL, |
| 132 | .surround_rec_get_set_param_data = NULL, |
| 133 | .surround_rec_init = NULL, |
| 134 | .surround_rec_deinit = NULL, |
| 135 | .surround_rec_process = NULL, |
| 136 | |
| 137 | .drc_handle = NULL, |
| 138 | .drc_init = NULL, |
| 139 | .drc_deinit = NULL, |
| 140 | .drc_process = NULL, |
| 141 | |
| 142 | .ssr_process_thread_stop = 0, |
| 143 | .ssr_process_thread_started = 0, |
| 144 | .in_buf_data = NULL, |
| 145 | .out_buf_data = NULL, |
| 146 | .out_buf_free = NULL, |
| 147 | .out_buf = NULL, |
| 148 | .in_buf_free = NULL, |
| 149 | .in_buf = NULL, |
| 150 | .cond_process = PTHREAD_COND_INITIALIZER, |
| 151 | .cond_read = PTHREAD_COND_INITIALIZER, |
| 152 | .ssr_process_lock = PTHREAD_MUTEX_INITIALIZER, |
| 153 | .is_ssr_mode_on = false, |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 156 | static void *ssr_process_thread(void *context); |
| 157 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 158 | static int32_t drc_init_lib(int num_chan, int sample_rate __unused) |
| 159 | { |
| 160 | int ret = 0; |
| 161 | const char *cfgFileName = ""; |
| 162 | |
| 163 | if (ssrmod.drc_obj) { |
| 164 | ALOGE("%s: DRC library is already initialized", __func__); |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | ssrmod.drc_handle = dlopen(LIB_DRC, RTLD_NOW); |
| 169 | if (ssrmod.drc_handle == NULL) { |
| 170 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_DRC); |
| 171 | ret = -ENOSYS; |
| 172 | goto init_fail; |
| 173 | } |
| 174 | |
| 175 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_DRC); |
| 176 | ssrmod.drc_init = (drc_init_t) |
| 177 | dlsym(ssrmod.drc_handle, "DRC_init"); |
| 178 | ssrmod.drc_deinit = (drc_deinit_t) |
| 179 | dlsym(ssrmod.drc_handle, "DRC_deinit"); |
| 180 | ssrmod.drc_process = (drc_process_t) |
| 181 | dlsym(ssrmod.drc_handle, "DRC_process"); |
| 182 | |
| 183 | if (!ssrmod.drc_init || |
| 184 | !ssrmod.drc_deinit || |
| 185 | !ssrmod.drc_process){ |
| 186 | ALOGW("%s: Could not find one of the symbols from %s", |
| 187 | __func__, LIB_DRC); |
| 188 | ret = -ENOSYS; |
| 189 | goto init_fail; |
| 190 | } |
| 191 | |
| 192 | /* TO DO: different config files for different sample rates */ |
| 193 | if (num_chan == 6) { |
| 194 | cfgFileName = "/system/etc/drc/drc_cfg_5.1.txt"; |
| 195 | } else if (num_chan == 2) { |
| 196 | cfgFileName = "/system/etc/drc/drc_cfg_AZ.txt"; |
| 197 | } |
| 198 | |
| 199 | ALOGV("%s: Calling drc_init: num ch: %d, period: %d, cfg file: %s", __func__, num_chan, SSR_PERIOD_SIZE, cfgFileName); |
| 200 | ret = ssrmod.drc_init(&ssrmod.drc_obj, num_chan, SSR_PERIOD_SIZE, cfgFileName); |
| 201 | if (ret) { |
| 202 | ALOGE("drc_init failed with ret:%d",ret); |
| 203 | ret = -EINVAL; |
| 204 | goto init_fail; |
| 205 | } |
| 206 | |
| 207 | return 0; |
| 208 | |
| 209 | init_fail: |
| 210 | if (ssrmod.drc_obj) { |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 211 | ssrmod.drc_obj = NULL; |
| 212 | } |
| 213 | if(ssrmod.drc_handle) { |
| 214 | dlclose(ssrmod.drc_handle); |
| 215 | ssrmod.drc_handle = NULL; |
| 216 | } |
| 217 | return ret; |
| 218 | } |
| 219 | |
| 220 | static int32_t ssr_init_surround_sound_3mic_lib(unsigned long buffersize, int num_in_chan, int num_out_chan, int sample_rate) |
| 221 | { |
| 222 | int ret = 0; |
| 223 | const char *cfgFileName = NULL; |
| 224 | |
| 225 | if ( ssrmod.surround_obj ) { |
| 226 | ALOGE("%s: surround sound library is already initialized", __func__); |
| 227 | return 0; |
| 228 | } |
| 229 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 230 | ssrmod.surround_rec_handle = dlopen(LIB_SURROUND_3MIC_PROC, RTLD_NOW); |
| 231 | if (ssrmod.surround_rec_handle == NULL) { |
| 232 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_SURROUND_3MIC_PROC); |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 233 | goto init_fail; |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 234 | } else { |
| 235 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_SURROUND_3MIC_PROC); |
| 236 | ssrmod.surround_rec_get_get_param_data = (surround_rec_get_get_param_data_t) |
| 237 | dlsym(ssrmod.surround_rec_handle, "surround_rec_get_get_param_data"); |
| 238 | |
| 239 | ssrmod.surround_rec_get_set_param_data = (surround_rec_get_set_param_data_t) |
| 240 | dlsym(ssrmod.surround_rec_handle, "surround_rec_get_set_param_data"); |
| 241 | ssrmod.surround_rec_init = (surround_rec_init_t) |
| 242 | dlsym(ssrmod.surround_rec_handle, "surround_rec_init"); |
| 243 | ssrmod.surround_rec_deinit = (surround_rec_deinit_t) |
| 244 | dlsym(ssrmod.surround_rec_handle, "surround_rec_deinit"); |
| 245 | ssrmod.surround_rec_process = (surround_rec_process_t) |
| 246 | dlsym(ssrmod.surround_rec_handle, "surround_rec_process"); |
| 247 | |
| 248 | if (!ssrmod.surround_rec_get_get_param_data || |
| 249 | !ssrmod.surround_rec_get_set_param_data || |
| 250 | !ssrmod.surround_rec_init || |
| 251 | !ssrmod.surround_rec_deinit || |
| 252 | !ssrmod.surround_rec_process){ |
| 253 | ALOGW("%s: Could not find the one of the symbols from %s", |
| 254 | __func__, LIB_SURROUND_3MIC_PROC); |
| 255 | ret = -ENOSYS; |
| 256 | goto init_fail; |
| 257 | } |
| 258 | } |
| 259 | |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 260 | /* Allocate memory for input buffer */ |
| 261 | ssrmod.surround_raw_buffer = (Word16 *) calloc(buffersize, |
| 262 | sizeof(Word16)); |
| 263 | if (!ssrmod.surround_raw_buffer) { |
| 264 | ALOGE("%s: Memory allocation failure. Not able to allocate " |
| 265 | "memory for surroundInputBuffer", __func__); |
| 266 | ret = -ENOMEM; |
| 267 | goto init_fail; |
| 268 | } |
| 269 | |
| 270 | ssrmod.surround_raw_buffer_size = buffersize; |
| 271 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 272 | ssrmod.num_out_chan = num_out_chan; |
| 273 | |
| 274 | if (num_out_chan == 6) { |
| 275 | cfgFileName = "/system/etc/surround_sound_3mic/surround_sound_rec_5.1.cfg"; |
| 276 | } else if (num_out_chan == 2) { |
| 277 | cfgFileName = "/system/etc/surround_sound_3mic/surround_sound_rec_AZ.cfg"; |
| 278 | } else { |
| 279 | ALOGE("%s: No cfg file for num_out_chan: %d", __func__, num_out_chan); |
| 280 | } |
| 281 | |
| 282 | ALOGV("%s: Calling surround_rec_init: in ch: %d, out ch: %d, period: %d, sample rate: %d, cfg file: %s", |
| 283 | __func__, num_in_chan, num_out_chan, SSR_PERIOD_SIZE, sample_rate, cfgFileName); |
| 284 | ret = ssrmod.surround_rec_init(&ssrmod.surround_obj, |
| 285 | num_in_chan, num_out_chan, SSR_PERIOD_SIZE, sample_rate, cfgFileName); |
| 286 | if (ret) { |
| 287 | ALOGE("surround_rec_init failed with ret:%d",ret); |
| 288 | ret = -EINVAL; |
| 289 | goto init_fail; |
| 290 | } |
| 291 | |
| 292 | return 0; |
| 293 | |
| 294 | init_fail: |
| 295 | if (ssrmod.surround_obj) { |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 296 | ssrmod.surround_obj = NULL; |
| 297 | } |
| 298 | if (ssrmod.surround_raw_buffer) { |
| 299 | free(ssrmod.surround_raw_buffer); |
| 300 | ssrmod.surround_raw_buffer = NULL; |
| 301 | ssrmod.surround_raw_buffer_size = 0; |
| 302 | } |
| 303 | if(ssrmod.surround_rec_handle) { |
| 304 | dlclose(ssrmod.surround_rec_handle); |
| 305 | ssrmod.surround_rec_handle = NULL; |
| 306 | } |
| 307 | return ret; |
| 308 | } |
| 309 | |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 310 | void audio_extn_ssr_update_enabled() |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 311 | { |
| 312 | char ssr_enabled[PROPERTY_VALUE_MAX] = "false"; |
| 313 | |
| 314 | property_get("ro.qc.sdk.audio.ssr",ssr_enabled,"0"); |
| 315 | if (!strncmp("true", ssr_enabled, 4)) { |
| 316 | ALOGD("%s: surround sound recording is supported", __func__); |
| 317 | ssrmod.is_ssr_enabled = true; |
| 318 | } else { |
| 319 | ALOGD("%s: surround sound recording is not supported", __func__); |
| 320 | ssrmod.is_ssr_enabled = false; |
| 321 | } |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | bool audio_extn_ssr_get_enabled() |
| 325 | { |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 326 | ALOGV("%s: is_ssr_enabled:%d is_ssr_mode_on:%d ", __func__, ssrmod.is_ssr_enabled, ssrmod.is_ssr_mode_on); |
| 327 | |
| 328 | if(ssrmod.is_ssr_enabled && ssrmod.is_ssr_mode_on) |
| 329 | return true; |
| 330 | |
| 331 | return false; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 334 | int audio_extn_ssr_check_and_set_usecase(struct stream_in *in) |
| 335 | { |
| 336 | int ret = -1; |
| 337 | int channel_count = audio_channel_count_from_in_mask(in->channel_mask); |
| 338 | audio_devices_t devices = in->device; |
| 339 | audio_source_t source = in->source; |
| 340 | |
| 341 | /* validate input params |
| 342 | * only stereo and 5:1 channel config is supported |
| 343 | * only AUDIO_DEVICE_IN_BUILTIN_MIC, AUDIO_DEVICE_IN_BACK_MIC supports 3 mics */ |
| 344 | if (audio_extn_ssr_get_enabled() && |
| 345 | ((channel_count == 2) || (channel_count == 6)) && |
| 346 | ((AUDIO_SOURCE_MIC == source) || (AUDIO_SOURCE_CAMCORDER == source)) && |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 347 | ((AUDIO_DEVICE_IN_BUILTIN_MIC == devices) || (AUDIO_DEVICE_IN_BACK_MIC == devices)) && |
| 348 | (in->format == AUDIO_FORMAT_PCM_16_BIT)) { |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 349 | |
| 350 | ALOGD("%s: Found SSR use case starting SSR lib with channel_count :%d", |
| 351 | __func__, channel_count); |
| 352 | |
| 353 | if (!audio_extn_ssr_init(in, channel_count)) { |
| 354 | ALOGD("%s: Created SSR session succesfully", __func__); |
| 355 | ret = 0; |
| 356 | } else { |
| 357 | ALOGE("%s: Unable to start SSR record session", __func__); |
| 358 | } |
| 359 | } |
| 360 | return ret; |
| 361 | } |
| 362 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 363 | static void pcm_buffer_queue_push(struct pcm_buffer_queue **queue, |
| 364 | struct pcm_buffer_queue *node) |
| 365 | { |
| 366 | struct pcm_buffer_queue *iter; |
| 367 | |
| 368 | node->next = NULL; |
| 369 | if ((*queue) == NULL) { |
| 370 | *queue = node; |
| 371 | } else { |
| 372 | iter = *queue; |
| 373 | while (iter->next) { |
| 374 | iter = iter->next; |
| 375 | } |
| 376 | iter->next = node; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | static struct pcm_buffer_queue *pcm_buffer_queue_pop(struct pcm_buffer_queue **queue) |
| 381 | { |
| 382 | struct pcm_buffer_queue *node = (*queue); |
| 383 | if (node != NULL) { |
| 384 | *queue = node->next; |
| 385 | node->next = NULL; |
| 386 | } |
| 387 | return node; |
| 388 | } |
| 389 | |
| 390 | static void deinit_ssr_process_thread() |
| 391 | { |
| 392 | pthread_mutex_lock(&ssrmod.ssr_process_lock); |
| 393 | ssrmod.ssr_process_thread_stop = 1; |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 394 | |
| 395 | if(ssrmod.in_buf_data != NULL) |
| 396 | free(ssrmod.in_buf_data); |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 397 | ssrmod.in_buf_data = NULL; |
| 398 | ssrmod.in_buf = NULL; |
| 399 | ssrmod.in_buf_free = NULL; |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 400 | |
| 401 | if(ssrmod.out_buf_data != NULL) |
| 402 | free(ssrmod.out_buf_data); |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 403 | ssrmod.out_buf_data = NULL; |
| 404 | ssrmod.out_buf = NULL; |
| 405 | ssrmod.out_buf_free = NULL; |
| 406 | pthread_cond_broadcast(&ssrmod.cond_process); |
| 407 | pthread_cond_broadcast(&ssrmod.cond_read); |
| 408 | pthread_mutex_unlock(&ssrmod.ssr_process_lock); |
| 409 | if (ssrmod.ssr_process_thread_started) { |
| 410 | pthread_join(ssrmod.ssr_process_thread, (void **)NULL); |
| 411 | ssrmod.ssr_process_thread_started = 0; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | struct stream_in *audio_extn_ssr_get_stream() |
| 416 | { |
| 417 | return ssrmod.in; |
| 418 | } |
| 419 | |
| 420 | int32_t audio_extn_ssr_init(struct stream_in *in, int num_out_chan) |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 421 | { |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 422 | uint32_t ret = -1; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 423 | char c_multi_ch_dump[128] = {0}; |
| 424 | uint32_t buffer_size; |
| 425 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 426 | ALOGD("%s: ssr case, sample rate %d", __func__, in->config.rate); |
| 427 | |
| 428 | if (ssrmod.surround_obj != NULL) { |
| 429 | ALOGV("%s: reinitializing surround sound library", __func__); |
| 430 | audio_extn_ssr_deinit(); |
| 431 | } |
| 432 | |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 433 | if (audio_extn_ssr_get_enabled()) { |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 434 | ssrmod.ssr_3mic = 1; |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 435 | } else { |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 436 | ALOGE(" Rejecting SSR -- init is called without enabling SSR"); |
| 437 | goto fail; |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 440 | /* buffer size equals to period_size * period_count */ |
| 441 | buffer_size = SSR_PERIOD_SIZE * NUM_IN_CHANNELS * sizeof(int16_t); |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 442 | ALOGV("%s: buffer_size: %d", __func__, buffer_size); |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 443 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 444 | if (ssrmod.ssr_3mic != 0) { |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 445 | ret = ssr_init_surround_sound_3mic_lib(buffer_size, NUM_IN_CHANNELS, num_out_chan, in->config.rate); |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 446 | if (0 != ret) { |
| 447 | ALOGE("%s: ssr_init_surround_sound_3mic_lib failed: %d " |
| 448 | "buffer_size:%d", __func__, ret, buffer_size); |
| 449 | goto fail; |
| 450 | } |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 453 | /* Initialize DRC if available */ |
| 454 | ret = drc_init_lib(num_out_chan, in->config.rate); |
| 455 | if (0 != ret) { |
| 456 | ALOGE("%s: drc_init_lib failed, ret %d", __func__, ret); |
| 457 | } |
| 458 | |
| 459 | pthread_mutex_lock(&ssrmod.ssr_process_lock); |
| 460 | if (!ssrmod.ssr_process_thread_started) { |
| 461 | int i; |
| 462 | int output_buf_size = SSR_PERIOD_SIZE * sizeof(int16_t) * num_out_chan; |
| 463 | |
| 464 | ssrmod.in_buf_data = (void *)calloc(buffer_size, NUM_IN_BUFS); |
| 465 | if (ssrmod.in_buf_data == NULL) { |
| 466 | ALOGE("%s: failed to allocate input buffer", __func__); |
| 467 | pthread_mutex_unlock(&ssrmod.ssr_process_lock); |
| 468 | ret = -ENOMEM; |
| 469 | goto fail; |
| 470 | } |
| 471 | ssrmod.out_buf_data = (void *)calloc(output_buf_size, NUM_OUT_BUFS); |
| 472 | if (ssrmod.out_buf_data == NULL) { |
| 473 | ALOGE("%s: failed to allocate output buffer", __func__); |
| 474 | pthread_mutex_unlock(&ssrmod.ssr_process_lock); |
| 475 | ret = -ENOMEM; |
| 476 | // ssrmod.in_buf_data will be freed in deinit_ssr_process_thread() |
| 477 | goto fail; |
| 478 | } |
| 479 | |
| 480 | ssrmod.in_buf = NULL; |
| 481 | ssrmod.in_buf_free = NULL; |
| 482 | ssrmod.out_buf = NULL; |
| 483 | ssrmod.out_buf_free = NULL; |
| 484 | |
| 485 | for (i=0; i < NUM_IN_BUFS; i++) { |
| 486 | struct pcm_buffer_queue *buf = &ssrmod.in_buf_nodes[i]; |
| 487 | buf->buffer.data = &(((char *)ssrmod.in_buf_data)[i*buffer_size]); |
| 488 | buf->buffer.length = buffer_size; |
| 489 | pcm_buffer_queue_push(&ssrmod.in_buf_free, buf); |
| 490 | } |
| 491 | |
| 492 | for (i=0; i < NUM_OUT_BUFS; i++) { |
| 493 | struct pcm_buffer_queue *buf = &ssrmod.out_buf_nodes[i]; |
| 494 | buf->buffer.data = &(((char *)ssrmod.out_buf_data)[i*output_buf_size]); |
| 495 | buf->buffer.length = output_buf_size; |
| 496 | pcm_buffer_queue_push(&ssrmod.out_buf, buf); |
| 497 | } |
| 498 | |
| 499 | ssrmod.ssr_process_thread_stop = 0; |
| 500 | ALOGV("%s: creating thread", __func__); |
| 501 | ret = pthread_create(&ssrmod.ssr_process_thread, |
| 502 | (const pthread_attr_t *) NULL, |
| 503 | ssr_process_thread, NULL); |
| 504 | if (ret != 0) { |
| 505 | ALOGE("%s: failed to create thread for surround sound recording.", |
| 506 | __func__); |
| 507 | pthread_mutex_unlock(&ssrmod.ssr_process_lock); |
| 508 | goto fail; |
| 509 | } |
| 510 | |
| 511 | ssrmod.ssr_process_thread_started = 1; |
| 512 | ALOGV("%s: done creating thread", __func__); |
| 513 | } |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 514 | |
| 515 | in->config.channels = NUM_IN_CHANNELS; |
| 516 | in->config.period_size = SSR_PERIOD_SIZE; |
| 517 | in->config.period_count = in->config.channels * sizeof(int16_t); |
| 518 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 519 | pthread_mutex_unlock(&ssrmod.ssr_process_lock); |
| 520 | |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 521 | property_get("ssr.pcmdump",c_multi_ch_dump,"0"); |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 522 | if (0 == strncmp("true", c_multi_ch_dump, sizeof("ssr.dump-pcm"))) { |
| 523 | /* Remember to change file system permission of data(e.g. chmod 777 data/), |
| 524 | otherwise, fopen may fail */ |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 525 | if ( !ssrmod.fp_input) { |
| 526 | ALOGD("%s: Opening ssr input dump file \n", __func__); |
| 527 | ssrmod.fp_input = fopen("/data/misc/audio/ssr_input_3ch.pcm", "wb"); |
| 528 | } |
| 529 | |
| 530 | if ( !ssrmod.fp_output) { |
| 531 | if(ssrmod.num_out_chan == 6) { |
| 532 | ALOGD("%s: Opening ssr input dump file for 6 channel\n", __func__); |
| 533 | ssrmod.fp_output = fopen("/data/misc/audio/ssr_output_6ch.pcm", "wb"); |
| 534 | } else { |
| 535 | ALOGD("%s: Opening ssr input dump file for 2 channel\n", __func__); |
| 536 | ssrmod.fp_output = fopen("/data/misc/audio/ssr_output_2ch.pcm", "wb"); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | if ((!ssrmod.fp_input) || (!ssrmod.fp_output)) { |
| 541 | ALOGE("%s: input dump or ouput dump open failed: mfp_4ch:%p mfp_6ch:%p", |
| 542 | __func__, ssrmod.fp_input, ssrmod.fp_output); |
| 543 | } |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 546 | ssrmod.in = in; |
| 547 | |
| 548 | ALOGV("%s: exit", __func__); |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 549 | return 0; |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 550 | |
| 551 | fail: |
| 552 | (void) audio_extn_ssr_deinit(); |
| 553 | return ret; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | int32_t audio_extn_ssr_deinit() |
| 557 | { |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 558 | ALOGV("%s: entry", __func__); |
| 559 | deinit_ssr_process_thread(); |
| 560 | |
| 561 | if (ssrmod.drc_obj) { |
| 562 | ssrmod.drc_deinit(ssrmod.drc_obj); |
| 563 | ssrmod.drc_obj = NULL; |
| 564 | } |
| 565 | |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 566 | if (ssrmod.surround_obj) { |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 567 | |
| 568 | if (ssrmod.ssr_3mic) { |
| 569 | ssrmod.surround_rec_deinit(ssrmod.surround_obj); |
| 570 | ssrmod.surround_obj = NULL; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 571 | } |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 572 | if (ssrmod.surround_raw_buffer) { |
| 573 | free(ssrmod.surround_raw_buffer); |
| 574 | ssrmod.surround_raw_buffer = NULL; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 575 | } |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 576 | if (ssrmod.fp_input) |
| 577 | fclose(ssrmod.fp_input); |
| 578 | if (ssrmod.fp_output) |
| 579 | fclose(ssrmod.fp_output); |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 582 | if(ssrmod.drc_handle) { |
| 583 | dlclose(ssrmod.drc_handle); |
| 584 | ssrmod.drc_handle = NULL; |
| 585 | } |
| 586 | |
| 587 | if(ssrmod.surround_rec_handle) { |
| 588 | dlclose(ssrmod.surround_rec_handle); |
| 589 | ssrmod.surround_rec_handle = NULL; |
| 590 | } |
| 591 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 592 | ssrmod.in = NULL; |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 593 | //SSR session can be closed due to device switch |
| 594 | //Do not force reset ssr mode |
| 595 | |
| 596 | //ssrmod.is_ssr_mode_on = false; |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 597 | ALOGV("%s: exit", __func__); |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 602 | static void *ssr_process_thread(void *context __unused) |
| 603 | { |
| 604 | int32_t ret; |
| 605 | |
| 606 | ALOGV("%s: enter", __func__); |
| 607 | |
| 608 | setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_URGENT_AUDIO); |
| 609 | set_sched_policy(0, SP_FOREGROUND); |
| 610 | |
| 611 | pthread_mutex_lock(&ssrmod.ssr_process_lock); |
| 612 | while (!ssrmod.ssr_process_thread_stop) { |
| 613 | struct pcm_buffer_queue *out_buf; |
| 614 | struct pcm_buffer_queue *in_buf; |
| 615 | |
| 616 | while ((!ssrmod.ssr_process_thread_stop) && |
| 617 | ((ssrmod.out_buf_free == NULL) || |
| 618 | (ssrmod.in_buf == NULL))) { |
| 619 | ALOGV("%s: waiting for buffers", __func__); |
| 620 | pthread_cond_wait(&ssrmod.cond_process, &ssrmod.ssr_process_lock); |
| 621 | } |
| 622 | if (ssrmod.ssr_process_thread_stop) { |
| 623 | break; |
| 624 | } |
| 625 | ALOGV("%s: got buffers", __func__); |
| 626 | |
| 627 | out_buf = pcm_buffer_queue_pop(&ssrmod.out_buf_free); |
| 628 | in_buf = pcm_buffer_queue_pop(&ssrmod.in_buf); |
| 629 | |
| 630 | pthread_mutex_unlock(&ssrmod.ssr_process_lock); |
| 631 | |
| 632 | /* apply ssr libs to convert 4ch to 6ch */ |
| 633 | if (ssrmod.ssr_3mic) { |
| 634 | ssrmod.surround_rec_process(ssrmod.surround_obj, |
| 635 | (int16_t *) in_buf->buffer.data, |
| 636 | (int16_t *) out_buf->buffer.data); |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | /* Run DRC if initialized */ |
| 640 | if (ssrmod.drc_obj != NULL) { |
| 641 | ALOGV("%s: Running DRC", __func__); |
| 642 | ret = ssrmod.drc_process(ssrmod.drc_obj, out_buf->buffer.data, out_buf->buffer.data); |
| 643 | if (ret != 0) { |
| 644 | ALOGE("%s: drc_process returned %d", __func__, ret); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | /*dump for raw pcm data*/ |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 649 | if (ssrmod.fp_input) |
| 650 | fwrite(in_buf->buffer.data, 1, in_buf->buffer.length, ssrmod.fp_input); |
| 651 | if (ssrmod.fp_output) |
| 652 | fwrite(out_buf->buffer.data, 1, out_buf->buffer.length, ssrmod.fp_output); |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 653 | |
| 654 | pthread_mutex_lock(&ssrmod.ssr_process_lock); |
| 655 | |
| 656 | pcm_buffer_queue_push(&ssrmod.out_buf, out_buf); |
| 657 | pcm_buffer_queue_push(&ssrmod.in_buf_free, in_buf); |
| 658 | |
| 659 | /* Read thread should go on without waiting for condition |
| 660 | * variable. If it has to wait (due to this thread not keeping |
| 661 | * up with the read requests), let this thread use the remainder |
| 662 | * of its buffers before waking up the read thread. */ |
| 663 | if (ssrmod.in_buf == NULL) { |
| 664 | pthread_cond_signal(&ssrmod.cond_read); |
| 665 | } |
| 666 | } |
| 667 | pthread_mutex_unlock(&ssrmod.ssr_process_lock); |
| 668 | |
| 669 | ALOGV("%s: exit", __func__); |
| 670 | |
| 671 | pthread_exit(NULL); |
| 672 | } |
| 673 | |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 674 | int32_t audio_extn_ssr_read(struct audio_stream_in *stream, |
| 675 | void *buffer, size_t bytes) |
| 676 | { |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 677 | struct stream_in *in = (struct stream_in *)stream; |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 678 | int32_t ret = 0; |
| 679 | struct pcm_buffer_queue *in_buf; |
| 680 | struct pcm_buffer_queue *out_buf; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 681 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 682 | ALOGV("%s: entry", __func__); |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 683 | |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 684 | if (!ssrmod.surround_obj) { |
| 685 | ALOGE("%s: surround_obj not initialized", __func__); |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 686 | return -ENOMEM; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 687 | } |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 688 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 689 | ret = pcm_read(in->pcm, ssrmod.surround_raw_buffer, ssrmod.surround_raw_buffer_size); |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 690 | if (ret < 0) { |
| 691 | ALOGE("%s: %s ret:%d", __func__, pcm_get_error(in->pcm),ret); |
| 692 | return ret; |
| 693 | } |
| 694 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 695 | pthread_mutex_lock(&ssrmod.ssr_process_lock); |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 696 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 697 | if (!ssrmod.ssr_process_thread_started) { |
| 698 | pthread_mutex_unlock(&ssrmod.ssr_process_lock); |
| 699 | ALOGV("%s: ssr_process_thread not initialized", __func__); |
| 700 | return -EINVAL; |
| 701 | } |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 702 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 703 | if ((ssrmod.in_buf_free == NULL) || (ssrmod.out_buf == NULL)) { |
| 704 | ALOGE("%s: waiting for buffers", __func__); |
| 705 | pthread_cond_wait(&ssrmod.cond_read, &ssrmod.ssr_process_lock); |
| 706 | if ((ssrmod.in_buf_free == NULL) || (ssrmod.out_buf == NULL)) { |
| 707 | pthread_mutex_unlock(&ssrmod.ssr_process_lock); |
| 708 | ALOGE("%s: failed to acquire buffers", __func__); |
| 709 | return -EINVAL; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | in_buf = pcm_buffer_queue_pop(&ssrmod.in_buf_free); |
| 714 | out_buf = pcm_buffer_queue_pop(&ssrmod.out_buf); |
| 715 | |
| 716 | memcpy(in_buf->buffer.data, ssrmod.surround_raw_buffer, in_buf->buffer.length); |
| 717 | pcm_buffer_queue_push(&ssrmod.in_buf, in_buf); |
| 718 | |
| 719 | memcpy(buffer, out_buf->buffer.data, bytes); |
| 720 | pcm_buffer_queue_push(&ssrmod.out_buf_free, out_buf); |
| 721 | |
| 722 | pthread_cond_signal(&ssrmod.cond_process); |
| 723 | |
| 724 | pthread_mutex_unlock(&ssrmod.ssr_process_lock); |
| 725 | |
| 726 | ALOGV("%s: exit", __func__); |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 727 | return ret; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 728 | } |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 729 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 730 | void audio_extn_ssr_set_parameters(struct audio_device *adev __unused, |
| 731 | struct str_parms *parms) |
| 732 | { |
| 733 | int err; |
| 734 | char value[4096] = {0}; |
| 735 | |
| 736 | //Do not update SSR mode during recording |
| 737 | if ( !ssrmod.surround_obj) { |
| 738 | int ret = 0; |
| 739 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_SSRMODE_ON, value, |
| 740 | sizeof(value)); |
| 741 | if (ret >= 0) { |
| 742 | if (strcmp(value, "true") == 0) { |
| 743 | ALOGD("Received SSR session request..setting SSR mode to true"); |
| 744 | ssrmod.is_ssr_mode_on = true; |
| 745 | } else { |
| 746 | ALOGD("resetting SSR mode to false"); |
| 747 | ssrmod.is_ssr_mode_on = false; |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | if (ssrmod.ssr_3mic && ssrmod.surround_obj) { |
| 752 | const set_param_data_t *set_params = ssrmod.surround_rec_get_set_param_data(); |
| 753 | if (set_params != NULL) { |
| 754 | while (set_params->name != NULL && set_params->set_param_fn != NULL) { |
| 755 | err = str_parms_get_str(parms, set_params->name, value, sizeof(value)); |
| 756 | if (err >= 0) { |
| 757 | ALOGV("Set %s to %s\n", set_params->name, value); |
| 758 | set_params->set_param_fn(ssrmod.surround_obj, value); |
| 759 | } |
| 760 | set_params++; |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | void audio_extn_ssr_get_parameters(const struct audio_device *adev __unused, |
| 767 | struct str_parms *parms, |
| 768 | struct str_parms *reply) |
| 769 | { |
| 770 | int err; |
| 771 | char value[4096] = {0}; |
| 772 | |
| 773 | if (ssrmod.ssr_3mic && ssrmod.surround_obj) { |
| 774 | const get_param_data_t *get_params = ssrmod.surround_rec_get_get_param_data(); |
| 775 | int get_all = 0; |
| 776 | err = str_parms_get_str(parms, "ssr.all", value, sizeof(value)); |
| 777 | if (err >= 0) { |
| 778 | get_all = 1; |
| 779 | } |
| 780 | if (get_params != NULL) { |
| 781 | while (get_params->name != NULL && get_params->get_param_fn != NULL) { |
| 782 | err = str_parms_get_str(parms, get_params->name, value, sizeof(value)); |
| 783 | if (get_all || (err >= 0)) { |
| 784 | ALOGV("Getting parameter %s", get_params->name); |
| 785 | char *val = get_params->get_param_fn(ssrmod.surround_obj); |
| 786 | if (val != NULL) { |
| 787 | str_parms_add_str(reply, get_params->name, val); |
| 788 | free(val); |
| 789 | } |
| 790 | } |
| 791 | get_params++; |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 797 | #endif /* SSR_ENABLED */ |