Bläddra i källkod

1.丢包率显示

huangxiaodong 11 månader sedan
förälder
incheckning
f254b8b9a6

+ 10 - 4
创维盒子/双子星云手机/CloudPlayer/View/imageVersionRenewTipView.m

@@ -64,6 +64,8 @@
     }];
     
     NSString *curTip1Str = NSLocalizedString(@"image_version_pop_144_tip1",nil);
+    NSString *curTipRedStr = NSLocalizedString(@"image_version_pop_144_tip1_2",nil);
+    
     _tip1Lab = [[UILabel alloc] init];
     //_tip1Lab.text = curTip1Str;
     _tip1Lab.numberOfLines = 0;
@@ -73,14 +75,18 @@
     [_whiteBgView addSubview:_tip1Lab];
     //_tip1Lab.backgroundColor = [UIColor greenColor];
     
-    NSMutableAttributedString *totalStr = [[NSMutableAttributedString alloc] initWithString:curTip1Str];
-    
+    NSString *fullTitle = [[NSString alloc] initWithFormat:@"%@%@",curTip1Str,curTipRedStr];
+    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:fullTitle];
+    NSRange rightRange = NSMakeRange([fullTitle rangeOfString:curTipRedStr].location, curTipRedStr.length);
+    UIColor *rightColor =[UIColor hwColor:@"#FF2828" alpha:1.0];
+    [attrStr addAttribute:NSForegroundColorAttributeName value:rightColor range:rightRange];
+
     // 设置行间距
     NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
     [paragraphStyle setLineSpacing:5];        //设置行间距
-    [totalStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr  length])];
+    [attrStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [fullTitle  length])];
     
