• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "media_errors.h"
16 #include "media_log.h"
17 #include "soundpool_manager.h"
18 
19 namespace OHOS {
20 namespace Media {
~SoundPoolManager()21 SoundPoolManager::~SoundPoolManager()
22 {
23     MEDIA_LOGI("Destruction SoundPoolManager.");
24     std::lock_guard<std::mutex> lock(mutex_);
25     soundPools_.clear();
26 };
27 
28 
GetSoundPool(const pid_t pid,std::shared_ptr<SoundPool> & soundPool)29 int32_t SoundPoolManager::GetSoundPool(const pid_t pid, std::shared_ptr<SoundPool>& soundPool)
30 {
31     std::lock_guard<std::mutex> lock(mutex_);
32     auto it = soundPools_.find(pid);
33     it != soundPools_.end() ? soundPool = it->second : soundPool = nullptr;
34     return MSERR_OK;
35 }
36 
SetSoundPool(const pid_t pid,std::shared_ptr<SoundPool> soundPool)37 int32_t SoundPoolManager::SetSoundPool(const pid_t pid, std::shared_ptr<SoundPool> soundPool)
38 {
39     std::lock_guard<std::mutex> lock(mutex_);
40     auto it = soundPools_.find(pid);
41     if (it != soundPools_.end()) {
42         MEDIA_LOGI("SoundPool have setted, use old object.");
43         return MSERR_OK;
44     }
45     soundPool = std::make_shared<SoundPool>();
46     soundPools_.emplace(pid, soundPool);
47 
48     return MSERR_OK;
49 }
50 
Release(const pid_t pid)51 int32_t SoundPoolManager::Release(const pid_t pid)
52 {
53     std::lock_guard<std::mutex> lock(mutex_);
54     auto it = soundPools_.find(pid);
55     if (it != soundPools_.end()) {
56         MEDIA_LOGI("Release soundpool, pid:%{pulibc}d.", pid);
57         soundPools_.erase(it);
58         return MSERR_OK;
59     }
60     return MSERR_OK;
61 }
62 } // namespace Media
63 } // namespace OHOS
64