180922886Sopenharmony_ci/* 280922886Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480922886Sopenharmony_ci * you may not use this file except in compliance with the License. 580922886Sopenharmony_ci * You may obtain a copy of the License at 680922886Sopenharmony_ci * 780922886Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880922886Sopenharmony_ci * 980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280922886Sopenharmony_ci * See the License for the specific language governing permissions and 1380922886Sopenharmony_ci * limitations under the License. 1480922886Sopenharmony_ci */ 1580922886Sopenharmony_ci 1680922886Sopenharmony_ci#ifndef AV_SESSION_AUDIO_ADAPTER_H 1780922886Sopenharmony_ci#define AV_SESSION_AUDIO_ADAPTER_H 1880922886Sopenharmony_ci 1980922886Sopenharmony_ci#include <functional> 2080922886Sopenharmony_ci#include <memory> 2180922886Sopenharmony_ci#include <mutex> 2280922886Sopenharmony_ci#include "audio_stream_manager.h" 2380922886Sopenharmony_ci#include "audio_info.h" 2480922886Sopenharmony_ci 2580922886Sopenharmony_cinamespace OHOS::AVSession { 2680922886Sopenharmony_ciusing AudioRendererChangeInfos = std::vector<std::shared_ptr<AudioStandard::AudioRendererChangeInfo>>; 2780922886Sopenharmony_ciusing DeviceChangeAction = AudioStandard::DeviceChangeAction; 2880922886Sopenharmony_ciclass AudioAdapter : public AudioStandard::AudioRendererStateChangeCallback, 2980922886Sopenharmony_ci public AudioStandard::AudioManagerDeviceChangeCallback, 3080922886Sopenharmony_ci public std::enable_shared_from_this<AudioAdapter> { 3180922886Sopenharmony_cipublic: 3280922886Sopenharmony_ci using StateListener = std::function<void(const AudioRendererChangeInfos& infos)>; 3380922886Sopenharmony_ci using DeviceChangeListener = std::function<void(const DeviceChangeAction& deviceChangeAction)>; 3480922886Sopenharmony_ci static AudioAdapter& GetInstance(); 3580922886Sopenharmony_ci 3680922886Sopenharmony_ci AudioAdapter(); 3780922886Sopenharmony_ci ~AudioAdapter() override; 3880922886Sopenharmony_ci 3980922886Sopenharmony_ci void Init(); 4080922886Sopenharmony_ci 4180922886Sopenharmony_ci void AddStreamRendererStateListener(const StateListener& listener); 4280922886Sopenharmony_ci 4380922886Sopenharmony_ci void AddDeviceChangeListener(const DeviceChangeListener& listener); 4480922886Sopenharmony_ci 4580922886Sopenharmony_ci int32_t MuteAudioStream(int32_t uid); 4680922886Sopenharmony_ci 4780922886Sopenharmony_ci int32_t UnMuteAudioStream(int32_t uid); 4880922886Sopenharmony_ci 4980922886Sopenharmony_ci int32_t PauseAudioStream(int32_t uid, AudioStandard::StreamUsage usage); 5080922886Sopenharmony_ci 5180922886Sopenharmony_ci void OnRendererStateChange(const AudioRendererChangeInfos& infos) override; 5280922886Sopenharmony_ci 5380922886Sopenharmony_ci void OnDeviceChange(const DeviceChangeAction& deviceChangeAction) override; 5480922886Sopenharmony_ci 5580922886Sopenharmony_ci bool GetRendererRunning(int32_t uid); 5680922886Sopenharmony_ci 5780922886Sopenharmony_ciprivate: 5880922886Sopenharmony_ci static std::shared_ptr<AudioAdapter> instance_; 5980922886Sopenharmony_ci static std::once_flag onceFlag_; 6080922886Sopenharmony_ci std::vector<StateListener> listeners_; 6180922886Sopenharmony_ci std::vector<DeviceChangeListener> deviceChangeListeners_; 6280922886Sopenharmony_ci}; 6380922886Sopenharmony_ci} 6480922886Sopenharmony_ci#endif // AV_SESSION_AUDIO_ADAPTER_H 65