#define PERIOD_LEN 250
#define MAX_FRAME_PADDING 2
#define MAX_MISSING_SEQ 20
-#define jb_debug(_jb, _level, _format, ...) if (_jb->debug_level >= _level) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(_jb->session), SWITCH_LOG_ALERT, "JB:%p:%s lv:%d ln:%.4d sz:%.3u/%.3u/%.3u/%.3u c:%.3u %.3u/%.3u/%.3u/%.3u %.2f%% ->" _format, (void *) _jb, (jb->type == SJB_TEXT ? "txt" : (jb->type == SJB_AUDIO ? "aud" : "vid")), _level, __LINE__, _jb->min_frame_len, _jb->max_frame_len, _jb->frame_len, _jb->complete_frames, _jb->period_count, _jb->consec_good_count, _jb->period_good_count, _jb->consec_miss_count, _jb->period_miss_count, _jb->period_miss_pct, __VA_ARGS__)
+#define jb_debug(_jb, _level, _format, ...) if (_jb->debug_level >= _level) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(_jb->session), SWITCH_LOG_ALERT, "JB:%p:%s:%d/%d lv:%d ln:%.4d sz:%.3u/%.3u/%.3u/%.3u c:%.3u %.3u/%.3u/%.3u/%.3u %.2f%% ->" _format, (void *) _jb, (jb->type == SJB_TEXT ? "txt" : (jb->type == SJB_AUDIO ? "aud" : "vid")), _jb->allocated_nodes, _jb->visible_nodes, _level, __LINE__, _jb->min_frame_len, _jb->max_frame_len, _jb->frame_len, _jb->complete_frames, _jb->period_count, _jb->consec_good_count, _jb->period_good_count, _jb->consec_miss_count, _jb->period_miss_count, _jb->period_miss_pct, __VA_ARGS__)
//const char *TOKEN_1 = "ONE";
//const char *TOKEN_2 = "TWO";
uint16_t psuedo_seq;
uint16_t last_psuedo_seq;
uint32_t visible_nodes;
+ uint32_t allocated_nodes;
uint32_t complete_frames;
uint32_t frame_len;
uint32_t min_frame_len;
if (!np) {
np = switch_core_alloc(jb->pool, sizeof(*np));
-
+ jb->allocated_nodes++;
np->next = jb->node_list;
if (np->next) {
np->next->prev = np;
switch_core_inthash_delete(jb->node_hash_ts, node->packet.header.ts);
}
- switch_core_inthash_delete(jb->node_hash, node->packet.header.seq);
+ if (switch_core_inthash_delete(jb->node_hash, node->packet.header.seq)) {
+ if (node->packet.header.m && jb->type == SJB_VIDEO) {
+ jb->complete_frames--;
+ }
+ }
switch_mutex_unlock(jb->list_mutex);
}
}
switch_mutex_unlock(jb->list_mutex);
-
- if (x) jb->complete_frames--;
}
static inline switch_jb_node_t *jb_find_lowest_seq(switch_jb_t *jb, uint32_t ts)
switch_core_inthash_insert(jb->node_hash, node->packet.header.seq, node);
+ if (packet->header.m && jb->type == SJB_VIDEO) {
+ jb->complete_frames++;
+ }
+
if (jb->node_hash_ts) {
switch_core_inthash_insert(jb->node_hash_ts, node->packet.header.ts, node);
}
if (jb->type == SJB_VIDEO) {
if (jb->write_init && ((htons(packet->header.seq) >= htons(jb->highest_wrote_seq) && (ntohl(node->packet.header.ts) > ntohl(jb->highest_wrote_ts))) ||
(ntohl(jb->highest_wrote_ts) > (UINT_MAX - 1000) && ntohl(node->packet.header.ts) < 1000))) {
- 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);
jb->next_seq = 0;
jb->highest_read_ts = 0;
jb->highest_read_seq = 0;
- jb->complete_frames = 0;
jb->read_init = 0;
jb->next_seq = 0;
jb->complete_frames = 0;
if (jb->type == SJB_TEXT || jb->type == SJB_AUDIO ||
(jb->read_init && htons(node->packet.header.seq) >= htons(jb->highest_read_seq) && (ntohl(node->packet.header.ts) > ntohl(jb->highest_read_ts)))) {
- jb->complete_frames--;
+
+ if (jb->type == SJB_TEXT || jb->type == SJB_AUDIO) {
+ jb->complete_frames--;
+ }
jb_debug(jb, 2, "READ 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_read_ts = node->packet.header.ts;
} else if (!jb->read_init) {
thin_frames(jb, 8, 25);
}
+ if (jb->complete_frames > jb->max_frame_len * 2) {
+ jb_debug(jb, 2, "JB TOO BIG (%d), RESET\n", jb->complete_frames);
+ switch_jb_reset(jb);
+ }
+
return status;
}