123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887 |
- //
- // YOUPAIBBBaseVideoCallVC.m
- // VQU
- //
- // Created by Elaine on 2021/10/28.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAIBBBaseVideoCallVC.h"
- #import "FUOpenGLView.h"
- #import "FUCamera.h"
- #import "PFAPIDemoBar.h"
- #import "PFDateHandle.h"
- #import <PixelFree/SMPixelFree.h>
- //#import "YOUPAIAGVideoProcessing.h"
- #import "AppDelegate.h"
- #import "YOUPAIBBCustomSystomNotification.h"
- @interface YOUPAIBBBaseVideoCallVC ()<FUCameraDelegate,PFAPIDemoBarDelegate>
- @property (assign,nonatomic) CGPoint youpaipstartPoint; //用来做清屏
- @property (nonatomic, strong) FUCamera *youpaipmCamera; //Faceunity Camera
- @property(nonatomic,assign)BOOL youpaipisRecordScreen;
- @property(nonatomic,strong)UIView *youpaiprecoderHideView;
- @property (nonatomic, assign) BOOL youpaipisHangupCallVideo; /// 是否手动挂断
- @property(nonatomic,strong)UIImageView *timeLogo;
- @property(nonatomic,strong)UIButton *closeBtn;
- @property(nonatomic, strong) PFAPIDemoBar *beautyEditView;
- @property (nonatomic, strong) NSUserDefaults *def;
- @property (nonatomic,strong) SMPixelFree *mPixelFree;
- @property (nonatomic,assign)BOOL clickCompare;
- @end
- @implementation YOUPAIBBBaseVideoCallVC
- //@synthesize consumer;
- -(BOOL)prefersStatusBarHidden
- {
- return YES;
- }
- - (FUCamera *)youpaipmCamera {
- if (!_youpaipmCamera) {
- _youpaipmCamera = [[FUCamera alloc] init];
- _youpaipmCamera.delegate = self;
- }
- return _youpaipmCamera;
- }
- - (void)dealloc{
- NSLog(@"dealloc basevideo");
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- self.navigationController.navigationBarHidden = YES;
- [LCSaveData saveIsVideo:YES];
-
- [self.youpaipmCamera startCapture];
- // [IQKeyboardManager sharedManager].enable = NO;
- }
- - (void)viewDidAppear:(BOOL)animated{
- [super viewDidAppear:animated];
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- [self.youpaipplayer stop];
- //add by leo 此处会导致vc无法释放
- self.youpaipplayer =nil;
- //add by leo 异常退出/被踢 显示处于视频中
- [LCSaveData saveIsVideo:NO];
- self.navigationController.navigationBarHidden = NO;
- // [IQKeyboardManager sharedManager].enable = YES;
- }
- - (void)viewDidLoad{
- [super viewDidLoad];
- self.sx_disableInteractivePop = YES;
- self.def = [NSUserDefaults standardUserDefaults];
- [self initPixelFree];
- [self setDefaultParam];
-
-
- NSString* path = [[NSBundle mainBundle] pathForResource:@"sound"ofType:@"bundle"];
- NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/call_bg.mp3",path]];
- self.youpaipplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
- [self.youpaipplayer prepareToPlay];
- self.youpaipplayer.numberOfLoops = -1;
- [self.youpaipplayer play];
- [self youpaifinitView];
- [self youpaifinitAgora];
- NSString* str=[AgoraRtcEngineKit getSdkVersion];
-
- //设置默认曝光度
- [self.youpaipmCamera setExposureValue:0];
- [self.youpaipmCamera startCapture];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifwillResignActive) name:UIApplicationWillResignActiveNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifwillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifdidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
- //挂断视频,接听通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifhangupCallVideoNotification) name:@"HangupCallVideo" object:nil];
- }
- #pragma mark 澜极美颜--start
- -(PFAPIDemoBar *)beautyEditView {
- if (!_beautyEditView) {
- _beautyEditView = [[PFAPIDemoBar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 280, self.view.frame.size.width, 280)];
-
- _beautyEditView.mDelegate = self;
- }
- return _beautyEditView ;
- }
- -(void)comparisonButtonDidClick:(BOOL)state{
- self.clickCompare = state;
- }
- -(void)writeData:(NSData *)data fileName:(NSString *)fileName{
- NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentDirectory = [documentDirectories objectAtIndex:0];
- // 获取目标文件的完整路径
- NSString *filePath = [documentDirectory stringByAppendingPathComponent:fileName];
-
- // [[NSFileManager defaultManager] fileExistsAtPath:filePath];
- // 创建文件并覆盖写入数据
- BOOL success = [[NSFileManager defaultManager] createFileAtPath:filePath
- contents:data
- attributes:nil];
- if (success) {
- NSLog(@"数据写入成功");
- } else {
- NSLog(@"数据写入失败");
- }
-
- }
- -(NSData *)readDatafileName:(NSString *)fileName{
- NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentDirectory = [documentDirectories objectAtIndex:0];
- // 获取目标文件的完整路径
- NSString *filePath = [documentDirectory stringByAppendingPathComponent:fileName];
-
- NSData *data = [NSData dataWithContentsOfFile:filePath];
- return data;
- }
- -(void)initPixelFree{
- NSString *face_FiltePath = [[NSBundle mainBundle] pathForResource:@"filter_model.bundle" ofType:nil];
- NSString *authFile = [[NSBundle mainBundle] pathForResource:@"pixelfreeAuth.lic" ofType:nil];
- self.mPixelFree = [[SMPixelFree alloc] initWithProcessContext:nil srcFilterPath:face_FiltePath authFile:authFile];
- [self.view addSubview:self.beautyEditView];
- self.beautyEditView.hidden = YES;
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- self.beautyEditView.hidden = YES;
- [self.view endEditing:YES];
- }
- -(void)setDefaultParam{
- NSArray<PFBeautyParam *>* defaultData = [PFDateHandle setupShapData];
- NSArray<PFBeautyParam *>* defaultSkinData = [PFDateHandle setupSkinData];
- NSArray<PFBeautyParam *>* defaultfiltersData = [PFDateHandle setupFilterData];
- NSArray<PFBeautyParam *>* defaultfaceData = [PFDateHandle setupFaceType];
- // 读本地缓存
- NSData *data = [self readDatafileName:@"shapeParamsData"];
- if (data) {
- defaultData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
- }
-
- data = [self readDatafileName:@"skinParamsData"];
- if (data) {
- defaultSkinData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
- }
-
- data = [self readDatafileName:@"filtersParamsData"];
- if (data) {
- defaultfiltersData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
- }
-
- data = [self readDatafileName:@"oneKeyParamsData"];
- if (data) {
- defaultfaceData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
- }
- // 更新 UI
- self.beautyEditView.shapeParams = defaultData;
- self.beautyEditView.skinParams = defaultSkinData;
- self.beautyEditView.filtersParams = defaultfiltersData;
- self.beautyEditView.faceTypeParams = defaultfaceData;
-
- NSUserDefaults*userDefaults = [NSUserDefaults standardUserDefaults];
- int oneKeyType = (int)[userDefaults integerForKey:@"oneKeyType"];
- int filtersIndex = (int)[userDefaults integerForKey:@"filtersUseIndex"];
- self.beautyEditView.oneKeyType = oneKeyType;
- self.beautyEditView.filterIndex = filtersIndex;
-
- [self.beautyEditView updateDemoBar];
-
-
- // 更新 SDK 设置
- for (PFBeautyParam *param in defaultData) {
- [self filterValueChange:param];
- }
-
- for (PFBeautyParam *param in defaultSkinData) {
- [self filterValueChange:param];
- }
-
-
- PFBeautyParam *param = defaultfaceData[oneKeyType];
- [self filterValueChange:param];
- param = defaultfiltersData[filtersIndex];
- [self filterValueChange:param];
- }
- -(void)filterValueChange:(PFBeautyParam *)param{
- CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
- float value = param.mValue;
- if(param.type == FUDataTypeBeautify){
- if ([param.mParam isEqualToString:@"face_EyeStrength"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_EyeStrength value:&value];
- }
- if ([param.mParam isEqualToString:@"face_thinning"]) {
- float aa = param.mValue;
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_thinning value:&value];
- }
- if ([param.mParam isEqualToString:@"face_narrow"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_narrow value:&value];
- }
- if ([param.mParam isEqualToString:@"face_chin"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_chin value:&value];
- }
- if ([param.mParam isEqualToString:@"face_V"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_V value:&value];
- }
- if ([param.mParam isEqualToString:@"face_small"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_small value:&value];
- }
- if ([param.mParam isEqualToString:@"face_nose"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_nose value:&value];
- }
- if ([param.mParam isEqualToString:@"face_forehead"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_forehead value:&value];
- }
- if ([param.mParam isEqualToString:@"face_mouth"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_mouth value:&value];
- }
- if ([param.mParam isEqualToString:@"face_philtrum"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_philtrum value:&value];
- }
- if ([param.mParam isEqualToString:@"face_long_nose"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_long_nose value:&value];
- }
- if ([param.mParam isEqualToString:@"face_eye_space"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_eye_space value:&value];
- }
-
- if ([param.mParam isEqualToString:@"face_smile"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_smile value:&value];
- }
- if ([param.mParam isEqualToString:@"face_eye_rotate"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_eye_rotate value:&value];
- }
- if ([param.mParam isEqualToString:@"face_canthus"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_canthus value:&value];
- }
- if ([param.mParam isEqualToString:@"runddy"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceRuddyStrength value:&value];
- }
- if ([param.mParam isEqualToString:@"writen"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceWhitenStrength value:&value];
- }
- if ([param.mParam isEqualToString:@"blur"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceBlurStrength value:&value];
- }
- if ([param.mParam isEqualToString:@"sharpen"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceSharpenStrength value:&value];
- }
- if ([param.mParam isEqualToString:@"newWhitenStrength"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceM_newWhitenStrength value:&value];
- }
- if ([param.mParam isEqualToString:@"qualityStrength"]) {
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceH_qualityStrength value:&value];
- }
- }
- if (param.type == FUDataTypeFilter) {
- const char *aaa = [param.mParam UTF8String];
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterName value:(void *)aaa];
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterStrength value:&value];
- }
- if (param.type == FUDataTypeStickers) {
- if([param.mParam isEqualToString:@"origin"]){
- [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:NULL];
- } else{
- // NSString *path = [[NSBundle mainBundle] pathForResource:@"Stickers" ofType:nil];
- // NSString *currentFolder = [path stringByAppendingPathComponent:param.mParam];
- // const char *aaa = [currentFolder UTF8String];
- // [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:(void *)aaa];
- NSString *name = [NSString stringWithFormat:@"%@.bundle",param.mParam];
- NSString *paths = [[NSBundle mainBundle] pathForResource:name ofType:nil];
- [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:(void *)[paths UTF8String]];
- }
- }
-
- if (param.type == FUDataTypeOneKey) {
- if ([param.mTitle isEqualToString:@"origin"]) {
- int value = PFBeautyTypeOneKeyNormal;
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
-
- }
- if ([param.mTitle isEqualToString:@"自然"]) {
- int value = PFBeautyTypeOneKeyNatural;
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
-
- }
- if ([param.mTitle isEqualToString:@"可爱"]) {
- int value = PFBeautyTypeOneKeyCute;
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
-
- }
- if ([param.mTitle isEqualToString:@"女神"]) {
- int value = PFBeautyTypeOneKeyGoddess;
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
-
- }
- if ([param.mTitle isEqualToString:@"白净"]) {
- int value = PFBeautyTypeOneKeyFair;
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
-
- }
- }
- }
- -(void)bottomDidChange:(int)index{
- if (index != 0 && _beautyEditView.oneKeyType != PFBeautyTypeOneKeyNormal) {
- int value = PFBeautyTypeOneKeyNormal;
- [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
- [self showDelayedAlert];
- _beautyEditView.oneKeyType = PFBeautyTypeOneKeyNormal;
- }
- }
- - (void)showDelayedAlert {
- // 创建 UIAlertController
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"一键美颜已关闭" preferredStyle:UIAlertControllerStyleAlert];
-
- dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
- dispatch_after(delay, dispatch_get_main_queue(), ^{
- [alertController dismissViewControllerAnimated:YES completion:nil];
- });
- [self presentViewController:alertController animated:YES completion:nil];
- }
- #pragma mark 澜极美颜--end
- - (void)youpaifhangupCallVideoNotification{
- [self youpaifvideoEnd:BBCustomSystomNotificationTypeWithHangupCallVideo];
- [ZCHUDHelper showTitle:@"对方已挂断"];
- }
- - (void)youpaifinitView{
- self.youpaipremoteVideo = [[UIView alloc]initWithFrame:CGRectMake(0,0,KScreenWidth,KScreenHeight)];
- self.youpaipremoteVideo.backgroundColor = [UIColor blackColor];
- [self.view addSubview:self.youpaipremoteVideo];
- self.youpaiprecoderHideView = [[UIView alloc]init];
- [self.youpaiprecoderHideView setBackgroundColor:[UIColor whiteColor]];
- [self.youpaiprecoderHideView setHidden:YES];
- [self.view addSubview:self.youpaiprecoderHideView];
- UIView* msgCoverView = [[UIView alloc]initWithFrame:CGRectMake(-KScreenWidth, 0, KScreenWidth*2, KScreenHeight)];
- msgCoverView.backgroundColor = [UIColor clearColor];
- UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifmsgViewPanHandel:)];
- [msgCoverView addGestureRecognizer:pan];
- UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifdoubleTapHandel:)];
- doubleTap.numberOfTapsRequired = 2;
- [msgCoverView addGestureRecognizer:doubleTap];
- self.youpaipmsgCoverView = msgCoverView;
- [self.view addSubview:msgCoverView];
- UIView* interView = [[UIView alloc]initWithFrame:CGRectMake(KScreenWidth, 0, KScreenWidth, KScreenHeight)];
- interView.backgroundColor = [UIColor clearColor];
- self.youpaipinterView = interView;
- UITapGestureRecognizer* interTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifinterHandel:)];
- [self.youpaipinterView addGestureRecognizer:interTap];
- [msgCoverView addSubview:interView];
- //设置顶部按钮
- UIButton* closeBtn = [[UIButton alloc]initWithFrame:CGRectMake(16,StatusBarHeight+4, 30, 30)];
- [closeBtn setImage:[UIImage imageNamed:@"vqu_images_video_end"] forState:(UIControlStateNormal)];
- [closeBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
- [closeBtn setEnlargeEdge:10];
- [self.view addSubview:closeBtn];
- self.closeBtn = closeBtn;
- self.closeBtn.hidden = YES;
- UIView *timeBgv = [[UIView alloc] init];
- timeBgv.layer.cornerRadius = 12.0f;
- timeBgv.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
- [self.view addSubview:timeBgv];
- [timeBgv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(54.0f);
- make.top.offset(StatusBarHeight+7);
- make.height.offset(24.0f);
- }];
- UIImageView* timeLogo = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, 30, 30)];
- timeLogo.contentMode = UIViewContentModeScaleAspectFill;
- timeLogo.image = [UIImage imageNamed:@"vqu_images_video_time"];
- [timeBgv addSubview:timeLogo];
- [timeLogo mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(0);
- make.centerY.equalTo(timeBgv);
- make.size.mas_offset(CGSizeMake(30, 30));
- }];
- self.timeLogo = timeLogo;
- self.timeLogo.hidden = YES;
- UILabel* timeLabel = [self youpaifcreateLabelWithFrame:CGRectMake(44,0,100,30) text:@"00:00"];
- timeLabel.textColor = HexColorFromRGB(0xFFFFFF);
- self.youpaiptimeLabel = timeLabel;
- [timeBgv addSubview:timeLabel];
- [self youpaiftimeStart];
- [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.offset(0.0f);
- make.right.offset(-8.0f);
- make.left.equalTo(timeLogo.mas_right);
- }];
- self.youpaiptimeLabel.hidden = YES;
- self.youpaiplocalVideo = [[UIView alloc]initWithFrame:CGRectMake(KScreenWidth-106,StatusBarHeight+4, 90,120)];
- self.youpaiplocalVideo.backgroundColor = [UIColor blackColor];
- self.youpaiplocalVideo.layer.cornerRadius = 5.0;
- self.youpaiplocalVideo.layer.masksToBounds = YES;
- [self.view addSubview:self.youpaiplocalVideo];
- UITapGestureRecognizer* localTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifloaclVideoHandel:)];
- [self.youpaiplocalVideo addGestureRecognizer:localTap];
- //摄像
- UIButton* cameraBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.youpaiplocalVideo.center.x-16,StatusBarHeight+4+120+8.5,32,25)];
- [cameraBtn setImage:[UIImage imageNamed:@"vqu_images_video_off"] forState:(UIControlStateNormal)];
- [cameraBtn addTarget:self action:@selector(youpaifcameraBtnClick:) forControlEvents:(UIControlEventTouchUpInside)];
- [self.view addSubview:cameraBtn];
- cameraBtn.selected = YES;
- self.youpaipcameraBtn = cameraBtn;
- self.youpaipcameraBtn.hidden = YES;
- self.youpaipcameraBtn.centerX = self.youpaiplocalVideo.center.x;
- }
- - (UILabel*)youpaifcreateLabelWithFrame:(CGRect)frame text:(NSString*)contentText{
- UILabel* lab = [[UILabel alloc]initWithFrame:frame];
- lab.textColor = [UIColor whiteColor];
- lab.font = [UIFont systemFontOfSize:11];
- lab.textAlignment = NSTextAlignmentLeft;
- lab.text = contentText;
- return lab;
- }
- #pragma mark - Agora
- - (void)youpaifinitAgora{
- self.agoraKit = [AgoraRtcEngineKit sharedEngineWithAppId:AgoraID delegate:self];
- NSLog(@"version is %@",[AgoraRtcEngineKit getSdkVersion]);
- AgoraVideoEncoderConfiguration *configuration = [[AgoraVideoEncoderConfiguration alloc] initWithSize:AgoraVideoDimension1280x720 frameRate:AgoraVideoFrameRateFps24 bitrate:AgoraVideoBitrateCompatible orientationMode:AgoraVideoOutputOrientationModeAdaptative mirrorMode:AgoraVideoMirrorModeAuto];
- [self.agoraKit setVideoEncoderConfiguration:configuration];
- [self.agoraKit enableVideo];
- [self.agoraKit setExternalVideoSource:YES useTexture:YES sourceType:AgoraExternalVideoSourceTypeVideoFrame]; //只允许外部源
- [self.agoraKit setChannelProfile:AgoraChannelProfileLiveBroadcasting];
- [self.agoraKit setClientRole:AgoraClientRoleBroadcaster];
- //add by leo 修复视频镜像问题
- [self.agoraKit setLocalVideoMirrorMode:AgoraVideoMirrorModeDisabled];
- [self.agoraKit enableWebSdkInteroperability:YES];
- AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
- videoCanvas.uid = 0;
- videoCanvas.view = self.youpaiplocalVideo;
- videoCanvas.renderMode = AgoraVideoRenderModeHidden;
- self.localCanvas = videoCanvas;
- [self.agoraKit setupLocalVideo:videoCanvas];
- }
- #pragma mark - AgoraRtcEngineDelegate
- //收到对方的视频
- - (void)rtcEngine:(AgoraRtcEngineKit *)engine firstRemoteVideoDecodedOfUid:(NSUInteger)uid size: (CGSize)size elapsed:(NSInteger)elapsed {
- self.youpaipremoteVideo.hidden = NO;
- self.youpaipcameraBtn.hidden = NO;
- self.youpaiptimeLabel.hidden = NO;
- self.closeBtn.hidden = NO;
- self.timeLogo.hidden = NO;
- AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
- videoCanvas.renderMode = AgoraVideoRenderModeHidden;
- self.remoteCanvas= videoCanvas;
- self.remoteCanvas.uid = uid;
- self.remoteCanvas.view = self.youpaipremoteVideo;
- int value =[self.agoraKit setupRemoteVideo:self.remoteCanvas];
- NSLog(@"%d",value);
- }
- - (void)rtcEngine:(AgoraRtcEngineKit *)engine
- didVideoMuted:(BOOL)muted byUid:(NSUInteger)uid{
- if (muted) {//对端关闭了视频
- self.localCanvas.view = self.youpaipremoteVideo;
- self.remoteCanvas.view = self.youpaiplocalVideo;
- [self.agoraKit setupLocalVideo:self.localCanvas];
- [self.agoraKit setupRemoteVideo:self.remoteCanvas];
- self.youpaiplocalVideo.hidden = YES;
- }else{
- self.localCanvas.view = self.youpaiplocalVideo;
- self.remoteCanvas.view = self.youpaipremoteVideo;
- [self.agoraKit setupLocalVideo:self.localCanvas];
- [self.agoraKit setupRemoteVideo:self.remoteCanvas];
- self.youpaiplocalVideo.hidden = NO;
- }
- }
- - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOfflineOfUid:(NSUInteger)uid reason:(AgoraUserOfflineReason)reason{
- if (!self.youpaipisHangupCallVideo) {
- [self youpaifvideoEnd:BBCustomSystomNotificationTypeWithWasInterruptedCallVideo];
- [ZCHUDHelper showTitle:[YOUPAIBBCustomSystomNotification youpaifnotificationTitleWithType:BBCustomSystomNotificationTypeWithWasInterruptedCallVideo]];
- }
- }
- - (void)rtcEngine:(AgoraRtcEngineKit *)engine didAudioRouteChanged:(AgoraAudioOutputRouting)routing{
- // [ZCHUDHelper showTitle:[NSString stringWithFormat:@"音频路由已切换%d",routing]];
- }
- //踢人 v1.1.1
- //- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine connectionChangedToState:(AgoraConnectionStateType)state reason:(AgoraConnectionChangedReason)reason
- //{
- // if(reason ==3)
- // {
- // NSLog(@"收到踢人消息");
- // // [self youpaifvideoEnd:5];
- // }
- //}
- #pragma mark - Agora Video Source Protocol
- - (BOOL)shouldInitialize {
- return YES;
- }
- - (void)shouldStart {
- [self.youpaipmCamera startCapture];
- }
- - (void)shouldStop {
- [self.youpaipmCamera stopCapture];
- }
- - (void)shouldDispose {
- }
- //
- //
- //- (AgoraVideoBufferType)bufferType {
- // return AgoraVideoBufferTypePixelBuffer;
- //}
- //- (AgoraVideoCaptureType)captureType{
- // return AgoraVideoCaptureTypeCamera;
- //}
- #pragma mark - FUCameraDelegate
- bool lzIsNeeded = YES;
- -(void)didOutputVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer {
- if (lzIsNeeded) {
- lzIsNeeded = !lzIsNeeded;
- return;
- }
- lzIsNeeded = !lzIsNeeded;
- // CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
- CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer) ;
- CVPixelBufferLockBaseAddress(pixelBuffer, 0);
- // CFAbsoluteTime startRenderTime = CFAbsoluteTimeGetCurrent();
- //render the items to pixelbuffer
- [_mPixelFree processWithBuffer:pixelBuffer rotationMode:PFRotationMode0];
- // CFAbsoluteTime renderTime = (CFAbsoluteTimeGetCurrent() - startRenderTime);
- //
- //
- // CFAbsoluteTime frameTime = (CFAbsoluteTimeGetCurrent() - startTime);
- //
- // int frameWidth = (int)CVPixelBufferGetWidth(pixelBuffer);
- // int frameHeight = (int)CVPixelBufferGetHeight(pixelBuffer);
- CGSize frameSize;
- if (CVPixelBufferGetPixelFormatType(pixelBuffer) == kCVPixelFormatType_32BGRA) {
- frameSize = CGSizeMake(CVPixelBufferGetBytesPerRow(pixelBuffer) / 4, CVPixelBufferGetHeight(pixelBuffer));
- }else{
- frameSize = CGSizeMake(CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer));
- }
- // push video frame to agora
- // [self.consumer consumePixelBuffer:pixelBuffer withTimestamp:CMSampleBufferGetPresentationTimeStamp(sampleBuffer) rotation:AgoraVideoRotationNone];
- CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
- }
- #pragma mark - WebSocketDelegate
- - (void)youpaifrequestSuccess{
- }
- - (void)youpaifresponseConnent{
- }
- - (void)youpaifresponseChoosing:(NSString*)tip{
- }
- //add by leo 剩余可通话时间
- - (void)youpaifcanCallTime:(NSString*)tip
- {
- }
- //v1.1.1断连重连
- - (void)youpaifvideoStart{
- [self.youpaipplayer stop];
- // self.videoModel.duration = [dict[@"duration"] integerValue];
- //是否主叫
- BOOL callfrom = [[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqualToString:self.youpaipvideoModel.youpaipfrom_uid];
- if (self.youpaipvideoModel.youpaipporn_check_v2.youpaipis_open&&(self.youpaipvideoModel.youpaipporn_check_v2.youpaipcheck_from_user||callfrom)) {
- NSLog(@"鉴黄已打开");
- [YOUPAIXLVideoShotTool sharedPusher].shotCycle = self.youpaipvideoModel.youpaipporn_check_v2.youpaipinterval_time;
- [YOUPAIXLVideoShotTool sharedPusher].periodArray = self.youpaipvideoModel.youpaipporn_check_v2.youpaipperiod_array;
- // [YOUPAIAGVideoProcessing registerVideoPreprocessing:self.agoraKit];
- //老版本
- /*
- [YOUPAIXLVideoShotTool sharedPusher].shotCycle = self.videoModel.porn_check.interval_time;
- [YOUPAIXLVideoShotTool sharedPusher].period = self.videoModel.porn_check.period;
- */
- [YOUPAIXLVideoShotTool sharedPusher].room_id = self.youpaipvideoModel.youpaiproom_id;
- [YOUPAIXLVideoShotTool sharedPusher].localVideo = self.youpaiplocalVideo;
- [YOUPAIXLVideoShotTool sharedPusher].remoteVideo = self.youpaipremoteVideo;
- [YOUPAIXLVideoShotTool sharedPusher].isPornCheckOpen = YES;
- if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqualToString:self.youpaipvideoModel.youpaipfrom_uid]) {//自己是被叫端
- [YOUPAIXLVideoShotTool sharedPusher].isFrom = YES;
- [YOUPAIXLVideoShotTool sharedPusher].uid = self.youpaipvideoModel.youpaipto_uid;
- }else{
- [YOUPAIXLVideoShotTool sharedPusher].isFrom = NO;
- [YOUPAIXLVideoShotTool sharedPusher].uid = self.youpaipvideoModel.youpaipfrom_uid;
- }
- [YOUPAIXLVideoShotTool start];
- }
- //加入声网频道
- //modify by leo fix bug object unrelease
- WeakSelf;
- [self.agoraKit joinChannelByToken:nil channelId:self.youpaipvideoModel.youpaiproom_id info:nil uid:[[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id integerValue] joinSuccess:^(NSString *channel, NSUInteger uid, NSInteger elapsed) {
- if([weakSelf.agoraKit isSpeakerphoneEnabled]){
- [weakSelf.agoraKit setEnableSpeakerphone:YES];
- }
- // self.localVideo.hidden = YES;
- [UIApplication sharedApplication].idleTimerDisabled = YES;
- }];
- }
- //1主动取消 2。拒绝 3.超时 4.被叫者挂断 5.主叫者挂断 6.费用不足
- - (void)youpaifvideoEnd:(NSInteger)type{
- kAppDelegate.ksocketManager = nil;
- [LCSaveData saveIsVideo:NO];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- if (self.timer) {
- dispatch_source_cancel(self.timer);//删除GCD定时器
- self.timer = nil;
- }
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.youpaipmCamera stopCapture];
- dispatch_async(self.youpaipmCamera.videoCaptureQueue, ^{
- });
- [self.agoraKit setExternalVideoSource:YES useTexture:YES sourceType:AgoraExternalVideoSourceTypeVideoFrame]; //只允许外部源
- [self.agoraKit leaveChannel:nil];
- [AgoraRtcEngineKit destroy];
- if (type==11) {
- if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqualToString:self.youpaipvideoModel.youpaipto_uid]){//自己是被叫端
- [self.navigationController dismissViewControllerAnimated:YES completion:^{
- }];
- }else{//自己是主叫端
- [YOUPAIXLVideoShotTool stop];
- [self.navigationController dismissViewControllerAnimated:YES completion:^{
- NSLog(@"1111111");
- }];
- }
- }
- if (type==4|| type==5 || type==6 || type==10) {//去往评价结束界面
- //add by leo 关闭上传截图 定时器
- [YOUPAIXLVideoShotTool stop];
- [self.navigationController dismissViewControllerAnimated:YES completion:^{
- NSLog(@"12121212");
- }];
- }else{
- [self.navigationController dismissViewControllerAnimated:YES completion:^{
- NSLog(@"2222222");
- }];
- }
- });
- }
- - (void)youpaifcloseBtnClick{
- //确定退出视频咨询
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"确定挂断视频通话?" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
- }];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
- self.youpaipisHangupCallVideo = YES;
- [self youpaifvideoEnd:4];
- [YOUPAIBBCustomSystomNotification youpaifcustomSystomNotificationWithModel:self.youpaipvideoModel type:BBCustomSystomNotificationTypeWithHangupCallVideo block:^(NSError * _Nonnull error) {
-
- }];
- [ZCHUDHelper showTitle:@"已挂断"];
- }];
- [alertController addAction:cancelAction];
- [alertController addAction:okAction];
- [self presentViewController:alertController animated:YES completion:nil];
- }
- #pragma mark - interActive
- - (void)youpaiftimeStart{
- //v1.1.1断连重连
- __block int timeout = self.youpaipvideoModel.youpaipduration;
- WeakSelf;
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
- self.timer = timer;
- dispatch_source_set_timer(timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
- dispatch_source_set_event_handler(timer, ^{
- timeout++;
- dispatch_async(dispatch_get_main_queue(), ^{
- weakSelf.youpaiptimeLabel.text =[ZCUtils getMMSSFromSS:timeout];
- kAppDelegate.logCallTime = weakSelf.youpaiptimeLabel.text;
- });
- });
- dispatch_resume(timer);
- }
- - (void)youpaifinterHandel:(UITapGestureRecognizer*)interTap{
- if (interTap.state == UIGestureRecognizerStateEnded) {
- if (interTap.view == self.youpaipinterView) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.view endEditing:YES];
- });
- }else{}
- }
- }
- - (void)youpaifdoubleTapHandel:(UITapGestureRecognizer*)tap{
- if (tap.state == UIGestureRecognizerStateEnded) {
- if (self.youpaipinterView.frame.origin.x == KScreenWidth) {
- [self youpaifmsgViewAnimWithX:0];
- }else{
- [self youpaifmsgViewAnimWithX:KScreenWidth];
- }
- }
- }
- - (void)youpaifmsgViewPanHandel:(UIPanGestureRecognizer*)panGesture{
- //移动两点之间的绝对距离
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.view endEditing:YES];
- });
- CGPoint translation = [panGesture translationInView:self.youpaipinterView];
- if (self.youpaipinterView.frame.origin.x==0 && translation.x<0) {
- }else if(self.youpaipinterView.frame.origin.x==KScreenWidth && translation.x>0){
- }else {
- CGPoint endPosition;
- if (panGesture.state == UIGestureRecognizerStateBegan){
- self.youpaipstartPoint = [panGesture locationInView:self.youpaipinterView];
- }else if (panGesture.state == UIGestureRecognizerStateChanged){
- CGPoint origin = self.youpaipinterView.frame.origin;
- origin.x+=translation.x;
- if (origin.x<=0) {
- origin.x = 0;
- self.youpaipinterView.frame= CGRectMake(origin.x, 0, KScreenWidth, KScreenHeight);
- }else if(origin.x>=KScreenWidth){
- origin.x = KScreenWidth;
- self.youpaipinterView.frame= CGRectMake(origin.x, 0, KScreenWidth, KScreenHeight);
- }
- }else if (panGesture.state == UIGestureRecognizerStateEnded) {
- endPosition = [panGesture locationInView:self.youpaipinterView];
- if (endPosition.x-self.youpaipstartPoint.x>80) {//右移 小动画
- [self youpaifmsgViewAnimWithX:KScreenWidth];
- }else if(endPosition.x-self.youpaipstartPoint.x<-80){ //移
- [self youpaifmsgViewAnimWithX:0];
- }
- }
- }
- }
- - (void)youpaifmsgViewAnimWithX:(CGFloat)x{
- NSTimeInterval durtionTime = fabs(self.youpaipinterView.x-x)*0.5/KScreenWidth;
- [UIView animateWithDuration:durtionTime animations:^{
- self.youpaipinterView.frame = CGRectMake(x, 0, KScreenWidth, KScreenHeight);
- } completion:^(BOOL finished) {
- self.youpaipinterView.frame = CGRectMake(x, 0, KScreenWidth, KScreenHeight);
- }];
- }
- - (void)youpaifloaclVideoHandel:(UITapGestureRecognizer*)localTap{
- if (localTap.state == UIGestureRecognizerStateEnded) {
- if([self.remoteCanvas.view isEqual:self.youpaipremoteVideo]){
- self.remoteCanvas.view = self.youpaiplocalVideo;
- self.localCanvas.view = self.youpaipremoteVideo;
- [self.agoraKit setupLocalVideo:self.localCanvas];
- [self.agoraKit setupRemoteVideo:self.remoteCanvas];
- }else{
- self.remoteCanvas.view = self.youpaipremoteVideo;
- self.localCanvas.view = self.youpaiplocalVideo;
- [self.agoraKit setupLocalVideo:self.localCanvas];
- [self.agoraKit setupRemoteVideo:self.remoteCanvas];
- }
- }
- }
- #pragma mark - ButtonClick
- - (void)youpaifbeautyBtnClick{
- [self.view bringSubviewToFront:self.beautyEditView];
- self.beautyEditView.hidden = NO;
- }
- - (void)youpaifswitchBtnClick:(UIButton*)btn{
- [_youpaipmCamera changeCameraInputDeviceisFront:!_youpaipmCamera.isFrontCamera];
- [self.agoraKit switchCamera];
- }
- - (void)youpaifvoiceBtnClick:(UIButton*)btn{
- if (btn.selected == YES) {
- btn.selected = NO;
- [btn setImage:[UIImage imageNamed:@"vqu_images_video_sound_off"] forState:(UIControlStateNormal)];
- [self.agoraKit disableAudio];
- }else{
- btn.selected = YES;
- [btn setImage:[UIImage imageNamed:@"vqu_images_video_sound_on"] forState:(UIControlStateNormal)];
- [self.agoraKit enableAudio];
- }
- }
- - (void)youpaifcameraBtnClick:(UIButton*)btn{
- if (btn.selected == YES) {
- btn.selected = NO;
- self.localCanvas.view = self.youpaiplocalVideo;
- self.remoteCanvas.view = self.youpaipremoteVideo;
- [self.agoraKit setupLocalVideo:self.localCanvas];
- [self.agoraKit setupRemoteVideo:self.remoteCanvas];
- [btn setImage:[UIImage imageNamed:@"vqu_images_video_on"] forState:(UIControlStateNormal)];
- [self.agoraKit muteLocalVideoStream:YES];
- self.youpaiplocalVideo.hidden = YES;
- }else{
- btn.selected = YES;
- [btn setImage:[UIImage imageNamed:@"vqu_images_video_off"] forState:(UIControlStateNormal)];
- [self.agoraKit muteLocalVideoStream:NO];
- self.youpaiplocalVideo.hidden = NO;
- }
- }
- #pragma mark - 键盘交互事件
- - (void)youpaifwillResignActive {
- [_youpaipmCamera stopCapture];
- }
- - (void)youpaifwillEnterForeground {
- [_youpaipmCamera startCapture];
- if (self.youpaipvoiceBtn.selected == NO) {
- [self.agoraKit enableAudio];
- [self.agoraKit disableAudio];
- }else{
- [self.agoraKit disableAudio];
- [self.agoraKit enableAudio];
- }
- }
- - (void)youpaifdidBecomeActive {
- [_youpaipmCamera startCapture];
- }
- @end
|