Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #define LOG_TAG "PreProcessing" |
| 20 | //#define LOG_NDEBUG 0 |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 21 | #include <audio_effects/effect_aec.h> |
| 22 | #include <audio_effects/effect_agc.h> |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 23 | #include <hardware/audio_effect.h> |
| 24 | #include <utils/Log.h> |
| 25 | #include <utils/Timers.h> |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 26 | #include <audio_effects/effect_agc2.h> |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 27 | #include <audio_effects/effect_ns.h> |
Eric Laurent | 5387696 | 2012-01-31 12:35:20 -0800 | [diff] [blame] | 28 | #include <audio_processing.h> |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 29 | #include <module_common_types.h> |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 30 | |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 31 | // undefine to perform multi channels API functional tests |
| 32 | //#define DUAL_MIC_TEST |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 33 | |
| 34 | //------------------------------------------------------------------------------ |
| 35 | // local definitions |
| 36 | //------------------------------------------------------------------------------ |
| 37 | |
| 38 | // maximum number of sessions |
| 39 | #define PREPROC_NUM_SESSIONS 8 |
| 40 | |
| 41 | // types of pre processing modules |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 42 | enum preproc_id { |
| 43 | PREPROC_AGC, // Automatic Gain Control |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 44 | PREPROC_AGC2, // Automatic Gain Control 2 |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 45 | PREPROC_AEC, // Acoustic Echo Canceler |
| 46 | PREPROC_NS, // Noise Suppressor |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 47 | PREPROC_NUM_EFFECTS |
| 48 | }; |
| 49 | |
| 50 | // Session state |
| 51 | enum preproc_session_state { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 52 | PREPROC_SESSION_STATE_INIT, // initialized |
| 53 | PREPROC_SESSION_STATE_CONFIG // configuration received |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | // Effect/Preprocessor state |
| 57 | enum preproc_effect_state { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 58 | PREPROC_EFFECT_STATE_INIT, // initialized |
| 59 | PREPROC_EFFECT_STATE_CREATED, // webRTC engine created |
| 60 | PREPROC_EFFECT_STATE_CONFIG, // configuration received/disabled |
| 61 | PREPROC_EFFECT_STATE_ACTIVE // active/enabled |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | // handle on webRTC engine |
| 65 | typedef void* preproc_fx_handle_t; |
| 66 | |
| 67 | typedef struct preproc_session_s preproc_session_t; |
| 68 | typedef struct preproc_effect_s preproc_effect_t; |
| 69 | typedef struct preproc_ops_s preproc_ops_t; |
| 70 | |
| 71 | // Effect operation table. Functions for all pre processors are declared in sPreProcOps[] table. |
| 72 | // Function pointer can be null if no action required. |
| 73 | struct preproc_ops_s { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 74 | int (*create)(preproc_effect_t* fx); |
| 75 | int (*init)(preproc_effect_t* fx); |
| 76 | int (*reset)(preproc_effect_t* fx); |
| 77 | void (*enable)(preproc_effect_t* fx); |
| 78 | void (*disable)(preproc_effect_t* fx); |
| 79 | int (*set_parameter)(preproc_effect_t* fx, void* param, void* value); |
| 80 | int (*get_parameter)(preproc_effect_t* fx, void* param, uint32_t* size, void* value); |
| 81 | int (*set_device)(preproc_effect_t* fx, uint32_t device); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | // Effect context |
| 85 | struct preproc_effect_s { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 86 | const struct effect_interface_s* itfe; |
| 87 | uint32_t procId; // type of pre processor (enum preproc_id) |
| 88 | uint32_t state; // current state (enum preproc_effect_state) |
| 89 | preproc_session_t* session; // session the effect is on |
| 90 | const preproc_ops_t* ops; // effect ops table |
| 91 | preproc_fx_handle_t engine; // handle on webRTC engine |
| 92 | uint32_t type; // subtype of effect |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 93 | #ifdef DUAL_MIC_TEST |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 94 | bool aux_channels_on; // support auxiliary channels |
| 95 | size_t cur_channel_config; // current auciliary channel configuration |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 96 | #endif |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | // Session context |
| 100 | struct preproc_session_s { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 101 | struct preproc_effect_s effects[PREPROC_NUM_EFFECTS]; // effects in this session |
| 102 | uint32_t state; // current state (enum preproc_session_state) |
| 103 | int id; // audio session ID |
| 104 | int io; // handle of input stream this session is on |
| 105 | webrtc::AudioProcessing* apm; // handle on webRTC audio processing module (APM) |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 106 | // Audio Processing module builder |
| 107 | webrtc::AudioProcessingBuilder ap_builder; |
Harish Mahendrakar | d510fdd | 2021-03-16 13:26:31 -0700 | [diff] [blame] | 108 | // frameCount represents the size of the buffers used for processing, and must represent 10ms. |
| 109 | size_t frameCount; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 110 | uint32_t samplingRate; // sampling rate at effect process interface |
| 111 | uint32_t inChannelCount; // input channel count |
| 112 | uint32_t outChannelCount; // output channel count |
| 113 | uint32_t createdMsk; // bit field containing IDs of crested pre processors |
| 114 | uint32_t enabledMsk; // bit field containing IDs of enabled pre processors |
| 115 | uint32_t processedMsk; // bit field containing IDs of pre processors already |
| 116 | // processed in current round |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 117 | // audio config strucutre |
| 118 | webrtc::AudioProcessing::Config config; |
| 119 | webrtc::StreamConfig inputConfig; // input stream configuration |
| 120 | webrtc::StreamConfig outputConfig; // output stream configuration |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 121 | uint32_t revChannelCount; // number of channels on reverse stream |
| 122 | uint32_t revEnabledMsk; // bit field containing IDs of enabled pre processors |
| 123 | // with reverse channel |
| 124 | uint32_t revProcessedMsk; // bit field containing IDs of pre processors with reverse |
| 125 | // channel already processed in current round |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 126 | webrtc::StreamConfig revConfig; // reverse stream configuration. |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 129 | #ifdef DUAL_MIC_TEST |
| 130 | enum { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 131 | PREPROC_CMD_DUAL_MIC_ENABLE = EFFECT_CMD_FIRST_PROPRIETARY, // enable dual mic mode |
| 132 | PREPROC_CMD_DUAL_MIC_PCM_DUMP_START, // start pcm capture |
| 133 | PREPROC_CMD_DUAL_MIC_PCM_DUMP_STOP // stop pcm capture |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | enum { |
| 137 | CHANNEL_CFG_MONO, |
| 138 | CHANNEL_CFG_STEREO, |
| 139 | CHANNEL_CFG_MONO_AUX, |
| 140 | CHANNEL_CFG_STEREO_AUX, |
| 141 | CHANNEL_CFG_CNT, |
| 142 | CHANNEL_CFG_FIRST_AUX = CHANNEL_CFG_MONO_AUX, |
| 143 | }; |
| 144 | |
| 145 | const channel_config_t sDualMicConfigs[CHANNEL_CFG_CNT] = { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 146 | {AUDIO_CHANNEL_IN_MONO, 0}, |
| 147 | {AUDIO_CHANNEL_IN_STEREO, 0}, |
| 148 | {AUDIO_CHANNEL_IN_FRONT, AUDIO_CHANNEL_IN_BACK}, |
| 149 | {AUDIO_CHANNEL_IN_STEREO, AUDIO_CHANNEL_IN_RIGHT}}; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 150 | |
| 151 | bool sHasAuxChannels[PREPROC_NUM_EFFECTS] = { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 152 | false, // PREPROC_AGC |
Atneya Nair | 2a77e83 | 2021-12-08 19:31:45 -0500 | [diff] [blame^] | 153 | false, // PREPROC_AGC2 |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 154 | true, // PREPROC_AEC |
| 155 | true, // PREPROC_NS |
| 156 | }; |
| 157 | |
| 158 | bool gDualMicEnabled; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 159 | FILE* gPcmDumpFh; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 160 | static pthread_mutex_t gPcmDumpLock = PTHREAD_MUTEX_INITIALIZER; |
| 161 | #endif |
| 162 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 163 | //------------------------------------------------------------------------------ |
| 164 | // Effect descriptors |
| 165 | //------------------------------------------------------------------------------ |
| 166 | |
| 167 | // UUIDs for effect types have been generated from http://www.itu.int/ITU-T/asn1/uuid.html |
| 168 | // as the pre processing effects are not defined by OpenSL ES |
| 169 | |
| 170 | // Automatic Gain Control |
| 171 | static const effect_descriptor_t sAgcDescriptor = { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 172 | {0x0a8abfe0, 0x654c, 0x11e0, 0xba26, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type |
| 173 | {0xaa8130e0, 0x66fc, 0x11e0, 0xbad0, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 174 | EFFECT_CONTROL_API_VERSION, |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 175 | (EFFECT_FLAG_TYPE_PRE_PROC | EFFECT_FLAG_DEVICE_IND), |
| 176 | 0, // FIXME indicate CPU load |
| 177 | 0, // FIXME indicate memory usage |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 178 | "Automatic Gain Control", |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 179 | "The Android Open Source Project"}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 180 | |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 181 | // Automatic Gain Control 2 |
| 182 | static const effect_descriptor_t sAgc2Descriptor = { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 183 | {0xae3c653b, 0xbe18, 0x4ab8, 0x8938, {0x41, 0x8f, 0x0a, 0x7f, 0x06, 0xac}}, // type |
| 184 | {0x89f38e65, 0xd4d2, 0x4d64, 0xad0e, {0x2b, 0x3e, 0x79, 0x9e, 0xa8, 0x86}}, // uuid |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 185 | EFFECT_CONTROL_API_VERSION, |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 186 | (EFFECT_FLAG_TYPE_PRE_PROC | EFFECT_FLAG_DEVICE_IND), |
| 187 | 0, // FIXME indicate CPU load |
| 188 | 0, // FIXME indicate memory usage |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 189 | "Automatic Gain Control 2", |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 190 | "The Android Open Source Project"}; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 191 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 192 | // Acoustic Echo Cancellation |
| 193 | static const effect_descriptor_t sAecDescriptor = { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 194 | {0x7b491460, 0x8d4d, 0x11e0, 0xbd61, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type |
| 195 | {0xbb392ec0, 0x8d4d, 0x11e0, 0xa896, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 196 | EFFECT_CONTROL_API_VERSION, |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 197 | (EFFECT_FLAG_TYPE_PRE_PROC | EFFECT_FLAG_DEVICE_IND), |
| 198 | 0, // FIXME indicate CPU load |
| 199 | 0, // FIXME indicate memory usage |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 200 | "Acoustic Echo Canceler", |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 201 | "The Android Open Source Project"}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 202 | |
| 203 | // Noise suppression |
| 204 | static const effect_descriptor_t sNsDescriptor = { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 205 | {0x58b4b260, 0x8e06, 0x11e0, 0xaa8e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type |
| 206 | {0xc06c8400, 0x8e06, 0x11e0, 0x9cb6, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 207 | EFFECT_CONTROL_API_VERSION, |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 208 | (EFFECT_FLAG_TYPE_PRE_PROC | EFFECT_FLAG_DEVICE_IND), |
| 209 | 0, // FIXME indicate CPU load |
| 210 | 0, // FIXME indicate memory usage |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 211 | "Noise Suppression", |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 212 | "The Android Open Source Project"}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 213 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 214 | static const effect_descriptor_t* sDescriptors[PREPROC_NUM_EFFECTS] = {&sAgcDescriptor, |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 215 | &sAgc2Descriptor, |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 216 | &sAecDescriptor, |
| 217 | &sNsDescriptor}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 218 | |
| 219 | //------------------------------------------------------------------------------ |
| 220 | // Helper functions |
| 221 | //------------------------------------------------------------------------------ |
| 222 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 223 | const effect_uuid_t* const sUuidToPreProcTable[PREPROC_NUM_EFFECTS] = {FX_IID_AGC, |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 224 | FX_IID_AGC2, |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 225 | FX_IID_AEC, FX_IID_NS}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 226 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 227 | const effect_uuid_t* ProcIdToUuid(int procId) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 228 | if (procId >= PREPROC_NUM_EFFECTS) { |
| 229 | return EFFECT_UUID_NULL; |
| 230 | } |
| 231 | return sUuidToPreProcTable[procId]; |
| 232 | } |
| 233 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 234 | uint32_t UuidToProcId(const effect_uuid_t* uuid) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 235 | size_t i; |
| 236 | for (i = 0; i < PREPROC_NUM_EFFECTS; i++) { |
| 237 | if (memcmp(uuid, sUuidToPreProcTable[i], sizeof(*uuid)) == 0) { |
| 238 | break; |
| 239 | } |
| 240 | } |
| 241 | return i; |
| 242 | } |
| 243 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 244 | bool HasReverseStream(uint32_t procId) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 245 | if (procId == PREPROC_AEC) { |
| 246 | return true; |
| 247 | } |
| 248 | return false; |
| 249 | } |
| 250 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 251 | //------------------------------------------------------------------------------ |
| 252 | // Automatic Gain Control (AGC) |
| 253 | //------------------------------------------------------------------------------ |
| 254 | |
Eric Laurent | 5387696 | 2012-01-31 12:35:20 -0800 | [diff] [blame] | 255 | static const int kAgcDefaultTargetLevel = 3; |
| 256 | static const int kAgcDefaultCompGain = 9; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 257 | static const bool kAgcDefaultLimiter = true; |
| 258 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 259 | int Agc2Init(preproc_effect_t* effect) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 260 | ALOGV("Agc2Init"); |
| 261 | effect->session->config = effect->session->apm->GetConfig(); |
| 262 | effect->session->config.gain_controller2.fixed_digital.gain_db = 0.f; |
| 263 | effect->session->config.gain_controller2.adaptive_digital.level_estimator = |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 264 | effect->session->config.gain_controller2.kRms; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 265 | effect->session->config.gain_controller2.adaptive_digital.extra_saturation_margin_db = 2.f; |
| 266 | effect->session->apm->ApplyConfig(effect->session->config); |
| 267 | return 0; |
| 268 | } |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 269 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 270 | int AgcInit(preproc_effect_t* effect) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 271 | ALOGV("AgcInit"); |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 272 | effect->session->config = effect->session->apm->GetConfig(); |
| 273 | effect->session->config.gain_controller1.target_level_dbfs = kAgcDefaultTargetLevel; |
| 274 | effect->session->config.gain_controller1.compression_gain_db = kAgcDefaultCompGain; |
| 275 | effect->session->config.gain_controller1.enable_limiter = kAgcDefaultLimiter; |
| 276 | effect->session->apm->ApplyConfig(effect->session->config); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 280 | int Agc2Create(preproc_effect_t* effect) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 281 | Agc2Init(effect); |
| 282 | return 0; |
| 283 | } |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 284 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 285 | int AgcCreate(preproc_effect_t* effect) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 286 | AgcInit(effect); |
| 287 | return 0; |
| 288 | } |
| 289 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 290 | int Agc2GetParameter(preproc_effect_t* effect, void* pParam, uint32_t* pValueSize, void* pValue) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 291 | int status = 0; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 292 | uint32_t param = *(uint32_t*)pParam; |
| 293 | agc2_settings_t* pProperties = (agc2_settings_t*)pValue; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 294 | |
| 295 | switch (param) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 296 | case AGC2_PARAM_FIXED_DIGITAL_GAIN: |
| 297 | if (*pValueSize < sizeof(float)) { |
| 298 | *pValueSize = 0.f; |
| 299 | return -EINVAL; |
| 300 | } |
| 301 | break; |
| 302 | case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR: |
| 303 | if (*pValueSize < sizeof(int32_t)) { |
| 304 | *pValueSize = 0; |
| 305 | return -EINVAL; |
| 306 | } |
| 307 | break; |
| 308 | case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN: |
| 309 | if (*pValueSize < sizeof(float)) { |
| 310 | *pValueSize = 0.f; |
| 311 | return -EINVAL; |
| 312 | } |
| 313 | break; |
| 314 | case AGC2_PARAM_PROPERTIES: |
| 315 | if (*pValueSize < sizeof(agc2_settings_t)) { |
| 316 | *pValueSize = 0; |
| 317 | return -EINVAL; |
| 318 | } |
| 319 | break; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 320 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 321 | default: |
| 322 | ALOGW("Agc2GetParameter() unknown param %08x", param); |
| 323 | status = -EINVAL; |
| 324 | break; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | effect->session->config = effect->session->apm->GetConfig(); |
| 328 | switch (param) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 329 | case AGC2_PARAM_FIXED_DIGITAL_GAIN: |
| 330 | *(float*)pValue = |
| 331 | (float)(effect->session->config.gain_controller2.fixed_digital.gain_db); |
| 332 | ALOGV("Agc2GetParameter() target level %f dB", *(float*)pValue); |
| 333 | break; |
| 334 | case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR: |
| 335 | *(uint32_t*)pValue = (uint32_t)( |
| 336 | effect->session->config.gain_controller2.adaptive_digital.level_estimator); |
| 337 | ALOGV("Agc2GetParameter() level estimator %d", |
| 338 | *(webrtc::AudioProcessing::Config::GainController2::LevelEstimator*)pValue); |
| 339 | break; |
| 340 | case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN: |
| 341 | *(float*)pValue = (float)(effect->session->config.gain_controller2.adaptive_digital |
| 342 | .extra_saturation_margin_db); |
| 343 | ALOGV("Agc2GetParameter() extra saturation margin %f dB", *(float*)pValue); |
| 344 | break; |
| 345 | case AGC2_PARAM_PROPERTIES: |
| 346 | pProperties->fixedDigitalGain = |
| 347 | (float)(effect->session->config.gain_controller2.fixed_digital.gain_db); |
| 348 | pProperties->level_estimator = (uint32_t)( |
| 349 | effect->session->config.gain_controller2.adaptive_digital.level_estimator); |
| 350 | pProperties->extraSaturationMargin = |
| 351 | (float)(effect->session->config.gain_controller2.adaptive_digital |
| 352 | .extra_saturation_margin_db); |
| 353 | break; |
| 354 | default: |
| 355 | ALOGW("Agc2GetParameter() unknown param %d", param); |
| 356 | status = -EINVAL; |
| 357 | break; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | return status; |
| 361 | } |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 362 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 363 | int AgcGetParameter(preproc_effect_t* effect, void* pParam, uint32_t* pValueSize, void* pValue) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 364 | int status = 0; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 365 | uint32_t param = *(uint32_t*)pParam; |
| 366 | t_agc_settings* pProperties = (t_agc_settings*)pValue; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 367 | |
| 368 | switch (param) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 369 | case AGC_PARAM_TARGET_LEVEL: |
| 370 | case AGC_PARAM_COMP_GAIN: |
| 371 | if (*pValueSize < sizeof(int16_t)) { |
| 372 | *pValueSize = 0; |
| 373 | return -EINVAL; |
| 374 | } |
| 375 | break; |
| 376 | case AGC_PARAM_LIMITER_ENA: |
| 377 | if (*pValueSize < sizeof(bool)) { |
| 378 | *pValueSize = 0; |
| 379 | return -EINVAL; |
| 380 | } |
| 381 | break; |
| 382 | case AGC_PARAM_PROPERTIES: |
| 383 | if (*pValueSize < sizeof(t_agc_settings)) { |
| 384 | *pValueSize = 0; |
| 385 | return -EINVAL; |
| 386 | } |
| 387 | break; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 388 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 389 | default: |
| 390 | ALOGW("AgcGetParameter() unknown param %08x", param); |
| 391 | status = -EINVAL; |
| 392 | break; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 395 | effect->session->config = effect->session->apm->GetConfig(); |
| 396 | switch (param) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 397 | case AGC_PARAM_TARGET_LEVEL: |
| 398 | *(int16_t*)pValue = |
| 399 | (int16_t)(effect->session->config.gain_controller1.target_level_dbfs * -100); |
| 400 | ALOGV("AgcGetParameter() target level %d milliBels", *(int16_t*)pValue); |
| 401 | break; |
| 402 | case AGC_PARAM_COMP_GAIN: |
| 403 | *(int16_t*)pValue = |
| 404 | (int16_t)(effect->session->config.gain_controller1.compression_gain_db * -100); |
| 405 | ALOGV("AgcGetParameter() comp gain %d milliBels", *(int16_t*)pValue); |
| 406 | break; |
| 407 | case AGC_PARAM_LIMITER_ENA: |
| 408 | *(bool*)pValue = (bool)(effect->session->config.gain_controller1.enable_limiter); |
| 409 | ALOGV("AgcGetParameter() limiter enabled %s", |
| 410 | (*(int16_t*)pValue != 0) ? "true" : "false"); |
| 411 | break; |
| 412 | case AGC_PARAM_PROPERTIES: |
| 413 | pProperties->targetLevel = |
| 414 | (int16_t)(effect->session->config.gain_controller1.target_level_dbfs * -100); |
| 415 | pProperties->compGain = |
| 416 | (int16_t)(effect->session->config.gain_controller1.compression_gain_db * -100); |
| 417 | pProperties->limiterEnabled = |
| 418 | (bool)(effect->session->config.gain_controller1.enable_limiter); |
| 419 | break; |
| 420 | default: |
| 421 | ALOGW("AgcGetParameter() unknown param %d", param); |
| 422 | status = -EINVAL; |
| 423 | break; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 424 | } |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 425 | return status; |
| 426 | } |
| 427 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 428 | int Agc2SetParameter(preproc_effect_t* effect, void* pParam, void* pValue) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 429 | int status = 0; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 430 | uint32_t param = *(uint32_t*)pParam; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 431 | float valueFloat = 0.f; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 432 | agc2_settings_t* pProperties = (agc2_settings_t*)pValue; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 433 | effect->session->config = effect->session->apm->GetConfig(); |
| 434 | switch (param) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 435 | case AGC2_PARAM_FIXED_DIGITAL_GAIN: |
| 436 | valueFloat = (float)(*(int32_t*)pValue); |
| 437 | ALOGV("Agc2SetParameter() fixed digital gain %f dB", valueFloat); |
| 438 | effect->session->config.gain_controller2.fixed_digital.gain_db = valueFloat; |
| 439 | break; |
| 440 | case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR: |
| 441 | ALOGV("Agc2SetParameter() level estimator %d", |
| 442 | *(webrtc::AudioProcessing::Config::GainController2::LevelEstimator*)pValue); |
| 443 | effect->session->config.gain_controller2.adaptive_digital.level_estimator = |
| 444 | (*(webrtc::AudioProcessing::Config::GainController2::LevelEstimator*)pValue); |
| 445 | break; |
| 446 | case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN: |
| 447 | valueFloat = (float)(*(int32_t*)pValue); |
| 448 | ALOGV("Agc2SetParameter() extra saturation margin %f dB", valueFloat); |
| 449 | effect->session->config.gain_controller2.adaptive_digital.extra_saturation_margin_db = |
| 450 | valueFloat; |
| 451 | break; |
| 452 | case AGC2_PARAM_PROPERTIES: |
| 453 | ALOGV("Agc2SetParameter() properties gain %f, level %d margin %f", |
| 454 | pProperties->fixedDigitalGain, pProperties->level_estimator, |
| 455 | pProperties->extraSaturationMargin); |
| 456 | effect->session->config.gain_controller2.fixed_digital.gain_db = |
| 457 | pProperties->fixedDigitalGain; |
| 458 | effect->session->config.gain_controller2.adaptive_digital.level_estimator = |
| 459 | (webrtc::AudioProcessing::Config::GainController2::LevelEstimator) |
| 460 | pProperties->level_estimator; |
| 461 | effect->session->config.gain_controller2.adaptive_digital.extra_saturation_margin_db = |
| 462 | pProperties->extraSaturationMargin; |
| 463 | break; |
| 464 | default: |
| 465 | ALOGW("Agc2SetParameter() unknown param %08x value %08x", param, *(uint32_t*)pValue); |
| 466 | status = -EINVAL; |
| 467 | break; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 468 | } |
| 469 | effect->session->apm->ApplyConfig(effect->session->config); |
| 470 | |
| 471 | ALOGV("Agc2SetParameter() done status %d", status); |
| 472 | |
| 473 | return status; |
| 474 | } |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 475 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 476 | int AgcSetParameter(preproc_effect_t* effect, void* pParam, void* pValue) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 477 | int status = 0; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 478 | uint32_t param = *(uint32_t*)pParam; |
| 479 | t_agc_settings* pProperties = (t_agc_settings*)pValue; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 480 | effect->session->config = effect->session->apm->GetConfig(); |
| 481 | switch (param) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 482 | case AGC_PARAM_TARGET_LEVEL: |
| 483 | ALOGV("AgcSetParameter() target level %d milliBels", *(int16_t*)pValue); |
| 484 | effect->session->config.gain_controller1.target_level_dbfs = |
| 485 | (-(*(int16_t*)pValue / 100)); |
| 486 | break; |
| 487 | case AGC_PARAM_COMP_GAIN: |
| 488 | ALOGV("AgcSetParameter() comp gain %d milliBels", *(int16_t*)pValue); |
| 489 | effect->session->config.gain_controller1.compression_gain_db = |
| 490 | (*(int16_t*)pValue / 100); |
| 491 | break; |
| 492 | case AGC_PARAM_LIMITER_ENA: |
| 493 | ALOGV("AgcSetParameter() limiter enabled %s", *(bool*)pValue ? "true" : "false"); |
| 494 | effect->session->config.gain_controller1.enable_limiter = (*(bool*)pValue); |
| 495 | break; |
| 496 | case AGC_PARAM_PROPERTIES: |
| 497 | ALOGV("AgcSetParameter() properties level %d, gain %d limiter %d", |
| 498 | pProperties->targetLevel, pProperties->compGain, pProperties->limiterEnabled); |
| 499 | effect->session->config.gain_controller1.target_level_dbfs = |
| 500 | -(pProperties->targetLevel / 100); |
| 501 | effect->session->config.gain_controller1.compression_gain_db = |
| 502 | pProperties->compGain / 100; |
| 503 | effect->session->config.gain_controller1.enable_limiter = pProperties->limiterEnabled; |
| 504 | break; |
| 505 | default: |
| 506 | ALOGW("AgcSetParameter() unknown param %08x value %08x", param, *(uint32_t*)pValue); |
| 507 | status = -EINVAL; |
| 508 | break; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 509 | } |
| 510 | effect->session->apm->ApplyConfig(effect->session->config); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 511 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 512 | ALOGV("AgcSetParameter() done status %d", status); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 513 | |
| 514 | return status; |
| 515 | } |
| 516 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 517 | void Agc2Enable(preproc_effect_t* effect) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 518 | effect->session->config = effect->session->apm->GetConfig(); |
| 519 | effect->session->config.gain_controller2.enabled = true; |
| 520 | effect->session->apm->ApplyConfig(effect->session->config); |
| 521 | } |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 522 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 523 | void AgcEnable(preproc_effect_t* effect) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 524 | effect->session->config = effect->session->apm->GetConfig(); |
| 525 | effect->session->config.gain_controller1.enabled = true; |
| 526 | effect->session->apm->ApplyConfig(effect->session->config); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 529 | void Agc2Disable(preproc_effect_t* effect) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 530 | effect->session->config = effect->session->apm->GetConfig(); |
| 531 | effect->session->config.gain_controller2.enabled = false; |
| 532 | effect->session->apm->ApplyConfig(effect->session->config); |
| 533 | } |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 534 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 535 | void AgcDisable(preproc_effect_t* effect) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 536 | effect->session->config = effect->session->apm->GetConfig(); |
| 537 | effect->session->config.gain_controller1.enabled = false; |
| 538 | effect->session->apm->ApplyConfig(effect->session->config); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 541 | static const preproc_ops_t sAgcOps = {AgcCreate, AgcInit, NULL, AgcEnable, AgcDisable, |
| 542 | AgcSetParameter, AgcGetParameter, NULL}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 543 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 544 | static const preproc_ops_t sAgc2Ops = {Agc2Create, Agc2Init, NULL, |
| 545 | Agc2Enable, Agc2Disable, Agc2SetParameter, |
| 546 | Agc2GetParameter, NULL}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 547 | |
| 548 | //------------------------------------------------------------------------------ |
| 549 | // Acoustic Echo Canceler (AEC) |
| 550 | //------------------------------------------------------------------------------ |
| 551 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 552 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 553 | int AecInit(preproc_effect_t* effect) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 554 | ALOGV("AecInit"); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 555 | effect->session->config = effect->session->apm->GetConfig(); |
Rivukanta Bhattacharya | c4c5417 | 2020-11-25 23:55:44 +0530 | [diff] [blame] | 556 | effect->session->config.echo_canceller.mobile_mode = true; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 557 | effect->session->apm->ApplyConfig(effect->session->config); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 561 | int AecCreate(preproc_effect_t* effect) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 562 | AecInit(effect); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 563 | return 0; |
| 564 | } |
| 565 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 566 | int AecGetParameter(preproc_effect_t* effect, void* pParam, uint32_t* pValueSize, void* pValue) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 567 | int status = 0; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 568 | uint32_t param = *(uint32_t*)pParam; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 569 | |
| 570 | if (*pValueSize < sizeof(uint32_t)) { |
| 571 | return -EINVAL; |
| 572 | } |
| 573 | switch (param) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 574 | case AEC_PARAM_ECHO_DELAY: |
| 575 | case AEC_PARAM_PROPERTIES: |
| 576 | *(uint32_t*)pValue = 1000 * effect->session->apm->stream_delay_ms(); |
| 577 | ALOGV("AecGetParameter() echo delay %d us", *(uint32_t*)pValue); |
| 578 | break; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 579 | case AEC_PARAM_MOBILE_MODE: |
| 580 | effect->session->config = effect->session->apm->GetConfig(); |
| 581 | *(uint32_t*)pValue = effect->session->config.echo_canceller.mobile_mode; |
| 582 | ALOGV("AecGetParameter() mobile mode %d us", *(uint32_t*)pValue); |
| 583 | break; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 584 | default: |
| 585 | ALOGW("AecGetParameter() unknown param %08x value %08x", param, *(uint32_t*)pValue); |
| 586 | status = -EINVAL; |
| 587 | break; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 588 | } |
| 589 | return status; |
| 590 | } |
| 591 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 592 | int AecSetParameter(preproc_effect_t* effect, void* pParam, void* pValue) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 593 | int status = 0; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 594 | uint32_t param = *(uint32_t*)pParam; |
| 595 | uint32_t value = *(uint32_t*)pValue; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 596 | |
| 597 | switch (param) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 598 | case AEC_PARAM_ECHO_DELAY: |
| 599 | case AEC_PARAM_PROPERTIES: |
| 600 | status = effect->session->apm->set_stream_delay_ms(value / 1000); |
| 601 | ALOGV("AecSetParameter() echo delay %d us, status %d", value, status); |
| 602 | break; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 603 | case AEC_PARAM_MOBILE_MODE: |
| 604 | effect->session->config = effect->session->apm->GetConfig(); |
| 605 | effect->session->config.echo_canceller.mobile_mode = value; |
| 606 | ALOGV("AecSetParameter() mobile mode %d us", value); |
| 607 | effect->session->apm->ApplyConfig(effect->session->config); |
| 608 | break; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 609 | default: |
| 610 | ALOGW("AecSetParameter() unknown param %08x value %08x", param, *(uint32_t*)pValue); |
| 611 | status = -EINVAL; |
| 612 | break; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 613 | } |
| 614 | return status; |
| 615 | } |
| 616 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 617 | void AecEnable(preproc_effect_t* effect) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 618 | effect->session->config = effect->session->apm->GetConfig(); |
| 619 | effect->session->config.echo_canceller.enabled = true; |
| 620 | effect->session->apm->ApplyConfig(effect->session->config); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 623 | void AecDisable(preproc_effect_t* effect) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 624 | effect->session->config = effect->session->apm->GetConfig(); |
| 625 | effect->session->config.echo_canceller.enabled = false; |
| 626 | effect->session->apm->ApplyConfig(effect->session->config); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 629 | int AecSetDevice(preproc_effect_t* effect, uint32_t device) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 630 | ALOGV("AecSetDevice %08x", device); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 631 | |
Eric Laurent | 8895925 | 2012-08-28 14:26:53 -0700 | [diff] [blame] | 632 | if (audio_is_input_device(device)) { |
| 633 | return 0; |
| 634 | } |
| 635 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 639 | static const preproc_ops_t sAecOps = {AecCreate, AecInit, NULL, |
| 640 | AecEnable, AecDisable, AecSetParameter, |
| 641 | AecGetParameter, AecSetDevice}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 642 | |
| 643 | //------------------------------------------------------------------------------ |
| 644 | // Noise Suppression (NS) |
| 645 | //------------------------------------------------------------------------------ |
| 646 | |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 647 | static const webrtc::AudioProcessing::Config::NoiseSuppression::Level kNsDefaultLevel = |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 648 | webrtc::AudioProcessing::Config::NoiseSuppression::kModerate; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 649 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 650 | int NsInit(preproc_effect_t* effect) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 651 | ALOGV("NsInit"); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 652 | effect->session->config = effect->session->apm->GetConfig(); |
| 653 | effect->session->config.noise_suppression.level = kNsDefaultLevel; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 654 | effect->session->apm->ApplyConfig(effect->session->config); |
Alex Luebs | 766bf73 | 2015-12-14 21:32:13 -0800 | [diff] [blame] | 655 | effect->type = NS_TYPE_SINGLE_CHANNEL; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 656 | return 0; |
| 657 | } |
| 658 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 659 | int NsCreate(preproc_effect_t* effect) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 660 | NsInit(effect); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 661 | return 0; |
| 662 | } |
| 663 | |
Rivukanta Bhattacharya | 013e02e | 2021-03-12 05:50:55 +0530 | [diff] [blame] | 664 | int NsGetParameter(preproc_effect_t* /*effect __unused*/, void* /*pParam __unused*/, |
| 665 | uint32_t* /*pValueSize __unused*/, void* /*pValue __unused*/) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 666 | int status = 0; |
| 667 | return status; |
| 668 | } |
| 669 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 670 | int NsSetParameter(preproc_effect_t* effect, void* pParam, void* pValue) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 671 | int status = 0; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 672 | uint32_t param = *(uint32_t*)pParam; |
| 673 | uint32_t value = *(uint32_t*)pValue; |
| 674 | effect->session->config = effect->session->apm->GetConfig(); |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 675 | switch (param) { |
| 676 | case NS_PARAM_LEVEL: |
| 677 | effect->session->config.noise_suppression.level = |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 678 | (webrtc::AudioProcessing::Config::NoiseSuppression::Level)value; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 679 | ALOGV("NsSetParameter() level %d", value); |
| 680 | break; |
| 681 | default: |
| 682 | ALOGW("NsSetParameter() unknown param %08x value %08x", param, value); |
| 683 | status = -EINVAL; |
| 684 | } |
| 685 | effect->session->apm->ApplyConfig(effect->session->config); |
Alex Luebs | 766bf73 | 2015-12-14 21:32:13 -0800 | [diff] [blame] | 686 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 687 | return status; |
| 688 | } |
| 689 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 690 | void NsEnable(preproc_effect_t* effect) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 691 | effect->session->config = effect->session->apm->GetConfig(); |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 692 | effect->session->config.noise_suppression.enabled = true; |
| 693 | effect->session->apm->ApplyConfig(effect->session->config); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 696 | void NsDisable(preproc_effect_t* effect) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 697 | ALOGV("NsDisable"); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 698 | effect->session->config = effect->session->apm->GetConfig(); |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 699 | effect->session->config.noise_suppression.enabled = false; |
| 700 | effect->session->apm->ApplyConfig(effect->session->config); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 703 | static const preproc_ops_t sNsOps = {NsCreate, NsInit, NULL, NsEnable, |
| 704 | NsDisable, NsSetParameter, NsGetParameter, NULL}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 705 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 706 | static const preproc_ops_t* sPreProcOps[PREPROC_NUM_EFFECTS] = {&sAgcOps, |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 707 | &sAgc2Ops, |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 708 | &sAecOps, &sNsOps}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 709 | |
| 710 | //------------------------------------------------------------------------------ |
| 711 | // Effect functions |
| 712 | //------------------------------------------------------------------------------ |
| 713 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 714 | void Session_SetProcEnabled(preproc_session_t* session, uint32_t procId, bool enabled); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 715 | |
| 716 | extern "C" const struct effect_interface_s sEffectInterface; |
| 717 | extern "C" const struct effect_interface_s sEffectInterfaceReverse; |
| 718 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 719 | #define BAD_STATE_ABORT(from, to) LOG_ALWAYS_FATAL("Bad state transition from %d to %d", from, to); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 720 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 721 | int Effect_SetState(preproc_effect_t* effect, uint32_t state) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 722 | int status = 0; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 723 | ALOGV("Effect_SetState proc %d, new %d old %d", effect->procId, state, effect->state); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 724 | switch (state) { |
| 725 | case PREPROC_EFFECT_STATE_INIT: |
| 726 | switch (effect->state) { |
| 727 | case PREPROC_EFFECT_STATE_ACTIVE: |
| 728 | effect->ops->disable(effect); |
| 729 | Session_SetProcEnabled(effect->session, effect->procId, false); |
| 730 | break; |
| 731 | case PREPROC_EFFECT_STATE_CONFIG: |
| 732 | case PREPROC_EFFECT_STATE_CREATED: |
| 733 | case PREPROC_EFFECT_STATE_INIT: |
| 734 | break; |
| 735 | default: |
| 736 | BAD_STATE_ABORT(effect->state, state); |
| 737 | } |
| 738 | break; |
| 739 | case PREPROC_EFFECT_STATE_CREATED: |
| 740 | switch (effect->state) { |
| 741 | case PREPROC_EFFECT_STATE_INIT: |
| 742 | status = effect->ops->create(effect); |
| 743 | break; |
| 744 | case PREPROC_EFFECT_STATE_CREATED: |
| 745 | case PREPROC_EFFECT_STATE_ACTIVE: |
| 746 | case PREPROC_EFFECT_STATE_CONFIG: |
| 747 | ALOGE("Effect_SetState invalid transition"); |
| 748 | status = -ENOSYS; |
| 749 | break; |
| 750 | default: |
| 751 | BAD_STATE_ABORT(effect->state, state); |
| 752 | } |
Andy Hung | 320fd85 | 2018-10-09 14:06:37 -0700 | [diff] [blame] | 753 | break; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 754 | case PREPROC_EFFECT_STATE_CONFIG: |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 755 | switch (effect->state) { |
| 756 | case PREPROC_EFFECT_STATE_INIT: |
| 757 | ALOGE("Effect_SetState invalid transition"); |
| 758 | status = -ENOSYS; |
| 759 | break; |
| 760 | case PREPROC_EFFECT_STATE_ACTIVE: |
| 761 | effect->ops->disable(effect); |
| 762 | Session_SetProcEnabled(effect->session, effect->procId, false); |
| 763 | break; |
| 764 | case PREPROC_EFFECT_STATE_CREATED: |
| 765 | case PREPROC_EFFECT_STATE_CONFIG: |
| 766 | break; |
| 767 | default: |
| 768 | BAD_STATE_ABORT(effect->state, state); |
| 769 | } |
| 770 | break; |
| 771 | case PREPROC_EFFECT_STATE_ACTIVE: |
| 772 | switch (effect->state) { |
| 773 | case PREPROC_EFFECT_STATE_INIT: |
| 774 | case PREPROC_EFFECT_STATE_CREATED: |
| 775 | ALOGE("Effect_SetState invalid transition"); |
| 776 | status = -ENOSYS; |
| 777 | break; |
| 778 | case PREPROC_EFFECT_STATE_ACTIVE: |
| 779 | // enabling an already enabled effect is just ignored |
| 780 | break; |
| 781 | case PREPROC_EFFECT_STATE_CONFIG: |
| 782 | effect->ops->enable(effect); |
| 783 | Session_SetProcEnabled(effect->session, effect->procId, true); |
| 784 | break; |
| 785 | default: |
| 786 | BAD_STATE_ABORT(effect->state, state); |
| 787 | } |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 788 | break; |
| 789 | default: |
| 790 | BAD_STATE_ABORT(effect->state, state); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 791 | } |
| 792 | if (status == 0) { |
| 793 | effect->state = state; |
| 794 | } |
| 795 | return status; |
| 796 | } |
| 797 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 798 | int Effect_Init(preproc_effect_t* effect, uint32_t procId) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 799 | if (HasReverseStream(procId)) { |
| 800 | effect->itfe = &sEffectInterfaceReverse; |
| 801 | } else { |
| 802 | effect->itfe = &sEffectInterface; |
| 803 | } |
| 804 | effect->ops = sPreProcOps[procId]; |
| 805 | effect->procId = procId; |
| 806 | effect->state = PREPROC_EFFECT_STATE_INIT; |
| 807 | return 0; |
| 808 | } |
| 809 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 810 | int Effect_Create(preproc_effect_t* effect, preproc_session_t* session, |
| 811 | effect_handle_t* interface) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 812 | effect->session = session; |
| 813 | *interface = (effect_handle_t)&effect->itfe; |
| 814 | return Effect_SetState(effect, PREPROC_EFFECT_STATE_CREATED); |
| 815 | } |
| 816 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 817 | int Effect_Release(preproc_effect_t* effect) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 818 | return Effect_SetState(effect, PREPROC_EFFECT_STATE_INIT); |
| 819 | } |
| 820 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 821 | //------------------------------------------------------------------------------ |
| 822 | // Session functions |
| 823 | //------------------------------------------------------------------------------ |
| 824 | |
| 825 | #define RESAMPLER_QUALITY SPEEX_RESAMPLER_QUALITY_VOIP |
| 826 | |
| 827 | static const int kPreprocDefaultSr = 16000; |
| 828 | static const int kPreProcDefaultCnl = 1; |
| 829 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 830 | int Session_Init(preproc_session_t* session) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 831 | size_t i; |
| 832 | int status = 0; |
| 833 | |
| 834 | session->state = PREPROC_SESSION_STATE_INIT; |
| 835 | session->id = 0; |
| 836 | session->io = 0; |
| 837 | session->createdMsk = 0; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 838 | for (i = 0; i < PREPROC_NUM_EFFECTS && status == 0; i++) { |
| 839 | status = Effect_Init(&session->effects[i], i); |
| 840 | } |
| 841 | return status; |
| 842 | } |
| 843 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 844 | extern "C" int Session_CreateEffect(preproc_session_t* session, int32_t procId, |
| 845 | effect_handle_t* interface) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 846 | int status = -ENOMEM; |
| 847 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 848 | ALOGV("Session_CreateEffect procId %d, createdMsk %08x", procId, session->createdMsk); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 849 | |
| 850 | if (session->createdMsk == 0) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 851 | session->apm = session->ap_builder.Create(); |
| 852 | if (session->apm == NULL) { |
| 853 | ALOGW("Session_CreateEffect could not get apm engine"); |
| 854 | goto error; |
| 855 | } |
Harish Mahendrakar | d510fdd | 2021-03-16 13:26:31 -0700 | [diff] [blame] | 856 | session->frameCount = kPreprocDefaultSr / 100; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 857 | session->samplingRate = kPreprocDefaultSr; |
| 858 | session->inChannelCount = kPreProcDefaultCnl; |
| 859 | session->outChannelCount = kPreProcDefaultCnl; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 860 | session->inputConfig.set_sample_rate_hz(kPreprocDefaultSr); |
| 861 | session->inputConfig.set_num_channels(kPreProcDefaultCnl); |
| 862 | session->outputConfig.set_sample_rate_hz(kPreprocDefaultSr); |
| 863 | session->outputConfig.set_num_channels(kPreProcDefaultCnl); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 864 | session->revChannelCount = kPreProcDefaultCnl; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 865 | session->revConfig.set_sample_rate_hz(kPreprocDefaultSr); |
| 866 | session->revConfig.set_num_channels(kPreProcDefaultCnl); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 867 | session->enabledMsk = 0; |
| 868 | session->processedMsk = 0; |
| 869 | session->revEnabledMsk = 0; |
| 870 | session->revProcessedMsk = 0; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 871 | } |
| 872 | status = Effect_Create(&session->effects[procId], session, interface); |
| 873 | if (status < 0) { |
| 874 | goto error; |
| 875 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 876 | ALOGV("Session_CreateEffect OK"); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 877 | session->createdMsk |= (1 << procId); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 878 | return status; |
| 879 | |
| 880 | error: |
| 881 | if (session->createdMsk == 0) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 882 | delete session->apm; |
| 883 | session->apm = NULL; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 884 | } |
| 885 | return status; |
| 886 | } |
| 887 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 888 | int Session_ReleaseEffect(preproc_session_t* session, preproc_effect_t* fx) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 889 | ALOGW_IF(Effect_Release(fx) != 0, " Effect_Release() failed for proc ID %d", fx->procId); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 890 | session->createdMsk &= ~(1 << fx->procId); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 891 | if (session->createdMsk == 0) { |
Alex Luebs | 9718b7d | 2015-11-24 14:33:14 -0800 | [diff] [blame] | 892 | delete session->apm; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 893 | session->apm = NULL; |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 894 | session->id = 0; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 900 | int Session_SetConfig(preproc_session_t* session, effect_config_t* config) { |
Alex Luebs | 3f11ef0 | 2016-01-15 15:51:58 -0800 | [diff] [blame] | 901 | uint32_t inCnl = audio_channel_count_from_in_mask(config->inputCfg.channels); |
| 902 | uint32_t outCnl = audio_channel_count_from_in_mask(config->outputCfg.channels); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 903 | |
| 904 | if (config->inputCfg.samplingRate != config->outputCfg.samplingRate || |
| 905 | config->inputCfg.format != config->outputCfg.format || |
| 906 | config->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT) { |
| 907 | return -EINVAL; |
| 908 | } |
| 909 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 910 | ALOGV("Session_SetConfig sr %d cnl %08x", config->inputCfg.samplingRate, |
| 911 | config->inputCfg.channels); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 912 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 913 | session->samplingRate = config->inputCfg.samplingRate; |
Harish Mahendrakar | d510fdd | 2021-03-16 13:26:31 -0700 | [diff] [blame] | 914 | session->frameCount = session->samplingRate / 100; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 915 | session->inChannelCount = inCnl; |
| 916 | session->outChannelCount = outCnl; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 917 | session->inputConfig.set_sample_rate_hz(session->samplingRate); |
| 918 | session->inputConfig.set_num_channels(inCnl); |
| 919 | session->outputConfig.set_sample_rate_hz(session->samplingRate); |
| 920 | session->outputConfig.set_num_channels(inCnl); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 921 | |
| 922 | session->revChannelCount = inCnl; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 923 | session->revConfig.set_sample_rate_hz(session->samplingRate); |
| 924 | session->revConfig.set_num_channels(inCnl); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 925 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 926 | session->state = PREPROC_SESSION_STATE_CONFIG; |
| 927 | return 0; |
| 928 | } |
| 929 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 930 | void Session_GetConfig(preproc_session_t* session, effect_config_t* config) { |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 931 | memset(config, 0, sizeof(effect_config_t)); |
| 932 | config->inputCfg.samplingRate = config->outputCfg.samplingRate = session->samplingRate; |
| 933 | config->inputCfg.format = config->outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
Glenn Kasten | ab334fd | 2012-03-14 12:56:06 -0700 | [diff] [blame] | 934 | config->inputCfg.channels = audio_channel_in_mask_from_count(session->inChannelCount); |
| 935 | // "out" doesn't mean output device, so this is the correct API to convert channel count to mask |
| 936 | config->outputCfg.channels = audio_channel_in_mask_from_count(session->outChannelCount); |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 937 | config->inputCfg.mask = config->outputCfg.mask = |
| 938 | (EFFECT_CONFIG_SMP_RATE | EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT); |
| 939 | } |
| 940 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 941 | int Session_SetReverseConfig(preproc_session_t* session, effect_config_t* config) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 942 | if (config->inputCfg.samplingRate != config->outputCfg.samplingRate || |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 943 | config->inputCfg.format != config->outputCfg.format || |
| 944 | config->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 945 | return -EINVAL; |
| 946 | } |
| 947 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 948 | ALOGV("Session_SetReverseConfig sr %d cnl %08x", config->inputCfg.samplingRate, |
| 949 | config->inputCfg.channels); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 950 | |
| 951 | if (session->state < PREPROC_SESSION_STATE_CONFIG) { |
| 952 | return -ENOSYS; |
| 953 | } |
| 954 | if (config->inputCfg.samplingRate != session->samplingRate || |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 955 | config->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 956 | return -EINVAL; |
| 957 | } |
Andy Hung | e541269 | 2014-05-16 11:25:07 -0700 | [diff] [blame] | 958 | uint32_t inCnl = audio_channel_count_from_out_mask(config->inputCfg.channels); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 959 | session->revChannelCount = inCnl; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 960 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 961 | return 0; |
| 962 | } |
| 963 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 964 | void Session_GetReverseConfig(preproc_session_t* session, effect_config_t* config) { |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 965 | memset(config, 0, sizeof(effect_config_t)); |
| 966 | config->inputCfg.samplingRate = config->outputCfg.samplingRate = session->samplingRate; |
| 967 | config->inputCfg.format = config->outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 968 | config->inputCfg.channels = config->outputCfg.channels = |
Glenn Kasten | ab334fd | 2012-03-14 12:56:06 -0700 | [diff] [blame] | 969 | audio_channel_in_mask_from_count(session->revChannelCount); |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 970 | config->inputCfg.mask = config->outputCfg.mask = |
| 971 | (EFFECT_CONFIG_SMP_RATE | EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT); |
| 972 | } |
| 973 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 974 | void Session_SetProcEnabled(preproc_session_t* session, uint32_t procId, bool enabled) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 975 | if (enabled) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 976 | session->enabledMsk |= (1 << procId); |
| 977 | if (HasReverseStream(procId)) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 978 | session->revEnabledMsk |= (1 << procId); |
| 979 | } |
| 980 | } else { |
| 981 | session->enabledMsk &= ~(1 << procId); |
| 982 | if (HasReverseStream(procId)) { |
| 983 | session->revEnabledMsk &= ~(1 << procId); |
| 984 | } |
| 985 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 986 | ALOGV("Session_SetProcEnabled proc %d, enabled %d enabledMsk %08x revEnabledMsk %08x", procId, |
| 987 | enabled, session->enabledMsk, session->revEnabledMsk); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 988 | session->processedMsk = 0; |
| 989 | if (HasReverseStream(procId)) { |
| 990 | session->revProcessedMsk = 0; |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | //------------------------------------------------------------------------------ |
| 995 | // Bundle functions |
| 996 | //------------------------------------------------------------------------------ |
| 997 | |
| 998 | static int sInitStatus = 1; |
| 999 | static preproc_session_t sSessions[PREPROC_NUM_SESSIONS]; |
| 1000 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1001 | preproc_session_t* PreProc_GetSession(int32_t procId, int32_t sessionId, int32_t ioId) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1002 | size_t i; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1003 | for (i = 0; i < PREPROC_NUM_SESSIONS; i++) { |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1004 | if (sSessions[i].id == sessionId) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1005 | if (sSessions[i].createdMsk & (1 << procId)) { |
| 1006 | return NULL; |
| 1007 | } |
| 1008 | return &sSessions[i]; |
| 1009 | } |
| 1010 | } |
| 1011 | for (i = 0; i < PREPROC_NUM_SESSIONS; i++) { |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1012 | if (sSessions[i].id == 0) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1013 | sSessions[i].id = sessionId; |
| 1014 | sSessions[i].io = ioId; |
| 1015 | return &sSessions[i]; |
| 1016 | } |
| 1017 | } |
| 1018 | return NULL; |
| 1019 | } |
| 1020 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1021 | int PreProc_Init() { |
| 1022 | size_t i; |
| 1023 | int status = 0; |
| 1024 | |
| 1025 | if (sInitStatus <= 0) { |
| 1026 | return sInitStatus; |
| 1027 | } |
| 1028 | for (i = 0; i < PREPROC_NUM_SESSIONS && status == 0; i++) { |
| 1029 | status = Session_Init(&sSessions[i]); |
| 1030 | } |
| 1031 | sInitStatus = status; |
| 1032 | return sInitStatus; |
| 1033 | } |
| 1034 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1035 | const effect_descriptor_t* PreProc_GetDescriptor(const effect_uuid_t* uuid) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1036 | size_t i; |
| 1037 | for (i = 0; i < PREPROC_NUM_EFFECTS; i++) { |
| 1038 | if (memcmp(&sDescriptors[i]->uuid, uuid, sizeof(effect_uuid_t)) == 0) { |
| 1039 | return sDescriptors[i]; |
| 1040 | } |
| 1041 | } |
| 1042 | return NULL; |
| 1043 | } |
| 1044 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1045 | extern "C" { |
| 1046 | |
| 1047 | //------------------------------------------------------------------------------ |
| 1048 | // Effect Control Interface Implementation |
| 1049 | //------------------------------------------------------------------------------ |
| 1050 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1051 | int PreProcessingFx_Process(effect_handle_t self, audio_buffer_t* inBuffer, |
| 1052 | audio_buffer_t* outBuffer) { |
| 1053 | preproc_effect_t* effect = (preproc_effect_t*)self; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1054 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1055 | if (effect == NULL) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1056 | ALOGV("PreProcessingFx_Process() ERROR effect == NULL"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1057 | return -EINVAL; |
| 1058 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1059 | preproc_session_t* session = (preproc_session_t*)effect->session; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1060 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1061 | if (inBuffer == NULL || inBuffer->raw == NULL || outBuffer == NULL || outBuffer->raw == NULL) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1062 | ALOGW("PreProcessingFx_Process() ERROR bad pointer"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1063 | return -EINVAL; |
| 1064 | } |
| 1065 | |
Harish Mahendrakar | d510fdd | 2021-03-16 13:26:31 -0700 | [diff] [blame] | 1066 | if (inBuffer->frameCount != outBuffer->frameCount) { |
| 1067 | ALOGW("inBuffer->frameCount %zu is not equal to outBuffer->frameCount %zu", |
| 1068 | inBuffer->frameCount, outBuffer->frameCount); |
| 1069 | return -EINVAL; |
| 1070 | } |
| 1071 | |
| 1072 | if (inBuffer->frameCount != session->frameCount) { |
| 1073 | ALOGW("inBuffer->frameCount %zu != %zu representing 10ms at sampling rate %d", |
| 1074 | inBuffer->frameCount, session->frameCount, session->samplingRate); |
| 1075 | return -EINVAL; |
| 1076 | } |
| 1077 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1078 | session->processedMsk |= (1 << effect->procId); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1079 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1080 | // ALOGV("PreProcessingFx_Process In %d frames enabledMsk %08x processedMsk %08x", |
| 1081 | // inBuffer->frameCount, session->enabledMsk, session->processedMsk); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1082 | if ((session->processedMsk & session->enabledMsk) == session->enabledMsk) { |
| 1083 | effect->session->processedMsk = 0; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 1084 | if (int status = effect->session->apm->ProcessStream( |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1085 | (const int16_t* const)inBuffer->s16, |
| 1086 | (const webrtc::StreamConfig)effect->session->inputConfig, |
| 1087 | (const webrtc::StreamConfig)effect->session->outputConfig, |
| 1088 | (int16_t* const)outBuffer->s16); |
| 1089 | status != 0) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 1090 | ALOGE("Process Stream failed with error %d\n", status); |
| 1091 | return status; |
| 1092 | } |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1093 | return 0; |
| 1094 | } else { |
| 1095 | return -ENODATA; |
| 1096 | } |
| 1097 | } |
| 1098 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1099 | int PreProcessingFx_Command(effect_handle_t self, uint32_t cmdCode, uint32_t cmdSize, |
| 1100 | void* pCmdData, uint32_t* replySize, void* pReplyData) { |
| 1101 | preproc_effect_t* effect = (preproc_effect_t*)self; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1102 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1103 | if (effect == NULL) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1104 | return -EINVAL; |
| 1105 | } |
| 1106 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1107 | // ALOGV("PreProcessingFx_Command: command %d cmdSize %d",cmdCode, cmdSize); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1108 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1109 | switch (cmdCode) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1110 | case EFFECT_CMD_INIT: |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1111 | if (pReplyData == NULL || *replySize != sizeof(int)) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1112 | return -EINVAL; |
| 1113 | } |
| 1114 | if (effect->ops->init) { |
| 1115 | effect->ops->init(effect); |
| 1116 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1117 | *(int*)pReplyData = 0; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1118 | break; |
| 1119 | |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1120 | case EFFECT_CMD_SET_CONFIG: { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1121 | if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) || pReplyData == NULL || |
| 1122 | *replySize != sizeof(int)) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1123 | ALOGV("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1124 | "EFFECT_CMD_SET_CONFIG: ERROR"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1125 | return -EINVAL; |
| 1126 | } |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1127 | #ifdef DUAL_MIC_TEST |
| 1128 | // make sure that the config command is accepted by making as if all effects were |
| 1129 | // disabled: this is OK for functional tests |
| 1130 | uint32_t enabledMsk = effect->session->enabledMsk; |
| 1131 | if (gDualMicEnabled) { |
| 1132 | effect->session->enabledMsk = 0; |
| 1133 | } |
| 1134 | #endif |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1135 | *(int*)pReplyData = Session_SetConfig(effect->session, (effect_config_t*)pCmdData); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1136 | #ifdef DUAL_MIC_TEST |
| 1137 | if (gDualMicEnabled) { |
| 1138 | effect->session->enabledMsk = enabledMsk; |
| 1139 | } |
| 1140 | #endif |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1141 | if (*(int*)pReplyData != 0) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1142 | break; |
| 1143 | } |
Eric Laurent | 76533e9 | 2012-02-17 17:52:04 -0800 | [diff] [blame] | 1144 | if (effect->state != PREPROC_EFFECT_STATE_ACTIVE) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1145 | *(int*)pReplyData = Effect_SetState(effect, PREPROC_EFFECT_STATE_CONFIG); |
Eric Laurent | 76533e9 | 2012-02-17 17:52:04 -0800 | [diff] [blame] | 1146 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1147 | } break; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1148 | |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 1149 | case EFFECT_CMD_GET_CONFIG: |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1150 | if (pReplyData == NULL || *replySize != sizeof(effect_config_t)) { |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 1151 | ALOGV("\tLVM_ERROR : PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1152 | "EFFECT_CMD_GET_CONFIG: ERROR"); |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 1153 | return -EINVAL; |
| 1154 | } |
| 1155 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1156 | Session_GetConfig(effect->session, (effect_config_t*)pReplyData); |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 1157 | break; |
| 1158 | |
| 1159 | case EFFECT_CMD_SET_CONFIG_REVERSE: |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1160 | if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) || pReplyData == NULL || |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 1161 | *replySize != sizeof(int)) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1162 | ALOGV("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1163 | "EFFECT_CMD_SET_CONFIG_REVERSE: ERROR"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1164 | return -EINVAL; |
| 1165 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1166 | *(int*)pReplyData = |
| 1167 | Session_SetReverseConfig(effect->session, (effect_config_t*)pCmdData); |
| 1168 | if (*(int*)pReplyData != 0) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1169 | break; |
| 1170 | } |
| 1171 | break; |
| 1172 | |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 1173 | case EFFECT_CMD_GET_CONFIG_REVERSE: |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1174 | if (pReplyData == NULL || *replySize != sizeof(effect_config_t)) { |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 1175 | ALOGV("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1176 | "EFFECT_CMD_GET_CONFIG_REVERSE: ERROR"); |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 1177 | return -EINVAL; |
| 1178 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1179 | Session_GetReverseConfig(effect->session, (effect_config_t*)pCmdData); |
Eric Laurent | 3d5188b | 2011-12-16 15:30:36 -0800 | [diff] [blame] | 1180 | break; |
| 1181 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1182 | case EFFECT_CMD_RESET: |
| 1183 | if (effect->ops->reset) { |
| 1184 | effect->ops->reset(effect); |
| 1185 | } |
| 1186 | break; |
| 1187 | |
Eric Laurent | 0f714a4 | 2015-06-19 15:33:57 -0700 | [diff] [blame] | 1188 | case EFFECT_CMD_GET_PARAM: { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1189 | effect_param_t* p = (effect_param_t*)pCmdData; |
Eric Laurent | 0f714a4 | 2015-06-19 15:33:57 -0700 | [diff] [blame] | 1190 | |
| 1191 | if (pCmdData == NULL || cmdSize < sizeof(effect_param_t) || |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1192 | cmdSize < (sizeof(effect_param_t) + p->psize) || pReplyData == NULL || |
| 1193 | replySize == NULL || *replySize < (sizeof(effect_param_t) + p->psize)) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1194 | ALOGV("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1195 | "EFFECT_CMD_GET_PARAM: ERROR"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1196 | return -EINVAL; |
| 1197 | } |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1198 | |
| 1199 | memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); |
| 1200 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1201 | p = (effect_param_t*)pReplyData; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1202 | |
| 1203 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 1204 | |
| 1205 | if (effect->ops->get_parameter) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1206 | p->status = |
| 1207 | effect->ops->get_parameter(effect, p->data, &p->vsize, p->data + voffset); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1208 | *replySize = sizeof(effect_param_t) + voffset + p->vsize; |
| 1209 | } |
| 1210 | } break; |
| 1211 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1212 | case EFFECT_CMD_SET_PARAM: { |
| 1213 | if (pCmdData == NULL || cmdSize < sizeof(effect_param_t) || pReplyData == NULL || |
| 1214 | replySize == NULL || *replySize != sizeof(int32_t)) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1215 | ALOGV("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1216 | "EFFECT_CMD_SET_PARAM: ERROR"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1217 | return -EINVAL; |
| 1218 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1219 | effect_param_t* p = (effect_param_t*)pCmdData; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1220 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1221 | if (p->psize != sizeof(int32_t)) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1222 | ALOGV("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1223 | "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1224 | return -EINVAL; |
| 1225 | } |
| 1226 | if (effect->ops->set_parameter) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1227 | *(int*)pReplyData = |
| 1228 | effect->ops->set_parameter(effect, (void*)p->data, p->data + p->psize); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1229 | } |
| 1230 | } break; |
| 1231 | |
| 1232 | case EFFECT_CMD_ENABLE: |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1233 | if (pReplyData == NULL || replySize == NULL || *replySize != sizeof(int)) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1234 | ALOGV("PreProcessingFx_Command cmdCode Case: EFFECT_CMD_ENABLE: ERROR"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1235 | return -EINVAL; |
| 1236 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1237 | *(int*)pReplyData = Effect_SetState(effect, PREPROC_EFFECT_STATE_ACTIVE); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1238 | break; |
| 1239 | |
| 1240 | case EFFECT_CMD_DISABLE: |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1241 | if (pReplyData == NULL || replySize == NULL || *replySize != sizeof(int)) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1242 | ALOGV("PreProcessingFx_Command cmdCode Case: EFFECT_CMD_DISABLE: ERROR"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1243 | return -EINVAL; |
| 1244 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1245 | *(int*)pReplyData = Effect_SetState(effect, PREPROC_EFFECT_STATE_CONFIG); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1246 | break; |
| 1247 | |
| 1248 | case EFFECT_CMD_SET_DEVICE: |
| 1249 | case EFFECT_CMD_SET_INPUT_DEVICE: |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1250 | if (pCmdData == NULL || cmdSize != sizeof(uint32_t)) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1251 | ALOGV("PreProcessingFx_Command cmdCode Case: EFFECT_CMD_SET_DEVICE: ERROR"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1252 | return -EINVAL; |
| 1253 | } |
| 1254 | |
| 1255 | if (effect->ops->set_device) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1256 | effect->ops->set_device(effect, *(uint32_t*)pCmdData); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1257 | } |
| 1258 | break; |
| 1259 | |
| 1260 | case EFFECT_CMD_SET_VOLUME: |
| 1261 | case EFFECT_CMD_SET_AUDIO_MODE: |
| 1262 | break; |
| 1263 | |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1264 | #ifdef DUAL_MIC_TEST |
| 1265 | ///// test commands start |
| 1266 | case PREPROC_CMD_DUAL_MIC_ENABLE: { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1267 | if (pCmdData == NULL || cmdSize != sizeof(uint32_t) || pReplyData == NULL || |
| 1268 | replySize == NULL) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1269 | ALOGE("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1270 | "PREPROC_CMD_DUAL_MIC_ENABLE: ERROR"); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1271 | *replySize = 0; |
| 1272 | return -EINVAL; |
| 1273 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1274 | gDualMicEnabled = *(bool*)pCmdData; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1275 | if (gDualMicEnabled) { |
| 1276 | effect->aux_channels_on = sHasAuxChannels[effect->procId]; |
| 1277 | } else { |
| 1278 | effect->aux_channels_on = false; |
| 1279 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1280 | effect->cur_channel_config = |
| 1281 | (effect->session->inChannelCount == 1) ? CHANNEL_CFG_MONO : CHANNEL_CFG_STEREO; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1282 | |
| 1283 | ALOGV("PREPROC_CMD_DUAL_MIC_ENABLE: %s", gDualMicEnabled ? "enabled" : "disabled"); |
| 1284 | *replySize = sizeof(int); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1285 | *(int*)pReplyData = 0; |
| 1286 | } break; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1287 | case PREPROC_CMD_DUAL_MIC_PCM_DUMP_START: { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1288 | if (pCmdData == NULL || pReplyData == NULL || replySize == NULL) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1289 | ALOGE("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1290 | "PREPROC_CMD_DUAL_MIC_PCM_DUMP_START: ERROR"); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1291 | *replySize = 0; |
| 1292 | return -EINVAL; |
| 1293 | } |
| 1294 | pthread_mutex_lock(&gPcmDumpLock); |
| 1295 | if (gPcmDumpFh != NULL) { |
| 1296 | fclose(gPcmDumpFh); |
| 1297 | gPcmDumpFh = NULL; |
| 1298 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1299 | char* path = strndup((char*)pCmdData, cmdSize); |
| 1300 | gPcmDumpFh = fopen((char*)path, "wb"); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1301 | pthread_mutex_unlock(&gPcmDumpLock); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1302 | ALOGV("PREPROC_CMD_DUAL_MIC_PCM_DUMP_START: path %s gPcmDumpFh %p", path, gPcmDumpFh); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1303 | ALOGE_IF(gPcmDumpFh <= 0, "gPcmDumpFh open error %d %s", errno, strerror(errno)); |
| 1304 | free(path); |
| 1305 | *replySize = sizeof(int); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1306 | *(int*)pReplyData = 0; |
| 1307 | } break; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1308 | case PREPROC_CMD_DUAL_MIC_PCM_DUMP_STOP: { |
| 1309 | if (pReplyData == NULL || replySize == NULL) { |
| 1310 | ALOGE("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1311 | "PREPROC_CMD_DUAL_MIC_PCM_DUMP_STOP: ERROR"); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1312 | *replySize = 0; |
| 1313 | return -EINVAL; |
| 1314 | } |
| 1315 | pthread_mutex_lock(&gPcmDumpLock); |
| 1316 | if (gPcmDumpFh != NULL) { |
| 1317 | fclose(gPcmDumpFh); |
| 1318 | gPcmDumpFh = NULL; |
| 1319 | } |
| 1320 | pthread_mutex_unlock(&gPcmDumpLock); |
| 1321 | ALOGV("PREPROC_CMD_DUAL_MIC_PCM_DUMP_STOP"); |
| 1322 | *replySize = sizeof(int); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1323 | *(int*)pReplyData = 0; |
| 1324 | } break; |
| 1325 | ///// test commands end |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1326 | |
| 1327 | case EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS: { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1328 | if (!gDualMicEnabled) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1329 | return -EINVAL; |
| 1330 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1331 | if (pCmdData == NULL || cmdSize != 2 * sizeof(uint32_t) || pReplyData == NULL || |
| 1332 | replySize == NULL) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1333 | ALOGE("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1334 | "EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS: ERROR"); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1335 | *replySize = 0; |
| 1336 | return -EINVAL; |
| 1337 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1338 | if (*(uint32_t*)pCmdData != EFFECT_FEATURE_AUX_CHANNELS || !effect->aux_channels_on) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1339 | ALOGV("PreProcessingFx_Command feature EFFECT_FEATURE_AUX_CHANNELS not supported by" |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1340 | " fx %d", |
| 1341 | effect->procId); |
| 1342 | *(uint32_t*)pReplyData = -ENOSYS; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1343 | *replySize = sizeof(uint32_t); |
| 1344 | break; |
| 1345 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1346 | size_t num_configs = *((uint32_t*)pCmdData + 1); |
| 1347 | if (*replySize < (2 * sizeof(uint32_t) + num_configs * sizeof(channel_config_t))) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1348 | *replySize = 0; |
| 1349 | return -EINVAL; |
| 1350 | } |
| 1351 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1352 | *((uint32_t*)pReplyData + 1) = CHANNEL_CFG_CNT; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1353 | if (num_configs < CHANNEL_CFG_CNT || |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1354 | *replySize < (2 * sizeof(uint32_t) + CHANNEL_CFG_CNT * sizeof(channel_config_t))) { |
| 1355 | *(uint32_t*)pReplyData = -ENOMEM; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1356 | } else { |
| 1357 | num_configs = CHANNEL_CFG_CNT; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1358 | *(uint32_t*)pReplyData = 0; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1359 | } |
| 1360 | ALOGV("PreProcessingFx_Command EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS num config %d", |
| 1361 | num_configs); |
| 1362 | |
| 1363 | *replySize = 2 * sizeof(uint32_t) + num_configs * sizeof(channel_config_t); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1364 | *((uint32_t*)pReplyData + 1) = num_configs; |
| 1365 | memcpy((uint32_t*)pReplyData + 2, &sDualMicConfigs, |
| 1366 | num_configs * sizeof(channel_config_t)); |
| 1367 | } break; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1368 | case EFFECT_CMD_GET_FEATURE_CONFIG: |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1369 | if (!gDualMicEnabled) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1370 | return -EINVAL; |
| 1371 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1372 | if (pCmdData == NULL || cmdSize != sizeof(uint32_t) || pReplyData == NULL || |
| 1373 | replySize == NULL || *replySize < sizeof(uint32_t) + sizeof(channel_config_t)) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1374 | ALOGE("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1375 | "EFFECT_CMD_GET_FEATURE_CONFIG: ERROR"); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1376 | return -EINVAL; |
| 1377 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1378 | if (*(uint32_t*)pCmdData != EFFECT_FEATURE_AUX_CHANNELS || !effect->aux_channels_on) { |
| 1379 | *(uint32_t*)pReplyData = -ENOSYS; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1380 | *replySize = sizeof(uint32_t); |
| 1381 | break; |
| 1382 | } |
| 1383 | ALOGV("PreProcessingFx_Command EFFECT_CMD_GET_FEATURE_CONFIG"); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1384 | *(uint32_t*)pReplyData = 0; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1385 | *replySize = sizeof(uint32_t) + sizeof(channel_config_t); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1386 | memcpy((uint32_t*)pReplyData + 1, &sDualMicConfigs[effect->cur_channel_config], |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1387 | sizeof(channel_config_t)); |
| 1388 | break; |
| 1389 | case EFFECT_CMD_SET_FEATURE_CONFIG: { |
| 1390 | ALOGV("PreProcessingFx_Command EFFECT_CMD_SET_FEATURE_CONFIG: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1391 | "gDualMicEnabled %d effect->aux_channels_on %d", |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1392 | gDualMicEnabled, effect->aux_channels_on); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1393 | if (!gDualMicEnabled) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1394 | return -EINVAL; |
| 1395 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1396 | if (pCmdData == NULL || cmdSize != (sizeof(uint32_t) + sizeof(channel_config_t)) || |
| 1397 | pReplyData == NULL || replySize == NULL || *replySize < sizeof(uint32_t)) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1398 | ALOGE("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1399 | "EFFECT_CMD_SET_FEATURE_CONFIG: ERROR\n" |
| 1400 | "pCmdData %p cmdSize %d pReplyData %p replySize %p *replySize %d", |
| 1401 | pCmdData, cmdSize, pReplyData, replySize, replySize ? *replySize : -1); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1402 | return -EINVAL; |
| 1403 | } |
| 1404 | *replySize = sizeof(uint32_t); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1405 | if (*(uint32_t*)pCmdData != EFFECT_FEATURE_AUX_CHANNELS || !effect->aux_channels_on) { |
| 1406 | *(uint32_t*)pReplyData = -ENOSYS; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1407 | ALOGV("PreProcessingFx_Command cmdCode Case: " |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1408 | "EFFECT_CMD_SET_FEATURE_CONFIG: ERROR\n" |
| 1409 | "CmdData %d effect->aux_channels_on %d", |
| 1410 | *(uint32_t*)pCmdData, effect->aux_channels_on); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1411 | break; |
| 1412 | } |
| 1413 | size_t i; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1414 | for (i = 0; i < CHANNEL_CFG_CNT; i++) { |
| 1415 | if (memcmp((uint32_t*)pCmdData + 1, &sDualMicConfigs[i], |
| 1416 | sizeof(channel_config_t)) == 0) { |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1417 | break; |
| 1418 | } |
| 1419 | } |
| 1420 | if (i == CHANNEL_CFG_CNT) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1421 | *(uint32_t*)pReplyData = -EINVAL; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1422 | ALOGW("PreProcessingFx_Command EFFECT_CMD_SET_FEATURE_CONFIG invalid config" |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1423 | "[%08x].[%08x]", |
| 1424 | *((uint32_t*)pCmdData + 1), *((uint32_t*)pCmdData + 2)); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1425 | } else { |
| 1426 | effect->cur_channel_config = i; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1427 | *(uint32_t*)pReplyData = 0; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1428 | ALOGV("PreProcessingFx_Command EFFECT_CMD_SET_FEATURE_CONFIG New config" |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1429 | "[%08x].[%08x]", |
| 1430 | sDualMicConfigs[i].main_channels, sDualMicConfigs[i].aux_channels); |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1431 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1432 | } break; |
Eric Laurent | 3f9c84c | 2012-04-03 15:36:53 -0700 | [diff] [blame] | 1433 | #endif |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1434 | default: |
| 1435 | return -EINVAL; |
| 1436 | } |
| 1437 | return 0; |
| 1438 | } |
| 1439 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1440 | int PreProcessingFx_GetDescriptor(effect_handle_t self, effect_descriptor_t* pDescriptor) { |
| 1441 | preproc_effect_t* effect = (preproc_effect_t*)self; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1442 | |
| 1443 | if (effect == NULL || pDescriptor == NULL) { |
| 1444 | return -EINVAL; |
| 1445 | } |
| 1446 | |
Glenn Kasten | a189a68 | 2012-02-20 12:16:30 -0800 | [diff] [blame] | 1447 | *pDescriptor = *sDescriptors[effect->procId]; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1448 | |
| 1449 | return 0; |
| 1450 | } |
| 1451 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1452 | int PreProcessingFx_ProcessReverse(effect_handle_t self, audio_buffer_t* inBuffer, |
Rivukanta Bhattacharya | 013e02e | 2021-03-12 05:50:55 +0530 | [diff] [blame] | 1453 | audio_buffer_t* outBuffer) { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1454 | preproc_effect_t* effect = (preproc_effect_t*)self; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1455 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1456 | if (effect == NULL) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1457 | ALOGW("PreProcessingFx_ProcessReverse() ERROR effect == NULL"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1458 | return -EINVAL; |
| 1459 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1460 | preproc_session_t* session = (preproc_session_t*)effect->session; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1461 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1462 | if (inBuffer == NULL || inBuffer->raw == NULL) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1463 | ALOGW("PreProcessingFx_ProcessReverse() ERROR bad pointer"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1464 | return -EINVAL; |
| 1465 | } |
| 1466 | |
Harish Mahendrakar | d510fdd | 2021-03-16 13:26:31 -0700 | [diff] [blame] | 1467 | if (inBuffer->frameCount != outBuffer->frameCount) { |
| 1468 | ALOGW("inBuffer->frameCount %zu is not equal to outBuffer->frameCount %zu", |
| 1469 | inBuffer->frameCount, outBuffer->frameCount); |
| 1470 | return -EINVAL; |
| 1471 | } |
| 1472 | |
| 1473 | if (inBuffer->frameCount != session->frameCount) { |
| 1474 | ALOGW("inBuffer->frameCount %zu != %zu representing 10ms at sampling rate %d", |
| 1475 | inBuffer->frameCount, session->frameCount, session->samplingRate); |
| 1476 | return -EINVAL; |
| 1477 | } |
| 1478 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1479 | session->revProcessedMsk |= (1 << effect->procId); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1480 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1481 | // ALOGV("PreProcessingFx_ProcessReverse In %d frames revEnabledMsk %08x revProcessedMsk |
| 1482 | // %08x", |
| 1483 | // inBuffer->frameCount, session->revEnabledMsk, session->revProcessedMsk); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1484 | |
| 1485 | if ((session->revProcessedMsk & session->revEnabledMsk) == session->revEnabledMsk) { |
| 1486 | effect->session->revProcessedMsk = 0; |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 1487 | if (int status = effect->session->apm->ProcessReverseStream( |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1488 | (const int16_t* const)inBuffer->s16, |
| 1489 | (const webrtc::StreamConfig)effect->session->revConfig, |
| 1490 | (const webrtc::StreamConfig)effect->session->revConfig, |
| 1491 | (int16_t* const)outBuffer->s16); |
| 1492 | status != 0) { |
Saketh Sathuvalli | 0833703 | 2020-09-22 21:13:45 +0530 | [diff] [blame] | 1493 | ALOGE("Process Reverse Stream failed with error %d\n", status); |
| 1494 | return status; |
| 1495 | } |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1496 | return 0; |
| 1497 | } else { |
| 1498 | return -ENODATA; |
| 1499 | } |
| 1500 | } |
| 1501 | |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1502 | // effect_handle_t interface implementation for effect |
| 1503 | const struct effect_interface_s sEffectInterface = { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1504 | PreProcessingFx_Process, PreProcessingFx_Command, PreProcessingFx_GetDescriptor, NULL}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1505 | |
| 1506 | const struct effect_interface_s sEffectInterfaceReverse = { |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1507 | PreProcessingFx_Process, PreProcessingFx_Command, PreProcessingFx_GetDescriptor, |
| 1508 | PreProcessingFx_ProcessReverse}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1509 | |
| 1510 | //------------------------------------------------------------------------------ |
| 1511 | // Effect Library Interface Implementation |
| 1512 | //------------------------------------------------------------------------------ |
| 1513 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1514 | int PreProcessingLib_Create(const effect_uuid_t* uuid, int32_t sessionId, int32_t ioId, |
| 1515 | effect_handle_t* pInterface) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1516 | ALOGV("EffectCreate: uuid: %08x session %d IO: %d", uuid->timeLow, sessionId, ioId); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1517 | |
| 1518 | int status; |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1519 | const effect_descriptor_t* desc; |
| 1520 | preproc_session_t* session; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1521 | uint32_t procId; |
| 1522 | |
| 1523 | if (PreProc_Init() != 0) { |
| 1524 | return sInitStatus; |
| 1525 | } |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1526 | desc = PreProc_GetDescriptor(uuid); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1527 | if (desc == NULL) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1528 | ALOGW("EffectCreate: fx not found uuid: %08x", uuid->timeLow); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1529 | return -EINVAL; |
| 1530 | } |
| 1531 | procId = UuidToProcId(&desc->type); |
| 1532 | |
| 1533 | session = PreProc_GetSession(procId, sessionId, ioId); |
| 1534 | if (session == NULL) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1535 | ALOGW("EffectCreate: no more session available"); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1536 | return -EINVAL; |
| 1537 | } |
| 1538 | |
| 1539 | status = Session_CreateEffect(session, procId, pInterface); |
| 1540 | |
| 1541 | if (status < 0 && session->createdMsk == 0) { |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1542 | session->id = 0; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1543 | } |
| 1544 | return status; |
| 1545 | } |
| 1546 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1547 | int PreProcessingLib_Release(effect_handle_t interface) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1548 | ALOGV("EffectRelease start %p", interface); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1549 | if (PreProc_Init() != 0) { |
| 1550 | return sInitStatus; |
| 1551 | } |
| 1552 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1553 | preproc_effect_t* fx = (preproc_effect_t*)interface; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1554 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1555 | if (fx->session->id == 0) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1556 | return -EINVAL; |
| 1557 | } |
| 1558 | return Session_ReleaseEffect(fx->session, fx); |
| 1559 | } |
| 1560 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1561 | int PreProcessingLib_GetDescriptor(const effect_uuid_t* uuid, effect_descriptor_t* pDescriptor) { |
| 1562 | if (pDescriptor == NULL || uuid == NULL) { |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1563 | return -EINVAL; |
| 1564 | } |
| 1565 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1566 | const effect_descriptor_t* desc = PreProc_GetDescriptor(uuid); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1567 | if (desc == NULL) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1568 | ALOGV("PreProcessingLib_GetDescriptor() not found"); |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1569 | return -EINVAL; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1572 | ALOGV("PreProcessingLib_GetDescriptor() got fx %s", desc->name); |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1573 | |
Glenn Kasten | a189a68 | 2012-02-20 12:16:30 -0800 | [diff] [blame] | 1574 | *pDescriptor = *desc; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1575 | return 0; |
| 1576 | } |
| 1577 | |
Marco Nelissen | 7f16b19 | 2012-10-25 16:05:57 -0700 | [diff] [blame] | 1578 | // This is the only symbol that needs to be exported |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1579 | __attribute__((visibility("default"))) audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = { |
| 1580 | .tag = AUDIO_EFFECT_LIBRARY_TAG, |
| 1581 | .version = EFFECT_LIBRARY_API_VERSION, |
| 1582 | .name = "Audio Preprocessing Library", |
| 1583 | .implementor = "The Android Open Source Project", |
| 1584 | .create_effect = PreProcessingLib_Create, |
| 1585 | .release_effect = PreProcessingLib_Release, |
| 1586 | .get_descriptor = PreProcessingLib_GetDescriptor}; |
Eric Laurent | a9390d4 | 2011-06-17 20:17:17 -0700 | [diff] [blame] | 1587 | |
Harish Mahendrakar | b6926c7 | 2020-11-27 15:22:44 -0800 | [diff] [blame] | 1588 | }; // extern "C" |