AudioSession.h revision 4b2fcd8abf90b1bd95539f9f4ef2ac39ce9e2df1
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 26namespace android { 27 28class AudioPolicyClientInterface; 29 30class AudioSession : public RefBase 31{ 32public: 33 AudioSession(audio_session_t session, 34 audio_source_t inputSource, 35 audio_format_t format, 36 uint32_t sampleRate, 37 audio_channel_mask_t channelMask, 38 audio_input_flags_t flags, 39 uid_t uid, 40 bool isSoundTrigger, 41 AudioMix* policyMix, 42 AudioPolicyClientInterface *clientInterface); 43 44 status_t dump(int fd, int spaces, int index) const; 45 46 audio_session_t session() const { return mSession; } 47 audio_source_t inputSource()const { return mInputSource; } 48 audio_format_t format() const { return mFormat; } 49 uint32_t sampleRate() const { return mSampleRate; } 50 audio_channel_mask_t channelMask() const { return mChannelMask; } 51 audio_input_flags_t flags() const { return mFlags; } 52 uid_t uid() const { return mUid; } 53 bool matches(const sp<AudioSession> &other) const; 54 bool isSoundTrigger() const { return mIsSoundTrigger; } 55 uint32_t openCount() const { return mOpenCount; } ; 56 uint32_t activeCount() const { return mActiveCount; } ; 57 58 uint32_t changeOpenCount(int delta); 59 uint32_t changeActiveCount(int delta); 60 61private: 62 const audio_session_t mSession; 63 const audio_source_t mInputSource; 64 const audio_format_t mFormat; 65 const uint32_t mSampleRate; 66 const audio_channel_mask_t mChannelMask; 67 const audio_input_flags_t mFlags; 68 const uid_t mUid; 69 bool mIsSoundTrigger; 70 uint32_t mOpenCount; 71 uint32_t mActiveCount; 72 AudioMix* mPolicyMix; // non NULL when used by a dynamic policy 73 AudioPolicyClientInterface* mClientInterface; 74}; 75 76class AudioSessionCollection : 77 public DefaultKeyedVector<audio_session_t, sp<AudioSession> > 78{ 79public: 80 status_t addSession(audio_session_t session, 81 const sp<AudioSession>& audioSession); 82 83 status_t removeSession(audio_session_t session); 84 85 uint32_t getOpenCount() const; 86 87 AudioSessionCollection getActiveSessions() const; 88 bool hasActiveSession() const; 89 bool isSourceActive(audio_source_t source) const; 90 audio_source_t getHighestPrioritySource(bool activeOnly) const; 91 92 status_t dump(int fd, int spaces) const; 93}; 94 95}; // namespace android 96