From 3a24b972c03418832ecc5eb94166ab4b6e5e7205 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 7 Oct 2015 11:21:51 -0500 Subject: [PATCH] FS-8315 #resolve [rtp_media_timeout not working] --- src/switch_jitterbuffer.c | 4 ++++ src/switch_rtp.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/switch_jitterbuffer.c b/src/switch_jitterbuffer.c index c7d13d33e2..530db657e3 100644 --- a/src/switch_jitterbuffer.c +++ b/src/switch_jitterbuffer.c @@ -1138,6 +1138,10 @@ SWITCH_DECLARE(switch_status_t) switch_jb_get_packet(switch_jb_t *jb, switch_rtp switch_mutex_lock(jb->mutex); + if (jb->complete_frames == 0) { + switch_goto_status(SWITCH_STATUS_BREAK, end); + } + if (jb->complete_frames < jb->frame_len) { jb_debug(jb, 2, "BUFFERING %u/%u\n", jb->complete_frames , jb->frame_len); switch_goto_status(SWITCH_STATUS_MORE_DATA, end); diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 049611c28d..6554e6c90d 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -438,6 +438,8 @@ struct switch_rtp { uint8_t has_rtp; uint8_t has_rtcp; uint8_t has_ice; + uint8_t punts; + uint8_t clean; #ifdef ENABLE_ZRTP zrtp_session_t *zrtp_session; zrtp_profile_t *zrtp_profile; @@ -4060,20 +4062,22 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_jitter_buffer(switch_rtp_t * max_queue_frames = queue_frames * 3; } - READ_INC(rtp_session); + if (rtp_session->jb) { status = switch_jb_set_frames(rtp_session->jb, queue_frames, max_queue_frames); } else { + READ_INC(rtp_session); status = switch_jb_create(&rtp_session->jb, SJB_AUDIO, queue_frames, max_queue_frames, rtp_session->pool); switch_jb_set_session(rtp_session->jb, rtp_session->session); if (switch_true(switch_channel_get_variable_dup(switch_core_session_get_channel(rtp_session->session), "jb_use_timestamps", SWITCH_FALSE, -1))) { switch_jb_ts_mode(rtp_session->jb, samples_per_packet, samples_per_second); } //switch_jb_debug_level(rtp_session->jb, 10); + READ_DEC(rtp_session); } - READ_DEC(rtp_session); + return status; } @@ -5022,6 +5026,12 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t tries++; if (tries > 20) { + if (rtp_session->jb && !rtp_session->pause_jb && jb_valid(rtp_session)) { + switch_jb_reset(rtp_session->jb); + } + rtp_session->punts++; + rtp_session->clean = 0; + *bytes = 0; return SWITCH_STATUS_BREAK; } @@ -5108,8 +5118,8 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t } } - rtp_session->missed_count = 0; if (rtp_session->has_rtp) { + rtp_session->missed_count = 0; switch_cp_addr(rtp_session->rtp_from_addr, rtp_session->from_addr); rtp_session->last_rtp_hdr = rtp_session->recv_msg.header; } @@ -5554,8 +5564,12 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t switch(jstatus) { case SWITCH_STATUS_MORE_DATA: - block = 1; - goto more; + if (rtp_session->punts < 4) { + block = 1; + goto more; + } + *bytes = 0; + break; case SWITCH_STATUS_NOTFOUND: { int pt = get_recv_payload(rtp_session); @@ -5574,7 +5588,9 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t rtp_session->stats.inbound.jb_packet_count++; status = SWITCH_STATUS_SUCCESS; rtp_session->last_rtp_hdr = rtp_session->recv_msg.header; - + if (++rtp_session->clean > 200) { + rtp_session->punts = 0; + } if (!xcheck_jitter) { check_jitter(rtp_session); xcheck_jitter = *bytes; @@ -6217,9 +6233,9 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ ret = -1; goto end; } - + if (rtp_session->max_missed_packets && read_loops == 1 && !rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) { - if (bytes) { + if (bytes && status == SWITCH_STATUS_SUCCESS) { rtp_session->missed_count = 0; } else if (++rtp_session->missed_count >= rtp_session->max_missed_packets) { ret = -2;