• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 OHOS_FOCUS_SESSION_STRATEGY_H
17 #define OHOS_FOCUS_SESSION_STRATEGY_H
18 
19 #include <functional>
20 #include <map>
21 #include <memory>
22 #include "audio_stream_manager.h"
23 #include "audio_adapter.h"
24 
25 namespace OHOS::AVSession {
26 class FocusSessionStrategy {
27 public:
28     struct FocusSessionChangeInfo {
29         int32_t uid {};
30     };
31     using FocusSessionChangeCallback = std::function<void(const FocusSessionChangeInfo&)>;
32     using FocusSessionSelector = std::function<bool(const FocusSessionChangeInfo&)>;
33 
34     FocusSessionStrategy();
35     ~FocusSessionStrategy();
36 
37     void Init();
38 
39     void RegisterFocusSessionChangeCallback(const FocusSessionChangeCallback& callback);
40     void RegisterFocusSessionSelector(const FocusSessionSelector& selector);
41 
42 private:
43     void HandleAudioRenderStateChangeEvent(const AudioRendererChangeInfos& infos);
44 
45     bool IsFocusSession(const AudioStandard::AudioRendererChangeInfo& info);
46     bool SelectFocusSession(const AudioRendererChangeInfos& infos, FocusSessionChangeInfo& sessionInfo);
47 
48     FocusSessionChangeCallback callback_;
49     FocusSessionSelector selector_;
50     std::shared_ptr<AudioStandard::AudioRendererStateChangeCallback> audioRendererStateChangeCallback_;
51     std::recursive_mutex stateLock_;
52     std::map<int32_t, AudioStandard::RendererState> lastStates_;
53 };
54 }
55 #endif // OHOS_FOCUS_SESSION_STRATEGY_H