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