• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
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 AUDIO_BACKGROUND_ADAPTER
17 #define AUDIO_BACKGROUND_ADAPTER
18 
19 #include <mutex>
20 #include <list>
21 #include <map>
22 #include "audio_system_manager.h"
23 #include "i_player_service.h"
24 
25 namespace OHOS {
26 namespace Media {
27 class AudioBackgroundAdapter
28     : public AudioStandard::AudioBackgroundMuteCallback,
29       public std::enable_shared_from_this<AudioBackgroundAdapter>  {
30 public:
31     static AudioBackgroundAdapter &Instance();
32     void AddListener(std::weak_ptr<IPlayerService> player, int32_t uid);
33     void OnAudioRestart();
34     AudioBackgroundAdapter();
35     ~AudioBackgroundAdapter();
36 
37 private:
38     void Init();
39     void OnBackgroundMute(const int32_t uid) override;
40 
41     static std::shared_ptr<AudioBackgroundAdapter> instance_;
42     static std::once_flag onceFlag_;
43     std::atomic<bool> init_ = false;
44     std::map<int32_t, std::list<std::weak_ptr<IPlayerService>>> playerMap_;
45     std::mutex mutex_;
46     std::mutex initMutex_;
47 };
48 }
49 }
50 #endif // AUDIO_BACKGROUND_ADAPTER