1 /* 2 * Copyright (c) 2023-2024 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_DSCREEN_MGR_V2_0_H 17 #define OHOS_DSCREEN_MGR_V2_0_H 18 19 #include "distributed_hardware_fwk_kit.h" 20 #include "dm_common.h" 21 #include "single_instance.h" 22 #include "screen_manager.h" 23 24 #include "av_sender_engine_adapter.h" 25 #include "dscreen.h" 26 #include "dscreen_maprelation.h" 27 #include "idistributed_hardware_source.h" 28 #include "idscreen_sink.h" 29 #include "idscreen_source_callback.h" 30 #include "video_param.h" 31 32 namespace OHOS { 33 namespace DistributedHardware { 34 namespace V2_0 { 35 class DScreenCallback : public IDScreenCallback { 36 public: 37 void OnRegResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 38 const int32_t status, const std::string &data) override; 39 void OnUnregResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 40 const int32_t status, const std::string &data) override; 41 }; 42 43 class DScreenGroupListener : public Rosen::ScreenManager::IScreenGroupListener { 44 public: 45 void OnChange(const std::vector<uint64_t> &screenIds, Rosen::ScreenGroupChangeEvent event) override; 46 }; 47 48 class DScreenManager : public std::enable_shared_from_this<DScreenManager> { 49 DECLARE_SINGLE_INSTANCE_BASE(DScreenManager); 50 51 public: 52 DScreenManager(); 53 ~DScreenManager(); 54 55 void OnRegResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 56 int32_t status, const std::string &data); 57 void OnUnregResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 58 int32_t status, const std::string &data); 59 60 int32_t Initialize(); 61 int32_t Release(); 62 int32_t EnableDistributedScreen(const std::string &devId, const std::string &dhId, const EnableParam ¶m, 63 const std::string &reqId); 64 int32_t DisableDistributedScreen(const std::string &devId, const std::string &dhId, const std::string &reqId); 65 void RegisterDScreenCallback(const sptr<IDScreenSourceCallback> &callback); 66 void HandleScreenChange(const std::shared_ptr<DScreen> &changedScreen, Rosen::ScreenGroupChangeEvent event); 67 std::shared_ptr<DScreen> FindDScreenById(uint64_t screenId); 68 void GetScreenDumpInfo(std::string &result); 69 70 private: 71 int32_t StartDScreenMirror(const std::shared_ptr<DScreen> &dScreen); 72 int32_t StopDScreenMirror(const std::shared_ptr<DScreen> &dScreen); 73 int32_t LoadAVSenderEngineProvider(); 74 int32_t UnloadAVSenderEngineProvider(); 75 void PublishMessage(const DHTopic topic, const std::shared_ptr<DScreen> &dScreen); 76 77 private: 78 std::string localDevId_; 79 std::mutex dScreenMapMtx_; 80 std::mutex dScreenCallbackMtx_; 81 std::map<std::string, std::shared_ptr<DScreen>> dScreens_; 82 83 IAVEngineProvider *providerPtr_ = nullptr; 84 sptr<DScreenGroupListener> dScreenGroupListener_ = nullptr; 85 std::shared_ptr<IDScreenCallback> dScreenCallback_ = nullptr; 86 sptr<IDScreenSourceCallback> dScreenSourceCallbackProxy_ = nullptr; 87 }; 88 } // namespace V2_0 89 } // namespace DistributedHardware 90 } // namespace OHOS 91 #endif