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_SCREEN_DATA_CHANNEL_IMPL_H 17 #define OHOS_SCREEN_DATA_CHANNEL_IMPL_H 18 19 #include <memory> 20 #include <string> 21 22 #include "data_buffer.h" 23 #include "iscreen_channel.h" 24 #include "softbus_adapter.h" 25 26 #include "nlohmann/json.hpp" 27 namespace OHOS { 28 namespace DistributedHardware { 29 class ScreenDataChannelImpl : public IScreenChannel, 30 public ISoftbusListener, 31 public std::enable_shared_from_this<ScreenDataChannelImpl> { 32 public: ScreenDataChannelImpl(std::string peerDevId)33 explicit ScreenDataChannelImpl(std::string peerDevId) : peerDevId_(peerDevId) {}; 34 ~ScreenDataChannelImpl() override = default; 35 int32_t CreateSession(const std::shared_ptr<IScreenChannelListener> &listener) override; 36 int32_t ReleaseSession() override; 37 int32_t OpenSession(const std::shared_ptr<IScreenChannelListener> listener) override; 38 int32_t CloseSession() override; 39 int32_t SendData(const std::shared_ptr<DataBuffer> &screenData) override; 40 void SetJpegSessionFlag(bool flag) override; 41 int32_t SendFullData(const std::shared_ptr<DataBuffer> &screenData); 42 int32_t SendDirtyData(const std::shared_ptr<DataBuffer> &screenData); 43 void ProcessDirtyData(const StreamData *data, std::shared_ptr<DataBuffer> dataBuffer, const StreamData *ext); 44 void ProcessDullData(const StreamData *data, std::shared_ptr<DataBuffer> dataBuffer); 45 void OnSessionOpened(int32_t sessionId, PeerSocketInfo info) override; 46 void OnSessionClosed(int32_t sessionId, ShutdownReason reason) override; 47 void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) override; 48 void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, 49 const StreamFrameInfo *param) override; 50 void DirtyVecToJson(nlohmann::json &rectJson, const std::shared_ptr<DataBuffer> &screenData); 51 void JsonToDirtyJson(nlohmann::json &rectJson, std::shared_ptr<DataBuffer> &screenData); 52 private: 53 static const constexpr char *DSCREEN_LOG_TAG = "ScreenDataChannel"; 54 bool jpegSessionFlag_ = false; 55 const std::string peerDevId_; 56 int32_t sessionId_ = 0; 57 int32_t jpegSessionId_ = 0; 58 bool dataSessionOpened = false; 59 bool jpegSessionOpened = false; 60 std::weak_ptr<IScreenChannelListener> channelListener_; 61 }; 62 } // namespace DistributedHardware 63 } // namespace OHOS 64 #endif