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 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,int spaces,const char * extraInfo) const513 void AudioInputDescriptor::dump(String8 *dst, int spaces, const char* extraInfo) const
514 {
515 std::string flagsLiteral = toString(mFlags);
516 if (!flagsLiteral.empty()) {
517 flagsLiteral = " (" + flagsLiteral + ")";
518 }
519 dst->appendFormat("Port ID: %d; 0x%04x%s%s%s\n",
520 getId(), mFlags, flagsLiteral.c_str(),
521 extraInfo != nullptr ? "; " : "", extraInfo != nullptr ? extraInfo : "");
522 dst->appendFormat("%*s%s; %d; Channel mask: 0x%x\n", spaces, "",
523 audio_format_to_string(mFormat), mSamplingRate, mChannelMask);
524 dst->appendFormat("%*sDevices: %s\n", spaces, "",
525 mDevice->toString(true /*includeSensitiveInfo*/).c_str());
526 mEnabledEffects.dump(dst, spaces /*spaces*/, false /*verbose*/);
527 if (getClientCount() != 0) {
528 dst->appendFormat("%*sAudioRecord Clients (%zu):\n", spaces, "", getClientCount());
529 ClientMapHandler<RecordClientDescriptor>::dump(dst, spaces);
530 dst->append("\n");
531 }
532 }
533
isSourceActive(audio_source_t source) const534 bool AudioInputCollection::isSourceActive(audio_source_t source) const
535 {
536 for (size_t i = 0; i < size(); i++) {
537 const sp<AudioInputDescriptor> inputDescriptor = valueAt(i);
538 if (inputDescriptor->isSourceActive(source)) {
539 return true;
540 }
541 }
542 return false;
543 }
544
getInputFromId(audio_port_handle_t id) const545 sp<AudioInputDescriptor> AudioInputCollection::getInputFromId(audio_port_handle_t id) const
546 {
547 for (size_t i = 0; i < size(); i++) {
548 const sp<AudioInputDescriptor> inputDescriptor = valueAt(i);
549 if (inputDescriptor->getId() == id) {
550 return inputDescriptor;
551 }
552 }
553 return NULL;
554 }
555
activeInputsCountOnDevices(const DeviceVector & devices) const556 uint32_t AudioInputCollection::activeInputsCountOnDevices(const DeviceVector &devices) const
557 {
558 uint32_t count = 0;
559 for (size_t i = 0; i < size(); i++) {
560 const sp<AudioInputDescriptor> inputDescriptor = valueAt(i);
561 if (inputDescriptor->isActive() &&
562 (devices.isEmpty() || devices.contains(inputDescriptor->getDevice()))) {
563 count++;
564 }
565 }
566 return count;
567 }
568
getActiveInputs()569 Vector<sp <AudioInputDescriptor> > AudioInputCollection::getActiveInputs()
570 {
571 Vector<sp <AudioInputDescriptor> > activeInputs;
572
573 for (size_t i = 0; i < size(); i++) {
574 const sp<AudioInputDescriptor> inputDescriptor = valueAt(i);
575 if (inputDescriptor->isActive()) {
576 activeInputs.add(inputDescriptor);
577 }
578 }
579 return activeInputs;
580 }
581
getInputForClient(audio_port_handle_t portId)582 sp<AudioInputDescriptor> AudioInputCollection::getInputForClient(audio_port_handle_t portId)
583 {
584 for (size_t i = 0; i < size(); i++) {
585 sp<AudioInputDescriptor> inputDesc = valueAt(i);
586 if (inputDesc->getClient(portId) != nullptr) {
587 return inputDesc;
588 }
589 }
590 return 0;
591 }
592
trackEffectEnabled(const sp<EffectDescriptor> & effect,bool enabled)593 void AudioInputCollection::trackEffectEnabled(const sp<EffectDescriptor> &effect,
594 bool enabled)
595 {
596 for (size_t i = 0; i < size(); i++) {
597 sp<AudioInputDescriptor> inputDesc = valueAt(i);
598 if (inputDesc->mIoHandle == effect->mIo) {
599 return inputDesc->trackEffectEnabled(effect, enabled);
600 }
601 }
602 }
603
clearSessionRoutesForDevice(const sp<DeviceDescriptor> & disconnectedDevice)604 void AudioInputCollection::clearSessionRoutesForDevice(
605 const sp<DeviceDescriptor> &disconnectedDevice)
606 {
607 for (size_t i = 0; i < size(); i++) {
608 sp<AudioInputDescriptor> inputDesc = valueAt(i);
609 for (const auto& client : inputDesc->getClientIterable()) {
610 if (client->preferredDeviceId() == disconnectedDevice->getId()) {
611 client->setPreferredDeviceId(AUDIO_PORT_HANDLE_NONE);
612 }
613 }
614 }
615 }
616
dump(String8 * dst) const617 void AudioInputCollection::dump(String8 *dst) const
618 {
619 dst->appendFormat("\n Inputs (%zu):\n", size());
620 for (size_t i = 0; i < size(); i++) {
621 const std::string prefix = base::StringPrintf(" %zu. ", i + 1);
622 const std::string extraInfo = base::StringPrintf("I/O handle: %d", keyAt(i));
623 dst->appendFormat("%s", prefix.c_str());
624 valueAt(i)->dump(dst, prefix.size(), extraInfo.c_str());
625 }
626 }
627
628 }; //namespace android
629