• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 
16 #include "OHAudioManager.h"
17 
18 #include <set>
19 
20 #include "audio_common_log.h"
21 #include "audio_system_manager.h"
22 
23 namespace {
24 // should be same with OH_AudioScene in native_audio_common.h
25 const std::set<OHOS::AudioStandard::AudioScene> INVALID_AUDIO_SCENES = {
26     OHOS::AudioStandard::AUDIO_SCENE_DEFAULT,
27     OHOS::AudioStandard::AUDIO_SCENE_RINGING,
28     OHOS::AudioStandard::AUDIO_SCENE_PHONE_CALL,
29     OHOS::AudioStandard::AUDIO_SCENE_PHONE_CHAT,
30     OHOS::AudioStandard::AUDIO_SCENE_VOICE_RINGING
31 };
32 }
33 using OHOS::AudioStandard::OHAudioManager;
convertManager(OH_AudioManager * audioManager)34 static OHOS::AudioStandard::OHAudioManager *convertManager(OH_AudioManager *audioManager)
35 {
36     return (OHAudioManager*) audioManager;
37 }
38 
OH_GetAudioManager(OH_AudioManager ** audioManager)39 OH_AudioCommon_Result OH_GetAudioManager(OH_AudioManager **audioManager)
40 {
41     if (audioManager == nullptr) {
42         AUDIO_ERR_LOG("invalid OH_AudioManager");
43         return AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM;
44     }
45     OHAudioManager *manager = OHAudioManager::GetInstance();
46     *audioManager = (OH_AudioManager *)manager;
47     return AUDIOCOMMON_RESULT_SUCCESS;
48 }
49 
OH_GetAudioScene(OH_AudioManager * manager,OH_AudioScene * scene)50 OH_AudioCommon_Result OH_GetAudioScene(OH_AudioManager* manager, OH_AudioScene *scene)
51 {
52     if (manager == nullptr || scene == nullptr) {
53         AUDIO_ERR_LOG("invalid OH_AudioManager or scene");
54         return AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM;
55     }
56     *scene = static_cast<OH_AudioScene>(convertManager(manager)->GetAudioScene());
57     return AUDIOCOMMON_RESULT_SUCCESS;
58 }
59 
60 namespace OHOS {
61 namespace AudioStandard {
GetInstance()62 OHAudioManager *OHAudioManager::GetInstance()
63 {
64     static OHAudioManager manager;
65     return &manager;
66 }
67 
GetAudioScene()68 AudioScene OHAudioManager::GetAudioScene()
69 {
70     AudioScene scene = AudioSystemManager::GetInstance()->GetAudioScene();
71     if (!INVALID_AUDIO_SCENES.count(scene)) {
72         AUDIO_WARNING_LOG("Get scene:%{public}d that is not defined, return defalut!", scene);
73         return AUDIO_SCENE_DEFAULT;
74     }
75     if (scene == AUDIO_SCENE_VOICE_RINGING) {
76         return AUDIO_SCENE_RINGING;
77     }
78     return scene;
79 }
80 }  // namespace AudioStandard
81 }  // namespace OHOS
82