123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- //
- // LPBeautySetVC.m
- // zhimi
- //
- // Created by 张灿 on 2019/1/17.
- // Copyright © 2019年 caiPro. All rights reserved.
- //
- #import "LPBeautySetVC.h"
- #import "FUCamera.h"
- #import "PFAPIDemoBar.h"
- #import "PFDateHandle.h"
- #include <PixelFree/SMPixelFree.h>
- #import <AgoraRtcEngineKit/AgoraRtcEngineKit.h>
- @interface LPBeautySetVC()<PFAPIDemoBarDelegate,FUCameraDelegate,AgoraRtcEngineDelegate>
- @property (nonatomic, strong) AgoraRtcEngineKit *agoraKit;
- @property (nonatomic,strong) AgoraRtcVideoCanvas *localCanvas;
- @property (nonatomic, strong) AgoraRtcVideoCanvas *videoCanvas;
- @property (nonatomic, strong) FUCamera *mCamera; //Faceunity Camera
- @end
- @implementation LPBeautySetVC
- @synthesize consumer;
- - (BOOL)prefersStatusBarHidden
- {
- return YES;
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.mCamera startCapture];
- }
- - (AgoraVideoBufferType)bufferType {
- return AgoraVideoBufferTypePixelBuffer;
- }
- - (BOOL)shouldInitialize {
- return YES;
- }
- - (void)shouldStart {
- [self.mCamera startCapture];
- }
- - (void)shouldStop {
- [self.mCamera stopCapture];
- }
- - (void)shouldDispose {
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor blackColor];
- UIView *localView = [[UIView alloc]initWithFrame:self.view.bounds];
- [self.view addSubview:localView];
-
- self.agoraKit = [AgoraRtcEngineKit sharedEngineWithAppId:[LCSaveData getAgoraID] delegate:self];
- NSLog(@"version is %@",[AgoraRtcEngineKit getSdkVersion]);
-
- AgoraVideoEncoderConfiguration *configuration =
- [[AgoraVideoEncoderConfiguration alloc]
- initWithSize:AgoraVideoDimension840x480
- frameRate:AgoraVideoFrameRateFps15 bitrate:AgoraVideoBitrateCompatible
- orientationMode:AgoraVideoOutputOrientationModeAdaptative];
- [self.agoraKit setVideoEncoderConfiguration:configuration];
- [self.agoraKit enableVideo];
- [self.agoraKit setVideoSource:self];
- [self.agoraKit setChannelProfile:AgoraChannelProfileLiveBroadcasting];
- [self.agoraKit setClientRole:AgoraClientRoleBroadcaster];
- //add by Elon Musk 修复视频镜像问题
- [self.agoraKit setLocalVideoMirrorMode:AgoraVideoMirrorModeDisabled];
- [self.agoraKit enableWebSdkInteroperability:YES];
-
- AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
- videoCanvas.uid = 0;
- videoCanvas.view = localView;
- videoCanvas.renderMode = AgoraVideoRenderModeHidden;
- self.localCanvas = videoCanvas;
- [self.agoraKit setupLocalVideo:videoCanvas];
-
- // [self.agoraKit startPreview];
-
- // //设置默认曝光度
- [self.mCamera setExposureValue:0];
- [self.mCamera startCapture];
- //
- self.videoFilter = [FBEffectManager shareManager];
- if ([isSDKInit isEqual: @"初始化失败"]) {
- [[FaceBeauty shareInstance] initFaceBeauty:FaceBeauty_APP_ID withDelegate:self];
- }
-
- [[FBUIManager shareManager] loadToWindowDelegate:self];
- [[FBUIManager shareManager] showBeautyView];
-
- [self setupUI];
- }
- #pragma mark - FUCameraDelegate
- bool isNeeded2 = YES;
- -(void)didOutputVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer {
- if (isNeeded2) {
- isNeeded2 = !isNeeded2;
- return;
- }
- isNeeded2 = !isNeeded2;
- CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer) ;
- CVPixelBufferLockBaseAddress(pixelBuffer, 0);
- CVPixelBufferRef pixelBuffer2 = [self.videoFilter processFrame:pixelBuffer];
- [self.consumer consumePixelBuffer:pixelBuffer2 withTimestamp:CMSampleBufferGetPresentationTimeStamp(sampleBuffer) rotation:AgoraVideoRotationNone];
- CVPixelBufferUnlockBaseAddress(pixelBuffer2, 0);
- }
- - (FUCamera *)mCamera {
- if (!_mCamera) {
- _mCamera = [[FUCamera alloc] init];
- _mCamera.delegate = self;
- }
- return _mCamera;
- }
- - (void)onInitFailure {
- isSDKInit = @"初始化失败";
- }
- - (void)onInitSuccess {
- isSDKInit = @"初始化成功";
- }
- - (void)setupUI{
- UIButton* backAction = [[UIButton alloc]initWithFrame:CGRectMake(15, 20, 40, 40)];
- if (Is_iPhoneX) {
- backAction.frame = CGRectMake(15, 45, 40, 40);
- }
- [backAction setTitle:@"取消" forState:(UIControlStateNormal)];
- [backAction setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
- [backAction addTarget:self action:@selector(backClick) forControlEvents:(UIControlEventTouchUpInside)];
- [self.view addSubview:backAction];
- }
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- [self.view endEditing:YES];
- [[FBUIManager shareManager] showBeautyView];
- }
- - (void)backClick{
- [self.mCamera stopCapture];
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- @end
|