diff --git a/conf/default_context.xml b/conf/default_context.xml index 7b8b2688a5..de88059a47 100644 --- a/conf/default_context.xml +++ b/conf/default_context.xml @@ -53,7 +53,7 @@ - + diff --git a/libs/stfu/stfu.c b/libs/stfu/stfu.c index 371b47b9ca..64bf9c0608 100644 --- a/libs/stfu/stfu.c +++ b/libs/stfu/stfu.c @@ -90,6 +90,21 @@ stfu_instance_t *stfu_n_init(uint32_t qlen) return i; } +void stfu_n_reset(stfu_instance_t *i) +{ + i->in_queue = &i->a_queue; + i->out_queue = &i->b_queue; + i->in_queue->array_len = 0; + i->out_queue->array_len = 0; + i->out_queue->wr_len = 0; + i->out_queue->last_index = 0; + i->miss_count = 0; + i->last_ts = 0; + i->running = 0; + i->miss_count = 0; + i->interval = 0; +} + static int32_t stfu_n_measure_interval(stfu_queue_t *queue) { uint32_t index; @@ -148,7 +163,7 @@ stfu_status_t stfu_n_add_data(stfu_instance_t *i, uint32_t ts, void *data, size_ i->out_queue->wr_len = 0; i->out_queue->last_index = 0; i->miss_count = 0; - + if (stfu_n_process(i, i->out_queue) < 0) { return STFU_IT_FAILED; } @@ -183,7 +198,7 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i) stfu_frame_t *frame = NULL, *rframe = NULL; - if ((i->out_queue->wr_len == i->out_queue->array_len) || !i->out_queue->array_len) { + if (((i->out_queue->wr_len == i->out_queue->array_len) || !i->out_queue->array_len)) { return NULL; } @@ -199,7 +214,7 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i) } frame = &i->out_queue->array[index]; - + if (frame->ts != should_have) { int tried = 0; for (index2 = 0; index2 < i->out_queue->array_len; index2++) { @@ -226,12 +241,13 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i) i->miss_count++; - if (i->miss_count > 10 || i->in_queue->array_len == i->in_queue->array_size ) { - i->out_queue->wr_len = i->out_queue->array_len; - i->last_ts = should_have = frame->ts; + if (i->miss_count > 10 || (i->in_queue->array_len == i->in_queue->array_size) || tried >= i->in_queue->array_size) { + i->running = 0; + i->interval = 0; + i->out_queue->wr_len = i->out_queue->array_size; return NULL; } - + i->last_ts = should_have; rframe = &i->out_queue->int_frame; rframe->dlen = i->out_queue->array[i->out_queue->last_index].dlen; diff --git a/libs/stfu/stfu.h b/libs/stfu/stfu.h index 792a4959c7..18c74dbd14 100644 --- a/libs/stfu/stfu.h +++ b/libs/stfu/stfu.h @@ -88,7 +88,9 @@ void stfu_n_destroy(stfu_instance_t **i); stfu_instance_t *stfu_n_init(uint32_t qlen); stfu_status_t stfu_n_add_data(stfu_instance_t *i, uint32_t ts, void *data, size_t datalen, int last); stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i); -#define stfu_im_done() stfu_n_add_data(i, 0, NULL, 0, 1) +void stfu_n_reset(stfu_instance_t *i); + +#define stfu_im_done(i) stfu_n_add_data(i, 0, NULL, 0, 1) #define stfu_n_eat(i,t,d,l) stfu_n_add_data(i, t, d, l, 0) #ifdef __cplusplus diff --git a/src/mod/timers/mod_softtimer/mod_softtimer.c b/src/mod/timers/mod_softtimer/mod_softtimer.c index b3a3f64261..cc305d8c98 100644 --- a/src/mod/timers/mod_softtimer/mod_softtimer.c +++ b/src/mod/timers/mod_softtimer/mod_softtimer.c @@ -73,7 +73,7 @@ static inline switch_status_t timer_init(switch_timer_t *timer) { timer_private_t *private_info; - if (globals.RUNNING != 1) { + if (globals.RUNNING != 1 || !globals.mutex) { return SWITCH_STATUS_FALSE; } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 12ac302411..ecfa437c0e 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -816,6 +816,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ switch_size_t bytes = 0; switch_status_t status; uint8_t check = 1; + stfu_frame_t *jb_frame; if (!rtp_session->timer.interval) { rtp_session->last_time = switch_time_now(); @@ -833,22 +834,23 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ return -1; } - if (rtp_session->jb && bytes) { - stfu_frame_t *frame; + if (rtp_session->jb && bytes && rtp_session->recv_msg.header.pt == rtp_session->payload) { + if (rtp_session->recv_msg.header.m) { + stfu_n_reset(rtp_session->jb); + } stfu_n_eat(rtp_session->jb, ntohl(rtp_session->recv_msg.header.ts), rtp_session->recv_msg.body, bytes - rtp_header_len); - if ((frame = stfu_n_read_a_frame(rtp_session->jb))) { - memcpy(rtp_session->recv_msg.body, frame->data, frame->dlen); - if (frame->plc) { + if ((jb_frame = stfu_n_read_a_frame(rtp_session->jb))) { + memcpy(rtp_session->recv_msg.body, jb_frame->data, jb_frame->dlen); + if (jb_frame->plc) { *flags |= SFF_PLC; - } - bytes = frame->dlen + rtp_header_len; - rtp_session->recv_msg.header.ts = htonl(frame->ts); + } + bytes = jb_frame->dlen + rtp_header_len; + rtp_session->recv_msg.header.ts = htonl(jb_frame->ts); } else { bytes = 0; continue; - } - + } } if (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) { @@ -882,15 +884,22 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ if (check) { do_2833(rtp_session); - - if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) { + + if (rtp_session->jb && (jb_frame = stfu_n_read_a_frame(rtp_session->jb))) { + memcpy(rtp_session->recv_msg.body, jb_frame->data, jb_frame->dlen); + if (jb_frame->plc) { + *flags |= SFF_PLC; + } + bytes = jb_frame->dlen + rtp_header_len; + rtp_session->recv_msg.header.ts = htonl(jb_frame->ts); + } else if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) { uint8_t *data = (uint8_t *) rtp_session->recv_msg.body; /* We're late! We're Late! */ if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK) && status == SWITCH_STATUS_BREAK) { switch_yield(1000); continue; } - + memset(data, 0, 2); data[0] = 65;