-    _tip1Lab.attributedText = totalStr;
+    _tip1Lab.attributedText = attrStr;
     
     
     [_tip1Lab mas_makeConstraints:^(MASConstraintMaker *make) {

+ 42 - 31
创维盒子/双子星云手机/CloudPlayer/View/playerSetView.m

@@ -122,19 +122,21 @@
 //        make.top.mas_equalTo(laberTop);
 //    }];
 //    
-//    _PacketLossLabel =  [[UILabel alloc] init];
-//    _PacketLossLabel.font = [UIFont systemFontOfSize:12.0];
-//    _PacketLossLabel.textColor = [UIColor hwColor:@"#FF2855"];
-//    //_PacketLossLabel.text = NSLocalizedString(@"webrtc_msg_delayed",nil);
-//    [blackBgView addSubview:_PacketLossLabel];
-//    //_PacketLossLabel.backgroundColor = [UIColor redColor];
-//    
-//    [_PacketLossLabel mas_makeConstraints:^(MASConstraintMaker *make) {
-//        make.left.mas_equalTo(PacketLossTipLabel.mas_right).offset(0);
-//        make.width.mas_equalTo(laberW+5);
-//        make.height.mas_equalTo(laberH);
-//        make.top.mas_equalTo(laberTop);
-//    }];
+    _PacketLossLabel =  [[UILabel alloc] init];
+    _PacketLossLabel.font = [UIFont systemFontOfSize:12.0];
+    _PacketLossLabel.textAlignment = NSTextAlignmentCenter;
+    _PacketLossLabel.textColor = [UIColor whiteColor];//[UIColor hwColor:@"#FF2855"];
+    //_PacketLossLabel.text = NSLocalizedString(@"webrtc_msg_delayed",nil);
+    [_blackBgView addSubview:_PacketLossLabel];
+    //_PacketLossLabel.backgroundColor = [UIColor redColor];
+    
+    [_PacketLossLabel mas_makeConstraints:^(MASConstraintMaker *make) {
+        //make.left.mas_equalTo(PacketLossTipLabel.mas_right).offset(0);
+        make.centerX.mas_equalTo(self.mas_centerX);
+        make.width.mas_equalTo(laberW*3.0);
+        make.height.mas_equalTo(laberH);
+        make.top.mas_equalTo(laberTop);
+    }];
 
     //带宽
 //    UILabel * speedLossTipLabel =  [[UILabel alloc] init];
@@ -154,14 +156,15 @@
     _speedLabel =  [[UILabel alloc] init];
     _speedLabel.font = [UIFont systemFontOfSize:12.0];
     _speedLabel.textColor = [UIColor whiteColor];
-    _speedLabel.textAlignment = NSTextAlignmentCenter;
+    _speedLabel.textAlignment = NSTextAlignmentRight;
     //_speedLabel.text = NSLocalizedString(@"webrtc_msg_delayed",nil);
     [_blackBgView addSubview:_speedLabel];
     //_speedLabel.backgroundColor = [UIColor redColor];
     
     [_speedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
         //make.centerX.mas_equalTo(1.5*laberW);
-        make.centerX.mas_equalTo(self.mas_centerX);
+        //make.centerX.mas_equalTo(self.mas_centerX);
+        make.right.mas_equalTo(-15);
         make.width.mas_equalTo(laberW*3.0);
         make.height.mas_equalTo(laberH);
         make.top.mas_equalTo(laberTop);
@@ -182,20 +185,20 @@
 //        make.top.mas_equalTo(laberTop);
 //    }];
     
-    _fpsLabel =  [[UILabel alloc] init];
-    _fpsLabel.textAlignment = NSTextAlignmentRight;
-    _fpsLabel.font = [UIFont systemFontOfSize:12.0];
-    _fpsLabel.textColor = [UIColor whiteColor];
-    //_fpsLabel.text = NSLocalizedString(@"webrtc_msg_delayed",nil);
-    [_blackBgView addSubview:_fpsLabel];
-    //_fpsLabel.backgroundColor = [UIColor redColor];
-    
-    [_fpsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
-        make.right.mas_equalTo(-15);
-        make.width.mas_equalTo(laberW*2);
-        make.height.mas_equalTo(laberH);
-        make.top.mas_equalTo(laberTop);
-    }];
+    //_fpsLabel =  [[UILabel alloc] init];
+//    _fpsLabel.textAlignment = NSTextAlignmentRight;
+//    _fpsLabel.font = [UIFont systemFontOfSize:12.0];
+//    _fpsLabel.textColor = [UIColor whiteColor];
+//    //_fpsLabel.text = NSLocalizedString(@"webrtc_msg_delayed",nil);
+//    [_blackBgView addSubview:_fpsLabel];
+//    //_fpsLabel.backgroundColor = [UIColor redColor];
+//    
+//    [_fpsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
+//        make.right.mas_equalTo(-15);
+//        make.width.mas_equalTo(laberW*2);
+//        make.height.mas_equalTo(laberH);
+//        make.top.mas_equalTo(laberTop);
+//    }];
     
     [self setWebRctMsgBydelayed:0 withPacketLoss:@"-" withSpeed:@"-" withFPS:@"-"];
     
@@ -591,9 +594,17 @@
         _delayedLabel.text = [[NSString alloc] initWithFormat:@"%ldms",delayedMS];
     }
     
-    //_PacketLossLabel.text = PacketLossStr;
+    NSString*LossleftStr = NSLocalizedString(@"webrtc_msg_PacketLoss",nil);
+    NSString*LossRightStr = PacketLossStr;
+    NSString *LossfullTitle = [[NSString alloc] initWithFormat:@"%@%@",LossleftStr,LossRightStr];
+    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:LossfullTitle];
+    NSRange rightRange = NSMakeRange([LossfullTitle rangeOfString:LossRightStr].location, LossRightStr.length);
+    UIColor *rightColor =[UIColor hwColor:@"#FF2855" alpha:1.0];
+    [attrStr addAttribute:NSForegroundColorAttributeName value:rightColor range:rightRange];
+    _PacketLossLabel.attributedText = attrStr;
+    
     _speedLabel.text = [[NSString alloc] initWithFormat:@"%@%@",NSLocalizedString(@"webrtc_msg_speed",nil),speedStr];
-    _fpsLabel.text = [[NSString alloc] initWithFormat:@"FPS:%@",fpsStr];
+    //_fpsLabel.text = [[NSString alloc] initWithFormat:@"FPS:%@",fpsStr];
 }
 
 #pragma mark 设置分辨率

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

@@ -22,6 +22,9 @@
     long lasPacketsReceived;
     //记录上次 总丢包数据
     long lastAlllostData;
