jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | #define LOG_TAG "EffectProxy" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 20 | #include <assert.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | #include <new> |
Mark Salyzyn | 60d0207 | 2016-09-29 08:48:48 -0700 | [diff] [blame] | 24 | |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 25 | #include <EffectProxy.h> |
Mark Salyzyn | 60d0207 | 2016-09-29 08:48:48 -0700 | [diff] [blame] | 26 | |
| 27 | #include <log/log.h> |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 28 | #include <utils/threads.h> |
Mark Salyzyn | 60d0207 | 2016-09-29 08:48:48 -0700 | [diff] [blame] | 29 | |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 30 | #include <media/EffectsFactoryApi.h> |
| 31 | |
| 32 | namespace android { |
| 33 | // This is a dummy proxy descriptor just to return to Factory during the initial |
| 34 | // GetDescriptor call. Later in the factory, it is replaced with the |
| 35 | // SW sub effect descriptor |
Eric Laurent | 385e750 | 2013-10-04 08:36:52 -0700 | [diff] [blame] | 36 | // proxy UUID af8da7e0-2ca1-11e3-b71d-0002a5d5c51b |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 37 | const effect_descriptor_t gProxyDescriptor = { |
| 38 | EFFECT_UUID_INITIALIZER, // type |
Eric Laurent | 385e750 | 2013-10-04 08:36:52 -0700 | [diff] [blame] | 39 | {0xaf8da7e0, 0x2ca1, 0x11e3, 0xb71d, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, // uuid |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 40 | EFFECT_CONTROL_API_VERSION, //version of effect control API |
| 41 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | |
| 42 | EFFECT_FLAG_VOLUME_CTRL), // effect capability flags |
| 43 | 0, // CPU load |
| 44 | 1, // Data memory |
| 45 | "Proxy", //effect name |
| 46 | "AOSP", //implementor name |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | static const effect_descriptor_t *const gDescriptors[] = |
| 51 | { |
| 52 | &gProxyDescriptor, |
| 53 | }; |
| 54 | |
Eric Laurent | eba9bf7 | 2013-09-27 15:04:26 -0700 | [diff] [blame] | 55 | |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 56 | int EffectProxyCreate(const effect_uuid_t *uuid, |
| 57 | int32_t sessionId, |
| 58 | int32_t ioId, |
| 59 | effect_handle_t *pHandle) { |
| 60 | |
| 61 | effect_descriptor_t* desc; |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 62 | audio_effect_library_t** aeli; |
| 63 | sub_effect_entry_t** sube; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 64 | EffectContext* pContext; |
| 65 | if (pHandle == NULL || uuid == NULL) { |
| 66 | ALOGE("EffectProxyCreate() called with NULL pointer"); |
| 67 | return -EINVAL; |
| 68 | } |
| 69 | ALOGV("EffectProxyCreate start.."); |
| 70 | pContext = new EffectContext; |
| 71 | pContext->sessionId = sessionId; |
| 72 | pContext->ioId = ioId; |
| 73 | pContext->uuid = *uuid; |
| 74 | pContext->common_itfe = &gEffectInterface; |
Eric Laurent | 5d6d86a | 2013-09-20 12:27:32 -0700 | [diff] [blame] | 75 | |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 76 | // The sub effects will be created in effect_command when the first command |
| 77 | // for the effect is received |
| 78 | pContext->eHandle[SUB_FX_HOST] = pContext->eHandle[SUB_FX_OFFLOAD] = NULL; |
| 79 | |
| 80 | // Get the HW and SW sub effect descriptors from the effects factory |
| 81 | desc = new effect_descriptor_t[SUB_FX_COUNT]; |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 82 | aeli = new audio_effect_library_t*[SUB_FX_COUNT]; |
| 83 | sube = new sub_effect_entry_t*[SUB_FX_COUNT]; |
| 84 | pContext->sube = new sub_effect_entry_t*[SUB_FX_COUNT]; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 85 | pContext->desc = new effect_descriptor_t[SUB_FX_COUNT]; |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 86 | pContext->aeli = new audio_effect_library_t*[SUB_FX_COUNT]; |
| 87 | int retValue = EffectGetSubEffects(uuid, sube, SUB_FX_COUNT); |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 88 | // EffectGetSubEffects returns the number of sub-effects copied. |
| 89 | if (retValue != SUB_FX_COUNT) { |
| 90 | ALOGE("EffectCreate() could not get the sub effects"); |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 91 | delete[] sube; |
| 92 | delete[] desc; |
| 93 | delete[] aeli; |
| 94 | delete[] pContext->sube; |
| 95 | delete[] pContext->desc; |
| 96 | delete[] pContext->aeli; |
Caroline Tice | f8dd1bd | 2016-10-18 16:32:13 -0700 | [diff] [blame] | 97 | delete pContext; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 98 | return -EINVAL; |
| 99 | } |
| 100 | // Check which is the HW descriptor and copy the descriptors |
| 101 | // to the Context desc array |
| 102 | // Also check if there is only one HW and one SW descriptor. |
| 103 | // HW descriptor alone has the HW_TUNNEL flag. |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 104 | desc[0] = *(effect_descriptor_t*)(sube[0])->object; |
| 105 | desc[1] = *(effect_descriptor_t*)(sube[1])->object; |
| 106 | aeli[0] = sube[0]->lib->desc; |
| 107 | aeli[1] = sube[1]->lib->desc; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 108 | if ((desc[0].flags & EFFECT_FLAG_HW_ACC_TUNNEL) && |
| 109 | !(desc[1].flags & EFFECT_FLAG_HW_ACC_TUNNEL)) { |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 110 | pContext->sube[SUB_FX_OFFLOAD] = sube[0]; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 111 | pContext->desc[SUB_FX_OFFLOAD] = desc[0]; |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 112 | pContext->aeli[SUB_FX_OFFLOAD] = aeli[0]; |
| 113 | pContext->sube[SUB_FX_HOST] = sube[1]; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 114 | pContext->desc[SUB_FX_HOST] = desc[1]; |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 115 | pContext->aeli[SUB_FX_HOST] = aeli[1]; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 116 | } |
| 117 | else if ((desc[1].flags & EFFECT_FLAG_HW_ACC_TUNNEL) && |
| 118 | !(desc[0].flags & EFFECT_FLAG_HW_ACC_TUNNEL)) { |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 119 | pContext->sube[SUB_FX_HOST] = sube[0]; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 120 | pContext->desc[SUB_FX_HOST] = desc[0]; |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 121 | pContext->aeli[SUB_FX_HOST] = aeli[0]; |
| 122 | pContext->sube[SUB_FX_OFFLOAD] = sube[1]; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 123 | pContext->desc[SUB_FX_OFFLOAD] = desc[1]; |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 124 | pContext->aeli[SUB_FX_OFFLOAD] = aeli[1]; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 125 | } |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 126 | delete[] desc; |
| 127 | delete[] aeli; |
| 128 | delete[] sube; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 129 | #if (LOG_NDEBUG == 0) |
| 130 | effect_uuid_t uuid_print = pContext->desc[SUB_FX_HOST].uuid; |
| 131 | ALOGV("EffectCreate() UUID of HOST: %08X-%04X-%04X-%04X-%02X%02X%02X%02X" |
| 132 | "%02X%02X\n",uuid_print.timeLow, uuid_print.timeMid, |
| 133 | uuid_print.timeHiAndVersion, uuid_print.clockSeq, uuid_print.node[0], |
| 134 | uuid_print.node[1], uuid_print.node[2], uuid_print.node[3], |
| 135 | uuid_print.node[4], uuid_print.node[5]); |
| 136 | ALOGV("EffectCreate() UUID of OFFLOAD: %08X-%04X-%04X-%04X-%02X%02X%02X%02X" |
| 137 | "%02X%02X\n", uuid_print.timeLow, uuid_print.timeMid, |
| 138 | uuid_print.timeHiAndVersion, uuid_print.clockSeq, uuid_print.node[0], |
| 139 | uuid_print.node[1], uuid_print.node[2], uuid_print.node[3], |
| 140 | uuid_print.node[4], uuid_print.node[5]); |
| 141 | #endif |
Eric Laurent | 5d6d86a | 2013-09-20 12:27:32 -0700 | [diff] [blame] | 142 | |
| 143 | pContext->replySize = PROXY_REPLY_SIZE_DEFAULT; |
| 144 | pContext->replyData = (char *)malloc(PROXY_REPLY_SIZE_DEFAULT); |
| 145 | |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 146 | *pHandle = (effect_handle_t)pContext; |
| 147 | ALOGV("EffectCreate end"); |
| 148 | return 0; |
| 149 | } //end EffectProxyCreate |
| 150 | |
| 151 | int EffectProxyRelease(effect_handle_t handle) { |
| 152 | EffectContext * pContext = (EffectContext *)handle; |
| 153 | if (pContext == NULL) { |
| 154 | ALOGV("ERROR : EffectRelease called with NULL pointer"); |
| 155 | return -EINVAL; |
| 156 | } |
| 157 | ALOGV("EffectRelease"); |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 158 | delete[] pContext->desc; |
Eric Laurent | 5d6d86a | 2013-09-20 12:27:32 -0700 | [diff] [blame] | 159 | free(pContext->replyData); |
| 160 | |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 161 | if (pContext->eHandle[SUB_FX_HOST]) |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 162 | pContext->aeli[SUB_FX_HOST]->release_effect(pContext->eHandle[SUB_FX_HOST]); |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 163 | if (pContext->eHandle[SUB_FX_OFFLOAD]) |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 164 | pContext->aeli[SUB_FX_OFFLOAD]->release_effect(pContext->eHandle[SUB_FX_OFFLOAD]); |
| 165 | delete[] pContext->aeli; |
| 166 | delete[] pContext->sube; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 167 | delete pContext; |
| 168 | pContext = NULL; |
| 169 | return 0; |
| 170 | } /*end EffectProxyRelease */ |
| 171 | |
| 172 | int EffectProxyGetDescriptor(const effect_uuid_t *uuid, |
| 173 | effect_descriptor_t *pDescriptor) { |
| 174 | const effect_descriptor_t *desc = NULL; |
| 175 | |
| 176 | if (pDescriptor == NULL || uuid == NULL) { |
| 177 | ALOGV("EffectGetDescriptor() called with NULL pointer"); |
| 178 | return -EINVAL; |
| 179 | } |
| 180 | desc = &gProxyDescriptor; |
| 181 | *pDescriptor = *desc; |
| 182 | return 0; |
| 183 | } /* end EffectProxyGetDescriptor */ |
| 184 | |
| 185 | /* Effect Control Interface Implementation: Process */ |
| 186 | int Effect_process(effect_handle_t self, |
| 187 | audio_buffer_t *inBuffer, |
| 188 | audio_buffer_t *outBuffer) { |
| 189 | |
| 190 | EffectContext *pContext = (EffectContext *) self; |
| 191 | int ret = 0; |
| 192 | if (pContext != NULL) { |
| 193 | int index = pContext->index; |
| 194 | // if the index refers to HW , do not do anything. Just return. |
| 195 | if (index == SUB_FX_HOST) { |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 196 | ret = (*pContext->eHandle[index])->process(pContext->eHandle[index], |
| 197 | inBuffer, outBuffer); |
| 198 | } |
| 199 | } |
| 200 | return ret; |
| 201 | } /* end Effect_process */ |
| 202 | |
| 203 | /* Effect Control Interface Implementation: Command */ |
| 204 | int Effect_command(effect_handle_t self, |
| 205 | uint32_t cmdCode, |
| 206 | uint32_t cmdSize, |
| 207 | void *pCmdData, |
| 208 | uint32_t *replySize, |
| 209 | void *pReplyData) { |
| 210 | |
| 211 | EffectContext *pContext = (EffectContext *) self; |
Eric Laurent | eba9bf7 | 2013-09-27 15:04:26 -0700 | [diff] [blame] | 212 | int status = 0; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 213 | if (pContext == NULL) { |
| 214 | ALOGV("Effect_command() Proxy context is NULL"); |
| 215 | return -EINVAL; |
| 216 | } |
| 217 | if (pContext->eHandle[SUB_FX_HOST] == NULL) { |
| 218 | ALOGV("Effect_command() Calling HOST EffectCreate"); |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 219 | status = pContext->aeli[SUB_FX_HOST]->create_effect( |
| 220 | &pContext->desc[SUB_FX_HOST].uuid, |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 221 | pContext->sessionId, pContext->ioId, |
| 222 | &(pContext->eHandle[SUB_FX_HOST])); |
| 223 | if (status != NO_ERROR || (pContext->eHandle[SUB_FX_HOST] == NULL)) { |
| 224 | ALOGV("Effect_command() Error creating SW sub effect"); |
| 225 | return status; |
| 226 | } |
| 227 | } |
| 228 | if (pContext->eHandle[SUB_FX_OFFLOAD] == NULL) { |
| 229 | ALOGV("Effect_command() Calling OFFLOAD EffectCreate"); |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 230 | status = pContext->aeli[SUB_FX_OFFLOAD]->create_effect( |
| 231 | &pContext->desc[SUB_FX_OFFLOAD].uuid, |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 232 | pContext->sessionId, pContext->ioId, |
| 233 | &(pContext->eHandle[SUB_FX_OFFLOAD])); |
| 234 | if (status != NO_ERROR || (pContext->eHandle[SUB_FX_OFFLOAD] == NULL)) { |
| 235 | ALOGV("Effect_command() Error creating HW effect"); |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 236 | pContext->eHandle[SUB_FX_OFFLOAD] = NULL; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 237 | // Do not return error here as SW effect is created |
| 238 | // Return error if the CMD_OFFLOAD sends the index as OFFLOAD |
| 239 | } |
| 240 | pContext->index = SUB_FX_HOST; |
| 241 | } |
| 242 | // EFFECT_CMD_OFFLOAD used to (1) send whether the thread is offload or not |
| 243 | // (2) Send the ioHandle of the effectThread when the effect |
| 244 | // is moved from one type of thread to another. |
| 245 | // pCmdData points to a memory holding effect_offload_param_t structure |
| 246 | if (cmdCode == EFFECT_CMD_OFFLOAD) { |
| 247 | ALOGV("Effect_command() cmdCode = EFFECT_CMD_OFFLOAD"); |
| 248 | if (cmdSize == 0 || pCmdData == NULL) { |
| 249 | ALOGV("effectsOffload: Effect_command: CMD_OFFLOAD has no data"); |
| 250 | *(int*)pReplyData = FAILED_TRANSACTION; |
| 251 | return FAILED_TRANSACTION; |
| 252 | } |
| 253 | effect_offload_param_t* offloadParam = (effect_offload_param_t*)pCmdData; |
| 254 | // Assign the effect context index based on isOffload field of the structure |
| 255 | pContext->index = offloadParam->isOffload ? SUB_FX_OFFLOAD : SUB_FX_HOST; |
| 256 | // if the index is HW and the HW effect is unavailable, return error |
| 257 | // and reset the index to SW |
| 258 | if (pContext->eHandle[pContext->index] == NULL) { |
| 259 | ALOGV("Effect_command()CMD_OFFLOAD sub effect unavailable"); |
| 260 | *(int*)pReplyData = FAILED_TRANSACTION; |
| 261 | return FAILED_TRANSACTION; |
| 262 | } |
| 263 | pContext->ioId = offloadParam->ioHandle; |
| 264 | ALOGV("Effect_command()CMD_OFFLOAD index:%d io %d", pContext->index, pContext->ioId); |
| 265 | // Update the DSP wrapper with the new ioHandle. |
| 266 | // Pass the OFFLOAD command to the wrapper. |
| 267 | // The DSP wrapper needs to handle this CMD |
jpadmana | f90c7e0 | 2013-11-14 17:20:52 +0530 | [diff] [blame] | 268 | if (pContext->eHandle[SUB_FX_OFFLOAD]) { |
| 269 | ALOGV("Effect_command: Calling OFFLOAD command"); |
| 270 | return (*pContext->eHandle[SUB_FX_OFFLOAD])->command( |
| 271 | pContext->eHandle[SUB_FX_OFFLOAD], cmdCode, cmdSize, |
| 272 | pCmdData, replySize, pReplyData); |
| 273 | } |
| 274 | *(int*)pReplyData = NO_ERROR; |
| 275 | ALOGV("Effect_command OFFLOAD return 0, replyData %d", |
| 276 | *(int*)pReplyData); |
| 277 | |
| 278 | return NO_ERROR; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | int index = pContext->index; |
| 282 | if (index != SUB_FX_HOST && index != SUB_FX_OFFLOAD) { |
| 283 | ALOGV("Effect_command: effect index is neither offload nor host"); |
| 284 | return -EINVAL; |
| 285 | } |
Eric Laurent | eba9bf7 | 2013-09-27 15:04:26 -0700 | [diff] [blame] | 286 | |
| 287 | // Getter commands are only sent to the active sub effect. |
Eric Laurent | 5d6d86a | 2013-09-20 12:27:32 -0700 | [diff] [blame] | 288 | int *subStatus[SUB_FX_COUNT]; |
| 289 | uint32_t *subReplySize[SUB_FX_COUNT]; |
| 290 | void *subReplyData[SUB_FX_COUNT]; |
| 291 | uint32_t tmpSize; |
| 292 | int tmpStatus; |
Eric Laurent | eba9bf7 | 2013-09-27 15:04:26 -0700 | [diff] [blame] | 293 | |
Eric Laurent | 5d6d86a | 2013-09-20 12:27:32 -0700 | [diff] [blame] | 294 | // grow temp reply buffer if needed |
| 295 | if (replySize != NULL) { |
| 296 | tmpSize = pContext->replySize; |
| 297 | while (tmpSize < *replySize && tmpSize < PROXY_REPLY_SIZE_MAX) { |
| 298 | tmpSize *= 2; |
Eric Laurent | eba9bf7 | 2013-09-27 15:04:26 -0700 | [diff] [blame] | 299 | } |
Eric Laurent | 5d6d86a | 2013-09-20 12:27:32 -0700 | [diff] [blame] | 300 | if (tmpSize > pContext->replySize) { |
| 301 | ALOGV("Effect_command grow reply buf to %d", tmpSize); |
| 302 | pContext->replyData = (char *)realloc(pContext->replyData, tmpSize); |
| 303 | pContext->replySize = tmpSize; |
Eric Laurent | eba9bf7 | 2013-09-27 15:04:26 -0700 | [diff] [blame] | 304 | } |
Eric Laurent | 5d6d86a | 2013-09-20 12:27:32 -0700 | [diff] [blame] | 305 | if (tmpSize > *replySize) { |
| 306 | tmpSize = *replySize; |
| 307 | } |
| 308 | } else { |
| 309 | tmpSize = 0; |
Eric Laurent | eba9bf7 | 2013-09-27 15:04:26 -0700 | [diff] [blame] | 310 | } |
Eric Laurent | 5d6d86a | 2013-09-20 12:27:32 -0700 | [diff] [blame] | 311 | // tmpSize is now the actual reply size for the non active sub effect |
| 312 | |
| 313 | // Send command to sub effects. The command is sent to all sub effects so that their internal |
| 314 | // state is kept in sync. |
| 315 | // Only the reply from the active sub effect is returned to the caller. The reply from the |
| 316 | // other sub effect is lost in pContext->replyData |
| 317 | for (int i = 0; i < SUB_FX_COUNT; i++) { |
| 318 | if (pContext->eHandle[i] == NULL) { |
| 319 | continue; |
| 320 | } |
| 321 | if (i == index) { |
| 322 | subStatus[i] = &status; |
| 323 | subReplySize[i] = replySize; |
| 324 | subReplyData[i] = pReplyData; |
| 325 | } else { |
| 326 | subStatus[i] = &tmpStatus; |
| 327 | subReplySize[i] = replySize == NULL ? NULL : &tmpSize; |
| 328 | subReplyData[i] = pReplyData == NULL ? NULL : pContext->replyData; |
| 329 | } |
| 330 | *subStatus[i] = (*pContext->eHandle[i])->command( |
| 331 | pContext->eHandle[i], cmdCode, cmdSize, |
| 332 | pCmdData, subReplySize[i], subReplyData[i]); |
| 333 | } |
| 334 | |
Eric Laurent | eba9bf7 | 2013-09-27 15:04:26 -0700 | [diff] [blame] | 335 | return status; |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 336 | } /* end Effect_command */ |
| 337 | |
| 338 | |
| 339 | /* Effect Control Interface Implementation: get_descriptor */ |
| 340 | int Effect_getDescriptor(effect_handle_t self, |
| 341 | effect_descriptor_t *pDescriptor) { |
| 342 | |
| 343 | EffectContext * pContext = (EffectContext *) self; |
| 344 | const effect_descriptor_t *desc; |
| 345 | |
| 346 | ALOGV("Effect_getDescriptor"); |
| 347 | if (pContext == NULL || pDescriptor == NULL) { |
| 348 | ALOGV("Effect_getDescriptor() invalid param"); |
| 349 | return -EINVAL; |
| 350 | } |
| 351 | if (pContext->desc == NULL) { |
| 352 | ALOGV("Effect_getDescriptor() could not get descriptor"); |
| 353 | return -EINVAL; |
| 354 | } |
| 355 | desc = &pContext->desc[SUB_FX_HOST]; |
| 356 | *pDescriptor = *desc; |
| 357 | pDescriptor->uuid = pContext->uuid; // Replace the uuid with the Proxy UUID |
| 358 | // Also set/clear the EFFECT_FLAG_OFFLOAD_SUPPORTED flag based on the sub effects availability |
| 359 | if (pContext->eHandle[SUB_FX_OFFLOAD] != NULL) |
| 360 | pDescriptor->flags |= EFFECT_FLAG_OFFLOAD_SUPPORTED; |
| 361 | else |
| 362 | pDescriptor->flags &= ~EFFECT_FLAG_OFFLOAD_SUPPORTED; |
| 363 | return 0; |
| 364 | } /* end Effect_getDescriptor */ |
| 365 | |
| 366 | } // namespace android |
| 367 | |
| 368 | __attribute__ ((visibility ("default"))) |
| 369 | audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = { |
synergy dev | 9803acb | 2013-12-17 17:48:51 -0800 | [diff] [blame] | 370 | .tag = AUDIO_EFFECT_LIBRARY_TAG, |
| 371 | .version = EFFECT_LIBRARY_API_VERSION, |
| 372 | .name = "Effect Proxy", |
| 373 | .implementor = "AOSP", |
| 374 | .create_effect = android::EffectProxyCreate, |
| 375 | .release_effect = android::EffectProxyRelease, |
| 376 | .get_descriptor = android::EffectProxyGetDescriptor, |
jpadmana | faca05e | 2013-06-04 16:03:29 +0530 | [diff] [blame] | 377 | }; |