}
#endif
+
+static inline switch_jb_node_t *jb_find_penultimate_node(switch_jb_t *jb)
+{
+ switch_jb_node_t *np, *highest = NULL, *second_highest = NULL;
+
+ switch_mutex_lock(jb->list_mutex);
+ for (np = jb->node_list; np; np = np->next) {
+ if (!np->visible) continue;
+
+ if (!highest || ntohl(highest->packet.header.ts) < ntohl(np->packet.header.ts)) {
+ if (highest) second_highest = highest;
+ highest = np;
+ }
+ }
+ switch_mutex_unlock(jb->list_mutex);
+
+ return second_highest ? second_highest : highest;
+}
+
+
static inline void jb_hit(switch_jb_t *jb)
{
jb->period_good_count++;
jb->consec_good_count = 0;
}
-static inline int verify_oldest_frame(switch_jb_t *jb)
+static inline int verify_penultimate_frame(switch_jb_t *jb)
{
- switch_jb_node_t *lowest = jb_find_lowest_node(jb), *np = NULL;
+ switch_jb_node_t *lowest = jb_find_penultimate_node(jb), *np = NULL;
int r = 0;
if (!lowest || !(lowest = jb_find_lowest_seq(jb, lowest->packet.header.ts))) {
end:
- if (!r && jb->session) {
- switch_core_session_request_video_refresh(jb->session);
- }
+ //if (!r && jb->session) {
+ //switch_core_session_request_video_refresh(jb->session);
+ //}
return r;
}
jb->complete_frames++;
jb_debug(jb, 2, "WRITE frame ts: %u complete=%u/%u n:%u\n", ntohl(node->packet.header.ts), jb->complete_frames , jb->frame_len, jb->visible_nodes);
jb->highest_wrote_ts = packet->header.ts;
- verify_oldest_frame(jb);
+ verify_penultimate_frame(jb);
} else if (!jb->write_init) {
jb->highest_wrote_ts = packet->header.ts;
}
if (jb->type == SJB_VIDEO) {
int x;
- if (jb->session) {
- switch_core_session_request_video_refresh(jb->session);
- }
+ //if (jb->session) {
+ // switch_core_session_request_video_refresh(jb->session);
+ //}
for (x = 0; x < 10; x++) {
increment_seq(jb);
switch_core_inthash_destroy(&jb->missing_seq_hash);
switch_core_inthash_init(&jb->missing_seq_hash);
switch_mutex_unlock(jb->mutex);
+
+ if (jb->session) {
+ switch_core_session_request_video_refresh(jb->session);
+ }
}
jb_debug(jb, 2, "%s", "RESET BUFFER\n");
switch_mutex_unlock(jb->mutex);
- if (status == SWITCH_STATUS_SUCCESS) {
+ if (status == SWITCH_STATUS_SUCCESS && jb->type == SJB_AUDIO) {
if (jb->complete_frames > jb->max_frame_len) {
drop_oldest_frame(jb);
}
return 0;
}
-#define MAX_NACK 10
+#define MAX_NACK 1
static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
{
int ret = 0;
int rtcp_ok = 0, rtcp_fb = 0;
switch_time_t now = switch_micro_time_now();
int rate = 0, nack_ttl = 0;
- uint32_t cur_nack[MAX_NACK];
+ uint32_t cur_nack[MAX_NACK] = { 0 };
if (rtp_session->flags[SWITCH_RTP_FLAG_AUTO_CNG] && rtp_session->send_msg.header.ts && rtp_session->cng_pt != INVALID_PT &&
(rtp_session->timer.samplecount - rtp_session->last_write_samplecount >= rtp_session->samples_per_interval * 60)) {
}
if (!rtp_session->ts_norm.last_ssrc || send_msg->header.ssrc != rtp_session->ts_norm.last_ssrc) {
-#define USE_DELTA
-#ifdef USE_DELTA
- if (rtp_session->ts_norm.last_ssrc) {
- rtp_session->ts_norm.delta_ct = 1;
- rtp_session->ts_norm.delta_ttl = 0;
- if (rtp_session->ts_norm.delta) {
- rtp_session->ts_norm.ts += rtp_session->ts_norm.delta;
+ if (switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_GEN_TS_DELTA)) {
+ if (rtp_session->ts_norm.last_ssrc) {
+ rtp_session->ts_norm.delta_ct = 1;
+ rtp_session->ts_norm.delta_ttl = 0;
+ if (rtp_session->ts_norm.delta) {
+ rtp_session->ts_norm.ts += rtp_session->ts_norm.delta;
+ }
}
}
-#endif
+
rtp_session->ts_norm.last_ssrc = send_msg->header.ssrc;
rtp_session->ts_norm.last_frame = ntohl(send_msg->header.ts);
}
if (ntohl(send_msg->header.ts) != rtp_session->ts_norm.last_frame) {
-#ifdef USE_DELTA
- int32_t delta = (int32_t) (ntohl(send_msg->header.ts) - rtp_session->ts_norm.last_frame);
+ if (switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_GEN_TS_DELTA)) {
+ int32_t delta = (int32_t) (ntohl(send_msg->header.ts) - rtp_session->ts_norm.last_frame);
- rtp_session->ts_norm.delta = delta;
- rtp_session->ts_norm.ts += rtp_session->ts_norm.delta;
-#else
- switch_core_timer_sync(&rtp_session->timer);
- rtp_session->ts_norm.ts = rtp_session->timer.samplecount;
-#endif
+ rtp_session->ts_norm.delta = delta;
+ rtp_session->ts_norm.ts += rtp_session->ts_norm.delta;
+ } else {
+ switch_core_timer_sync(&rtp_session->timer);
+ rtp_session->ts_norm.ts = rtp_session->timer.samplecount;
+ }
}
rtp_session->ts_norm.last_frame = ntohl(send_msg->header.ts);