From cb9232b3ab413fae7bcc2b94abd70f18ca02b263 Mon Sep 17 00:00:00 2001
From: wxr <wxr@hdlchina.com.cn>
Date: 星期二, 03 十二月 2024 11:20:32 +0800
Subject: [PATCH] 增加铃声;增加TCP/UDP连接选择

---
 HDLLinPhoneSDK(OC)/HDLLinPhoneSDK/HDLLinphoneManager.m |  193 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 189 insertions(+), 4 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 f914edc..5e45b98 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;
@@ -164,6 +169,24 @@
 						   {"BV16", 8000, "bv16_preference"},
 						   {"CODEC2", 8000, "codec2_preference"},
 						   {NULL, 0, Nil}};
+
+-(void)disableVP8{
+    const MSList *codecs =  linphone_core_get_video_codecs(LC);
+    PayloadType *pt;
+    const MSList *elem;
+
+    for (elem = codecs; elem != NULL; elem = elem->next) {
+        pt = (PayloadType *)elem->data;
+        NSString *pref = [HDLLinphoneManager getPreferenceForCodec:pt->mime_type withRate:pt->clock_rate];
+//        NSLog(@"缂栫爜pref锛�%@",pref);
+        if([pref isEqualToString:@"vp8_preference"]){
+            linphone_core_enable_payload_type(LC, pt, FALSE);
+        }else{
+            linphone_core_enable_payload_type(LC, pt, TRUE);
+        }
+    }
+    
+}
 
 + (NSString *)getPreferenceForCodec:(const char *)name withRate:(int)rate {
 	int i;
@@ -544,6 +567,8 @@
     
     [self loadAssistantConfig:@"assistant_external_sip.rc"];
     
+    [self disableVP8];
+    
 }
 
 - (void)loadAssistantConfig:(NSString *)rcFilename {
@@ -564,6 +589,7 @@
 //    linphone_core_enable_video_capture([HDLLinphoneManager getLc], false);
 //    linphone_core_enable_video_preview([HDLLinphoneManager getLc], FALSE);
 
+    
 
 }
 
