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