Eric Laurent | 801a118 | 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 | |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 26 | #include <binder/IPCThreadState.h> |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 27 | #include <media/AudioEffect.h> |
| 28 | #include <media/ShmemCompat.h> |
| 29 | #include <private/media/AudioEffectShared.h> |
| 30 | #include <utils/Log.h> |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 34 | using binder::Status; |
| 35 | |
| 36 | namespace { |
| 37 | |
| 38 | // Copy from a raw pointer + size into a vector of bytes. |
| 39 | void appendToBuffer(const void* data, |
| 40 | size_t size, |
| 41 | std::vector<uint8_t>* buffer) { |
| 42 | const uint8_t* p = reinterpret_cast<const uint8_t*>(data); |
| 43 | buffer->insert(buffer->end(), p, p + size); |
| 44 | } |
| 45 | |
| 46 | } // namespace |
| 47 | |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 48 | // --------------------------------------------------------------------------- |
| 49 | |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 50 | AudioEffect::AudioEffect(const String16& opPackageName) |
Mikhail Naganov | 416fffe | 2020-07-31 17:36:08 -0700 | [diff] [blame] | 51 | : mOpPackageName(opPackageName) |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 55 | status_t AudioEffect::set(const effect_uuid_t *type, |
| 56 | const effect_uuid_t *uuid, |
| 57 | int32_t priority, |
| 58 | effect_callback_t cbf, |
| 59 | void* user, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 60 | audio_session_t sessionId, |
Eric Laurent | 9487603 | 2019-11-13 12:45:28 -0800 | [diff] [blame] | 61 | audio_io_handle_t io, |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 62 | const AudioDeviceTypeAddr& device, |
| 63 | bool probe) |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 64 | { |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 65 | sp<media::IEffect> iEffect; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 66 | sp<IMemory> cblk; |
| 67 | int enabled; |
| 68 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 69 | ALOGV("set %p mUserData: %p uuid: %p timeLow %08x", this, user, type, type ? type->timeLow : 0); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 70 | |
| 71 | if (mIEffect != 0) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 72 | ALOGW("Effect already in use"); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 73 | return INVALID_OPERATION; |
| 74 | } |
| 75 | |
Eric Laurent | 9487603 | 2019-11-13 12:45:28 -0800 | [diff] [blame] | 76 | if (sessionId == AUDIO_SESSION_DEVICE && io != AUDIO_IO_HANDLE_NONE) { |
| 77 | ALOGW("IO handle should not be specified for device effect"); |
| 78 | return BAD_VALUE; |
| 79 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 80 | const sp<IAudioFlinger>& audioFlinger = AudioSystem::get_audio_flinger(); |
| 81 | if (audioFlinger == 0) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 82 | ALOGE("set(): Could not get audioflinger"); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 83 | return NO_INIT; |
| 84 | } |
| 85 | |
| 86 | if (type == NULL && uuid == NULL) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 87 | ALOGW("Must specify at least type or uuid"); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 88 | return BAD_VALUE; |
| 89 | } |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 90 | mProbe = probe; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 91 | mPriority = priority; |
| 92 | mCbf = cbf; |
| 93 | mUserData = user; |
| 94 | mSessionId = sessionId; |
| 95 | |
| 96 | memset(&mDescriptor, 0, sizeof(effect_descriptor_t)); |
Glenn Kasten | a189a68 | 2012-02-20 12:16:30 -0800 | [diff] [blame] | 97 | mDescriptor.type = *(type != NULL ? type : EFFECT_UUID_NULL); |
| 98 | mDescriptor.uuid = *(uuid != NULL ? uuid : EFFECT_UUID_NULL); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 99 | |
| 100 | mIEffectClient = new EffectClient(this); |
Eric Laurent | b643627 | 2016-12-07 19:24:50 -0800 | [diff] [blame] | 101 | mClientPid = IPCThreadState::self()->getCallingPid(); |
Andy Hung | 8b0bfd9 | 2019-12-23 13:11:11 -0800 | [diff] [blame] | 102 | mClientUid = IPCThreadState::self()->getCallingUid(); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 103 | |
Ytai Ben-Tsvi | ce18294 | 2020-11-04 14:48:01 -0800 | [diff] [blame] | 104 | media::CreateEffectRequest request; |
| 105 | request.desc = VALUE_OR_RETURN_STATUS( |
| 106 | legacy2aidl_effect_descriptor_t_EffectDescriptor(mDescriptor)); |
| 107 | request.client = mIEffectClient; |
| 108 | request.priority = priority; |
| 109 | request.output = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(io)); |
| 110 | request.sessionId = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(mSessionId)); |
| 111 | request.device = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioDeviceTypeAddress(device)); |
| 112 | request.opPackageName = VALUE_OR_RETURN_STATUS(legacy2aidl_String16_string(mOpPackageName)); |
| 113 | request.pid = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(mClientPid)); |
| 114 | request.probe = probe; |
| 115 | |
| 116 | media::CreateEffectResponse response; |
| 117 | |
| 118 | mStatus = audioFlinger->createEffect(request, &response); |
| 119 | |
| 120 | if (mStatus == OK) { |
| 121 | mId = response.id; |
| 122 | enabled = response.enabled; |
| 123 | iEffect = response.effect; |
| 124 | mDescriptor = VALUE_OR_RETURN_STATUS( |
| 125 | aidl2legacy_EffectDescriptor_effect_descriptor_t(response.desc)); |
| 126 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 127 | |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 128 | // In probe mode, we stop here and return the status: the IEffect interface to |
| 129 | // audio flinger will not be retained. initCheck() will return the creation status |
| 130 | // but all other APIs will return invalid operation. |
| 131 | if (probe || iEffect == 0 || (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS)) { |
Mikhail Naganov | abd6e9d | 2020-03-23 22:25:56 +0000 | [diff] [blame] | 132 | char typeBuffer[64] = {}, uuidBuffer[64] = {}; |
Mikhail Naganov | 424c4f5 | 2017-07-19 17:54:29 -0700 | [diff] [blame] | 133 | guidToString(type, typeBuffer, sizeof(typeBuffer)); |
| 134 | guidToString(uuid, uuidBuffer, sizeof(uuidBuffer)); |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 135 | ALOGE_IF(!probe, "set(): AudioFlinger could not create effect %s / %s, status: %d", |
Mikhail Naganov | abd6e9d | 2020-03-23 22:25:56 +0000 | [diff] [blame] | 136 | type != nullptr ? typeBuffer : "NULL", |
| 137 | uuid != nullptr ? uuidBuffer : "NULL", |
| 138 | mStatus); |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 139 | if (!probe && iEffect == 0) { |
Eric Laurent | eecd765 | 2015-06-04 16:20:16 -0700 | [diff] [blame] | 140 | mStatus = NO_INIT; |
| 141 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 142 | return mStatus; |
| 143 | } |
| 144 | |
| 145 | mEnabled = (volatile int32_t)enabled; |
| 146 | |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 147 | if (media::SharedFileRegion shmem; |
| 148 | !iEffect->getCblk(&shmem).isOk() |
| 149 | || !convertSharedFileRegionToIMemory(shmem, &cblk) |
| 150 | || cblk == 0) { |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 151 | mStatus = NO_INIT; |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 152 | ALOGE("Could not get control block"); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 153 | return mStatus; |
| 154 | } |
| 155 | |
Eric Laurent | eecd765 | 2015-06-04 16:20:16 -0700 | [diff] [blame] | 156 | mIEffect = iEffect; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 157 | mCblkMemory = cblk; |
Ytai Ben-Tsvi | 7dd3972 | 2019-09-05 15:14:30 -0700 | [diff] [blame] | 158 | // TODO: Using unsecurePointer() has some associated security pitfalls |
| 159 | // (see declaration for details). |
| 160 | // Either document why it is safe in this case or address the |
| 161 | // issue (e.g. by copying). |
| 162 | mCblk = static_cast<effect_param_cblk_t*>(cblk->unsecurePointer()); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 163 | int bufOffset = ((sizeof(effect_param_cblk_t) - 1) / sizeof(int) + 1) * sizeof(int); |
| 164 | mCblk->buffer = (uint8_t *)mCblk + bufOffset; |
| 165 | |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 166 | IInterface::asBinder(iEffect)->linkToDeath(mIEffectClient); |
Jean-Michel Trivi | a0fd9ca | 2014-09-18 14:07:18 -0700 | [diff] [blame] | 167 | ALOGV("set() %p OK effect: %s id: %d status %d enabled %d pid %d", this, mDescriptor.name, mId, |
| 168 | mStatus, mEnabled, mClientPid); |
| 169 | |
Eric Laurent | 3f75a5b | 2019-11-12 15:55:51 -0800 | [diff] [blame] | 170 | if (!audio_is_global_session(mSessionId)) { |
Andy Hung | 8b0bfd9 | 2019-12-23 13:11:11 -0800 | [diff] [blame] | 171 | AudioSystem::acquireAudioSessionId(mSessionId, mClientPid, mClientUid); |
Jean-Michel Trivi | a0fd9ca | 2014-09-18 14:07:18 -0700 | [diff] [blame] | 172 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 173 | |
| 174 | return mStatus; |
| 175 | } |
| 176 | |
Mikhail Naganov | 416fffe | 2020-07-31 17:36:08 -0700 | [diff] [blame] | 177 | status_t AudioEffect::set(const char *typeStr, |
| 178 | const char *uuidStr, |
| 179 | int32_t priority, |
| 180 | effect_callback_t cbf, |
| 181 | void* user, |
| 182 | audio_session_t sessionId, |
| 183 | audio_io_handle_t io, |
| 184 | const AudioDeviceTypeAddr& device, |
| 185 | bool probe) |
| 186 | { |
| 187 | effect_uuid_t type; |
| 188 | effect_uuid_t *pType = nullptr; |
| 189 | effect_uuid_t uuid; |
| 190 | effect_uuid_t *pUuid = nullptr; |
| 191 | |
| 192 | ALOGV("AudioEffect::set string\n - type: %s\n - uuid: %s", |
| 193 | typeStr ? typeStr : "nullptr", uuidStr ? uuidStr : "nullptr"); |
| 194 | |
| 195 | if (stringToGuid(typeStr, &type) == NO_ERROR) { |
| 196 | pType = &type; |
| 197 | } |
| 198 | if (stringToGuid(uuidStr, &uuid) == NO_ERROR) { |
| 199 | pUuid = &uuid; |
| 200 | } |
| 201 | |
| 202 | return set(pType, pUuid, priority, cbf, user, sessionId, io, device, probe); |
| 203 | } |
| 204 | |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 205 | |
| 206 | AudioEffect::~AudioEffect() |
| 207 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 208 | ALOGV("Destructor %p", this); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 209 | |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 210 | if (!mProbe && (mStatus == NO_ERROR || mStatus == ALREADY_EXISTS)) { |
Eric Laurent | 3f75a5b | 2019-11-12 15:55:51 -0800 | [diff] [blame] | 211 | if (!audio_is_global_session(mSessionId)) { |
Jean-Michel Trivi | a0fd9ca | 2014-09-18 14:07:18 -0700 | [diff] [blame] | 212 | AudioSystem::releaseAudioSessionId(mSessionId, mClientPid); |
| 213 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 214 | if (mIEffect != NULL) { |
| 215 | mIEffect->disconnect(); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 216 | IInterface::asBinder(mIEffect)->unlinkToDeath(mIEffectClient); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 217 | } |
Eric Laurent | eecd765 | 2015-06-04 16:20:16 -0700 | [diff] [blame] | 218 | mIEffect.clear(); |
| 219 | mCblkMemory.clear(); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 220 | } |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 221 | mIEffectClient.clear(); |
| 222 | IPCThreadState::self()->flushCommands(); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | |
| 226 | status_t AudioEffect::initCheck() const |
| 227 | { |
| 228 | return mStatus; |
| 229 | } |
| 230 | |
| 231 | // ------------------------------------------------------------------------- |
| 232 | |
| 233 | effect_descriptor_t AudioEffect::descriptor() const |
| 234 | { |
| 235 | return mDescriptor; |
| 236 | } |
| 237 | |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 238 | bool AudioEffect::getEnabled() const |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 239 | { |
| 240 | return (mEnabled != 0); |
| 241 | } |
| 242 | |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 243 | status_t AudioEffect::setEnabled(bool enabled) |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 244 | { |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 245 | if (mProbe) { |
| 246 | return INVALID_OPERATION; |
| 247 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 248 | if (mStatus != NO_ERROR) { |
Glenn Kasten | f063b49 | 2012-02-17 16:24:10 -0800 | [diff] [blame] | 249 | return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 250 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 251 | |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 252 | status_t status = NO_ERROR; |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 253 | AutoMutex lock(mLock); |
| 254 | if (enabled != mEnabled) { |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 255 | Status bs; |
| 256 | |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 257 | if (enabled) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 258 | ALOGV("enable %p", this); |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 259 | bs = mIEffect->enable(&status); |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 260 | } else { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 261 | ALOGV("disable %p", this); |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 262 | bs = mIEffect->disable(&status); |
| 263 | } |
| 264 | if (!bs.isOk()) { |
| 265 | status = bs.transactionError(); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 266 | } |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 267 | if (status == NO_ERROR) { |
| 268 | mEnabled = enabled; |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 269 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 270 | } |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 271 | return status; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Eric Laurent | 25f4395 | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 274 | status_t AudioEffect::command(uint32_t cmdCode, |
| 275 | uint32_t cmdSize, |
| 276 | void *cmdData, |
| 277 | uint32_t *replySize, |
| 278 | void *replyData) |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 279 | { |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 280 | if (mProbe) { |
| 281 | return INVALID_OPERATION; |
| 282 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 283 | if (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 284 | ALOGV("command() bad status %d", mStatus); |
John Grossman | af7d818 | 2012-01-11 12:23:42 -0800 | [diff] [blame] | 285 | return mStatus; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 288 | if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) { |
| 289 | if (mEnabled == (cmdCode == EFFECT_CMD_ENABLE)) { |
| 290 | return NO_ERROR; |
| 291 | } |
| 292 | if (replySize == NULL || *replySize != sizeof(status_t) || replyData == NULL) { |
| 293 | return BAD_VALUE; |
| 294 | } |
| 295 | mLock.lock(); |
Eric Laurent | 0fa449c | 2010-09-24 11:52:04 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 298 | std::vector<uint8_t> data; |
| 299 | appendToBuffer(cmdData, cmdSize, &data); |
| 300 | |
| 301 | status_t status; |
| 302 | std::vector<uint8_t> response; |
| 303 | |
| 304 | Status bs = mIEffect->command(cmdCode, data, *replySize, &response, &status); |
| 305 | if (!bs.isOk()) { |
| 306 | status = bs.transactionError(); |
| 307 | } |
| 308 | if (status == NO_ERROR) { |
| 309 | memcpy(replyData, response.data(), response.size()); |
| 310 | *replySize = response.size(); |
| 311 | } |
Eric Laurent | 0fa449c | 2010-09-24 11:52:04 -0700 | [diff] [blame] | 312 | |
| 313 | if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) { |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 314 | if (status == NO_ERROR) { |
| 315 | status = *(status_t *)replyData; |
Eric Laurent | 0fa449c | 2010-09-24 11:52:04 -0700 | [diff] [blame] | 316 | } |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 317 | if (status == NO_ERROR) { |
| 318 | mEnabled = (cmdCode == EFFECT_CMD_ENABLE); |
Eric Laurent | 0fa449c | 2010-09-24 11:52:04 -0700 | [diff] [blame] | 319 | } |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 320 | mLock.unlock(); |
Eric Laurent | 8569f0d | 2010-07-29 23:43:43 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Eric Laurent | 8569f0d | 2010-07-29 23:43:43 -0700 | [diff] [blame] | 323 | return status; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 326 | status_t AudioEffect::setParameter(effect_param_t *param) |
| 327 | { |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 328 | if (mProbe) { |
| 329 | return INVALID_OPERATION; |
| 330 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 331 | if (mStatus != NO_ERROR) { |
Glenn Kasten | f063b49 | 2012-02-17 16:24:10 -0800 | [diff] [blame] | 332 | return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | if (param == NULL || param->psize == 0 || param->vsize == 0) { |
| 336 | return BAD_VALUE; |
| 337 | } |
| 338 | |
Eric Laurent | 25f4395 | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 339 | uint32_t psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 340 | |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 341 | ALOGV("setParameter: param: %d, param2: %d", *(int *)param->data, |
| 342 | (param->psize == 8) ? *((int *)param->data + 1): -1); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 343 | |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 344 | std::vector<uint8_t> cmd; |
| 345 | appendToBuffer(param, sizeof(effect_param_t) + psize, &cmd); |
| 346 | std::vector<uint8_t> response; |
| 347 | status_t status; |
| 348 | Status bs = mIEffect->command(EFFECT_CMD_SET_PARAM, |
| 349 | cmd, |
| 350 | sizeof(int), |
| 351 | &response, |
| 352 | &status); |
| 353 | if (!bs.isOk()) { |
| 354 | status = bs.transactionError(); |
| 355 | return status; |
| 356 | } |
| 357 | assert(response.size() == sizeof(int)); |
| 358 | memcpy(¶m->status, response.data(), response.size()); |
| 359 | return status; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | status_t AudioEffect::setParameterDeferred(effect_param_t *param) |
| 363 | { |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 364 | if (mProbe) { |
| 365 | return INVALID_OPERATION; |
| 366 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 367 | if (mStatus != NO_ERROR) { |
Glenn Kasten | f063b49 | 2012-02-17 16:24:10 -0800 | [diff] [blame] | 368 | return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | if (param == NULL || param->psize == 0 || param->vsize == 0) { |
| 372 | return BAD_VALUE; |
| 373 | } |
| 374 | |
| 375 | Mutex::Autolock _l(mCblk->lock); |
| 376 | |
| 377 | int psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize; |
| 378 | int size = ((sizeof(effect_param_t) + psize - 1) / sizeof(int) + 1) * sizeof(int); |
| 379 | |
| 380 | if (mCblk->clientIndex + size > EFFECT_PARAM_BUFFER_SIZE) { |
| 381 | return NO_MEMORY; |
| 382 | } |
| 383 | int *p = (int *)(mCblk->buffer + mCblk->clientIndex); |
| 384 | *p++ = size; |
| 385 | memcpy(p, param, sizeof(effect_param_t) + psize); |
| 386 | mCblk->clientIndex += size; |
| 387 | |
| 388 | return NO_ERROR; |
| 389 | } |
| 390 | |
| 391 | status_t AudioEffect::setParameterCommit() |
| 392 | { |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 393 | if (mProbe) { |
| 394 | return INVALID_OPERATION; |
| 395 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 396 | if (mStatus != NO_ERROR) { |
Glenn Kasten | f063b49 | 2012-02-17 16:24:10 -0800 | [diff] [blame] | 397 | return (mStatus == ALREADY_EXISTS) ? (status_t) INVALID_OPERATION : mStatus; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | Mutex::Autolock _l(mCblk->lock); |
| 401 | if (mCblk->clientIndex == 0) { |
| 402 | return INVALID_OPERATION; |
| 403 | } |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 404 | std::vector<uint8_t> cmd; |
| 405 | std::vector<uint8_t> response; |
| 406 | status_t status; |
| 407 | Status bs = mIEffect->command(EFFECT_CMD_SET_PARAM_COMMIT, |
| 408 | cmd, |
| 409 | 0, |
| 410 | &response, |
| 411 | &status); |
| 412 | if (!bs.isOk()) { |
| 413 | status = bs.transactionError(); |
| 414 | } |
| 415 | return status; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | status_t AudioEffect::getParameter(effect_param_t *param) |
| 419 | { |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 420 | if (mProbe) { |
| 421 | return INVALID_OPERATION; |
| 422 | } |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 423 | if (mStatus != NO_ERROR && mStatus != ALREADY_EXISTS) { |
John Grossman | af7d818 | 2012-01-11 12:23:42 -0800 | [diff] [blame] | 424 | return mStatus; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | if (param == NULL || param->psize == 0 || param->vsize == 0) { |
| 428 | return BAD_VALUE; |
| 429 | } |
| 430 | |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 431 | ALOGV("getParameter: param: %d, param2: %d", *(int *)param->data, |
| 432 | (param->psize == 8) ? *((int *)param->data + 1): -1); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 433 | |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 434 | uint32_t psize = sizeof(effect_param_t) + ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + |
| 435 | param->vsize; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 436 | |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 437 | status_t status; |
| 438 | std::vector<uint8_t> cmd; |
| 439 | std::vector<uint8_t> response; |
| 440 | appendToBuffer(param, sizeof(effect_param_t) + param->psize, &cmd); |
| 441 | |
| 442 | Status bs = mIEffect->command(EFFECT_CMD_GET_PARAM, cmd, psize, &response, &status); |
| 443 | if (!bs.isOk()) { |
| 444 | status = bs.transactionError(); |
| 445 | return status; |
| 446 | } |
| 447 | memcpy(param, response.data(), response.size()); |
| 448 | return status; |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | |
| 452 | // ------------------------------------------------------------------------- |
| 453 | |
| 454 | void AudioEffect::binderDied() |
| 455 | { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 456 | ALOGW("IEffect died"); |
John Grossman | af7d818 | 2012-01-11 12:23:42 -0800 | [diff] [blame] | 457 | mStatus = DEAD_OBJECT; |
Glenn Kasten | a0d6833 | 2012-01-27 16:47:15 -0800 | [diff] [blame] | 458 | if (mCbf != NULL) { |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 459 | status_t status = DEAD_OBJECT; |
| 460 | mCbf(EVENT_ERROR, mUserData, &status); |
| 461 | } |
| 462 | mIEffect.clear(); |
| 463 | } |
| 464 | |
| 465 | // ------------------------------------------------------------------------- |
| 466 | |
| 467 | void AudioEffect::controlStatusChanged(bool controlGranted) |
| 468 | { |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 469 | ALOGV("controlStatusChanged %p control %d callback %p mUserData %p", this, controlGranted, mCbf, |
| 470 | mUserData); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 471 | if (controlGranted) { |
| 472 | if (mStatus == ALREADY_EXISTS) { |
| 473 | mStatus = NO_ERROR; |
| 474 | } |
| 475 | } else { |
| 476 | if (mStatus == NO_ERROR) { |
| 477 | mStatus = ALREADY_EXISTS; |
| 478 | } |
| 479 | } |
Glenn Kasten | a0d6833 | 2012-01-27 16:47:15 -0800 | [diff] [blame] | 480 | if (mCbf != NULL) { |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 481 | mCbf(EVENT_CONTROL_STATUS_CHANGED, mUserData, &controlGranted); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | void AudioEffect::enableStatusChanged(bool enabled) |
| 486 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 487 | ALOGV("enableStatusChanged %p enabled %d mCbf %p", this, enabled, mCbf); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 488 | if (mStatus == ALREADY_EXISTS) { |
Eric Laurent | f5aafb2 | 2010-11-18 08:40:16 -0800 | [diff] [blame] | 489 | mEnabled = enabled; |
Glenn Kasten | a0d6833 | 2012-01-27 16:47:15 -0800 | [diff] [blame] | 490 | if (mCbf != NULL) { |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 491 | mCbf(EVENT_ENABLE_STATUS_CHANGED, mUserData, &enabled); |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 496 | void AudioEffect::commandExecuted(int32_t cmdCode, |
| 497 | const std::vector<uint8_t>& cmdData, |
| 498 | const std::vector<uint8_t>& replyData) |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 499 | { |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 500 | if (cmdData.empty() || replyData.empty()) { |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 501 | return; |
| 502 | } |
| 503 | |
Glenn Kasten | a0d6833 | 2012-01-27 16:47:15 -0800 | [diff] [blame] | 504 | if (mCbf != NULL && cmdCode == EFFECT_CMD_SET_PARAM) { |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 505 | std::vector<uint8_t> cmdDataCopy(cmdData); |
| 506 | effect_param_t* cmd = reinterpret_cast<effect_param_t *>(cmdDataCopy.data()); |
| 507 | cmd->status = *reinterpret_cast<const int32_t *>(replyData.data()); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 508 | mCbf(EVENT_PARAMETER_CHANGED, mUserData, cmd); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | // ------------------------------------------------------------------------- |
| 513 | |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 514 | status_t AudioEffect::queryNumberEffects(uint32_t *numEffects) |
| 515 | { |
| 516 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 517 | if (af == 0) return PERMISSION_DENIED; |
| 518 | return af->queryNumberEffects(numEffects); |
| 519 | } |
| 520 | |
Eric Laurent | ffe9c25 | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 521 | status_t AudioEffect::queryEffect(uint32_t index, effect_descriptor_t *descriptor) |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 522 | { |
| 523 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 524 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | ffe9c25 | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 525 | return af->queryEffect(index, descriptor); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Glenn Kasten | 5e92a78 | 2012-01-30 07:40:52 -0800 | [diff] [blame] | 528 | status_t AudioEffect::getEffectDescriptor(const effect_uuid_t *uuid, |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 529 | const effect_uuid_t *type, |
| 530 | uint32_t preferredTypeFlag, |
| 531 | effect_descriptor_t *descriptor) |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 532 | { |
| 533 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 534 | if (af == 0) return PERMISSION_DENIED; |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 535 | return af->getEffectDescriptor(uuid, type, preferredTypeFlag, descriptor); |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 538 | status_t AudioEffect::queryDefaultPreProcessing(audio_session_t audioSession, |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 539 | effect_descriptor_t *descriptors, |
| 540 | uint32_t *count) |
| 541 | { |
| 542 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 543 | if (aps == 0) return PERMISSION_DENIED; |
| 544 | return aps->queryDefaultPreProcessing(audioSession, descriptors, count); |
| 545 | } |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 546 | |
| 547 | status_t AudioEffect::newEffectUniqueId(audio_unique_id_t* id) |
| 548 | { |
| 549 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 550 | if (af == 0) return PERMISSION_DENIED; |
| 551 | *id = af->newAudioUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT); |
| 552 | return NO_ERROR; |
| 553 | } |
| 554 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 555 | status_t AudioEffect::addSourceDefaultEffect(const char *typeStr, |
| 556 | const String16& opPackageName, |
| 557 | const char *uuidStr, |
| 558 | int32_t priority, |
| 559 | audio_source_t source, |
| 560 | audio_unique_id_t *id) |
| 561 | { |
| 562 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 563 | if (aps == 0) return PERMISSION_DENIED; |
| 564 | |
| 565 | if (typeStr == NULL && uuidStr == NULL) return BAD_VALUE; |
| 566 | |
| 567 | // Convert type & uuid from string to effect_uuid_t. |
| 568 | effect_uuid_t type; |
| 569 | if (typeStr != NULL) { |
| 570 | status_t res = stringToGuid(typeStr, &type); |
| 571 | if (res != OK) return res; |
| 572 | } else { |
| 573 | type = *EFFECT_UUID_NULL; |
| 574 | } |
| 575 | |
| 576 | effect_uuid_t uuid; |
| 577 | if (uuidStr != NULL) { |
| 578 | status_t res = stringToGuid(uuidStr, &uuid); |
| 579 | if (res != OK) return res; |
| 580 | } else { |
| 581 | uuid = *EFFECT_UUID_NULL; |
| 582 | } |
| 583 | |
| 584 | return aps->addSourceDefaultEffect(&type, opPackageName, &uuid, priority, source, id); |
| 585 | } |
| 586 | |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 587 | status_t AudioEffect::addStreamDefaultEffect(const char *typeStr, |
| 588 | const String16& opPackageName, |
| 589 | const char *uuidStr, |
| 590 | int32_t priority, |
| 591 | audio_usage_t usage, |
| 592 | audio_unique_id_t *id) |
| 593 | { |
| 594 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 595 | if (aps == 0) return PERMISSION_DENIED; |
| 596 | |
| 597 | if (typeStr == NULL && uuidStr == NULL) return BAD_VALUE; |
| 598 | |
| 599 | // Convert type & uuid from string to effect_uuid_t. |
| 600 | effect_uuid_t type; |
| 601 | if (typeStr != NULL) { |
| 602 | status_t res = stringToGuid(typeStr, &type); |
| 603 | if (res != OK) return res; |
| 604 | } else { |
| 605 | type = *EFFECT_UUID_NULL; |
| 606 | } |
| 607 | |
| 608 | effect_uuid_t uuid; |
| 609 | if (uuidStr != NULL) { |
| 610 | status_t res = stringToGuid(uuidStr, &uuid); |
| 611 | if (res != OK) return res; |
| 612 | } else { |
| 613 | uuid = *EFFECT_UUID_NULL; |
| 614 | } |
| 615 | |
| 616 | return aps->addStreamDefaultEffect(&type, opPackageName, &uuid, priority, usage, id); |
| 617 | } |
| 618 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 619 | status_t AudioEffect::removeSourceDefaultEffect(audio_unique_id_t id) |
| 620 | { |
| 621 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 622 | if (aps == 0) return PERMISSION_DENIED; |
| 623 | |
| 624 | return aps->removeSourceDefaultEffect(id); |
| 625 | } |
| 626 | |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 627 | status_t AudioEffect::removeStreamDefaultEffect(audio_unique_id_t id) |
| 628 | { |
| 629 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 630 | if (aps == 0) return PERMISSION_DENIED; |
| 631 | |
| 632 | return aps->removeStreamDefaultEffect(id); |
| 633 | } |
| 634 | |
Eric Laurent | 801a118 | 2010-06-09 00:17:29 -0700 | [diff] [blame] | 635 | // ------------------------------------------------------------------------- |
| 636 | |
| 637 | status_t AudioEffect::stringToGuid(const char *str, effect_uuid_t *guid) |
| 638 | { |
| 639 | if (str == NULL || guid == NULL) { |
| 640 | return BAD_VALUE; |
| 641 | } |
| 642 | |
| 643 | int tmp[10]; |
| 644 | |
| 645 | if (sscanf(str, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", |
| 646 | tmp, tmp+1, tmp+2, tmp+3, tmp+4, tmp+5, tmp+6, tmp+7, tmp+8, tmp+9) < 10) { |
| 647 | return BAD_VALUE; |
| 648 | } |
| 649 | guid->timeLow = (uint32_t)tmp[0]; |
| 650 | guid->timeMid = (uint16_t)tmp[1]; |
| 651 | guid->timeHiAndVersion = (uint16_t)tmp[2]; |
| 652 | guid->clockSeq = (uint16_t)tmp[3]; |
| 653 | guid->node[0] = (uint8_t)tmp[4]; |
| 654 | guid->node[1] = (uint8_t)tmp[5]; |
| 655 | guid->node[2] = (uint8_t)tmp[6]; |
| 656 | guid->node[3] = (uint8_t)tmp[7]; |
| 657 | guid->node[4] = (uint8_t)tmp[8]; |
| 658 | guid->node[5] = (uint8_t)tmp[9]; |
| 659 | |
| 660 | return NO_ERROR; |
| 661 | } |
| 662 | |
| 663 | status_t AudioEffect::guidToString(const effect_uuid_t *guid, char *str, size_t maxLen) |
| 664 | { |
| 665 | if (guid == NULL || str == NULL) { |
| 666 | return BAD_VALUE; |
| 667 | } |
| 668 | |
| 669 | snprintf(str, maxLen, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", |
| 670 | guid->timeLow, |
| 671 | guid->timeMid, |
| 672 | guid->timeHiAndVersion, |
| 673 | guid->clockSeq, |
| 674 | guid->node[0], |
| 675 | guid->node[1], |
| 676 | guid->node[2], |
| 677 | guid->node[3], |
| 678 | guid->node[4], |
| 679 | guid->node[5]); |
| 680 | |
| 681 | return NO_ERROR; |
| 682 | } |
| 683 | |
| 684 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 685 | } // namespace android |