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 <system/audio.h> 20 #include <utils/Errors.h> 21 #include <utils/RefBase.h> 22 #include <utils/Errors.h> 23 #include <utils/KeyedVector.h> 24 #include <media/AudioPolicy.h> 25 #include <media/IAudioPolicyServiceClient.h> 26 #include "AudioSessionInfoProvider.h" 27 28 namespace android { 29 30 class AudioPolicyClientInterface; 31 class AudioPolicyMix; 32 33 class AudioSession : public RefBase, public AudioSessionInfoUpdateListener 34 { 35 public: 36 AudioSession(audio_session_t session, 37 audio_source_t inputSource, 38 audio_format_t format, 39 uint32_t sampleRate, 40 audio_channel_mask_t channelMask, 41 audio_input_flags_t flags, 42 uid_t uid, 43 bool isSoundTrigger, 44 const sp<AudioPolicyMix> &policyMix, 45 AudioPolicyClientInterface *clientInterface); 46 47 status_t dump(int fd, int spaces, int index) const; 48 session()49 audio_session_t session() const { return mRecordClientInfo.session; } inputSource()50 audio_source_t inputSource()const { return mRecordClientInfo.source; } format()51 audio_format_t format() const { return mConfig.format; } sampleRate()52 uint32_t sampleRate() const { return mConfig.sample_rate; } channelMask()53 audio_channel_mask_t channelMask() const { return mConfig.channel_mask; } flags()54 audio_input_flags_t flags() const { return mFlags; } uid()55 uid_t uid() const { return mRecordClientInfo.uid; } setUid(uid_t uid)56 void setUid(uid_t uid) { mRecordClientInfo.uid = uid; } 57 bool matches(const sp<AudioSession> &other) const; isSoundTrigger()58 bool isSoundTrigger() const { return mIsSoundTrigger; } openCount()59 uint32_t openCount() const { return mOpenCount; } ; activeCount()60 uint32_t activeCount() const { return mActiveCount; } ; 61 62 uint32_t changeOpenCount(int delta); 63 uint32_t changeActiveCount(int delta); 64 65 void setInfoProvider(AudioSessionInfoProvider *provider); 66 // implementation of AudioSessionInfoUpdateListener 67 virtual void onSessionInfoUpdate() const; 68 69 private: 70 record_client_info_t mRecordClientInfo; 71 const struct audio_config_base mConfig; 72 const audio_input_flags_t mFlags; 73 bool mIsSoundTrigger; 74 uint32_t mOpenCount; 75 uint32_t mActiveCount; 76 wp<AudioPolicyMix> mPolicyMix; // non NULL when used by a dynamic policy 77 AudioPolicyClientInterface* mClientInterface; 78 const AudioSessionInfoProvider* mInfoProvider; 79 }; 80 81 class AudioSessionCollection : 82 public DefaultKeyedVector<audio_session_t, sp<AudioSession> >, 83 public AudioSessionInfoUpdateListener 84 { 85 public: 86 status_t addSession(audio_session_t session, 87 const sp<AudioSession>& audioSession, 88 AudioSessionInfoProvider *provider); 89 90 status_t removeSession(audio_session_t session); 91 92 uint32_t getOpenCount() const; 93 94 AudioSessionCollection getActiveSessions() const; 95 size_t getActiveSessionCount() const; 96 bool hasActiveSession() const; 97 bool isSourceActive(audio_source_t source) const; 98 audio_source_t getHighestPrioritySource(bool activeOnly) const; 99 100 // implementation of AudioSessionInfoUpdateListener 101 virtual void onSessionInfoUpdate() const; 102 103 status_t dump(int fd, int spaces) const; 104 }; 105 106 }; // namespace android 107