From a616abd9b740e74eb7aea29cb692ca86ba1f7d7a Mon Sep 17 00:00:00 2001 From: wxr <wxr@hdlchina.com.cn> Date: 星期二, 27 八月 2024 15:24:54 +0800 Subject: [PATCH] 增加铃声功能 --- HDLLinPhoneSDK(OC)/HDLLinPhoneSDK/HDLLinphoneManager.m | 180 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 134 insertions(+), 46 deletions(-) diff --git "a/HDLLinPhoneSDK\357\274\210OC\357\274\211/HDLLinPhoneSDK/HDLLinphoneManager.m" "b/HDLLinPhoneSDK\357\274\210OC\357\274\211/HDLLinPhoneSDK/HDLLinphoneManager.m" index d3cfbdc..f4a77b3 100644 --- "a/HDLLinPhoneSDK\357\274\210OC\357\274\211/HDLLinPhoneSDK/HDLLinphoneManager.m" +++ "b/HDLLinPhoneSDK\357\274\210OC\357\274\211/HDLLinPhoneSDK/HDLLinphoneManager.m" @@ -54,6 +54,8 @@ //#import "configManager.h" #import "HDLLinphoneLog.h" +#import "HDLLinphoneTimerManager.h" + #define LINPHONE_LOGS_MAX_ENTRY 5000 @@ -68,6 +70,9 @@ #define kIAPReady @"IAPReady" // no data #define IPAD (HDLLinphoneManager.runningOnIpad) + +#define RESET_VIDEO_ENABLE_TIMER_NAME @"hdlLinphoneVideoEnableTimer" //閲嶈瑙嗛寮�璁℃椂鍣ㄥ悕绉� +#define RESET_VIDEO_DISABLE_TIMER_NAME @"hdlLinphoneVideoDisableTimer" //閲嶈瑙嗛鍏宠鏃跺櫒鍚嶇О static LinphoneCore *theLinphoneCore = nil; static HDLLinphoneManager *theLinphoneManager = nil; @@ -268,7 +273,7 @@ name:AVAudioSessionRouteChangeNotification object:nil]; - NSString *path = [[NSBundle mainBundle] pathForResource:@"msg" ofType:@"wav"]; + NSString *path = [[NSBundle mainBundle] pathForResource:@"msg" ofType:@"caf"]; self.messagePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path] error:nil]; _sounds.vibrate = kSystemSoundID_Vibrate; @@ -423,7 +428,8 @@ withDefault:@"sip.linphone.org"] .UTF8String) != 0) { // LOGI(@"Migrating proxy config to use AVPF"); - linphone_proxy_config_enable_avpf(proxy, TRUE); +// linphone_proxy_config_enable_avpf(proxy, TRUE); + linphone_proxy_config_set_avpf_mode(proxy,LinphoneAVPFEnabled); } proxies = proxies->next; } @@ -521,11 +527,12 @@ NSError *err = nil; if (![audioSession setActive:NO error:&err] && err) { - + NSLog(@"audio鍚姩澶辫触"); err = nil; } if (!bAudioInputAvailable) { - + NSLog(@"璁惧涓嶆敮鎸乤udio"); + } } @@ -682,7 +689,7 @@ // linphone_core_enable_mic(LC, false); } -- (void)login:(NSString*)username password:(NSString*)pwd domain:(NSString*) domain{ +- (void)login:(NSString*)username password:(NSString*)pwd domain:(NSString*) domain connectType:(NSString*)connectType{ // NSString *domain = [self findTextField:ViewElement_Domain].text; // NSString *username = username; NSString *displayName = @""; @@ -704,14 +711,15 @@ linphone_proxy_config_set_identity_address(config, addr); // set transport - NSString *type = @"UDP"; +// NSString *type = @"UDP"; +// NSString *type = @"TCP"; linphone_proxy_config_set_route( config, - [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, type.lowercaseString.UTF8String] + [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, connectType.lowercaseString.UTF8String] .UTF8String); linphone_proxy_config_set_server_addr( config, - [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, type.lowercaseString.UTF8String] + [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, connectType.lowercaseString.UTF8String] .UTF8String); linphone_proxy_config_enable_publish(config, FALSE); @@ -767,12 +775,12 @@ #pragma mark Debug functions + (void)dumpLcConfig { - if (theLinphoneCore) { - LpConfig *conf = HDLLinphoneManager.instance.configDb; - char *config = lp_config_dump(conf); -// LOGI(@"\n%s", config); - ms_free(config); - } +// if (theLinphoneCore) { +// LpConfig *conf = HDLLinphoneManager.instance.configDb; +// char *config = lp_config_dump(conf); +//// LOGI(@"\n%s", config); +// ms_free(config); +// } } #pragma mark - Logs Functions handlers @@ -829,7 +837,7 @@ - (void)onCall:(LinphoneCall *)call StateChanged:(LinphoneCallState)state withMessage:(const char *)message { - NSLog(@"鍛煎彨鐘舵�侊細%u",state); + NSLog(@"鍛煎彨鐘舵�侊細%u,淇℃伅锛�%s",state,message); HDLLinPhoneSDK.instance.IsIncomingReceivedCallState=false; // Handling wrapper @@ -853,8 +861,10 @@ // NSString *address = [FastAddressBook displayNameForAddress:addr]; NSString *address=@""; if (state == LinphoneCallIncomingReceived) { + HDLLinPhoneSDK.instance.IsIncomingReceivedCallState=true; [HDLLinphoneManager.instance enableMicro:true]; + // LinphoneCallLog *callLog = linphone_call_get_call_log(call); // NSString *callId = [NSString stringWithUTF8String:linphone_call_log_get_call_id(callLog)]; // int index = [(NSNumber *)[_pushDict objectForKey:callId] intValue] - 1; @@ -1011,7 +1021,7 @@ if (state==LinphoneCallStateOutgoingProgress) { NSLog(@"绂佹楹﹀厠椋�"); - [HDLLinphoneManager.instance enableMicro:false]; +// [HDLLinphoneManager.instance enableMicro:false]; } // Disable speaker when no more call if ((state == LinphoneCallEnd || state == LinphoneCallError)) { @@ -1148,12 +1158,22 @@ speaker_already_enabled = TRUE; } } + + if( state == LinphoneCallConnected ){ + NSLog(@"杩炴帴浜�"); +// [self enableVideoPlay:TRUE]; + } + if (state == LinphoneCallStreamsRunning) { if (_speakerBeforePause) { _speakerBeforePause = FALSE; [self setSpeakerEnabled:TRUE]; speaker_already_enabled = TRUE; } + if (!self.isResettingVideoEnable&&self.deviceType==HDLLPType_HDLSR) { + self.isResettingVideoEnable=YES; + [self resetVideoEnable]; + } } if (state == LinphoneCallConnected && !mCallCenter) { /*only register CT call center CB for connected call*/ @@ -1174,6 +1194,31 @@ userInfo:dict]; } +/*閲嶆柊鎷夊彇瑙嗛娴侊紙瑙e喅鑷爺鍙瀵硅鍋跺皵鍑虹幇瑙嗛娴佹媺鍙栧緢鎱㈢殑闂锛� + */ +-(void)resetVideoEnable{ + NSLog(@"閲嶇疆瑙嗛寮�鍏�"); + __weak typeof(self) weakSelf = self; + [self enableVideoPlay:TRUE]; +// [self enableVideoPlay:FALSE]; +// [[HDLLinphoneTimerManager sharedInstance] scheduleTimerWithInterval:0.5 timerName:RESET_VIDEO_ENABLE_TIMER_NAME count:^(double count) { +// +// } finished:^{ +// NSLog(@"鎵撳紑瑙嗛"); +// [weakSelf enableVideoPlay:TRUE]; +// }]; +} + +/*鏄惁鍏佽瑙嗛鎾斁 + */ +-(void)enableVideoPlay:(bool_t)enable{ + LinphoneCall *call = linphone_core_get_current_call(LC); + LinphoneCallParams *call_params = linphone_core_create_call_params(LC,call); + linphone_call_params_enable_video(call_params, enable); + linphone_call_update(call, call_params); + linphone_call_params_unref(call_params); +} + static void linphone_iphone_call_state(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState state, const char *message) { [(__bridge HDLLinphoneManager *)linphone_core_cbs_get_user_data(linphone_core_get_current_callbacks(lc)) onCall:call StateChanged:state withMessage:message]; @@ -1191,7 +1236,7 @@ } - (void)onGlobalStateChanged:(LinphoneGlobalState)state withMessage:(const char *)message { -// LOGI(@"onGlobalStateChanged: %d (message: %s)", state, message); + LOGI(@"onGlobalStateChanged: %d (message: %s)", state, message); NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:state], @"state", @@ -2134,18 +2179,26 @@ linphone_core_cbs_set_user_data(cbs, (__bridge void *)(self)); // NSLog(@"Creating linphonecore1:%@",_configDb); - lp_config_set_int(_configDb, [@"app" UTF8String], [@"random_port_preference" UTF8String], 1); - +// lp_config_set_int(_configDb, [@"app" UTF8String], [@"random_port_preference" UTF8String], 1); + linphone_config_set_int(_configDb, [@"app" UTF8String], [@"random_port_preference" UTF8String], 1); theLinphoneCore = linphone_factory_create_core_with_config_3(factory, _configDb, NULL); linphone_core_add_callbacks(theLinphoneCore, cbs); - linphone_core_start(theLinphoneCore); +// linphone_core_start(theLinphoneCore); //璁剧疆涓洪殢鏈虹鍙� LinphoneSipTransports transportValue = {-1, -1, -1, -1}; // will also update the sip_*_port section of the config if (linphone_core_set_sip_transports(theLinphoneCore, &transportValue)) { - LOGE(@"cannot set transport"); + NSLog(@"cannot set transport"); } + // + linphone_core_set_network_reachable(theLinphoneCore,TRUE); +// +// AudioStream*stream=audio_stream_new(ms_factory_new(), -1, -1, TRUE); +// audio_stream_enable_gain_control(stream, TRUE); + + linphone_core_start(theLinphoneCore); + [self removeAllAccounts]; // Let the core handle cbs @@ -2196,6 +2249,16 @@ // start scheduler mIterateTimer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(iterate) userInfo:nil repeats:YES]; + + +// //鑷姩鍚姩鍜屾帴鏀秜ideo +// NSLog(@"璁剧疆鑷姩璁剧疆"); +// LinphoneVideoPolicy policy; +// policy.automatically_initiate = true; +// policy.automatically_accept =true; +// linphone_core_set_video_policy(theLinphoneCore, &policy); +// LinphoneVideoActivationPolicy policy; +// linphone_video_activation_policy_set_automatically_accept(&policy,true); } //-(void)appWillTerminate{ @@ -2586,10 +2649,15 @@ } - (void)migrateImportantFiles { - if ([HDLLinphoneManager copyFile:[HDLLinphoneManager documentFile:@"linphonerc"] destination:[HDLLinphoneManager preferenceFile:@"linphonerc"] override:TRUE ignore:TRUE]) - [NSFileManager.defaultManager - removeItemAtPath:[HDLLinphoneManager documentFile:@"linphonerc"] - error:nil]; +// if ([HDLLinphoneManager copyFile:[HDLLinphoneManager documentFile:@"linphonerc"] destination:[HDLLinphoneManager preferenceFile:@"linphonerc"] override:TRUE ignore:TRUE]) +// [NSFileManager.defaultManager +// removeItemAtPath:[HDLLinphoneManager documentFile:@"linphonerc"] +// error:nil]; + //涓嶄娇鐢ㄩ厤缃枃浠剁殑閰嶇疆 + NSFileManager *fileManager = NSFileManager.defaultManager; + NSError *error = nil; + [fileManager removeItemAtPath:[HDLLinphoneManager preferenceFile:@"linphonerc"] error:&error]; + if ([HDLLinphoneManager copyFile:[HDLLinphoneManager documentFile:@"linphone_chats.db"] destination:[HDLLinphoneManager dataFile:@"linphone_chats.db"] override:TRUE ignore:TRUE]) [NSFileManager.defaultManager @@ -2621,7 +2689,7 @@ LOGW(@"%@ already exists, simply removing %@ %@", dst, src, fileError ? fileError.localizedDescription : @"successfully"); } else { - [fileManager moveItemAtPath:src toPath:dst error:&fileError]; +// [fileManager moveItemAtPath:src toPath:dst error:&fileError]; LOGI(@"%@ moving to %@ %@", dst, src, fileError ? fileError.localizedDescription : @"successfully"); } } @@ -2634,7 +2702,7 @@ src = srcIpad; } NSString *dst = [HDLLinphoneManager preferenceFile:@"linphonerc"]; - [HDLLinphoneManager copyFile:src destination:dst override:FALSE ignore:FALSE]; +// [HDLLinphoneManager copyFile:src destination:dst override:FALSE ignore:FALSE]; } - (void)overrideDefaultSettings { @@ -2644,7 +2712,9 @@ // factory = factoryIpad; // } NSString *confiFileName = [HDLLinphoneManager preferenceFile:@"linphonerc"]; - _configDb = lp_config_new_with_factory([confiFileName UTF8String], [factory UTF8String]); + + _configDb = linphone_config_new_with_factory([confiFileName UTF8String], [factory UTF8String]); + } #pragma mark - Audio route Functions @@ -2897,7 +2967,8 @@ } } linphone_address_destroy(addr); - linphone_call_params_destroy(lcallParams); +// linphone_call_params_destroy(lcallParams); + linphone_call_params_unref(lcallParams); return TRUE; } @@ -3089,19 +3160,33 @@ } - (void)configureVbrCodecs { - PayloadType *pt; - int bitrate = lp_config_get_int( - _configDb, "audio", "codec_bitrate_limit", - kLinphoneAudioVbrCodecDefaultBitrate); /*default value is in linphonerc or linphonerc-factory*/ - const MSList *audio_codecs = linphone_core_get_audio_codecs(theLinphoneCore); - const MSList *codec = audio_codecs; - while (codec) { - pt = codec->data; - if (linphone_core_payload_type_is_vbr(theLinphoneCore, pt)) { - linphone_core_set_payload_type_bitrate(theLinphoneCore, pt, bitrate); - } - codec = codec->next; - } +// PayloadType *pt; +// int bitrate = linphone_config_get_int( +// _configDb, "audio", "codec_bitrate_limit", +// kLinphoneAudioVbrCodecDefaultBitrate); /*default value is in linphonerc or linphonerc-factory*/ +// const MSList *audio_codecs = linphone_core_get_audio_codecs(theLinphoneCore); +// const MSList *codec = audio_codecs; +// while (codec) { +// pt = codec->data; +// if (linphone_core_payload_type_is_vbr(theLinphoneCore, pt)) { +// linphone_core_set_payload_type_bitrate(theLinphoneCore, pt, bitrate); +// } +// codec = codec->next; +// } + + PayloadType *pt; + int bitrate = linphone_config_get_int( + _configDb, "audio", "codec_bitrate_limit", + kLinphoneAudioVbrCodecDefaultBitrate); /*default value is in linphonerc or linphonerc-factory*/ + const MSList *audio_codecs = linphone_core_get_audio_payload_types(theLinphoneCore); + const MSList *codec = audio_codecs; + while (codec) { + pt = codec->data; + if (linphone_core_payload_type_is_vbr(theLinphoneCore, pt)) { + linphone_core_set_payload_type_bitrate(theLinphoneCore, pt, bitrate); + } + codec = codec->next; + } } + (id)getMessageAppDataForKey:(NSString *)key inMessage:(LinphoneChatMessage *)msg { @@ -3145,7 +3230,9 @@ - (void)lpConfigSetString:(NSString *)value forKey:(NSString *)key inSection:(NSString *)section { if (!key) return; - lp_config_set_string(_configDb, [section UTF8String], [key UTF8String], value ? [value UTF8String] : NULL); +// lp_config_set_string(_configDb, [section UTF8String], [key UTF8String], value ? [value UTF8String] : NULL); + linphone_config_set_string(_configDb, [section UTF8String], [key UTF8String], value ? [value UTF8String] : NULL); + } - (NSString *)lpConfigStringForKey:(NSString *)key { return [self lpConfigStringForKey:key withDefault:nil]; @@ -3159,7 +3246,8 @@ - (NSString *)lpConfigStringForKey:(NSString *)key inSection:(NSString *)section withDefault:(NSString *)defaultValue { if (!key) return defaultValue; - const char *value = lp_config_get_string(_configDb, [section UTF8String], [key UTF8String], NULL); +// const char *value = lp_config_get_string(_configDb, [section UTF8String], [key UTF8String], NULL); + const char *value = linphone_config_get_string(_configDb, [section UTF8String], [key UTF8String], NULL); return value ? [NSString stringWithUTF8String:value] : defaultValue; } @@ -3169,7 +3257,7 @@ - (void)lpConfigSetInt:(int)value forKey:(NSString *)key inSection:(NSString *)section { if (!key) return; - lp_config_set_int(_configDb, [section UTF8String], [key UTF8String], (int)value); + linphone_config_set_int(_configDb, [section UTF8String], [key UTF8String], (int)value); } - (int)lpConfigIntForKey:(NSString *)key { return [self lpConfigIntForKey:key withDefault:-1]; @@ -3183,7 +3271,7 @@ - (int)lpConfigIntForKey:(NSString *)key inSection:(NSString *)section withDefault:(int)defaultValue { if (!key) return defaultValue; - return lp_config_get_int(_configDb, [section UTF8String], [key UTF8String], (int)defaultValue); + return linphone_config_get_int(_configDb, [section UTF8String], [key UTF8String], (int)defaultValue); } - (void)lpConfigSetBool:(BOOL)value forKey:(NSString *)key { -- Gitblit v1.8.0