• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef ST_AUDIO_COLLABORATIVE_SERVICE_H
16 #define ST_AUDIO_COLLABORATIVE_SERVICE_H
17 #include <mutex>
18 #include <map>
19 #include "audio_device_descriptor.h"
20 #include "audio_effect.h"
21 #include "audio_policy_manager_factory.h"
22 #include "iaudio_policy_interface.h"
23 namespace OHOS {
24 namespace AudioStandard {
25 class AudioCollaborativeService {
26 public:
GetAudioCollaborativeService()27     static AudioCollaborativeService& GetAudioCollaborativeService()
28     {
29         static AudioCollaborativeService audioCollaborativeService;
30         return audioCollaborativeService;
31     }
32     void Init(const std::vector<EffectChain> &effectChains);
33     bool IsCollaborativePlaybackSupported();
34     bool IsCollaborativePlaybackEnabledForDevice(
35         const std::shared_ptr<AudioDeviceDescriptor> &selectedAudioDevice);
36     // only function to change map state
37     int32_t SetCollaborativePlaybackEnabledForDevice(
38         const std::shared_ptr<AudioDeviceDescriptor> &selectedAudioDevice, bool enabled);
39     // current device change, map state unchanged
40     void UpdateCurrentDevice(const AudioDeviceDescriptor &selectedAudioDevice);
41     bool GetRealCollaborativeState();
42 private:
AudioCollaborativeService()43     AudioCollaborativeService()
44         :audioPolicyManager_(AudioPolicyManagerFactory::GetAudioPolicyManager())
45     {}
46     ~AudioCollaborativeService();
47     // outputDeviceChange differentiate if updation is caused by output device change
48     int32_t UpdateCollaborativeStateReal();
49     bool isCollaborativePlaybackSupported_ = false;
50     // same with current device in map
51     bool isCollaborativeStateEnabled_ = false;
52     std::string curDeviceAddress_;
53     std::mutex collaborativeServiceMutex_;
54     std::map<std::string, bool> addressToCollaborativeEnabledMap_;
55     std::map<std::string, bool> addressToCollaborativeMemoryMap_;
56     IAudioPolicyInterface& audioPolicyManager_;
57 };
58 } // OHOS
59 } // AudioStandard
60 #endif