Skip to content

Commit 5871bd1

Browse files
author
zhaoyongqiang
committed
适配4.0.0-rc.1
1 parent 25bd629 commit 5871bd1

6 files changed

Lines changed: 536 additions & 546 deletions

File tree

iOS/APIExample/Examples/Advanced/VideoProcess/VideoProcess.swift

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -188,45 +188,40 @@ class VideoProcessMain : BaseViewController
188188
}
189189

190190
@IBAction func onChangeLowLightEnhance(_ sender: UISwitch) {
191-
let options : [String : Any] = ["enable" : sender.isOn ? 1 : 0,
192-
"level" : 1,
193-
"mode" : 0]
194-
changeVideoEnhancement(value: options, key: "lowlight_enhance_option")
191+
let options = AgoraLowlightEnhanceOptions()
192+
options.level = .fast
193+
options.mode = .auto
194+
agoraKit.setLowlightEnhanceOptions(sender.isOn, options: options)
195195
}
196196

197197
@IBAction func onChangeVideoDenoise(_ sender: UISwitch) {
198-
let options : [String : Any] = ["enable" : sender.isOn ? 1 : 0,
199-
"level" : 0,
200-
"mode" : 0]
201-
changeVideoEnhancement(value: options, key: "video_denoiser_option")
198+
let options = AgoraVideoDenoiserOptions()
199+
options.level = .highQuality
200+
options.mode = .manual
201+
agoraKit.setVideoDenoiserOptions(sender.isOn, options: options)
202202
}
203203

204204
@IBAction func onChangeColorEnhance(_ sender: UISwitch) {
205-
let options : [String : Any] = ["enable" : colorEnhanceSwitch.isOn ? 1 : 0,
206-
"strength" : strength,
207-
"skinProtect" : skinProtect]
208-
changeVideoEnhancement(value: options, key: "color_enhance_option")
205+
let options = AgoraColorEnhanceOptions()
206+
options.strengthLevel = Float(strength)
207+
options.skinProtectLevel = Float(skinProtect)
208+
agoraKit.setColorEnhanceOptions(sender.isOn, options: options)
209209
}
210210

211211
@IBAction func onStrengthSlider(_ sender:UISlider){
212212
strength = Double(sender.value)
213-
let options : [String : Any] = ["enable" : colorEnhanceSwitch.isOn ? 1 : 0,
214-
"strength" : strength,
215-
"skinProtect" : skinProtect]
216-
changeVideoEnhancement(value: options, key: "color_enhance_option")
213+
let options = AgoraColorEnhanceOptions()
214+
options.strengthLevel = Float(strength)
215+
options.skinProtectLevel = Float(skinProtect)
216+
agoraKit.setColorEnhanceOptions(colorEnhanceSwitch.isOn, options: options)
217217
}
218218

219219
@IBAction func onSkinProtectSlider(_ sender:UISlider){
220220
skinProtect = Double(sender.value)
221-
let options : [String : Any] = ["enable" : colorEnhanceSwitch.isOn ? 1 : 0,
222-
"strength" : strength,
223-
"skinProtect" : skinProtect]
224-
changeVideoEnhancement(value: options, key: "color_enhance_option")
225-
}
226-
227-
func changeVideoEnhancement(value: [String : Any], key: String) {
228-
guard let data = try? JSONSerialization.data(withJSONObject: value, options: .prettyPrinted) else { return }
229-
agoraKit.setExtensionPropertyWithVendor("agora", extension: "beauty", key: key, value: String(data:data,encoding:.utf8)!)
221+
let options = AgoraColorEnhanceOptions()
222+
options.strengthLevel = Float(strength)
223+
options.skinProtectLevel = Float(skinProtect)
224+
agoraKit.setColorEnhanceOptions(colorEnhanceSwitch.isOn, options: options)
230225
}
231226

232227
@IBAction func onChangeVirtualBgSwtich(_ sender: UISwitch) {

macOS/APIExample/Commons/Utils/MediaUtils.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ + (NSImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:
2525
unsigned char * NV12buf = (unsigned char *)malloc(size);
2626
[self yuv420p_to_nv12:buf nv12:NV12buf width:width height:height];
2727

28+
free(buf);
29+
2830
int w = width;
2931
int h = height;
3032
NSDictionary *pixelAttributes = @{(NSString*)kCVPixelBufferIOSurfacePropertiesKey:@{}};
@@ -37,6 +39,7 @@ + (NSImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:
3739
&pixelBuffer);
3840
if (result != kCVReturnSuccess) {
3941
NSLog(@"Unable to create cvpixelbuffer %d", result);
42+
free(NV12buf);
4043
return nil;
4144
}
4245

@@ -62,10 +65,11 @@ + (NSImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:
6265
NSImage *finalImage = [[NSImage alloc] initWithCGImage:videoImage size:NSMakeSize(width, height)];
6366
CVPixelBufferRelease(pixelBuffer);
6467
CGImageRelease(videoImage);
68+
69+
free(NV12buf);
6570
return finalImage;
6671
}
6772

68-
6973
+ (void)yuv420p_to_nv12:(unsigned char*)yuv420p nv12:(unsigned char*)nv12 width:(int)width height:(int)height {
7074
int i, j;
7175
int y_size = width * height;

0 commit comments

Comments
 (0)