I...HATES...PTIME

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4114 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-02-03 19:47:21 +00:00
parent 051ea5de5c
commit fa53d0aded
2 changed files with 38 additions and 4 deletions

View File

@ -684,6 +684,7 @@ static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, c
{ {
char buf[1024]; char buf[1024];
switch_time_t now = switch_time_now(); switch_time_t now = switch_time_now();
uint32_t ptime = 0;
if (!force && !ip && !sr && switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) { if (!force && !ip && !sr && switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
return; return;
@ -727,7 +728,11 @@ static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, c
int i; int i;
for (i = 0; i < tech_pvt->num_codecs; i++) { for (i = 0; i < tech_pvt->num_codecs; i++) {
const switch_codec_implementation_t *imp = tech_pvt->codecs[i]; const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", imp->ianacode); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", imp->ianacode);
if (!ptime) {
ptime = imp->microseconds_per_frame / 1000;
}
} }
} }
@ -742,19 +747,21 @@ static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, c
if (tech_pvt->fmtp_out) { if (tech_pvt->fmtp_out) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=fmtp:%d %s\n", tech_pvt->pt, tech_pvt->fmtp_out); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=fmtp:%d %s\n", tech_pvt->pt, tech_pvt->fmtp_out);
} }
if (tech_pvt->read_codec.implementation) { if (tech_pvt->read_codec.implementation && ! ptime) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", tech_pvt->read_codec.implementation->microseconds_per_frame / 1000); ptime = tech_pvt->read_codec.implementation->microseconds_per_frame / 1000;
} }
} else if (tech_pvt->num_codecs) { } else if (tech_pvt->num_codecs) {
int i; int i;
for (i = 0; i < tech_pvt->num_codecs; i++) { for (i = 0; i < tech_pvt->num_codecs; i++) {
const switch_codec_implementation_t *imp = tech_pvt->codecs[i]; const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
if (ptime && ptime != imp->microseconds_per_frame / 1000) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ptime %u != advertised ptime %u\n", imp->microseconds_per_frame / 1000, ptime);
}
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d %s/%d\n", imp->ianacode, imp->iananame, imp->samples_per_second); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d %s/%d\n", imp->ianacode, imp->iananame, imp->samples_per_second);
if (imp->fmtp) { if (imp->fmtp) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=fmtp:%d %s\n", imp->ianacode, imp->fmtp); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=fmtp:%d %s\n", imp->ianacode, imp->fmtp);
} }
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", imp->microseconds_per_frame / 1000);
} }
} }
@ -762,6 +769,10 @@ static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, c
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d telephone-event/8000\na=fmtp:%d 0-16\n", tech_pvt->te, tech_pvt->te); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d telephone-event/8000\na=fmtp:%d 0-16\n", tech_pvt->te, tech_pvt->te);
} }
if (ptime) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", ptime);
}
tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, buf); tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, buf);
} }

View File

@ -141,6 +141,7 @@ struct switch_rtp {
char *ice_user; char *ice_user;
char *user_ice; char *user_ice;
char *timer_name;
switch_time_t last_stun; switch_time_t last_stun;
uint32_t packet_size; uint32_t packet_size;
uint32_t conf_packet_size; uint32_t conf_packet_size;
@ -428,6 +429,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session
rtp_session->payload = payload; rtp_session->payload = payload;
rtp_session->ms_per_packet = ms_per_packet; rtp_session->ms_per_packet = ms_per_packet;
rtp_session->packet_size = rtp_session->conf_packet_size = packet_size; rtp_session->packet_size = rtp_session->conf_packet_size = packet_size;
rtp_session->timer_name = switch_core_strdup(rtp_session->pool, timer_name);
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) { if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
err_status_t stat; err_status_t stat;
@ -760,15 +762,36 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
if (bytes > 0 && rtp_session->recv_msg.header.version == 2) { if (bytes > 0 && rtp_session->recv_msg.header.version == 2) {
uint32_t effective_size = (uint32_t)(bytes - rtp_header_len); uint32_t effective_size = (uint32_t)(bytes - rtp_header_len);
uint32_t new_ms = 0, old_size = 0;
if (effective_size && rtp_session->packet_size && rtp_session->recv_msg.header.pt == rtp_session->payload && if (effective_size && rtp_session->packet_size && rtp_session->recv_msg.header.pt == rtp_session->payload &&
effective_size != rtp_session->packet_size) { 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", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Configured packet size %u != inbound packet size %u: auto-correcting..\n",
rtp_session->packet_size, rtp_session->packet_size,
effective_size effective_size
); );
old_size = rtp_session->packet_size;
new_ms = (((rtp_session->ms_per_packet / 1000) * effective_size) / old_size);
rtp_session->ms_per_packet = new_ms * 1000;
rtp_session->packet_size = effective_size; rtp_session->packet_size = effective_size;
if (rtp_session->timer.timer_interface) {
switch_core_timer_destroy(&rtp_session->timer);
if (!switch_strlen_zero(rtp_session->timer_name)) {
if (switch_core_timer_init(&rtp_session->timer,
rtp_session->timer_name,
rtp_session->ms_per_packet / 1000,
rtp_session->packet_size,
rtp_session->pool) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting timer [%s] %d bytes per %dms\n",
rtp_session->timer_name, rtp_session->packet_size, rtp_session->ms_per_packet / 1000);
}
}
}
} }
} }
if (rtp_session->timer.interval) { if (rtp_session->timer.interval) {
check = (uint8_t)(switch_core_timer_check(&rtp_session->timer) == SWITCH_STATUS_SUCCESS); check = (uint8_t)(switch_core_timer_check(&rtp_session->timer) == SWITCH_STATUS_SUCCESS);