1313NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd = @" XP2PTypeStreamEnd" ; // 设备主动停止推流,或者由于达到设备最大连接数,拒绝推流
1414
1515NSFileHandle *p2pOutLogFile;
16- NSFileHandle *fileHandle;
16+ // NSFileHandle *fileHandle;
1717
1818@interface TIoTCoreXP2PBridge ()<TIoTAVCaptionFLVDelegate>
1919@property (nonatomic , strong ) NSString *dev_name;
@@ -28,18 +28,18 @@ - (void)cancelTimer;
2828 return nullptr ;
2929 }
3030 NSString *message = [NSString stringWithCString: msg encoding: [NSString defaultCStringEncoding ]];
31- // BOOL logEnable = [TIoTCoreXP2PBridge sharedInstance].logEnable;
32- // if (logEnable) {
33- // NSLog(@"XP2P log: %@\n", message);
34- // }
35- //
36- // if (type == XP2PTypeLog) {
37- // if (logEnable) {
38- // dispatch_async(dispatch_get_main_queue(), ^{
39- // [p2pOutLogFile writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
40- // });
41- // }
42- // }
31+ BOOL logEnable = [TIoTCoreXP2PBridge sharedInstance ].logEnable ;
32+ if (logEnable) {
33+ NSLog (@" XP2P log: %@ \n " , message);
34+ }
35+
36+ if (type == XP2PTypeLog) {
37+ if (logEnable) {
38+ dispatch_async (dispatch_get_main_queue (), ^{
39+ [p2pOutLogFile writeData: [message dataUsingEncoding: NSUTF8StringEncoding]];
40+ });
41+ }
42+ }
4343
4444 NSString *DeviceName = [NSString stringWithCString: idd encoding: [NSString defaultCStringEncoding ]]?:@" " ;
4545
@@ -192,8 +192,8 @@ + (instancetype)sharedInstance {
192192- (instancetype )init {
193193 self = [super init ];
194194 if (self) {
195- // 默认打开log开关
196- _logEnable = YES ;
195+ // 默认关log开关
196+ _logEnable = NO ;
197197
198198 NSString *logFile = [[NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES ) lastObject ] stringByAppendingPathComponent: @" TIoTXP2P.log" ];
199199 [[NSFileManager defaultManager ] removeItemAtPath: logFile error: nil ];
@@ -319,10 +319,14 @@ - (void)sendVoiceToServer:(NSString *)dev_name channel:(NSString *)channel_numbe
319319}
320320
321321- (void )sendVoiceToServer : (NSString *)dev_name channel : (NSString *)channel_number audioConfig : (TIoTAVCaptionFLVAudioType)audio_rate withLocalPreviewView : (UIView *)localView videoPosition : (AVCaptureDevicePosition)videoPosition {
322- NSString *audioFile = [[NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES ) lastObject ] stringByAppendingPathComponent: @" testVideoStreamfile.flv" ];
323- [[NSFileManager defaultManager ] removeItemAtPath: audioFile error: nil ];
324- [[NSFileManager defaultManager ] createFileAtPath: audioFile contents: nil attributes: nil ];
325- fileHandle = [NSFileHandle fileHandleForWritingAtPath: audioFile];
322+ [self sendVoiceToServer: dev_name channel: channel_number audioConfig: audio_rate withLocalPreviewView: localView videoPosition: videoPosition isEchoCancel: NO ];
323+ }
324+
325+ - (void )sendVoiceToServer : (NSString *)dev_name channel : (NSString *)channel_number audioConfig : (TIoTAVCaptionFLVAudioType)audio_rate withLocalPreviewView : (UIView *)localView videoPosition : (AVCaptureDevicePosition)videoPosition isEchoCancel : (BOOL )isEchoCancel {
326+ // NSString *audioFile = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"testVideoStreamfile.flv"];
327+ // [[NSFileManager defaultManager] removeItemAtPath:audioFile error:nil];
328+ // [[NSFileManager defaultManager] createFileAtPath:audioFile contents:nil attributes:nil];
329+ // fileHandle = [NSFileHandle fileHandleForWritingAtPath:audioFile];
326330
327331 self.isSending = YES ;
328332
@@ -334,7 +338,7 @@ - (void)sendVoiceToServer:(NSString *)dev_name channel:(NSString *)channel_numbe
334338 if (systemAvCapture == nil ) {
335339 systemAvCapture = [[TIoTAVCaptionFLV alloc ] initWithAudioConfig: audio_rate];
336340 systemAvCapture.videoLocalView = localView;
337- systemAvCapture.isEchoCancel = YES ;
341+ systemAvCapture.isEchoCancel = isEchoCancel ;
338342 }
339343 systemAvCapture.devicePosition = videoPosition;
340344 systemAvCapture.videoLocalView = localView;
@@ -348,7 +352,9 @@ - (void)sendVoiceToServer:(NSString *)dev_name channel:(NSString *)channel_numbe
348352 _p2p_wl_avg_ctx.len = MAX_AVG_LENGTH;
349353 // 每次send时,先销毁之前已存在timer,保证多次send内部只持有一个timer
350354 [self cancelTimer ];
351- _getBufTimer = [NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @selector (getSendBufSize ) userInfo: nil repeats: YES ];
355+ if (localView != nil ) {
356+ _getBufTimer = [NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @selector (getSendBufSize ) userInfo: nil repeats: YES ];
357+ }
352358}
353359
354360
@@ -365,7 +371,7 @@ - (void)getSendBufSize {
365371// for (int i =0; i < _p2p_wl_avg_ctx.len; i++) {
366372// printf("\n stream_buf_con==%d \n",_p2p_wl_avg_ctx.buf[i]);
367373// }
368- NSLog (@" send_bufsize==%d , now_video_rate==%d , avg_index==%d " ,bufsize, now_video_rate, p2p_wl_avg);
374+ // NSLog(@"send_bufsize==%d, now_video_rate==%d, avg_index==%d",bufsize, now_video_rate, p2p_wl_avg);
369375
370376 // 降码率
371377 // 当发现p2p的水线超过一定值时,降低视频码率,这是一个经验值,一般来说要大于 [视频码率/2]
@@ -391,6 +397,11 @@ - (void)resolutionRatio:(AVCaptureSessionPreset)resolutionValue {
391397 self.resolution = resolutionValue;
392398}
393399
400+ - (void )refreshLocalView : (UIView *)localView {
401+ systemAvCapture.videoLocalView = localView;
402+ [systemAvCapture refreshLocalPreviewView ];
403+ }
404+
394405- (void )changeCameraPositon {
395406 [systemAvCapture changeCameraPositon ];
396407}
@@ -416,8 +427,8 @@ - (void)stopService:(NSString *)dev_name {
416427
417428 [p2pOutLogFile synchronizeFile ];
418429 // 关闭文件
419- [fileHandle closeFile ];
420- fileHandle = NULL ;
430+ // [fileHandle closeFile];
431+ // fileHandle = NULL;
421432}
422433
423434- (void )cancelTimer {
0 commit comments