diff --git a/Podfile.lock b/Podfile.lock index bdad0cb9a..52b6f3440 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -136,10 +136,10 @@ PODS: - TIoTLinkKit_IJKPlayer (1.0.2) - TIoTLinkKit_TPNS (1.0.1) - TIoTLinkKit_WechatOpenSDK (1.0.1) - - TIoTLinkKit_XP2P (2.3.3-beta.202112080926) + - TIoTLinkKit_XP2P (2.3.4-beta.202112160406) - TIoTLinkVideo (1.0.0): - TIoTLinkKit_Faac (= 2.0.5) - - TIoTLinkKit_XP2P (= 2.3.3-beta.202112080926) + - TIoTLinkKit_XP2P (= 2.3.4-beta.202112160406) - TrueTime (5.0.3) - TXLiteAVSDK_TRTC (8.0.9644) - TZImagePickerController (3.2.1) @@ -261,8 +261,8 @@ SPEC CHECKSUMS: TIoTLinkKit_IJKPlayer: e47c3fed6b204e7544f84a24310cab7a372854d1 TIoTLinkKit_TPNS: 7cea4fc1d20ef6c4c11c4f0b66bbb10ecf4ed968 TIoTLinkKit_WechatOpenSDK: 7822d68cc5c46edf3f6020422202e7b65ea87614 - TIoTLinkKit_XP2P: 2759237404fa06b0888703f34af3b2c5a6e583a6 - TIoTLinkVideo: 46cd77511384c9826a885bcd56eff6a1e2ed0eca + TIoTLinkKit_XP2P: 849329c6900d18a91b254701fb4b116f4c4ef3db + TIoTLinkVideo: 12eca35ee373da4bc2f6b4c1d21a4c8c5af026f6 TrueTime: b49551ffafb28a9dee04e51b226f42a416010842 TXLiteAVSDK_TRTC: e3383a81565e8bb2aaaaab4bd099ad5239cd5b2d TZImagePickerController: bf4c57b98d8707fce41ea6be872414a71c7a8c9d diff --git a/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoPreviewDeviceVC.m b/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoPreviewDeviceVC.m index 077fa2476..3c9d6aed2 100644 --- a/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoPreviewDeviceVC.m +++ b/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoPreviewDeviceVC.m @@ -1108,8 +1108,9 @@ - (void)refushVideo:(NSNotification *)notify { self.startPlayer = CACurrentMediaTime(); }); */ + [self setVieoPlayerStartPlayWith:self.qualityString]; - [self getDeviceStatusWithType:action_live qualityType:self.qualityString]; +// [self getDeviceStatusWithType:action_live qualityType:self.qualityString]; } } @@ -1121,13 +1122,14 @@ - (void)responseP2PdisConnect:(NSNotification *)notify { return; } + NSLog(@"通道断开,正在重连"); [MBProgressHUD showError:@"通道断开,正在重连"]; - [[TIoTCoreXP2PBridge sharedInstance] stopService: DeviceName]; - - TIoTCoreAppEnvironment *env = [TIoTCoreAppEnvironment shareEnvironment]; - [[TIoTCoreXP2PBridge sharedInstance] startAppWith:env.cloudProductId dev_name:DeviceName?:@""]; - [[TIoTCoreXP2PBridge sharedInstance] setXp2pInfo:DeviceName?:@"" sec_id:env.cloudSecretId sec_key:env.cloudSecretKey xp2pinfo:@""]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + TIoTCoreAppEnvironment *env = [TIoTCoreAppEnvironment shareEnvironment]; + [[TIoTCoreXP2PBridge sharedInstance] setXp2pInfo:DeviceName?:@"" sec_id:env.cloudSecretId sec_key:env.cloudSecretKey xp2pinfo:@""]; + [self setVieoPlayerStartPlayWith:self.qualityString]; + }); } /// MARK:新设备 @@ -1157,9 +1159,6 @@ - (void)setVieoPlayerStartPlayWith:(NSString *)qualityString { - (void)nav_customBack { [self stopPlayMovie]; - if (self.isNVR == NO) { - [[TIoTCoreXP2PBridge sharedInstance] stopService:self.deviceName?:@""]; - } [self removeMovieNotificationObservers]; [self.navigationController popViewControllerAnimated:YES]; } @@ -1211,7 +1210,8 @@ - (void)configVideo { [self.player setOptionIntValue:1 forKey:@"start-on-prepared" ofCategory:kIJKFFOptionCategoryPlayer]; [self.player setOptionIntValue:1 forKey:@"threads" ofCategory:kIJKFFOptionCategoryCodec]; [self.player setOptionIntValue:0 forKey:@"sync-av-start" ofCategory:kIJKFFOptionCategoryPlayer]; -// [self.player setOptionValue:@"16000" forKey:@"ar" ofCategory:kIJKFFOptionCategoryCodec]; +// [self.player setOptionValue:@"8000" forKey:@"ar" ofCategory:kIJKFFOptionCategoryCodec]; +// [self.player setOptionValue:@"1" forKey:@"ac" ofCategory:kIJKFFOptionCategoryCodec]; }else { // 2.通过裸流服务拉流 @@ -1431,13 +1431,6 @@ - (void)resetVideoPlayerWithQuality:(NSString *)qualityString { qualityID = [NSString stringWithFormat:@"%@&channel=0",qualityString]; } - if (self.isNVR == NO) { -// NSString *deviceName = self.deviceName?:@""; -// [[TIoTCoreXP2PBridge sharedInstance] startAppWith:[TIoTCoreAppEnvironment shareEnvironment].cloudSecretId -// sec_key:[TIoTCoreAppEnvironment shareEnvironment].cloudSecretKey -// pro_id:[TIoTCoreAppEnvironment shareEnvironment].cloudProductId -// dev_name:deviceName]; - } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSString *urlString = [[TIoTCoreXP2PBridge sharedInstance] getUrlForHttpFlv:self.deviceName?:@""]; diff --git a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h index cee40703e..5f6d0851e 100644 --- a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h +++ b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h @@ -10,6 +10,11 @@ NS_ASSUME_NONNULL_BEGIN +extern NSNotificationName const TIoTCoreXP2PBridgeNotificationDisconnect; +extern NSNotificationName const TIoTCoreXP2PBridgeNotificationReady; +extern NSNotificationName const TIoTCoreXP2PBridgeNotificationDeviceMsg; +extern NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd; + @protocol TIoTCoreXP2PBridgeDelegate /* diff --git a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm index bcae87d95..7bedd1961 100644 --- a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm +++ b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm @@ -7,6 +7,12 @@ #import "TIoTCoreXP2PBridge.h" #include + +NSNotificationName const TIoTCoreXP2PBridgeNotificationDisconnect = @"xp2disconnect"; //p2p通道断开 +NSNotificationName const TIoTCoreXP2PBridgeNotificationReady = @"xp2preconnect"; //app本地已ready,表示探测完成,可以发起请求了 +NSNotificationName const TIoTCoreXP2PBridgeNotificationDeviceMsg = @"XP2PTypeDeviceMsgArrived"; //收到设备端的请求数据 +NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd = @"XP2PTypeStreamEnd"; // 设备主动停止推流,或者由于达到设备最大连接数,拒绝推流 + NSFileHandle *p2pOutLogFile; const char* XP2PMsgHandle(const char *idd, XP2PType type, const char* msg) { @@ -44,20 +50,31 @@ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [p2pOutLogFile synchronizeFile]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"xp2disconnect" object:nil userInfo:@{@"id": DeviceName}]; + [[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationDisconnect object:nil userInfo:@{@"id": DeviceName}]; }); }else if (type == XP2PTypeDetectReady) { NSLog(@"XP2P log: ready %@\n", message); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [p2pOutLogFile synchronizeFile]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"xp2preconnect" object:nil userInfo:@{@"id": DeviceName}]; + [[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationReady object:nil userInfo:@{@"id": DeviceName}]; }); } else if (type == XP2PTypeDeviceMsgArrived) { -// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ -// NSLog(@"revice device msg: %@", message); -// }); + // 设备端向App发消息 + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationDeviceMsg object:nil userInfo:@{@"id": DeviceName, @"msg": message}]; + }); + } + else if (type == XP2PTypeCmdNOReturn) { + //设备自定义信令未回复内容 + NSLog(@"设备自定义信令未回复内容: %@", message); + } + else if (type == XP2PTypeStreamEnd) { + // 设备主动停止推流,或者由于达到设备最大连接数,拒绝推流 + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:TIoTCoreXP2PBridgeNotificationStreamEnd object:nil userInfo:@{@"id": DeviceName}]; + }); } return nullptr; @@ -70,6 +87,15 @@ void XP2PDataMsgHandle(const char *idd, uint8_t* recv_buf, size_t recv_len) { } } +char* XP2PReviceDeviceCustomMsgHandle(const char *idd, uint8_t* recv_buf, size_t recv_len) { +// id delegate = [TIoTCoreXP2PBridge sharedInstance].delegate; +// if ([delegate respondsToSelector:@selector(getVideoPacket:len:)]) { +// [delegate getVideoPacket:recv_buf len:recv_len]; +// } + return nullptr; +} + +typedef char *(*device_data_recv_handle_t)(const char *id, uint8_t *recv_buf, size_t recv_len); @interface TIoTCoreXP2PBridge () @property (nonatomic, strong) NSString *dev_name; @@ -112,7 +138,7 @@ - (XP2PErrCode)startAppWith:(NSString *)sec_id sec_key:(NSString *)sec_key pro_i return [self startAppWith:sec_id sec_key:sec_key pro_id:pro_id dev_name:dev_name xp2pinfo:@""]; } - (XP2PErrCode)startAppWith:(NSString *)sec_id sec_key:(NSString *)sec_key pro_id:(NSString *)pro_id dev_name:(NSString *)dev_name xp2pinfo:(NSString *)xp2pinfo { - setUserCallbackToXp2p(XP2PDataMsgHandle, XP2PMsgHandle); + setUserCallbackToXp2p(XP2PDataMsgHandle, XP2PMsgHandle, XP2PReviceDeviceCustomMsgHandle); //1.配置IOT_P2P SDK self.dev_name = dev_name; @@ -127,7 +153,7 @@ - (XP2PErrCode)startAppWith:(NSString *)sec_id sec_key:(NSString *)sec_key pro_i - (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name { // setStunServerToXp2p("11.11.11.11", 111); //注册回调 - setUserCallbackToXp2p(XP2PDataMsgHandle, XP2PMsgHandle); + setUserCallbackToXp2p(XP2PDataMsgHandle, XP2PMsgHandle, XP2PReviceDeviceCustomMsgHandle); //1.配置IOT_P2P SDK self.dev_name = dev_name; diff --git a/TIoTLinkVideo.podspec b/TIoTLinkVideo.podspec index 8e1c5bdec..c7dda2682 100644 --- a/TIoTLinkVideo.podspec +++ b/TIoTLinkVideo.podspec @@ -17,7 +17,7 @@ Pod::Spec.new do |s| s.static_framework = true s.source_files = 'Source/SDK/LinkVideo/**/*.{h,m,c,mm}' - s.dependency 'TIoTLinkKit_XP2P', '2.3.3' + s.dependency 'TIoTLinkKit_XP2P', '2.3.4-beta.202112160406' s.dependency 'TIoTLinkKit_Faac', '2.0.5' s.pod_target_xcconfig = { 'VALID_ARCHS' => 'arm64'