1 /*
2  * Copyright (C) 2023 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 SOUNDPOOL_MANAGER_H
16 #define SOUNDPOOL_MANAGER_H
17 
18 #include <unistd.h>
19 #include <unordered_map>
20 #include "media_log.h"
21 #include "soundpool.h"
22 
23 namespace OHOS {
24 namespace Media {
25 class SoundPool;
26 
27 class SoundPoolManager {
28 public:
29     SoundPoolManager(const SoundPoolManager&) = delete;
30     SoundPoolManager& operator = (const SoundPoolManager&) = delete;
31     ~SoundPoolManager();
32 
33     int32_t GetSoundPool(const pid_t pid, std::shared_ptr<SoundPool>& soundPool);
34     int32_t SetSoundPool(const pid_t pid, std::shared_ptr<SoundPool> soundPool);
35     int32_t Release(const pid_t pid);
36 
GetInstance()37     static SoundPoolManager& GetInstance()
38     {
39         static SoundPoolManager instance;
40         return instance;
41     };
42 
43 private:
SoundPoolManager()44     SoundPoolManager() {}
45     std::mutex mutex_;
46     std::unordered_map<pid_t, std::shared_ptr<SoundPool>> soundPools_;
47 };
48 } // namespace Media
49 } // namespace OHOS
50 #endif // SOUNDPOOL_MANAGER_H
51