• 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 <android-base/stringprintf.h>
21 
22 #include <audiomanager/AudioManager.h>
23 #include <media/AudioPolicy.h>
24 #include <policy.h>
25 #include <AudioPolicyInterface.h>
26 #include "AudioInputDescriptor.h"
27 #include "AudioPolicyMix.h"
28 #include "HwModule.h"
29 
30 namespace android {
31 
AudioInputDescriptor(const sp<IOProfile> & profile,AudioPolicyClientInterface * clientInterface)32 AudioInputDescriptor::AudioInputDescriptor(const sp<IOProfile>& profile,
33                                            AudioPolicyClientInterface *clientInterface)
34     : mProfile(profile)
35     ,  mClientInterface(clientInterface)
36 {
37     if (profile != NULL) {
38         profile->pickAudioProfile(mSamplingRate, mChannelMask, mFormat);
39         if (profile->getGains().size() > 0) {
40             profile->getGains()[0]->getDefaultConfig(&mGain);
41         }
42         mFlags = (audio_input_flags_t)profile->getFlags();
43     }
44 }
45 
getModuleHandle() const46 audio_module_handle_t AudioInputDescriptor::getModuleHandle() const
47 {
48     if (mProfile == 0) {
49         return AUDIO_MODULE_HANDLE_NONE;
50     }
51     return mProfile->getModuleHandle();
52 }
53 
source() const54 audio_source_t AudioInputDescriptor::source() const
55 {
56     return getHighestPriorityAttributes().source;
57 }
58 
applyAudioPortConfig(const struct audio_port_config * config,audio_port_config * backupConfig)59 status_t AudioInputDescriptor::applyAudioPortConfig(const struct audio_port_config *config,
60                                                     audio_port_config *backupConfig)
61 {
62     struct audio_port_config localBackupConfig = { .config_mask = config->config_mask };
63     status_t status = NO_ERROR;
64 
65     toAudioPortConfig(&localBackupConfig);
66     if ((status = validationBeforeApplyConfig(config)) == NO_ERROR) {
67         AudioPortConfig::applyAudioPortConfig(config, backupConfig);
68     }
69 
70     if (backupConfig != NULL) {
71         *backupConfig = localBackupConfig;
72     }
73     return status;
74 }
75 
toAudioPortConfig(struct audio_port_config * dstConfig,const struct audio_port_config * srcConfig) const76 void AudioInputDescriptor::toAudioPortConfig(struct audio_port_config *dstConfig,
77                                              const struct audio_port_config *srcConfig) const
78 {
79     ALOG_ASSERT(mProfile != 0,
80                 "toAudioPortConfig() called on input with null profile %d", mIoHandle);
81     dstConfig->config_mask = AUDIO_PORT_CONFIG_ALL;
82     if (srcConfig != NULL) {
83         dstConfig->config_mask |= srcConfig->config_mask;
84     }
85 
86     AudioPortConfig::toAudioPortConfig(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                                                   static_cast<audio_input_flags_t>(
239                                                           flags & mProfile->getFlags()));
240     LOG_ALWAYS_FATAL_IF(mDevice->type() != deviceType,
241                         "%s openInput returned device %08x when given device %08x",
242                         __FUNCTION__, mDevice->type(), deviceType);
243 
244     if (status == NO_ERROR) {
245         LOG_ALWAYS_FATAL_IF(*input == AUDIO_IO_HANDLE_NONE,
246                             "%s openInput returned input handle %d for device %s",
247                             __FUNCTION__, *input, mDevice->toString().c_str());
248         mSamplingRate = lConfig.sample_rate;
249         mChannelMask = lConfig.channel_mask;
250         mFormat = lConfig.format;
251         mId = PolicyAudioPort::getNextUniqueId();
252         mIoHandle = *input;
253         mProfile->curOpenCount++;
254     }
255 
256     return status;
257 }
258 
start()259 status_t AudioInputDescriptor::start()
260 {
261     if (!isActive()) {
262         if (!mProfile->canStartNewIo()) {
263             ALOGI("%s mProfile->curActiveCount %d", __func__, mProfile->curActiveCount);
264             return INVALID_OPERATION;
265         }
266         mProfile->curActiveCount++;
267     }
268     return NO_ERROR;
269 }
270 
stop()271 void AudioInputDescriptor::stop()
272 {
273     if (!isActive()) {
274         LOG_ALWAYS_FATAL_IF(mProfile->curActiveCount < 1,
275                             "%s invalid profile active count %u",
276                             __func__, mProfile->curActiveCount);
277         mProfile->curActiveCount--;
278     }
279 }
280 
close()281 void AudioInputDescriptor::close()
282 {
283     if (mIoHandle != AUDIO_IO_HANDLE_NONE) {
284         // clean up active clients if any (can happen if close() is called to force
285         // clients to reconnect
286         for (const auto &client : getClientIterable()) {
287             if (client->active()) {
288                 ALOGW("%s client with port ID %d still active on input %d",
289                     __func__, client->portId(), mId);
290                 setClientActive(client, false);
291                 stop();
292             }
293         }
294 
295         mClientInterface->closeInput(mIoHandle);
296         LOG_ALWAYS_FATAL_IF(mProfile->curOpenCount < 1, "%s profile open count %u",
297                             __FUNCTION__, mProfile->curOpenCount);
298 
299         mProfile->curOpenCount--;
300         LOG_ALWAYS_FATAL_IF(mProfile->curOpenCount <  mProfile->curActiveCount,
301                 "%s(%d): mProfile->curOpenCount %d < mProfile->curActiveCount %d.",
302                 __func__, mId, mProfile->curOpenCount, mProfile->curActiveCount);
303         mIoHandle = AUDIO_IO_HANDLE_NONE;
304     }
305 }
306 
addClient(const sp<RecordClientDescriptor> & client)307 void AudioInputDescriptor::addClient(const sp<RecordClientDescriptor> &client) {
308     ClientMapHandler<RecordClientDescriptor>::addClient(client);
309 
310     for (size_t i = 0; i < mEnabledEffects.size(); i++) {
311         if (mEnabledEffects.valueAt(i)->mSession == client->session()) {
312             client->trackEffectEnabled(mEnabledEffects.valueAt(i), true);
313         }
314     }
315 }
316 
setClientActive(const sp<RecordClientDescriptor> & client,bool active)317 void AudioInputDescriptor::setClientActive(const sp<RecordClientDescriptor>& client, bool active)
318 {
319     LOG_ALWAYS_FATAL_IF(getClient(client->portId()) == nullptr,
320         "%s(%d) does not exist on input descriptor", __func__, client->portId());
321     if (active == client->active()) {
322         return;
323     }
324 
325     // Handle non-client-specific activity ref count
326     int32_t oldGlobalActiveCount = mGlobalActiveCount;
327     if (!active && mGlobalActiveCount < 1) {
328         LOG_ALWAYS_FATAL("%s(%d) invalid deactivation with globalActiveCount %d",
329                __func__, client->portId(), mGlobalActiveCount);
330         // mGlobalActiveCount = 1;
331     }
332     const int delta = active ? 1 : -1;
333     mGlobalActiveCount += delta;
334 
335     sp<AudioPolicyMix> policyMix = mPolicyMix.promote();
336     if ((oldGlobalActiveCount == 0) && (mGlobalActiveCount > 0)) {
337         if ((policyMix != NULL) && ((policyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0))
338         {
339             mClientInterface->onDynamicPolicyMixStateUpdate(policyMix->mDeviceAddress,
340                                                             MIX_STATE_MIXING);
341         }
342     } else if ((oldGlobalActiveCount > 0) && (mGlobalActiveCount == 0)) {
343         if ((policyMix != NULL) && ((policyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0))
344         {
345             mClientInterface->onDynamicPolicyMixStateUpdate(policyMix->mDeviceAddress,
346                                                             MIX_STATE_IDLE);
347         }
348     }
349 
350     client->setActive(active);
351 
352     checkSuspendEffects();
353 
354     int event = active ? RECORD_CONFIG_EVENT_START : RECORD_CONFIG_EVENT_STOP;
355     updateClientRecordingConfiguration(event, client);
356 }
357 
updateClientRecordingConfiguration(int event,const sp<RecordClientDescriptor> & client)358 void AudioInputDescriptor::updateClientRecordingConfiguration(
359     int event, const sp<RecordClientDescriptor>& client)
360 {
361     ALOGV("%s riid %d uid %d port %d session %d event %d",
362             __func__, client->riid(), client->uid(), client->portId(), client->session(), event);
363     // do not send callback if starting and no device is selected yet to avoid
364     // double callbacks from startInput() before and after the device is selected
365     // "start" and "stop" events for "high level" clients (AudioRecord) are sent by the client side
366     if ((event == RECORD_CONFIG_EVENT_START && mPatchHandle == AUDIO_PATCH_HANDLE_NONE)
367             || (!client->isLowLevel()
368                     && (event == RECORD_CONFIG_EVENT_START || event == RECORD_CONFIG_EVENT_STOP))) {
369         return;
370     }
371 
372     const audio_config_base_t sessionConfig = client->config();
373     const record_client_info_t recordClientInfo{client->riid(), client->uid(), client->session(),
374                                                 client->source(), client->portId(),
375                                                 client->isSilenced()};
376     const audio_config_base_t config = getConfig();
377 
378     std::vector<effect_descriptor_t> clientEffects;
379     EffectDescriptorCollection effectsList = client->getEnabledEffects();
380     for (size_t i = 0; i < effectsList.size(); i++) {
381         clientEffects.push_back(effectsList.valueAt(i)->mDesc);
382     }
383 
384     std::vector<effect_descriptor_t> effects;
385     effectsList = getEnabledEffects();
386     for (size_t i = 0; i < effectsList.size(); i++) {
387         effects.push_back(effectsList.valueAt(i)->mDesc);
388     }
389 
390     mClientInterface->onRecordingConfigurationUpdate(event, &recordClientInfo, &sessionConfig,
391                                                      clientEffects, &config, effects,
392                                                      mPatchHandle, source());
393 }
394 
getClientsForSession(audio_session_t session)395 RecordClientVector AudioInputDescriptor::getClientsForSession(
396     audio_session_t session)
397 {
398     RecordClientVector clients;
399     for (const auto &client : getClientIterable()) {
400         if (client->session() == session) {
401             clients.push_back(client);
402         }
403     }
404     return clients;
405 }
406 
clientsList(bool activeOnly,audio_source_t source,bool preferredDeviceOnly) const407 RecordClientVector AudioInputDescriptor::clientsList(bool activeOnly, audio_source_t source,
408                                                      bool preferredDeviceOnly) const
409 {
410     RecordClientVector clients;
411     for (const auto &client : getClientIterable()) {
412         if ((!activeOnly || client->active())
413             && (source == AUDIO_SOURCE_DEFAULT || source == client->source())
414             && (!preferredDeviceOnly || client->hasPreferredDevice())) {
415             clients.push_back(client);
416         }
417     }
418     return clients;
419 }
420 
trackEffectEnabled(const sp<EffectDescriptor> & effect,bool enabled)421 void AudioInputDescriptor::trackEffectEnabled(const sp<EffectDescriptor> &effect,
422                                               bool enabled)
423 {
424     if (enabled) {
425         mEnabledEffects.replaceValueFor(effect->mId, effect);
426     } else {
427         mEnabledEffects.removeItem(effect->mId);
428         // always exit from suspend when disabling an effect as only enabled effects
429         // are managed by checkSuspendEffects()
430         if (effect->mSuspended) {
431             effect->mSuspended = false;
432             mClientInterface->setEffectSuspended(effect->mId, effect->mSession, effect->mSuspended);
433         }
434     }
435 
436     RecordClientVector clients = getClientsForSession((audio_session_t)effect->mSession);
437     RecordClientVector updatedClients;
438 
439     for (const auto& client : clients) {
440         sp<EffectDescriptor> clientEffect = client->getEnabledEffects().getEffect(effect->mId);
441         bool changed = (enabled && clientEffect == nullptr)
442                 || (!enabled && clientEffect != nullptr);
443         client->trackEffectEnabled(effect, enabled);
444         if (changed && client->active()) {
445             updatedClients.push_back(client);
446         }
447     }
448 
449     checkSuspendEffects();
450 
451     for (const auto& client : updatedClients) {
452         updateClientRecordingConfiguration(RECORD_CONFIG_EVENT_UPDATE, client);
453     }
454 }
455 
getEnabledEffects() const456 EffectDescriptorCollection AudioInputDescriptor::getEnabledEffects() const
457 {
458     // report effects for highest priority active source as applied to all clients
459     EffectDescriptorCollection enabledEffects;
460     sp<RecordClientDescriptor> topClient = getHighestPriorityClient();
461     if (topClient != nullptr) {
462         enabledEffects = topClient->getEnabledEffects();
463     }
464     return enabledEffects;
465 }
466 
setAppState(audio_port_handle_t portId,app_state_t state)467 void AudioInputDescriptor::setAppState(audio_port_handle_t portId, app_state_t state)
468 {
469     RecordClientVector clients = clientsList(false /*activeOnly*/);
470     RecordClientVector updatedClients;
471 
472     for (const auto& client : clients) {
473         if (portId == client->portId()) {
474             bool wasSilenced = client->isSilenced();
475             client->setAppState(state);
476             if (client->active() && wasSilenced != client->isSilenced()) {
477                 updatedClients.push_back(client);
478             }
479         }
480     }
481 
482     checkSuspendEffects();
483 
484     for (const auto& client : updatedClients) {
485         updateClientRecordingConfiguration(RECORD_CONFIG_EVENT_UPDATE, client);
486     }
487 }
488 
checkSuspendEffects()489 void AudioInputDescriptor::checkSuspendEffects()
490 {
491     sp<RecordClientDescriptor> topClient = getHighestPriorityClient();
492     if (topClient == nullptr) {
493         return;
494     }
495 
496     for (size_t i = 0; i < mEnabledEffects.size(); i++) {
497         sp<EffectDescriptor> effect = mEnabledEffects.valueAt(i);
498         if (effect->mSession == topClient->session()) {
499             if (effect->mSuspended) {
500                 effect->mSuspended = false;
501                 mClientInterface->setEffectSuspended(effect->mId,
502                                                      effect->mSession,
503                                                      effect->mSuspended);
504             }
505         } else if (!effect->mSuspended) {
506             effect->mSuspended = true;
507             mClientInterface->setEffectSuspended(effect->mId,
508                                                  effect->mSession,
509                                                  effect->mSuspended);
510         }
511     }
512 }
513 
dump(String8 * dst,int spaces,const char * extraInfo) const514 void AudioInputDescriptor::dump(String8 *dst, int spaces, const char* extraInfo) const
515 {
516     std::string flagsLiteral = toString(mFlags);
517     if (!flagsLiteral.empty()) {
518         flagsLiteral = " (" + flagsLiteral + ")";
519     }
520     dst->appendFormat("Port ID: %d; 0x%04x%s%s%s\n",
521             getId(), mFlags, flagsLiteral.c_str(),
522             extraInfo != nullptr ? "; " : "", extraInfo != nullptr ? extraInfo : "");
523     dst->appendFormat("%*s%s; %d; Channel mask: 0x%x\n", spaces, "",
524             audio_format_to_string(mFormat), mSamplingRate, mChannelMask);
525     dst->appendFormat("%*sDevices: %s\n", spaces, "",
526             mDevice->toString(true /*includeSensitiveInfo*/).c_str());
527     mEnabledEffects.dump(dst, spaces /*spaces*/, false /*verbose*/);
528     if (getClientCount() != 0) {
529         dst->appendFormat("%*sAudioRecord Clients (%zu):\n", spaces, "", getClientCount());
530         ClientMapHandler<RecordClientDescriptor>::dump(dst, spaces);
531         dst->append("\n");
532     }
533 }
534 
isSourceActive(audio_source_t source) const535 bool AudioInputCollection::isSourceActive(audio_source_t source) const
536 {
537     for (size_t i = 0; i < size(); i++) {
538         const sp<AudioInputDescriptor>  inputDescriptor = valueAt(i);
539         if (inputDescriptor->isSourceActive(source)) {
540             return true;
541         }
542     }
543     return false;
544 }
545 
getInputFromId(audio_port_handle_t id) const546 sp<AudioInputDescriptor> AudioInputCollection::getInputFromId(audio_port_handle_t id) const
547 {
548     for (size_t i = 0; i < size(); i++) {
549         const sp<AudioInputDescriptor> inputDescriptor = valueAt(i);
550         if (inputDescriptor->getId() == id) {
551             return inputDescriptor;
552         }
553     }
554     return NULL;
555 }
556 
activeInputsCountOnDevices(const DeviceVector & devices) const557 uint32_t AudioInputCollection::activeInputsCountOnDevices(const DeviceVector &devices) const
558 {
559     uint32_t count = 0;
560     for (size_t i = 0; i < size(); i++) {
561         const sp<AudioInputDescriptor>  inputDescriptor = valueAt(i);
562         if (inputDescriptor->isActive() &&
563                 (devices.isEmpty() || devices.contains(inputDescriptor->getDevice()))) {
564             count++;
565         }
566     }
567     return count;
568 }
569 
getActiveInputs()570 Vector<sp <AudioInputDescriptor> > AudioInputCollection::getActiveInputs()
571 {
572     Vector<sp <AudioInputDescriptor> > activeInputs;
573 
574     for (size_t i = 0; i < size(); i++) {
575         const sp<AudioInputDescriptor>  inputDescriptor = valueAt(i);
576         if (inputDescriptor->isActive()) {
577             activeInputs.add(inputDescriptor);
578         }
579     }
580     return activeInputs;
581 }
582 
getInputForClient(audio_port_handle_t portId)583 sp<AudioInputDescriptor> AudioInputCollection::getInputForClient(audio_port_handle_t portId)
584 {
585     for (size_t i = 0; i < size(); i++) {
586         sp<AudioInputDescriptor> inputDesc = valueAt(i);
587         if (inputDesc->getClient(portId) != nullptr) {
588             return inputDesc;
589         }
590     }
591     return 0;
592 }
593 
trackEffectEnabled(const sp<EffectDescriptor> & effect,bool enabled)594 void AudioInputCollection::trackEffectEnabled(const sp<EffectDescriptor> &effect,
595                                             bool enabled)
596 {
597     for (size_t i = 0; i < size(); i++) {
598         sp<AudioInputDescriptor> inputDesc = valueAt(i);
599         if (inputDesc->mIoHandle == effect->mIo) {
600             return inputDesc->trackEffectEnabled(effect, enabled);
601         }
602     }
603 }
604 
clearSessionRoutesForDevice(const sp<DeviceDescriptor> & disconnectedDevice)605 void AudioInputCollection::clearSessionRoutesForDevice(
606     const sp<DeviceDescriptor> &disconnectedDevice)
607 {
608     for (size_t i = 0; i < size(); i++) {
609         sp<AudioInputDescriptor> inputDesc = valueAt(i);
610         for (const auto& client : inputDesc->getClientIterable()) {
611             if (client->preferredDeviceId() == disconnectedDevice->getId()) {
612                 client->setPreferredDeviceId(AUDIO_PORT_HANDLE_NONE);
613             }
614         }
615     }
616 }
617 
dump(String8 * dst) const618 void AudioInputCollection::dump(String8 *dst) const
619 {
620     dst->appendFormat("\n Inputs (%zu):\n", size());
621     for (size_t i = 0; i < size(); i++) {
622         const std::string prefix = base::StringPrintf("  %zu. ", i + 1);
623         const std::string extraInfo = base::StringPrintf("I/O handle: %d", keyAt(i));
624         dst->appendFormat("%s", prefix.c_str());
625         valueAt(i)->dump(dst, prefix.size(), extraInfo.c_str());
626     }
627 }
628 
629 }; //namespace android
630