modest rearranging

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4057 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-01-26 15:42:38 +00:00
parent 4e75aa0b52
commit a5bec02bea
3 changed files with 44 additions and 124 deletions

View File

@ -1124,8 +1124,6 @@ static switch_status_t sofia_on_init(switch_core_session_t *session)
tech_pvt->read_frame.buflen = SWITCH_RTP_MAX_BUF_LEN;
switch_channel_set_variable(channel, "endpoint_disposition", "INIT");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SOFIA INIT\n");
if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
switch_set_flag_locked(tech_pvt, TFLAG_NOMEDIA);
@ -1152,7 +1150,6 @@ static switch_status_t sofia_on_ring(switch_core_session_t *session)
tech_pvt = (private_object_t *) switch_core_session_get_private(session);
assert(tech_pvt != NULL);
switch_channel_set_variable(channel, "endpoint_disposition", "RING");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SOFIA RING\n");
return SWITCH_STATUS_SUCCESS;
@ -1170,7 +1167,6 @@ static switch_status_t sofia_on_execute(switch_core_session_t *session)
tech_pvt = (private_object_t *) switch_core_session_get_private(session);
assert(tech_pvt != NULL);
switch_channel_set_variable(channel, "endpoint_disposition", "EXECUTE");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SOFIA EXECUTE\n");
return SWITCH_STATUS_SUCCESS;
@ -1587,7 +1583,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
SOATAG_AUDIO_AUX("cn telephone-event"),
NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_END());
switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
}
}
@ -2002,7 +1998,6 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_AUDIO_AUX("cn telephone-event"),
TAG_END());
switch_channel_set_variable(channel, "endpoint_disposition", "PROGRESS");
}
}
break;
@ -2202,7 +2197,6 @@ static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, sw
switch_channel_set_flag(nchannel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(nchannel, CS_INIT);
switch_channel_set_variable(nchannel, "endpoint_disposition", "OUTBOUND");
*new_session = nsession;
status = SWITCH_STATUS_SUCCESS;
if (session) {
@ -2264,8 +2258,9 @@ static uint8_t negotiate_sdp(switch_core_session_t *session, sdp_session_t *sdp)
sdp_rtpmap_t *map;
for (map = m->m_rtpmaps; map; map = map->rm_next) {
int32_t i;
int32_t i, btn = 0;
const switch_codec_implementation_t *mimp = NULL, *better_than_nothing[10] = {0};
if (!strcasecmp(map->rm_encoding, "telephone-event")) {
tech_pvt->te = (switch_payload_t)map->rm_pt;
}
@ -2281,23 +2276,36 @@ static uint8_t negotiate_sdp(switch_core_session_t *session, sdp_session_t *sdp)
}
if (match && (map->rm_rate == imp->samples_per_second)) {
char tmp[50];
tech_pvt->rm_encoding = switch_core_session_strdup(session, (char *)map->rm_encoding);
tech_pvt->pt = (switch_payload_t)map->rm_pt;
tech_pvt->rm_rate = map->rm_rate;
tech_pvt->codec_ms = imp->microseconds_per_frame / 1000;
tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(session, (char *)sdp->sdp_connection->c_address);
tech_pvt->rm_fmtp = switch_core_session_strdup(session, (char *)map->rm_fmtp);
tech_pvt->remote_sdp_audio_port = (switch_port_t)m->m_port;
tech_pvt->agreed_pt = (switch_payload_t)map->rm_pt;
snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_sdp_audio_port);
switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, tech_pvt->remote_sdp_audio_ip);
switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, tmp);
if (ptime && ptime * 1000 != imp->microseconds_per_frame && btn < 10) {
better_than_nothing[btn++] = imp;
continue;
}
mimp = imp;
break;
} else {
match = 0;
}
}
}
if (!match && btn) {
match = 1;
mimp = better_than_nothing[0];
}
if (mimp) {
char tmp[50];
tech_pvt->rm_encoding = switch_core_session_strdup(session, (char *)map->rm_encoding);
tech_pvt->pt = (switch_payload_t)map->rm_pt;
tech_pvt->rm_rate = map->rm_rate;
tech_pvt->codec_ms = mimp->microseconds_per_frame / 1000;
tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(session, (char *)sdp->sdp_connection->c_address);
tech_pvt->rm_fmtp = switch_core_session_strdup(session, (char *)map->rm_fmtp);
tech_pvt->remote_sdp_audio_port = (switch_port_t)m->m_port;
tech_pvt->agreed_pt = (switch_payload_t)map->rm_pt;
snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_sdp_audio_port);
switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, tech_pvt->remote_sdp_audio_ip);
switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, tmp);
}
if (match) {
if (tech_set_codec(tech_pvt, 1) != SWITCH_STATUS_SUCCESS) {
@ -2829,7 +2837,6 @@ static void sip_i_state(int status,
if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
switch_set_flag_locked(tech_pvt, TFLAG_ANS);
switch_channel_mark_answered(channel);
switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
other_channel = switch_core_session_get_channel(other_session);
switch_channel_answer(other_channel);
@ -2854,7 +2861,6 @@ static void sip_i_state(int status,
if (match) {
switch_set_flag_locked(tech_pvt, TFLAG_ANS);
switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
if (tech_choose_port(tech_pvt) == SWITCH_STATUS_SUCCESS) {
activate_rtp(tech_pvt);
switch_channel_mark_answered(channel);
@ -2867,7 +2873,6 @@ static void sip_i_state(int status,
}
} else if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
switch_set_flag_locked(tech_pvt, TFLAG_ANS);
switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
switch_channel_mark_answered(channel);
if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
other_channel = switch_core_session_get_channel(other_session);

View File

@ -1006,6 +1006,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_pre_answer(switch_channel
switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_NOTICE, "Pre-Answer %s!\n", channel->name);
switch_channel_set_flag(channel, CF_EARLY_MEDIA);
switch_channel_set_variable(channel, "endpoint_disposition", "EARLY MEDIA");
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_PROGRESS) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_fire(&event);
@ -1078,7 +1079,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan
switch_channel_event_set_data(channel, event);
switch_event_fire(&event);
}
switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n", channel->name);
return SWITCH_STATUS_SUCCESS;

View File

@ -60,19 +60,6 @@ typedef srtp_hdr_t rtp_hdr_t;
#pragma pack(4)
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
typedef struct {
uint32_t ts; /* timestamp */
} PACKED srtp_mini_hdr_t;
#else
typedef struct {
uint32_t ts; /* timestamp */
} PACKED srtp_mini_hdr_t;
#endif
#ifdef _MSC_VER
#pragma pack()
#endif
@ -85,12 +72,6 @@ typedef struct {
} rtp_msg_t;
typedef struct {
srtp_mini_hdr_t header;
char body[SWITCH_RTP_MAX_BUF_LEN];
} rtp_mini_msg_t;
struct rfc2833_digit {
char digit;
int duration;
@ -162,6 +143,7 @@ struct switch_rtp {
char *user_ice;
switch_time_t last_stun;
uint32_t packet_size;
uint32_t conf_packet_size;
uint32_t rpacket_size;
switch_time_t last_read;
uint32_t ms_per_packet;
@ -170,7 +152,6 @@ struct switch_rtp {
switch_buffer_t *packet_buffer;
struct switch_rtp_vad_data vad_data;
struct switch_rtp_rfc2833_data dtmf_data;
uint8_t mini;
switch_payload_t te;
switch_mutex_t *flag_mutex;
switch_timer_t timer;
@ -180,30 +161,6 @@ struct switch_rtp {
static int global_init = 0;
static void switch_rtp_miniframe_probe(switch_rtp_t *rtp_session)
{
const char *str = "!!!!";
rtp_msg_t msg = {{0}};
int x;
msg.header.ssrc = htonl(RTP_MAGIC_NUMBER);
msg.header.ts = htonl(rtp_session->packet_size);
msg.header.seq = htons(RTP_MAGIC_NUMBER);
msg.header.m = 1;
msg.header.pt = RTP_MAGIC_NUMBER;
msg.header.version = 2;
msg.header.p = 0;
msg.header.x = 0;
msg.header.cc = 0;
snprintf(msg.body, sizeof(msg.body), str);
for(x = 0; x < 3 ; x++) {
switch_size_t bytes = strlen(str) + sizeof(msg.header);
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)&msg, &bytes);
}
}
static switch_status_t ice_out(switch_rtp_t *rtp_session)
{
@ -470,7 +427,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session
rtp_session->seq = (uint16_t)rtp_session->send_msg.header.seq;
rtp_session->payload = payload;
rtp_session->ms_per_packet = ms_per_packet;
rtp_session->packet_size = packet_size;
rtp_session->packet_size = rtp_session->conf_packet_size = packet_size;
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
err_status_t stat;
@ -537,12 +494,7 @@ SWITCH_DECLARE(switch_rtp_t *)switch_rtp_new(char *rx_host,
if (switch_rtp_set_local_address(rtp_session, rx_host, rx_port, err) != SWITCH_STATUS_SUCCESS) {
return NULL;
}
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_MINI)) {
switch_rtp_miniframe_probe(rtp_session);
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_MINI);
}
return rtp_session;
}
@ -807,36 +759,14 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
}
if (bytes > 0) {
uint32_t effective_size = (uint32_t)(bytes - sizeof(srtp_mini_hdr_t));
if (rtp_session->recv_msg.header.pt == RTP_MAGIC_NUMBER) {
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_MINI)) {
switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_MINI);
rtp_session->rpacket_size = ntohl(rtp_session->recv_msg.header.ts);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "YAY MINI-RTP! %d\n", rtp_session->rpacket_size);
switch_rtp_miniframe_probe(rtp_session);
}
continue;
}
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_MINI) && rtp_session->rpacket_size && effective_size > 0) {
uint32_t mfactor = (effective_size % rtp_session->rpacket_size);
if (!mfactor) {
uint32_t ts;
rtp_mini_msg_t *mini = (rtp_mini_msg_t *) &rtp_session->recv_msg;
ts = mini->header.ts;
bytes -= sizeof(srtp_mini_hdr_t);
memmove(rtp_session->recv_msg.body, mini->body, bytes);
rtp_session->recv_msg.header.ts = ts;
rtp_session->recv_msg.header.seq = htons(rtp_session->rseq++);
rtp_session->recv_msg.header.pt = rtp_session->rpayload;
bytes += rtp_header_len;
rtp_session->recv_msg.header.version = 2;
}
}
uint32_t effective_size = (uint32_t)(bytes - rtp_header_len);
if (rtp_session->recv_msg.header.pt == rtp_session->payload && effective_size != rtp_session->packet_size) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Configured packet size %u != inbound packet size %u: auto-correcting..\n",
rtp_session->packet_size,
effective_size
);
rtp_session->packet_size = effective_size;
}
}
if (rtp_session->timer.interval) {
@ -1282,23 +1212,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
}
if (send) {
if (rtp_session->mini) {
rtp_mini_msg_t mini = {{0}};
bytes -= rtp_header_len;
mini.header.ts = send_msg->header.ts;
memcpy(mini.body, send_msg->body, bytes);
bytes += sizeof(srtp_mini_hdr_t);
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)&mini, &bytes);
} else {
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)send_msg, &bytes);
}
if (!rtp_session->mini && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_MINI)) {
rtp_session->mini++;
rtp_session->rpayload = (switch_payload_t)send_msg->header.pt;
rtp_session->rseq = ntohs((uint16_t)send_msg->header.seq);
}
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)send_msg, &bytes);
}
if (rtp_session->ice_user) {