• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ST_AUDIO_SESSION_H
17 #define ST_AUDIO_SESSION_H
18 
19 #include <mutex>
20 
21 #include "audio_interrupt_info.h"
22 #include "audio_session_info.h"
23 
24 namespace OHOS {
25 namespace AudioStandard {
26 enum class AudioSessionState {
27     SESSION_INVALID = -1,
28     SESSION_NEW = 0,
29     SESSION_ACTIVE = 1,
30     SESSION_DEACTIVE = 2,
31     SESSION_RELEASED = 3,
32 };
33 
34 class AudioSessionStateMonitor;
35 
36 class AudioSession {
37 public:
38     AudioSession(const int32_t callerPid, const AudioSessionStrategy &strategy,
39         const std::shared_ptr<AudioSessionStateMonitor> audioSessionStateMonitor);
40     ~AudioSession();
41 
42     int32_t Activate();
43     int32_t Deactivate();
44     AudioSessionState GetSessionState();
45     void SetSessionStrategy(const AudioSessionStrategy strategy);
46     AudioSessionStrategy GetSessionStrategy();
47     int32_t AddAudioInterrpt(const std::pair<AudioInterrupt, AudioFocuState> interruptPair);
48     int32_t RemoveAudioInterrpt(const std::pair<AudioInterrupt, AudioFocuState> interruptPair);
49     int32_t RemoveAudioInterrptByStreamId(const uint32_t &streamId);
50     bool IsAudioSessionEmpty();
51     bool IsAudioRendererEmpty();
52 
53 private:
54     std::mutex sessionMutex_;
55 
56     int32_t callerPid_;
57     AudioSessionStrategy strategy_;
58     std::weak_ptr<AudioSessionStateMonitor> audioSessionStateMonitor_;
59 
60     AudioSessionState state_ = AudioSessionState::SESSION_INVALID;
61     std::unordered_map<uint32_t, std::pair<AudioInterrupt, AudioFocuState>> interruptMap_;
62 };
63 } // namespace AudioStandard
64 } // namespace OHOS
65 
66 #endif // ST_AUDIO_SESSION_SERVICE_H