-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathZegoCustomVideoRenderManager.cpp
88 lines (79 loc) · 3.96 KB
/
ZegoCustomVideoRenderManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "include/zego_express_engine/ZegoCustomVideoRenderManager.h"
#include <ZegoExpressSDK.h>
static std::shared_ptr<ZegoCustomVideoRenderManager> instance_ = nullptr;
static std::once_flag singletonFlag;
class ZegoCustomVideoRenderHandler : public ZEGO::EXPRESS::IZegoCustomVideoRenderHandler {
public:
void setCustomVideoRenderHandler(std::shared_ptr<IZegoFlutterCustomVideoRenderHandler> handler) {
handler_ = handler;
}
private:
std::shared_ptr<IZegoFlutterCustomVideoRenderHandler> handler_ = nullptr;
void onCapturedVideoFrameRawData(unsigned char ** data,
unsigned int * dataLength,
ZEGO::EXPRESS::ZegoVideoFrameParam param,
ZEGO::EXPRESS::ZegoVideoFlipMode flipMode,
ZEGO::EXPRESS::ZegoPublishChannel channel) override {
if (handler_) {
ZGFlutterVideoFrameParam frameParam;
frameParam.width = param.width;
frameParam.height = param.height;
frameParam.rotation = param.rotation;
frameParam.format = (ZGFlutterVideoFrameFormat)param.format;
for (size_t i = 0; i < 4; i++)
{
frameParam.strides[i] = param.strides[i];
}
handler_->onCapturedVideoFrameRawData(data, dataLength, frameParam, (ZGFlutterVideoFlipMode)flipMode, (ZGFlutterPublishChannel)channel);
}
}
void onRemoteVideoFrameRawData(unsigned char ** data, unsigned int * dataLength,
ZEGO::EXPRESS::ZegoVideoFrameParam param,
const std::string & streamID) override {
if (handler_) {
ZGFlutterVideoFrameParam frameParam;
frameParam.width = param.width;
frameParam.height = param.height;
frameParam.rotation = param.rotation;
frameParam.format = (ZGFlutterVideoFrameFormat)param.format;
for (size_t i = 0; i < 4; i++)
{
frameParam.strides[i] = param.strides[i];
}
handler_->onRemoteVideoFrameRawData(data, dataLength, frameParam, streamID);
}
}
void onRemoteVideoFrameEncodedData(const unsigned char * data,
unsigned int dataLength,
ZEGO::EXPRESS::ZegoVideoEncodedFrameParam param,
unsigned long long referenceTimeMillisecond,
const std::string & streamID)override {
if (handler_) {
ZGFlutterVideoEncodedFrameParam frameParam;
frameParam.width = param.width;
frameParam.height = param.height;
frameParam.rotation = param.rotation;
frameParam.format = (ZGFlutterVideoEncodedFrameFormat)param.format;
frameParam.isKeyFrame = param.isKeyFrame;
frameParam.SEIData = param.SEIData;
frameParam.SEIDataLength = param.SEIDataLength;
handler_->onRemoteVideoFrameEncodedData(data, dataLength, frameParam, referenceTimeMillisecond, streamID);
}
}
};
std::shared_ptr<ZegoCustomVideoRenderManager> ZegoCustomVideoRenderManager::getInstance() {
std::call_once(singletonFlag, [&] {
instance_ = std::make_shared<ZegoCustomVideoRenderManager>();
});
return instance_;
}
std::shared_ptr<ZEGO::EXPRESS::IZegoCustomVideoRenderHandler> ZegoCustomVideoRenderManager::getHandler() {
return zegoHandler_;
}
void ZegoCustomVideoRenderManager::setCustomVideoRenderHandler(std::shared_ptr<IZegoFlutterCustomVideoRenderHandler> handler) {
handler_ = handler;
if (handler_ && !zegoHandler_) {
zegoHandler_ = std::make_shared<ZegoCustomVideoRenderHandler>();
}
dynamic_cast<ZegoCustomVideoRenderHandler*>(zegoHandler_.get())->setCustomVideoRenderHandler(handler_);
}