+    //记录上次 丢包率
+    long prelostRate;
+    double prelostTimestamp;//计算丢包率时间戳(X秒算一次)
     
     BOOL isExitType;//退出云机
     
@@ -1186,9 +1189,7 @@
         _didReportWebRtcFailType = NO;//链接成功后 失败要重新上报
     }
     
-    NSString *selectedCandidatePairId = nil;
-    NSString *localCandidateId  = nil;
-    NSString *remoteCandidateId = nil;
+    //NSString *selectedCandidatePairId = nil;
     /*延时数据*/
     NSNumber *currentRoundTripTime = nil;
     
@@ -1227,30 +1228,12 @@
                 
                 preReceive = (diffReceive / diffTime) * 1000000;
                 
-                //HLog(@"传输数据速度---->%ld",preReceive);
-                
-//                mainBlock((^{
-//                    if (self->mPlayerView.upControlView.hidden == NO){
-//                        NSString *str = [NSString stringWithFormat:@"清晰度 %ldk/s",preReceive/1024];
-//                        NSMutableAttributedString *underAttr = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName:[UIColor hwColor:@"#FFFFFF"]}];
-//                        [underAttr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} range:NSMakeRange(0, str.length - 2)];
-//                        [underAttr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10]} range:NSMakeRange(str.length - 2,2)];
-//                        [self->mPlayerView.upControlView.articulationBtn setAttributedTitle:underAttr forState:(UIControlStateNormal)];
-//                    }else{
-//                        NSString *str = [NSString stringWithFormat:@"%ldk/s",preReceive/1024];
-//                        NSMutableAttributedString *underAttr = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName:[UIColor hwColor:@"#FFFFFF"]}];
-//                        [underAttr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} range:NSMakeRange(0, str.length - 2)];
-//                        [underAttr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10]} range:NSMakeRange(str.length - 2,2)];
-//                        [self->mPlayerView.controlBtn setAttributedTitle:underAttr forState:(UIControlStateNormal)];
-//                    }
-//                }));
             }else{
                 lastTimestamp = timestamp;
                 lastBytesReceived = bytesReceived;
             }
             
-            selectedCandidatePairId = (NSString *)[rtcStatistics.values objectForKey:@"selectedCandidatePairId"];
-            //HLog(@"三网数据--selectedCandidatePairId-->%@",selectedCandidatePairId);
+            //selectedCandidatePairId = (NSString *)[rtcStatistics.values objectForKey:@"selectedCandidatePairId"];
         }
         
         /*丢包数据*/
@@ -1282,125 +1265,53 @@
         }
     }
 
