1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 #include <string> 17 #include "common/const_def.h" 18 #include "wfd_sink.h" 19 #include "wifi_diaplay.h" 20 21 namespace OHOS { 22 namespace Sharing { 23 class WfdSinkDemoListener; 24 class WfdSinkDemo : public std::enable_shared_from_this<WfdSinkDemo> { 25 public: 26 WfdSinkDemo(); 27 ~WfdSinkDemo() = default; 28 29 void ListDevices(); 30 void DoCmd(std::string cmd); 31 void AddDevice(const std::string deviceId); 32 void RemoveDevice(const std::string deviceId); 33 34 bool Stop(); 35 bool Start(); 36 bool GetConfig(); 37 bool SetListener(); 38 bool CreateClient(); 39 bool Mute(std::string deviceId); 40 bool Play(std::string deviceId); 41 bool Pause(std::string deviceId); 42 bool Close(std::string deviceId); 43 bool SetDiscoverable(bool enable); 44 bool AppendSurface(std::string deviceId); 45 bool RemoveSurface(std::string deviceId, std::string surfaceId); 46 bool SetSceneType(std::string deviceId, std::string surfaceId, SceneType sceneType); 47 bool SetMediaFormat(std::string deviceId, VideoFormat videoFormatId, AudioFormat audioFormatId); 48 49 int32_t UnMute(std::string deviceId); 50 51 std::shared_ptr<WfdSink> GetClient(); 52 53 private: 54 uint32_t wdnum_ = 0; 55 56 std::shared_ptr<WfdSink> client_ = nullptr; 57 std::shared_ptr<WfdSinkDemoListener> listener_ = nullptr; 58 59 std::vector<std::string> devices_{}; 60 std::vector<sptr<Surface>> surfaces_{}; 61 62 std::unordered_map<uint64_t, bool> surfaceUsing_{}; 63 std::unordered_map<uint64_t, std::string> surfaceDevMap_{}; 64 }; 65 66 class WfdSinkDemoListener : public IWfdEventListener { 67 public: 68 void OnInfo(std::shared_ptr<BaseMsg> &msg) override; 69 void OnConnectionChanged(const ConnectionInfo &info); 70 void OnError(uint32_t regionId, uint32_t agentId, SharingErrorCode errorCode); 71 SetListener(std::shared_ptr<WfdSinkDemo> listener)72 void SetListener(std::shared_ptr<WfdSinkDemo> listener) 73 { 74 listener_ = listener; 75 } 76 77 private: 78 std::weak_ptr<WfdSinkDemo> listener_; 79 }; 80 } // namespace Sharing 81 } // namespace OHOS 82