blob: bbeb85430e1dc10e64f16926f48125c03e04c539 [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,
50 int 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,
64 int 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,
96 int 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);
131
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800132 iEffect = audioFlinger->createEffect((effect_descriptor_t *)&mDescriptor,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700133 mIEffectClient, priority, io, mSessionId, mOpPackageName, &mStatus, &mId, &enabled);
Eric Laurent801a1182010-06-09 00:17:29 -0700134
135 if (iEffect == 0 || (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS)) {
Steve Block29357bc2012-01-06 19:20:56 +0000136 ALOGE("set(): AudioFlinger could not create effect, status: %d", mStatus);
Eric Laurent801a1182010-06-09 00:17:29 -0700137 return mStatus;
138 }
139
140 mEnabled = (volatile int32_t)enabled;
141
142 mIEffect = iEffect;
143 cblk = iEffect->getCblk();
144 if (cblk == 0) {
145 mStatus = NO_INIT;
Steve Block29357bc2012-01-06 19:20:56 +0000146 ALOGE("Could not get control block");
Eric Laurent801a1182010-06-09 00:17:29 -0700147 return mStatus;
148 }
149
Eric Laurent801a1182010-06-09 00:17:29 -0700150 mCblkMemory = cblk;
151 mCblk = static_cast<effect_param_cblk_t*>(cblk->pointer());
152 int bufOffset = ((sizeof(effect_param_cblk_t) - 1) / sizeof(int) + 1) * sizeof(int);
153 mCblk->buffer = (uint8_t *)mCblk + bufOffset;
154
Marco Nelissen06b46062014-11-14 07:58:25 -0800155 IInterface::asBinder(iEffect)->linkToDeath(mIEffectClient);
Jean-Michel Trivia0fd9ca2014-09-18 14:07:18 -0700156 mClientPid = IPCThreadState::self()->getCallingPid();
157 ALOGV("set() %p OK effect: %s id: %d status %d enabled %d pid %d", this, mDescriptor.name, mId,
158 mStatus, mEnabled, mClientPid);
159
160 if (mSessionId > AUDIO_SESSION_OUTPUT_MIX) {
161 AudioSystem::acquireAudioSessionId(mSessionId, mClientPid);
162 }
Eric Laurent801a1182010-06-09 00:17:29 -0700163
164 return mStatus;
165}
166
167
168AudioEffect::~AudioEffect()
169{
Steve Block3856b092011-10-20 11:56:00 +0100170 ALOGV("Destructor %p", this);
Eric Laurent801a1182010-06-09 00:17:29 -0700171
172 if (mStatus == NO_ERROR || mStatus == ALREADY_EXISTS) {
Jean-Michel Trivia0fd9ca2014-09-18 14:07:18 -0700173 if (mSessionId > AUDIO_SESSION_OUTPUT_MIX) {
174 AudioSystem::releaseAudioSessionId(mSessionId, mClientPid);
175 }
Eric Laurent801a1182010-06-09 00:17:29 -0700176 if (mIEffect != NULL) {
177 mIEffect->disconnect();
Marco Nelissen06b46062014-11-14 07:58:25 -0800178 IInterface::asBinder(mIEffect)->unlinkToDeath(mIEffectClient);
Eric Laurent801a1182010-06-09 00:17:29 -0700179 }
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700180 IPCThreadState::self()->flushCommands();
Eric Laurent801a1182010-06-09 00:17:29 -0700181 }
182 mIEffect.clear();
183 mIEffectClient.clear();
184 mCblkMemory.clear();
185}
186
187
188status_t AudioEffect::initCheck() const
189{
190 return mStatus;
191}
192
193// -------------------------------------------------------------------------
194
195effect_descriptor_t AudioEffect::descriptor() const
196{
197 return mDescriptor;
198}
199
Eric Laurentda7581b2010-07-02 08:12:41 -0700200bool AudioEffect::getEnabled() const
Eric Laurent801a1182010-06-09 00:17:29 -0700201{
202 return (mEnabled != 0);
203}
204
Eric Laurentda7581b2010-07-02 08:12:41 -0700205status_t AudioEffect::setEnabled(bool enabled)
Eric Laurent801a1182010-06-09 00:17:29 -0700206{
207 if (mStatus != NO_ERROR) {
Glenn Kastenf063b492012-02-17 16:24:10 -0800208 return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700209 }
Eric Laurent801a1182010-06-09 00:17:29 -0700210
Eric Laurentf5aafb22010-11-18 08:40:16 -0800211 status_t status = NO_ERROR;
212
213 AutoMutex lock(mLock);
214 if (enabled != mEnabled) {
215 if (enabled) {
Steve Block3856b092011-10-20 11:56:00 +0100216 ALOGV("enable %p", this);
Eric Laurentf5aafb22010-11-18 08:40:16 -0800217 status = mIEffect->enable();
218 } else {
Steve Block3856b092011-10-20 11:56:00 +0100219 ALOGV("disable %p", this);
Eric Laurentf5aafb22010-11-18 08:40:16 -0800220 status = mIEffect->disable();
Eric Laurentda7581b2010-07-02 08:12:41 -0700221 }
Eric Laurentf5aafb22010-11-18 08:40:16 -0800222 if (status == NO_ERROR) {
223 mEnabled = enabled;
Eric Laurentda7581b2010-07-02 08:12:41 -0700224 }
Eric Laurent801a1182010-06-09 00:17:29 -0700225 }
Eric Laurentf5aafb22010-11-18 08:40:16 -0800226 return status;
Eric Laurent801a1182010-06-09 00:17:29 -0700227}
228
Eric Laurent25f43952010-07-28 05:40:18 -0700229status_t AudioEffect::command(uint32_t cmdCode,
230 uint32_t cmdSize,
231 void *cmdData,
232 uint32_t *replySize,
233 void *replyData)
Eric Laurent801a1182010-06-09 00:17:29 -0700234{
235 if (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS) {
Steve Block3856b092011-10-20 11:56:00 +0100236 ALOGV("command() bad status %d", mStatus);
John Grossmanaf7d8182012-01-11 12:23:42 -0800237 return mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700238 }
239
Eric Laurentf5aafb22010-11-18 08:40:16 -0800240 if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) {
241 if (mEnabled == (cmdCode == EFFECT_CMD_ENABLE)) {
242 return NO_ERROR;
243 }
244 if (replySize == NULL || *replySize != sizeof(status_t) || replyData == NULL) {
245 return BAD_VALUE;
246 }
247 mLock.lock();
Eric Laurent0fa449c2010-09-24 11:52:04 -0700248 }
249
Eric Laurent8569f0d2010-07-29 23:43:43 -0700250 status_t status = mIEffect->command(cmdCode, cmdSize, cmdData, replySize, replyData);
Eric Laurent0fa449c2010-09-24 11:52:04 -0700251
252 if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) {
Eric Laurentf5aafb22010-11-18 08:40:16 -0800253 if (status == NO_ERROR) {
254 status = *(status_t *)replyData;
Eric Laurent0fa449c2010-09-24 11:52:04 -0700255 }
Eric Laurentf5aafb22010-11-18 08:40:16 -0800256 if (status == NO_ERROR) {
257 mEnabled = (cmdCode == EFFECT_CMD_ENABLE);
Eric Laurent0fa449c2010-09-24 11:52:04 -0700258 }
Eric Laurentf5aafb22010-11-18 08:40:16 -0800259 mLock.unlock();
Eric Laurent8569f0d2010-07-29 23:43:43 -0700260 }
261
Eric Laurent8569f0d2010-07-29 23:43:43 -0700262 return status;
Eric Laurent801a1182010-06-09 00:17:29 -0700263}
264
265
266status_t AudioEffect::setParameter(effect_param_t *param)
267{
268 if (mStatus != NO_ERROR) {
Glenn Kastenf063b492012-02-17 16:24:10 -0800269 return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700270 }
271
272 if (param == NULL || param->psize == 0 || param->vsize == 0) {
273 return BAD_VALUE;
274 }
275
Eric Laurent25f43952010-07-28 05:40:18 -0700276 uint32_t size = sizeof(int);
277 uint32_t psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize;
Eric Laurent801a1182010-06-09 00:17:29 -0700278
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700279 ALOGV("setParameter: param: %d, param2: %d", *(int *)param->data,
280 (param->psize == 8) ? *((int *)param->data + 1): -1);
Eric Laurent801a1182010-06-09 00:17:29 -0700281
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700282 return mIEffect->command(EFFECT_CMD_SET_PARAM, sizeof (effect_param_t) + psize, param, &size,
283 &param->status);
Eric Laurent801a1182010-06-09 00:17:29 -0700284}
285
286status_t AudioEffect::setParameterDeferred(effect_param_t *param)
287{
288 if (mStatus != NO_ERROR) {
Glenn Kastenf063b492012-02-17 16:24:10 -0800289 return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700290 }
291
292 if (param == NULL || param->psize == 0 || param->vsize == 0) {
293 return BAD_VALUE;
294 }
295
296 Mutex::Autolock _l(mCblk->lock);
297
298 int psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize;
299 int size = ((sizeof(effect_param_t) + psize - 1) / sizeof(int) + 1) * sizeof(int);
300
301 if (mCblk->clientIndex + size > EFFECT_PARAM_BUFFER_SIZE) {
302 return NO_MEMORY;
303 }
304 int *p = (int *)(mCblk->buffer + mCblk->clientIndex);
305 *p++ = size;
306 memcpy(p, param, sizeof(effect_param_t) + psize);
307 mCblk->clientIndex += size;
308
309 return NO_ERROR;
310}
311
312status_t AudioEffect::setParameterCommit()
313{
314 if (mStatus != NO_ERROR) {
Glenn Kastenf063b492012-02-17 16:24:10 -0800315 return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700316 }
317
318 Mutex::Autolock _l(mCblk->lock);
319 if (mCblk->clientIndex == 0) {
320 return INVALID_OPERATION;
321 }
Eric Laurent25f43952010-07-28 05:40:18 -0700322 uint32_t size = 0;
Eric Laurent801a1182010-06-09 00:17:29 -0700323 return mIEffect->command(EFFECT_CMD_SET_PARAM_COMMIT, 0, NULL, &size, NULL);
324}
325
326status_t AudioEffect::getParameter(effect_param_t *param)
327{
328 if (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS) {
John Grossmanaf7d8182012-01-11 12:23:42 -0800329 return mStatus;
Eric Laurent801a1182010-06-09 00:17:29 -0700330 }
331
332 if (param == NULL || param->psize == 0 || param->vsize == 0) {
333 return BAD_VALUE;
334 }
335
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700336 ALOGV("getParameter: param: %d, param2: %d", *(int *)param->data,
337 (param->psize == 8) ? *((int *)param->data + 1): -1);
Eric Laurent801a1182010-06-09 00:17:29 -0700338
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700339 uint32_t psize = sizeof(effect_param_t) + ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) +
340 param->vsize;
Eric Laurent801a1182010-06-09 00:17:29 -0700341
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700342 return mIEffect->command(EFFECT_CMD_GET_PARAM, sizeof(effect_param_t) + param->psize, param,
343 &psize, param);
Eric Laurent801a1182010-06-09 00:17:29 -0700344}
345
346
347// -------------------------------------------------------------------------
348
349void AudioEffect::binderDied()
350{
Steve Block5ff1dd52012-01-05 23:22:43 +0000351 ALOGW("IEffect died");
John Grossmanaf7d8182012-01-11 12:23:42 -0800352 mStatus = DEAD_OBJECT;
Glenn Kastena0d68332012-01-27 16:47:15 -0800353 if (mCbf != NULL) {
Eric Laurent801a1182010-06-09 00:17:29 -0700354 status_t status = DEAD_OBJECT;
355 mCbf(EVENT_ERROR, mUserData, &status);
356 }
357 mIEffect.clear();
358}
359
360// -------------------------------------------------------------------------
361
362void AudioEffect::controlStatusChanged(bool controlGranted)
363{
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700364 ALOGV("controlStatusChanged %p control %d callback %p mUserData %p", this, controlGranted, mCbf,
365 mUserData);
Eric Laurent801a1182010-06-09 00:17:29 -0700366 if (controlGranted) {
367 if (mStatus == ALREADY_EXISTS) {
368 mStatus = NO_ERROR;
369 }
370 } else {
371 if (mStatus == NO_ERROR) {
372 mStatus = ALREADY_EXISTS;
373 }
374 }
Glenn Kastena0d68332012-01-27 16:47:15 -0800375 if (mCbf != NULL) {
Eric Laurent801a1182010-06-09 00:17:29 -0700376 mCbf(EVENT_CONTROL_STATUS_CHANGED, mUserData, &controlGranted);
377 }
378}
379
380void AudioEffect::enableStatusChanged(bool enabled)
381{
Steve Block3856b092011-10-20 11:56:00 +0100382 ALOGV("enableStatusChanged %p enabled %d mCbf %p", this, enabled, mCbf);
Eric Laurent801a1182010-06-09 00:17:29 -0700383 if (mStatus == ALREADY_EXISTS) {
Eric Laurentf5aafb22010-11-18 08:40:16 -0800384 mEnabled = enabled;
Glenn Kastena0d68332012-01-27 16:47:15 -0800385 if (mCbf != NULL) {
Eric Laurent801a1182010-06-09 00:17:29 -0700386 mCbf(EVENT_ENABLE_STATUS_CHANGED, mUserData, &enabled);
387 }
388 }
389}
390
Eric Laurent25f43952010-07-28 05:40:18 -0700391void AudioEffect::commandExecuted(uint32_t cmdCode,
Glenn Kasten0f11b512014-01-31 16:18:54 -0800392 uint32_t cmdSize __unused,
Eric Laurent25f43952010-07-28 05:40:18 -0700393 void *cmdData,
Glenn Kasten0f11b512014-01-31 16:18:54 -0800394 uint32_t replySize __unused,
Eric Laurent25f43952010-07-28 05:40:18 -0700395 void *replyData)
Eric Laurent801a1182010-06-09 00:17:29 -0700396{
397 if (cmdData == NULL || replyData == NULL) {
398 return;
399 }
400
Glenn Kastena0d68332012-01-27 16:47:15 -0800401 if (mCbf != NULL && cmdCode == EFFECT_CMD_SET_PARAM) {
Eric Laurent801a1182010-06-09 00:17:29 -0700402 effect_param_t *cmd = (effect_param_t *)cmdData;
403 cmd->status = *(int32_t *)replyData;
404 mCbf(EVENT_PARAMETER_CHANGED, mUserData, cmd);
405 }
406}
407
408// -------------------------------------------------------------------------
409
Eric Laurent801a1182010-06-09 00:17:29 -0700410status_t AudioEffect::queryNumberEffects(uint32_t *numEffects)
411{
412 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
413 if (af == 0) return PERMISSION_DENIED;
414 return af->queryNumberEffects(numEffects);
415}
416
Eric Laurentffe9c252010-06-23 17:38:20 -0700417status_t AudioEffect::queryEffect(uint32_t index, effect_descriptor_t *descriptor)
Eric Laurent801a1182010-06-09 00:17:29 -0700418{
419 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
420 if (af == 0) return PERMISSION_DENIED;
Eric Laurentffe9c252010-06-23 17:38:20 -0700421 return af->queryEffect(index, descriptor);
Eric Laurent801a1182010-06-09 00:17:29 -0700422}
423
Glenn Kasten5e92a782012-01-30 07:40:52 -0800424status_t AudioEffect::getEffectDescriptor(const effect_uuid_t *uuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800425 effect_descriptor_t *descriptor) /*const*/
Eric Laurent801a1182010-06-09 00:17:29 -0700426{
427 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
428 if (af == 0) return PERMISSION_DENIED;
429 return af->getEffectDescriptor(uuid, descriptor);
430}
431
Eric Laurent57dae992011-07-24 13:36:09 -0700432
433status_t AudioEffect::queryDefaultPreProcessing(int audioSession,
434 effect_descriptor_t *descriptors,
435 uint32_t *count)
436{
437 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
438 if (aps == 0) return PERMISSION_DENIED;
439 return aps->queryDefaultPreProcessing(audioSession, descriptors, count);
440}
Eric Laurent801a1182010-06-09 00:17:29 -0700441// -------------------------------------------------------------------------
442
443status_t AudioEffect::stringToGuid(const char *str, effect_uuid_t *guid)
444{
445 if (str == NULL || guid == NULL) {
446 return BAD_VALUE;
447 }
448
449 int tmp[10];
450
451 if (sscanf(str, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
452 tmp, tmp+1, tmp+2, tmp+3, tmp+4, tmp+5, tmp+6, tmp+7, tmp+8, tmp+9) < 10) {
453 return BAD_VALUE;
454 }
455 guid->timeLow = (uint32_t)tmp[0];
456 guid->timeMid = (uint16_t)tmp[1];
457 guid->timeHiAndVersion = (uint16_t)tmp[2];
458 guid->clockSeq = (uint16_t)tmp[3];
459 guid->node[0] = (uint8_t)tmp[4];
460 guid->node[1] = (uint8_t)tmp[5];
461 guid->node[2] = (uint8_t)tmp[6];
462 guid->node[3] = (uint8_t)tmp[7];
463 guid->node[4] = (uint8_t)tmp[8];
464 guid->node[5] = (uint8_t)tmp[9];
465
466 return NO_ERROR;
467}
468
469status_t AudioEffect::guidToString(const effect_uuid_t *guid, char *str, size_t maxLen)
470{
471 if (guid == NULL || str == NULL) {
472 return BAD_VALUE;
473 }
474
475 snprintf(str, maxLen, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
476 guid->timeLow,
477 guid->timeMid,
478 guid->timeHiAndVersion,
479 guid->clockSeq,
480 guid->node[0],
481 guid->node[1],
482 guid->node[2],
483 guid->node[3],
484 guid->node[4],
485 guid->node[5]);
486
487 return NO_ERROR;
488}
489
490
Glenn Kasten40bc9062015-03-20 09:09:33 -0700491} // namespace android