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 #pragma once 18 19 #define __STDC_LIMIT_MACROS 20 #include <inttypes.h> 21 22 #include <sys/types.h> 23 24 #include <media/AudioContainers.h> 25 #include <utils/Errors.h> 26 #include <utils/Timers.h> 27 #include <utils/KeyedVector.h> 28 #include <system/audio.h> 29 #include "AudioIODescriptorInterface.h" 30 #include "ClientDescriptor.h" 31 #include "DeviceDescriptor.h" 32 #include "PolicyAudioPort.h" 33 #include <vector> 34 35 namespace android { 36 37 class IOProfile; 38 class AudioPolicyMix; 39 class AudioPolicyClientInterface; 40 41 class ActivityTracking 42 { 43 public: 44 virtual ~ActivityTracking() = default; 45 bool isActive(uint32_t inPastMs = 0, nsecs_t sysTime = 0) const 46 { 47 if (mActivityCount > 0) { 48 return true; 49 } 50 if (inPastMs == 0) { 51 return false; 52 } 53 if (sysTime == 0) { 54 sysTime = systemTime(); 55 } 56 if (ns2ms(sysTime - mStopTime) < inPastMs) { 57 return true; 58 } 59 return false; 60 } changeActivityCount(int delta)61 void changeActivityCount(int delta) 62 { 63 if ((delta + (int)mActivityCount) < 0) { 64 LOG_ALWAYS_FATAL("%s: invalid delta %d, refCount %d", __func__, delta, mActivityCount); 65 } 66 mActivityCount += delta; 67 if (!mActivityCount) { 68 setStopTime(systemTime()); 69 } 70 } getActivityCount()71 uint32_t getActivityCount() const { return mActivityCount; } getStopTime()72 nsecs_t getStopTime() const { return mStopTime; } setStopTime(nsecs_t stopTime)73 void setStopTime(nsecs_t stopTime) { mStopTime = stopTime; } 74 dump(String8 * dst,int spaces)75 virtual void dump(String8 *dst, int spaces) const 76 { 77 dst->appendFormat("%*s- ActivityCount: %d, StopTime: %" PRId64 ", ", spaces, "", 78 getActivityCount(), getStopTime()); 79 } 80 private: 81 uint32_t mActivityCount = 0; 82 nsecs_t mStopTime = 0; 83 }; 84 85 /** 86 * @brief VolumeActivity: it tracks the activity for volume policy (volume index, mute, 87 * memorize previous stop, and store mute if incompatible device with another strategy. 88 */ 89 class VolumeActivity : public ActivityTracking 90 { 91 public: isMuted()92 bool isMuted() const { return mMuteCount > 0; } getMuteCount()93 int getMuteCount() const { return mMuteCount; } incMuteCount()94 int incMuteCount() { return ++mMuteCount; } decMuteCount()95 int decMuteCount() { return mMuteCount > 0 ? --mMuteCount : -1; } 96 dump(String8 * dst,int spaces)97 void dump(String8 *dst, int spaces) const override 98 { 99 ActivityTracking::dump(dst, spaces); 100 dst->appendFormat(", Volume: %.03f, MuteCount: %02d\n", mCurVolumeDb, mMuteCount); 101 } setVolume(float volumeDb)102 void setVolume(float volumeDb) { mCurVolumeDb = volumeDb; } getVolume()103 float getVolume() const { return mCurVolumeDb; } 104 105 private: 106 int mMuteCount = 0; /**< mute request counter */ 107 float mCurVolumeDb = NAN; /**< current volume in dB. */ 108 }; 109 /** 110 * Note: volume activities shall be indexed by CurvesId if we want to allow multiple 111 * curves per volume source, inferring a mute management or volume balancing between HW and SW is 112 * done 113 */ 114 using VolumeActivities = std::map<VolumeSource, VolumeActivity>; 115 116 /** 117 * @brief The Activity class: it tracks the activity for volume policy (volume index, mute, 118 * memorize previous stop, and store mute if incompatible device with another strategy. 119 * Having this class prevents from looping on all attributes (legacy streams) of the strategy 120 */ 121 class RoutingActivity : public ActivityTracking 122 { 123 public: setMutedByDevice(bool isMuted)124 void setMutedByDevice( bool isMuted) { mIsMutedByDevice = isMuted; } isMutedByDevice()125 bool isMutedByDevice() const { return mIsMutedByDevice; } 126 dump(String8 * dst,int spaces)127 void dump(String8 *dst, int spaces) const override { 128 ActivityTracking::dump(dst, spaces); 129 dst->appendFormat("\n"); 130 } 131 private: 132 /** 133 * strategies muted because of incompatible device selection. 134 * See AudioPolicyManager::checkDeviceMuteStrategies() 135 */ 136 bool mIsMutedByDevice = false; 137 }; 138 using RoutingActivities = std::map<product_strategy_t, RoutingActivity>; 139 140 // descriptor for audio outputs. Used to maintain current configuration of each opened audio output 141 // and keep track of the usage of this output by each audio stream type. 142 class AudioOutputDescriptor: public AudioPortConfig, 143 public PolicyAudioPortConfig, 144 public AudioIODescriptorInterface, 145 public ClientMapHandler<TrackClientDescriptor> 146 { 147 public: 148 AudioOutputDescriptor(const sp<PolicyAudioPort>& policyAudioPort, 149 AudioPolicyClientInterface *clientInterface); ~AudioOutputDescriptor()150 virtual ~AudioOutputDescriptor() {} 151 152 void dump(String8 *dst, int spaces, const char* extraInfo = nullptr) const override; 153 void log(const char* indent); 154 devices()155 virtual DeviceVector devices() const { return mDevices; } 156 bool sharesHwModuleWith(const sp<AudioOutputDescriptor>& outputDesc); supportedDevices()157 virtual DeviceVector supportedDevices() const { return mDevices; } isDuplicated()158 virtual bool isDuplicated() const { return false; } latency()159 virtual uint32_t latency() { return 0; } 160 virtual bool isFixedVolume(const DeviceTypeSet& deviceTypes); 161 virtual bool setVolume(float volumeDb, bool muted, 162 VolumeSource volumeSource, const StreamTypeVector &streams, 163 const DeviceTypeSet& deviceTypes, 164 uint32_t delayMs, 165 bool force); 166 167 /** 168 * @brief setStopTime set the stop time due to the client stoppage or a re routing of this 169 * client 170 * @param client to be considered 171 * @param sysTime when the client stopped/was rerouted 172 */ 173 void setStopTime(const sp<TrackClientDescriptor>& client, nsecs_t sysTime); 174 175 /** 176 * Changes the client->active() state and the output descriptor's global active count, 177 * along with the stream active count and mActiveClients. 178 * The client must be previously added by the base class addClient(). 179 * In case of duplicating thread, client shall be added on the duplicated thread, not on the 180 * involved outputs but setClientActive will be called on all output to track strategy and 181 * active client for a given output. 182 * Active ref count of the client will be incremented/decremented through setActive API 183 */ 184 virtual void setClientActive(const sp<TrackClientDescriptor>& client, bool active); 185 bool isClientActive(const sp<TrackClientDescriptor>& client); 186 187 bool isActive(uint32_t inPastMs) const; 188 bool isActive(VolumeSource volumeSource = VOLUME_SOURCE_NONE, 189 uint32_t inPastMs = 0, 190 nsecs_t sysTime = 0) const; 191 bool isAnyActive(VolumeSource volumeSourceToIgnore) const; 192 getActiveVolumeSources()193 std::vector<VolumeSource> getActiveVolumeSources() const { 194 std::vector<VolumeSource> activeList; 195 for (const auto &iter : mVolumeActivities) { 196 if (iter.second.isActive()) { 197 activeList.push_back(iter.first); 198 } 199 } 200 return activeList; 201 } getActivityCount(VolumeSource vs)202 uint32_t getActivityCount(VolumeSource vs) const 203 { 204 return mVolumeActivities.find(vs) != std::end(mVolumeActivities)? 205 mVolumeActivities.at(vs).getActivityCount() : 0; 206 } isMuted(VolumeSource vs)207 bool isMuted(VolumeSource vs) const 208 { 209 return mVolumeActivities.find(vs) != std::end(mVolumeActivities)? 210 mVolumeActivities.at(vs).isMuted() : false; 211 } getMuteCount(VolumeSource vs)212 int getMuteCount(VolumeSource vs) const 213 { 214 return mVolumeActivities.find(vs) != std::end(mVolumeActivities)? 215 mVolumeActivities.at(vs).getMuteCount() : 0; 216 } incMuteCount(VolumeSource vs)217 int incMuteCount(VolumeSource vs) 218 { 219 return mVolumeActivities[vs].incMuteCount(); 220 } decMuteCount(VolumeSource vs)221 int decMuteCount(VolumeSource vs) 222 { 223 return mVolumeActivities[vs].decMuteCount(); 224 } setCurVolume(VolumeSource vs,float volumeDb)225 void setCurVolume(VolumeSource vs, float volumeDb) 226 { 227 // Even if not activity for this source registered, need to create anyway 228 mVolumeActivities[vs].setVolume(volumeDb); 229 } getCurVolume(VolumeSource vs)230 float getCurVolume(VolumeSource vs) const 231 { 232 return mVolumeActivities.find(vs) != std::end(mVolumeActivities) ? 233 mVolumeActivities.at(vs).getVolume() : NAN; 234 } 235 236 bool isStrategyActive(product_strategy_t ps, uint32_t inPastMs = 0, nsecs_t sysTime = 0) const 237 { 238 return mRoutingActivities.find(ps) != std::end(mRoutingActivities)? 239 mRoutingActivities.at(ps).isActive(inPastMs, sysTime) : false; 240 } isStrategyMutedByDevice(product_strategy_t ps)241 bool isStrategyMutedByDevice(product_strategy_t ps) const 242 { 243 return mRoutingActivities.find(ps) != std::end(mRoutingActivities)? 244 mRoutingActivities.at(ps).isMutedByDevice() : false; 245 } setStrategyMutedByDevice(product_strategy_t ps,bool isMuted)246 void setStrategyMutedByDevice(product_strategy_t ps, bool isMuted) 247 { 248 mRoutingActivities[ps].setMutedByDevice(isMuted); 249 } 250 251 // PolicyAudioPortConfig getPolicyAudioPort()252 virtual sp<PolicyAudioPort> getPolicyAudioPort() const 253 { 254 return mPolicyAudioPort; 255 } 256 257 // AudioPortConfig 258 virtual status_t applyAudioPortConfig(const struct audio_port_config *config, 259 struct audio_port_config *backupConfig = NULL); 260 virtual void toAudioPortConfig(struct audio_port_config *dstConfig, 261 const struct audio_port_config *srcConfig = NULL) const; getAudioPort()262 virtual sp<AudioPort> getAudioPort() const { return mPolicyAudioPort->asAudioPort(); } 263 264 virtual void toAudioPort(struct audio_port_v7 *port) const; 265 266 audio_module_handle_t getModuleHandle() const; 267 268 // implementation of AudioIODescriptorInterface 269 audio_config_base_t getConfig() const override; 270 audio_patch_handle_t getPatchHandle() const override; 271 void setPatchHandle(audio_patch_handle_t handle) override; isMmap()272 bool isMmap() override { 273 if (const auto policyPort = getPolicyAudioPort(); policyPort != nullptr) { 274 if (const auto port = policyPort->asAudioPort(); port != nullptr) { 275 return port->isMmap(); 276 } 277 } 278 return false; 279 } 280 281 TrackClientVector clientsList(bool activeOnly = false, 282 product_strategy_t strategy = PRODUCT_STRATEGY_NONE, 283 bool preferredDeviceOnly = false) const; 284 285 // override ClientMapHandler to abort when removing a client when active. removeClient(audio_port_handle_t portId)286 void removeClient(audio_port_handle_t portId) override { 287 auto client = getClient(portId); 288 LOG_ALWAYS_FATAL_IF(client.get() == nullptr, 289 "%s(%d): nonexistent client portId %d", __func__, mId, portId); 290 // it is possible that when a client is removed, we could remove its 291 // associated active count by calling changeStreamActiveCount(), 292 // but that would be hiding a problem, so we log fatal instead. 293 auto clientIter = std::find(begin(mActiveClients), end(mActiveClients), client); 294 LOG_ALWAYS_FATAL_IF(clientIter != mActiveClients.end(), 295 "%s(%d) removing client portId %d which is active (count %d)", 296 __func__, mId, portId, client->getActivityCount()); 297 ClientMapHandler<TrackClientDescriptor>::removeClient(portId); 298 } 299 getActiveClients()300 const TrackClientVector& getActiveClients() const { 301 return mActiveClients; 302 } 303 304 // Returns 0 if not all active clients have the same exclusive preferred device 305 // or the number of active clients with the same exclusive preferred device 306 size_t sameExclusivePreferredDevicesCount() const; 307 useHwGain()308 bool useHwGain() const 309 { 310 return !devices().isEmpty() ? devices().itemAt(0)->hasGainController() : false; 311 } isRouted()312 bool isRouted() const { return mPatchHandle != AUDIO_PATCH_HANDLE_NONE; } 313 314 DeviceVector mDevices; /**< current devices this output is routed to */ 315 wp<AudioPolicyMix> mPolicyMix; // non NULL when used by a dynamic policy 316 getRecommendedMuteDurationMs()317 virtual uint32_t getRecommendedMuteDurationMs() const { return 0; } 318 319 protected: 320 const sp<PolicyAudioPort> mPolicyAudioPort; 321 AudioPolicyClientInterface * const mClientInterface; 322 uint32_t mGlobalActiveCount = 0; // non-client-specific active count 323 audio_patch_handle_t mPatchHandle = AUDIO_PATCH_HANDLE_NONE; 324 audio_output_flags_t& mFlags = AudioPortConfig::mFlags.output; 325 326 // The ActiveClients shows the clients that contribute to the @VolumeSource counts 327 // and may include upstream clients from a duplicating thread. 328 // Compare with the ClientMap (mClients) which are external AudioTrack clients of the 329 // output descriptor (and do not count internal PatchTracks). 330 TrackClientVector mActiveClients; 331 332 RoutingActivities mRoutingActivities; /**< track routing activity on this ouput.*/ 333 334 VolumeActivities mVolumeActivities; /**< track volume activity on this ouput.*/ 335 }; 336 337 // Audio output driven by a software mixer in audio flinger. 338 class SwAudioOutputDescriptor: public AudioOutputDescriptor 339 { 340 public: 341 SwAudioOutputDescriptor(const sp<IOProfile>& profile, 342 AudioPolicyClientInterface *clientInterface); ~SwAudioOutputDescriptor()343 virtual ~SwAudioOutputDescriptor() {} 344 345 void dump(String8 *dst, int spaces, const char* extraInfo = nullptr) const override; 346 virtual DeviceVector devices() const; setDevices(const DeviceVector & devices)347 void setDevices(const DeviceVector &devices) { mDevices = devices; } 348 bool sharesHwModuleWith(const sp<SwAudioOutputDescriptor>& outputDesc); 349 virtual DeviceVector supportedDevices() const; 350 virtual bool devicesSupportEncodedFormats(const DeviceTypeSet& deviceTypes); 351 virtual bool containsSingleDeviceSupportingEncodedFormats( 352 const sp<DeviceDescriptor>& device) const; 353 virtual uint32_t latency(); isDuplicated()354 virtual bool isDuplicated() const { return (mOutput1 != NULL && mOutput2 != NULL); } 355 virtual bool isFixedVolume(const DeviceTypeSet& deviceTypes); subOutput1()356 sp<SwAudioOutputDescriptor> subOutput1() { return mOutput1; } subOutput2()357 sp<SwAudioOutputDescriptor> subOutput2() { return mOutput2; } 358 void setClientActive(const sp<TrackClientDescriptor>& client, bool active) override; setAllClientsInactive()359 void setAllClientsInactive() 360 { 361 for (const auto &client : clientsList(true)) { 362 setClientActive(client, false); 363 } 364 } 365 366 /** 367 * @brief setSwMute for SwOutput routed on a device that supports Hw Gain, this function allows 368 * to mute the tracks associated to a given volume source only. 369 * As an output may host one or more source(s), and as AudioPolicyManager may dispatch or not 370 * the volume change request according to the priority of the volume source to control the 371 * unique hw gain controller, a separated API allows to force a mute/unmute of a volume source. 372 * @param muted true to mute, false otherwise 373 * @param vs volume source to be considered 374 * @param device scoped for the change 375 * @param delayMs potentially applyed to prevent cut sounds. 376 */ 377 void setSwMute(bool muted, VolumeSource vs, const StreamTypeVector &streams, 378 const DeviceTypeSet& device, uint32_t delayMs); 379 380 virtual bool setVolume(float volumeDb, bool muted, 381 VolumeSource volumeSource, const StreamTypeVector &streams, 382 const DeviceTypeSet& device, 383 uint32_t delayMs, 384 bool force); 385 386 virtual void toAudioPortConfig(struct audio_port_config *dstConfig, 387 const struct audio_port_config *srcConfig = NULL) const; 388 virtual void toAudioPort(struct audio_port_v7 *port) const; 389 390 status_t open(const audio_config_t *halConfig, 391 const audio_config_base_t *mixerConfig, 392 const DeviceVector &devices, 393 audio_stream_type_t stream, 394 audio_output_flags_t flags, 395 audio_io_handle_t *output); 396 397 // Called when a stream is about to be started 398 // Note: called before setClientActive(true); 399 status_t start(); 400 // Called after a stream is stopped. 401 // Note: called after setClientActive(false); 402 void stop(); 403 void close(); 404 status_t openDuplicating(const sp<SwAudioOutputDescriptor>& output1, 405 const sp<SwAudioOutputDescriptor>& output2, 406 audio_io_handle_t *ioHandle); 407 408 /** 409 * @brief supportsDevice 410 * @param device to be checked against 411 * @return true if the device is supported by type (for non bus / remote submix devices), 412 * true if the device is supported (both type and address) for bus / remote submix 413 * false otherwise 414 */ 415 bool supportsDevice(const sp<DeviceDescriptor> &device) const; 416 417 /** 418 * @brief supportsAllDevices 419 * @param devices to be checked against 420 * @return true if the device is weakly supported by type (e.g. for non bus / rsubmix devices), 421 * true if the device is supported (both type and address) for bus / remote submix 422 * false otherwise 423 */ 424 bool supportsAllDevices(const DeviceVector &devices) const; 425 426 /** 427 * @brief supportsDevicesForPlayback 428 * @param devices to be checked against 429 * @return true if the devices is a supported combo for playback 430 * false otherwise 431 */ 432 bool supportsDevicesForPlayback(const DeviceVector &devices) const; 433 434 /** 435 * @brief filterSupportedDevices takes a vector of devices and filters them according to the 436 * device supported by this output (the profile from which this output derives from) 437 * @param devices reference device vector to be filtered 438 * @return vector of devices filtered from the supported devices of this output (weakly or not 439 * depending on the device type) 440 */ 441 DeviceVector filterSupportedDevices(const DeviceVector &devices) const; 442 443 uint32_t getRecommendedMuteDurationMs() const override; 444 445 void setTracksInvalidatedStatusByStrategy(product_strategy_t strategy); 446 447 const sp<IOProfile> mProfile; // I/O profile this output derives from 448 audio_io_handle_t mIoHandle; // output handle 449 uint32_t mLatency; // 450 using AudioOutputDescriptor::mFlags; 451 sp<SwAudioOutputDescriptor> mOutput1; // used by duplicated outputs: first output 452 sp<SwAudioOutputDescriptor> mOutput2; // used by duplicated outputs: second output 453 uint32_t mDirectOpenCount; // number of clients using this output (direct outputs only) 454 audio_session_t mDirectClientSession; // session id of the direct output client 455 bool mPendingReopenToQueryProfiles = false; 456 audio_channel_mask_t mMixerChannelMask = AUDIO_CHANNEL_NONE; 457 }; 458 459 // Audio output driven by an input device directly. 460 class HwAudioOutputDescriptor: public AudioOutputDescriptor 461 { 462 public: 463 HwAudioOutputDescriptor(const sp<SourceClientDescriptor>& source, 464 AudioPolicyClientInterface *clientInterface); ~HwAudioOutputDescriptor()465 virtual ~HwAudioOutputDescriptor() {} 466 467 void dump(String8 *dst, int spaces, const char* extraInfo) const override; 468 469 virtual bool setVolume(float volumeDb, bool muted, 470 VolumeSource volumeSource, const StreamTypeVector &streams, 471 const DeviceTypeSet& deviceTypes, 472 uint32_t delayMs, 473 bool force); 474 475 virtual void toAudioPortConfig(struct audio_port_config *dstConfig, 476 const struct audio_port_config *srcConfig = NULL) const; 477 virtual void toAudioPort(struct audio_port_v7 *port) const; 478 479 const sp<SourceClientDescriptor> mSource; 480 481 }; 482 483 class SwAudioOutputCollection : 484 public DefaultKeyedVector< audio_io_handle_t, sp<SwAudioOutputDescriptor> > 485 { 486 public: 487 bool isActive(VolumeSource volumeSource, uint32_t inPastMs = 0) const; 488 489 /** 490 * return whether any source contributing to VolumeSource is playing remotely, override 491 * to change the definition of 492 * local/remote playback, used for instance by notification manager to not make 493 * media players lose audio focus when not playing locally 494 * For the base implementation, "remotely" means playing during screen mirroring which 495 * uses an output for playback with a non-empty, non "0" address. 496 */ 497 bool isActiveRemotely(VolumeSource volumeSource, uint32_t inPastMs = 0) const; 498 499 /** 500 * return whether any source contributing to VolumeSource is playing, but not on a "remote" 501 * device. 502 * Override to change the definition of a local/remote playback. 503 * Used for instance by policy manager to alter the speaker playback ("speaker safe" behavior) 504 * when media plays or not locally. 505 * For the base implementation, "remotely" means playing during screen mirroring. 506 */ 507 bool isActiveLocally(VolumeSource volumeSource, uint32_t inPastMs = 0) const; 508 509 /** 510 * @brief isStrategyActiveOnSameModule checks if the given strategy is active (or was active 511 * in the past) on the given output and all the outputs belonging to the same HW Module 512 * the same module than the given output 513 * @param outputDesc to be considered 514 * @param ps product strategy to be checked upon activity status 515 * @param inPastMs if 0, check currently, otherwise, check in the past 516 * @param sysTime shall be set if request is done for the past activity. 517 * @return true if an output following the strategy is active on the same module than desc, 518 * false otherwise 519 */ 520 bool isStrategyActiveOnSameModule(product_strategy_t ps, 521 const sp<SwAudioOutputDescriptor>& desc, 522 uint32_t inPastMs = 0, nsecs_t sysTime = 0) const; 523 524 /** 525 * @brief isStrategyActive checks if the given strategy is active 526 * on the given output 527 * @param ps product strategy to be checked upon activity status 528 * @return true if an output following the strategy is active, false otherwise 529 */ 530 bool isStrategyActive(product_strategy_t ps) const; 531 532 /** 533 * @brief clearSessionRoutesForDevice: when a device is disconnected, and if this device has 534 * been chosen as the preferred device by any client, the policy manager shall 535 * prevent from using this device any more by clearing all the session routes involving this 536 * device. 537 * In other words, the preferred device port id of these clients will be resetted to NONE. 538 * @param disconnectedDevice device to be disconnected 539 */ 540 void clearSessionRoutesForDevice(const sp<DeviceDescriptor> &disconnectedDevice); 541 542 /** 543 * returns the A2DP output handle if it is open or 0 otherwise 544 */ 545 audio_io_handle_t getA2dpOutput() const; 546 547 /** 548 * returns true if primary HAL supports A2DP Offload 549 */ 550 bool isA2dpOffloadedOnPrimary() const; 551 552 sp<SwAudioOutputDescriptor> getOutputFromId(audio_port_handle_t id) const; 553 554 sp<SwAudioOutputDescriptor> getPrimaryOutput() const; 555 556 /** 557 * @brief isAnyOutputActive checks if any output is active (aka playing) except the one(s) that 558 * hold the volume source to be ignored 559 * @param volumeSourceToIgnore source not to be considered in the activity detection 560 * @return true if any output is active for any volume source except the one to be ignored 561 */ isAnyOutputActive(VolumeSource volumeSourceToIgnore)562 bool isAnyOutputActive(VolumeSource volumeSourceToIgnore) const 563 { 564 for (size_t i = 0; i < size(); i++) { 565 const sp<AudioOutputDescriptor> &outputDesc = valueAt(i); 566 if (outputDesc->isAnyActive(volumeSourceToIgnore)) { 567 return true; 568 } 569 } 570 return false; 571 } 572 573 audio_devices_t getSupportedDevices(audio_io_handle_t handle) const; 574 575 sp<SwAudioOutputDescriptor> getOutputForClient(audio_port_handle_t portId); 576 577 /** 578 * return whether any output is active and routed to any of the specified devices 579 */ 580 bool isAnyDeviceTypeActive(const DeviceTypeSet& deviceTypes) const; 581 582 void dump(String8 *dst) const; 583 }; 584 585 class HwAudioOutputCollection : 586 public DefaultKeyedVector< audio_io_handle_t, sp<HwAudioOutputDescriptor> > 587 { 588 public: 589 bool isActive(VolumeSource volumeSource, uint32_t inPastMs = 0) const; 590 591 /** 592 * @brief isAnyOutputActive checks if any output is active (aka playing) except the one(s) that 593 * hold the volume source to be ignored 594 * @param volumeSourceToIgnore source not to be considered in the activity detection 595 * @return true if any output is active for any volume source except the one to be ignored 596 */ isAnyOutputActive(VolumeSource volumeSourceToIgnore)597 bool isAnyOutputActive(VolumeSource volumeSourceToIgnore) const 598 { 599 for (size_t i = 0; i < size(); i++) { 600 const sp<AudioOutputDescriptor> &outputDesc = valueAt(i); 601 if (outputDesc->isAnyActive(volumeSourceToIgnore)) { 602 return true; 603 } 604 } 605 return false; 606 } 607 608 void dump(String8 *dst) const; 609 }; 610 611 612 } // namespace android 613