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_SOURCE_MANAGER_H 17 #define OHOS_DAUDIO_SOURCE_MANAGER_H 18 19 #include <map> 20 #include <mutex> 21 #include <thread> 22 23 #include "daudio_hdi_handler.h" 24 #include "daudio_source_dev.h" 25 #include "daudio_source_mgr_callback.h" 26 #include "idaudio_sink.h" 27 #include "single_instance.h" 28 29 namespace OHOS { 30 namespace DistributedHardware { 31 class DAudioSourceManager { 32 DECLARE_SINGLE_INSTANCE_BASE(DAudioSourceManager); 33 34 public: 35 int32_t Init(const sptr<IDAudioIpcCallback> &callback); 36 int32_t UnInit(); 37 int32_t EnableDAudio(const std::string &devId, const std::string &dhId, const std::string &version, 38 const std::string &attrs, const std::string &reqId); 39 int32_t DisableDAudio(const std::string &devId, const std::string &dhId, const std::string &reqId); 40 int32_t HandleDAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, 41 const std::string &eventContent); 42 int32_t DAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType, 43 const std::string &eventContent); 44 int32_t OnEnableDAudio(const std::string &devId, const std::string &dhId, const int32_t result); 45 int32_t OnDisableDAudio(const std::string &devId, const std::string &dhId, const int32_t result); 46 int32_t LoadAVSenderEngineProvider(); 47 int32_t UnloadAVSenderEngineProvider(); 48 int32_t LoadAVReceiverEngineProvider(); 49 int32_t UnloadAVReceiverEngineProvider(); 50 IAVEngineProvider *getSenderProvider(); 51 IAVEngineProvider *getReceiverProvider(); 52 53 private: 54 DAudioSourceManager(); 55 ~DAudioSourceManager(); 56 int32_t CreateAudioDevice(const std::string &devId); 57 void DeleteAudioDevice(const std::string &devId, const std::string &dhId); 58 std::string GetRequestId(const std::string &devId, const std::string &dhId); 59 void ClearAudioDev(const std::string &devId); 60 61 typedef struct { 62 std::string devId; 63 std::shared_ptr<DAudioSourceDev> dev; 64 std::map<std::string, std::string> ports; 65 } AudioDevice; 66 67 private: 68 static constexpr const char* DEVCLEAR_THREAD = "sourceClearTh"; 69 70 std::string localDevId_; 71 std::mutex devMapMtx_; 72 std::map<std::string, AudioDevice> audioDevMap_; 73 std::mutex remoteSvrMutex_; 74 std::map<std::string, sptr<IDAudioSink>> sinkServiceMap_; 75 sptr<IDAudioIpcCallback> ipcCallback_ = nullptr; 76 std::shared_ptr<DAudioSourceMgrCallback> daudioMgrCallback_ = nullptr; 77 std::thread devClearThread_; 78 IAVEngineProvider *sendProviderPtr_ = nullptr; 79 IAVEngineProvider *rcvProviderPtr_ = nullptr; 80 void *pSHandler_ = nullptr; 81 void *pRHandler_ = nullptr; 82 }; 83 } // DistributedHardware 84 } // OHOS 85 #endif // OHOS_DAUDIO_SINK_MANAGER_H