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_SINK_TRANS_H 17 #define OHOS_SCREEN_SINK_TRANS_H 18 19 #include <string> 20 #include <memory> 21 22 #include "iscreen_sink_trans.h" 23 #include "iscreen_sink_trans_callback.h" 24 #include "iimage_sink_processor.h" 25 #include "iscreen_channel.h" 26 27 namespace OHOS { 28 namespace DistributedHardware { 29 class ScreenSinkTrans : public IScreenSinkTrans, 30 public IScreenChannelListener, 31 public IImageSinkProcessorListener, 32 public std::enable_shared_from_this<ScreenSinkTrans> { 33 public: 34 ScreenSinkTrans() = default; 35 ~ScreenSinkTrans() override = default; 36 37 int32_t SetUp(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId) override; 38 int32_t Release() override; 39 int32_t Start() override; 40 int32_t Stop() override; 41 int32_t RegisterStateCallback(const std::shared_ptr<IScreenSinkTransCallback> &callback) override; 42 int32_t SetImageSurface(const sptr<Surface> &surface) override; 43 void SetScreenVersion(const std::string &version) override; 44 45 void OnSessionOpened() override; 46 void OnSessionClosed() override; 47 void OnDataReceived(const std::shared_ptr<DataBuffer> &data) override; 48 void OnProcessorStateNotify(int32_t state) override; 49 50 private: 51 int32_t CheckVideoParam(const VideoParam ¶m); 52 int32_t CheckTransParam(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId); 53 int32_t InitScreenTrans(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId); 54 int32_t RegisterChannelListener(); 55 int32_t RegisterProcessorListener(const VideoParam &localParam, const VideoParam &remoteParam, 56 const std::string &peerDevId); 57 58 private: 59 static const constexpr char *DSCREEN_LOG_TAG = "ScreenSinkTrans"; 60 61 std::string version_ = "1.0"; 62 sptr<Surface> decoderSurface_; 63 std::shared_ptr<IImageSinkProcessor> imageProcessor_; 64 std::shared_ptr<IScreenChannel> screenChannel_; 65 std::weak_ptr<IScreenSinkTransCallback> transCallback_; 66 }; 67 } // namespace DistributedHardware 68 } // namespace OHOS 69 #endif