Changeset 6137
- Timestamp:
- Jan 28, 2020 1:47:56 AM (5 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r6112 r6137 1024 1024 &app_config.auto_hangup_timer, 1025 1025 &delay); 1026 } 1027 1028 /* IP change progress callback. */ 1029 void on_ip_change_progress(pjsua_ip_change_op op, 1030 pj_status_t status, 1031 const pjsua_ip_change_op_info *info) 1032 { 1033 char info_str[128]; 1034 pjsua_acc_info acc_info; 1035 pjsua_transport_info tp_info; 1036 1037 if (status == PJ_SUCCESS) { 1038 switch (op) { 1039 case PJSUA_IP_CHANGE_OP_RESTART_LIS: 1040 pjsua_transport_get_info(info->lis_restart.transport_id, &tp_info); 1041 pj_ansi_snprintf(info_str, sizeof(info_str), 1042 "restart transport %.*s", 1043 tp_info.info.slen, tp_info.info.ptr); 1044 break; 1045 case PJSUA_IP_CHANGE_OP_ACC_SHUTDOWN_TP: 1046 pjsua_acc_get_info(info->acc_shutdown_tp.acc_id, &acc_info); 1047 1048 pj_ansi_snprintf(info_str, sizeof(info_str), 1049 "transport shutdown for account %.*s", 1050 acc_info.acc_uri.slen, acc_info.acc_uri.ptr); 1051 break; 1052 case PJSUA_IP_CHANGE_OP_ACC_UPDATE_CONTACT: 1053 pjsua_acc_get_info(info->acc_shutdown_tp.acc_id, &acc_info); 1054 if (info->acc_update_contact.code) { 1055 pj_ansi_snprintf(info_str, sizeof(info_str), 1056 "update contact for account %.*s, code[%d]", 1057 acc_info.acc_uri.slen, acc_info.acc_uri.ptr, 1058 info->acc_update_contact.code); 1059 } else { 1060 pj_ansi_snprintf(info_str, sizeof(info_str), 1061 "update contact for account %.*s", 1062 acc_info.acc_uri.slen, acc_info.acc_uri.ptr); 1063 } 1064 break; 1065 case PJSUA_IP_CHANGE_OP_ACC_HANGUP_CALLS: 1066 pjsua_acc_get_info(info->acc_shutdown_tp.acc_id, &acc_info); 1067 pj_ansi_snprintf(info_str, sizeof(info_str), 1068 "hangup call for account %.*s, call_id[%d]", 1069 acc_info.acc_uri.slen, acc_info.acc_uri.ptr, 1070 info->acc_hangup_calls.call_id); 1071 break; 1072 case PJSUA_IP_CHANGE_OP_ACC_REINVITE_CALLS: 1073 pjsua_acc_get_info(info->acc_shutdown_tp.acc_id, &acc_info); 1074 pj_ansi_snprintf(info_str, sizeof(info_str), 1075 "reinvite call for account %.*s, call_id[%d]", 1076 acc_info.acc_uri.slen, acc_info.acc_uri.ptr, 1077 info->acc_reinvite_calls.call_id); 1078 break; 1079 case PJSUA_IP_CHANGE_OP_COMPLETED: 1080 pj_ansi_snprintf(info_str, sizeof(info_str), 1081 "done"); 1082 break; 1083 } 1084 PJ_LOG(3,(THIS_FILE, "IP change progress report : %s", info_str)); 1085 1086 } else { 1087 PJ_PERROR(3,(THIS_FILE, status, "IP change progress fail")); 1088 } 1026 1089 } 1027 1090 … … 1301 1364 app_config.cfg.cb.on_snd_dev_operation = &on_snd_dev_operation; 1302 1365 app_config.cfg.cb.on_call_media_event = &on_call_media_event; 1366 app_config.cfg.cb.on_ip_change_progress = &on_ip_change_progress; 1303 1367 #ifdef TRANSPORT_ADAPTER_SAMPLE 1304 1368 app_config.cfg.cb.on_create_media_transport = &on_create_media_transport; -
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_legacy.c
r6123 r6137 1756 1756 } 1757 1757 1758 static void ui_handle_ip_change() 1759 { 1760 pjsua_ip_change_param param; 1761 pjsua_ip_change_param_default(¶m); 1762 pjsua_handle_ip_change(¶m); 1763 } 1758 1764 1759 1765 /* … … 2007 2013 break; 2008 2014 2015 case 'I': /* Handle IP change. */ 2016 ui_handle_ip_change(); 2017 break; 2018 2009 2019 default: 2010 2020 if (menuin[0] != '\n' && menuin[0] != '\r') { -
pjproject/trunk/pjsip-apps/src/swig/symbols.i
r6075 r6137 848 848 PJSUA_IP_CHANGE_OP_ACC_UPDATE_CONTACT, 849 849 PJSUA_IP_CHANGE_OP_ACC_HANGUP_CALLS, 850 PJSUA_IP_CHANGE_OP_ACC_REINVITE_CALLS 850 PJSUA_IP_CHANGE_OP_ACC_REINVITE_CALLS, 851 PJSUA_IP_CHANGE_OP_COMPLETED 851 852 } pjsua_ip_change_op; 852 853 -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r6117 r6137 749 749 * The re-INVITE call process. 750 750 */ 751 PJSUA_IP_CHANGE_OP_ACC_REINVITE_CALLS 751 PJSUA_IP_CHANGE_OP_ACC_REINVITE_CALLS, 752 753 /** 754 * The ip change process has completed. 755 */ 756 PJSUA_IP_CHANGE_OP_COMPLETED 752 757 753 758 } pjsua_ip_change_op; -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
r6035 r6137 898 898 pj_status_t pjsua_acc_handle_call_on_ip_change(pjsua_acc *acc); 899 899 900 /* 901 * End IP change process per account. 902 */ 903 void pjsua_acc_end_ip_change(pjsua_acc *acc); 904 900 905 PJ_END_DECL 901 906 -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
r6035 r6137 693 693 acc->via_tp = NULL; 694 694 acc->next_rtp_port = 0; 695 acc->ip_change_op = PJSUA_IP_CHANGE_OP_NULL; 695 acc->ip_change_op = PJSUA_IP_CHANGE_OP_NULL; 696 696 697 697 /* Remove from array */ … … 2423 2423 2424 2424 pj_bzero(&ip_chg_info, sizeof(ip_chg_info)); 2425 pjsip_regc_get_info(param->regc, &rinfo); 2425 pjsip_regc_get_info(param->regc, &rinfo); 2426 2426 ip_chg_info.acc_update_contact.acc_id = acc->index; 2427 2427 ip_chg_info.acc_update_contact.code = param->code; 2428 2428 ip_chg_info.acc_update_contact.is_register = !param->is_unreg; 2429 (*pjsua_var.ua_cfg.cb.on_ip_change_progress)(acc->ip_change_op, 2430 param->status, 2429 (*pjsua_var.ua_cfg.cb.on_ip_change_progress)(acc->ip_change_op, 2430 param->status, 2431 2431 &ip_chg_info); 2432 2432 } … … 2441 2441 2442 2442 status = pjsua_acc_set_registration(acc->index, PJ_TRUE); 2443 if ((status != PJ_SUCCESS) && 2444 pjsua_var.ua_cfg.cb.on_ip_change_progress) 2443 if ((status != PJ_SUCCESS) && 2444 pjsua_var.ua_cfg.cb.on_ip_change_progress) 2445 2445 { 2446 2446 pjsua_ip_change_op_info ip_chg_info; … … 2450 2450 ip_chg_info.acc_update_contact.is_register = PJ_TRUE; 2451 2451 (*pjsua_var.ua_cfg.cb.on_ip_change_progress)( 2452 acc->ip_change_op, 2453 status, 2452 acc->ip_change_op, 2453 status, 2454 2454 &ip_chg_info); 2455 2456 pjsua_acc_end_ip_change(acc); 2455 2457 } 2456 2458 } else { 2457 2459 /* Avoid deadlock issue when sending BYE or Re-INVITE. */ 2458 pjsua_schedule_timer2(&handle_call_on_ip_change_cb, 2460 pjsua_schedule_timer2(&handle_call_on_ip_change_cb, 2459 2461 (void*)acc, 0); 2460 2462 } 2461 } 2462 } 2463 2463 } else { 2464 pjsua_acc_end_ip_change(acc); 2465 } 2466 } 2467 2464 2468 PJSUA_UNLOCK(); 2465 2469 pj_log_pop_indent(); … … 3903 3907 pjsip_regc_release_transport(pjsua_var.acc[i].regc); 3904 3908 3905 if (pjsua_var.acc[i].ip_change_op == 3909 if (pjsua_var.acc[i].ip_change_op == 3906 3910 PJSUA_IP_CHANGE_OP_ACC_SHUTDOWN_TP) 3907 3911 { 3912 /* Before progressing to next step, report here. */ 3913 if (pjsua_var.ua_cfg.cb.on_ip_change_progress) { 3914 pjsua_ip_change_op_info ch_info; 3915 3916 pj_bzero(&ch_info, sizeof(ch_info)); 3917 ch_info.acc_shutdown_tp.acc_id = acc->index; 3918 3919 pjsua_var.ua_cfg.cb.on_ip_change_progress( 3920 acc->ip_change_op, 3921 PJ_SUCCESS, 3922 &ch_info); 3923 } 3924 3908 3925 if (acc->cfg.allow_contact_rewrite) { 3909 3926 pjsua_acc_update_contact_on_ip_change(acc); … … 3940 3957 status = pjsua_acc_set_registration(acc->index, !need_unreg); 3941 3958 3942 if ((status != PJ_SUCCESS) && (pjsua_var.ua_cfg.cb.on_ip_change_progress)) 3959 if ((status != PJ_SUCCESS) && (pjsua_var.ua_cfg.cb.on_ip_change_progress) 3960 && (acc->ip_change_op == PJSUA_IP_CHANGE_OP_ACC_UPDATE_CONTACT)) 3943 3961 { 3962 /* If update contact fails, notification might already been triggered 3963 * from registration callback. 3964 */ 3944 3965 pjsua_ip_change_op_info info; 3945 3966 3946 3967 pj_bzero(&info, sizeof(info)); 3947 3968 info.acc_update_contact.acc_id = acc->index; 3948 info.acc_update_contact.is_register = !need_unreg; 3969 info.acc_update_contact.is_register = !need_unreg; 3949 3970 3950 3971 pjsua_var.ua_cfg.cb.on_ip_change_progress(acc->ip_change_op, 3951 3972 status, 3952 3973 &info); 3974 3975 pjsua_acc_end_ip_change(acc); 3953 3976 } 3954 3977 return status; … … 3965 3988 3966 3989 PJSUA_LOCK(); 3967 if (acc->cfg.ip_change_cfg.hangup_calls || 3990 if (acc->cfg.ip_change_cfg.hangup_calls || 3968 3991 acc->cfg.ip_change_cfg.reinvite_flags) 3969 3992 { … … 3977 4000 } 3978 4001 3979 if (acc->cfg.ip_change_cfg.hangup_calls) { 4002 if ((acc->cfg.ip_change_cfg.hangup_calls) && 4003 (call_info.state >= PJSIP_INV_STATE_EARLY)) 4004 { 3980 4005 acc->ip_change_op = PJSUA_IP_CHANGE_OP_ACC_HANGUP_CALLS; 3981 4006 PJ_LOG(3, (THIS_FILE, "call to %.*s: hangup " … … 4032 4057 } 4033 4058 } 4034 } 4035 acc->ip_change_op = PJSUA_IP_CHANGE_OP_NULL;4059 } 4060 pjsua_acc_end_ip_change(acc); 4036 4061 PJSUA_UNLOCK(); 4037 4062 return status; 4038 4063 } 4064 4065 void pjsua_acc_end_ip_change(pjsua_acc *acc) 4066 { 4067 int i = 0; 4068 pj_bool_t all_done = PJ_TRUE; 4069 4070 PJSUA_LOCK(); 4071 if (acc && acc->ip_change_op < PJSUA_IP_CHANGE_OP_COMPLETED) { 4072 PJ_LOG(3, (THIS_FILE, "IP address change handling for acc %d " 4073 "completed", acc->index)); 4074 acc->ip_change_op = PJSUA_IP_CHANGE_OP_COMPLETED; 4075 if (pjsua_var.acc_cnt) { 4076 for (; i < (int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 4077 if (pjsua_var.acc[i].valid && 4078 pjsua_var.acc[i].ip_change_op != 4079 PJSUA_IP_CHANGE_OP_COMPLETED) 4080 { 4081 all_done = PJ_FALSE; 4082 break; 4083 } 4084 } 4085 } 4086 } 4087 if (all_done && pjsua_var.ua_cfg.cb.on_ip_change_progress) { 4088 PJ_LOG(3, (THIS_FILE, "IP address change handling completed")); 4089 pjsua_var.ua_cfg.cb.on_ip_change_progress( 4090 PJSUA_IP_CHANGE_OP_COMPLETED, 4091 PJ_SUCCESS, 4092 NULL); 4093 } 4094 PJSUA_UNLOCK(); 4095 } -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r6015 r6137 3572 3572 3573 3573 PJSUA_LOCK(); 3574 3575 if (pjsua_var.acc_cnt == 0) { 3576 PJ_LOG(3, (THIS_FILE, 3577 "No account is set, IP change handling will stop")); 3578 pjsua_acc_end_ip_change(NULL); 3579 PJSUA_UNLOCK(); 3580 return status; 3581 } 3582 3574 3583 /* Reset ip_change_active flag. */ 3575 3584 for (; i < (int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 3576 3585 pjsua_var.acc[i].ip_change_op = PJSUA_IP_CHANGE_OP_NULL; 3577 3586 acc_done[i] = PJ_FALSE; 3578 } 3579 3587 } 3588 3580 3589 for (i = 0; i < (int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 3581 3590 pj_bool_t shutdown_transport = PJ_FALSE; … … 3595 3604 3596 3605 pjsip_regc_get_info(acc->regc, ®c_info); 3597 3606 3598 3607 /* Check if transport restart listener succeed. */ 3599 3608 for (; j < PJ_ARRAY_SIZE(pjsua_var.tpdata); ++j) { 3600 if (pjsua_var.tpdata[j].data.ptr != NULL && 3609 if (pjsua_var.tpdata[j].data.ptr != NULL && 3601 3610 pjsua_var.tpdata[j].restart_status != PJ_SUCCESS && 3602 3611 pjsua_var.tpdata[j].type == regc_info.transport->key.type) … … 3605 3614 == regc_info.transport->factory) || 3606 3615 (pjsua_var.tpdata[j].data.tp 3607 == regc_info.transport)) 3616 == regc_info.transport)) 3608 3617 { 3609 3618 found_restart_tp_fail = PJ_TRUE; … … 3623 3632 } 3624 3633 } 3625 3634 pjsua_acc_end_ip_change(acc); 3626 3635 continue; 3627 3636 } … … 3633 3642 shutdown_transport = acc->cfg.ip_change_cfg.shutdown_tp; 3634 3643 shut_acc_ids[shut_acc_cnt++] = acc->index; 3635 } 3644 } 3636 3645 } else if (acc->cfg.reg_uri.slen && 3637 acc->reg_last_code != PJSIP_SC_ BAD_GATEWAY&&3646 acc->reg_last_code != PJSIP_SC_OK && 3638 3647 acc->reg_last_code != PJSIP_SC_REQUEST_TIMEOUT && 3639 3648 acc->reg_last_code != PJSIP_SC_INTERNAL_SERVER_ERROR && … … 3641 3650 acc->reg_last_code != PJSIP_SC_SERVICE_UNAVAILABLE && 3642 3651 acc->reg_last_code != PJSIP_SC_SERVER_TIMEOUT && 3643 acc->reg_last_code != PJSIP_SC_TEMPORARILY_UNAVAILABLE) 3652 acc->reg_last_code != PJSIP_SC_TEMPORARILY_UNAVAILABLE) 3644 3653 { 3654 PJ_LOG(3, (THIS_FILE, "Permanent registration failure, " 3655 "IP change handling will stop for acc %d", acc->index)); 3656 3657 pjsua_acc_end_ip_change(acc); 3645 3658 continue; 3646 } 3647 pj_ansi_snprintf(acc_id, sizeof(acc_id), "#%d", i); 3659 } 3660 pj_ansi_snprintf(acc_id, sizeof(acc_id), "#%d", i); 3648 3661 3649 3662 if (transport) { … … 3656 3669 3657 3670 if (!next_acc->valid || !next_acc->regc || 3658 (next_acc->ip_change_op > PJSUA_IP_CHANGE_OP_NULL)) 3671 (next_acc->ip_change_op > PJSUA_IP_CHANGE_OP_NULL)) 3659 3672 { 3660 3673 continue; … … 3683 3696 if (shutdown_transport) { 3684 3697 unsigned j; 3685 /* Shutdown the transport. */ 3698 /* Shutdown the transport. */ 3686 3699 PJ_LOG(3, (THIS_FILE, "Shutdown transport %s used by account %s " 3687 3700 "triggered by IP change", transport->obj_name, acc_id)); … … 3694 3707 3695 3708 status = pjsip_transport_shutdown2(transport, PJ_TRUE); 3696 3697 /* Report progress to each acc which uses the same transport. */3698 for (j = 0; j < shut_acc_cnt; ++j) {3699 pjsua_acc *tmp_acc = &pjsua_var.acc[shut_acc_ids[j]];3700 3701 if (pjsua_var.ua_cfg.cb.on_ip_change_progress) {3702 pjsua_ip_change_op_info info;3703 3704 pj_bzero(&info, sizeof(info));3705 info.acc_shutdown_tp.acc_id = tmp_acc->index;3706 3707 pjsua_var.ua_cfg.cb.on_ip_change_progress(3708 tmp_acc->ip_change_op,3709 status,3710 &info);3711 }3712 3713 }3714 3709 } else { 3715 3710 acc_done[i] = PJ_TRUE; … … 3726 3721 3727 3722 3728 static pj_status_t restart_listener(pjsua_transport_id id, 3723 static pj_status_t restart_listener(pjsua_transport_id id, 3729 3724 unsigned restart_lis_delay) 3730 3725 { 3731 3726 pj_sockaddr bind_addr; 3732 3727 pjsua_transport_info tp_info; 3733 pj_status_t status; 3734 3735 pjsua_transport_get_info(id, &tp_info); 3728 pj_status_t status; 3729 3730 pjsua_transport_get_info(id, &tp_info); 3736 3731 pj_sockaddr_init(pjsip_transport_type_get_af(tp_info.type), 3737 3732 &bind_addr, 3738 3733 NULL, 3739 3734 pj_sockaddr_get_port(&tp_info.local_addr)); 3740 3735 3741 3736 switch (tp_info.type) { 3742 3737 case PJSIP_TRANSPORT_UDP: … … 3771 3766 } 3772 3767 3773 PJ_PERROR(3,(THIS_FILE, status, "Listener % s restart",3774 pjsip_transport_get_type_name(tp_info.type)));3768 PJ_PERROR(3,(THIS_FILE, status, "Listener %.*s restart", 3769 tp_info.info.slen, tp_info.info.ptr)); 3775 3770 3776 3771 if (status != PJ_SUCCESS && (restart_lis_delay > 0)) { 3777 3772 /* Try restarting again, with delay. */ 3778 pjsua_schedule_timer2(&restart_listener_cb, 3779 (void*)(pj_size_t)id, 3773 pjsua_schedule_timer2(&restart_listener_cb, 3774 (void*)(pj_size_t)id, 3780 3775 restart_lis_delay); 3781 3776 3782 PJ_LOG(3,(THIS_FILE, "Retry listener %s restart in %d ms", 3783 pjsip_transport_get_type_name(tp_info.type), 3784 restart_lis_delay)); 3777 PJ_LOG(3,(THIS_FILE, "Retry listener %.*s restart in %d ms", 3778 tp_info.info.slen, tp_info.info.ptr, restart_lis_delay)); 3785 3779 3786 3780 status = PJ_SUCCESS; … … 3797 3791 info.lis_restart.transport_id = id; 3798 3792 pjsua_var.ua_cfg.cb.on_ip_change_progress( 3799 PJSUA_IP_CHANGE_OP_RESTART_LIS, 3800 status, 3793 PJSUA_IP_CHANGE_OP_RESTART_LIS, 3794 status, 3801 3795 &info); 3802 3796 } … … 3804 3798 /* Move forward if all listener has been restarted. */ 3805 3799 for (; i < PJ_ARRAY_SIZE(pjsua_var.tpdata); ++i) { 3806 if (pjsua_var.tpdata[i].data.ptr != NULL && 3807 pjsua_var.tpdata[i].is_restarting) 3800 if (pjsua_var.tpdata[i].data.ptr != NULL && 3801 pjsua_var.tpdata[i].is_restarting) 3808 3802 { 3809 3803 all_done = PJ_FALSE; … … 3832 3826 PJ_ASSERT_RETURN(param, PJ_EINVAL); 3833 3827 3828 for (; i < (int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 3829 if (pjsua_var.acc[i].valid && 3830 pjsua_var.acc[i].ip_change_op != PJSUA_IP_CHANGE_OP_NULL && 3831 pjsua_var.acc[i].ip_change_op != PJSUA_IP_CHANGE_OP_COMPLETED) 3832 { 3833 PJ_LOG(2, (THIS_FILE, 3834 "Previous IP address change handling still in progress")); 3835 } 3836 } 3837 3834 3838 PJ_LOG(3, (THIS_FILE, "Start handling IP address change")); 3835 3836 3839 if (param->restart_listener) { 3837 3840 PJSUA_LOCK(); … … 3846 3849 } 3847 3850 for (i = 0; i < PJ_ARRAY_SIZE(pjsua_var.tpdata); ++i) { 3848 if (pjsua_var.tpdata[i].data.ptr != NULL) { 3851 if (pjsua_var.tpdata[i].data.ptr != NULL) { 3849 3852 status = restart_listener(i, param->restart_lis_delay); 3850 3853 }
Note: See TracChangeset
for help on using the changeset viewer.