wxr
2024-12-03 cb9232b3ab413fae7bcc2b94abd70f18ca02b263
HDLLinPhoneSDK£¨OC£©/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;
@@ -139,7 +144,7 @@
   const char *prefname;
};
struct codec_name_pref_table codec_pref_table[] = {{"speex", 8000, "speex_8k_preference"},
struct codec_name_pref_table hdl_codec_pref_table[] = {{"speex", 8000, "speex_8k_preference"},
                     {"speex", 16000, "speex_16k_preference"},
                     {"silk", 24000, "silk_24k_preference"},
                     {"silk", 16000, "silk_16k_preference"},
@@ -165,25 +170,43 @@
                     {"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;
   for (i = 0; codec_pref_table[i].name != NULL; ++i) {
      if (strcasecmp(codec_pref_table[i].name, name) == 0 && codec_pref_table[i].rate == rate)
         return [NSString stringWithUTF8String:codec_pref_table[i].prefname];
   for (i = 0; hdl_codec_pref_table[i].name != NULL; ++i) {
      if (strcasecmp(hdl_codec_pref_table[i].name, name) == 0 && hdl_codec_pref_table[i].rate == rate)
         return [NSString stringWithUTF8String:hdl_codec_pref_table[i].prefname];
   }
   return Nil;
}
+ (NSSet *)unsupportedCodecs {
   NSMutableSet *set = [NSMutableSet set];
   for (int i = 0; codec_pref_table[i].name != NULL; ++i) {
   for (int i = 0; hdl_codec_pref_table[i].name != NULL; ++i) {
      PayloadType *available = linphone_core_find_payload_type(
                            theLinphoneCore, codec_pref_table[i].name, codec_pref_table[i].rate, LINPHONE_FIND_PAYLOAD_IGNORE_CHANNELS);
                            theLinphoneCore, hdl_codec_pref_table[i].name, hdl_codec_pref_table[i].rate, LINPHONE_FIND_PAYLOAD_IGNORE_CHANNELS);
      if ((available == NULL)
          // these two codecs should not be hidden, even if not supported
          && strcmp(codec_pref_table[i].prefname, "h264_preference") != 0 &&
          strcmp(codec_pref_table[i].prefname, "mp4v-es_preference") != 0) {
         [set addObject:[NSString stringWithUTF8String:codec_pref_table[i].prefname]];
          && strcmp(hdl_codec_pref_table[i].prefname, "h264_preference") != 0 &&
          strcmp(hdl_codec_pref_table[i].prefname, "mp4v-es_preference") != 0) {
         [set addObject:[NSString stringWithUTF8String:hdl_codec_pref_table[i].prefname]];
      }
   }
   return set;
@@ -268,7 +291,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 +446,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 +545,12 @@
    NSError *err = nil;
    
    if (![audioSession setActive:NO error:&err] && err) {
        NSLog(@"audio启动失败");
        err = nil;
    }
    if (!bAudioInputAvailable) {
        NSLog(@"设备不支持audio");
    }
}
@@ -541,6 +566,8 @@
//    }
    
    [self loadAssistantConfig:@"assistant_external_sip.rc"];
    [self disableVP8];
    
}
@@ -559,7 +586,10 @@
    linphone_core_set_preferred_video_size([HDLLinphoneManager getLc], vsize);
    linphone_core_set_video_preset([HDLLinphoneManager getLc], [@"custom" UTF8String]);
    linphone_core_set_preferred_framerate([HDLLinphoneManager getLc], 5);
//    linphone_core_enable_video_capture([HDLLinphoneManager getLc], false);
//    linphone_core_enable_video_preview([HDLLinphoneManager getLc], FALSE);
}
@@ -680,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 = @"";
@@ -703,10 +733,135 @@
    // set transport
    NSString *type = @"UDP";
    linphone_proxy_config_set_route(
//    NSString *type = @"TCP";
    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]
@@ -765,12 +920,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
@@ -827,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
@@ -851,8 +1006,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;
@@ -1009,7 +1166,7 @@
    if (state==LinphoneCallStateOutgoingProgress) {
        NSLog(@"禁止麦克风");
        [HDLLinphoneManager.instance enableMicro:false];
//        [HDLLinphoneManager.instance enableMicro:false];
    }
   // Disable speaker when no more call
   if ((state == LinphoneCallEnd || state == LinphoneCallError)) {
@@ -1063,45 +1220,45 @@
            : @"";
         NSUUID *uuid = (NSUUID *)[self.providerDelegate.uuids objectForKey:callId2];
         if (uuid) {
            LinphoneCall *callKit_call = (LinphoneCall *)linphone_core_get_calls(LC)
            LinphoneCall *callK_call = (LinphoneCall *)linphone_core_get_calls(LC)
               ? linphone_core_get_calls(LC)->data
               : NULL;
            const char *callKit_callId = callKit_call
               ? linphone_call_log_get_call_id(linphone_call_get_call_log(callKit_call))
            const char *call_callId = callK_call
               ? linphone_call_log_get_call_id(linphone_call_get_call_log(callK_call))
               : NULL;
            if (callKit_callId && !_conf) {
            if (call_callId && !_conf) {
               // Create a CallKit call because there's not !
               NSString *callKit_callIdNS = [NSString stringWithUTF8String:callKit_callId];
               NSUUID *callKit_uuid = [NSUUID UUID];
               [HDLLinphoneManager.instance.providerDelegate.uuids setObject:callKit_uuid forKey:callKit_callIdNS];
               [HDLLinphoneManager.instance.providerDelegate.calls setObject:callKit_callIdNS forKey:callKit_uuid];
               NSString *callK_callIdNS = [NSString stringWithUTF8String:call_callId];
               NSUUID *callK_uuid = [NSUUID UUID];
               [HDLLinphoneManager.instance.providerDelegate.uuids setObject:callK_uuid forKey:callK_callIdNS];
               [HDLLinphoneManager.instance.providerDelegate.calls setObject:callK_callIdNS forKey:callK_uuid];
//               NSString *address = [FastAddressBook displayNameForAddress:linphone_call_get_remote_address(callKit_call)];
                    NSString *address=@"";
               CXHandle *handle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:address];
               CXStartCallAction *act = [[CXStartCallAction alloc] initWithCallUUID:callKit_uuid handle:handle];
               CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
               [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr completion:^(NSError *err){}];
               [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:callKit_uuid startedConnectingAtDate:nil];
               [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:callKit_uuid connectedAtDate:nil];
//                    NSString *address=@"";
//               CXHandle *handle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:address];
//               CXStartCallAction *act = [[CXStartCallAction alloc] initWithCallUUID:callKit_uuid handle:handle];
//               CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
//               [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr completion:^(NSError *err){}];
//               [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:callKit_uuid startedConnectingAtDate:nil];
//               [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:callKit_uuid connectedAtDate:nil];
            }
            CXEndCallAction *act = [[CXEndCallAction alloc] initWithCallUUID:uuid];
            CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
            [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr completion:^(NSError *err){}];
            LOGI(@"CallKit - clearing CK as call ended on uuid %@",uuid);
            [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:uuid connectedAtDate:[NSDate date]];
            [self.providerDelegate.uuids removeObjectForKey:callId2];
            [self.providerDelegate.calls removeObjectForKey:uuid];
            [self.providerDelegate.provider reportCallWithUUID:uuid endedAtDate:[NSDate date] reason:(state == LinphoneCallError ? CXCallEndedReasonFailed : CXCallEndedReasonRemoteEnded)];
//            CXEndCallAction *act = [[CXEndCallAction alloc] initWithCallUUID:uuid];
//            CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
//            [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr completion:^(NSError *err){}];
//            LOGI(@"CallKit - clearing CK as call ended on uuid %@",uuid);
//            [HDLLinphoneManager.instance.providerDelegate.provider reportOutgoingCallWithUUID:uuid connectedAtDate:[NSDate date]];
//            [self.providerDelegate.uuids removeObjectForKey:callId2];
//            [self.providerDelegate.calls removeObjectForKey:uuid];
//            [self.providerDelegate.provider reportCallWithUUID:uuid endedAtDate:[NSDate date] reason:(state == LinphoneCallError ? CXCallEndedReasonFailed : CXCallEndedReasonRemoteEnded)];
         } else { // Can happen when Call-ID changes (Replaces header)
            if (linphone_core_get_calls_nb(LC) ==0) { // Need to clear all CK calls
               for (NSUUID *myUuid in self.providerDelegate.calls) {
                  [self.providerDelegate.provider reportCallWithUUID:myUuid
                   endedAtDate:NULL
                   reason:(state == LinphoneCallError
                      ? CXCallEndedReasonFailed
                      : CXCallEndedReasonRemoteEnded)];
               }
//               for (NSUUID *myUuid in self.providerDelegate.calls) {
//                  [self.providerDelegate.provider reportCallWithUUID:myUuid
//                   endedAtDate:NULL
//                   reason:(state == LinphoneCallError
//                      ? CXCallEndedReasonFailed
//                      : CXCallEndedReasonRemoteEnded)];
//               }
               [self.providerDelegate.uuids removeAllObjects];
               [self.providerDelegate.calls removeAllObjects];
            }
@@ -1146,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*/
@@ -1172,6 +1339,31 @@
    userInfo:dict];
}
/*重新拉取视频流(解决自研可视对讲偶尔出现视频流拉取很慢的问题)
 */
-(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];
@@ -1189,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",
@@ -2130,11 +2322,29 @@
   linphone_core_cbs_set_version_update_check_result_received(cbs, linphone_iphone_version_update_check_result_received);
   linphone_core_cbs_set_qrcode_found(cbs, linphone_iphone_qr_code_found);
   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);
    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)) {
        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
   linphone_core_cbs_unref(cbs);
@@ -2184,6 +2394,16 @@
   // start scheduler
   mIterateTimer =
      [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(iterate) userInfo:nil repeats:YES];
//    //自动启动和接收video
//    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{
@@ -2574,10 +2794,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
@@ -2609,7 +2834,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");
      }
   }
