1 /*
2  * Copyright (c) 2022-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_SCREEN_REGION_V2_0_H
17 #define OHOS_DSCREEN_SCREEN_REGION_V2_0_H
18 
19 #include <cstdio>
20 #include <fstream>
21 #include <mutex>
22 #include <string>
23 
24 #include "surface.h"
25 
26 #include "2.0/include/av_receiver_engine_adapter.h"
27 #include "distributed_hardware_fwk_kit.h"
28 #include "dscreen_maprelation.h"
29 #include "screen_client_common.h"
30 #include "video_param.h"
31 
32 namespace OHOS {
33 namespace DistributedHardware {
34 namespace V2_0 {
35 class ScreenRegion :  public AVReceiverAdapterCallback, public std::enable_shared_from_this<ScreenRegion> {
36 public:
37     ScreenRegion(const std::string &remoteDevId);
38     ~ScreenRegion();
39 
40     // interfaces from AVReceiverAdapterCallback
41     void OnEngineEvent(DScreenEventType event, const std::string &content) override;
42     void OnEngineMessage(const std::shared_ptr<AVTransMessage> &message) override;
43     void OnEngineDataDone(const std::shared_ptr<AVTransBuffer> &buffer) override;
44     void GetWSBuffer(sptr<OHOS::SurfaceBuffer> &wsBuffer, const std::shared_ptr<AVTransBuffer> &buffer);
45 
46     int32_t Release();
47     int32_t InitReceiverEngine(IAVEngineProvider *providerPtr);
48     int32_t GetWindowId();
49     uint64_t GetScreenId();
50     std::string GetRemoteDevId();
51     std::shared_ptr<VideoParam> GetVideoParam();
52     std::shared_ptr<WindowProperty> GetWindowProperty();
53 
54 private:
55     int32_t StartReceiverEngine(const std::string &content);
56     int32_t StopReceiverEngine();
57     int32_t SetUp(const std::string &content);
58     int32_t ConfigWindow();
59     int32_t SetReceiverAdapterParameters();
60     int32_t SetAlignedHeight();
61     bool CheckContentJson(json &contentJson);
62     void PublishMessage(const DHTopic topic, const uint64_t &screenId, const std::string &remoteDevId,
63         const int32_t &windowId, std::shared_ptr<WindowProperty> windowProperty);
64 
65 private:
66     uint64_t screenId_;
67     uint64_t displayId_;
68     std::string remoteDevId_;
69     int32_t windowId_ = INVALID_WINDOW_ID;
70     uint32_t alignedHeight_ = 0;
71     bool isRunning = false;
72     std::atomic<uint32_t> frameNumber_;
73 
74     sptr<OHOS::Surface> windowSurface_ = nullptr;
75     std::shared_ptr<VideoParam> videoParam_ = nullptr;
76     std::shared_ptr<WindowProperty> windowProperty_ = nullptr;
77     std::shared_ptr<DScreenMapRelation> mapRelation_ = nullptr;
78     std::shared_ptr<AVTransReceiverAdapter> receiverAdapter_ = nullptr;
79 };
80 } // namespace V2_0
81 } // namespace DistributedHardware
82 } // namespace OHOS
83 #endif