From 4905f8e676a145a4a273c098b51c9c7a892c7ea3 Mon Sep 17 00:00:00 2001 From: tonychan Date: Thu, 2 Nov 2023 11:15:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4pcm=20vad=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2pcm=E6=BC=8F=E6=8E=89,=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=8C=82=E6=96=AD=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I542db41ef624511fb17cc2855916156e6c84d8d0 --- .../P2P/Controller/TIoTDemoVideoPushVC.m | 28 +++++++++++++- .../Video/P2P/Controller/TIoTSessionManager.m | 2 - .../Controller/TIoTDemoLocalRecordVC.m | 2 +- Source/SDK/LinkVideo/FLV/TIoTAVCaptionFLV.mm | 10 ++--- Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h | 3 +- Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm | 37 +++++++++---------- 6 files changed, 52 insertions(+), 30 deletions(-) diff --git a/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoVideoPushVC.m b/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoVideoPushVC.m index 971ecdc0..ac04ee41 100644 --- a/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoVideoPushVC.m +++ b/Source/LinkSDKDemo/Video/P2P/Controller/TIoTDemoVideoPushVC.m @@ -44,7 +44,7 @@ typedef NS_ENUM(NSInteger, TIotDemoDeviceDirection) { }; -@interface TIoTDemoVideoPushVC () +@interface TIoTDemoVideoPushVC () @property (nonatomic, assign) CGRect screenRect; @property (nonatomic, strong) UIImageView *imageView; @property (nonatomic, strong) UIView *remoteVideoView; //录像中提示view @@ -81,6 +81,30 @@ - (instancetype)init { return self; } +#pragma mark - TIoTCoreXP2PBridgeDelegate +- (NSString *)reviceDeviceMsgWithID:(NSString *)dev_name data:(NSData *)data { + NSString *deviceMsg = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; + NSLog(@"接收到设备主动发的消息==%@", deviceMsg); + + return @"responseMES"; +} + +//下载完成事件 +- (void)reviceEventMsgWithID:(NSString *)dev_name eventType:(XP2PType)eventType msg:(const char *)msg { + if (eventType == XP2PTypeClose) { + + NSString *msgDetail = [NSString stringWithCString:msg encoding:[NSString defaultCStringEncoding]]; + if ([msgDetail containsString:@"2000"]) { + [MBProgressHUD dismissInView:self.view]; + [MBProgressHUD showError:@"语音对讲服务关闭"]; + } + NSLog(@"msgDDD=%@",msgDetail); + } +} + + + + - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. @@ -89,6 +113,8 @@ - (void)viewDidLoad { _is_ijkPlayer_stream = YES; //关闭日志 + [TIoTCoreXP2PBridge sharedInstance].delegate = self; + [TIoTCoreXP2PBridge sharedInstance].logEnable = YES; self.navigationController.navigationBar.tintColor = [UIColor blackColor]; diff --git a/Source/LinkSDKDemo/Video/P2P/Controller/TIoTSessionManager.m b/Source/LinkSDKDemo/Video/P2P/Controller/TIoTSessionManager.m index f6608ca7..ce4a2ae9 100644 --- a/Source/LinkSDKDemo/Video/P2P/Controller/TIoTSessionManager.m +++ b/Source/LinkSDKDemo/Video/P2P/Controller/TIoTSessionManager.m @@ -81,7 +81,6 @@ - (void)cacheCurrentAudioSession { //需要录音时,AudioSession的设置代码如下: - (void)resumeRTCAudioSession { - return; self.session = [AVAudioSession sharedInstance]; if (self.session.category != AVAudioSessionCategoryPlayAndRecord) { [self cacheCurrentAudioSession]; //先缓存之前的 @@ -103,7 +102,6 @@ - (void)resumeRTCAudioSession { } //功能结束时重置audioSession,重置到缓存的audioSession设置 - (void)resetToCachedAudioSession { - return; if (!cachedCategory) { return; } diff --git a/Source/LinkSDKDemo/Video/PlayBack/LocalPlayBack/Controller/TIoTDemoLocalRecordVC.m b/Source/LinkSDKDemo/Video/PlayBack/LocalPlayBack/Controller/TIoTDemoLocalRecordVC.m index d8d41fd0..be550820 100644 --- a/Source/LinkSDKDemo/Video/PlayBack/LocalPlayBack/Controller/TIoTDemoLocalRecordVC.m +++ b/Source/LinkSDKDemo/Video/PlayBack/LocalPlayBack/Controller/TIoTDemoLocalRecordVC.m @@ -781,7 +781,7 @@ - (NSString *)reviceDeviceMsgWithID:(NSString *)dev_name data:(NSData *)data { } //下载完成事件 -- (void)reviceEventMsgWithID:(NSString *)dev_name eventType:(XP2PType)eventType { +- (void)reviceEventMsgWithID:(NSString *)dev_name eventType:(XP2PType)eventType msg:(nonnull const char *)msg{ if (eventType == XP2PTypeDownloadEnd) {//下载完成的事件 if (self.downLoading) { diff --git a/Source/SDK/LinkVideo/FLV/TIoTAVCaptionFLV.mm b/Source/SDK/LinkVideo/FLV/TIoTAVCaptionFLV.mm index 0fec7f16..61ac3a7d 100755 --- a/Source/SDK/LinkVideo/FLV/TIoTAVCaptionFLV.mm +++ b/Source/SDK/LinkVideo/FLV/TIoTAVCaptionFLV.mm @@ -368,7 +368,7 @@ - (void)setPitch:(int)pitch { ijk_soundtouch_handle = ijk_soundtouch_create(1.0, _pitch, tmpChannel, 16000); } -static uint8_t trae_pcm_buffer[512]; +//static uint8_t trae_pcm_buffer[512]; static uint8_t trae_aac_buffer[8192]; float indata[FRAME_LEN]; TPCircularBuffer aac_circularBuffer; @@ -377,12 +377,12 @@ static void record_callback(uint8_t *buffer, int size, void *u) { // printf("pcm_size_callback: %d\n", size); TIoTAVCaptionFLV *vc = (__bridge TIoTAVCaptionFLV *)(u); - memset(trae_pcm_buffer, 0, 512); + /*memset(trae_pcm_buffer, 0, 512); UInt32 len = [vc.pcmRecord getData:&pcm_circularBuffer :trae_pcm_buffer :512]; if (len < 512) { return; } - /* + // check vad int temp; for(int i = 0; i< FRAME_LEN; i++) { @@ -401,13 +401,13 @@ static void record_callback(uint8_t *buffer, int size, void *u) if (!vc.isVadRecongize) { return; } + [vc.pcmRecord addData:&aac_circularBuffer :trae_pcm_buffer :512]; */ //pcm=>aac - [vc.pcmRecord addData:&aac_circularBuffer :trae_pcm_buffer :512]; dispatch_async(vc.audioEncodeQueue, ^{ static int tmpChannelDataLen = 2048;//vc.pcmRecord.pcmStreamDescription.mChannelsPerFrame * 2048; - UInt32 aaclen = [vc.pcmRecord getData:&aac_circularBuffer :trae_aac_buffer :tmpChannelDataLen]; + UInt32 aaclen = [vc.pcmRecord getData:&pcm_circularBuffer :trae_aac_buffer :tmpChannelDataLen]; if (aaclen < tmpChannelDataLen) { return; } diff --git a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h index b5a0a71c..e9bf1773 100644 --- a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h +++ b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h @@ -43,8 +43,9 @@ extern NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd; /* * sdk 事件消息,事件对应类型与意义详见 XP2PType 类型说明 + * msg 事件详情 */ -- (void)reviceEventMsgWithID:(NSString *)dev_name eventType:(XP2PType)eventType; +- (void)reviceEventMsgWithID:(NSString *)dev_name eventType:(XP2PType)eventType msg:(const char*) msg; @end diff --git a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm index 10629865..455c2fc6 100644 --- a/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm +++ b/Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm @@ -96,8 +96,8 @@ - (void)cancelTimer; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ id delegate = [TIoTCoreXP2PBridge sharedInstance].delegate; - if ([delegate respondsToSelector:@selector(reviceEventMsgWithID:eventType:)]) { - [delegate reviceEventMsgWithID:DeviceName eventType:type]; + if ([delegate respondsToSelector:@selector(reviceEventMsgWithID:eventType:msg:)]) { + [delegate reviceEventMsgWithID:DeviceName eventType:type msg:msg]; } }); } @@ -116,23 +116,25 @@ void XP2PDataMsgHandle(const char *idd, uint8_t* recv_buf, size_t recv_len) { char *msg = (char *)recv_buf; printf("device feedback ==> %s\n",msg); - NSString *DeviceName = [NSString stringWithCString:idd encoding:[NSString defaultCStringEncoding]]?:@""; - NSData *DeviceData = [NSData dataWithBytes:recv_buf length:recv_len]; - + NSString *response = @"{\"status\":0}"; //默认返回值 + id delegate = [TIoTCoreXP2PBridge sharedInstance].delegate; if ([delegate respondsToSelector:@selector(reviceDeviceMsgWithID:data:)]) { - NSString *response = [delegate reviceDeviceMsgWithID:DeviceName data:DeviceData]; - if (response) { - NSUInteger length = strlen(response.UTF8String); - char *response_msg = (char *)malloc(length + 1); - strncpy(response_msg, response.UTF8String, length); - response_msg[length] = '\0'; - - return response_msg; + NSString *DeviceName = [NSString stringWithCString:idd encoding:[NSString defaultCStringEncoding]]?:@""; + NSData *DeviceData = [NSData dataWithBytes:recv_buf length:recv_len]; + NSString *res = [delegate reviceDeviceMsgWithID:DeviceName data:DeviceData]; + if (res) { + response = res; } } - return NULL; + + NSUInteger length = strlen(response.UTF8String); + char *response_msg = (char *)malloc(length + 1); + strncpy(response_msg, response.UTF8String, length); + response_msg[length] = '\0'; + + return response_msg; } typedef char *(*device_data_recv_handle_t)(const char *id, uint8_t *recv_buf, size_t recv_len); @@ -357,7 +359,7 @@ - (void)setupAVAudioSession:(TIoTCoreAudioConfig *)audio_config { } - (void)sendVoiceToServer:(NSString *)dev_name channel:(NSString *)channel_number audioConfig:(TIoTCoreAudioConfig *)audio_config videoConfig:(TIoTCoreVideoConfig *)video_config { - [self setupAVAudioSession:audio_config]; +// [self setupAVAudioSession:audio_config]; // NSString *audioFile = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"testVideoStreamfile.flv"]; // [[NSFileManager defaultManager] removeItemAtPath:audioFile error:nil]; // [[NSFileManager defaultManager] createFileAtPath:audioFile contents:nil attributes:nil]; @@ -465,11 +467,6 @@ - (XP2PErrCode)stopVoiceToServer { [systemAvCapture stopCapture]; int errorcode = stopSendService(self.dev_name.UTF8String, nullptr); - - AVAudioSession *avsession = [AVAudioSession sharedInstance]; - [avsession setCategory:AVAudioSessionCategoryAmbient withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil]; - [avsession setActive:YES error:nil]; - return (XP2PErrCode)errorcode; }