Tea for two (or maybe thirty eight?)

This commit is contained in:
Anthony Minessale
2010-05-12 21:25:54 -05:00
committed by Brian West
parent 7cfe6bb222
commit 7b3d3f7ef2
17 changed files with 1961 additions and 217 deletions
+81 -19
View File
@@ -977,9 +977,9 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
if (tech_pvt->last_codec_ms && tech_pvt->last_codec_ms == codec_ms) {
tech_pvt->mismatch_count++;
}
tech_pvt->last_codec_ms = codec_ms;
if (tech_pvt->mismatch_count > MAX_MISMATCH_FRAMES) {
if (switch_rtp_ready(tech_pvt->rtp_session) && codec_ms != tech_pvt->codec_ms) {
const char *val;
@@ -996,19 +996,23 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
}
tech_pvt->read_frame.datalen = 0;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"We were told to use ptime %d but what they meant to say was %d\n"
"This issue has so far been identified to happen on the following broken platforms/devices:\n"
"Linksys/Sipura aka Cisco\n"
"ShoreTel\n"
"Sonus/L3\n"
"We will try to fix it but some of the devices on this list are so broken who knows what will happen..\n",
(int) tech_pvt->codec_ms, (int) codec_ms);
switch_channel_set_variable_printf(channel, "sip_h_X-Broken-PTIME", "Adv=%d;Sent=%d",
(int) tech_pvt->codec_ms, (int) codec_ms);
if (codec_ms != tech_pvt->codec_ms) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"We were told to use ptime %d but what they meant to say was %d\n"
"This issue has so far been identified to happen on the following broken platforms/devices:\n"
"Linksys/Sipura aka Cisco\n"
"ShoreTel\n"
"Sonus/L3\n"
"We will try to fix it but some of the devices on this list are so broken,\n"
"who knows what will happen..\n",
(int) tech_pvt->codec_ms, (int) codec_ms);
tech_pvt->codec_ms = codec_ms;
switch_channel_set_variable_printf(channel, "sip_h_X-Broken-PTIME", "Adv=%d;Sent=%d",
(int) tech_pvt->codec_ms, (int) codec_ms);
tech_pvt->codec_ms = codec_ms;
}
if (sofia_glue_tech_set_codec(tech_pvt, 2) != SWITCH_STATUS_SUCCESS) {
*frame = NULL;
@@ -1049,6 +1053,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
tech_pvt->last_ts = 0;
/* inform them of the codec they are actually sending */
if (++tech_pvt->codec_reinvites > 2) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"Ok, some devices *cough* X-lite *cough*\n"
@@ -1065,7 +1070,10 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
} else {
tech_pvt->mismatch_count = 0;
}
tech_pvt->last_ts = tech_pvt->read_frame.timestamp;
} else {
tech_pvt->mismatch_count = 0;
tech_pvt->last_ts = 0;
@@ -1512,16 +1520,70 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
break;
case SWITCH_MESSAGE_INDICATE_UDPTL_MODE:
{
switch_t38_options_t *t38_options = switch_channel_get_private(tech_pvt->channel, "t38_options");
if (!t38_options) {
nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
goto end_lock;
}
if (switch_rtp_ready(tech_pvt->rtp_session)) {
switch_rtp_udptl_mode(tech_pvt->rtp_session);
}
}
break;
case SWITCH_MESSAGE_INDICATE_T38_DESCRIPTION:
{
switch_t38_options_t *t38_options = switch_channel_get_private(tech_pvt->channel, "t38_options");
if (!t38_options) {
nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
goto end_lock;
}
if (switch_rtp_ready(tech_pvt->rtp_session)) {
switch_rtp_udptl_mode(tech_pvt->rtp_session);
}
sofia_glue_set_image_sdp(tech_pvt, t38_options, msg->numeric_arg);
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
char *extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_RESPONSE_HEADER_PREFIX);
if (sofia_use_soa(tech_pvt)) {
nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_AUTOANSWER(0),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
TAG_END());
} else {
nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_AUTOANSWER(0),
NUTAG_MEDIA_ENABLE(0),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")),
SIPTAG_CONTENT_TYPE_STR("application/sdp"),
SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
TAG_END());
}
switch_safe_free(extra_headers);
sofia_set_flag_locked(tech_pvt, TFLAG_ANS);
}
}
break;
case SWITCH_MESSAGE_INDICATE_REQUEST_IMAGE_MEDIA:
{
switch_t38_options_t *t38_options = (switch_t38_options_t *) msg->pointer_arg;
sofia_glue_set_image_sdp(tech_pvt, t38_options);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Sending request for image media. %s\n",
switch_channel_get_name(channel), tech_pvt->local_sdp_str);
switch_t38_options_t *t38_options = switch_channel_get_private(tech_pvt->channel, "t38_options");
sofia_glue_set_image_sdp(tech_pvt, t38_options, msg->numeric_arg);
switch_channel_set_flag(channel, CF_REQ_MEDIA);
sofia_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
sofia_glue_do_invite(session);
+1 -1
View File
@@ -930,7 +930,7 @@ void sofia_glue_toggle_hold(private_object_t *tech_pvt, int sendonly);
const char *sofia_state_string(int state);
switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force);
void sofia_wait_for_reply(struct private_object *tech_pvt, nua_event_t event, uint32_t timeout);
void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *t38_options);
void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *t38_options, int insist);
/*
* SLA (shared line appearance) entrypoints
+5
View File
@@ -4578,6 +4578,11 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
sdp_parser_free(parser);
}
}
if (match && switch_channel_test_app_flag(tech_pvt->channel, CF_APP_T38)) {
goto done;
}
if (match) {
if (sofia_glue_tech_choose_port(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
goto done;
+62 -20
View File
@@ -37,7 +37,7 @@
#include <switch_stun.h>
void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *t38_options)
void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *t38_options, int insist)
{
char buf[2048];
const char *ip = t38_options->ip;
@@ -45,6 +45,9 @@ void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *
const char *family = "IP4";
const char *username = tech_pvt->profile->username;
//sofia_clear_flag(tech_pvt, TFLAG_ENABLE_SOA);
if (!ip) {
if (!(ip = tech_pvt->adv_sdp_audio_ip)) {
ip = tech_pvt->proxy_sdp_audio_ip;
@@ -76,15 +79,29 @@ void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *
}
tech_pvt->session_id++;
family = strchr(ip, ':') ? "IP6" : "IP4";
switch_snprintf(buf, sizeof(buf),
"v=0\n"
"o=%s %010u %010u IN %s %s\n"
"s=%s\n"
"c=IN %s %s\n"
"t=0 0\n"
"t=0 0\n",
username,
tech_pvt->owner_id,
tech_pvt->session_id,
family,
ip,
username,
family,
ip);
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
"m=image %d udptl t38\n"
"a=T38FaxVersion:%d\n"
"a=T38MaxBitRate:%d\n"
"%s"
"%s"
@@ -94,23 +111,32 @@ void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *
"a=T38FaxMaxDatagram:%d\n"
"a=T38FaxUdpEC:%s\n"
"a=T38VendorInfo:%s\n",
username,
tech_pvt->owner_id,
tech_pvt->session_id,
family,
ip,
username,
family,
ip,
port,
t38_options->T38FaxVersion,
t38_options->T38MaxBitRate,
t38_options->T38FaxFillBitRemoval ? "a=T38FaxFillBitRemoval\n" : "",
t38_options->T38FaxTranscodingMMR ? "a=T38FaxTranscodingMMR\n" : "",
t38_options->T38FaxTranscodingJBIG ? "a=T38FaxTranscodingJBIG\n" : "",
t38_options->T38FaxRateManagement,
t38_options->T38FaxMaxBuffer, t38_options->T38FaxMaxDatagram, t38_options->T38FaxUdpEC, t38_options->T38VendorInfo);
t38_options->T38FaxMaxBuffer,
t38_options->T38FaxMaxDatagram,
t38_options->T38FaxUdpEC,
t38_options->T38VendorInfo);
if (insist) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
"m=audio 0 RTP/AVP 19\n");
}
sofia_glue_tech_set_local_sdp(tech_pvt, buf, SWITCH_TRUE);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "%s image media sdp:\n%s\n",
switch_channel_get_name(tech_pvt->channel), tech_pvt->local_sdp_str);
}
void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, uint32_t port, const char *sr, int force)
@@ -1582,7 +1608,9 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
return status;
}
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
if (!switch_channel_get_private(tech_pvt->channel, "t38_options") || zstr(tech_pvt->local_sdp_str)) {
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
}
sofia_set_flag_locked(tech_pvt, TFLAG_READY);
@@ -3417,10 +3445,24 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
}
if (got_udptl && m->m_type == sdp_media_image && m->m_port) {
switch_t38_options_t *t38_options = switch_core_session_alloc(tech_pvt->session, sizeof(switch_t38_options_t));
switch_t38_options_t *t38_options = switch_channel_get_private(tech_pvt->channel, "t38_options");
if (!t38_options) {
t38_options = switch_core_session_alloc(tech_pvt->session, sizeof(switch_t38_options_t));
}
t38_options->port = m->m_port;
if (m->m_connections) {
t38_options->ip = switch_core_session_strdup(tech_pvt->session, m->m_connections->c_address);
} else if (sdp && sdp->sdp_connection) {
t38_options->ip = switch_core_session_strdup(tech_pvt->session, sdp->sdp_connection->c_address);
}
for (attr = m->m_attributes; attr; attr = attr->a_next) {
if (!strcasecmp(attr->a_name, "T38MaxBitRate") && attr->a_value) {
if (!strcasecmp(attr->a_name, "T38FaxVersion") && attr->a_value) {
t38_options->T38FaxVersion = (uint16_t) atoi(attr->a_value);
} else if (!strcasecmp(attr->a_name, "T38MaxBitRate") && attr->a_value) {
t38_options->T38MaxBitRate = (uint32_t) atoi(attr->a_value);
} else if (!strcasecmp(attr->a_name, "T38FaxFillBitRemoval")) {
t38_options->T38FaxFillBitRemoval = SWITCH_TRUE;
@@ -3440,13 +3482,13 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
t38_options->T38VendorInfo = switch_core_session_strdup(tech_pvt->session, attr->a_value);
}
}
switch_channel_set_variable(tech_pvt->channel, "has_t38", "true");
switch_channel_set_private(tech_pvt->channel, "t38_options", t38_options);
//switch_channel_set_flag(tech_pvt->channel, CF_PROXY_MEDIA);
//switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA);
switch_channel_set_app_flag(tech_pvt->channel, CF_APP_T38);
/* do nothing here, mod_fax will trigger a response (if it's listening =/)*/
match = 1;
goto done;
} else if (m->m_type == sdp_media_audio && m->m_port && !got_audio) {
sdp_rtpmap_t *map;
for (attr = m->m_attributes; attr; attr = attr->a_next) {