]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
I...HATES...PTIME
authorAnthony Minessale <anthony.minessale@gmail.com>
Sat, 3 Feb 2007 19:47:21 +0000 (19:47 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Sat, 3 Feb 2007 19:47:21 +0000 (19:47 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4114 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/mod_sofia.c
src/switch_rtp.c

index 09e3c065ba6d06c77761e3d1d1c35dc3f15b9cce..a6a1dae8297021a6434395da6ad786b76cb8f1bc 100644 (file)
@@ -684,6 +684,7 @@ static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, c
 {
        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 @@ static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, c
                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 @@ static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, c
                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 @@ 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);
        }
 
+    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);
 }
 
index 5dd815292230ec35a6e845f081ae46860c8b1034..91d35a92fee913f21f9ef808810500423166d2a3 100644 (file)
@@ -141,6 +141,7 @@ struct switch_rtp {
 
        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 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session
        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 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
 
                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);