Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2010, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | #define LOG_TAG "AudioEffect" |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <limits.h> |
| 25 | |
| 26 | #include <private/media/AudioEffectShared.h> |
| 27 | #include <media/AudioEffect.h> |
| 28 | |
| 29 | #include <utils/Log.h> |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 30 | #include <binder/IPCThreadState.h> |
| 31 | |
| 32 | |
| 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | // --------------------------------------------------------------------------- |
| 37 | |
| 38 | AudioEffect::AudioEffect() |
| 39 | : mStatus(NO_INIT) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | |
| 44 | AudioEffect::AudioEffect(const effect_uuid_t *type, |
| 45 | const effect_uuid_t *uuid, |
| 46 | int32_t priority, |
| 47 | effect_callback_t cbf, |
| 48 | void* user, |
| 49 | int sessionId, |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 50 | audio_io_handle_t io |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 51 | ) |
| 52 | : mStatus(NO_INIT) |
| 53 | { |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 54 | mStatus = set(type, uuid, priority, cbf, user, sessionId, io); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | AudioEffect::AudioEffect(const char *typeStr, |
| 58 | const char *uuidStr, |
| 59 | int32_t priority, |
| 60 | effect_callback_t cbf, |
| 61 | void* user, |
| 62 | int sessionId, |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 63 | audio_io_handle_t io |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 64 | ) |
| 65 | : mStatus(NO_INIT) |
| 66 | { |
| 67 | effect_uuid_t type; |
| 68 | effect_uuid_t *pType = NULL; |
| 69 | effect_uuid_t uuid; |
| 70 | effect_uuid_t *pUuid = NULL; |
| 71 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 72 | ALOGV("Constructor string\n - type: %s\n - uuid: %s", typeStr, uuidStr); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 73 | |
| 74 | if (typeStr != NULL) { |
| 75 | if (stringToGuid(typeStr, &type) == NO_ERROR) { |
| 76 | pType = &type; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if (uuidStr != NULL) { |
| 81 | if (stringToGuid(uuidStr, &uuid) == NO_ERROR) { |
| 82 | pUuid = &uuid; |
| 83 | } |
| 84 | } |
| 85 | |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 86 | mStatus = set(pType, pUuid, priority, cbf, user, sessionId, io); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | status_t AudioEffect::set(const effect_uuid_t *type, |
| 90 | const effect_uuid_t *uuid, |
| 91 | int32_t priority, |
| 92 | effect_callback_t cbf, |
| 93 | void* user, |
| 94 | int sessionId, |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 95 | audio_io_handle_t io) |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 96 | { |
| 97 | sp<IEffect> iEffect; |
| 98 | sp<IMemory> cblk; |
| 99 | int enabled; |
| 100 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 101 | ALOGV("set %p mUserData: %p uuid: %p timeLow %08x", this, user, type, type ? type->timeLow : 0); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 102 | |
| 103 | if (mIEffect != 0) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 104 | ALOGW("Effect already in use"); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 105 | return INVALID_OPERATION; |
| 106 | } |
| 107 | |
| 108 | const sp<IAudioFlinger>& audioFlinger = AudioSystem::get_audio_flinger(); |
| 109 | if (audioFlinger == 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 110 | ALOGE("set(): Could not get audioflinger"); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 111 | return NO_INIT; |
| 112 | } |
| 113 | |
| 114 | if (type == NULL && uuid == NULL) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 115 | ALOGW("Must specify at least type or uuid"); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 116 | return BAD_VALUE; |
| 117 | } |
| 118 | |
| 119 | mPriority = priority; |
| 120 | mCbf = cbf; |
| 121 | mUserData = user; |
| 122 | mSessionId = sessionId; |
| 123 | |
| 124 | memset(&mDescriptor, 0, sizeof(effect_descriptor_t)); |
| 125 | memcpy(&mDescriptor.type, EFFECT_UUID_NULL, sizeof(effect_uuid_t)); |
| 126 | memcpy(&mDescriptor.uuid, EFFECT_UUID_NULL, sizeof(effect_uuid_t)); |
| 127 | |
| 128 | if (type != NULL) { |
| 129 | memcpy(&mDescriptor.type, type, sizeof(effect_uuid_t)); |
| 130 | } |
| 131 | if (uuid != NULL) { |
| 132 | memcpy(&mDescriptor.uuid, uuid, sizeof(effect_uuid_t)); |
| 133 | } |
| 134 | |
| 135 | mIEffectClient = new EffectClient(this); |
| 136 | |
| 137 | iEffect = audioFlinger->createEffect(getpid(), (effect_descriptor_t *)&mDescriptor, |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 138 | mIEffectClient, priority, io, mSessionId, &mStatus, &mId, &enabled); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 139 | |
| 140 | if (iEffect == 0 || (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS)) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 141 | ALOGE("set(): AudioFlinger could not create effect, status: %d", mStatus); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 142 | return mStatus; |
| 143 | } |
| 144 | |
| 145 | mEnabled = (volatile int32_t)enabled; |
| 146 | |
| 147 | mIEffect = iEffect; |
| 148 | cblk = iEffect->getCblk(); |
| 149 | if (cblk == 0) { |
| 150 | mStatus = NO_INIT; |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 151 | ALOGE("Could not get control block"); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 152 | return mStatus; |
| 153 | } |
| 154 | |
| 155 | mIEffect = iEffect; |
| 156 | mCblkMemory = cblk; |
| 157 | mCblk = static_cast<effect_param_cblk_t*>(cblk->pointer()); |
| 158 | int bufOffset = ((sizeof(effect_param_cblk_t) - 1) / sizeof(int) + 1) * sizeof(int); |
| 159 | mCblk->buffer = (uint8_t *)mCblk + bufOffset; |
| 160 | |
| 161 | iEffect->asBinder()->linkToDeath(mIEffectClient); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 162 | ALOGV("set() %p OK effect: %s id: %d status %d enabled %d, ", this, mDescriptor.name, mId, mStatus, mEnabled); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 163 | |
| 164 | return mStatus; |
| 165 | } |
| 166 | |
| 167 | |
| 168 | AudioEffect::~AudioEffect() |
| 169 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 170 | ALOGV("Destructor %p", this); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 171 | |
| 172 | if (mStatus == NO_ERROR || mStatus == ALREADY_EXISTS) { |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 173 | if (mIEffect != NULL) { |
| 174 | mIEffect->disconnect(); |
| 175 | mIEffect->asBinder()->unlinkToDeath(mIEffectClient); |
| 176 | } |
| 177 | IPCThreadState::self()->flushCommands(); |
| 178 | } |
| 179 | mIEffect.clear(); |
| 180 | mIEffectClient.clear(); |
| 181 | mCblkMemory.clear(); |
| 182 | } |
| 183 | |
| 184 | |
| 185 | status_t AudioEffect::initCheck() const |
| 186 | { |
| 187 | return mStatus; |
| 188 | } |
| 189 | |
| 190 | // ------------------------------------------------------------------------- |
| 191 | |
| 192 | effect_descriptor_t AudioEffect::descriptor() const |
| 193 | { |
| 194 | return mDescriptor; |
| 195 | } |
| 196 | |
Eric Laurent | df9b81c | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 197 | bool AudioEffect::getEnabled() const |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 198 | { |
| 199 | return (mEnabled != 0); |
| 200 | } |
| 201 | |
Eric Laurent | df9b81c | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 202 | status_t AudioEffect::setEnabled(bool enabled) |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 203 | { |
| 204 | if (mStatus != NO_ERROR) { |
| 205 | return INVALID_OPERATION; |
| 206 | } |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 207 | |
Eric Laurent | f3d6dd0 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 208 | status_t status = NO_ERROR; |
| 209 | |
| 210 | AutoMutex lock(mLock); |
| 211 | if (enabled != mEnabled) { |
| 212 | if (enabled) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 213 | ALOGV("enable %p", this); |
Eric Laurent | f3d6dd0 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 214 | status = mIEffect->enable(); |
| 215 | } else { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 216 | ALOGV("disable %p", this); |
Eric Laurent | f3d6dd0 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 217 | status = mIEffect->disable(); |
Eric Laurent | df9b81c | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 218 | } |
Eric Laurent | f3d6dd0 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 219 | if (status == NO_ERROR) { |
| 220 | mEnabled = enabled; |
Eric Laurent | df9b81c | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 221 | } |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 222 | } |
Eric Laurent | f3d6dd0 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 223 | return status; |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Eric Laurent | a4c72ac | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 226 | status_t AudioEffect::command(uint32_t cmdCode, |
| 227 | uint32_t cmdSize, |
| 228 | void *cmdData, |
| 229 | uint32_t *replySize, |
| 230 | void *replyData) |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 231 | { |
| 232 | if (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 233 | ALOGV("command() bad status %d", mStatus); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 234 | return INVALID_OPERATION; |
| 235 | } |
| 236 | |
Eric Laurent | f3d6dd0 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 237 | if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) { |
| 238 | if (mEnabled == (cmdCode == EFFECT_CMD_ENABLE)) { |
| 239 | return NO_ERROR; |
| 240 | } |
| 241 | if (replySize == NULL || *replySize != sizeof(status_t) || replyData == NULL) { |
| 242 | return BAD_VALUE; |
| 243 | } |
| 244 | mLock.lock(); |
Eric Laurent | 4d3fb50 | 2010-09-24 11:52:04 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Eric Laurent | 2a6b80b | 2010-07-29 23:43:43 -0700 | [diff] [blame] | 247 | status_t status = mIEffect->command(cmdCode, cmdSize, cmdData, replySize, replyData); |
Eric Laurent | 4d3fb50 | 2010-09-24 11:52:04 -0700 | [diff] [blame] | 248 | |
| 249 | if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) { |
Eric Laurent | f3d6dd0 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 250 | if (status == NO_ERROR) { |
| 251 | status = *(status_t *)replyData; |
Eric Laurent | 4d3fb50 | 2010-09-24 11:52:04 -0700 | [diff] [blame] | 252 | } |
Eric Laurent | f3d6dd0 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 253 | if (status == NO_ERROR) { |
| 254 | mEnabled = (cmdCode == EFFECT_CMD_ENABLE); |
Eric Laurent | 4d3fb50 | 2010-09-24 11:52:04 -0700 | [diff] [blame] | 255 | } |
Eric Laurent | f3d6dd0 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 256 | mLock.unlock(); |
Eric Laurent | 2a6b80b | 2010-07-29 23:43:43 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Eric Laurent | 2a6b80b | 2010-07-29 23:43:43 -0700 | [diff] [blame] | 259 | return status; |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | |
| 263 | status_t AudioEffect::setParameter(effect_param_t *param) |
| 264 | { |
| 265 | if (mStatus != NO_ERROR) { |
| 266 | return INVALID_OPERATION; |
| 267 | } |
| 268 | |
| 269 | if (param == NULL || param->psize == 0 || param->vsize == 0) { |
| 270 | return BAD_VALUE; |
| 271 | } |
| 272 | |
Eric Laurent | a4c72ac | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 273 | uint32_t size = sizeof(int); |
| 274 | uint32_t psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize; |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 275 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 276 | ALOGV("setParameter: param: %d, param2: %d", *(int *)param->data, (param->psize == 8) ? *((int *)param->data + 1): -1); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 277 | |
| 278 | return mIEffect->command(EFFECT_CMD_SET_PARAM, sizeof (effect_param_t) + psize, param, &size, ¶m->status); |
| 279 | } |
| 280 | |
| 281 | status_t AudioEffect::setParameterDeferred(effect_param_t *param) |
| 282 | { |
| 283 | if (mStatus != NO_ERROR) { |
| 284 | return INVALID_OPERATION; |
| 285 | } |
| 286 | |
| 287 | if (param == NULL || param->psize == 0 || param->vsize == 0) { |
| 288 | return BAD_VALUE; |
| 289 | } |
| 290 | |
| 291 | Mutex::Autolock _l(mCblk->lock); |
| 292 | |
| 293 | int psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize; |
| 294 | int size = ((sizeof(effect_param_t) + psize - 1) / sizeof(int) + 1) * sizeof(int); |
| 295 | |
| 296 | if (mCblk->clientIndex + size > EFFECT_PARAM_BUFFER_SIZE) { |
| 297 | return NO_MEMORY; |
| 298 | } |
| 299 | int *p = (int *)(mCblk->buffer + mCblk->clientIndex); |
| 300 | *p++ = size; |
| 301 | memcpy(p, param, sizeof(effect_param_t) + psize); |
| 302 | mCblk->clientIndex += size; |
| 303 | |
| 304 | return NO_ERROR; |
| 305 | } |
| 306 | |
| 307 | status_t AudioEffect::setParameterCommit() |
| 308 | { |
| 309 | if (mStatus != NO_ERROR) { |
| 310 | return INVALID_OPERATION; |
| 311 | } |
| 312 | |
| 313 | Mutex::Autolock _l(mCblk->lock); |
| 314 | if (mCblk->clientIndex == 0) { |
| 315 | return INVALID_OPERATION; |
| 316 | } |
Eric Laurent | a4c72ac | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 317 | uint32_t size = 0; |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 318 | return mIEffect->command(EFFECT_CMD_SET_PARAM_COMMIT, 0, NULL, &size, NULL); |
| 319 | } |
| 320 | |
| 321 | status_t AudioEffect::getParameter(effect_param_t *param) |
| 322 | { |
| 323 | if (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS) { |
| 324 | return INVALID_OPERATION; |
| 325 | } |
| 326 | |
| 327 | if (param == NULL || param->psize == 0 || param->vsize == 0) { |
| 328 | return BAD_VALUE; |
| 329 | } |
| 330 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 331 | ALOGV("getParameter: param: %d, param2: %d", *(int *)param->data, (param->psize == 8) ? *((int *)param->data + 1): -1); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 332 | |
Eric Laurent | a4c72ac | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 333 | uint32_t psize = sizeof(effect_param_t) + ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize; |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 334 | |
| 335 | return mIEffect->command(EFFECT_CMD_GET_PARAM, sizeof(effect_param_t) + param->psize, param, &psize, param); |
| 336 | } |
| 337 | |
| 338 | |
| 339 | // ------------------------------------------------------------------------- |
| 340 | |
| 341 | void AudioEffect::binderDied() |
| 342 | { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 343 | ALOGW("IEffect died"); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 344 | mStatus = NO_INIT; |
Glenn Kasten | 3694ec1 | 2012-01-27 16:47:15 -0800 | [diff] [blame] | 345 | if (mCbf != NULL) { |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 346 | status_t status = DEAD_OBJECT; |
| 347 | mCbf(EVENT_ERROR, mUserData, &status); |
| 348 | } |
| 349 | mIEffect.clear(); |
| 350 | } |
| 351 | |
| 352 | // ------------------------------------------------------------------------- |
| 353 | |
| 354 | void AudioEffect::controlStatusChanged(bool controlGranted) |
| 355 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 356 | ALOGV("controlStatusChanged %p control %d callback %p mUserData %p", this, controlGranted, mCbf, mUserData); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 357 | if (controlGranted) { |
| 358 | if (mStatus == ALREADY_EXISTS) { |
| 359 | mStatus = NO_ERROR; |
| 360 | } |
| 361 | } else { |
| 362 | if (mStatus == NO_ERROR) { |
| 363 | mStatus = ALREADY_EXISTS; |
| 364 | } |
| 365 | } |
Glenn Kasten | 3694ec1 | 2012-01-27 16:47:15 -0800 | [diff] [blame] | 366 | if (mCbf != NULL) { |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 367 | mCbf(EVENT_CONTROL_STATUS_CHANGED, mUserData, &controlGranted); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | void AudioEffect::enableStatusChanged(bool enabled) |
| 372 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 373 | ALOGV("enableStatusChanged %p enabled %d mCbf %p", this, enabled, mCbf); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 374 | if (mStatus == ALREADY_EXISTS) { |
Eric Laurent | f3d6dd0 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 375 | mEnabled = enabled; |
Glenn Kasten | 3694ec1 | 2012-01-27 16:47:15 -0800 | [diff] [blame] | 376 | if (mCbf != NULL) { |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 377 | mCbf(EVENT_ENABLE_STATUS_CHANGED, mUserData, &enabled); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
Eric Laurent | a4c72ac | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 382 | void AudioEffect::commandExecuted(uint32_t cmdCode, |
| 383 | uint32_t cmdSize, |
| 384 | void *cmdData, |
| 385 | uint32_t replySize, |
| 386 | void *replyData) |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 387 | { |
| 388 | if (cmdData == NULL || replyData == NULL) { |
| 389 | return; |
| 390 | } |
| 391 | |
Glenn Kasten | 3694ec1 | 2012-01-27 16:47:15 -0800 | [diff] [blame] | 392 | if (mCbf != NULL && cmdCode == EFFECT_CMD_SET_PARAM) { |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 393 | effect_param_t *cmd = (effect_param_t *)cmdData; |
| 394 | cmd->status = *(int32_t *)replyData; |
| 395 | mCbf(EVENT_PARAMETER_CHANGED, mUserData, cmd); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | // ------------------------------------------------------------------------- |
| 400 | |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 401 | status_t AudioEffect::queryNumberEffects(uint32_t *numEffects) |
| 402 | { |
| 403 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 404 | if (af == 0) return PERMISSION_DENIED; |
| 405 | return af->queryNumberEffects(numEffects); |
| 406 | } |
| 407 | |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 408 | status_t AudioEffect::queryEffect(uint32_t index, effect_descriptor_t *descriptor) |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 409 | { |
| 410 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 411 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 412 | return af->queryEffect(index, descriptor); |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | status_t AudioEffect::getEffectDescriptor(effect_uuid_t *uuid, effect_descriptor_t *descriptor) |
| 416 | { |
| 417 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 418 | if (af == 0) return PERMISSION_DENIED; |
| 419 | return af->getEffectDescriptor(uuid, descriptor); |
| 420 | } |
| 421 | |
Eric Laurent | 0f7f4ec | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 422 | |
| 423 | status_t AudioEffect::queryDefaultPreProcessing(int audioSession, |
| 424 | effect_descriptor_t *descriptors, |
| 425 | uint32_t *count) |
| 426 | { |
| 427 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 428 | if (aps == 0) return PERMISSION_DENIED; |
| 429 | return aps->queryDefaultPreProcessing(audioSession, descriptors, count); |
| 430 | } |
Eric Laurent | 948235c | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 431 | // ------------------------------------------------------------------------- |
| 432 | |
| 433 | status_t AudioEffect::stringToGuid(const char *str, effect_uuid_t *guid) |
| 434 | { |
| 435 | if (str == NULL || guid == NULL) { |
| 436 | return BAD_VALUE; |
| 437 | } |
| 438 | |
| 439 | int tmp[10]; |
| 440 | |
| 441 | if (sscanf(str, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", |
| 442 | tmp, tmp+1, tmp+2, tmp+3, tmp+4, tmp+5, tmp+6, tmp+7, tmp+8, tmp+9) < 10) { |
| 443 | return BAD_VALUE; |
| 444 | } |
| 445 | guid->timeLow = (uint32_t)tmp[0]; |
| 446 | guid->timeMid = (uint16_t)tmp[1]; |
| 447 | guid->timeHiAndVersion = (uint16_t)tmp[2]; |
| 448 | guid->clockSeq = (uint16_t)tmp[3]; |
| 449 | guid->node[0] = (uint8_t)tmp[4]; |
| 450 | guid->node[1] = (uint8_t)tmp[5]; |
| 451 | guid->node[2] = (uint8_t)tmp[6]; |
| 452 | guid->node[3] = (uint8_t)tmp[7]; |
| 453 | guid->node[4] = (uint8_t)tmp[8]; |
| 454 | guid->node[5] = (uint8_t)tmp[9]; |
| 455 | |
| 456 | return NO_ERROR; |
| 457 | } |
| 458 | |
| 459 | status_t AudioEffect::guidToString(const effect_uuid_t *guid, char *str, size_t maxLen) |
| 460 | { |
| 461 | if (guid == NULL || str == NULL) { |
| 462 | return BAD_VALUE; |
| 463 | } |
| 464 | |
| 465 | snprintf(str, maxLen, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", |
| 466 | guid->timeLow, |
| 467 | guid->timeMid, |
| 468 | guid->timeHiAndVersion, |
| 469 | guid->clockSeq, |
| 470 | guid->node[0], |
| 471 | guid->node[1], |
| 472 | guid->node[2], |
| 473 | guid->node[3], |
| 474 | guid->node[4], |
| 475 | guid->node[5]); |
| 476 | |
| 477 | return NO_ERROR; |
| 478 | } |
| 479 | |
| 480 | |
| 481 | }; // namespace android |
| 482 | |