1 /* 2 * Copyright (c) 2022 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 #ifndef AV_SESSION_AUDIO_ADAPTER_H 17 #define AV_SESSION_AUDIO_ADAPTER_H 18 19 #include <functional> 20 #include <memory> 21 #include <mutex> 22 #include "audio_stream_manager.h" 23 #include "audio_info.h" 24 25 namespace OHOS::AVSession { 26 using AudioRendererChangeInfos = std::vector<std::unique_ptr<AudioStandard::AudioRendererChangeInfo>>; 27 class AudioAdapter : public AudioStandard::AudioRendererStateChangeCallback, 28 public std::enable_shared_from_this<AudioAdapter> { 29 public: 30 using StateListener = std::function<void(const AudioRendererChangeInfos& infos)>; 31 static AudioAdapter& GetInstance(); 32 33 AudioAdapter(); 34 ~AudioAdapter() override; 35 36 void Init(); 37 38 void AddStreamRendererStateListener(const StateListener& listener); 39 40 int32_t PauseAudioStream(int32_t uid); 41 42 void OnRendererStateChange(const AudioRendererChangeInfos& infos) override; 43 44 bool GetRendererState(int32_t uid, AudioStandard::RendererState& rendererState); 45 46 private: 47 static std::shared_ptr<AudioAdapter> instance_; 48 static std::once_flag onceFlag_; 49 std::vector<StateListener> listeners_; 50 }; 51 } 52 #endif // AV_SESSION_AUDIO_ADAPTER_H