-    //netWorkInfoLabel 网络信息 测试用
-    
-    if (selectedCandidatePairId) {
-        for (NSString *key in [stats.statistics allKeys]) {
-            RTCStatistics *rtcStatistics = [stats.statistics objectForKey:key];
-            if ([rtcStatistics.type isEqualToString:@"candidate-pair"]){
-                NSString *tempselectedCandidatePairId = rtcStatistics.id;
-                if ([tempselectedCandidatePairId isEqualToString:selectedCandidatePairId]) {
-                    localCandidateId  = (NSString *)[rtcStatistics.values objectForKey:@"localCandidateId"];
-                    remoteCandidateId = (NSString *)[rtcStatistics.values objectForKey:@"remoteCandidateId"];
 
-//                    HLog(@"三网数据--localCandidateId-->%@",localCandidateId);
-//                    HLog(@"三网数据--remoteCandidateId-->%@",remoteCandidateId);
-                }
-            }
-        }
-    }
-
-    NSString *remoteCandidateStr = nil;
-    NSString *localCandidateStr  = nil;
-    if (localCandidateId && remoteCandidateId) {
-        for (NSString *key in [stats.statistics allKeys]) {
-            RTCStatistics *rtcStatistics = [stats.statistics objectForKey:key];
-            if ([rtcStatistics.type isEqualToString:@"local-candidate"]){
-                NSString *templocalCandidateId = rtcStatistics.id;
-                if ([templocalCandidateId isEqualToString:localCandidateId]) {
-                    //HLog(@"三网数据--localCandidateIdInfo-->%@",rtcStatistics.values);
-                    localCandidateStr = @"本地\n";
-                    NSString *candidateType = (NSString *)[rtcStatistics.values objectForKey:@"candidateType"];
-                    if (candidateType) {
-                        localCandidateStr = [localCandidateStr stringByAppendingString:[NSString stringWithFormat:@"candidateType:%@",candidateType]];
-                        localCandidateStr = [localCandidateStr stringByAppendingString:@"\n"];
-                    }
-                    NSString *address = (NSString *)[rtcStatistics.values objectForKey:@"address"];
-                    if (address) {
-                        localCandidateStr = [localCandidateStr stringByAppendingString:[NSString stringWithFormat:@"address:%@",address]];
-                        localCandidateStr = [localCandidateStr stringByAppendingString:@"\n"];
-                    }
-                    NSString *ip = (NSString *)[rtcStatistics.values objectForKey:@"ip"];
-                    if (ip) {
-                        localCandidateStr = [localCandidateStr stringByAppendingString:[NSString stringWithFormat:@"ip:%@",ip]];
-                        localCandidateStr = [localCandidateStr stringByAppendingString:@"\n"];
-                    }
-                    NSString *relatedAddress = (NSString *)[rtcStatistics.values objectForKey:@"relatedAddress"];
-                    if (relatedAddress) {
-                        localCandidateStr = [localCandidateStr stringByAppendingString:[NSString stringWithFormat:@"relatedAddress:%@",relatedAddress]];
-                        localCandidateStr = [localCandidateStr stringByAppendingString:@"\n"];
-                    }
-                }
-            }else if ([rtcStatistics.type isEqualToString:@"remote-candidate"]){
-                NSString *tempRemoteCandidateId = rtcStatistics.id;
-                if ([tempRemoteCandidateId isEqualToString:remoteCandidateId]) {
-                    //HLog(@"三网数据--remoteCandidateIdInfo-->%@",rtcStatistics.values);
-                    remoteCandidateStr = @"远端\n";
-                    NSString *candidateType = (NSString *)[rtcStatistics.values objectForKey:@"candidateType"];
-                    if (candidateType) {
-                        remoteCandidateStr = [remoteCandidateStr stringByAppendingString:[NSString stringWithFormat:@"candidateType:%@",candidateType]];
-                        remoteCandidateStr = [remoteCandidateStr stringByAppendingString:@"\n"];
-                    }
-                    NSString *address = (NSString *)[rtcStatistics.values objectForKey:@"address"];
-                    if (address) {
-                        remoteCandidateStr = [remoteCandidateStr stringByAppendingString:[NSString stringWithFormat:@"address:%@",address]];
-                        remoteCandidateStr = [remoteCandidateStr stringByAppendingString:@"\n"];
-                    }
-                    NSString *ip = (NSString *)[rtcStatistics.values objectForKey:@"ip"];
-                    if (ip) {
-                        remoteCandidateStr = [remoteCandidateStr stringByAppendingString:[NSString stringWithFormat:@"ip:%@",ip]];
-                        remoteCandidateStr = [remoteCandidateStr stringByAppendingString:@"\n"];
-                    }
-                    NSString *relatedAddress = (NSString *)[rtcStatistics.values objectForKey:@"relatedAddress"];
-                    if (relatedAddress) {
-                        remoteCandidateStr = [remoteCandidateStr stringByAppendingString:[NSString stringWithFormat:@"relatedAddress:%@",relatedAddress]];
-                        remoteCandidateStr = [remoteCandidateStr stringByAppendingString:@"\n"];
-                    }
-                }
-            }
-        }
-    }
-
-//    NSString *showStr = @"";
-//    if (localCandidateStr) {
-//        showStr = [showStr stringByAppendingString:localCandidateStr];
-//    }
-//    if (remoteCandidateStr) {
-//        showStr = [showStr stringByAppendingString:remoteCandidateStr];
-//    }
-    
+  
     //网络延迟, 丢包率,FPS,网速 分辨率   流量
     //延时数据
     NSInteger delayedMS = (NSInteger)(currentRoundTripTime.floatValue*1000);
