Skip to content

Commit

Permalink
可设置tcp切换时间,默认5s
Browse files Browse the repository at this point in the history
Change-Id: Ie1fb575a26dad4a3383727d8870089e2405fb05c
  • Loading branch information
tonychanchen committed Oct 24, 2023
1 parent b158cd7 commit dd3214b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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中,防止账号泄露,此处仅为演示功能
Expand Down
16 changes: 12 additions & 4 deletions Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"; // 设备主动停止推流,或者由于达到设备最大连接数,拒绝推流

Expand Down Expand Up @@ -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}];
Expand Down Expand Up @@ -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;
}

Expand Down
28 changes: 14 additions & 14 deletions Source/SDK/LinkVideo/doc/iOS Video接入指引文档.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
https://github.com/tencentyun/iot-thirdparty-ios/tree/master/Source/XP2P-iOS

* 工程如何引用:

将所有.a与AppWrapper.h 加入工程中,加入libc++, libsqlite3, libz系统库

##### 使用iOS库方法
Expand All @@ -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, "");

Expand Down Expand Up @@ -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通道传输音视频流
```
Expand Down Expand Up @@ -236,7 +237,7 @@
* 获取当前发送链路的连接模式
```
//返回模式标识:0 无效;62 直连;63 转发
int netmode = [TIoTCoreXP2PBridge getStreamLinkMode:dev_name]
Expand All @@ -257,7 +258,7 @@
//通过 startAvRecvService 和 stopAvRecvService 接口,可以启动和停止裸流传输,客户端拉取到的裸流数据对应 data 参数
- (void)getVideoPacketWithID:(NSString *)dev_name data:(uint8_t *)data len:(size_t)len;
```
* P2P代理方法: 接收设备主动发送消息回调
**谨慎!!! 此接口切勿执行耗时操作,耗时操作请切换线程,切勿卡住当前线程,返回值需立即返回**
Expand All @@ -272,9 +273,8 @@
- (NSString *)reviceDeviceMsgWithID:(NSString *)dev_name data:(NSData *)data;
```
* P2P代理方法:接收设备发送的事件消息
```
/*
*接收到设备发送事件
Expand Down
2 changes: 1 addition & 1 deletion TIoTLinkVideo.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit dd3214b

Please sign in to comment.