Skip to content

Commit dd3214b

Browse files
committed
可设置tcp切换时间,默认5s
Change-Id: Ie1fb575a26dad4a3383727d8870089e2405fb05c
1 parent b158cd7 commit dd3214b

File tree

6 files changed

+37
-25
lines changed

6 files changed

+37
-25
lines changed

Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ PODS:
3434
- TIoTLinkKit_SoundTouch (1.0.0)
3535
- TIoTLinkKit_TPNS (1.0.1)
3636
- TIoTLinkKit_WechatOpenSDK (1.0.1)
37-
- TIoTLinkKit_XP2P (2.4.38)
37+
- TIoTLinkKit_XP2P (2.4.40)
3838
- TIoTLinkVideo (1.0.0):
3939
- CocoaAsyncSocket (= 7.6.5)
4040
- TIoTLinkKit_FLV (= 2.2.3)
4141
- TIoTLinkKit_SoundTouch (= 1.0.0)
42-
- TIoTLinkKit_XP2P (= 2.4.38)
42+
- TIoTLinkKit_XP2P (= 2.4.40)
4343
- TPCircularBuffer (= 1.6.1)
4444
- TPCircularBuffer (1.6.1)
4545
- TrueTime (5.0.3)
@@ -129,8 +129,8 @@ SPEC CHECKSUMS:
129129
TIoTLinkKit_SoundTouch: cf79ae182b6c2349ff65bac7a338974bc538fa77
130130
TIoTLinkKit_TPNS: 7cea4fc1d20ef6c4c11c4f0b66bbb10ecf4ed968
131131
TIoTLinkKit_WechatOpenSDK: 7822d68cc5c46edf3f6020422202e7b65ea87614
132-
TIoTLinkKit_XP2P: baa1eff35498ce8fe1bbc80c0ffe9906be27b6b5
133-
TIoTLinkVideo: 80a20c6e1c527234e974ad1869828ac4147f139e
132+
TIoTLinkKit_XP2P: 5b9690823f2cbc758964d5bc60f8e8e475e76aaa
133+
TIoTLinkVideo: e8522c6c22e7cb93dd3f108d246347e3b226baa1
134134
TPCircularBuffer: c13243556527551c4d320709c7b14a6d20cdc30a
135135
TrueTime: b49551ffafb28a9dee04e51b226f42a416010842
136136
TXLiteAVSDK_TRTC: e3383a81565e8bb2aaaaab4bd099ad5239cd5b2d

Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoPreviewDeviceVC.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ - (void)viewDidLoad {
105105

106106
_is_ijkPlayer_stream = YES;
107107
//关闭日志
108-
// [TIoTCoreXP2PBridge sharedInstance].logEnable = NO;
108+
[TIoTCoreXP2PBridge sharedInstance].logEnable = YES;
109109
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
110110

111111
self.qualityString = quality_high;
@@ -127,7 +127,8 @@ - (void)viewDidLoad {
127127
[self setupPreViewViews];
128128

129129
TIoTCoreAppEnvironment *env = [TIoTCoreAppEnvironment shareEnvironment];
130-
int errorcode = [[TIoTCoreXP2PBridge sharedInstance] startAppWith:env.cloudProductId dev_name:self.deviceName?:@""];
130+
//sensor_timeout:6 表示6s后没ready就切tcp模式
131+
int errorcode = [[TIoTCoreXP2PBridge sharedInstance] startAppWith:env.cloudProductId dev_name:self.deviceName?:@"" sensor_timeout:6];
131132
if (errorcode == XP2P_ERR_VERSION) {
132133
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"APP SDK 版本与设备端 SDK 版本号不匹配,版本号需前两位保持一致" message:nil preferredStyle:(UIAlertControllerStyleAlert)];
133134
UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {

Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
1414

1515
extern NSNotificationName const TIoTCoreXP2PBridgeNotificationDisconnect;
1616
extern NSNotificationName const TIoTCoreXP2PBridgeNotificationReady;
17+
extern NSNotificationName const TIoTCoreXP2PBridgeNotificationDetectError;
1718
extern NSNotificationName const TIoTCoreXP2PBridgeNotificationDeviceMsg;
1819
extern NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd;
1920

@@ -72,8 +73,10 @@ extern NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd;
7273

7374
/*
7475
* 启动 sdk 服务,productid和devicename可以从video控制台创建得倒
76+
* sensor_timeout: 探测失败切换tcp的超时时间,最小3s,默认5s
7577
*/
7678
- (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name;
79+
- (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name sensor_timeout:(int)sensor_timeout;
7780

7881
/*
7982
* 此接口慎重:需注意 正式版app发布时候不需要传入secretid和secretkey,避免将这两个参数放置在app中,防止账号泄露,此处仅为演示功能

Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
NSNotificationName const TIoTCoreXP2PBridgeNotificationDisconnect = @"xp2disconnect"; //p2p通道断开
1111
NSNotificationName const TIoTCoreXP2PBridgeNotificationReady = @"xp2preconnect"; //app本地已ready,表示探测完成,可以发起请求了
12+
NSNotificationName const TIoTCoreXP2PBridgeNotificationDetectError = @"xp2detecterror"; //探测失败,网络不正常表示探测完成,可以发起请求了
1213
NSNotificationName const TIoTCoreXP2PBridgeNotificationDeviceMsg = @"XP2PTypeDeviceMsgArrived"; //收到设备端的请求数据
1314
NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd = @"XP2PTypeStreamEnd"; // 设备主动停止推流,或者由于达到设备最大连接数,拒绝推流
1415

@@ -54,11 +55,16 @@ - (void)cancelTimer;
5455

5556
NSString *DeviceName = [NSString stringWithCString:idd encoding:[NSString defaultCStringEncoding]]?:@"";
5657

57-
if (type == XP2PTypeDisconnect || type == XP2PTypeDetectError) {
58+
if (type == XP2PTypeDisconnect) {
5859
[[TIoTCoreXP2PBridge sharedInstance] cancelTimer];
5960
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
6061
[[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationDisconnect object:nil userInfo:@{@"id": DeviceName}];
6162
});
63+
}else if (type == XP2PTypeDetectError) {
64+
[[TIoTCoreXP2PBridge sharedInstance] cancelTimer];
65+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
66+
[[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationDetectError object:nil userInfo:@{@"id": DeviceName}];
67+
});
6268
}else if (type == XP2PTypeDetectReady) {
6369
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
6470
[[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
209215
//1.配置IOT_P2P SDK
210216
self.dev_name = dev_name;
211217
setQcloudApiCred([sec_id UTF8String], [sec_key UTF8String]); //正式版app发布时候需要去掉,避免泄露secretid和secretkey,此处仅为演示
212-
int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String);
218+
int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String, 5);
213219
setDeviceXp2pInfo(dev_name.UTF8String, xp2pinfo.UTF8String);
214220
return (XP2PErrCode)ret;
215221
}
216222

217223

218-
219224
- (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name {
225+
return [self startAppWith:pro_id dev_name:dev_name sensor_timeout:5];
226+
}
227+
- (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name sensor_timeout:(int)sensor_timeout{
220228
// setStunServerToXp2p("11.11.11.11", 111);
221229
//注册回调
222230
setUserCallbackToXp2p(XP2PDataMsgHandle, XP2PMsgHandle, XP2PReviceDeviceCustomMsgHandle);
223231

224232
//1.配置IOT_P2P SDK
225233
self.dev_name = dev_name;
226-
int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String);
234+
int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String, sensor_timeout);
227235
return (XP2PErrCode)ret;
228236
}
229237

Source/SDK/LinkVideo/doc/iOS Video接入指引文档.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
https://github.com/tencentyun/iot-thirdparty-ios/tree/master/Source/XP2P-iOS
1010

1111
* 工程如何引用:
12-
12+
1313
将所有.a与AppWrapper.h 加入工程中,加入libc++, libsqlite3, libz系统库
1414

1515
##### 使用iOS库方法
@@ -36,7 +36,7 @@
3636

3737
//2.配置IOT_P2P SDK,demoapp作为演示需要配置第二步,客户正式发布的app不建议配置第二步,需通过自建业务服务获取xp2pInfo传入第三步的参数中
3838
setQcloudApiCred(sec_id, sec_key); //正式版app发布时候需要去掉,避免泄露secretid和secretkey,此处仅为演示
39-
39+
4040
//3.启动p2p通道,此处id参数传入了dev_name,用户也可以维护一套自己区分不同设备的id;最后的参数在正式发布版本中需传xp2p_info,所有接口的参数含义可以参考本文档最底下链接
4141
startServiceWithXp2pInfo(dev_name, pro_id, dev_name, "");
4242

@@ -131,30 +131,31 @@
131131
```
132132

133133
* 获取当前发送链路的连接模式
134-
134+
135135
```
136136
//连接模式:0 无效;62 直连;63 转发
137137
getStreamLinkMode(dev_name)
138-
```
139-
138+
```
139+
140140
* 调试接口,用于iOS端保存播放器拉取数据流
141141
142142
```
143143
startRecordPlayerStream(dev_name)
144-
```
145-
144+
```
145+
146146
147147
148148
##### iOS库调用方法
149149
* P2P通道初始化
150150
151151
```
152-
[[TIoTCoreXP2PBridge sharedInstance] startAppWith:@"" sec_key:@"" pro_id:@"" dev_name:@""];
152+
//sensor_timeout: 探测失败切换tcp的超时时间,最小3s,默认5s
153+
[[TIoTCoreXP2PBridge sharedInstance] startAppWith:@"" sec_key:@"" pro_id:@"" dev_name:@"" sensor_timeout:6];
153154
```
154155
**注意事项:**
155-
156+
156157
* demo app为了获取设备列表,需要客户填写腾讯云api的密钥,获取的设备信息是客户该产品所有的设备,不区分C端用户,真实使用场景是希望获取设备列表的操作在客户自建后台进行的,云api的secretID、secretKey不保存在app上,避免泄露风险
157-
158+
158159
* P2P通道传输音视频流
159160
160161
```
@@ -236,7 +237,7 @@
236237
237238
238239
* 获取当前发送链路的连接模式
239-
240+
240241
```
241242
//返回模式标识:0 无效;62 直连;63 转发
242243
int netmode = [TIoTCoreXP2PBridge getStreamLinkMode:dev_name]
@@ -257,7 +258,7 @@
257258
//通过 startAvRecvService 和 stopAvRecvService 接口,可以启动和停止裸流传输,客户端拉取到的裸流数据对应 data 参数
258259
- (void)getVideoPacketWithID:(NSString *)dev_name data:(uint8_t *)data len:(size_t)len;
259260
```
260-
261+
261262
* P2P代理方法: 接收设备主动发送消息回调
262263
**谨慎!!! 此接口切勿执行耗时操作,耗时操作请切换线程,切勿卡住当前线程,返回值需立即返回**
263264
@@ -272,9 +273,8 @@
272273
- (NSString *)reviceDeviceMsgWithID:(NSString *)dev_name data:(NSData *)data;
273274
```
274275
275-
276276
* P2P代理方法:接收设备发送的事件消息
277-
277+
278278
```
279279
/*
280280
*接收到设备发送事件

TIoTLinkVideo.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
1818

1919
s.source_files = 'Source/SDK/LinkVideo/**/*.{h,m,c,mm}'
2020

21-
s.dependency 'TIoTLinkKit_XP2P', '2.4.38'
21+
s.dependency 'TIoTLinkKit_XP2P', '2.4.40'
2222
s.dependency 'TIoTLinkKit_FLV', '2.2.3'
2323
s.dependency 'CocoaAsyncSocket', '7.6.5'
2424
s.dependency 'TIoTLinkKit_SoundTouch', '1.0.0'

0 commit comments

Comments
 (0)