blob: a5f9ab6874aa6c9283860e8573dab77cc6a29b4d [file] [log] [blame]
Eric Laurent801a1182010-06-09 00:17:29 -07001/*
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 Laurent801a1182010-06-09 00:17:29 -070030#include <binder/IPCThreadState.h>
31
32
33
34namespace android {
35
36// ---------------------------------------------------------------------------
37
Svet Ganovbe71aa22015-04-28 12:06:02 -070038AudioEffect::AudioEffect(const String16& opPackageName)
39 : mStatus(NO_INIT), mOpPackageName(opPackageName)
Eric Laurent801a1182010-06-09 00:17:29 -070040{
41}
42
43
44AudioEffect::AudioEffect(const effect_uuid_t *type,
Svet Ganovbe71aa22015-04-28 12:06:02 -070045 const String16& opPackageName,
Eric Laurent801a1182010-06-09 00:17:29 -070046 const effect_uuid_t *uuid,
47 int32_t priority,
48 effect_callback_t cbf,
49 void* user,
Glenn Kastend848eb42016-03-08 13:42:11 -080050 audio_session_t sessionId,
Eric Laurent7c7f10b2011-06-17 21:29:58 -070051 audio_io_handle_t io
Eric Laurent801a1182010-06-09 00:17:29 -070052 )
Svet Ganovbe71aa22015-04-28 12:06:02 -070053 : mStatus(NO_INIT), mOpPackageName(opPackageName)
Eric Laurent801a1182010-06-09 00:17:29 -070054{
Eric Laurent7c7f10b2011-06-17 21:29:58 -070055 mStatus = set(type, uuid, priority, cbf, user, sessionId, io);
Eric Laurent801a1182010-06-09 00:17:29 -070056}
57
58AudioEffect::AudioEffect(const char *typeStr,
Svet Ganovbe71aa22015-04-28 12:06:02 -070059 const String16& opPackageName,
Eric Laurent801a1182010-06-09 00:17:29 -070060 const char *uuidStr,
61 int32_t priority,
62 effect_callback_t cbf,
63 void* user,
Glenn Kastend848eb42016-03-08 13:42:11 -080064 audio_session_t sessionId,
Eric Laurent7c7f10b2011-06-17 21:29:58 -070065 audio_io_handle_t io
Eric Laurent801a1182010-06-09 00:17:29 -070066 )
Svet Ganovbe71aa22015-04-28 12:06:02 -070067 : mStatus(NO_INIT), mOpPackageName(opPackageName)
Eric Laurent801a1182010-06-09 00:17:29 -070068{
69 effect_uuid_t type;
70 effect_uuid_t *pType = NULL;
71 effect_uuid_t uuid;
72 effect_uuid_t *pUuid = NULL;
73
Steve Block3856b092011-10-20 11:56:00 +010074 ALOGV("Constructor string\n - type: %s\n - uuid: %s", typeStr, uuidStr);
Eric Laurent801a1182010-06-09 00:17:29 -070075
76 if (typeStr != NULL) {
77 if (stringToGuid(typeStr, &type) == NO_ERROR) {
78 pType = &type;
79 }
80 }
81
82 if (uuidStr != NULL) {
83 if (stringToGuid(uuidStr, &uuid) == NO_ERROR) {
84 pUuid = &uuid;
85 }
86 }
87
Eric Laurent7c7f10b2011-06-17 21:29:58 -070088 mStatus = set(pType, pUuid, priority, cbf, user, sessionId, io);
Eric Laurent801a1182010-06-09 00:17:29 -070089}
90
91status_t AudioEffect::set(const effect_uuid_t *type,
92 const effect_uuid_t *uuid,
93 int32_t priority,
94 effect_callback_t cbf,
95 void* user,
Glenn Kastend848eb42016-03-08 13:42:11 -080096 audio_session_t sessionId,
Eric Laurent7c7f10b2011-06-17 21:29:58 -070097 audio_io_handle_t io)
Eric Laurent801a1182010-06-09 00:17:29 -070098{
99 sp<IEffect> iEffect;
100 sp<IMemory> cblk;
101 int enabled;
102
Steve Block3856b092011-10-20 11:56:00 +0100103 ALOGV("set %p mUserData: %p uuid: %p timeLow %08x", this, user, type, type ? type->timeLow : 0);
Eric Laurent801a1182010-06-09 00:17:29 -0700104
105 if (mIEffect != 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000106 ALOGW("Effect already in use");
Eric Laurent801a1182010-06-09 00:17:29 -0700107 return INVALID_OPERATION;
108 }
109
110 const sp<IAudioFlinger>& audioFlinger = AudioSystem::get_audio_flinger();
111 if (audioFlinger == 0) {
Steve Block29357bc2012-01-06 19:20:56 +0000112 ALOGE("set(): Could not get audioflinger");
Eric Laurent801a1182010-06-09 00:17:29 -0700113 return NO_INIT;
114 }
115
116 if (type == NULL && uuid == NULL) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000117 ALOGW("Must specify at least type or uuid");
Eric Laurent801a1182010-06-09 00:17:29 -0700118 return BAD_VALUE;
119 }
120
121 mPriority = priority;
122 mCbf = cbf;
123 mUserData = user;
124 mSessionId = sessionId;
125
126 memset(&mDescriptor, 0, sizeof(effect_descriptor_t));
Glenn Kastena189a682012-02-20 12:16:30 -0800127 mDescriptor.type = *(type != NULL ? type : EFFECT_UUID_NULL);
128 mDescriptor.uuid = *(uuid != NULL ? uuid : EFFECT_UUID_NULL);
Eric Laurent801a1182010-06-09 00:17:29 -0700129
130 mIEffectClient = new EffectClient(this);
Eric Laurentb6436272016-12-07 19:24:50 -0800131 mClientPid = IPCThreadState::self()->getCallingPid();
Eric Laurent801a1182010-06-09 00:17:29 -0700132
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800133 iEffect = audioFlinger->createEffect((effect_descriptor_t *)&mDescriptor,
Eric Laurentb6436272016-12-07 19:24:50 -0800134 mIEffectClient, priority, io, mSessionId, mOpPackageName, mClientPid,
135 &mStatus, &mId, &enabled);
Eric Laurent801a1182010-06-09 00:17:29 -0700136
137 if (iEffect == 0 || (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS)) {
Steve Block29357bc2012-01-06 19:20:56 +0000138 ALOGE("set(): AudioFlinger could not create effect, status: %d", mStatus);
Eric Laurenteecd7652015-06-04 16:20:16 -0700139 if (iEffect == 0) {
140 mStatus = NO_INIT;
141 }
Eric Laurent801a1182010-06-09 00:17:29 -0700142 return mStatus;
143 }
144
145 mEnabled = (volatile int32_t)enabled;
146
Eric Laurent801a1182010-06-09 00:17:29 -0700147 cblk = iEffect->getCblk();
148 if (cblk == 0) {
149 mStatus = NO_INIT;
Steve Block29357bc2012-01-06 19:20:56 +0000150 ALOGE("Could not get control block");
Eric Laurent801a1182010-06-09 00:17:29 -0700151 return mStatus;
152 }
153
Eric Laurenteecd7652015-06-04 16:20:16 -0700154 mIEffect = iEffect;
Eric Laurent801a1182010-06-09 00:17:29 -0700155 mCblkMemory = cblk;
156 mCblk = static_cast<effect_param_cblk_t*>(cblk->pointer());
157 int bufOffset = ((sizeof(effect_param_cblk_t) - 1) / sizeof(int) + 1) * sizeof(int);
158 mCblk->buffer = (uint8_t *)mCblk + bufOffset;
159
Marco Nelissen06b46062014-11-14 07:58:25 -0800160 IInterface::asBinder(iEffect)->linkToDeath(mIEffectClient);
Jean-Michel Trivia0fd9ca2014-09-18 14:07:18 -0700161 ALOGV("set() %p OK effect: %s id: %d status %d enabled %d pid %d", this, mDescriptor.name, mId,
162 mStatus, mEnabled, mClientPid);
163
164 if (mSessionId > AUDIO_SESSION_OUTPUT_MIX) {
165 AudioSystem::acquireAudioSessionId(mSessionId, mClientPid);
166 }
Eric Laurent801a1182010-06-09 00:17:29 -0700167
168 return mStatus;
169}
170
171
172AudioEffect::~AudioEffect()
173{
Steve Block3856b092011-10-20 11:56:00 +0100174 ALOGV("Destructor %p", this);
Eric Laurent801a1182010-06-09 00:17:29 -0700175
176 if (mStatus == NO_ERROR || mStatus == ALREADY_EXISTS) {
Jean-Michel Trivia0fd9ca2014-09-18 14:07:18 -0700177 if (mSessionId > AUDIO_SESSION_OUTPUT_MIX) {
178 AudioSystem::releaseAudioSessionId(mSessionId, mClientPid);
179 }
Eric Laurent801a1182010-06-09 00:17:29 -0700180 if (mIEffect != NULL) {
181 mIEffect->disconnect();
Marco Nelissen06b46062014-11-14 07:58:25 -0800182 IInterface::asBinder(mIEffect)->unlinkToDeath(mIEffectClient);
Eric Laurent801a1182010-06-09 00:17:29 -0700183 }
Eric Laurenteecd7652015-06-04 16:20:16 -0700184 mIEffect.clear();
185 mCblkMemory.clear();
186 mIEffectClient.clear();
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700187 IPCThreadState::self()->flushCommands();
Eric Laurent801a1182010-06-09 00:17:29 -0700188 }
Eric Laurent801a1182010-06-09 00:17:29 -0700189}
190
191
192status_t AudioEffect::initCheck() const
193{
194 return mStatus;
195}
196
197// -------------------------------------------------------------------------
198
199effect_descriptor_t AudioEffect::descriptor() const
200{
201 return mDescriptor;
202}
203
Eric Laurentda7581b2010-07-02 08:12:41 -0700204bool AudioEffect::getEnabled() const
Eric Laurent801a1182010-06-09 00:17:29 -0700205{
206 return (mEnabled != 0);
207}
208
Eric Laurentda7581b2010-07-02 08:12:41 -0700209status_t AudioEffect::setEnabled(bool enabled)
Eric Laurent801a1182010-06-09 00:17:29 -0700210{
211 if (mStatus != NO_ERROR) {
Glenn Kastenf063b492012-02-17 16:24:10 -0800212 return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700213 }
Eric Laurent801a1182010-06-09 00:17:29 -0700214
Eric Laurentf5aafb22010-11-18 08:40:16 -0800215 status_t status = NO_ERROR;
216
217 AutoMutex lock(mLock);
218 if (enabled != mEnabled) {
219 if (enabled) {
Steve Block3856b092011-10-20 11:56:00 +0100220 ALOGV("enable %p", this);
Eric Laurentf5aafb22010-11-18 08:40:16 -0800221 status = mIEffect->enable();
222 } else {
Steve Block3856b092011-10-20 11:56:00 +0100223 ALOGV("disable %p", this);
Eric Laurentf5aafb22010-11-18 08:40:16 -0800224 status = mIEffect->disable();
Eric Laurentda7581b2010-07-02 08:12:41 -0700225 }
Eric Laurentf5aafb22010-11-18 08:40:16 -0800226 if (status == NO_ERROR) {
227 mEnabled = enabled;
Eric Laurentda7581b2010-07-02 08:12:41 -0700228 }
Eric Laurent801a1182010-06-09 00:17:29 -0700229 }
Eric Laurentf5aafb22010-11-18 08:40:16 -0800230 return status;
Eric Laurent801a1182010-06-09 00:17:29 -0700231}
232
Eric Laurent25f43952010-07-28 05:40:18 -0700233status_t AudioEffect::command(uint32_t cmdCode,
234 uint32_t cmdSize,
235 void *cmdData,
236 uint32_t *replySize,
237 void *replyData)
Eric Laurent801a1182010-06-09 00:17:29 -0700238{
239 if (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS) {
Steve Block3856b092011-10-20 11:56:00 +0100240 ALOGV("command() bad status %d", mStatus);
John Grossmanaf7d8182012-01-11 12:23:42 -0800241 return mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700242 }
243
Eric Laurentf5aafb22010-11-18 08:40:16 -0800244 if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) {
245 if (mEnabled == (cmdCode == EFFECT_CMD_ENABLE)) {
246 return NO_ERROR;
247 }
248 if (replySize == NULL || *replySize != sizeof(status_t) || replyData == NULL) {
249 return BAD_VALUE;
250 }
251 mLock.lock();
Eric Laurent0fa449c2010-09-24 11:52:04 -0700252 }
253
Eric Laurent8569f0d2010-07-29 23:43:43 -0700254 status_t status = mIEffect->command(cmdCode, cmdSize, cmdData, replySize, replyData);
Eric Laurent0fa449c2010-09-24 11:52:04 -0700255
256 if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) {
Eric Laurentf5aafb22010-11-18 08:40:16 -0800257 if (status == NO_ERROR) {
258 status = *(status_t *)replyData;
Eric Laurent0fa449c2010-09-24 11:52:04 -0700259 }
Eric Laurentf5aafb22010-11-18 08:40:16 -0800260 if (status == NO_ERROR) {
261 mEnabled = (cmdCode == EFFECT_CMD_ENABLE);
Eric Laurent0fa449c2010-09-24 11:52:04 -0700262 }
Eric Laurentf5aafb22010-11-18 08:40:16 -0800263 mLock.unlock();
Eric Laurent8569f0d2010-07-29 23:43:43 -0700264 }
265
Eric Laurent8569f0d2010-07-29 23:43:43 -0700266 return status;
Eric Laurent801a1182010-06-09 00:17:29 -0700267}
268
269
270status_t AudioEffect::setParameter(effect_param_t *param)
271{
272 if (mStatus != NO_ERROR) {
Glenn Kastenf063b492012-02-17 16:24:10 -0800273 return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700274 }
275
276 if (param == NULL || param->psize == 0 || param->vsize == 0) {
277 return BAD_VALUE;
278 }
279
Eric Laurent25f43952010-07-28 05:40:18 -0700280 uint32_t size = sizeof(int);
281 uint32_t psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize;
Eric Laurent801a1182010-06-09 00:17:29 -0700282
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700283 ALOGV("setParameter: param: %d, param2: %d", *(int *)param->data,
284 (param->psize == 8) ? *((int *)param->data + 1): -1);
Eric Laurent801a1182010-06-09 00:17:29 -0700285
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700286 return mIEffect->command(EFFECT_CMD_SET_PARAM, sizeof (effect_param_t) + psize, param, &size,
287 &param->status);
Eric Laurent801a1182010-06-09 00:17:29 -0700288}
289
290status_t AudioEffect::setParameterDeferred(effect_param_t *param)
291{
292 if (mStatus != NO_ERROR) {
Glenn Kastenf063b492012-02-17 16:24:10 -0800293 return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700294 }
295
296 if (param == NULL || param->psize == 0 || param->vsize == 0) {
297 return BAD_VALUE;
298 }
299
300 Mutex::Autolock _l(mCblk->lock);
301
302 int psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize;
303 int size = ((sizeof(effect_param_t) + psize - 1) / sizeof(int) + 1) * sizeof(int);
304
305 if (mCblk->clientIndex + size > EFFECT_PARAM_BUFFER_SIZE) {
306 return NO_MEMORY;
307 }
308 int *p = (int *)(mCblk->buffer + mCblk->clientIndex);
309 *p++ = size;
310 memcpy(p, param, sizeof(effect_param_t) + psize);
311 mCblk->clientIndex += size;
312
313 return NO_ERROR;
314}
315
316status_t AudioEffect::setParameterCommit()
317{
318 if (mStatus != NO_ERROR) {
Glenn Kastenf063b492012-02-17 16:24:10 -0800319 return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700320 }
321
322 Mutex::Autolock _l(mCblk->lock);
323 if (mCblk->clientIndex == 0) {
324 return INVALID_OPERATION;
325 }
Eric Laurent25f43952010-07-28 05:40:18 -0700326 uint32_t size = 0;
Eric Laurent801a1182010-06-09 00:17:29 -0700327 return mIEffect->command(EFFECT_CMD_SET_PARAM_COMMIT, 0, NULL, &size, NULL);
328}
329
330status_t AudioEffect::getParameter(effect_param_t *param)
331{
332 if (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS) {
John Grossmanaf7d8182012-01-11 12:23:42 -0800333 return mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700334 }
335
336 if (param == NULL || param->psize == 0 || param->vsize == 0) {
337 return BAD_VALUE;
338 }
339
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700340 ALOGV("getParameter: param: %d, param2: %d", *(int *)param->data,
341 (param->psize == 8) ? *((int *)param->data + 1): -1);
Eric Laurent801a1182010-06-09 00:17:29 -0700342
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700343 uint32_t psize = sizeof(effect_param_t) + ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) +
344 param->vsize;
Eric Laurent801a1182010-06-09 00:17:29 -0700345
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700346 return mIEffect->command(EFFECT_CMD_GET_PARAM, sizeof(effect_param_t) + param->psize, param,
347 &psize, param);
Eric Laurent801a1182010-06-09 00:17:29 -0700348}
349
350
351// -------------------------------------------------------------------------
352
353void AudioEffect::binderDied()
354{
Steve Block5ff1dd52012-01-05 23:22:43 +0000355 ALOGW("IEffect died");
John Grossmanaf7d8182012-01-11 12:23:42 -0800356 mStatus = DEAD_OBJECT;
Glenn Kastena0d68332012-01-27 16:47:15 -0800357 if (mCbf != NULL) {
Eric Laurent801a1182010-06-09 00:17:29 -0700358 status_t status = DEAD_OBJECT;
359 mCbf(EVENT_ERROR, mUserData, &status);
360 }
361 mIEffect.clear();
362}
363
364// -------------------------------------------------------------------------
365
366void AudioEffect::controlStatusChanged(bool controlGranted)
367{
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700368 ALOGV("controlStatusChanged %p control %d callback %p mUserData %p", this, controlGranted, mCbf,
369 mUserData);
Eric Laurent801a1182010-06-09 00:17:29 -0700370 if (controlGranted) {
371 if (mStatus == ALREADY_EXISTS) {
372 mStatus = NO_ERROR;
373 }
374 } else {
375 if (mStatus == NO_ERROR) {
376 mStatus = ALREADY_EXISTS;
377 }
378 }
Glenn Kastena0d68332012-01-27 16:47:15 -0800379 if (mCbf != NULL) {
Eric Laurent801a1182010-06-09 00:17:29 -0700380 mCbf(EVENT_CONTROL_STATUS_CHANGED, mUserData, &controlGranted);
381 }
382}
383
384void AudioEffect::enableStatusChanged(bool enabled)
385{
Steve Block3856b092011-10-20 11:56:00 +0100386 ALOGV("enableStatusChanged %p enabled %d mCbf %p", this, enabled, mCbf);
Eric Laurent801a1182010-06-09 00:17:29 -0700387 if (mStatus == ALREADY_EXISTS) {
Eric Laurentf5aafb22010-11-18 08:40:16 -0800388 mEnabled = enabled;
Glenn Kastena0d68332012-01-27 16:47:15 -0800389 if (mCbf != NULL) {
Eric Laurent801a1182010-06-09 00:17:29 -0700390 mCbf(EVENT_ENABLE_STATUS_CHANGED, mUserData, &enabled);
391 }
392 }
393}
394
Eric Laurent25f43952010-07-28 05:40:18 -0700395void AudioEffect::commandExecuted(uint32_t cmdCode,
Glenn Kasten0f11b512014-01-31 16:18:54 -0800396 uint32_t cmdSize __unused,
Eric Laurent25f43952010-07-28 05:40:18 -0700397 void *cmdData,
Glenn Kasten0f11b512014-01-31 16:18:54 -0800398 uint32_t replySize __unused,
Eric Laurent25f43952010-07-28 05:40:18 -0700399 void *replyData)
Eric Laurent801a1182010-06-09 00:17:29 -0700400{
401 if (cmdData == NULL || replyData == NULL) {
402 return;
403 }
404
Glenn Kastena0d68332012-01-27 16:47:15 -0800405 if (mCbf != NULL && cmdCode == EFFECT_CMD_SET_PARAM) {
Eric Laurent801a1182010-06-09 00:17:29 -0700406 effect_param_t *cmd = (effect_param_t *)cmdData;
407 cmd->status = *(int32_t *)replyData;
408 mCbf(EVENT_PARAMETER_CHANGED, mUserData, cmd);
409 }
410}
411
412// -------------------------------------------------------------------------
413
Eric Laurent801a1182010-06-09 00:17:29 -0700414status_t AudioEffect::queryNumberEffects(uint32_t *numEffects)
415{
416 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
417 if (af == 0) return PERMISSION_DENIED;
418 return af->queryNumberEffects(numEffects);
419}
420
Eric Laurentffe9c252010-06-23 17:38:20 -0700421status_t AudioEffect::queryEffect(uint32_t index, effect_descriptor_t *descriptor)
Eric Laurent801a1182010-06-09 00:17:29 -0700422{
423 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
424 if (af == 0) return PERMISSION_DENIED;
Eric Laurentffe9c252010-06-23 17:38:20 -0700425 return af->queryEffect(index, descriptor);
Eric Laurent801a1182010-06-09 00:17:29 -0700426}
427
Glenn Kasten5e92a782012-01-30 07:40:52 -0800428status_t AudioEffect::getEffectDescriptor(const effect_uuid_t *uuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800429 effect_descriptor_t *descriptor) /*const*/
Eric Laurent801a1182010-06-09 00:17:29 -0700430{
431 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
432 if (af == 0) return PERMISSION_DENIED;
433 return af->getEffectDescriptor(uuid, descriptor);
434}
435
Eric Laurent57dae992011-07-24 13:36:09 -0700436
Glenn Kastend848eb42016-03-08 13:42:11 -0800437status_t AudioEffect::queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700438 effect_descriptor_t *descriptors,
439 uint32_t *count)
440{
441 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
442 if (aps == 0) return PERMISSION_DENIED;
443 return aps->queryDefaultPreProcessing(audioSession, descriptors, count);
444}
Eric Laurent801a1182010-06-09 00:17:29 -0700445// -------------------------------------------------------------------------
446
447status_t AudioEffect::stringToGuid(const char *str, effect_uuid_t *guid)
448{
449 if (str == NULL || guid == NULL) {
450 return BAD_VALUE;
451 }
452
453 int tmp[10];
454
455 if (sscanf(str, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
456 tmp, tmp+1, tmp+2, tmp+3, tmp+4, tmp+5, tmp+6, tmp+7, tmp+8, tmp+9) < 10) {
457 return BAD_VALUE;
458 }
459 guid->timeLow = (uint32_t)tmp[0];
460 guid->timeMid = (uint16_t)tmp[1];
461 guid->timeHiAndVersion = (uint16_t)tmp[2];
462 guid->clockSeq = (uint16_t)tmp[3];
463 guid->node[0] = (uint8_t)tmp[4];
464 guid->node[1] = (uint8_t)tmp[5];
465 guid->node[2] = (uint8_t)tmp[6];
466 guid->node[3] = (uint8_t)tmp[7];
467 guid->node[4] = (uint8_t)tmp[8];
468 guid->node[5] = (uint8_t)tmp[9];
469
470 return NO_ERROR;
471}
472
473status_t AudioEffect::guidToString(const effect_uuid_t *guid, char *str, size_t maxLen)
474{
475 if (guid == NULL || str == NULL) {
476 return BAD_VALUE;
477 }
478
479 snprintf(str, maxLen, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
480 guid->timeLow,
481 guid->timeMid,
482 guid->timeHiAndVersion,
483 guid->clockSeq,
484 guid->node[0],
485 guid->node[1],
486 guid->node[2],
487 guid->node[3],
488 guid->node[4],
489 guid->node[5]);
490
491 return NO_ERROR;
492}
493
494
Glenn Kasten40bc9062015-03-20 09:09:33 -0700495} // namespace android