From e61b0d65a05ae5e9a24e2990c2df45debeeb322a Mon Sep 17 00:00:00 2001 From: vukvasic Date: Fri, 24 Mar 2017 10:17:44 +0100 Subject: [PATCH] Effects change possibility --- LFLiveKit/LFLiveSession.h | 2 +- LFLiveKit/LFLiveSession.m | 4 ++ LFLiveKit/capture/LFVideoCapture.h | 2 +- LFLiveKit/capture/LFVideoCapture.m | 70 ++++++++++++++++++++++++++++-- 4 files changed, 73 insertions(+), 5 deletions(-) diff --git a/LFLiveKit/LFLiveSession.h b/LFLiveKit/LFLiveSession.h index 95985e42..c4d8b6b7 100755 --- a/LFLiveKit/LFLiveSession.h +++ b/LFLiveKit/LFLiveSession.h @@ -17,7 +17,6 @@ #import "LFLiveDebug.h" - typedef NS_ENUM(NSInteger,LFLiveCaptureType) { LFLiveCaptureAudio, //< capture only audio LFLiveCaptureVideo, //< capture onlt video @@ -157,6 +156,7 @@ typedef NS_ENUM(NSInteger,LFLiveCaptureTypeMask) { /** support outer input pcm audio(set LFLiveCaptureTypeMask) .*/ - (void)pushAudio:(nullable NSData*)audioData; +-(void)loadCustomFilter:(int)input; @end diff --git a/LFLiveKit/LFLiveSession.m b/LFLiveKit/LFLiveSession.m index 41a7034e..793507e8 100755 --- a/LFLiveKit/LFLiveSession.m +++ b/LFLiveKit/LFLiveSession.m @@ -384,6 +384,10 @@ - (LFVideoCapture *)videoCaptureSource { return _videoEncoder; } +-(void)loadCustomFilter:(int)input { + + [_videoCaptureSource loadCustomFilter: input]; +} - (id)socket { if (!_socket) { _socket = [[LFStreamRTMPSocket alloc] initWithStream:self.streamInfo reconnectInterval:self.reconnectInterval reconnectCount:self.reconnectCount]; diff --git a/LFLiveKit/capture/LFVideoCapture.h b/LFLiveKit/capture/LFVideoCapture.h index 4e719c0e..bfb264c2 100755 --- a/LFLiveKit/capture/LFVideoCapture.h +++ b/LFLiveKit/capture/LFVideoCapture.h @@ -80,5 +80,5 @@ capture unstable. */ - (nullable instancetype)initWithVideoConfiguration:(nullable LFLiveVideoConfiguration *)configuration NS_DESIGNATED_INITIALIZER; - +-(void)loadCustomFilter:(int)input; @end diff --git a/LFLiveKit/capture/LFVideoCapture.m b/LFLiveKit/capture/LFVideoCapture.m index 7e42a3f5..7514ffd0 100755 --- a/LFLiveKit/capture/LFVideoCapture.m +++ b/LFLiveKit/capture/LFVideoCapture.m @@ -51,7 +51,7 @@ - (instancetype)initWithVideoConfiguration:(LFLiveVideoConfiguration *)configura [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground:) name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarChanged:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; - self.beautyFace = YES; + self.beautyFace = NO; self.beautyLevel = 0.5; self.brightLevel = 0.5; self.zoomScale = 1.0; @@ -279,6 +279,56 @@ - (void)processVideo:(GPUImageOutput *)output { } } + +-(GPUImage3x3ConvolutionFilter*) loadConvulationEffect{ + GPUImage3x3ConvolutionFilter *filter = [[GPUImage3x3ConvolutionFilter alloc] init]; + [filter setConvolutionKernel:(GPUMatrix3x3){ + { -1.0f, 0.0f, 1.0f}, + {-2.0f, 0.0f, 2.0f}, + {-1.0f, 0.0f, 1.0f} + }]; + return filter; +} + +-(void)loadCustomFilter:(int)input { + switch(input){ + case 0: + self.filter = [[LFGPUImageEmptyFilter alloc] init]; + break; + case 1: + self.filter = [[GPUImageSobelEdgeDetectionFilter alloc] init]; + break; + case 2: + self.filter = [[GPUImageColorInvertFilter alloc] init]; + break; + case 3: + self.filter = [[GPUImageSepiaFilter alloc] init]; + break; + case 4: + self.filter = [[GPUImagePixellateFilter alloc] init]; + break; + case 5: + self.filter = [self loadConvulationEffect]; + break; + case 6: + self.filter = [[GPUImageCGAColorspaceFilter alloc] init]; + break; + case 7: + self.filter = [[GPUImageCrosshatchFilter alloc] init]; + break; + case 8: + self.filter = [[GPUImageGrayscaleFilter alloc] init]; + break; + case 9: + self.filter = [[LFGPUImageBeautyFilter alloc] init]; + break; + default: + self.filter = [[LFGPUImageEmptyFilter alloc] init]; + break; + } + [self reloadEffects]; +} + - (void)reloadFilter{ [self.filter removeAllTargets]; [self.blendFilter removeAllTargets]; @@ -289,14 +339,29 @@ - (void)reloadFilter{ if (self.beautyFace) { self.output = [[LFGPUImageEmptyFilter alloc] init]; - self.filter = [[LFGPUImageBeautyFilter alloc] init]; self.beautyFilter = (LFGPUImageBeautyFilter*)self.filter; } else { self.output = [[LFGPUImageEmptyFilter alloc] init]; self.filter = [[LFGPUImageEmptyFilter alloc] init]; self.beautyFilter = nil; + } + [self reloadSecondPart]; + +} + +- (void) reloadEffects{ + [self.filter removeAllTargets]; + [self.blendFilter removeAllTargets]; + [self.uiElementInput removeAllTargets]; + [self.videoCamera removeAllTargets]; + [self.output removeAllTargets]; + [self.cropfilter removeAllTargets]; + [self reloadSecondPart]; +} + +- (void) reloadSecondPart{ ///< 调节镜像 [self reloadMirror]; @@ -335,7 +400,6 @@ - (void)reloadFilter{ [self.output setFrameProcessingCompletionBlock:^(GPUImageOutput *output, CMTime time) { [_self processVideo:output]; }]; - } - (void)reloadMirror{