AudioOutputDescriptor.h revision 45ed3b053d9af2250f5ece9ee4e826905c3763a7
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#include "AudioPort.h" 20#include <RoutingStrategy.h> 21#include <utils/Errors.h> 22#include <utils/Timers.h> 23#include <utils/KeyedVector.h> 24#include <system/audio.h> 25 26namespace android { 27 28class IOProfile; 29class AudioMix; 30 31// descriptor for audio outputs. Used to maintain current configuration of each opened audio output 32// and keep track of the usage of this output by each audio stream type. 33class AudioOutputDescriptor: public AudioPortConfig 34{ 35public: 36 AudioOutputDescriptor(const sp<IOProfile>& profile); 37 38 status_t dump(int fd); 39 40 audio_devices_t device() const; 41 void changeRefCount(audio_stream_type_t stream, int delta); 42 43 void setIoHandle(audio_io_handle_t ioHandle); 44 bool isDuplicated() const { return (mOutput1 != NULL && mOutput2 != NULL); } 45 audio_devices_t supportedDevices(); 46 uint32_t latency(); 47 bool sharesHwModuleWith(const sp<AudioOutputDescriptor> outputDesc); 48 bool isActive(uint32_t inPastMs = 0) const; 49 bool isStreamActive(audio_stream_type_t stream, 50 uint32_t inPastMs = 0, 51 nsecs_t sysTime = 0) const; 52 53 virtual void toAudioPortConfig(struct audio_port_config *dstConfig, 54 const struct audio_port_config *srcConfig = NULL) const; 55 virtual sp<AudioPort> getAudioPort() const { return mProfile; } 56 void toAudioPort(struct audio_port *port) const; 57 58 audio_module_handle_t getModuleHandle() const; 59 60 audio_port_handle_t mId; 61 audio_io_handle_t mIoHandle; // output handle 62 uint32_t mLatency; // 63 audio_output_flags_t mFlags; // 64 audio_devices_t mDevice; // current device this output is routed to 65 AudioMix *mPolicyMix; // non NULL when used by a dynamic policy 66 audio_patch_handle_t mPatchHandle; 67 uint32_t mRefCount[AUDIO_STREAM_CNT]; // number of streams of each type using this output 68 nsecs_t mStopTime[AUDIO_STREAM_CNT]; 69 sp<AudioOutputDescriptor> mOutput1; // used by duplicated outputs: first output 70 sp<AudioOutputDescriptor> mOutput2; // used by duplicated outputs: second output 71 float mCurVolume[AUDIO_STREAM_CNT]; // current stream volume 72 int mMuteCount[AUDIO_STREAM_CNT]; // mute request counter 73 const sp<IOProfile> mProfile; // I/O profile this output derives from 74 bool mStrategyMutedByDevice[NUM_STRATEGIES]; // strategies muted because of incompatible 75 // device selection. See checkDeviceMuteStrategies() 76 uint32_t mDirectOpenCount; // number of clients using this output (direct outputs only) 77}; 78 79class AudioOutputCollection : 80 public DefaultKeyedVector< audio_io_handle_t, sp<AudioOutputDescriptor> > 81{ 82public: 83 bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const; 84 85 /** 86 * return whether a stream is playing remotely, override to change the definition of 87 * local/remote playback, used for instance by notification manager to not make 88 * media players lose audio focus when not playing locally 89 * For the base implementation, "remotely" means playing during screen mirroring which 90 * uses an output for playback with a non-empty, non "0" address. 91 */ 92 bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0) const; 93 94 /** 95 * returns the A2DP output handle if it is open or 0 otherwise 96 */ 97 audio_io_handle_t getA2dpOutput() const; 98 99 sp<AudioOutputDescriptor> getOutputFromId(audio_port_handle_t id) const; 100 101 sp<AudioOutputDescriptor> getPrimaryOutput() const; 102 103 /** 104 * return true if any output is playing anything besides the stream to ignore 105 */ 106 bool isAnyOutputActive(audio_stream_type_t streamToIgnore) const; 107 108 audio_devices_t getSupportedDevices(audio_io_handle_t handle) const; 109 110 status_t dump(int fd) const; 111}; 112 113}; // namespace android 114