// // IfishP2PVideoPlayView.m // Ifish // // Created by imac on 16/11/11. // Copyright © 2016年 lianxiang. All rights reserved. // #import "IfishP2PVideoPlayView.h" #import "Utils.h" #import "P2PClient.h" #pragma mark - 监控竖屏时,各控件初始化 #define BOTTOM_BAR_HEIGHT (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 95.0:50.0) #define PRESS_LAYOUT_WIDTH_AND_HEIGHT 38 #define CONTROLLER_BTN_COUNT 5 #define PUBLIC_WIDTH_OR_HEIGHT (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 95.0:50.0) #define CONTROLLER_BTN_H_W (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 70.0:40.0) //布防、声音...高度宽度 #define RESOLUTION_BTN_H (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 44.0:30.0) //分辨率按钮高度 #define CONTROLLER_RIGHT_ITEM_WIDTH 70 #define CONTROLLER_RIGHT_ITEM_HEIGHT 40 #define CONTROLLER_LEFT_ITEM_WIDTH 20 #define CONTROLLER_BTN_TAG_HUNGUP 0 #define CONTROLLER_BTN_TAG_SOUND 1 #define CONTROLLER_BTN_TAG_SCREENSHOT 2 #define CONTROLLER_BTN_TAG_PRESS_TALK 3 #define CONTROLLER_BTN_TAG_DEFENCE_LOCK 4 #define CONTROLLER_BTN_TAG_HD 5 #define CONTROLLER_BTN_TAG_SD 6 #define CONTROLLER_BTN_TAG_LD 7 #define CONTROLLER_BTN_TAG_RESOLUTION 8 #define CONTROLLER_LABEL_TAG_HD 10 #define CONTROLLER_LABEL_TAG_SD 11 #define CONTROLLER_LABEL_TAG_LD 12 #define CONTROLLER_BTN_TAG_GPIO1_0 13 //lock #define LEFTVIEW_WIDTH (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 88:88) #define LEFTVIEW_HEIGHT (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 120:120) #define CUSTOM_BORDER_BUTTON_WIDTH 20 #define CUSTOM_BORDER_BUTTON_HEIGHT 45 #define LEFT_BAR_BTN_WIDTH (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 90:60) #define LEFT_BAR_BTN_MARGIN (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 15:10) #define LOADINGPRESSVIEW_WIDTH_HEIGHT (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 50:80) @implementation IfishP2PVideoPlayView // 快速创建View的方法 + (instancetype)videoPlayView { return [[[NSBundle mainBundle] loadNibNamed:@"IfishP2PVideoPlayView" owner:nil options:nil] firstObject]; } -(void)awakeFromNib{ [super awakeFromNib]; [self connectDevice]; self.isShowControllerBar = YES; self.isVideoModeHD = NO; _isReject=YES; _isStop = NO; _isOkFirstRenderVideoFrame = YES; //监控竖屏时,各控件初始化(先) [self initComponentForPortrait]; //监控横屏时,各控件初始化(后) [self initComponentForHorizontalScreen]; [self cameraConnectSeting]; } -(void)cameraConnectSeting{ //rtsp监控界面弹出修改 [self monitorP2PCall]; //设置代理 [[P2PClient sharedClient] setDelegate:self]; [self hiddenMonitoringUI:NO callErrorInfo:nil isReCall:YES]; } //rtsp监控界面弹出修改 -(void)monitorP2PCall{ NSString *newPassword = GIWEI_INITPASS; NSString *cameraPass = [Utils GetTreatedPassword:newPassword]; NSString *cameraId = @"3573889"; [[P2PClient sharedClient] p2pCallWithId:cameraId password:cameraPass callType:P2PCALL_TYPE_MONITOR]; // [[P2PClient sharedClient] p2pCallWithId:self.contact.cameraId password:self.contact.cameraPass callType:P2PCALL_TYPE_MONITOR]; [[P2PClient sharedClient] setP2pCallState:P2PCALL_STATUS_CALLING]; BOOL isBCalled = [[P2PClient sharedClient] isBCalled]; P2PCallType type = [[P2PClient sharedClient] p2pCallType]; NSString *callId = [[P2PClient sharedClient] callId]; if(!isBCalled){ BOOL isApMode = ([[AppDelegate sharedDefault]dwApContactID] != 0); if (!isApMode) { //[[P2PClient sharedClient] p2pCallWithId:callId password:self.contact.cameraPass callType:type]; [[P2PClient sharedClient] p2pCallWithId:callId password:cameraPass callType:type]; } else { //[[P2PClient sharedClient] p2pCallWithId:@"1" password:self.contact.cameraPass callType:type]; [[P2PClient sharedClient] p2pCallWithId:@"1" password:cameraPass callType:type]; } } } -(void)initComponentForPortrait{ //视频监控连接中的背景图片 NSString *filePath = [Utils getHeaderFilePathWithId:self.contact.cameraId]; UIImage *headImg = [UIImage imageWithContentsOfFile:filePath]; if(headImg==nil){ headImg = LXImageWithImageName(@"ic_header.png"); } self.canvasView.layer.contents = (id)headImg.CGImage; _yProgressView.backgroundView.image = LXImageWithImageName(@"monitor_press.png"); [_yProgressView start]; self.remoteView.delegate= self; [self.remoteView.layer setMasksToBounds:YES]; //_remoteView 添加点击手势现实和隐藏 midToolHView UITapGestureRecognizer *appermidToolView=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSingleTap)]; [appermidToolView setCancelsTouchesInView:YES]; [appermidToolView setDelaysTouchesEnded:YES]; [self.canvasView addGestureRecognizer:appermidToolView]; } #pragma mark - 监控横屏时,各控件初始化 -(void)initComponentForHorizontalScreen{ CGRect rect = [AppDelegate getScreenSize:NO isHorizontal:YES]; CGFloat width = rect.size.width; _monitorInterfaceW = width; CGFloat height = rect.size.height; if(CURRENT_VERSION<7.0){ height +=20; } _monitorInterfaceH = height; _horizontalScreenH = height; // //横屏背景 UIView *fullScreenBgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, height)]; fullScreenBgView.backgroundColor = XBlack; self.fullScreenBgView = fullScreenBgView; //进入横屏时,响应onDoubleTap //退出横屏时,响应onDoubleTap 暂停 UITapGestureRecognizer *doubleTapG = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onDoubleTap)]; doubleTapG.delegate = self; [doubleTapG setNumberOfTapsRequired:2]; [self.remoteView addGestureRecognizer:doubleTapG]; //进入横屏时,响应onSingleTap //退出横屏时,响应onSingleTap UITapGestureRecognizer *singleTapG = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSingleTap)]; singleTapG.delegate = self; [singleTapG setNumberOfTapsRequired:1]; [singleTapG requireGestureRecognizerToFail:doubleTapG]; [self.remoteView addGestureRecognizer:singleTapG]; //进入横屏时,响应localLengthPinchToZoom //退出横屏时,不响应localLengthPinchToZoom NSString * plist = [[NSBundle mainBundle] pathForResource:@"Common-Configuration" ofType:@"plist"]; NSDictionary * dic = [NSDictionary dictionaryWithContentsOfFile:plist]; BOOL isSupportZoom = [dic[@"isSupportZoom"] boolValue]; UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] init]; if (!isSupportZoom) {//电子放大与焦距变倍不共存 [_remoteView addGestureRecognizer:pinchGestureRecognizer]; } self.pinchGestureRecognizer = pinchGestureRecognizer; //右边的画质图标 //进入横屏时,显示 //退出横屏时,隐藏 int rightItemCount = 3; //半透明背景 UIView *controllerRightBg = [[UIView alloc] initWithFrame:CGRectMake(5.0, height, CONTROLLER_RIGHT_ITEM_WIDTH, CONTROLLER_RIGHT_ITEM_HEIGHT*rightItemCount)]; controllerRightBg.layer.cornerRadius = 1.0f; [controllerRightBg setAlpha:0.5]; [controllerRightBg setBackgroundColor:XBlack]; self.controllerRightBg = controllerRightBg; [self addSubview:controllerRightBg]; [self.controllerRightBg setHidden:YES]; UIView *controllerRight = [[UIView alloc] initWithFrame:CGRectMake(5.0, height, CONTROLLER_RIGHT_ITEM_WIDTH, CONTROLLER_RIGHT_ITEM_HEIGHT*rightItemCount)]; self.controllerRight = controllerRight; [self addSubview:controllerRight]; [self.controllerRight setHidden:YES]; //分隔线 for (int i=1; i < rightItemCount; i++) { UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, i*CONTROLLER_RIGHT_ITEM_HEIGHT+1.0*(i-1), CONTROLLER_RIGHT_ITEM_WIDTH, 1.0)]; lineView.backgroundColor = XWhite; [controllerRight addSubview:lineView]; } for(int i=0;i>>你可以看到画面了"]; _isReject = NO; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self renderView]; }); //[[PAIOUnit sharedUnit] setMuteAudio:YES]; // [[PAIOUnit sharedUnit] setSpeckState:YES]; } #pragma mark - 开始渲染监控画面 - (void)renderView { _isPlaying = YES; /* GAVFrame * m_pAVFrame ; while (!self.isReject) { NSLog(@" while 渲染监控画面"); if(fgGetVideoFrameToDisplay(&m_pAVFrame)) { if (!_isOkRenderVideoFrame) { _isOkRenderVideoFrame = YES; _isOkFirstRenderVideoFrame = YES; dispatch_async(dispatch_get_main_queue(), ^{ //隐藏监控连接中的UI [self hiddenMonitoringUI:YES callErrorInfo:nil isReCall:NO]; [self didHiddenMonitorUIWith:YES]; }); //设置默认高清 [self setGaoQingHuoBiaoQing]; } [self.remoteView render:m_pAVFrame]; vReleaseVideoFrame(); } usleep(10000); } _isPlaying = NO; */ } #pragma mark - 设置标清或高清 //由于要隐藏掉 画质选项卡 这里重写方法 设置视频默认高清 或标清 -(void)setGaoQingHuoBiaoQing{ BOOL is16B9 = [[P2PClient sharedClient] is16B9]; BOOL is960P = [[P2PClient sharedClient] is960P]; //右边的画质图标 int rightItemCount = 0; if(is16B9 || is960P){ rightItemCount = 3; }else{ rightItemCount = 2; } //设置高清 if (rightItemCount==3) { [[P2PClient sharedClient] sendCommandType:USR_CMD_VIDEO_CTL andOption:7]; [self updateRightButtonState:CONTROLLER_BTN_TAG_HD]; }else if (rightItemCount == 2){ //设置标清 [[P2PClient sharedClient] sendCommandType:USR_CMD_VIDEO_CTL andOption:5]; [self updateRightButtonState:CONTROLLER_BTN_TAG_SD]; } } #pragma mark - 设置高清、标清选中 -(void)updateRightButtonState:(NSInteger)tag{ for(UIView *view in self.controllerRight.subviews){ UILabel *labelHD = (UILabel *)[view viewWithTag:CONTROLLER_LABEL_TAG_HD]; if (labelHD) { labelHD.textColor = XWhite; } UILabel *labelSD = (UILabel *)[view viewWithTag:CONTROLLER_LABEL_TAG_SD]; if (labelSD) { labelSD.textColor = XWhite; } UILabel *labelLD = (UILabel *)[view viewWithTag:CONTROLLER_LABEL_TAG_LD]; if (labelLD) { labelLD.textColor = XWhite; } } UIButton *button = (UIButton*)[self.controllerRight viewWithTag:tag]; //重新调整监控画面 UIButton *rButton = (UIButton *)[self.bottomBarView viewWithTag:CONTROLLER_BTN_TAG_RESOLUTION]; if (tag == CONTROLLER_BTN_TAG_HD) { UILabel *label = (UILabel *)[button viewWithTag:CONTROLLER_LABEL_TAG_HD]; label.textColor = XBlue; //[rButton setTitle:NSLocalizedString(@"HD", nil) forState:UIControlStateNormal]; [rButton setTitle:NSLocalizedString(@"高清", nil) forState:UIControlStateNormal]; }else if(tag == CONTROLLER_BTN_TAG_SD){ UILabel *label = (UILabel *)[button viewWithTag:CONTROLLER_LABEL_TAG_SD]; label.textColor = XBlue; [rButton setTitle:NSLocalizedString(@"标清", nil) forState:UIControlStateNormal]; //[rButton setTitle:NSLocalizedString(@"SD", nil) forState:UIControlStateNormal]; }else if (tag == CONTROLLER_BTN_TAG_LD){ UILabel *label = (UILabel *)[button viewWithTag:CONTROLLER_LABEL_TAG_LD]; label.textColor = XBlue; [rButton setTitle:NSLocalizedString(@"流畅", nil) forState:UIControlStateNormal]; //[rButton setTitle:NSLocalizedString(@"LD", nil) forState:UIControlStateNormal]; } [self didHiddenResolutionInterface]; } -(void)didHiddenResolutionInterface{ [UIView animateWithDuration:0.2 animations:^{ CGRect controllerRight = self.controllerRight.frame; controllerRight.origin.y = _horizontalScreenH; self.controllerRight.frame = controllerRight; self.controllerRightBg.frame = controllerRight; } completion:^(BOOL finished) { self.isAlreadyShowResolution = NO; }]; } #pragma mark - 隐藏监控连接中的UI -(void)hiddenMonitoringUI:(BOOL)isHidden callErrorInfo:(NSDictionary*)info isReCall:(BOOL)isReCall{ if (isHidden) { [self.yProgressView stop]; [self.yProgressView setHidden:YES]; //连接不上原因文字 暂时不用 // [self.labelTip setHidden:YES]; [self.promptButton setEnabled:NO]; [self.promptButton setHidden:YES]; [self.stopBtnH setEnabled:YES]; }else{ if (isReCall) { self.yProgressView.backgroundView.image = LXImageWithImageName(@"monitor_press.png"); [self.yProgressView start]; // self.labelTip.text = [NSString stringWithFormat:@"%@",NSLocalizedString(@"monitor_out_prompt", nil)]; [self.promptButton setEnabled:NO]; //self.stopImageViewH.image = LXImageWithImageName(@"monitor_stop_h.png"); [self.stopBtnH setBackgroundImage:LXImageWithImageName(@"monitor_stop_h.png") forState:UIControlStateNormal]; // 禁用 底部栏暂停按钮 [self.stopBtnH setEnabled:NO]; }else{ if (_isStop) { //暂停 self.yProgressView.angle = 0.0f; self.yProgressView.backgroundView.image = LXImageWithImageName(@"ifishCamera_start"); //int errorFlag = [[info objectForKey:@"errorFlag"] intValue]; // self.labelTip.text = [self getCallErrorStringWith:errorFlag]; //self.stopImageViewH.image = LXImageWithImageName(@"monitor_on_h.png"); [self.stopBtnH setBackgroundImage:LXImageWithImageName(@"monitor_on_h.png") forState:UIControlStateNormal]; }else{ self.yProgressView.angle = 0.0f; self.yProgressView.backgroundView.image = LXImageWithImageName(@"ifishCamera_start"); //int errorFlag = [[info objectForKey:@"errorFlag"] intValue]; //int errorFlag = CALL_ERROR_HANGUP ; // self.labelTip.text = [self getCallErrorStringWith:errorFlag]; [self.stopBtnH setBackgroundImage:LXImageWithImageName(@"monitor_on_h.png") forState:UIControlStateNormal]; } self.yProgressView.angle = 0.0f; [self.yProgressView stop]; //int errorFlag = [[info objectForKey:@"errorFlag"] intValue]; //self.labelTip.text = [self getCallErrorStringWith:errorFlag]; [self.promptButton setEnabled:YES]; [self.stopBtnH setEnabled:YES]; } [self.yProgressView setHidden:NO]; // [self.labelTip setHidden:NO]; [self.promptButton setHidden:NO]; [self.canvasView bringSubviewToFront:self.promptButton]; } } -(void)didHiddenMonitorUIWith:(BOOL)isAfterRender{ if (!isAfterRender) { [self.controllerRightBg setAlpha:0.0]; [self.controllerRight setAlpha:0.0]; [self.bottomView setAlpha:0.0]; [self.bottomBarView setAlpha:0.0]; [self.customBorderButton setAlpha:0.0]; [self.leftView setAlpha:0.0]; [self.focalLengthView setAlpha:0.0]; [self.pressView setAlpha:0.0]; }else{ [self.controllerRightBg setAlpha:0.5]; [self.controllerRight setAlpha:1.0]; [self.bottomView setAlpha:0.5]; [self.bottomBarView setAlpha:1.0]; [self.customBorderButton setAlpha:0.5]; [self.leftView setAlpha:0.5]; [self.focalLengthView setAlpha:1.0]; [self.pressView setAlpha:1.0]; } } #pragma mark - 点击手势(单击) -(void)onSingleTap { } #pragma mark - openGLViewDelegate -(void)onScreenShotted:(UIImage*)image { } @end