FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
API-Examples/macOS/SimpleFilter/ExtensionVideoFilter.cpp at main · jinweizhao/API-Examples · GitHub
jinweizhao
/
API-Examples
Public
forked from
AgoraIO/API-Examples
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
API-Examples
/
macOS
/
SimpleFilter
/
ExtensionVideoFilter.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
126 lines (111 loc) · 5.12 KB
Breadcrumbs
API-Examples
/
macOS
/
SimpleFilter
/
ExtensionVideoFilter.cpp
Copy path
File metadata and controls
126 lines (111 loc) · 5.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
//
Created by 张涛 on 2020/4/26.
//
#
include
"
ExtensionVideoFilter.hpp
"
#
include
<
sstream
>
namespace
agora
{
namespace
extension
{
ExtensionVideoFilter::ExtensionVideoFilter
(agora_refptr<YUVImageProcessor> processor):threadPool_(
1
) {
YUVProcessor = processor;
}
ExtensionVideoFilter::~ExtensionVideoFilter
() {
YUVProcessor->
releaseOpenGL
();
}
//
Set the process mode between the SDK and the video plug-in
//
If set ProcessMode to Sync mode, Agora SDK and video extension will pass data through adaptVideoFrame
//
If set ProcessMode to Async mode, Agora SDK and video extension will pass data through pendVideoFrame and deliverVideoFrame
//
If set independent_thread to false, all callbacks sent by Agora SDK are performed on the internal video processing thread
//
If set independent_thread to true, all callbacks sent by Agora SDK are performed on a separate thread
void
ExtensionVideoFilter::getProcessMode
(ProcessMode& mode,
bool
& independent_thread) {
mode = ProcessMode::
kSync
;
independent_thread =
false
;
mode_ = mode;
}
//
Set the type and format of the video data to be processed
void
ExtensionVideoFilter::getVideoFormatWanted
(rtc::VideoFrameData::Type& type,
rtc::RawPixelBuffer::Format& format) {
type = rtc::VideoFrameData::Type::
kRawPixels
;
format = rtc::RawPixelBuffer::Format::
kI420
;
}
int
ExtensionVideoFilter::start
(agora::agora_refptr<Control> control) {
printf
(
"
ExtensionVideoFilter::start
\n
"
);
if
(!YUVProcessor) {
return
-
1
;
}
if
(control) {
control_ = control;
YUVProcessor->
setExtensionControl
(control);
}
if
(mode_ == ProcessMode::
kAsync
){
invoker_id = threadPool_.
RegisterInvoker
(
"
thread_videofilter
"
);
auto
res = threadPool_.
PostTaskWithRes
(invoker_id, [yuvProcessor=YUVProcessor] {
return
yuvProcessor->
initOpenGL
();
});
isInitOpenGL = res.
get
();
}
else
{
isInitOpenGL = YUVProcessor->
initOpenGL
();
}
return
0
;
}
int
ExtensionVideoFilter::stop
() {
printf
(
"
ExtensionVideoFilter::stop
\n
"
);
if
(YUVProcessor) {
YUVProcessor->
releaseOpenGL
();
isInitOpenGL =
false
;
}
return
0
;
}
rtc::IExtensionVideoFilter::ProcessResult
ExtensionVideoFilter::pendVideoFrame
(agora::agora_refptr<rtc::IVideoFrame> frame) {
if
(!frame || !isInitOpenGL) {
return
kBypass
;
}
bool
isAsyncMode = (mode_ == ProcessMode::
kAsync
);
if
(isAsyncMode && YUVProcessor && control_ && invoker_id >=
0
) {
threadPool_.
PostTask
(invoker_id, [videoFrame=frame, processor=YUVProcessor, control=control_] {
rtc::VideoFrameData srcData;
videoFrame->
getVideoFrameData
(srcData);
processor->
processFrame
(srcData);
//
In asynchronous mode (mode is set to Async),
//
the plug-in needs to call this method to return the processed video frame to the SDK.
control->
deliverVideoFrame
(videoFrame);
});
return
kSuccess
;
}
return
kBypass
;
}
rtc::IExtensionVideoFilter::ProcessResult
ExtensionVideoFilter::adaptVideoFrame
(agora::agora_refptr<rtc::IVideoFrame> src,
agora::agora_refptr<rtc::IVideoFrame>& dst) {
if
(!isInitOpenGL) {
return
kBypass
;
}
bool
isSyncMode = (mode_ == ProcessMode::
kSync
);
if
(isSyncMode && YUVProcessor) {
rtc::VideoFrameData srcData;
src->
getVideoFrameData
(srcData);
YUVProcessor->
processFrame
(srcData);
dst = src;
return
kSuccess
;
}
return
kBypass
;
}
//
When the app developer calls RtcEngine.setExtensionProperty,
//
Agora SDK will call this method to set video plug-in properties
int
ExtensionVideoFilter::setProperty
(
const
char
*key,
const
void
*buf,
size_t
buf_size) {
printf
(
"
setProperty %s %s
\n
"
, key, buf);
std::string
stringParameter
((
char
*)buf);
YUVProcessor->
setParameters
(stringParameter);
return
0
;
}
//
When the app developer calls getExtensionProperty,
//
Agora SDK will call this method to get the properties of the video plug-in
int
ExtensionVideoFilter::getProperty
(
const
char
*key,
void
*buf,
size_t
buf_size) {
return
-
1
;
}
void
ExtensionVideoFilter::setEnabled
(
bool
enable) {
}
bool
ExtensionVideoFilter::isEnabled
() {
return
true
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL