Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "SoundTriggerHwService" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <string.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <pthread.h> |
| 24 | |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 25 | #include <system/sound_trigger.h> |
| 26 | #include <cutils/atomic.h> |
| 27 | #include <cutils/properties.h> |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 28 | #include <hardware/hardware.h> |
| 29 | #include <media/AudioSystem.h> |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 30 | #include <utils/Errors.h> |
| 31 | #include <utils/Log.h> |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 32 | #include <binder/IServiceManager.h> |
| 33 | #include <binder/MemoryBase.h> |
| 34 | #include <binder/MemoryHeapBase.h> |
Eric Laurent | 936c84a | 2014-07-17 10:26:04 -0700 | [diff] [blame] | 35 | #include <hardware/sound_trigger.h> |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 36 | #include <ServiceUtilities.h> |
| 37 | #include "SoundTriggerHwService.h" |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 38 | |
| 39 | namespace android { |
| 40 | |
| 41 | #ifdef SOUND_TRIGGER_USE_STUB_MODULE |
| 42 | #define HW_MODULE_PREFIX "stub" |
| 43 | #else |
| 44 | #define HW_MODULE_PREFIX "primary" |
| 45 | #endif |
| 46 | |
| 47 | SoundTriggerHwService::SoundTriggerHwService() |
| 48 | : BnSoundTriggerHwService(), |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 49 | mNextUniqueId(1), |
| 50 | mMemoryDealer(new MemoryDealer(1024 * 1024, "SoundTriggerHwService")), |
| 51 | mCaptureState(false) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | |
| 55 | void SoundTriggerHwService::onFirstRef() |
| 56 | { |
| 57 | const hw_module_t *mod; |
| 58 | int rc; |
| 59 | sound_trigger_hw_device *dev; |
| 60 | |
| 61 | rc = hw_get_module_by_class(SOUND_TRIGGER_HARDWARE_MODULE_ID, HW_MODULE_PREFIX, &mod); |
| 62 | if (rc != 0) { |
| 63 | ALOGE("couldn't load sound trigger module %s.%s (%s)", |
| 64 | SOUND_TRIGGER_HARDWARE_MODULE_ID, "primary", strerror(-rc)); |
| 65 | return; |
| 66 | } |
| 67 | rc = sound_trigger_hw_device_open(mod, &dev); |
| 68 | if (rc != 0) { |
| 69 | ALOGE("couldn't open sound trigger hw device in %s.%s (%s)", |
| 70 | SOUND_TRIGGER_HARDWARE_MODULE_ID, "primary", strerror(-rc)); |
| 71 | return; |
| 72 | } |
| 73 | if (dev->common.version != SOUND_TRIGGER_DEVICE_API_VERSION_CURRENT) { |
| 74 | ALOGE("wrong sound trigger hw device version %04x", dev->common.version); |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | sound_trigger_module_descriptor descriptor; |
| 79 | rc = dev->get_properties(dev, &descriptor.properties); |
| 80 | if (rc != 0) { |
| 81 | ALOGE("could not read implementation properties"); |
| 82 | return; |
| 83 | } |
| 84 | descriptor.handle = |
| 85 | (sound_trigger_module_handle_t)android_atomic_inc(&mNextUniqueId); |
| 86 | ALOGI("loaded default module %s, handle %d", descriptor.properties.description, |
| 87 | descriptor.handle); |
| 88 | |
| 89 | sp<ISoundTriggerClient> client; |
| 90 | sp<Module> module = new Module(this, dev, descriptor, client); |
| 91 | mModules.add(descriptor.handle, module); |
| 92 | mCallbackThread = new CallbackThread(this); |
| 93 | } |
| 94 | |
| 95 | SoundTriggerHwService::~SoundTriggerHwService() |
| 96 | { |
| 97 | if (mCallbackThread != 0) { |
| 98 | mCallbackThread->exit(); |
| 99 | } |
| 100 | for (size_t i = 0; i < mModules.size(); i++) { |
| 101 | sound_trigger_hw_device_close(mModules.valueAt(i)->hwDevice()); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | status_t SoundTriggerHwService::listModules(struct sound_trigger_module_descriptor *modules, |
| 106 | uint32_t *numModules) |
| 107 | { |
| 108 | ALOGV("listModules"); |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 109 | if (!captureHotwordAllowed()) { |
| 110 | return PERMISSION_DENIED; |
| 111 | } |
| 112 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 113 | AutoMutex lock(mServiceLock); |
| 114 | if (numModules == NULL || (*numModules != 0 && modules == NULL)) { |
| 115 | return BAD_VALUE; |
| 116 | } |
| 117 | size_t maxModules = *numModules; |
| 118 | *numModules = mModules.size(); |
| 119 | for (size_t i = 0; i < mModules.size() && i < maxModules; i++) { |
| 120 | modules[i] = mModules.valueAt(i)->descriptor(); |
| 121 | } |
| 122 | return NO_ERROR; |
| 123 | } |
| 124 | |
| 125 | status_t SoundTriggerHwService::attach(const sound_trigger_module_handle_t handle, |
| 126 | const sp<ISoundTriggerClient>& client, |
| 127 | sp<ISoundTrigger>& moduleInterface) |
| 128 | { |
| 129 | ALOGV("attach module %d", handle); |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 130 | if (!captureHotwordAllowed()) { |
| 131 | return PERMISSION_DENIED; |
| 132 | } |
| 133 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 134 | AutoMutex lock(mServiceLock); |
| 135 | moduleInterface.clear(); |
| 136 | if (client == 0) { |
| 137 | return BAD_VALUE; |
| 138 | } |
| 139 | ssize_t index = mModules.indexOfKey(handle); |
| 140 | if (index < 0) { |
| 141 | return BAD_VALUE; |
| 142 | } |
| 143 | sp<Module> module = mModules.valueAt(index); |
| 144 | |
| 145 | module->setClient(client); |
| 146 | client->asBinder()->linkToDeath(module); |
| 147 | moduleInterface = module; |
| 148 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 149 | module->setCaptureState_l(mCaptureState); |
| 150 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 151 | return NO_ERROR; |
| 152 | } |
| 153 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 154 | status_t SoundTriggerHwService::setCaptureState(bool active) |
| 155 | { |
| 156 | ALOGV("setCaptureState %d", active); |
| 157 | AutoMutex lock(mServiceLock); |
| 158 | mCaptureState = active; |
| 159 | for (size_t i = 0; i < mModules.size(); i++) { |
| 160 | mModules.valueAt(i)->setCaptureState_l(active); |
| 161 | } |
| 162 | return NO_ERROR; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | void SoundTriggerHwService::detachModule(sp<Module> module) |
| 167 | { |
Eric Laurent | 936c84a | 2014-07-17 10:26:04 -0700 | [diff] [blame] | 168 | ALOGV("detachModule"); |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 169 | AutoMutex lock(mServiceLock); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 170 | module->clearClient(); |
| 171 | } |
| 172 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 173 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 174 | static const int kDumpLockRetries = 50; |
| 175 | static const int kDumpLockSleep = 60000; |
| 176 | |
| 177 | static bool tryLock(Mutex& mutex) |
| 178 | { |
| 179 | bool locked = false; |
| 180 | for (int i = 0; i < kDumpLockRetries; ++i) { |
| 181 | if (mutex.tryLock() == NO_ERROR) { |
| 182 | locked = true; |
| 183 | break; |
| 184 | } |
| 185 | usleep(kDumpLockSleep); |
| 186 | } |
| 187 | return locked; |
| 188 | } |
| 189 | |
| 190 | status_t SoundTriggerHwService::dump(int fd, const Vector<String16>& args __unused) { |
| 191 | String8 result; |
| 192 | if (checkCallingPermission(String16("android.permission.DUMP")) == false) { |
| 193 | result.appendFormat("Permission Denial: can't dump SoundTriggerHwService"); |
| 194 | write(fd, result.string(), result.size()); |
| 195 | } else { |
| 196 | bool locked = tryLock(mServiceLock); |
| 197 | // failed to lock - SoundTriggerHwService is probably deadlocked |
| 198 | if (!locked) { |
| 199 | result.append("SoundTriggerHwService may be deadlocked\n"); |
| 200 | write(fd, result.string(), result.size()); |
| 201 | } |
| 202 | |
| 203 | if (locked) mServiceLock.unlock(); |
| 204 | } |
| 205 | return NO_ERROR; |
| 206 | } |
| 207 | |
| 208 | status_t SoundTriggerHwService::onTransact( |
| 209 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 210 | return BnSoundTriggerHwService::onTransact(code, data, reply, flags); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | // static |
| 215 | void SoundTriggerHwService::recognitionCallback(struct sound_trigger_recognition_event *event, |
| 216 | void *cookie) |
| 217 | { |
| 218 | Module *module = (Module *)cookie; |
| 219 | if (module == NULL) { |
| 220 | return; |
| 221 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 222 | sp<SoundTriggerHwService> service = module->service().promote(); |
| 223 | if (service == 0) { |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | service->sendRecognitionEvent(event, module); |
| 228 | } |
| 229 | |
| 230 | sp<IMemory> SoundTriggerHwService::prepareRecognitionEvent_l( |
| 231 | struct sound_trigger_recognition_event *event) |
| 232 | { |
| 233 | sp<IMemory> eventMemory; |
| 234 | |
| 235 | //sanitize event |
| 236 | switch (event->type) { |
| 237 | case SOUND_MODEL_TYPE_KEYPHRASE: |
| 238 | ALOGW_IF(event->data_size != 0 && event->data_offset != |
| 239 | sizeof(struct sound_trigger_phrase_recognition_event), |
| 240 | "prepareRecognitionEvent_l(): invalid data offset %u for keyphrase event type", |
| 241 | event->data_offset); |
| 242 | event->data_offset = sizeof(struct sound_trigger_phrase_recognition_event); |
| 243 | break; |
| 244 | case SOUND_MODEL_TYPE_UNKNOWN: |
| 245 | ALOGW_IF(event->data_size != 0 && event->data_offset != |
| 246 | sizeof(struct sound_trigger_recognition_event), |
| 247 | "prepareRecognitionEvent_l(): invalid data offset %u for unknown event type", |
| 248 | event->data_offset); |
| 249 | event->data_offset = sizeof(struct sound_trigger_recognition_event); |
| 250 | break; |
| 251 | default: |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 252 | return eventMemory; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | size_t size = event->data_offset + event->data_size; |
| 256 | eventMemory = mMemoryDealer->allocate(size); |
| 257 | if (eventMemory == 0 || eventMemory->pointer() == NULL) { |
| 258 | eventMemory.clear(); |
| 259 | return eventMemory; |
| 260 | } |
| 261 | memcpy(eventMemory->pointer(), event, size); |
| 262 | |
| 263 | return eventMemory; |
| 264 | } |
| 265 | |
| 266 | void SoundTriggerHwService::sendRecognitionEvent(struct sound_trigger_recognition_event *event, |
| 267 | Module *module) |
| 268 | { |
| 269 | AutoMutex lock(mServiceLock); |
| 270 | if (module == NULL) { |
| 271 | return; |
| 272 | } |
| 273 | sp<IMemory> eventMemory = prepareRecognitionEvent_l(event); |
| 274 | if (eventMemory == 0) { |
| 275 | return; |
| 276 | } |
| 277 | sp<Module> strongModule; |
| 278 | for (size_t i = 0; i < mModules.size(); i++) { |
| 279 | if (mModules.valueAt(i).get() == module) { |
| 280 | strongModule = mModules.valueAt(i); |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | if (strongModule == 0) { |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | sendCallbackEvent_l(new CallbackEvent(CallbackEvent::TYPE_RECOGNITION, |
| 289 | eventMemory, strongModule)); |
| 290 | } |
| 291 | |
| 292 | // static |
| 293 | void SoundTriggerHwService::soundModelCallback(struct sound_trigger_model_event *event, |
| 294 | void *cookie) |
| 295 | { |
| 296 | Module *module = (Module *)cookie; |
| 297 | if (module == NULL) { |
| 298 | return; |
| 299 | } |
| 300 | sp<SoundTriggerHwService> service = module->service().promote(); |
| 301 | if (service == 0) { |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | service->sendSoundModelEvent(event, module); |
| 306 | } |
| 307 | |
| 308 | sp<IMemory> SoundTriggerHwService::prepareSoundModelEvent_l(struct sound_trigger_model_event *event) |
| 309 | { |
| 310 | sp<IMemory> eventMemory; |
| 311 | |
| 312 | size_t size = event->data_offset + event->data_size; |
| 313 | eventMemory = mMemoryDealer->allocate(size); |
| 314 | if (eventMemory == 0 || eventMemory->pointer() == NULL) { |
| 315 | eventMemory.clear(); |
| 316 | return eventMemory; |
| 317 | } |
| 318 | memcpy(eventMemory->pointer(), event, size); |
| 319 | |
| 320 | return eventMemory; |
| 321 | } |
| 322 | |
| 323 | void SoundTriggerHwService::sendSoundModelEvent(struct sound_trigger_model_event *event, |
| 324 | Module *module) |
| 325 | { |
| 326 | AutoMutex lock(mServiceLock); |
| 327 | sp<IMemory> eventMemory = prepareSoundModelEvent_l(event); |
| 328 | if (eventMemory == 0) { |
| 329 | return; |
| 330 | } |
| 331 | sp<Module> strongModule; |
| 332 | for (size_t i = 0; i < mModules.size(); i++) { |
| 333 | if (mModules.valueAt(i).get() == module) { |
| 334 | strongModule = mModules.valueAt(i); |
| 335 | break; |
| 336 | } |
| 337 | } |
| 338 | if (strongModule == 0) { |
| 339 | return; |
| 340 | } |
| 341 | sendCallbackEvent_l(new CallbackEvent(CallbackEvent::TYPE_SOUNDMODEL, |
| 342 | eventMemory, strongModule)); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 346 | sp<IMemory> SoundTriggerHwService::prepareServiceStateEvent_l(sound_trigger_service_state_t state) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 347 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 348 | sp<IMemory> eventMemory; |
| 349 | |
| 350 | size_t size = sizeof(sound_trigger_service_state_t); |
| 351 | eventMemory = mMemoryDealer->allocate(size); |
| 352 | if (eventMemory == 0 || eventMemory->pointer() == NULL) { |
| 353 | eventMemory.clear(); |
| 354 | return eventMemory; |
| 355 | } |
| 356 | *((sound_trigger_service_state_t *)eventMemory->pointer()) = state; |
| 357 | return eventMemory; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 360 | // call with mServiceLock held |
| 361 | void SoundTriggerHwService::sendServiceStateEvent_l(sound_trigger_service_state_t state, |
| 362 | Module *module) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 363 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 364 | sp<IMemory> eventMemory = prepareServiceStateEvent_l(state); |
| 365 | if (eventMemory == 0) { |
| 366 | return; |
| 367 | } |
| 368 | sp<Module> strongModule; |
| 369 | for (size_t i = 0; i < mModules.size(); i++) { |
| 370 | if (mModules.valueAt(i).get() == module) { |
| 371 | strongModule = mModules.valueAt(i); |
| 372 | break; |
| 373 | } |
| 374 | } |
| 375 | if (strongModule == 0) { |
| 376 | return; |
| 377 | } |
| 378 | sendCallbackEvent_l(new CallbackEvent(CallbackEvent::TYPE_SERVICE_STATE, |
| 379 | eventMemory, strongModule)); |
| 380 | } |
| 381 | |
| 382 | // call with mServiceLock held |
| 383 | void SoundTriggerHwService::sendCallbackEvent_l(const sp<CallbackEvent>& event) |
| 384 | { |
| 385 | mCallbackThread->sendCallbackEvent(event); |
| 386 | } |
| 387 | |
| 388 | void SoundTriggerHwService::onCallbackEvent(const sp<CallbackEvent>& event) |
| 389 | { |
| 390 | ALOGV("onCallbackEvent"); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 391 | sp<Module> module; |
| 392 | { |
| 393 | AutoMutex lock(mServiceLock); |
| 394 | module = event->mModule.promote(); |
| 395 | if (module == 0) { |
| 396 | return; |
| 397 | } |
| 398 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 399 | module->onCallbackEvent(event); |
| 400 | { |
| 401 | AutoMutex lock(mServiceLock); |
| 402 | // clear now to execute with mServiceLock locked |
| 403 | event->mMemory.clear(); |
| 404 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | #undef LOG_TAG |
| 408 | #define LOG_TAG "SoundTriggerHwService::CallbackThread" |
| 409 | |
| 410 | SoundTriggerHwService::CallbackThread::CallbackThread(const wp<SoundTriggerHwService>& service) |
| 411 | : mService(service) |
| 412 | { |
| 413 | } |
| 414 | |
| 415 | SoundTriggerHwService::CallbackThread::~CallbackThread() |
| 416 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 417 | while (!mEventQueue.isEmpty()) { |
| 418 | mEventQueue[0]->mMemory.clear(); |
| 419 | mEventQueue.removeAt(0); |
| 420 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | void SoundTriggerHwService::CallbackThread::onFirstRef() |
| 424 | { |
| 425 | run("soundTrigger cbk", ANDROID_PRIORITY_URGENT_AUDIO); |
| 426 | } |
| 427 | |
| 428 | bool SoundTriggerHwService::CallbackThread::threadLoop() |
| 429 | { |
| 430 | while (!exitPending()) { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 431 | sp<CallbackEvent> event; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 432 | sp<SoundTriggerHwService> service; |
| 433 | { |
| 434 | Mutex::Autolock _l(mCallbackLock); |
| 435 | while (mEventQueue.isEmpty() && !exitPending()) { |
| 436 | ALOGV("CallbackThread::threadLoop() sleep"); |
| 437 | mCallbackCond.wait(mCallbackLock); |
| 438 | ALOGV("CallbackThread::threadLoop() wake up"); |
| 439 | } |
| 440 | if (exitPending()) { |
| 441 | break; |
| 442 | } |
| 443 | event = mEventQueue[0]; |
| 444 | mEventQueue.removeAt(0); |
| 445 | service = mService.promote(); |
| 446 | } |
| 447 | if (service != 0) { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 448 | service->onCallbackEvent(event); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | return false; |
| 452 | } |
| 453 | |
| 454 | void SoundTriggerHwService::CallbackThread::exit() |
| 455 | { |
| 456 | Mutex::Autolock _l(mCallbackLock); |
| 457 | requestExit(); |
| 458 | mCallbackCond.broadcast(); |
| 459 | } |
| 460 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 461 | void SoundTriggerHwService::CallbackThread::sendCallbackEvent( |
| 462 | const sp<SoundTriggerHwService::CallbackEvent>& event) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 463 | { |
| 464 | AutoMutex lock(mCallbackLock); |
| 465 | mEventQueue.add(event); |
| 466 | mCallbackCond.signal(); |
| 467 | } |
| 468 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 469 | SoundTriggerHwService::CallbackEvent::CallbackEvent(event_type type, sp<IMemory> memory, |
| 470 | wp<Module> module) |
| 471 | : mType(type), mMemory(memory), mModule(module) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 472 | { |
| 473 | } |
| 474 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 475 | SoundTriggerHwService::CallbackEvent::~CallbackEvent() |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 476 | { |
| 477 | } |
| 478 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 479 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 480 | #undef LOG_TAG |
| 481 | #define LOG_TAG "SoundTriggerHwService::Module" |
| 482 | |
| 483 | SoundTriggerHwService::Module::Module(const sp<SoundTriggerHwService>& service, |
| 484 | sound_trigger_hw_device* hwDevice, |
| 485 | sound_trigger_module_descriptor descriptor, |
| 486 | const sp<ISoundTriggerClient>& client) |
| 487 | : mService(service), mHwDevice(hwDevice), mDescriptor(descriptor), |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 488 | mClient(client), mServiceState(SOUND_TRIGGER_STATE_NO_INIT) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 489 | { |
| 490 | } |
| 491 | |
| 492 | SoundTriggerHwService::Module::~Module() { |
| 493 | } |
| 494 | |
| 495 | void SoundTriggerHwService::Module::detach() { |
| 496 | ALOGV("detach()"); |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 497 | if (!captureHotwordAllowed()) { |
| 498 | return; |
| 499 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 500 | { |
| 501 | AutoMutex lock(mLock); |
| 502 | for (size_t i = 0; i < mModels.size(); i++) { |
| 503 | sp<Model> model = mModels.valueAt(i); |
| 504 | ALOGV("detach() unloading model %d", model->mHandle); |
| 505 | if (model->mState == Model::STATE_ACTIVE) { |
| 506 | mHwDevice->stop_recognition(mHwDevice, model->mHandle); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 507 | } |
| 508 | mHwDevice->unload_sound_model(mHwDevice, model->mHandle); |
| 509 | } |
| 510 | mModels.clear(); |
| 511 | } |
| 512 | if (mClient != 0) { |
| 513 | mClient->asBinder()->unlinkToDeath(this); |
| 514 | } |
| 515 | sp<SoundTriggerHwService> service = mService.promote(); |
| 516 | if (service == 0) { |
| 517 | return; |
| 518 | } |
| 519 | service->detachModule(this); |
| 520 | } |
| 521 | |
| 522 | status_t SoundTriggerHwService::Module::loadSoundModel(const sp<IMemory>& modelMemory, |
| 523 | sound_model_handle_t *handle) |
| 524 | { |
| 525 | ALOGV("loadSoundModel() handle"); |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 526 | if (!captureHotwordAllowed()) { |
| 527 | return PERMISSION_DENIED; |
| 528 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 529 | |
| 530 | if (modelMemory == 0 || modelMemory->pointer() == NULL) { |
| 531 | ALOGE("loadSoundModel() modelMemory is 0 or has NULL pointer()"); |
| 532 | return BAD_VALUE; |
| 533 | } |
| 534 | struct sound_trigger_sound_model *sound_model = |
| 535 | (struct sound_trigger_sound_model *)modelMemory->pointer(); |
| 536 | |
Eric Laurent | ef0c915 | 2016-08-17 06:19:32 -0700 | [diff] [blame] | 537 | size_t structSize; |
| 538 | if (sound_model->type == SOUND_MODEL_TYPE_KEYPHRASE) { |
| 539 | structSize = sizeof(struct sound_trigger_phrase_sound_model); |
| 540 | } else { |
| 541 | structSize = sizeof(struct sound_trigger_sound_model); |
| 542 | } |
| 543 | |
| 544 | if (sound_model->data_offset < structSize || |
| 545 | sound_model->data_size > (UINT_MAX - sound_model->data_offset) || |
| 546 | modelMemory->size() < sound_model->data_offset || |
| 547 | sound_model->data_size > (modelMemory->size() - sound_model->data_offset)) { |
| 548 | android_errorWriteLog(0x534e4554, "30148546"); |
| 549 | ALOGE("loadSoundModel() data_size is too big"); |
| 550 | return BAD_VALUE; |
| 551 | } |
| 552 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 553 | AutoMutex lock(mLock); |
| 554 | status_t status = mHwDevice->load_sound_model(mHwDevice, |
| 555 | sound_model, |
| 556 | SoundTriggerHwService::soundModelCallback, |
| 557 | this, |
| 558 | handle); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 559 | if (status != NO_ERROR) { |
| 560 | return status; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 561 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 562 | audio_session_t session; |
| 563 | audio_io_handle_t ioHandle; |
| 564 | audio_devices_t device; |
| 565 | |
| 566 | status = AudioSystem::acquireSoundTriggerSession(&session, &ioHandle, &device); |
| 567 | if (status != NO_ERROR) { |
| 568 | return status; |
| 569 | } |
| 570 | |
| 571 | sp<Model> model = new Model(*handle, session, ioHandle, device, sound_model->type); |
| 572 | mModels.replaceValueFor(*handle, model); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 573 | |
| 574 | return status; |
| 575 | } |
| 576 | |
| 577 | status_t SoundTriggerHwService::Module::unloadSoundModel(sound_model_handle_t handle) |
| 578 | { |
| 579 | ALOGV("unloadSoundModel() model handle %d", handle); |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 580 | if (!captureHotwordAllowed()) { |
| 581 | return PERMISSION_DENIED; |
| 582 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 583 | |
| 584 | AutoMutex lock(mLock); |
| 585 | ssize_t index = mModels.indexOfKey(handle); |
| 586 | if (index < 0) { |
| 587 | return BAD_VALUE; |
| 588 | } |
Eric Laurent | 1a1cba8 | 2014-06-09 16:20:05 -0700 | [diff] [blame] | 589 | sp<Model> model = mModels.valueAt(index); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 590 | mModels.removeItem(handle); |
Eric Laurent | 1a1cba8 | 2014-06-09 16:20:05 -0700 | [diff] [blame] | 591 | if (model->mState == Model::STATE_ACTIVE) { |
| 592 | mHwDevice->stop_recognition(mHwDevice, model->mHandle); |
Eric Laurent | 1a1cba8 | 2014-06-09 16:20:05 -0700 | [diff] [blame] | 593 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 594 | AudioSystem::releaseSoundTriggerSession(model->mCaptureSession); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 595 | return mHwDevice->unload_sound_model(mHwDevice, handle); |
| 596 | } |
| 597 | |
| 598 | status_t SoundTriggerHwService::Module::startRecognition(sound_model_handle_t handle, |
Eric Laurent | 0832b2d | 2014-07-06 16:17:25 -0700 | [diff] [blame] | 599 | const sp<IMemory>& dataMemory) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 600 | { |
| 601 | ALOGV("startRecognition() model handle %d", handle); |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 602 | if (!captureHotwordAllowed()) { |
| 603 | return PERMISSION_DENIED; |
| 604 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 605 | |
Eric Laurent | ef0c915 | 2016-08-17 06:19:32 -0700 | [diff] [blame] | 606 | if (dataMemory == 0 || dataMemory->pointer() == NULL) { |
| 607 | ALOGE("startRecognition() dataMemory is 0 or has NULL pointer()"); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 608 | return BAD_VALUE; |
| 609 | |
| 610 | } |
Eric Laurent | ef0c915 | 2016-08-17 06:19:32 -0700 | [diff] [blame] | 611 | |
| 612 | struct sound_trigger_recognition_config *config = |
| 613 | (struct sound_trigger_recognition_config *)dataMemory->pointer(); |
| 614 | |
| 615 | if (config->data_offset < sizeof(struct sound_trigger_recognition_config) || |
| 616 | config->data_size > (UINT_MAX - config->data_offset) || |
| 617 | dataMemory->size() < config->data_offset || |
| 618 | config->data_size > (dataMemory->size() - config->data_offset)) { |
| 619 | ALOGE("startRecognition() data_size is too big"); |
| 620 | return BAD_VALUE; |
| 621 | } |
| 622 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 623 | AutoMutex lock(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 624 | if (mServiceState == SOUND_TRIGGER_STATE_DISABLED) { |
| 625 | return INVALID_OPERATION; |
| 626 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 627 | sp<Model> model = getModel(handle); |
| 628 | if (model == 0) { |
| 629 | return BAD_VALUE; |
| 630 | } |
| 631 | |
| 632 | if (model->mState == Model::STATE_ACTIVE) { |
| 633 | return INVALID_OPERATION; |
| 634 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 635 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 636 | |
| 637 | //TODO: get capture handle and device from audio policy service |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 638 | config->capture_handle = model->mCaptureIOHandle; |
| 639 | config->capture_device = model->mCaptureDevice; |
| 640 | status_t status = mHwDevice->start_recognition(mHwDevice, handle, config, |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 641 | SoundTriggerHwService::recognitionCallback, |
Eric Laurent | 0832b2d | 2014-07-06 16:17:25 -0700 | [diff] [blame] | 642 | this); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 643 | |
| 644 | if (status == NO_ERROR) { |
| 645 | model->mState = Model::STATE_ACTIVE; |
| 646 | model->mConfig = *config; |
| 647 | } |
| 648 | |
| 649 | return status; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | status_t SoundTriggerHwService::Module::stopRecognition(sound_model_handle_t handle) |
| 653 | { |
| 654 | ALOGV("stopRecognition() model handle %d", handle); |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 655 | if (!captureHotwordAllowed()) { |
| 656 | return PERMISSION_DENIED; |
| 657 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 658 | |
| 659 | AutoMutex lock(mLock); |
| 660 | sp<Model> model = getModel(handle); |
| 661 | if (model == 0) { |
| 662 | return BAD_VALUE; |
| 663 | } |
| 664 | |
| 665 | if (model->mState != Model::STATE_ACTIVE) { |
| 666 | return INVALID_OPERATION; |
| 667 | } |
| 668 | mHwDevice->stop_recognition(mHwDevice, handle); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 669 | model->mState = Model::STATE_IDLE; |
| 670 | return NO_ERROR; |
| 671 | } |
| 672 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 673 | |
| 674 | void SoundTriggerHwService::Module::onCallbackEvent(const sp<CallbackEvent>& event) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 675 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 676 | ALOGV("onCallbackEvent type %d", event->mType); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 677 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 678 | sp<IMemory> eventMemory = event->mMemory; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 679 | |
| 680 | if (eventMemory == 0 || eventMemory->pointer() == NULL) { |
| 681 | return; |
| 682 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 683 | if (mClient == 0) { |
| 684 | ALOGI("%s mClient == 0", __func__); |
| 685 | return; |
| 686 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 687 | |
| 688 | switch (event->mType) { |
| 689 | case CallbackEvent::TYPE_RECOGNITION: { |
| 690 | struct sound_trigger_recognition_event *recognitionEvent = |
| 691 | (struct sound_trigger_recognition_event *)eventMemory->pointer(); |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 692 | sp<ISoundTriggerClient> client; |
| 693 | { |
| 694 | AutoMutex lock(mLock); |
| 695 | sp<Model> model = getModel(recognitionEvent->model); |
| 696 | if (model == 0) { |
| 697 | ALOGW("%s model == 0", __func__); |
| 698 | return; |
| 699 | } |
| 700 | if (model->mState != Model::STATE_ACTIVE) { |
| 701 | ALOGV("onCallbackEvent model->mState %d != Model::STATE_ACTIVE", model->mState); |
| 702 | return; |
| 703 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 704 | |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 705 | recognitionEvent->capture_session = model->mCaptureSession; |
| 706 | model->mState = Model::STATE_IDLE; |
| 707 | client = mClient; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 708 | } |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 709 | if (client != 0) { |
| 710 | client->onRecognitionEvent(eventMemory); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 711 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 712 | } break; |
| 713 | case CallbackEvent::TYPE_SOUNDMODEL: { |
| 714 | struct sound_trigger_model_event *soundmodelEvent = |
| 715 | (struct sound_trigger_model_event *)eventMemory->pointer(); |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 716 | sp<ISoundTriggerClient> client; |
| 717 | { |
| 718 | AutoMutex lock(mLock); |
| 719 | sp<Model> model = getModel(soundmodelEvent->model); |
| 720 | if (model == 0) { |
| 721 | ALOGW("%s model == 0", __func__); |
| 722 | return; |
| 723 | } |
| 724 | client = mClient; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 725 | } |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 726 | if (client != 0) { |
| 727 | client->onSoundModelEvent(eventMemory); |
| 728 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 729 | } break; |
| 730 | case CallbackEvent::TYPE_SERVICE_STATE: { |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 731 | sp<ISoundTriggerClient> client; |
| 732 | { |
| 733 | AutoMutex lock(mLock); |
| 734 | client = mClient; |
| 735 | } |
| 736 | if (client != 0) { |
| 737 | client->onServiceStateChange(eventMemory); |
| 738 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 739 | } break; |
| 740 | default: |
| 741 | LOG_ALWAYS_FATAL("onCallbackEvent unknown event type %d", event->mType); |
| 742 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | sp<SoundTriggerHwService::Model> SoundTriggerHwService::Module::getModel( |
| 746 | sound_model_handle_t handle) |
| 747 | { |
| 748 | sp<Model> model; |
| 749 | ssize_t index = mModels.indexOfKey(handle); |
| 750 | if (index >= 0) { |
| 751 | model = mModels.valueAt(index); |
| 752 | } |
| 753 | return model; |
| 754 | } |
| 755 | |
| 756 | void SoundTriggerHwService::Module::binderDied( |
| 757 | const wp<IBinder> &who __unused) { |
| 758 | ALOGW("client binder died for module %d", mDescriptor.handle); |
| 759 | detach(); |
| 760 | } |
| 761 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 762 | // Called with mServiceLock held |
| 763 | void SoundTriggerHwService::Module::setCaptureState_l(bool active) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 764 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 765 | ALOGV("Module::setCaptureState_l %d", active); |
| 766 | sp<SoundTriggerHwService> service; |
| 767 | sound_trigger_service_state_t state; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 768 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 769 | Vector< sp<IMemory> > events; |
| 770 | { |
| 771 | AutoMutex lock(mLock); |
| 772 | state = (active && !mDescriptor.properties.concurrent_capture) ? |
| 773 | SOUND_TRIGGER_STATE_DISABLED : SOUND_TRIGGER_STATE_ENABLED; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 774 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 775 | if (state == mServiceState) { |
| 776 | return; |
| 777 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 778 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 779 | mServiceState = state; |
| 780 | |
| 781 | service = mService.promote(); |
| 782 | if (service == 0) { |
| 783 | return; |
| 784 | } |
| 785 | |
| 786 | if (state == SOUND_TRIGGER_STATE_ENABLED) { |
| 787 | goto exit; |
| 788 | } |
| 789 | |
| 790 | for (size_t i = 0; i < mModels.size(); i++) { |
| 791 | sp<Model> model = mModels.valueAt(i); |
| 792 | if (model->mState == Model::STATE_ACTIVE) { |
| 793 | mHwDevice->stop_recognition(mHwDevice, model->mHandle); |
| 794 | // keep model in ACTIVE state so that event is processed by onCallbackEvent() |
| 795 | struct sound_trigger_phrase_recognition_event phraseEvent; |
| 796 | switch (model->mType) { |
| 797 | case SOUND_MODEL_TYPE_KEYPHRASE: |
| 798 | phraseEvent.num_phrases = model->mConfig.num_phrases; |
| 799 | for (size_t i = 0; i < phraseEvent.num_phrases; i++) { |
| 800 | phraseEvent.phrase_extras[i] = model->mConfig.phrases[i]; |
| 801 | } |
| 802 | break; |
| 803 | case SOUND_MODEL_TYPE_UNKNOWN: |
| 804 | default: |
| 805 | break; |
| 806 | } |
| 807 | phraseEvent.common.status = RECOGNITION_STATUS_ABORT; |
| 808 | phraseEvent.common.type = model->mType; |
| 809 | phraseEvent.common.model = model->mHandle; |
| 810 | phraseEvent.common.data_size = 0; |
| 811 | sp<IMemory> eventMemory = service->prepareRecognitionEvent_l(&phraseEvent.common); |
| 812 | if (eventMemory != 0) { |
| 813 | events.add(eventMemory); |
| 814 | } |
| 815 | } |
| 816 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 817 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 818 | |
| 819 | for (size_t i = 0; i < events.size(); i++) { |
| 820 | service->sendCallbackEvent_l(new CallbackEvent(CallbackEvent::TYPE_RECOGNITION, events[i], |
| 821 | this)); |
| 822 | } |
| 823 | |
| 824 | exit: |
| 825 | service->sendServiceStateEvent_l(state, this); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 828 | |
| 829 | SoundTriggerHwService::Model::Model(sound_model_handle_t handle, audio_session_t session, |
| 830 | audio_io_handle_t ioHandle, audio_devices_t device, |
| 831 | sound_trigger_sound_model_type_t type) : |
| 832 | mHandle(handle), mState(STATE_IDLE), mCaptureSession(session), |
| 833 | mCaptureIOHandle(ioHandle), mCaptureDevice(device), mType(type) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 834 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 835 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | status_t SoundTriggerHwService::Module::dump(int fd __unused, |
| 839 | const Vector<String16>& args __unused) { |
| 840 | String8 result; |
| 841 | return NO_ERROR; |
| 842 | } |
| 843 | |
| 844 | }; // namespace android |