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