@@ -2622,7 +2847,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 {
@@ -2632,7 +2857,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
@@ -2804,29 +3031,30 @@
      return;
   }
   if (linphone_core_get_calls_nb(theLinphoneCore) < 1 &&
       floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max &&
       self.providerDelegate.callKitCalls < 1) {
        NSLog(@"进这里呼叫了");
      self.providerDelegate.callKitCalls++;
      NSUUID *uuid = [NSUUID UUID];
      [HDLLinphoneManager.instance.providerDelegate.uuids setObject:uuid forKey:@""];
      [HDLLinphoneManager.instance.providerDelegate.calls setObject:@"" forKey:uuid];
      HDLLinphoneManager.instance.providerDelegate.pendingAddr = linphone_address_clone(iaddr);
//      NSString *address = [FastAddressBook displayNameForAddress:iaddr];
        NSString *address =@"unknow";
      CXHandle *handle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:address];
      CXStartCallAction *act = [[CXStartCallAction alloc] initWithCallUUID:uuid handle:handle];
      CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
      [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr
       completion:^(NSError *err){
            NSLog(@"呼叫error:%@",err);
         }];
   } else {
        NSLog(@"进doCall呼叫了");
      [self doCall:iaddr];
   }
//   if (linphone_core_get_calls_nb(theLinphoneCore) < 1 &&
//       floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max &&
//       self.providerDelegate.callKitCalls < 1) {
//        NSLog(@"进这里呼叫了");
//      self.providerDelegate.callKitCalls++;
//      NSUUID *uuid = [NSUUID UUID];
//      [HDLLinphoneManager.instance.providerDelegate.uuids setObject:uuid forKey:@""];
//      [HDLLinphoneManager.instance.providerDelegate.calls setObject:@"" forKey:uuid];
//      HDLLinphoneManager.instance.providerDelegate.pendingAddr = linphone_address_clone(iaddr);
////      NSString *address = [FastAddressBook displayNameForAddress:iaddr];
//        NSString *address =@"unknow";
//
//      CXHandle *handle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:address];
//      CXStartCallAction *act = [[CXStartCallAction alloc] initWithCallUUID:uuid handle:handle];
//      CXTransaction *tr = [[CXTransaction alloc] initWithAction:act];
//      [HDLLinphoneManager.instance.providerDelegate.controller requestTransaction:tr
//       completion:^(NSError *err){
//            NSLog(@"呼叫error:%@",err);
//         }];
//   } else {
//        NSLog(@"进doCall呼叫了");
//      [self doCall:iaddr];
//   }
    [self doCall:iaddr];
}
- (BOOL)doCall:(const LinphoneAddress *)iaddr {
@@ -2884,7 +3112,8 @@
      }
   }
   linphone_address_destroy(addr);
   linphone_call_params_destroy(lcallParams);
//   linphone_call_params_destroy(lcallParams);
    linphone_call_params_unref(lcallParams);
    
   return TRUE;
}
@@ -3076,19 +3305,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 {
@@ -3132,7 +3375,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];
@@ -3146,7 +3391,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;
}
@@ -3156,7 +3402,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];
@@ -3170,7 +3416,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 {