From dd3214b3780ad25d58da4e0e7f7201dfefc424a7 Mon Sep 17 00:00:00 2001 From: tonychan Date: Tue, 24 Oct 2023 17:07:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E8=AE=BE=E7=BD=AEtcp=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=97=B6=E9=97=B4=EF=BC=8C=E9=BB=98=E8=AE=A45s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie1fb575a26dad4a3383727d8870089e2405fb05c --- Podfile.lock | 8 +++--- .../P2P/Controller/TIoTDemoPreviewDeviceVC.m | 5 ++-- Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h | 3 ++ Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm | 16 ++++++++--- ...07\345\274\225\346\226\207\346\241\243.md" | 28 +++++++++---------- TIoTLinkVideo.podspec | 2 +- 6 files changed, 37 insertions(+), 25 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 153a03c1..2f537897 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -34,12 +34,12 @@ PODS: - TIoTLinkKit_SoundTouch (1.0.0) - TIoTLinkKit_TPNS (1.0.1) - TIoTLinkKit_WechatOpenSDK (1.0.1) - - TIoTLinkKit_XP2P (2.4.38) + - TIoTLinkKit_XP2P (2.4.40) - TIoTLinkVideo (1.0.0): - CocoaAsyncSocket (= 7.6.5) - TIoTLinkKit_FLV (= 2.2.3) - TIoTLinkKit_SoundTouch (= 1.0.0) - - TIoTLinkKit_XP2P (= 2.4.38) + - TIoTLinkKit_XP2P (= 2.4.40) - TPCircularBuffer (= 1.6.1) - TPCircularBuffer (1.6.1) - TrueTime (5.0.3) @@ -129,8 +129,8 @@ SPEC CHECKSUMS: TIoTLinkKit_SoundTouch: cf79ae182b6c2349ff65bac7a338974bc538fa77 TIoTLinkKit_TPNS: 7cea4fc1d20ef6c4c11c4f0b66bbb10ecf4ed968 TIoTLinkKit_WechatOpenSDK: 7822d68cc5c46edf3f6020422202e7b65ea87614 - TIoTLinkKit_XP2P: baa1eff35498ce8fe1bbc80c0ffe9906be27b6b5 - TIoTLinkVideo: 80a20c6e1c527234e974ad1869828ac4147f139e + TIoTLinkKit_XP2P: 5b9690823f2cbc758964d5bc60f8e8e475e76aaa + TIoTLinkVideo: e8522c6c22e7cb93dd3f108d246347e3b226baa1 TPCircularBuffer: c13243556527551c4d320709c7b14a6d20cdc30a TrueTime: b49551ffafb28a9dee04e51b226f42a416010842 TXLiteAVSDK_TRTC: e3383a81565e8bb2aaaaab4bd099ad5239cd5b2d diff --git a/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoPreviewDeviceVC.m b/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoPreviewDeviceVC.m index 492260ce..b47866bb 100644 --- a/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoPreviewDeviceVC.m +++ b/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoPreviewDeviceVC.m @@ -105,7 +105,7 @@ - (void)viewDidLoad { _is_ijkPlayer_stream = YES; //关闭日志 -// [TIoTCoreXP2PBridge sharedInstance].logEnable = NO; + [TIoTCoreXP2PBridge sharedInstance].logEnable = YES; self.navigationController.navigationBar.tintColor = [UIColor blackColor]; self.qualityString = quality_high; @@ -127,7 +127,8 @@ - (void)viewDidLoad { [self setupPreViewViews]; TIoTCoreAppEnvironment *env = [TIoTCoreAppEnvironment shareEnvironment]; - int errorcode = [[TIoTCoreXP2PBridge sharedInstance] startAppWith:env.cloudProductId dev_name:self.deviceName?:@""]; + //sensor_timeout:6 表示6s后没ready就切tcp模式 + int errorcode = [[TIoTCoreXP2PBridge sharedInstance] startAppWith:env.cloudProductId dev_name:self.deviceName?:@"" sensor_timeout:6]; if (errorcode == XP2P_ERR_VERSION) { UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"APP SDK 版本与设备端 SDK 版本号不匹配,版本号需前两位保持一致" message:nil preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { diff --git a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h index f7440e01..b5a0a71c 100644 --- a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h +++ b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h @@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN extern NSNotificationName const TIoTCoreXP2PBridgeNotificationDisconnect; extern NSNotificationName const TIoTCoreXP2PBridgeNotificationReady; +extern NSNotificationName const TIoTCoreXP2PBridgeNotificationDetectError; extern NSNotificationName const TIoTCoreXP2PBridgeNotificationDeviceMsg; extern NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd; @@ -72,8 +73,10 @@ extern NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd; /* * 启动 sdk 服务,productid和devicename可以从video控制台创建得倒 + * sensor_timeout: 探测失败切换tcp的超时时间,最小3s,默认5s */ - (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name; +- (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name sensor_timeout:(int)sensor_timeout; /* * 此接口慎重:需注意 正式版app发布时候不需要传入secretid和secretkey,避免将这两个参数放置在app中,防止账号泄露,此处仅为演示功能 diff --git a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm index 768933df..10629865 100644 --- a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm +++ b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm @@ -9,6 +9,7 @@ NSNotificationName const TIoTCoreXP2PBridgeNotificationDisconnect = @"xp2disconnect"; //p2p通道断开 NSNotificationName const TIoTCoreXP2PBridgeNotificationReady = @"xp2preconnect"; //app本地已ready,表示探测完成,可以发起请求了 +NSNotificationName const TIoTCoreXP2PBridgeNotificationDetectError = @"xp2detecterror"; //探测失败,网络不正常表示探测完成,可以发起请求了 NSNotificationName const TIoTCoreXP2PBridgeNotificationDeviceMsg = @"XP2PTypeDeviceMsgArrived"; //收到设备端的请求数据 NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd = @"XP2PTypeStreamEnd"; // 设备主动停止推流,或者由于达到设备最大连接数,拒绝推流 @@ -54,11 +55,16 @@ - (void)cancelTimer; NSString *DeviceName = [NSString stringWithCString:idd encoding:[NSString defaultCStringEncoding]]?:@""; - if (type == XP2PTypeDisconnect || type == XP2PTypeDetectError) { + if (type == XP2PTypeDisconnect) { [[TIoTCoreXP2PBridge sharedInstance] cancelTimer]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationDisconnect object:nil userInfo:@{@"id": DeviceName}]; }); + }else if (type == XP2PTypeDetectError) { + [[TIoTCoreXP2PBridge sharedInstance] cancelTimer]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationDetectError object:nil userInfo:@{@"id": DeviceName}]; + }); }else if (type == XP2PTypeDetectReady) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationReady object:nil userInfo:@{@"id": DeviceName}]; @@ -209,21 +215,23 @@ - (XP2PErrCode)startAppWith:(NSString *)sec_id sec_key:(NSString *)sec_key pro_i //1.配置IOT_P2P SDK self.dev_name = dev_name; setQcloudApiCred([sec_id UTF8String], [sec_key UTF8String]); //正式版app发布时候需要去掉,避免泄露secretid和secretkey,此处仅为演示 - int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String); + int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String, 5); setDeviceXp2pInfo(dev_name.UTF8String, xp2pinfo.UTF8String); return (XP2PErrCode)ret; } - - (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name { + return [self startAppWith:pro_id dev_name:dev_name sensor_timeout:5]; +} +- (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name sensor_timeout:(int)sensor_timeout{ // setStunServerToXp2p("11.11.11.11", 111); //注册回调 setUserCallbackToXp2p(XP2PDataMsgHandle, XP2PMsgHandle, XP2PReviceDeviceCustomMsgHandle); //1.配置IOT_P2P SDK self.dev_name = dev_name; - int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String); + int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String, sensor_timeout); return (XP2PErrCode)ret; } diff --git "a/Source/SDK/LinkVideo/doc/iOS Video\346\216\245\345\205\245\346\214\207\345\274\225\346\226\207\346\241\243.md" "b/Source/SDK/LinkVideo/doc/iOS Video\346\216\245\345\205\245\346\214\207\345\274\225\346\226\207\346\241\243.md" index 49086f47..e5e81986 100644 --- "a/Source/SDK/LinkVideo/doc/iOS Video\346\216\245\345\205\245\346\214\207\345\274\225\346\226\207\346\241\243.md" +++ "b/Source/SDK/LinkVideo/doc/iOS Video\346\216\245\345\205\245\346\214\207\345\274\225\346\226\207\346\241\243.md" @@ -9,7 +9,7 @@ https://github.com/tencentyun/iot-thirdparty-ios/tree/master/Source/XP2P-iOS * 工程如何引用: - + 将所有.a与AppWrapper.h 加入工程中,加入libc++, libsqlite3, libz系统库 ##### 使用iOS库方法 @@ -36,7 +36,7 @@ //2.配置IOT_P2P SDK,demoapp作为演示需要配置第二步,客户正式发布的app不建议配置第二步,需通过自建业务服务获取xp2pInfo传入第三步的参数中 setQcloudApiCred(sec_id, sec_key); //正式版app发布时候需要去掉,避免泄露secretid和secretkey,此处仅为演示 - + //3.启动p2p通道,此处id参数传入了dev_name,用户也可以维护一套自己区分不同设备的id;最后的参数在正式发布版本中需传xp2p_info,所有接口的参数含义可以参考本文档最底下链接 startServiceWithXp2pInfo(dev_name, pro_id, dev_name, ""); @@ -131,30 +131,31 @@ ``` * 获取当前发送链路的连接模式 - + ``` //连接模式:0 无效;62 直连;63 转发 getStreamLinkMode(dev_name) - ``` - + ``` + * 调试接口,用于iOS端保存播放器拉取数据流 ``` startRecordPlayerStream(dev_name) - ``` - + ``` + ##### iOS库调用方法 * P2P通道初始化 ``` - [[TIoTCoreXP2PBridge sharedInstance] startAppWith:@"" sec_key:@"" pro_id:@"" dev_name:@""]; + //sensor_timeout: 探测失败切换tcp的超时时间,最小3s,默认5s + [[TIoTCoreXP2PBridge sharedInstance] startAppWith:@"" sec_key:@"" pro_id:@"" dev_name:@"" sensor_timeout:6]; ``` **注意事项:** - + * demo app为了获取设备列表,需要客户填写腾讯云api的密钥,获取的设备信息是客户该产品所有的设备,不区分C端用户,真实使用场景是希望获取设备列表的操作在客户自建后台进行的,云api的secretID、secretKey不保存在app上,避免泄露风险 - + * P2P通道传输音视频流 ``` @@ -236,7 +237,7 @@ * 获取当前发送链路的连接模式 - + ``` //返回模式标识:0 无效;62 直连;63 转发 int netmode = [TIoTCoreXP2PBridge getStreamLinkMode:dev_name] @@ -257,7 +258,7 @@ //通过 startAvRecvService 和 stopAvRecvService 接口,可以启动和停止裸流传输,客户端拉取到的裸流数据对应 data 参数 - (void)getVideoPacketWithID:(NSString *)dev_name data:(uint8_t *)data len:(size_t)len; ``` - + * P2P代理方法: 接收设备主动发送消息回调 **谨慎!!! 此接口切勿执行耗时操作,耗时操作请切换线程,切勿卡住当前线程,返回值需立即返回** @@ -272,9 +273,8 @@ - (NSString *)reviceDeviceMsgWithID:(NSString *)dev_name data:(NSData *)data; ``` - * P2P代理方法:接收设备发送的事件消息 - + ``` /* *接收到设备发送事件 diff --git a/TIoTLinkVideo.podspec b/TIoTLinkVideo.podspec index 0134be03..f4188631 100644 --- a/TIoTLinkVideo.podspec +++ b/TIoTLinkVideo.podspec @@ -18,7 +18,7 @@ Pod::Spec.new do |s| s.source_files = 'Source/SDK/LinkVideo/**/*.{h,m,c,mm}' - s.dependency 'TIoTLinkKit_XP2P', '2.4.38' + s.dependency 'TIoTLinkKit_XP2P', '2.4.40' s.dependency 'TIoTLinkKit_FLV', '2.2.3' s.dependency 'CocoaAsyncSocket', '7.6.5' s.dependency 'TIoTLinkKit_SoundTouch', '1.0.0'