1 /* 2 * Copyright (c) 2022-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 16 #ifndef OHOS_DAUDIO_SINK_MANAGER_H 17 #define OHOS_DAUDIO_SINK_MANAGER_H 18 19 #include <map> 20 #include <mutex> 21 22 #include "single_instance.h" 23 24 #include "daudio_sink_dev.h" 25 #include "idaudio_source.h" 26 #include "i_av_engine_provider_callback.h" 27 28 namespace OHOS { 29 namespace DistributedHardware { 30 class EngineProviderListener : public IAVEngineProviderCallback { 31 public: EngineProviderListener()32 EngineProviderListener() {}; ~EngineProviderListener()33 ~EngineProviderListener() override {}; 34 35 int32_t OnProviderEvent(const AVTransEvent &event) override; 36 }; 37 38 class DAudioSinkManager { 39 DECLARE_SINGLE_INSTANCE_BASE(DAudioSinkManager); 40 public: 41 int32_t Init(); 42 int32_t UnInit(); 43 int32_t HandleDAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, 44 const std::string &eventContent); 45 int32_t DAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, 46 const std::string &eventContent); 47 void OnSinkDevReleased(const std::string &devId); 48 void NotifyEvent(const std::string &devId, const int32_t eventType, const std::string &eventContent); 49 void ClearAudioDev(const std::string &devId); 50 int32_t CreateAudioDevice(const std::string &devId); 51 void SetChannelState(const std::string &content); 52 53 private: 54 DAudioSinkManager(); 55 ~DAudioSinkManager(); 56 int32_t LoadAVSenderEngineProvider(); 57 int32_t UnloadAVSenderEngineProvider(); 58 int32_t LoadAVReceiverEngineProvider(); 59 int32_t UnloadAVReceiverEngineProvider(); 60 61 private: 62 static constexpr const char* DEVCLEAR_THREAD = "sinkClearTh"; 63 std::mutex devMapMutex_; 64 std::unordered_map<std::string, std::shared_ptr<DAudioSinkDev>> audioDevMap_; 65 std::mutex remoteSvrMutex_; 66 std::map<std::string, sptr<IDAudioSource>> sourceServiceMap_; 67 std::thread devClearThread_; 68 std::string localNetworkId_; 69 ChannelState channelState_ = ChannelState::UNKNOWN; 70 71 std::shared_ptr<EngineProviderListener> providerListener_; 72 IAVEngineProvider *sendProviderPtr_ = nullptr; 73 IAVEngineProvider *rcvProviderPtr_ = nullptr; 74 void *pSHandler_ = nullptr; 75 void *pRHandler_ = nullptr; 76 }; 77 } // DistributedHardware 78 } // OHOS 79 #endif // OHOS_DAUDIO_SINK_MANAGER_H 80