@@ -684,7 +710,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 {
 //    NSString *domain = [self findTextField:ViewElement_Domain].text;
 //    NSString *username = username;
     NSString *displayName = @"";
@@ -708,10 +734,134 @@
     // set transport
     NSString *type = @"UDP";
 //    NSString *type = @"TCP";
-    linphone_proxy_config_set_route(
+    linphone_proxy_config_set_routes(
                                     config,
                                     [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, type.lowercaseString.UTF8String]
                                     .UTF8String);
+    linphone_proxy_config_set_server_addr(
+                                          config,
+                                          [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, type.lowercaseString.UTF8String]
+                                          .UTF8String);
+
+    linphone_proxy_config_enable_publish(config, FALSE);
+    linphone_proxy_config_enable_register(config, TRUE);
+
+    LinphoneAuthInfo *info =
+        linphone_auth_info_new(linphone_address_get_username(addr), // username
+                               NULL,                                // user id
+                               pwd.UTF8String,                        // passwd
+                               NULL,                                // ha1
+                               linphone_address_get_domain(addr),   // realm - assumed to be domain
+                               linphone_address_get_domain(addr)    // domain
+                               );
+    linphone_core_add_auth_info(LC, info);
+    linphone_address_unref(addr);
+    linphone_address_unref(tmpAddr);
+
+    if (config) {
+        [[HDLLinphoneManager instance] configurePushTokenForProxyConfig:config];
+        if (linphone_core_add_proxy_config(LC, config) != -1) {
+            linphone_core_set_default_proxy_config(LC, config);
+            // reload address book to prepend proxy config domain to contacts' phone number
+            // todo: STOP doing that!
+//            [[LinphoneManager.instance fastAddressBook] fetchContactsInBackGroundThread];
+//            [PhoneMainView.instance changeCurrentView:DialerView.compositeViewDescription];
+            NSLog(@"鐧诲綍鎴愬姛浜嗭紵");
+        } else {
+//          [self displayAssistantConfigurationError];
+        }
+    } else {
+//      [self displayAssistantConfigurationError];
+    }
+}
+
+- (void)tcpLogin:(NSString*)username password:(NSString*)pwd domain:(NSString*) domain {
+    NSString *displayName = @"";
+    LinphoneProxyConfig *config = linphone_core_create_proxy_config(LC);
+    LinphoneAddress *addr = linphone_address_new(NULL);
+    LinphoneAddress *tmpAddr = linphone_address_new([NSString stringWithFormat:@"sip:%@",domain].UTF8String);
+    if (tmpAddr == nil) {
+        return;
+    }
+    
+    linphone_address_set_username(addr, username.UTF8String);
+    linphone_address_set_port(addr, linphone_address_get_port(tmpAddr));
+    linphone_address_set_domain(addr, linphone_address_get_domain(tmpAddr));
+    if (displayName && ![displayName isEqualToString:@""]) {
+        linphone_address_set_display_name(addr, displayName.UTF8String);
+    }
+    linphone_proxy_config_set_identity_address(config, addr);
+
+    NSString *type = @"TCP";
+//    linphone_proxy_config_set_routes(
+//                                    config,
+//                                    [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, type.lowercaseString.UTF8String]
+//                                    .UTF8String);
+    
+    // 鍒涘缓涓�涓矾鐢卞垪琛�
+    bctbx_list_t *routes = NULL;
+    
+    // 娣诲姞璺敱鍒板垪琛ㄤ腑
+    routes = bctbx_list_append(routes, (void *)tmpAddr);
+    
+    
+    // 璁剧疆璺敱
+    linphone_proxy_config_set_routes(config, routes);
+    
+    
+    linphone_proxy_config_set_server_addr(
+                                          config,
+                                          [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, type.lowercaseString.UTF8String]
+                                          .UTF8String);
+
+    linphone_proxy_config_enable_publish(config, FALSE);
+    linphone_proxy_config_enable_register(config, TRUE);
+
+    LinphoneAuthInfo *info =
+        linphone_auth_info_new(linphone_address_get_username(addr), // username
+                               NULL,                                // user id
+                               pwd.UTF8String,                        // passwd
+                               NULL,                                // ha1
+                               linphone_address_get_domain(addr),   // realm - assumed to be domain
+                               linphone_address_get_domain(addr)    // domain
+                               );
+    linphone_core_add_auth_info(LC, info);
+    linphone_address_unref(addr);
+    linphone_address_unref(tmpAddr);
+
+    if (config) {
+        [[HDLLinphoneManager instance] configurePushTokenForProxyConfig:config];
+        if (linphone_core_add_proxy_config(LC, config) != -1) {
+            linphone_core_set_default_proxy_config(LC, config);
+            NSLog(@"鐧诲綍鎴愬姛浜嗭紵");
+        } else {
+        }
+    } else {
+    }
+}
+
+- (void)udpLogin:(NSString*)username password:(NSString*)pwd domain:(NSString*) domain {
+    NSString *displayName = @"";
+    LinphoneProxyConfig *config = linphone_core_create_proxy_config(LC);
+    LinphoneAddress *addr = linphone_address_new(NULL);
+    LinphoneAddress *tmpAddr = linphone_address_new([NSString stringWithFormat:@"sip:%@",domain].UTF8String);
+    if (tmpAddr == nil) {
+        return;
+    }
+    
+    linphone_address_set_username(addr, username.UTF8String);
+    linphone_address_set_port(addr, linphone_address_get_port(tmpAddr));
+    linphone_address_set_domain(addr, linphone_address_get_domain(tmpAddr));
+    if (displayName && ![displayName isEqualToString:@""]) {
+        linphone_address_set_display_name(addr, displayName.UTF8String);
+    }
+    linphone_proxy_config_set_identity_address(config, addr);
+
+    NSString *type = @"UDP";
+//    linphone_proxy_config_set_routes(
+//                                    config,
+//                                    [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, type.lowercaseString.UTF8String]
+//                                    .UTF8String);
     linphone_proxy_config_set_server_addr(
                                           config,
                                           [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, type.lowercaseString.UTF8String]
@@ -832,7 +982,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
@@ -1153,12 +1303,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*/
@@ -1179,6 +1339,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];
@@ -1196,7 +1381,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",

--
Gitblit v1.8.0