From b91b7b2b97e712e797aded38ab5e27c759d2ff42 Mon Sep 17 00:00:00 2001 From: Allen Lin Date: Sat, 19 Jan 2019 17:24:52 +0800 Subject: [PATCH] feat: add customFilterGroup --- LFLiveKit/LFLiveSession.h | 3 ++- LFLiveKit/LFLiveSession.m | 9 +++++++++ LFLiveKit/capture/LFVideoCapture.h | 4 ++++ LFLiveKit/capture/LFVideoCapture.m | 22 ++++++++++++++++++---- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/LFLiveKit/LFLiveSession.h b/LFLiveKit/LFLiveSession.h index 95985e42..fdb4cc9b 100755 --- a/LFLiveKit/LFLiveSession.h +++ b/LFLiveKit/LFLiveSession.h @@ -16,7 +16,7 @@ #import "LFLiveVideoConfiguration.h" #import "LFLiveDebug.h" - +@class GPUImageFilterGroup; typedef NS_ENUM(NSInteger,LFLiveCaptureType) { LFLiveCaptureAudio, //< capture only audio @@ -127,6 +127,7 @@ typedef NS_ENUM(NSInteger,LFLiveCaptureTypeMask) { /* The saveLocalVideoPath is save the local video path */ @property (nonatomic, strong, nullable) NSURL *saveLocalVideoPath; +@property (nonatomic, nullable) GPUImageFilterGroup *customFilterGroup; #pragma mark - Initializer ///============================================================================= /// @name Initializer diff --git a/LFLiveKit/LFLiveSession.m b/LFLiveKit/LFLiveSession.m index 41a7034e..1d65ae95 100755 --- a/LFLiveKit/LFLiveSession.m +++ b/LFLiveKit/LFLiveSession.m @@ -268,6 +268,15 @@ - (void)setSaveLocalVideoPath:(NSURL*)saveLocalVideoPath{ [self.videoCaptureSource setSaveLocalVideoPath:saveLocalVideoPath]; } +- (GPUImageFilterGroup * _Nullable)customFilterGroup { + return self.videoCaptureSource.customFilterGroup; +} + +- (void)setCustomFilterGroup:(GPUImageFilterGroup * _Nullable)customFilterGroup { + [self.videoCaptureSource setCustomFilterGroup:customFilterGroup]; +} + + - (BOOL)beautyFace { return self.videoCaptureSource.beautyFace; } diff --git a/LFLiveKit/capture/LFVideoCapture.h b/LFLiveKit/capture/LFVideoCapture.h index 4e719c0e..a07ded71 100755 --- a/LFLiveKit/capture/LFVideoCapture.h +++ b/LFLiveKit/capture/LFVideoCapture.h @@ -10,7 +10,9 @@ #import #import "LFLiveVideoConfiguration.h" + @class LFVideoCapture; +@class GPUImageFilterGroup; /** LFVideoCapture callback videoData */ @protocol LFVideoCaptureDelegate - (void)captureOutput:(nullable LFVideoCapture *)capture pixelBuffer:(nullable CVPixelBufferRef)pixelBuffer; @@ -68,6 +70,8 @@ /* The saveLocalVideoPath is save the local video path */ @property (nonatomic, strong, nullable) NSURL *saveLocalVideoPath; +@property (nonatomic, nullable) GPUImageFilterGroup *customFilterGroup; + #pragma mark - Initializer ///============================================================================= /// @name Initializer diff --git a/LFLiveKit/capture/LFVideoCapture.m b/LFLiveKit/capture/LFVideoCapture.m index 7e42a3f5..c60eff71 100755 --- a/LFLiveKit/capture/LFVideoCapture.m +++ b/LFLiveKit/capture/LFVideoCapture.m @@ -267,6 +267,12 @@ - (GPUImageMovieWriter*)movieWriter{ return _movieWriter; } +- (void)setCustomFilterGroup:(GPUImageFilterGroup * _Nullable)customFilterGroup { + [_customFilterGroup removeAllTargets]; + _customFilterGroup = customFilterGroup; + [self reloadFilter]; +} + #pragma mark -- Custom Method - (void)processVideo:(GPUImageOutput *)output { __weak typeof(self) _self = self; @@ -287,6 +293,7 @@ - (void)reloadFilter{ [self.output removeAllTargets]; [self.cropfilter removeAllTargets]; + [self.customFilterGroup removeAllTargets]; if (self.beautyFace) { self.output = [[LFGPUImageEmptyFilter alloc] init]; self.filter = [[LFGPUImageBeautyFilter alloc] init]; @@ -309,21 +316,28 @@ - (void)reloadFilter{ }else{ [self.videoCamera addTarget:self.filter]; } - + + GPUImageOutput * lastFilter = self.filter; + if (self.customFilterGroup) { + [self.filter addTarget:self.customFilterGroup]; + lastFilter = self.customFilterGroup; + } + //< 添加水印 if(self.warterMarkView){ - [self.filter addTarget:self.blendFilter]; + [lastFilter addTarget:self.blendFilter]; [self.uiElementInput addTarget:self.blendFilter]; [self.blendFilter addTarget:self.gpuImageView]; if(self.saveLocalVideo) [self.blendFilter addTarget:self.movieWriter]; - [self.filter addTarget:self.output]; + [lastFilter addTarget:self.output]; [self.uiElementInput update]; }else{ - [self.filter addTarget:self.output]; + [lastFilter addTarget:self.output]; [self.output addTarget:self.gpuImageView]; if(self.saveLocalVideo) [self.output addTarget:self.movieWriter]; } + [self.customFilterGroup forceProcessingAtSize:self.configuration.videoSize]; [self.filter forceProcessingAtSize:self.configuration.videoSize]; [self.output forceProcessingAtSize:self.configuration.videoSize]; [self.blendFilter forceProcessingAtSize:self.configuration.videoSize];