[Freeswitch-svn] [commit] r4114 - in freeswitch/trunk/src: . mod/endpoints/mod_sofia
Freeswitch SVN
anthm at freeswitch.org
Sat Feb 3 14:47:21 EST 2007
Author: anthm
Date: Sat Feb 3 14:47:21 2007
New Revision: 4114
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
freeswitch/trunk/src/switch_rtp.c
Log:
I...HATES...PTIME
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Sat Feb 3 14:47:21 2007
@@ -684,6 +684,7 @@
{
char buf[1024];
switch_time_t now = switch_time_now();
+ uint32_t ptime = 0;
if (!force && !ip && !sr && switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
return;
@@ -727,7 +728,11 @@
int i;
for (i = 0; i < tech_pvt->num_codecs; i++) {
const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
+
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", imp->ianacode);
+ if (!ptime) {
+ ptime = imp->microseconds_per_frame / 1000;
+ }
}
}
@@ -742,19 +747,21 @@
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);
}
- if (tech_pvt->read_codec.implementation) {
- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
+ if (tech_pvt->read_codec.implementation && ! ptime) {
+ ptime = tech_pvt->read_codec.implementation->microseconds_per_frame / 1000;
}
} else if (tech_pvt->num_codecs) {
int i;
for (i = 0; i < tech_pvt->num_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);
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=ptime:%d\n", imp->microseconds_per_frame / 1000);
}
}
@@ -762,6 +769,10 @@
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);
}
Modified: freeswitch/trunk/src/switch_rtp.c
==============================================================================
--- freeswitch/trunk/src/switch_rtp.c (original)
+++ freeswitch/trunk/src/switch_rtp.c Sat Feb 3 14:47:21 2007
@@ -141,6 +141,7 @@
char *ice_user;
char *user_ice;
+ char *timer_name;
switch_time_t last_stun;
uint32_t packet_size;
uint32_t conf_packet_size;
@@ -428,6 +429,7 @@
rtp_session->payload = payload;
rtp_session->ms_per_packet = ms_per_packet;
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)) {
err_status_t stat;
@@ -760,15 +762,36 @@
if (bytes > 0 && rtp_session->recv_msg.header.version == 2) {
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 &&
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
);
+
+ 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;
+
+ 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) {
check = (uint8_t)(switch_core_timer_check(&rtp_session->timer) == SWITCH_STATUS_SUCCESS);
More information about the Freeswitch-svn
mailing list