]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add param to jb to try to recapture latency (disabled by default)
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 25 Feb 2011 17:59:45 +0000 (11:59 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 25 Feb 2011 17:59:45 +0000 (11:59 -0600)
src/include/switch_rtp.h
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c
src/switch_ivr.c
src/switch_rtp.c

index 2870bba3afd08cceca1f4a6eb1182eef84d2b86d..94c9d671e958948a468ae91968dd8c4070666333 100644 (file)
@@ -232,7 +232,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_rtcp(switch_rtp_t *rtp_sessi
 SWITCH_DECLARE(switch_status_t) switch_rtp_activate_jitter_buffer(switch_rtp_t *rtp_session, 
                                                                                                                                  uint32_t queue_frames,
                                                                                                                                  uint32_t max_queue_frames,
-                                                                                                                                 uint32_t samples_per_packet, uint32_t samples_per_second);
+                                                                                                                                 uint32_t samples_per_packet, uint32_t samples_per_second, uint32_t max_drift);
 
 SWITCH_DECLARE(switch_status_t) switch_rtp_debug_jitter_buffer(switch_rtp_t *rtp_session, const char *name);
 
index 9e8d8200f4cb311ae5395e09d138dfce18cb9d44..e8e78e51f5aace88ce5c71422bfccf360a7e3aa0 100644 (file)
@@ -1349,10 +1349,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
        case SWITCH_MESSAGE_INDICATE_JITTER_BUFFER:
                {
                        if (switch_rtp_ready(tech_pvt->rtp_session)) {
-                               int len, maxlen = 0, qlen = 0, maxqlen = 50;
+                               int len, maxlen = 0, qlen = 0, maxqlen = 50, max_drift = 0;
 
                                if (msg->string_arg) {
-                                       char *p;
+                                       char *p, *q;
                                        const char *s;
 
                                        if (!strcasecmp(msg->string_arg, "pause")) {
@@ -1379,6 +1379,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                                                if ((p = strchr(msg->string_arg, ':'))) {
                                                        p++;
                                                        maxlen = atol(p);
+                                                       if ((q = strchr(p, ':'))) {
+                                                               q++;
+                                                               max_drift = abs(atol(q));
+                                                       }
                                                }
                                        }
 
@@ -1391,9 +1395,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                                if (qlen) {
                                        if (switch_rtp_activate_jitter_buffer(tech_pvt->rtp_session, qlen, maxqlen,
                                                                                                                  tech_pvt->read_impl.samples_per_packet, 
-                                                                                                                 tech_pvt->read_impl.samples_per_second) == SWITCH_STATUS_SUCCESS) {
+                                                                                                                 tech_pvt->read_impl.samples_per_second, max_drift) == SWITCH_STATUS_SUCCESS) {
                                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), 
-                                                                                 SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames) (%d max frames)\n", len, qlen, maxqlen);
+                                                                                 SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames) (%d max frames) (%d max drift)\n", 
+                                                                                 len, qlen, maxqlen, max_drift);
                                                switch_channel_set_flag(tech_pvt->channel, CF_JITTERBUFFER);
                                        } else {
                                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), 
index 01a70f32b68537869868b54c8a37d26d42311830..66f5e5214049cc47ac6f37d8f89d1525ae9ce3e5 100644 (file)
@@ -3166,12 +3166,16 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
 
                if ((val = switch_channel_get_variable(tech_pvt->channel, "jitterbuffer_msec")) || (val = tech_pvt->profile->jb_msec)) {
                        int jb_msec = atoi(val);
-                       int maxlen = 0;
-                       char *p;
-
+                       int maxlen = 0, max_drift = 0;
+                       char *p, *q;
+                       
                        if ((p = strchr(val, ':'))) {
                                p++;
                                maxlen = atoi(p);
+                               if ((q = strchr(p, ':'))) {
+                                       q++;
+                                       max_drift = abs(atoi(q));
+                               }
                        }
 
                        if (jb_msec < 20 || jb_msec > 10000) {
@@ -3188,7 +3192,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
 
                                if (switch_rtp_activate_jitter_buffer(tech_pvt->rtp_session, qlen, maxqlen,
                                                                                                          tech_pvt->read_impl.samples_per_packet, 
-                                                                                                         tech_pvt->read_impl.samples_per_second) == SWITCH_STATUS_SUCCESS) {
+                                                                                                         tech_pvt->read_impl.samples_per_second, max_drift) == SWITCH_STATUS_SUCCESS) {
                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), 
                                                                          SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames)\n", jb_msec, qlen);
                                        switch_channel_set_flag(tech_pvt->channel, CF_JITTERBUFFER);
index a40da1b077813e16b24ac20920874a757157e187..5a082763b2df686c9812d3e55bf0ac68c4743442 100644 (file)
@@ -2289,7 +2289,7 @@ SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint3
 
        qlen = delay_ms / (interval);
        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting delay to %dms (%d frames)\n", delay_ms, qlen);
-       jb = stfu_n_init(qlen, qlen, read_impl.samples_per_packet, read_impl.samples_per_second);
+       jb = stfu_n_init(qlen, qlen, read_impl.samples_per_packet, read_impl.samples_per_second, 0);
 
        write_frame.codec = switch_core_session_get_read_codec(session);
 
index 029f067ab59c1d87c9f73561b6131b6321755d89..b6b383208176fdbe1428063ece978bc642ca630d 100644 (file)
@@ -1909,7 +1909,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_jitter_buffer(switch_rtp_t *
                                                                                                                                  uint32_t queue_frames, 
                                                                                                                                  uint32_t max_queue_frames, 
                                                                                                                                  uint32_t samples_per_packet, 
-                                                                                                                                 uint32_t samples_per_second)
+                                                                                                                                 uint32_t samples_per_second,
+                                                                                                                                 uint32_t max_drift)
 {
 
        if (!switch_rtp_ready(rtp_session)) {
@@ -1920,7 +1921,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_jitter_buffer(switch_rtp_t *
        if (rtp_session->jb) {
                stfu_n_resize(rtp_session->jb, queue_frames);
        } else {
-               rtp_session->jb = stfu_n_init(queue_frames, max_queue_frames ? max_queue_frames : 50, samples_per_packet, samples_per_second);
+               rtp_session->jb = stfu_n_init(queue_frames, max_queue_frames ? max_queue_frames : 50, samples_per_packet, samples_per_second, max_drift);
        }
        READ_DEC(rtp_session);
        
@@ -2402,7 +2403,7 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
        uint32_t ts;
 
        switch_assert(bytes);
-
+ more:
        *bytes = sizeof(rtp_msg_t);
        status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock_input, 0, (void *) &rtp_session->recv_msg, bytes);
        ts = ntohl(rtp_session->recv_msg.header.ts);
@@ -2489,9 +2490,13 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
                        stfu_n_reset(rtp_session->jb);
                }
 
-               stfu_n_eat(rtp_session->jb, rtp_session->last_read_ts, 
-                                  rtp_session->recv_msg.header.pt,
-                                  rtp_session->recv_msg.body, *bytes - rtp_header_len, rtp_session->timer.samplecount);
+               if (stfu_n_eat(rtp_session->jb, rtp_session->last_read_ts, 
+                                          rtp_session->recv_msg.header.pt,
+                                          rtp_session->recv_msg.body, *bytes - rtp_header_len, rtp_session->timer.samplecount) == STFU_ITS_TOO_LATE) {
+                       printf("doh\n");
+                       goto more;
+               }
+
                status = SWITCH_STATUS_FALSE;
                if (!return_jb_packet) {
                        return status;