Skip to content

Commit 82ffe9a

Browse files
committed
add raw data more api support
1 parent 8ace747 commit 82ffe9a

9 files changed

Lines changed: 49 additions & 3 deletions

File tree

iOS/APIExample.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@
171171
isa = PBXGroup;
172172
children = (
173173
036C42BA24D5853200A59000 /* AgoraMediaRawData.h */,
174-
036C42BB24D5853200A59000 /* AgoraMediaDataPlugin.mm */,
175174
036C42BC24D5853200A59000 /* AgoraMediaRawData.m */,
176175
036C42BD24D5853200A59000 /* AgoraMediaDataPlugin.h */,
176+
036C42BB24D5853200A59000 /* AgoraMediaDataPlugin.mm */,
177177
);
178178
path = RawDataApi;
179179
sourceTree = "<group>";

iOS/APIExample/Common/RawDataApi/AgoraMediaDataPlugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef UIImage AGImage;
1919
typedef NS_OPTIONS(NSInteger, ObserverVideoType) {
2020
ObserverVideoTypeCaptureVideo = 1 << 0,
2121
ObserverVideoTypeRenderVideo = 1 << 1,
22+
ObserverVideoTypePreEncodingVideo = 1 << 2
2223
};
2324

2425
typedef NS_OPTIONS(NSInteger, ObserverAudioType) {
@@ -41,6 +42,7 @@ typedef NS_OPTIONS(NSInteger, ObserverPacketType) {
4142
@optional
4243
- (AgoraVideoRawData * _Nonnull)mediaDataPlugin:(AgoraMediaDataPlugin * _Nonnull)mediaDataPlugin didCapturedVideoRawData:(AgoraVideoRawData * _Nonnull)videoRawData;
4344
- (AgoraVideoRawData * _Nonnull)mediaDataPlugin:(AgoraMediaDataPlugin * _Nonnull)mediaDataPlugin willRenderVideoRawData:(AgoraVideoRawData * _Nonnull)videoRawData ofUid:(uint)uid;
45+
- (AgoraVideoRawData * _Nonnull)mediaDataPlugin:(AgoraMediaDataPlugin * _Nonnull)mediaDataPlugin willPreEncodeVideoRawData:(AgoraVideoRawData * _Nonnull)videoRawData;
4446
@end
4547

4648
@protocol AgoraAudioDataPluginDelegate <NSObject>

iOS/APIExample/Common/RawDataApi/AgoraMediaDataPlugin.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ virtual bool onRenderVideoFrame(unsigned int uid, VideoFrame& videoFrame) overri
104104
return true;
105105
}
106106

107+
virtual bool onPreEncodeVideoFrame(VideoFrame& videoFrame) override
108+
{
109+
if (!mediaDataPlugin && ((mediaDataPlugin.observerVideoType >> 2) == 0)) return true;
110+
@autoreleasepool {
111+
AgoraVideoRawData *newData = nil;
112+
if ([mediaDataPlugin.videoDelegate respondsToSelector:@selector(mediaDataPlugin:willPreEncodeVideoRawData:)]) {
113+
AgoraVideoRawData *data = getVideoRawDataWithVideoFrame(videoFrame);
114+
newData = [mediaDataPlugin.videoDelegate mediaDataPlugin:mediaDataPlugin willPreEncodeVideoRawData:data];
115+
modifiedVideoFrameWithNewVideoRawData(videoFrame, newData);
116+
}
117+
}
118+
return true;
119+
}
120+
107121
virtual VIDEO_FRAME_TYPE getVideoFormatPreference() override
108122
{
109123
return VIDEO_FRAME_TYPE(mediaDataPlugin.videoFormatter.type);

iOS/APIExample/Examples/Advanced/RawMediaData.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ extension RawMediaData : AgoraVideoDataPluginDelegate
202202
return videoRawData
203203
}
204204

205+
/// Occurs each time the SDK receives a video frame before sending to encoder
206+
/// After you successfully register the video frame observer, the SDK triggers this callback each time a video frame is going to be sent to encoder. In this callback, you can get the video data before it is sent to enoder. You can then pre-process the data according to your scenarios.
207+
/// After pre-processing, you can send the processed video data back to the SDK by setting the videoFrame parameter in this callback.
208+
func mediaDataPlugin(_ mediaDataPlugin: AgoraMediaDataPlugin, willPreEncode videoRawData: AgoraVideoRawData) -> AgoraVideoRawData {
209+
return videoRawData
210+
}
211+
205212
/// Occurs each time the SDK receives a video frame sent by the remote user.
206213
///After you successfully register the video frame observer and isMultipleChannelFrameWanted return false, the SDK triggers this callback each time a video frame is received. In this callback, you can get the video data sent by the remote user. You can then post-process the data according to your scenarios.
207214
///After post-processing, you can send the processed data back to the SDK by setting the videoFrame parameter in this callback.

iOS/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ target 'APIExample' do
77
use_frameworks!
88

99
pod 'AGEVideoLayout', '~> 1.0.2'
10-
pod 'AgoraRtcEngine_iOS', '~> 3.1.0'
10+
pod 'AgoraRtcEngine_iOS', '~> 3.1.1'
1111
pod 'NewPopMenu', '~> 2.0'
1212
end
1313

macOS/APIExample.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@
130130
children = (
131131
03267E1E2500C265004A91A6 /* AgoraMediaRawData.h */,
132132
03267E202500C265004A91A6 /* AgoraMediaRawData.m */,
133-
03267E1F2500C265004A91A6 /* AgoraMediaDataPlugin.mm */,
134133
03267E212500C265004A91A6 /* AgoraMediaDataPlugin.h */,
134+
03267E1F2500C265004A91A6 /* AgoraMediaDataPlugin.mm */,
135135
);
136136
path = RawDataApi;
137137
sourceTree = "<group>";

macOS/APIExample/Commons/RawDataApi/AgoraMediaDataPlugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ typedef NS_OPTIONS(NSInteger, ObserverPacketType) {
4141
@optional
4242
- (AgoraVideoRawData * _Nonnull)mediaDataPlugin:(AgoraMediaDataPlugin * _Nonnull)mediaDataPlugin didCapturedVideoRawData:(AgoraVideoRawData * _Nonnull)videoRawData;
4343
- (AgoraVideoRawData * _Nonnull)mediaDataPlugin:(AgoraMediaDataPlugin * _Nonnull)mediaDataPlugin willRenderVideoRawData:(AgoraVideoRawData * _Nonnull)videoRawData ofUid:(uint)uid;
44+
- (AgoraVideoRawData * _Nonnull)mediaDataPlugin:(AgoraMediaDataPlugin * _Nonnull)mediaDataPlugin willPreEncodeVideoRawData:(AgoraVideoRawData * _Nonnull)videoRawData;
45+
4446
@end
4547

4648
@protocol AgoraAudioDataPluginDelegate <NSObject>

macOS/APIExample/Commons/RawDataApi/AgoraMediaDataPlugin.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ virtual bool onCaptureVideoFrame(VideoFrame& videoFrame) override
8383
return true;
8484
}
8585

86+
virtual bool onPreEncodeVideoFrame(VideoFrame& videoFrame) override
87+
{
88+
if (!mediaDataPlugin && ((mediaDataPlugin.observerVideoType >> 2) == 0)) return true;
89+
@autoreleasepool {
90+
AgoraVideoRawData *newData = nil;
91+
if ([mediaDataPlugin.videoDelegate respondsToSelector:@selector(mediaDataPlugin:willPreEncodeVideoRawData:)]) {
92+
AgoraVideoRawData *data = getVideoRawDataWithVideoFrame(videoFrame);
93+
newData = [mediaDataPlugin.videoDelegate mediaDataPlugin:mediaDataPlugin willPreEncodeVideoRawData:data];
94+
modifiedVideoFrameWithNewVideoRawData(videoFrame, newData);
95+
}
96+
}
97+
return true;
98+
}
99+
86100
virtual bool onRenderVideoFrame(unsigned int uid, VideoFrame& videoFrame) override
87101
{
88102
if (!mediaDataPlugin && ((mediaDataPlugin.observerVideoType >> 1) == 0)) return true;

macOS/APIExample/Examples/Advanced/RawMediaData.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ extension RawMediaData : AgoraVideoDataPluginDelegate
280280
return videoRawData
281281
}
282282

283+
/// Occurs each time the SDK receives a video frame before sending to encoder
284+
/// After you successfully register the video frame observer, the SDK triggers this callback each time a video frame is going to be sent to encoder. In this callback, you can get the video data before it is sent to enoder. You can then pre-process the data according to your scenarios.
285+
/// After pre-processing, you can send the processed video data back to the SDK by setting the videoFrame parameter in this callback.
286+
func mediaDataPlugin(_ mediaDataPlugin: AgoraMediaDataPlugin, willPreEncode videoRawData: AgoraVideoRawData) -> AgoraVideoRawData {
287+
return videoRawData
288+
}
289+
283290
/// Occurs each time the SDK receives a video frame sent by the remote user.
284291
///After you successfully register the video frame observer and isMultipleChannelFrameWanted return false, the SDK triggers this callback each time a video frame is received. In this callback, you can get the video data sent by the remote user. You can then post-process the data according to your scenarios.
285292
///After post-processing, you can send the processed data back to the SDK by setting the videoFrame parameter in this callback.

0 commit comments

Comments
 (0)