1 /*
2  * Copyright (c) 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_AV_TRANSPORT_RECEIVER_ADAPTER_H
17 #define OHOS_AV_TRANSPORT_RECEIVER_ADAPTER_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 #include <memory>
22 #include <queue>
23 #include <string>
24 #include <thread>
25 
26 #include "dscreen_constants.h"
27 #include "i_av_engine_provider.h"
28 #include "video_param.h"
29 
30 namespace OHOS {
31 namespace DistributedHardware {
32 class AVReceiverAdapterCallback {
33 public:
AVReceiverAdapterCallback()34     AVReceiverAdapterCallback() {};
35     virtual ~AVReceiverAdapterCallback() = default;
36     virtual void OnEngineEvent(DScreenEventType event, const std::string &content) = 0;
37     virtual void OnEngineMessage(const std::shared_ptr<AVTransMessage> &message) = 0;
38     virtual void OnEngineDataDone(const std::shared_ptr<AVTransBuffer> &buffer) = 0;
39 };
40 
41 class AVTransReceiverAdapter : public IAVReceiverEngineCallback,
42                                public std::enable_shared_from_this<AVTransReceiverAdapter> {
43 public:
AVTransReceiverAdapter()44     AVTransReceiverAdapter() {};
~AVTransReceiverAdapter()45     ~AVTransReceiverAdapter() override {};
46 
47     int32_t Initialize(IAVEngineProvider *providerPtr, const std::string& peerDevId);
48     int32_t Release();
49     int32_t Start();
50     int32_t Stop();
51     int32_t SetParameter(const AVTransTag &tag, const std::string &param);
52     int32_t SendMessageToRemote(const std::shared_ptr<AVTransMessage> &message);
53     int32_t RegisterAdapterCallback(const std::shared_ptr<AVReceiverAdapterCallback> &callback);
54 
55     // interfaces from IAVReceiverEngineCallback
56     int32_t OnReceiverEvent(const AVTransEvent& event) override;
57     int32_t OnMessageReceived(const std::shared_ptr<AVTransMessage> &message) override;
58     int32_t OnDataAvailable(const std::shared_ptr<AVTransBuffer> &buffer) override;
59 
60 private:
61     std::atomic<bool> initialized_ {false};
62     std::shared_ptr<IAVReceiverEngine> receiverEngine_;
63     std::shared_ptr<AVReceiverAdapterCallback> adapterCallback_;
64 };
65 } // namespace DistributedHardware
66 } // namespace OHOS
67 #endif