Pārlūkot izejas kodu

1.webrtc 对接出画面

huangxiaodong 10 mēneši atpakaļ
vecāks
revīzija
bc71dfea63

+ 43 - 10
创维盒子/双子星云手机/cloudPhone/cloudPhoneViewController.m

@@ -13,9 +13,11 @@
 #import "DFPlayer.h"
 #import "audioPlayerViewController.h"
 #import "webRtcMsgModel.h"
+#import "webRtcPlayerViewController.h"
 
 @interface cloudPhoneViewController ()
 @property (nonatomic,strong) cloudPhoneSetView *cloudPhoneSetV;
+@property (nonatomic,strong) webRtcMsgModel *webRtcMsgMod;
 @end
 
 @implementation cloudPhoneViewController
@@ -32,7 +34,7 @@
     
     [self drawAnyView];
     
-    [self queryWebRtcMsgFun];
+    [self queryWebRtcMsgFun:NO];
 }
 
 - (void)drawAnyView{
@@ -236,12 +238,14 @@
         {
             //[self checkFullScreenWithTVShowStateFun];
             
-            PlayerViewController *vc = [PlayerViewController new];
-            [self pushViewController:vc animated:YES];
+//            PlayerViewController *vc = [PlayerViewController new];
+//            [self pushViewController:vc animated:YES];
+//            
+//            if(ksharedAppDelegate.TvStatusMod.isTVShowType){
+//                [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
+//            }
             
-            if(ksharedAppDelegate.TvStatusMod.isTVShowType){
-                [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
-            }
+            [self queryWebRtcMsgFun:YES];
             
             //数据埋点
             [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Cloud_enter"];
@@ -444,26 +448,55 @@
 
 
 #pragma mark 获取webrct 的链接信息
--(void)queryWebRtcMsgFun
+-(void)queryWebRtcMsgFun:(BOOL)isPlayerType
 {
+    if(isPlayerType){
+        
+        if(_webRtcMsgMod && _webRtcMsgMod.data.sn){
+            [self gotoWebRtcVcBy:_webRtcMsgMod];
+            return;
+        }
+        
+        [self showNewIndicatorWithCanBack:YES canTouch:NO];
+    }
     
     NSMutableDictionary *paraDict = [NSMutableDictionary new];
 
     KWeakSelf
     [[netWorkManager shareInstance] CommonPostCallBackCode:webrctQueryByClient Parameters:paraDict success:^(id  _Nonnull responseObject){
+        
+        if(isPlayerType){
+            [weakSelf removeNewIndicator];
+        }
+        
         webRtcMsgModel *curModel = [[webRtcMsgModel alloc] initWithDictionary:responseObject error:nil];
         
         if(curModel && curModel.status == 0){
-            
+            weakSelf.webRtcMsgMod = curModel;
+            if(isPlayerType){
+                [weakSelf gotoWebRtcVcBy:curModel];
+            }
         }
         else
         {
-           
+            if(isPlayerType && curModel.msg){
+                [[iToast makeText:curModel.msg] show];
+            }
         }
         
     } failure:^(NSError * _Nonnull error) {
-        //[[iToast makeText:@"扫码信息错误"] show];
+        if(isPlayerType){
+            [weakSelf removeNewIndicator];
+            [[iToast makeText:NSLocalizedString(@"get_webrtcMsg_fail_tip",nil)] show];
+        }
     }];
 }
 
+#pragma mark 跳转webrtc 页面
+-  (void)gotoWebRtcVcBy:(webRtcMsgModel*)webRtcMsgMod
+{
+    webRtcPlayerViewController *vc = [webRtcPlayerViewController new];
+    vc.webRtcMsgMod = webRtcMsgMod;
+    [self.navigationController pushViewController:vc animated:YES];
+}
 @end

+ 2 - 2
创维盒子/双子星云手机/webRtc/model/webRtcMsgModel.h

@@ -9,11 +9,11 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
-@interface webRtcMsgSignallingModel : SuperModel //信令服务对象
+@interface webRtcMsgSignallingModel : SuperModel //信令服务对象 (推流)
 @property (nonatomic, copy) NSString *port;//端口
 @property (nonatomic, copy) NSString *domainName;//地址
 @end
-@interface webRtcMsgTurnModel : SuperModel //turn服务对象
+@interface webRtcMsgTurnModel : SuperModel //turn服务对象 (ice)
 @property (nonatomic, copy) NSString *port;//端口
 @property (nonatomic, copy) NSString *domainName;//地址
 @end

+ 2 - 1
创维盒子/双子星云手机/webRtc/webRtcPlayerViewController.h

@@ -6,10 +6,11 @@
 //
 
 #import "BaseViewController.h"
-
+#import "webRtcMsgModel.h"
 NS_ASSUME_NONNULL_BEGIN
 
 @interface webRtcPlayerViewController : BaseViewController
+@property (nonatomic,strong) webRtcMsgModel * webRtcMsgMod;
 
 @end
 

+ 251 - 2
创维盒子/双子星云手机/webRtc/webRtcPlayerViewController.m

@@ -8,18 +8,267 @@
 #import "webRtcPlayerViewController.h"
 #import <WebRTC/AMediaStream.h>
 #import <WebRTC/RTCMacros.h>
+#import "UIView+View.h"
 
-@interface webRtcPlayerViewController ()
-
+@interface webRtcPlayerViewController ()<MediaStreamClientEventsDelegate>
+@property (nonatomic, strong) AMediaStream *mediaStream;
+@property(nonatomic,strong)UIButton    *controlBtn;
 @end
 
 @implementation webRtcPlayerViewController
+@synthesize controlBtn;
 
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view.
+    
+    [self.toolBar setHidden:YES];
+    [self.navigationBar setHidden:YES];
+    [self.navBarBGView setHidden:YES];
+    [self.view setBackgroundColor:[UIColor blackColor]];
+   
 }
 
+- (void)viewDidDisappear:(BOOL)animated{
+    [super viewDidDisappear:animated];
+    
+    [_mediaStream disconnect];
+}
 
+- (void)setWebRtcMsgMod:(webRtcMsgModel *)webRtcMsgMod
+{
+    _webRtcMsgMod = webRtcMsgMod;
+    [self beginWebRtcPlayFun];
+}
+
+#pragma mark 开始拉流
+- (void)beginWebRtcPlayFun
+{
+    _mediaStream = [[RTC_OBJC_TYPE(AMediaStream) alloc] initWithFrame:CGRectZero];
+    [_mediaStream setEventDelegate:self];
+    [self.view addSubview:_mediaStream];
+    
+    [_mediaStream mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.left.mas_equalTo(0.f);
+        make.bottom.mas_equalTo(0.f);
+        make.right.mas_equalTo(0.f);
+        make.top.mas_equalTo(0.f);
+    }];
+    
+    //链接用
+    NSString *signallingUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.signalling.domainName,_webRtcMsgMod.data.signalling.port];
+    NSURL *url = [NSURL URLWithString:signallingUrl];
+    
+    //ice用
+    NSString *iceUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.turn.domainName,_webRtcMsgMod.data.turn.port];
+    
+    NSMutableDictionary *ice = [NSMutableDictionary new];
+    if(iceUrl){
+        [ice setValue:iceUrl forKey:@"CHINANET"];
+        [ice setValue:iceUrl forKey:@"CMNET"];
+        [ice setValue:iceUrl forKey:@"UNICOM"];
+    }
+   
+    NSString *roomName = _webRtcMsgMod.data.uniqueIdentifier;
+    
+    NSInteger result = [_mediaStream start:url
+                            ice:ice
+                             sn:roomName
+                         direct:0
+                            fmt:1//1(h264) 5(h265)
+                     videoWidth:1080.0
+                    videoHeight:1920.0
+                            fps:30
+                        bitrate:3000
+                      cardWidth:0
+                     cardHeight:0
+                    cardDensity:0
+                          token:@"vclusters"];
+    
+    HLog(@"result:%ld",result)
+    
+    CGFloat curRate = 1080.0/1920.0;
+    [self setPoMas_makeWithImageRate:curRate];
+    [self showNewIndicatorWithCanBack:YES canTouch:NO];
+    
+    [self initBaseUIFun];
+}
 
