• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 "APM::AudioInputDescriptor"
18 //#define LOG_NDEBUG 0
19 
20 #include <audiomanager/AudioManager.h>
21 #include <media/AudioPolicy.h>
22 #include <policy.h>
23 #include <AudioPolicyInterface.h>
24 #include "AudioInputDescriptor.h"
25 #include "AudioPolicyMix.h"
26 #include "HwModule.h"
27 
28 namespace android {
29 
AudioInputDescriptor(const sp<IOProfile> & profile,AudioPolicyClientInterface * clientInterface)30 AudioInputDescriptor::AudioInputDescriptor(const sp<IOProfile>& profile,
31                                            AudioPolicyClientInterface *clientInterface)
32     : mProfile(profile)
33     ,  mClientInterface(clientInterface)
34 {
35     if (profile != NULL) {
36         profile->pickAudioProfile(mSamplingRate, mChannelMask, mFormat);
37         if (profile->getGains().size() > 0) {
38             profile->getGains()[0]->getDefaultConfig(&mGain);
39         }
40     }
41 }
42 
getModuleHandle() const43 audio_module_handle_t AudioInputDescriptor::getModuleHandle() const
44 {
45     if (mProfile == 0) {
46         return AUDIO_MODULE_HANDLE_NONE;
47     }
48     return mProfile->getModuleHandle();
49 }
50 
source() const51 audio_source_t AudioInputDescriptor::source() const
52 {
53     return getHighestPriorityAttributes().source;
54 }
55 
applyAudioPortConfig(const struct audio_port_config * config,audio_port_config * backupConfig)56 status_t AudioInputDescriptor::applyAudioPortConfig(const struct audio_port_config *config,
57                                                     audio_port_config *backupConfig)
58 {
59     struct audio_port_config localBackupConfig = { .config_mask = config->config_mask };
60     status_t status = NO_ERROR;
61 
62     toAudioPortConfig(&localBackupConfig);
63     if ((status = validationBeforeApplyConfig(config)) == NO_ERROR) {
64         AudioPortConfig::applyAudioPortConfig(config, backupConfig);
65         applyPolicyAudioPortConfig(config);
66     }
67 
68     if (backupConfig != NULL) {
69         *backupConfig = localBackupConfig;
70     }
71     return status;
72 }
73 
toAudioPortConfig(struct audio_port_config * dstConfig,const struct audio_port_config * srcConfig) const74 void AudioInputDescriptor::toAudioPortConfig(struct audio_port_config *dstConfig,
75                                              const struct audio_port_config *srcConfig) const
76 {
77     ALOG_ASSERT(mProfile != 0,
78                 "toAudioPortConfig() called on input with null profile %d", mIoHandle);
79     dstConfig->config_mask = AUDIO_PORT_CONFIG_SAMPLE_RATE|AUDIO_PORT_CONFIG_CHANNEL_MASK|
80                             AUDIO_PORT_CONFIG_FORMAT|AUDIO_PORT_CONFIG_GAIN;
81     if (srcConfig != NULL) {
82         dstConfig->config_mask |= srcConfig->config_mask;
83     }
84 
85     AudioPortConfig::toAudioPortConfig(dstConfig, srcConfig);
86     toPolicyAudioPortConfig(dstConfig, srcConfig);
87 
88     dstConfig->role = AUDIO_PORT_ROLE_SINK;
89     dstConfig->type = AUDIO_PORT_TYPE_MIX;
90     dstConfig->ext.mix.hw_module = getModuleHandle();
91     dstConfig->ext.mix.handle = mIoHandle;
92     dstConfig->ext.mix.usecase.source = source();
93 }
94 
toAudioPort(struct audio_port_v7 * port) const95 void AudioInputDescriptor::toAudioPort(struct audio_port_v7 *port) const
96 {
97     ALOG_ASSERT(mProfile != 0, "toAudioPort() called on input with null profile %d", mIoHandle);
98 
99     mProfile->toAudioPort(port);
100     port->id = mId;
101     toAudioPortConfig(&port->active_config);
102     port->ext.mix.hw_module = getModuleHandle();
103     port->ext.mix.handle = mIoHandle;
104     port->ext.mix.latency_class = AUDIO_LATENCY_NORMAL;
105 }
106 
setPreemptedSessions(const SortedVector<audio_session_t> & sessions)107 void AudioInputDescriptor::setPreemptedSessions(const SortedVector<audio_session_t>& sessions)
108 {
109     mPreemptedSessions = sessions;
110 }
111 
getPreemptedSessions() const112 SortedVector<audio_session_t> AudioInputDescriptor::getPreemptedSessions() const
113 {
114     return mPreemptedSessions;
115 }
116 
hasPreemptedSession(audio_session_t session) const117 bool AudioInputDescriptor::hasPreemptedSession(audio_session_t session) const
118 {
119     return (mPreemptedSessions.indexOf(session) >= 0);
120 }
121 
clearPreemptedSessions()122 void AudioInputDescriptor::clearPreemptedSessions()
123 {
124     mPreemptedSessions.clear();
125 }
126 
isSourceActive(audio_source_t source) const127 bool AudioInputDescriptor::isSourceActive(audio_source_t source) const
128 {
129     for (const auto &client : getClientIterable()) {
130         if (client->active() &&
131             ((client->source() == source) ||
132                 ((source == AUDIO_SOURCE_VOICE_RECOGNITION) &&
133                     (client->source() == AUDIO_SOURCE_HOTWORD) &&
134                     client->isSoundTrigger()))) {
135             return true;
136         }
137     }
138     return false;
139 }
140 
getHighestPriorityAttributes() const141 audio_attributes_t AudioInputDescriptor::getHighestPriorityAttributes() const
142 {
143     audio_attributes_t attributes = { .source = AUDIO_SOURCE_DEFAULT };
144     sp<RecordClientDescriptor> topClient = getHighestPriorityClient();
145     return topClient ? topClient->attributes() : attributes;
146 }
147 
getHighestPriorityClient() const148 sp<RecordClientDescriptor> AudioInputDescriptor::getHighestPriorityClient() const
149 {
150     sp<RecordClientDescriptor> topClient;
151 
152     for (bool activeOnly : { true, false }) {
153         int32_t topPriority = -1;
154         app_state_t topState = APP_STATE_IDLE;
155         for (const auto &client : getClientIterable()) {
156             if (activeOnly && !client->active()) {
157               continue;
158             }
159             app_state_t curState = client->appState();
160             if (curState >= topState) {
161                 int32_t curPriority = source_priority(client->source());
162                 if (curPriority >= topPriority) {
163                     topClient = client;
164                     topPriority = curPriority;
165                 }
166                 topState = curState;
167             }
168         }
169         if (topClient != nullptr) {
170             break;
171         }
172     }
173     return topClient;
174 }
175 
isSoundTrigger() const176 bool AudioInputDescriptor::isSoundTrigger() const {
177     // sound trigger and non sound trigger clients are not mixed on a given input
178     // so check only first client
179     if (getClientCount() == 0) {
180         return false;
181     }
182     return getClientIterable().begin()->isSoundTrigger();
183 }
184 
getPatchHandle() const185 audio_patch_handle_t AudioInputDescriptor::getPatchHandle() const
186 {
187     return mPatchHandle;
188 }
189 
setPatchHandle(audio_patch_handle_t handle)190 void AudioInputDescriptor::setPatchHandle(audio_patch_handle_t handle)
191 {
192     mPatchHandle = handle;
193     for (const auto &client : getClientIterable()) {
194         if (client->active()) {
195             updateClientRecordingConfiguration(
196                     client->isLowLevel() ? RECORD_CONFIG_EVENT_START : RECORD_CONFIG_EVENT_UPDATE,
197                     client);
198         }
199     }
200 }
201 
getConfig() const202 audio_config_base_t AudioInputDescriptor::getConfig() const
203 {
204     const audio_config_base_t config = { .sample_rate = mSamplingRate, .channel_mask = mChannelMask,
205             .format = mFormat };
206     return config;
207 }
208 
open(const audio_config_t * config,const sp<DeviceDescriptor> & device,audio_source_t source,audio_input_flags_t flags,audio_io_handle_t * input)209 status_t AudioInputDescriptor::open(const audio_config_t *config,
210                                        const sp<DeviceDescriptor> &device,
211                                        audio_source_t source,
212                                        audio_input_flags_t flags,
213                                        audio_io_handle_t *input)
214 {
215     audio_config_t lConfig;
216     if (config == nullptr) {
217         lConfig = AUDIO_CONFIG_INITIALIZER;
218         lConfig.sample_rate = mSamplingRate;
219         lConfig.channel_mask = mChannelMask;
220         lConfig.format = mFormat;
221     } else {
222         lConfig = *config;
223     }
224 
225     mDevice = device;
226 
227     ALOGV("opening input for device %s profile %p name %s",
228           mDevice->toString().c_str(), mProfile.get(), mProfile->getName().c_str());
229 
230     audio_devices_t deviceType = mDevice->type();
231 
232     status_t status = mClientInterface->openInput(mProfile->getModuleHandle(),
233                                                   input,
234                                                   &lConfig,
235                                                   &deviceType,
236                                                   String8(mDevice->address().c_str()),
237                                                   source,
238                                                   flags);
239     LOG_ALWAYS_FATAL_IF(mDevice->type() != deviceType,
240                         "%s openInput returned device %08x when given device %08x",
241                         __FUNCTION__, mDevice->type(), deviceType);
242 
243     if (status == NO_ERROR) {
244         LOG_ALWAYS_FATAL_IF(*input == AUDIO_IO_HANDLE_NONE,
245                             "%s openInput returned input handle %d for device %s",
246                             __FUNCTION__, *input, mDevice->toString().c_str());
247         mSamplingRate = lConfig.sample_rate;
248         mChannelMask = lConfig.channel_mask;
249         mFormat = lConfig.format;
250         mId = PolicyAudioPort::getNextUniqueId();
251         mIoHandle = *input;
252         mProfile->curOpenCount++;
253     }
254 
255     return status;
256 }
257 
start()258 status_t AudioInputDescriptor::start()
259 {
260     if (!isActive()) {
261         if (!mProfile->canStartNewIo()) {
262             ALOGI("%s mProfile->curActiveCount %d", __func__, mProfile->curActiveCount);
263             return INVALID_OPERATION;
264         }
265         mProfile->curActiveCount++;
266     }
267     return NO_ERROR;
268 }
269 
stop()270 void AudioInputDescriptor::stop()
271 {
272     if (!isActive()) {
273         LOG_ALWAYS_FATAL_IF(mProfile->curActiveCount < 1,
274                             "%s invalid profile active count %u",
275                             __func__, mProfile->curActiveCount);
276         mProfile->curActiveCount--;
277     }
278 }
279 
close()280 void AudioInputDescriptor::close()
281 {
282     if (mIoHandle != AUDIO_IO_HANDLE_NONE) {
283         // clean up active clients if any (can happen if close() is called to force
284         // clients to reconnect
285         for (const auto &client : getClientIterable()) {
286             if (client->active()) {
287                 ALOGW("%s client with port ID %d still active on input %d",
288                     __func__, client->portId(), mId);
289                 setClientActive(client, false);
290                 stop();
291             }
292         }
293 
294         mClientInterface->closeInput(mIoHandle);
295         LOG_ALWAYS_FATAL_IF(mProfile->curOpenCount < 1, "%s profile open count %u",
296                             __FUNCTION__, mProfile->curOpenCount);
297 
298         mProfile->curOpenCount--;
299         LOG_ALWAYS_FATAL_IF(mProfile->curOpenCount <  mProfile->curActiveCount,
300                 "%s(%d): mProfile->curOpenCount %d < mProfile->curActiveCount %d.",
301                 __func__, mId, mProfile->curOpenCount, mProfile->curActiveCount);
302         mIoHandle = AUDIO_IO_HANDLE_NONE;
303     }
304 }
305 
addClient(const sp<RecordClientDescriptor> & client)306 void AudioInputDescriptor::addClient(const sp<RecordClientDescriptor> &client) {
307     ClientMapHandler<RecordClientDescriptor>::addClient(client);
308 
309     for (size_t i = 0; i < mEnabledEffects.size(); i++) {
310         if (mEnabledEffects.valueAt(i)->mSession == client->session()) {
311             client->trackEffectEnabled(mEnabledEffects.valueAt(i), true);
312         }
313     }
314 }
315 
setClientActive(const sp<RecordClientDescriptor> & client,bool active)316 void AudioInputDescriptor::setClientActive(const sp<RecordClientDescriptor>& client, bool active)
317 {
318     LOG_ALWAYS_FATAL_IF(getClient(client->portId()) == nullptr,
319         "%s(%d) does not exist on input descriptor", __func__, client->portId());
320     if (active == client->active()) {
321         return;
322     }
323 
324     // Handle non-client-specific activity ref count
325     int32_t oldGlobalActiveCount = mGlobalActiveCount;
326     if (!active && mGlobalActiveCount < 1) {
327         LOG_ALWAYS_FATAL("%s(%d) invalid deactivation with globalActiveCount %d",
328                __func__, client->portId(), mGlobalActiveCount);
329         // mGlobalActiveCount = 1;
330     }
331     const int delta = active ? 1 : -1;
332     mGlobalActiveCount += delta;
333 
334     sp<AudioPolicyMix> policyMix = mPolicyMix.promote();
335     if ((oldGlobalActiveCount == 0) && (mGlobalActiveCount > 0)) {
336         if ((policyMix != NULL) && ((policyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0))
337         {
338             mClientInterface->onDynamicPolicyMixStateUpdate(policyMix->mDeviceAddress,
339                                                             MIX_STATE_MIXING);
340         }
341     } else if ((oldGlobalActiveCount > 0) && (mGlobalActiveCount == 0)) {
342         if ((policyMix != NULL) && ((policyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0))
343         {
344             mClientInterface->onDynamicPolicyMixStateUpdate(policyMix->mDeviceAddress,
345                                                             MIX_STATE_IDLE);
346         }
347     }
348 
349     client->setActive(active);
350 
351     checkSuspendEffects();
352 
353     int event = active ? RECORD_CONFIG_EVENT_START : RECORD_CONFIG_EVENT_STOP;
354     updateClientRecordingConfiguration(event, client);
355 }
356 
updateClientRecordingConfiguration(int event,const sp<RecordClientDescriptor> & client)357 void AudioInputDescriptor::updateClientRecordingConfiguration(
358     int event, const sp<RecordClientDescriptor>& client)
359 {
360     ALOGV("%s riid %d uid %d port %d session %d event %d",
361             __func__, client->riid(), client->uid(), client->portId(), client->session(), event);
362     // do not send callback if starting and no device is selected yet to avoid
363     // double callbacks from startInput() before and after the device is selected
364     // "start" and "stop" events for "high level" clients (AudioRecord) are sent by the client side
365     if ((event == RECORD_CONFIG_EVENT_START && mPatchHandle == AUDIO_PATCH_HANDLE_NONE)
366             || (!client->isLowLevel()
367                     && (event == RECORD_CONFIG_EVENT_START || event == RECORD_CONFIG_EVENT_STOP))) {
368         return;
369     }
370 
371     const audio_config_base_t sessionConfig = client->config();
372     const record_client_info_t recordClientInfo{client->riid(), client->uid(), client->session(),
373                                                 client->source(), client->portId(),
374                                                 client->isSilenced()};
375     const audio_config_base_t config = getConfig();
376 
377     std::vector<effect_descriptor_t> clientEffects;
378     EffectDescriptorCollection effectsList = client->getEnabledEffects();
379     for (size_t i = 0; i < effectsList.size(); i++) {
380         clientEffects.push_back(effectsList.valueAt(i)->mDesc);
381     }
382 
383     std::vector<effect_descriptor_t> effects;
384     effectsList = getEnabledEffects();
385     for (size_t i = 0; i < effectsList.size(); i++) {
386         effects.push_back(effectsList.valueAt(i)->mDesc);
387     }
388 
389     mClientInterface->onRecordingConfigurationUpdate(event, &recordClientInfo, &sessionConfig,
390                                                      clientEffects, &config, effects,
391                                                      mPatchHandle, source());
392 }
393 
getClientsForSession(audio_session_t session)394 RecordClientVector AudioInputDescriptor::getClientsForSession(
395     audio_session_t session)
396 {
397     RecordClientVector clients;
398     for (const auto &client : getClientIterable()) {
399         if (client->session() == session) {
400             clients.push_back(client);
401         }
402     }
403     return clients;
404 }
405 
clientsList(bool activeOnly,audio_source_t source,bool preferredDeviceOnly) const406 RecordClientVector AudioInputDescriptor::clientsList(bool activeOnly, audio_source_t source,
407                                                      bool preferredDeviceOnly) const
408 {
409     RecordClientVector clients;
410     for (const auto &client : getClientIterable()) {
411         if ((!activeOnly || client->active())
412             && (source == AUDIO_SOURCE_DEFAULT || source == client->source())
413             && (!preferredDeviceOnly || client->hasPreferredDevice())) {
414             clients.push_back(client);
415         }
416     }
417     return clients;
418 }
419 
trackEffectEnabled(const sp<EffectDescriptor> & effect,bool enabled)420 void AudioInputDescriptor::trackEffectEnabled(const sp<EffectDescriptor> &effect,
421                                               bool enabled)
422 {
423     if (enabled) {
424         mEnabledEffects.replaceValueFor(effect->mId, effect);
425     } else {
426         mEnabledEffects.removeItem(effect->mId);
427         // always exit from suspend when disabling an effect as only enabled effects
428         // are managed by checkSuspendEffects()
429         if (effect->mSuspended) {
430             effect->mSuspended = false;
431             mClientInterface->setEffectSuspended(effect->mId, effect->mSession, effect->mSuspended);
432         }
433     }
434 
435     RecordClientVector clients = getClientsForSession((audio_session_t)effect->mSession);
436     RecordClientVector updatedClients;
437 
438     for (const auto& client : clients) {
439         sp<EffectDescriptor> clientEffect = client->getEnabledEffects().getEffect(effect->mId);
440         bool changed = (enabled && clientEffect == nullptr)
441                 || (!enabled && clientEffect != nullptr);
442         client->trackEffectEnabled(effect, enabled);
443         if (changed && client->active()) {
444             updatedClients.push_back(client);
445         }
446     }
447 
448     checkSuspendEffects();
449 
450     for (const auto& client : updatedClients) {
451         updateClientRecordingConfiguration(RECORD_CONFIG_EVENT_UPDATE, client);
452     }
453 }
454 
getEnabledEffects() const455 EffectDescriptorCollection AudioInputDescriptor::getEnabledEffects() const
456 {
457     // report effects for highest priority active source as applied to all clients
458     EffectDescriptorCollection enabledEffects;
459     sp<RecordClientDescriptor> topClient = getHighestPriorityClient();
460     if (topClient != nullptr) {
461         enabledEffects = topClient->getEnabledEffects();
462     }
463     return enabledEffects;
464 }
465 
setAppState(audio_port_handle_t portId,app_state_t state)466 void AudioInputDescriptor::setAppState(audio_port_handle_t portId, app_state_t state)
467 {
468     RecordClientVector clients = clientsList(false /*activeOnly*/);
469     RecordClientVector updatedClients;
470 
471     for (const auto& client : clients) {
472         if (portId == client->portId()) {
473             bool wasSilenced = client->isSilenced();
474             client->setAppState(state);
475             if (client->active() && wasSilenced != client->isSilenced()) {
476                 updatedClients.push_back(client);
477             }
478         }
479     }
480 
481     checkSuspendEffects();
482 
483     for (const auto& client : updatedClients) {
484         updateClientRecordingConfiguration(RECORD_CONFIG_EVENT_UPDATE, client);
485     }
486 }
487 
checkSuspendEffects()488 void AudioInputDescriptor::checkSuspendEffects()
489 {
490     sp<RecordClientDescriptor> topClient = getHighestPriorityClient();
491     if (topClient == nullptr) {
492         return;
493     }
494 
495     for (size_t i = 0; i < mEnabledEffects.size(); i++) {
496         sp<EffectDescriptor> effect = mEnabledEffects.valueAt(i);
497         if (effect->mSession == topClient->session()) {
498             if (effect->mSuspended) {
499                 effect->mSuspended = false;
500                 mClientInterface->setEffectSuspended(effect->mId,
501                                                      effect->mSession,
502                                                      effect->mSuspended);
503             }
504         } else if (!effect->mSuspended) {
505             effect->mSuspended = true;
506             mClientInterface->setEffectSuspended(effect->mId,
507                                                  effect->mSession,
508                                                  effect->mSuspended);
509         }
510     }
511 }
512 
dump(String8 * dst) const513 void AudioInputDescriptor::dump(String8 *dst) const
514 {
515     dst->appendFormat(" ID: %d\n", getId());
516     dst->appendFormat(" Sampling rate: %d\n", mSamplingRate);
517     dst->appendFormat(" Format: %d\n", mFormat);
518     dst->appendFormat(" Channels: %08x\n", mChannelMask);
519     dst->appendFormat(" Devices %s\n", mDevice->toString(true /*includeSensitiveInfo*/).c_str());
520     mEnabledEffects.dump(dst, 1 /*spaces*/, false /*verbose*/);
521     dst->append(" AudioRecord Clients:\n");
522     ClientMapHandler<RecordClientDescriptor>::dump(dst);
523     dst->append("\n");
524 }
525 
isSourceActive(audio_source_t source) const526 bool AudioInputCollection::isSourceActive(audio_source_t source) const
527 {
528     for (size_t i = 0; i < size(); i++) {
529         const sp<AudioInputDescriptor>  inputDescriptor = valueAt(i);
530         if (inputDescriptor->isSourceActive(source)) {
531             return true;
532         }
533     }
534     return false;
535 }
536 
getInputFromId(audio_port_handle_t id) const537 sp<AudioInputDescriptor> AudioInputCollection::getInputFromId(audio_port_handle_t id) const
538 {
539     for (size_t i = 0; i < size(); i++) {
540         const sp<AudioInputDescriptor> inputDescriptor = valueAt(i);
541         if (inputDescriptor->getId() == id) {
542             return inputDescriptor;
543         }
544     }
545     return NULL;
546 }
547 
activeInputsCountOnDevices(const DeviceVector & devices) const548 uint32_t AudioInputCollection::activeInputsCountOnDevices(const DeviceVector &devices) const
549 {
550     uint32_t count = 0;
551     for (size_t i = 0; i < size(); i++) {
552         const sp<AudioInputDescriptor>  inputDescriptor = valueAt(i);
553         if (inputDescriptor->isActive() &&
554                 (devices.isEmpty() || devices.contains(inputDescriptor->getDevice()))) {
555             count++;
556         }
557     }
558     return count;
559 }
560 
getActiveInputs()561 Vector<sp <AudioInputDescriptor> > AudioInputCollection::getActiveInputs()
562 {
563     Vector<sp <AudioInputDescriptor> > activeInputs;
564 
565     for (size_t i = 0; i < size(); i++) {
566         const sp<AudioInputDescriptor>  inputDescriptor = valueAt(i);
567         if (inputDescriptor->isActive()) {
568             activeInputs.add(inputDescriptor);
569         }
570     }
571     return activeInputs;
572 }
573 
getInputForClient(audio_port_handle_t portId)574 sp<AudioInputDescriptor> AudioInputCollection::getInputForClient(audio_port_handle_t portId)
575 {
576     for (size_t i = 0; i < size(); i++) {
577         sp<AudioInputDescriptor> inputDesc = valueAt(i);
578         if (inputDesc->getClient(portId) != nullptr) {
579             return inputDesc;
580         }
581     }
582     return 0;
583 }
584 
trackEffectEnabled(const sp<EffectDescriptor> & effect,bool enabled)585 void AudioInputCollection::trackEffectEnabled(const sp<EffectDescriptor> &effect,
586                                             bool enabled)
587 {
588     for (size_t i = 0; i < size(); i++) {
589         sp<AudioInputDescriptor> inputDesc = valueAt(i);
590         if (inputDesc->mIoHandle == effect->mIo) {
591             return inputDesc->trackEffectEnabled(effect, enabled);
592         }
593     }
594 }
595 
clearSessionRoutesForDevice(const sp<DeviceDescriptor> & disconnectedDevice)596 void AudioInputCollection::clearSessionRoutesForDevice(
597     const sp<DeviceDescriptor> &disconnectedDevice)
598 {
599     for (size_t i = 0; i < size(); i++) {
600         sp<AudioInputDescriptor> inputDesc = valueAt(i);
601         for (const auto& client : inputDesc->getClientIterable()) {
602             if (client->preferredDeviceId() == disconnectedDevice->getId()) {
603                 client->setPreferredDeviceId(AUDIO_PORT_HANDLE_NONE);
604             }
605         }
606     }
607 }
608 
dump(String8 * dst) const609 void AudioInputCollection::dump(String8 *dst) const
610 {
611     dst->append("\nInputs dump:\n");
612     for (size_t i = 0; i < size(); i++) {
613         dst->appendFormat("- Input %d dump:\n", keyAt(i));
614         valueAt(i)->dump(dst);
615     }
616 }
617 
618 }; //namespace android
619