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