-//    NSString*currentRoundTripTimeStr = [[NSString alloc] initWithFormat:@"延时:%ldms\n",delayedMS];
-//    showStr = [showStr stringByAppendingString:currentRoundTripTimeStr];
     
     //计算上次报道到这一次的丢包率---------界面展示百分比丢包率
-    long allPacketsReceived = packetsReceived - lasPacketsReceived;
-    alllostData = audiolostData + videolostData;
+    double curlostTimestamp = [iTools getNowTimeStamp];
+    
+    if(prelostTimestamp == 0 || (curlostTimestamp - prelostTimestamp >= 3)){
+        
+        long allPacketsReceived = packetsReceived - lasPacketsReceived;
+        
+        if(allPacketsReceived < 0){//异常处理
+            lastAlllostData = 0;
+            lasPacketsReceived = 0;
+            prelostRate = 0;
+        }
+        else{
+            alllostData = audiolostData + videolostData;
+            
+            NSInteger lostRate = ((alllostData - lastAlllostData) *1.0 / (allPacketsReceived + (alllostData - lastAlllostData))) *100;
+              //记录上一次丢包数
+            lastAlllostData = alllostData;
+              //记录上一次接收包数
+            lasPacketsReceived = packetsReceived;
+            
+            prelostRate = lostRate;
+            prelostTimestamp = curlostTimestamp;
+        }
+    }
+    
     
-    NSInteger lostRate = ((alllostData - lastAlllostData) *1.0 / (allPacketsReceived + (alllostData - lastAlllostData))) *100;
-      //记录上一次丢包数
-    lastAlllostData = alllostData;
-      //记录上一次接收包数
-    lasPacketsReceived = packetsReceived;
     
-    NSString*lostDataStr = [[NSString alloc] initWithFormat:@"%ld%%\n",lostRate];
-    //showStr = [showStr stringByAppendingString:lostDataStr];
+    NSString*lostDataStr = [[NSString alloc] initWithFormat:@"%ld%%",prelostRate];
     
     //FPS
-    NSString*FPSStr = [[NSString alloc] initWithFormat:@"%ld\n",framesPerSecond];
-    //showStr = [showStr stringByAppendingString:FPSStr];
+    NSString*FPSStr = @"";//[[NSString alloc] initWithFormat:@"%ld\n",framesPerSecond];
     
     //网速 传输数据速度
     NSString *netDataSpeedStr = @"";
     if(preReceive/1024.0 > 1024){
-        netDataSpeedStr = [NSString stringWithFormat:@"%.01fMB/S\n",preReceive/1024.0/1024.0];
+        netDataSpeedStr = [NSString stringWithFormat:@"%.01fMB/S",preReceive/1024.0/1024.0];
     }
     else{
-        netDataSpeedStr = [NSString stringWithFormat:@"%ldkB/S\n",preReceive/1024];
+        netDataSpeedStr = [NSString stringWithFormat:@"%ldkB/S",preReceive/1024];
     }
-    //showStr = [showStr stringByAppendingString:netDataSpeedStr];
     
     mainBlock(^{
         if(weakSelf.playerSetV){

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

@@ -640,7 +640,8 @@
 
 //1.4.4
 "cloudPhone_player_set_resolution"   = "分辨率";
-"image_version_pop_144_tip1"   = "盒子设备目前未升级到最新版本,请升级设备。升级可能需要较长时间,请谨慎操作!";
+"image_version_pop_144_tip1"   = "盒子设备目前未升级到最新版本,请尽快升级。此过程可能耗时较长,请耐心等待并谨慎操作!";
+"image_version_pop_144_tip1_2"   = "升级过程中确保盒子与手机网络连接稳定,以避免升级中断。";
 "image_version_pop_144_tip2_1"   = "升级过程需要较长时间,请在此期间不要关闭设备或拔掉电源,否则可能会导致系统损坏。升级完成后,盒子设备会自动重启,电视屏幕上也会显示重启操作,这是正常现象。";
 "image_version_pop_144_tip2_2"   = "如果超过15分钟升级仍未完成,请手动断电重启设备重新升级。若设备未能成功升级至最新版本,请提供设备的序列号(SN)并联系我们的客服团队获取帮助。";
 "image_version_Update_Now"   = "立即更新";