Ver código fonte

1.webrtc代码暂存

huangxiaodong 9 meses atrás
pai
commit
355ac96e5e

+ 43 - 42
创维盒子/双子星云手机/webRtc/webRtcManager/webRtcManager.m

@@ -35,8 +35,8 @@
     if (self = [super init]) {
         //[self registeNotification];
         
-        _mediaStream = [[RTC_OBJC_TYPE(AMediaStream) alloc] initWithFrame:CGRectZero];
-        [_mediaStream setEventDelegate:self];
+//        _mediaStream = [[RTC_OBJC_TYPE(AMediaStream) alloc] initWithFrame:CGRectZero];
+//        [_mediaStream setEventDelegate:self];
     }
     return self;
 }
@@ -44,12 +44,28 @@
 #pragma mark 关闭链接
 - (void)closeLinkWebRtcFun
 {
-    [_mediaStream disconnect];
+    KWeakSelf
+    mainBlock(^{
+        [weakSelf.mediaStream disconnect];
+    });
+    
 }
 
 #pragma mark 开始链接
 - (void)beginToLinkWebRtcFun
 {
+    KWeakSelf
+    mainBlock(^{
+        [weakSelf secondBeginToLinkWebRtcFun];
+    });
+}
+
+- (void)secondBeginToLinkWebRtcFun
+{
+    
+    _mediaStream = [[RTC_OBJC_TYPE(AMediaStream) alloc] initWithFrame:CGRectZero];
+    [_mediaStream setEventDelegate:self];
+    
     if(ksharedAppDelegate.isWebSockLinkOKAginType
        || !ksharedAppDelegate.DeviceWebRtcMsgMod){
         return;
@@ -70,31 +86,17 @@
         [ice setValue:iceUrl forKey:@"CMNET"];
         [ice setValue:iceUrl forKey:@"UNICOM"];
     }
-   
-    NSString *roomName = _webRtcMsgMod.data.uniqueIdentifier;
     
+    NSString *roomName = _webRtcMsgMod.data.uniqueIdentifier;
     
     NSInteger result = [_mediaStream startUploadChannel:url ice:ice sn:roomName token:@"vclusters"];
     
-//    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)
     [_mediaStream setShouldGetStats:YES];
 }
 
 - (void)relinkWebRtcFun{
+    ksharedAppDelegate.isWebSockLinkOKAginType = NO;
     [self beginToLinkWebRtcFun];
 }
 
@@ -811,29 +813,28 @@
 -(void)onChangeConnectionStateFromPeerName:(NSString*)peerName didChangeIceConnectionState:(RTCIceConnectionState)state
 {
     HLog(@"channel P2P onChangeConnectionStateFromPeerName: state:%ld",state)
-//    switch (state) {
-//        case RTCIceConnectionStateConnected:{
-//            //链接成功
-//            [self handlAllMsgAfterDidLinkFun];
-//        }
-//            break;
-//        case RTCIceConnectionStateCompleted:
-//            //链接完成
-//            break;
-//        case RTCIceConnectionStateFailed:
-//            //链接失败
-//            break;
-//        case RTCIceConnectionStateDisconnected:
-//            //链接断开
-//            [self relinkWebRtcFun];
-//            break;
-//        case RTCIceConnectionStateClosed:
-//            //链接关闭
-//            break;
-//            
-//        default:
-//            break;
-//    }
+    switch (state) {
+        case RTCIceConnectionStateConnected:{
+            //链接成功
+        }
+            break;
+        case RTCIceConnectionStateCompleted:
+            //链接完成
+            break;
+        case RTCIceConnectionStateFailed:
+            //链接失败
+            break;
+        case RTCIceConnectionStateDisconnected:
+            //链接断开
+            [self relinkWebRtcFun];
+            break;
+        case RTCIceConnectionStateClosed:
+            //链接关闭
+            break;
+            
+        default:
+            break;
+    }
     
 }
 

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

@@ -85,9 +85,15 @@
 #pragma mark 开始拉流
 - (void)beginWebRtcPlayFun
 {
+    if(_mediaStream){
+        //[_mediaStream disconnect];
+        //[_mediaStream removeFromSuperview];
+        //_mediaStream = nil;
+    }
     _mediaStream = [[RTC_OBJC_TYPE(AMediaStream) alloc] initWithFrame:CGRectZero];
     [_mediaStream setEventDelegate:self];
     [self.view addSubview:_mediaStream];
+    HLog(@"_mediaStream:%@",_mediaStream)
     
     [_mediaStream mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.mas_equalTo(0.f);
@@ -168,19 +174,26 @@
         [weakSelf showNewIndicatorWithCanBack:YES canTouch:NO];
         
         //判断是否是全屏
-        BOOL fullscreenType = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
-        CGSize  phoneSize = CGSizeMake(1080.0, 1920.0);
-        if(fullscreenType){
-            phoneSize = [RCCommandHelp commondToSetFullScreenPhoneSizeBySize];
-        }
+//        BOOL fullscreenType = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
+//        CGSize  phoneSize = CGSizeMake(1080.0, 1920.0);
+//        if(fullscreenType){
+//            phoneSize = [RCCommandHelp commondToSetFullScreenPhoneSizeBySize];
+//        }
+//        
+//        [weakSelf linkWebRtcFunWithSize:phoneSize];
         
-        [weakSelf linkWebRtcFunWithSize:phoneSize];
+        [weakSelf beginWebRtcPlayFun];
     });
 }
 
 #pragma mark 初始化其他UI
 - (void)initBaseUIFun
 {
+    if(_bottomContrView){
+        [_bottomContrView removeFromSuperview];
+        _bottomContrView = nil;
+    }
+    
     _bottomContrView = [[webRtcPlayerBottomContrView alloc] init];
     [self.view addSubview:_bottomContrView];
     [self getPlayerBottomNavShowOrHidefun];
@@ -190,6 +203,10 @@
     };
     
     /*控制按钮*/
+    if(controlBtn){
+        [controlBtn removeFromSuperview];
+        controlBtn = nil;
+    }
     UIImage  *driftBtnImage = [UIImage imageNamed:@"you_icon"];
     controlBtn = [[UIButton alloc] init];
     [controlBtn setBackgroundColor:[UIColor clearColor]];
@@ -344,6 +361,8 @@
     [self pauseStream];
     
     [webRtcManager shareManager].isRebootIngType = YES;
+    
+    [self showNewIndicatorWithCanBack:YES canTouch:NO];
 }
 
 #pragma mark X 秒后检查是否软件重启成功
@@ -749,6 +768,7 @@
 -(void)onFrameResolutionChangedFromPeerName:(NSString*)peerName videoWidth:(int)videoWidth videoHeight:(int)videoHeight rotation:(int)rotation {
     HLog(@"推拉流 onFrameResolutionChangedFromPeerName:%@---%d---%d--%d",peerName,videoWidth,videoHeight,rotation)
     
+    HLog(@"ok _mediaStream:%@",_mediaStream)
     mainBlock(^{
         [self handlUIAfterGetCloudPhoneVideoWidth:videoWidth videoHeight:videoHeight rotation:rotation];
     });