mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-08 20:43:51 +00:00
working mo better
This commit is contained in:
1 parent
5c90322e8c
commit
668f4a6207
10 files changed
+305
-122
No files matched your search
@@ -1109,10 +1109,21 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
|
||||
const char *agent = "unknown";
|
||||
const char *pres_on_reg = NULL;
|
||||
int send_pres = 0;
|
||||
int is_tls = 0, is_tcp = 0, is_ws = 0;
|
||||
int is_tls = 0, is_tcp = 0, is_ws = 0, is_wss = 0;
|
||||
char expbuf[35] = "";
|
||||
time_t reg_time = switch_epoch_time_now(NULL);
|
||||
|
||||
const char *vproto = NULL;
|
||||
const char *proto = "sip";
|
||||
|
||||
if (sip && sip->sip_via && (vproto = sip->sip_via->v_protocol)) {
|
||||
if (!strcasecmp(vproto, "sip/2.0/ws")) {
|
||||
is_ws = 1;
|
||||
is_nat++;
|
||||
} else if (!strcasecmp(vproto, "sip/2.0/wss")) {
|
||||
is_wss = 1;
|
||||
is_nat++;
|
||||
}
|
||||
}
|
||||
|
||||
if (v_event && *v_event) pres_on_reg = switch_event_get_header(*v_event, "send-presence-on-register");
|
||||
|
||||
@@ -1177,24 +1188,28 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
|
||||
const char *contact_host = contact->m_url->url_host;
|
||||
char *path_encoded = NULL;
|
||||
int path_encoded_len = 0;
|
||||
const char *proto = "sip";
|
||||
|
||||
|
||||
if (switch_stristr("transport=tls", sip->sip_contact->m_url->url_params)) {
|
||||
is_tls += 1;
|
||||
is_nat++;
|
||||
}
|
||||
|
||||
if (switch_stristr("transport=ws", sip->sip_contact->m_url->url_params)) {
|
||||
if (!is_wss && !is_ws && switch_stristr("transport=ws", sip->sip_contact->m_url->url_params)) {
|
||||
is_nat++;
|
||||
is_ws += 1;
|
||||
}
|
||||
|
||||
if (sip->sip_contact->m_url->url_type == url_sips && !switch_stristr("transport=ws", sip->sip_contact->m_url->url_params)) {
|
||||
if (sip->sip_contact->m_url->url_type == url_sips) {
|
||||
proto = "sips";
|
||||
is_tls += 2;
|
||||
is_nat++;
|
||||
}
|
||||
|
||||
if (is_wss) {
|
||||
proto = "sips";
|
||||
}
|
||||
|
||||
if (switch_stristr("transport=tcp", sip->sip_contact->m_url->url_params)) {
|
||||
is_tcp = 1;
|
||||
is_nat++;
|
||||
@@ -1209,6 +1224,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
|
||||
reg_desc = "Registered(TCP-NAT)";
|
||||
} else if (is_ws) {
|
||||
reg_desc = "Registered(WS-NAT)";
|
||||
} else if (is_wss) {
|
||||
reg_desc = "Registered(WSS-NAT)";
|
||||
} else {
|
||||
reg_desc = "Registered(UDP-NAT)";
|
||||
}
|
||||
@@ -1243,10 +1260,10 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
|
||||
} else if (is_nat) {
|
||||
char my_contact_str[1024];
|
||||
if (sip->sip_contact->m_url->url_params) {
|
||||
switch_snprintf(my_contact_str, sizeof(my_contact_str), "sip:%s@%s:%d;%s",
|
||||
switch_snprintf(my_contact_str, sizeof(my_contact_str), "%s:%s@%s:%d;%s", proto,
|
||||
contact->m_url->url_user, url_ip, network_port, sip->sip_contact->m_url->url_params);
|
||||
} else {
|
||||
switch_snprintf(my_contact_str, sizeof(my_contact_str), "sip:%s@%s:%d", contact->m_url->url_user, url_ip, network_port);
|
||||
switch_snprintf(my_contact_str, sizeof(my_contact_str), "%s:%s@%s:%d", proto, contact->m_url->url_user, url_ip, network_port);
|
||||
}
|
||||
|
||||
path_encoded_len = (int)(strlen(my_contact_str) * 3) + 1;
|
||||
@@ -1388,7 +1405,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
|
||||
size_t path_encoded_len;
|
||||
char my_contact_str[1024];
|
||||
|
||||
switch_snprintf(my_contact_str, sizeof(my_contact_str), "sip:%s@%s:%d", contact->m_url->url_user, url_ip, network_port);
|
||||
switch_snprintf(my_contact_str, sizeof(my_contact_str), "%s:%s@%s:%d", proto, contact->m_url->url_user, url_ip, network_port);
|
||||
path_encoded_len = (strlen(my_contact_str) * 3) + 1;
|
||||
|
||||
if (!switch_stristr("fs_path=", contact_str)) {
|
||||
@@ -1414,10 +1431,11 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
|
||||
if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") ||
|
||||
!strcasecmp(v_contact_str, "NDLB-connectile-dysfunction") || !strcasecmp(v_contact_str, "NDLB-tls-connectile-dysfunction")) {
|
||||
if (contact->m_url->url_params) {
|
||||
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d;%s%s;fs_nat=yes>",
|
||||
display, contact->m_url->url_user, url_ip, network_port, contact->m_url->url_params, received_data);
|
||||
switch_snprintf(contact_str, sizeof(contact_str), "%s <%s:%s@%s:%d;%s%s;fs_nat=yes>",
|
||||
display, proto, contact->m_url->url_user, url_ip, network_port, contact->m_url->url_params, received_data);
|
||||
} else {
|
||||
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d%s;fs_nat=yes>", display, contact->m_url->url_user, url_ip,
|
||||
switch_snprintf(contact_str, sizeof(contact_str), "%s <%s:%s@%s:%d%s;fs_nat=yes>", display, proto,
|
||||
contact->m_url->url_user, url_ip,
|
||||
network_port, received_data);
|
||||
}
|
||||
if (switch_stristr(v_contact_str, "transport=tls")) {
|
||||
@@ -1623,7 +1641,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
|
||||
switch_find_local_ip(guess_ip4, sizeof(guess_ip4), NULL, AF_INET);
|
||||
|
||||
contact = sofia_glue_get_url_from_contact(contact_str, 1);
|
||||
url = switch_mprintf("sofia/%q/sip:%q", profile->name, sofia_glue_strip_proto(contact));
|
||||
url = switch_mprintf("sofia/%q/%s:%q", profile->name, proto, sofia_glue_strip_proto(contact));
|
||||
|
||||
switch_core_add_registration(to_user, reg_host, call_id, url, (long) reg_time + (long) exptime + 60,
|
||||
network_ip, network_port_c, is_tls ? "tls" : is_tcp ? "tcp" : "udp", reg_meta);
|
||||
@@ -1773,7 +1791,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
|
||||
(reg_count == 1 && sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER))) && debounce_ok) {
|
||||
|
||||
if (switch_event_create(&s_mwi_event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header(s_mwi_event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", mwi_user, mwi_host);
|
||||
switch_event_add_header(s_mwi_event, SWITCH_STACK_BOTTOM, "Message-Account", "%s:%s@%s", proto, mwi_user, mwi_host);
|
||||
switch_event_add_header_string(s_mwi_event, SWITCH_STACK_BOTTOM, "VM-Sofia-Profile", profile->name);
|
||||
switch_event_add_header_string(s_mwi_event, SWITCH_STACK_BOTTOM, "VM-Call-ID", call_id);
|
||||
}
|
||||
|
||||
+92
-77
@@ -1977,6 +1977,10 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
|
||||
int total_codecs;
|
||||
switch_rtp_engine_t *a_engine, *v_engine;
|
||||
switch_media_handle_t *smh;
|
||||
uint32_t near_rate = 0;
|
||||
const switch_codec_implementation_t *mimp = NULL, *near_match = NULL;
|
||||
int codec_ms = 0;
|
||||
|
||||
|
||||
switch_assert(session);
|
||||
|
||||
@@ -2353,11 +2357,8 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
|
||||
|
||||
for (map = m->m_rtpmaps; map; map = map->rm_next) {
|
||||
int32_t i;
|
||||
uint32_t near_rate = 0;
|
||||
const switch_codec_implementation_t *mimp = NULL, *near_match = NULL;
|
||||
const char *rm_encoding;
|
||||
uint32_t map_bit_rate = 0;
|
||||
int codec_ms = 0;
|
||||
switch_codec_fmtp_t codec_fmtp = { 0 };
|
||||
|
||||
if (x++ < skip) {
|
||||
@@ -2411,9 +2412,12 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
|
||||
}
|
||||
|
||||
if (zstr(map->rm_fmtp)) {
|
||||
if (!strcasecmp(map->rm_encoding, "ilbc") || !strcasecmp(map->rm_encoding, "isac")) {
|
||||
if (!strcasecmp(map->rm_encoding, "ilbc")) {
|
||||
codec_ms = 30;
|
||||
map_bit_rate = 13330;
|
||||
} else if (!strcasecmp(map->rm_encoding, "isac")) {
|
||||
codec_ms = 30;
|
||||
map_bit_rate = 32000;
|
||||
}
|
||||
} else {
|
||||
if ((switch_core_codec_parse_fmtp(map->rm_encoding, map->rm_fmtp, map->rm_rate, &codec_fmtp)) == SWITCH_STATUS_SUCCESS) {
|
||||
@@ -2450,7 +2454,8 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
|
||||
match = 0;
|
||||
}
|
||||
|
||||
if (match && map->rm_rate && codec_rate && map->rm_rate != codec_rate && (!strcasecmp(map->rm_encoding, "pcma") || !strcasecmp(map->rm_encoding, "pcmu"))) {
|
||||
if (match && map->rm_rate && codec_rate && map->rm_rate != codec_rate && (!strcasecmp(map->rm_encoding, "pcma") ||
|
||||
!strcasecmp(map->rm_encoding, "pcmu"))) {
|
||||
/* if the sampling rate is specified and doesn't match, this is not a codec match for G.711 */
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "sampling rates have to match for G.711\n");
|
||||
match = 0;
|
||||
@@ -2474,85 +2479,92 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
|
||||
}
|
||||
}
|
||||
|
||||
if (!match && near_match) {
|
||||
const switch_codec_implementation_t *search[1];
|
||||
char *prefs[1];
|
||||
char tmp[80];
|
||||
int num;
|
||||
|
||||
switch_snprintf(tmp, sizeof(tmp), "%s@%uh@%ui", near_match->iananame, near_rate ? near_rate : near_match->samples_per_second,
|
||||
codec_ms);
|
||||
|
||||
prefs[0] = tmp;
|
||||
num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
|
||||
|
||||
if (num) {
|
||||
mimp = search[0];
|
||||
} else {
|
||||
mimp = near_match;
|
||||
}
|
||||
|
||||
if (!maxptime || mimp->microseconds_per_packet / 1000 <= maxptime) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Substituting codec %s@%ui@%uh\n",
|
||||
mimp->iananame, mimp->microseconds_per_packet / 1000, mimp->samples_per_second);
|
||||
match = 1;
|
||||
} else {
|
||||
mimp = NULL;
|
||||
match = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!match && greedy) {
|
||||
skip++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mimp) {
|
||||
char tmp[50];
|
||||
const char *mirror = switch_channel_get_variable(session->channel, "rtp_mirror_remote_audio_codec_payload");
|
||||
|
||||
a_engine->codec_params.rm_encoding = switch_core_session_strdup(session, (char *) map->rm_encoding);
|
||||
a_engine->codec_params.iananame = switch_core_session_strdup(session, (char *) mimp->iananame);
|
||||
a_engine->codec_params.pt = (switch_payload_t) map->rm_pt;
|
||||
a_engine->codec_params.rm_rate = mimp->samples_per_second;
|
||||
a_engine->codec_params.codec_ms = mimp->microseconds_per_packet / 1000;
|
||||
a_engine->codec_params.bitrate = mimp->bits_per_second;
|
||||
|
||||
|
||||
a_engine->codec_params.remote_sdp_ip = switch_core_session_strdup(session, (char *) connection->c_address);
|
||||
a_engine->codec_params.remote_sdp_port = (switch_port_t) m->m_port;
|
||||
a_engine->codec_params.rm_fmtp = switch_core_session_strdup(session, (char *) map->rm_fmtp);
|
||||
|
||||
a_engine->codec_params.agreed_pt = (switch_payload_t) map->rm_pt;
|
||||
smh->num_negotiated_codecs = 0;
|
||||
smh->negotiated_codecs[smh->num_negotiated_codecs++] = mimp;
|
||||
switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->codec_params.remote_sdp_port);
|
||||
switch_channel_set_variable(session->channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, a_engine->codec_params.remote_sdp_ip);
|
||||
switch_channel_set_variable(session->channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, tmp);
|
||||
a_engine->codec_params.recv_pt = (switch_payload_t)map->rm_pt;
|
||||
|
||||
if (!switch_true(mirror) &&
|
||||
switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND &&
|
||||
(!switch_channel_test_flag(session->channel, CF_REINVITE) || switch_media_handle_test_media_flag(smh, SCMF_RENEG_ON_REINVITE))) {
|
||||
switch_core_media_get_offered_pt(session, mimp, &a_engine->codec_params.recv_pt);
|
||||
}
|
||||
|
||||
switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->codec_params.recv_pt);
|
||||
switch_channel_set_variable(session->channel, "rtp_audio_recv_pt", tmp);
|
||||
|
||||
}
|
||||
|
||||
if (match) {
|
||||
if (switch_core_media_set_codec(session, 1, smh->mparams->codec_flags) == SWITCH_STATUS_SUCCESS) {
|
||||
got_audio = 1;
|
||||
check_ice(smh, SWITCH_MEDIA_TYPE_AUDIO, m);
|
||||
} else {
|
||||
match = 0;
|
||||
}
|
||||
if (match && mimp) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!match && near_match) {
|
||||
const switch_codec_implementation_t *search[1];
|
||||
char *prefs[1];
|
||||
char tmp[80];
|
||||
int num;
|
||||
|
||||
switch_snprintf(tmp, sizeof(tmp), "%s@%uh@%ui", near_match->iananame, near_rate ? near_rate : near_match->samples_per_second,
|
||||
codec_ms);
|
||||
|
||||
prefs[0] = tmp;
|
||||
num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
|
||||
|
||||
if (num) {
|
||||
mimp = search[0];
|
||||
} else {
|
||||
mimp = near_match;
|
||||
}
|
||||
|
||||
if (!maxptime || mimp->microseconds_per_packet / 1000 <= maxptime) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Substituting codec %s@%ui@%uh\n",
|
||||
mimp->iananame, mimp->microseconds_per_packet / 1000, mimp->samples_per_second);
|
||||
match = 1;
|
||||
} else {
|
||||
mimp = NULL;
|
||||
match = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (mimp) {
|
||||
char tmp[50];
|
||||
const char *mirror = switch_channel_get_variable(session->channel, "rtp_mirror_remote_audio_codec_payload");
|
||||
|
||||
a_engine->codec_params.rm_encoding = switch_core_session_strdup(session, (char *) map->rm_encoding);
|
||||
a_engine->codec_params.iananame = switch_core_session_strdup(session, (char *) mimp->iananame);
|
||||
a_engine->codec_params.pt = (switch_payload_t) map->rm_pt;
|
||||
a_engine->codec_params.rm_rate = mimp->samples_per_second;
|
||||
a_engine->codec_params.codec_ms = mimp->microseconds_per_packet / 1000;
|
||||
a_engine->codec_params.bitrate = mimp->bits_per_second;
|
||||
|
||||
|
||||
a_engine->codec_params.remote_sdp_ip = switch_core_session_strdup(session, (char *) connection->c_address);
|
||||
a_engine->codec_params.remote_sdp_port = (switch_port_t) m->m_port;
|
||||
a_engine->codec_params.rm_fmtp = switch_core_session_strdup(session, (char *) map->rm_fmtp);
|
||||
|
||||
a_engine->codec_params.agreed_pt = (switch_payload_t) map->rm_pt;
|
||||
smh->num_negotiated_codecs = 0;
|
||||
smh->negotiated_codecs[smh->num_negotiated_codecs++] = mimp;
|
||||
switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->codec_params.remote_sdp_port);
|
||||
switch_channel_set_variable(session->channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, a_engine->codec_params.remote_sdp_ip);
|
||||
switch_channel_set_variable(session->channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, tmp);
|
||||
a_engine->codec_params.recv_pt = (switch_payload_t)map->rm_pt;
|
||||
|
||||
if (!switch_true(mirror) &&
|
||||
switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND &&
|
||||
(!switch_channel_test_flag(session->channel, CF_REINVITE) || switch_media_handle_test_media_flag(smh, SCMF_RENEG_ON_REINVITE))) {
|
||||
switch_core_media_get_offered_pt(session, mimp, &a_engine->codec_params.recv_pt);
|
||||
}
|
||||
|
||||
switch_snprintf(tmp, sizeof(tmp), "%d", a_engine->codec_params.recv_pt);
|
||||
switch_channel_set_variable(session->channel, "rtp_audio_recv_pt", tmp);
|
||||
|
||||
}
|
||||
|
||||
if (match) {
|
||||
if (switch_core_media_set_codec(session, 1, smh->mparams->codec_flags) == SWITCH_STATUS_SUCCESS) {
|
||||
got_audio = 1;
|
||||
check_ice(smh, SWITCH_MEDIA_TYPE_AUDIO, m);
|
||||
} else {
|
||||
match = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!best_te && (switch_media_handle_test_media_flag(smh, SCMF_LIBERAL_DTMF) || switch_channel_test_flag(session->channel, CF_LIBERAL_DTMF))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
|
||||
"No 2833 in SDP. Liberal DTMF mode adding %d as telephone-event.\n", smh->mparams->te);
|
||||
@@ -6335,9 +6347,12 @@ static void add_audio_codec(sdp_rtpmap_t *map, int ptime, char *buf, switch_size
|
||||
}
|
||||
|
||||
if (zstr(map->rm_fmtp)) {
|
||||
if (!strcasecmp(map->rm_encoding, "ilbc") || !strcasecmp(map->rm_encoding, "isac")) {
|
||||
if (!strcasecmp(map->rm_encoding, "ilbc")) {
|
||||
ptime = codec_ms = 30;
|
||||
map_bit_rate = 13330;
|
||||
} else if (!strcasecmp(map->rm_encoding, "isac")) {
|
||||
ptime = codec_ms = 30;
|
||||
map_bit_rate = 32000;
|
||||
}
|
||||
} else {
|
||||
if ((switch_core_codec_parse_fmtp(map->rm_encoding, map->rm_fmtp, map->rm_rate, &codec_fmtp)) == SWITCH_STATUS_SUCCESS) {
|
||||
|
||||
Reference in new issue
Block a user