Commit e5ad0a4094a6cfa48cfb5c86b57cc0cc2860fac1
1 parent
04a4bdb5
添加滤镜,转换摄像头,去掉水印
Showing
1 changed file
with
81 additions
and
34 deletions
LiveVideoCloud/LiveVideoCloud/Classes/Sections/LiveSections/Controller/LVCLiveViewController.m
| @@ -9,11 +9,12 @@ | @@ -9,11 +9,12 @@ | ||
| 9 | #import "LVCLiveViewController.h" | 9 | #import "LVCLiveViewController.h" |
| 10 | #import <CNLivePlayerSDK/CNLiveGPUStreamerKit.h> | 10 | #import <CNLivePlayerSDK/CNLiveGPUStreamerKit.h> |
| 11 | #import <CNLivePlayerSDK/CNLiveWebcastManager.h> | 11 | #import <CNLivePlayerSDK/CNLiveWebcastManager.h> |
| 12 | +#import "FilterFunctionView.h" | ||
| 12 | 13 | ||
| 13 | #define KAppId @"60_irn9edco29" | 14 | #define KAppId @"60_irn9edco29" |
| 14 | #define KAppKey @"69fe70bda67e059286ad509d9f5377f815955645b52f94" | 15 | #define KAppKey @"69fe70bda67e059286ad509d9f5377f815955645b52f94" |
| 15 | 16 | ||
| 16 | -@interface LVCLiveViewController () { | 17 | +@interface LVCLiveViewController ()<UIGestureRecognizerDelegate> { |
| 17 | // 开始直播 | 18 | // 开始直播 |
| 18 | UIButton *_startLiveBtn; | 19 | UIButton *_startLiveBtn; |
| 19 | // 缩放因子 | 20 | // 缩放因子 |
| @@ -24,6 +25,8 @@ | @@ -24,6 +25,8 @@ | ||
| 24 | 25 | ||
| 25 | @property (nonatomic,strong) CNLiveGPUStreamerKit *kitCN; | 26 | @property (nonatomic,strong) CNLiveGPUStreamerKit *kitCN; |
| 26 | 27 | ||
| 28 | +@property (nonatomic,strong) FilterFunctionView *filterView; | ||
| 29 | + | ||
| 27 | @end | 30 | @end |
| 28 | 31 | ||
| 29 | @implementation LVCLiveViewController | 32 | @implementation LVCLiveViewController |
| @@ -69,7 +72,9 @@ | @@ -69,7 +72,9 @@ | ||
| 69 | // _kitCN.activityName = @"iOS test"; | 72 | // _kitCN.activityName = @"iOS test"; |
| 70 | // _kitCN.coverImgUrl = @"djfiwooa"; | 73 | // _kitCN.coverImgUrl = @"djfiwooa"; |
| 71 | 74 | ||
| 75 | + // 设置推流配置 | ||
| 72 | [self setStreamerCfg]; | 76 | [self setStreamerCfg]; |
| 77 | + // 添加监听 | ||
| 73 | [self addObservers]; | 78 | [self addObservers]; |
| 74 | 79 | ||
| 75 | _startLiveBtn = [self addButton:@"开始直播" frame:CGRectMake(100, 40, 80, 40) action:@selector(startCapture:)]; | 80 | _startLiveBtn = [self addButton:@"开始直播" frame:CGRectMake(100, 40, 80, 40) action:@selector(startCapture:)]; |
| @@ -77,7 +82,7 @@ | @@ -77,7 +82,7 @@ | ||
| 77 | [_startLiveBtn setTitle:@"停止直播" forState:UIControlStateSelected]; | 82 | [_startLiveBtn setTitle:@"停止直播" forState:UIControlStateSelected]; |
| 78 | 83 | ||
| 79 | [self addButton:@"关闭预览" frame:CGRectMake(10, 40, 80, 40) action:@selector(startPreview:)]; | 84 | [self addButton:@"关闭预览" frame:CGRectMake(10, 40, 80, 40) action:@selector(startPreview:)]; |
| 80 | - [self addButton:@"退出" frame:CGRectMake(190, 40, 80, 40) action:@selector(quit)]; | 85 | +// [self addButton:@"退出" frame:CGRectMake(190, 40, 80, 40) action:@selector(quit)]; |
| 81 | [self addButton:@"美颜" frame:CGRectMake(10, 100, 80, 40) action:@selector(openFilter:)]; | 86 | [self addButton:@"美颜" frame:CGRectMake(10, 100, 80, 40) action:@selector(openFilter:)]; |
| 82 | [self addButton:@"摄像头" frame:CGRectMake(100, 100, 80, 40) action:@selector(changeCamera:)]; | 87 | [self addButton:@"摄像头" frame:CGRectMake(100, 100, 80, 40) action:@selector(changeCamera:)]; |
| 83 | [self addButton:@"闪光灯" frame:CGRectMake(190, 100, 80, 40) action:@selector(openFlash)]; | 88 | [self addButton:@"闪光灯" frame:CGRectMake(190, 100, 80, 40) action:@selector(openFlash)]; |
| @@ -120,16 +125,16 @@ | @@ -120,16 +125,16 @@ | ||
| 120 | [_kitCN startPreview:self.captureView]; | 125 | [_kitCN startPreview:self.captureView]; |
| 121 | 126 | ||
| 122 | //水印图片 | 127 | //水印图片 |
| 123 | - _kitCN.watermark.logoPic = [UIImage imageNamed:@"互动电视180x180"]; | ||
| 124 | - _kitCN.watermark.logoRect = CGRectMake(0.8, 0.8, 50, 50); | ||
| 125 | - _kitCN.watermark.logoAlpha = 0.6; | 128 | +// _kitCN.watermark.logoPic = [UIImage imageNamed:@"互动电视180x180"]; |
| 129 | +// _kitCN.watermark.logoRect = CGRectMake(0.8, 0.8, 50, 50); | ||
| 130 | +// _kitCN.watermark.logoAlpha = 0.6; | ||
| 126 | 131 | ||
| 127 | //水印文字 | 132 | //水印文字 |
| 128 | - _kitCN.watermark.textLabel = [[UILabel alloc] init]; | ||
| 129 | - _kitCN.watermark.textLabel.text = [NSString stringWithFormat:@"cnlive"]; | ||
| 130 | - _kitCN.watermark.textLabel.font = [UIFont systemFontOfSize:8]; | ||
| 131 | - _kitCN.watermark.textRect = CGRectMake(0.78, 0.88, 0.2, 0.04); | ||
| 132 | - [_kitCN.watermark updateTextLabel]; | 133 | +// _kitCN.watermark.textLabel = [[UILabel alloc] init]; |
| 134 | +// _kitCN.watermark.textLabel.text = [NSString stringWithFormat:@"cnlive"]; | ||
| 135 | +// _kitCN.watermark.textLabel.font = [UIFont systemFontOfSize:8]; | ||
| 136 | +// _kitCN.watermark.textRect = CGRectMake(0.78, 0.88, 0.2, 0.04); | ||
| 137 | +// [_kitCN.watermark updateTextLabel]; | ||
| 133 | 138 | ||
| 134 | } | 139 | } |
| 135 | 140 | ||
| @@ -160,7 +165,7 @@ | @@ -160,7 +165,7 @@ | ||
| 160 | _startLiveBtn.selected = NO; | 165 | _startLiveBtn.selected = NO; |
| 161 | }]; | 166 | }]; |
| 162 | }else{ | 167 | }else{ |
| 163 | -// _stateLab.text = nil; | 168 | + |
| 164 | [_kitCN stopStream]; | 169 | [_kitCN stopStream]; |
| 165 | } | 170 | } |
| 166 | } | 171 | } |
| @@ -184,6 +189,59 @@ | @@ -184,6 +189,59 @@ | ||
| 184 | } | 189 | } |
| 185 | } | 190 | } |
| 186 | 191 | ||
| 192 | +// 美颜滤镜 | ||
| 193 | +- (void)openFilter:(UIButton *)button { | ||
| 194 | + | ||
| 195 | + button.selected = !button.selected; | ||
| 196 | + | ||
| 197 | + if (button.selected) { | ||
| 198 | + | ||
| 199 | + _filterView.hidden = NO; | ||
| 200 | + | ||
| 201 | + __weak LVCLiveViewController *weakselff = self; | ||
| 202 | + | ||
| 203 | + _filterView.filterViewBlock = ^(float grindRatio , float whitenRatio, float intensity){ | ||
| 204 | + | ||
| 205 | + [weakselff.kitCN.beautifyFaceFilter filterAdjustingParameterWithGrindRatio:grindRatio | ||
| 206 | + whitenRatio:whitenRatio | ||
| 207 | + intensity:intensity]; | ||
| 208 | + }; | ||
| 209 | + | ||
| 210 | + _filterView.currentTypeBlock = ^(NSInteger currentType){ | ||
| 211 | + [weakselff.kitCN.beautifyFaceFilter setBeautyType:currentType]; | ||
| 212 | + }; | ||
| 213 | + | ||
| 214 | + _filterView.currentIdxBlock = ^(NSInteger currentIdx){ | ||
| 215 | + weakselff.kitCN.beautifyFaceFilter.curEffectIdx = currentIdx; | ||
| 216 | + }; | ||
| 217 | + | ||
| 218 | + } else { | ||
| 219 | + | ||
| 220 | + _filterView.hidden = YES; | ||
| 221 | + | ||
| 222 | + } | ||
| 223 | +} | ||
| 224 | + | ||
| 225 | +// 转换前后置摄像头 | ||
| 226 | +- (void)changeCamera:(UIButton *)button { | ||
| 227 | + | ||
| 228 | +// button.selected = !button.selected; | ||
| 229 | +// if (button.selected) { | ||
| 230 | +// _kitCN.cameraPosition = AVCaptureDevicePositionBack; | ||
| 231 | +// }else{ | ||
| 232 | +// _kitCN.cameraPosition = AVCaptureDevicePositionFront; | ||
| 233 | +// } | ||
| 234 | + [_kitCN switchCamera]; | ||
| 235 | + | ||
| 236 | +} | ||
| 237 | + | ||
| 238 | +// 闪光灯 | ||
| 239 | +- (void)openFlash { | ||
| 240 | + | ||
| 241 | + [_kitCN toggleTorch]; | ||
| 242 | + // [_kitCN setTorchMode:AVCaptureTorchModeOn]; | ||
| 243 | +} | ||
| 244 | + | ||
| 187 | // 退出 | 245 | // 退出 |
| 188 | - (void)closeBtnClivk { | 246 | - (void)closeBtnClivk { |
| 189 | 247 | ||
| @@ -200,8 +258,8 @@ | @@ -200,8 +258,8 @@ | ||
| 200 | 258 | ||
| 201 | #pragma mark - UIGestureRecognizer Action !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 259 | #pragma mark - UIGestureRecognizer Action !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 202 | //对焦与曝光 | 260 | //对焦与曝光 |
| 203 | -- (void)onTap:(UIGestureRecognizer *)sender | ||
| 204 | -{ | 261 | +- (void)onTap:(UIGestureRecognizer *)sender { |
| 262 | + | ||
| 205 | CGPoint current = [sender locationInView:self.view]; | 263 | CGPoint current = [sender locationInView:self.view]; |
| 206 | CGPoint point = [self convertToPointOfInterestFromViewCoordinates:current]; | 264 | CGPoint point = [self convertToPointOfInterestFromViewCoordinates:current]; |
| 207 | [_kitCN exposureAtPoint:point]; | 265 | [_kitCN exposureAtPoint:point]; |
| @@ -209,7 +267,8 @@ | @@ -209,7 +267,8 @@ | ||
| 209 | } | 267 | } |
| 210 | 268 | ||
| 211 | //缩放 | 269 | //缩放 |
| 212 | -- (void)pinchDetected:(UIPinchGestureRecognizer *)recognizer{ | 270 | +- (void)pinchDetected:(UIPinchGestureRecognizer *)recognizer { |
| 271 | + | ||
| 213 | if (recognizer.state == UIGestureRecognizerStateBegan) { | 272 | if (recognizer.state == UIGestureRecognizerStateBegan) { |
| 214 | _currentPinchZoomFactor = _kitCN.pinchZoomFactor; | 273 | _currentPinchZoomFactor = _kitCN.pinchZoomFactor; |
| 215 | } | 274 | } |
| @@ -233,40 +292,34 @@ | @@ -233,40 +292,34 @@ | ||
| 233 | 292 | ||
| 234 | if ( _kitCN.captureState == CNLiveCaptureStateIdle){ | 293 | if ( _kitCN.captureState == CNLiveCaptureStateIdle){ |
| 235 | //初始化时状态为空闲 | 294 | //初始化时状态为空闲 |
| 236 | -// _stateLab.text = @"CNLiveCaptureStateIdle"; | ||
| 237 | 295 | ||
| 238 | return; | 296 | return; |
| 239 | } | 297 | } |
| 240 | else if (_kitCN.captureState == CNLiveCaptureStateCapturing ) { | 298 | else if (_kitCN.captureState == CNLiveCaptureStateCapturing ) { |
| 241 | //设备工作中 | 299 | //设备工作中 |
| 242 | -// _stateLab.text = @"CNLiveCaptureStateCapturing"; | ||
| 243 | 300 | ||
| 244 | return; | 301 | return; |
| 245 | } | 302 | } |
| 246 | else if (_kitCN.captureState == CNLiveCaptureStateClosingCapture ) { | 303 | else if (_kitCN.captureState == CNLiveCaptureStateClosingCapture ) { |
| 247 | //关闭采集设备中 | 304 | //关闭采集设备中 |
| 248 | -// _stateLab.text = @"CNLiveCaptureStateClosingCapture"; | ||
| 249 | 305 | ||
| 250 | return; | 306 | return; |
| 251 | } | 307 | } |
| 252 | else if (_kitCN.captureState == CNLiveCaptureStateDevAuthDenied ) { | 308 | else if (_kitCN.captureState == CNLiveCaptureStateDevAuthDenied ) { |
| 253 | //设备授权被拒绝 | 309 | //设备授权被拒绝 |
| 254 | NSLog(@"---------CNLiveCaptureStateDevAuthDenied"); | 310 | NSLog(@"---------CNLiveCaptureStateDevAuthDenied"); |
| 255 | -// _stateLab.text = @"camera/mic Authorization Denied"; | ||
| 256 | 311 | ||
| 257 | return; | 312 | return; |
| 258 | } | 313 | } |
| 259 | else if (_kitCN.captureState == CNLiveCaptureStateParameterError ) { | 314 | else if (_kitCN.captureState == CNLiveCaptureStateParameterError ) { |
| 260 | // 参数错误,无法打开 | 315 | // 参数错误,无法打开 |
| 261 | NSLog(@"---------CNLiveCaptureStateParameterError"); | 316 | NSLog(@"---------CNLiveCaptureStateParameterError"); |
| 262 | -// _stateLab.text = @"capture devices ParameterError"; | ||
| 263 | 317 | ||
| 264 | return; | 318 | return; |
| 265 | } | 319 | } |
| 266 | else if (_kitCN.captureState == CNLiveCaptureStateDevBusy ) { | 320 | else if (_kitCN.captureState == CNLiveCaptureStateDevBusy ) { |
| 267 | //设备正忙,请稍后尝试 | 321 | //设备正忙,请稍后尝试 |
| 268 | NSLog(@"---------CNLiveCaptureStateDevBusy"); | 322 | NSLog(@"---------CNLiveCaptureStateDevBusy"); |
| 269 | -// _stateLab.text = @"device busy, try later"; | ||
| 270 | 323 | ||
| 271 | } | 324 | } |
| 272 | } | 325 | } |
| @@ -276,19 +329,16 @@ | @@ -276,19 +329,16 @@ | ||
| 276 | if (_kitCN.streamState == CNLiveStreamStateIdle) { | 329 | if (_kitCN.streamState == CNLiveStreamStateIdle) { |
| 277 | 330 | ||
| 278 | NSLog(@"---------CNLiveStreamStateIdle"); | 331 | NSLog(@"---------CNLiveStreamStateIdle"); |
| 279 | -// _stateLab.text = @"CNLiveStreamStateIdle"; | ||
| 280 | } | 332 | } |
| 281 | 333 | ||
| 282 | if (_kitCN.streamState == CNLiveStreamStateConnected) { | 334 | if (_kitCN.streamState == CNLiveStreamStateConnected) { |
| 283 | 335 | ||
| 284 | NSLog(@"---------CNLiveStreamStateConnected"); | 336 | NSLog(@"---------CNLiveStreamStateConnected"); |
| 285 | -// _stateLab.text = [NSString stringWithFormat:@"CNLiveStreamStateConnected------%@",_hostURL]; | ||
| 286 | } | 337 | } |
| 287 | 338 | ||
| 288 | if (_kitCN.streamState == CNLiveStreamStateConnecting) { | 339 | if (_kitCN.streamState == CNLiveStreamStateConnecting) { |
| 289 | 340 | ||
| 290 | NSLog(@"---------CNLiveStreamStateConnecting"); | 341 | NSLog(@"---------CNLiveStreamStateConnecting"); |
| 291 | -// _stateLab.text = @"CNLiveStreamStateConnecting"; | ||
| 292 | } | 342 | } |
| 293 | 343 | ||
| 294 | //推流出错 | 344 | //推流出错 |
| @@ -302,14 +352,12 @@ | @@ -302,14 +352,12 @@ | ||
| 302 | if ( _kitCN.streamState == CNLiveStreamStateDisconnecting) { | 352 | if ( _kitCN.streamState == CNLiveStreamStateDisconnecting) { |
| 303 | 353 | ||
| 304 | NSLog(@"---------CNLiveStreamStateDisconnecting"); | 354 | NSLog(@"---------CNLiveStreamStateDisconnecting"); |
| 305 | -// _stateLab.text = @"CNLiveStreamStateDisconnecting"; | ||
| 306 | } | 355 | } |
| 307 | 356 | ||
| 308 | //结束推流成功 | 357 | //结束推流成功 |
| 309 | if ( _kitCN.streamState == CNLiveStopStreamSuccess) { | 358 | if ( _kitCN.streamState == CNLiveStopStreamSuccess) { |
| 310 | 359 | ||
| 311 | NSLog(@"---------CNLiveStopStreamSuccess"); | 360 | NSLog(@"---------CNLiveStopStreamSuccess"); |
| 312 | -// _stateLab.text = @"CNLiveStopStreamSuccess"; | ||
| 313 | } | 361 | } |
| 314 | } | 362 | } |
| 315 | // 推流失败 | 363 | // 推流失败 |
| @@ -320,19 +368,19 @@ | @@ -320,19 +368,19 @@ | ||
| 320 | NSLog(@"onErr: %lu ", (unsigned long) err); | 368 | NSLog(@"onErr: %lu ", (unsigned long) err); |
| 321 | 369 | ||
| 322 | if ( CNLiveStreamErrorCode_CNLiveAUTHFAILED == err ) { | 370 | if ( CNLiveStreamErrorCode_CNLiveAUTHFAILED == err ) { |
| 323 | -// _stateLab.text = @"SDK auth failed, \npls check ak/sk"; | 371 | + |
| 324 | } | 372 | } |
| 325 | else if ( CNLiveStreamErrorCode_CODEC_OPEN_FAILED == err) { | 373 | else if ( CNLiveStreamErrorCode_CODEC_OPEN_FAILED == err) { |
| 326 | -// _stateLab.text = @"Selected Codec not supported \n in this version"; | 374 | + |
| 327 | } | 375 | } |
| 328 | else if ( CNLiveStreamErrorCode_CONNECT_FAILED == err) { | 376 | else if ( CNLiveStreamErrorCode_CONNECT_FAILED == err) { |
| 329 | -// _stateLab.text = @"Connecting error, pls check host url \nor network"; | 377 | + |
| 330 | } | 378 | } |
| 331 | else if ( CNLiveStreamErrorCode_CONNECT_BREAK == err) { | 379 | else if ( CNLiveStreamErrorCode_CONNECT_BREAK == err) { |
| 332 | -// _stateLab.text = @"Connection break"; | 380 | + |
| 333 | } | 381 | } |
| 334 | else if ( CNLiveStreamErrorCode_ABNORMAL == err) { | 382 | else if ( CNLiveStreamErrorCode_ABNORMAL == err) { |
| 335 | -// _stateLab.text = @"CNLiveStreamErrorCode_ABNORMAL"; | 383 | + |
| 336 | [self toast:@"推流异常中断~~"]; | 384 | [self toast:@"推流异常中断~~"]; |
| 337 | _startLiveBtn.selected = NO; | 385 | _startLiveBtn.selected = NO; |
| 338 | 386 | ||
| @@ -376,8 +424,7 @@ | @@ -376,8 +424,7 @@ | ||
| 376 | } | 424 | } |
| 377 | 425 | ||
| 378 | // 提示框 | 426 | // 提示框 |
| 379 | -- (void)toast:(NSString*)message | ||
| 380 | -{ | 427 | +- (void)toast:(NSString*)message { |
| 381 | 428 | ||
| 382 | UIAlertView *toast = [[UIAlertView alloc] initWithTitle:nil | 429 | UIAlertView *toast = [[UIAlertView alloc] initWithTitle:nil |
| 383 | message:message | 430 | message:message |
| @@ -393,8 +440,8 @@ | @@ -393,8 +440,8 @@ | ||
| 393 | 440 | ||
| 394 | 441 | ||
| 395 | // 将UI的坐标转换成相机坐标 | 442 | // 将UI的坐标转换成相机坐标 |
| 396 | -- (CGPoint)convertToPointOfInterestFromViewCoordinates:(CGPoint)viewCoordinates | ||
| 397 | -{ | 443 | +- (CGPoint)convertToPointOfInterestFromViewCoordinates:(CGPoint)viewCoordinates { |
| 444 | + | ||
| 398 | CGPoint pointOfInterest = CGPointMake(.5f, .5f); | 445 | CGPoint pointOfInterest = CGPointMake(.5f, .5f); |
| 399 | CGSize frameSize = self.view.frame.size; | 446 | CGSize frameSize = self.view.frame.size; |
| 400 | CGSize apertureSize = [_kitCN captureDimension]; | 447 | CGSize apertureSize = [_kitCN captureDimension]; |