146f34cbfSopenharmony_ci/*
246f34cbfSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
346f34cbfSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
446f34cbfSopenharmony_ci * you may not use this file except in compliance with the License.
546f34cbfSopenharmony_ci * You may obtain a copy of the License at
646f34cbfSopenharmony_ci *
746f34cbfSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
846f34cbfSopenharmony_ci *
946f34cbfSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1046f34cbfSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1146f34cbfSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1246f34cbfSopenharmony_ci * See the License for the specific language governing permissions and
1346f34cbfSopenharmony_ci * limitations under the License.
1446f34cbfSopenharmony_ci */
1546f34cbfSopenharmony_ci
1646f34cbfSopenharmony_ci#include "OHAudioManager.h"
1746f34cbfSopenharmony_ci
1846f34cbfSopenharmony_ci#include <set>
1946f34cbfSopenharmony_ci
2046f34cbfSopenharmony_ci#include "audio_info.h"
2146f34cbfSopenharmony_ci#include "audio_common_log.h"
2246f34cbfSopenharmony_ci#include "audio_system_manager.h"
2346f34cbfSopenharmony_ci
2446f34cbfSopenharmony_cinamespace {
2546f34cbfSopenharmony_ci// should be same with OH_AudioScene in native_audio_common.h
2646f34cbfSopenharmony_ciconst std::set<OHOS::AudioStandard::AudioScene> INVALID_AUDIO_SCENES = {
2746f34cbfSopenharmony_ci    OHOS::AudioStandard::AUDIO_SCENE_DEFAULT,
2846f34cbfSopenharmony_ci    OHOS::AudioStandard::AUDIO_SCENE_RINGING,
2946f34cbfSopenharmony_ci    OHOS::AudioStandard::AUDIO_SCENE_PHONE_CALL,
3046f34cbfSopenharmony_ci    OHOS::AudioStandard::AUDIO_SCENE_PHONE_CHAT,
3146f34cbfSopenharmony_ci    OHOS::AudioStandard::AUDIO_SCENE_VOICE_RINGING
3246f34cbfSopenharmony_ci};
3346f34cbfSopenharmony_ci}
3446f34cbfSopenharmony_ciusing OHOS::AudioStandard::OHAudioManager;
3546f34cbfSopenharmony_cistatic OHOS::AudioStandard::OHAudioManager *convertManager(OH_AudioManager *audioManager)
3646f34cbfSopenharmony_ci{
3746f34cbfSopenharmony_ci    return (OHAudioManager*) audioManager;
3846f34cbfSopenharmony_ci}
3946f34cbfSopenharmony_ci
4046f34cbfSopenharmony_ciOH_AudioCommon_Result OH_GetAudioManager(OH_AudioManager **audioManager)
4146f34cbfSopenharmony_ci{
4246f34cbfSopenharmony_ci    if (audioManager == nullptr) {
4346f34cbfSopenharmony_ci        AUDIO_ERR_LOG("invalid OH_AudioManager");
4446f34cbfSopenharmony_ci        return AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM;
4546f34cbfSopenharmony_ci    }
4646f34cbfSopenharmony_ci    OHAudioManager *manager = OHAudioManager::GetInstance();
4746f34cbfSopenharmony_ci    *audioManager = (OH_AudioManager *)manager;
4846f34cbfSopenharmony_ci    return AUDIOCOMMON_RESULT_SUCCESS;
4946f34cbfSopenharmony_ci}
5046f34cbfSopenharmony_ci
5146f34cbfSopenharmony_ciOH_AudioCommon_Result OH_GetAudioScene(OH_AudioManager* manager, OH_AudioScene *scene)
5246f34cbfSopenharmony_ci{
5346f34cbfSopenharmony_ci    if (manager == nullptr || scene == nullptr) {
5446f34cbfSopenharmony_ci        AUDIO_ERR_LOG("invalid OH_AudioManager or scene");
5546f34cbfSopenharmony_ci        return AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM;
5646f34cbfSopenharmony_ci    }
5746f34cbfSopenharmony_ci    *scene = static_cast<OH_AudioScene>(convertManager(manager)->GetAudioScene());
5846f34cbfSopenharmony_ci    return AUDIOCOMMON_RESULT_SUCCESS;
5946f34cbfSopenharmony_ci}
6046f34cbfSopenharmony_ci
6146f34cbfSopenharmony_cinamespace OHOS {
6246f34cbfSopenharmony_cinamespace AudioStandard {
6346f34cbfSopenharmony_ciOHAudioManager *OHAudioManager::GetInstance()
6446f34cbfSopenharmony_ci{
6546f34cbfSopenharmony_ci    static OHAudioManager manager;
6646f34cbfSopenharmony_ci    return &manager;
6746f34cbfSopenharmony_ci}
6846f34cbfSopenharmony_ci
6946f34cbfSopenharmony_ciAudioScene OHAudioManager::GetAudioScene()
7046f34cbfSopenharmony_ci{
7146f34cbfSopenharmony_ci    AudioScene scene = AudioSystemManager::GetInstance()->GetAudioScene();
7246f34cbfSopenharmony_ci    if (!INVALID_AUDIO_SCENES.count(scene)) {
7346f34cbfSopenharmony_ci        AUDIO_WARNING_LOG("Get scene:%{public}d that is not defined, return defalut!", scene);
7446f34cbfSopenharmony_ci        return AUDIO_SCENE_DEFAULT;
7546f34cbfSopenharmony_ci    }
7646f34cbfSopenharmony_ci    if (scene == AUDIO_SCENE_VOICE_RINGING) {
7746f34cbfSopenharmony_ci        return AUDIO_SCENE_RINGING;
7846f34cbfSopenharmony_ci    }
7946f34cbfSopenharmony_ci    return scene;
8046f34cbfSopenharmony_ci}
8146f34cbfSopenharmony_ci}  // namespace AudioStandard
8246f34cbfSopenharmony_ci}  // namespace OHOS
83