+#pragma mark 初始化其他UI
+- (void)initBaseUIFun
+{
+    /*控制按钮*/
+    UIImage  *driftBtnImage = [UIImage imageNamed:@"you_icon"];
+    controlBtn = [[UIButton alloc] init];
+    [controlBtn setBackgroundColor:[UIColor clearColor]];
+    [controlBtn setBackgroundImage:driftBtnImage forState:(UIControlStateNormal)];
+    [controlBtn addTarget:self
+                     action:@selector(controlBtnPressed:)
+           forControlEvents:(UIControlEventTouchUpInside)];
+    
+    [self.view addSubview:controlBtn];
+    [self initPointForControlBtnFun];
+}
+
+#pragma mark 设置 controlBtn 的初始位置
+- (void)initPointForControlBtnFun
+{
+    CGFloat h_w_controlBtn = 60.f;
+    /*区分横竖屏*/
+    if (_mediaStream.width > _mediaStream.height){
+        [controlBtn setFrame:CGRectMake((_mediaStream.width - h_w_controlBtn)/2.f, _mediaStream.height - h_w_controlBtn - 20.f, h_w_controlBtn, h_w_controlBtn)];
+    }else{
+        //默认居右
+        //[mPlayerView.controlBtn setFrame:CGRectMake(mPlayerView.width - h_w_controlBtn - 20.f, (SCREEN_H - h_w_controlBtn)/2.f, h_w_controlBtn, h_w_controlBtn)];
+        
+        //默认居左
+        [controlBtn setFrame:CGRectMake( h_w_controlBtn + 10.f, (SCREEN_H - h_w_controlBtn)/2.f, h_w_controlBtn, h_w_controlBtn)];
+    }
+    
+
+}
+
+#pragma mark 控制按钮点击事件
+- (void)controlBtnPressed:(UIButton*)but
+{
+    
+}
+
+#pragma mark WebRTC 回调 MediaStreamClientEventsDelegate
+#pragma mark - 宽高变化
+-(void)onFrameResolutionChangedFromPeerName:(NSString*)peerName videoWidth:(int)videoWidth videoHeight:(int)videoHeight rotation:(int)rotation {
+    HLog(@"peerName:%@---%d---%d--%d",peerName,videoWidth,videoHeight,rotation)
+}
+
+//code 0 成功 1失败
+-(void)onAuthResultFromPeerName:(NSString*)peerName code:(int)code descriptions:(NSString*)descriptions
+{
+    HLog(@"onAuthResultFromPeerName:%@---%d---%@",peerName,code,descriptions)
+}
+
+- (void)dataChannelDidChangeFromPeerName:(NSString*)peerName State:(RTCDataChannelState)state{
+    ;
+}
+
+-(void)onIceConnectedFromPeerName:(NSString*)peerName{
+    HLog(@"onIceConnectedFromPeerName:%@",peerName);
+    mainBlock(^{
+        [self removeNewIndicator];
+    });
+}
+
+
+-(void)didGetStats:(NSString*)peerName stats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats {
+    HLog(@"stats:%@",stats);
+}
+
+- (void)setPoMas_makeWithImageRate:(CGFloat)w_h_rate{
+    /*播放视图*/
+//    touchCommondView.isLan = NO;
+    BOOL fullScreenShow = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
+
+    [_mediaStream mas_remakeConstraints:^(MASConstraintMaker *make) {
+        CGFloat scr_W = SCREEN_W;
+        CGFloat scr_H = SCREEN_H;
+        if (SCREEN_W > SCREEN_H){
+            scr_W = SCREEN_H;
+            scr_H = SCREEN_W;
+        }
+        if ((scr_H - scr_W/w_h_rate - 40.f)/2.f < 0){
+            if(fullScreenShow){
+                make.height.mas_equalTo(scr_H);
+                make.width.mas_equalTo(scr_W);
+            }
+            else{
+                make.height.mas_equalTo(scr_H - 40.f);
+                make.width.mas_equalTo((scr_H - 40.f)*w_h_rate);
+            }
+
+            make.centerX.equalTo(self.view.mas_centerX);
+            make.top.mas_equalTo(0);
+        }
+        else{
+            make.left.mas_equalTo(0.f);
+            make.right.mas_equalTo(0.f);
+            if(fullScreenShow){
+                make.height.mas_equalTo(scr_H);
+                make.top.mas_equalTo(0.f);
+            }
+            else{
+                make.height.mas_equalTo(scr_W/w_h_rate);
+                make.top.mas_equalTo((scr_H - scr_W/w_h_rate - 40.f)/2.f);
+            }
+        }
+    }];
+    
+    
+//    [bottomContrView setHidden:NO];
+//    [bottomContrView mas_remakeConstraints:^(MASConstraintMaker *make) {
+//        make.height.mas_equalTo(40.f);
+//        make.right.equalTo(touchCommondView.mas_right);
+//        if(fullScreenShow){
+//            make.bottom.mas_equalTo(0);
+//        }
+//        else{
+//            make.top.equalTo(touchCommondView.mas_bottom);
+//        }
+//        make.left.equalTo(touchCommondView.mas_left);
+//    }];
+//
+//    [mueBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
+//        make.right.mas_equalTo(-80.f);
+//        make.width.and.height.mas_equalTo(40.f);
+//        make.top.mas_equalTo(0);
+//        
+//    }];
+//
+//    [homeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
+//        make.centerX.equalTo(bottomContrView.mas_centerX);
+//        make.width.and.height.mas_equalTo(40.f);
+//        make.top.mas_equalTo(0);
+//    }];
+//
+//    UIImage  *backBtnImage = [UIImage imageNamed:@"fanhui_you_icon"];
+////        UIImage  *backBtnImage = [UIImage imageNamed:@"fanhui_icon"];
+//    [backBtn setImage:backBtnImage forState:(UIControlStateNormal)];
+//    [backBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
+//        make.left.mas_equalTo(80.f);
+//        make.width.and.height.mas_equalTo(40.f);
+//        make.top.mas_equalTo(0);
+//    }];
+//    
+//    [showHomeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
+//        make.right.mas_equalTo(-20.f);
+//        make.width.and.height.mas_equalTo(40.f);
+//        make.top.mas_equalTo(0);
+//    }];
+//    
+//    [self getPlayerBottomNavShowOrHidefun];
+}
+
+/**
+ * @brief 设置横屏模式UI布局
+ *
+ * @param  w_h_rate 宽高比
+
+ */
+- (void)setLanMas_makeWithImageRate:(CGFloat)w_h_rate{
+    /*需要考虑专业模式*/
+
+    /*暂时只考虑非专业模式无虚拟键布局*/
+    CGFloat h_forPhoneTop = 0;
+    if (IPHONE_X){
+        h_forPhoneTop = 44.f;
+    }
+    CGFloat des_W = SCREEN_W<SCREEN_H?SCREEN_W:SCREEN_H;/*实际较小的数字*/
+    CGFloat des_H = (SCREEN_W>SCREEN_H?SCREEN_W:SCREEN_H) - h_forPhoneTop;/*实际较大的数字*/
+    [_mediaStream mas_remakeConstraints:^(MASConstraintMaker *make) {
+        make.bottom.mas_equalTo(0.f);
+        make.width.mas_equalTo(des_W*w_h_rate);
+        make.left.mas_equalTo(h_forPhoneTop + (des_H - des_W*w_h_rate)/2.f);
+        make.top.mas_equalTo(0);
+    }];
+    
+   
+}
 @end

+ 1 - 0
创维盒子/双子星云手机/zh-Hans.lproj/Localizable.strings

@@ -612,3 +612,4 @@
 "pc_login_ing_tip" = "正在登录中…";
 "pc_login_ok_tip" = "登录成功";
 "pc_login_fail_tip" = "登录失败,请重试";
+"get_webrtcMsg_fail_tip" = "获取云机信息失败";