void stfu_n_report(stfu_instance_t *i, stfu_report_t *r);
void stfu_n_destroy(stfu_instance_t **i);
stfu_instance_t *stfu_n_init(uint32_t qlen, uint32_t max_qlen, uint32_t samples_per_packet, uint32_t samples_per_second, uint32_t max_drift_ms);
-stfu_status_t stfu_n_resize(stfu_instance_t *i, uint32_t qlen);
+stfu_status_t _stfu_n_resize(stfu_instance_t *i, int32_t qlen, int line);
+#define stfu_n_resize(_i, _ql) _stfu_n_resize(_i, _ql, __LINE__)
stfu_status_t stfu_n_add_data(stfu_instance_t *i, uint32_t ts, uint16_t seq, uint32_t pt, void *data, size_t datalen, uint32_t timer_ts, int last);
stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i);
SWITCH_DECLARE(int32_t) stfu_n_copy_next_frame(stfu_instance_t *jb, uint32_t timestamp, uint16_t seq, uint16_t distance, stfu_frame_t *next_frame);
//#define DB_JB 1
+#define DBG_IN 1
+#define DBG_OUT 2
+
#ifndef UINT_MAX
# define UINT_MAX 4294967295U
#endif
if (i->name) free(i->name);
if (name) {
+ int debug = 0;
+
+ if (strstr(name, ":out")) {
+ debug |= DBG_OUT;
+ }
+
+ if (strstr(name, ":in")) {
+ debug |= DBG_IN;
+ }
+
+ if (debug) i->debug = debug;
+ else i->debug = 3;
+
i->name = strdup(name);
- i->debug = 1;
} else {
i->name = strdup("none");
i->debug = 0;
r->period_missing_percent = i->period_missing_percent;
}
-stfu_status_t stfu_n_resize(stfu_instance_t *i, uint32_t qlen)
+stfu_status_t _stfu_n_resize(stfu_instance_t *i, int32_t qlen, int line)
{
stfu_status_t s;
+ uint32_t incr = qlen;
if (i->qlen == i->max_qlen) {
return STFU_IT_FAILED;
}
+ qlen = i->qlen + incr;
+
if (i->max_qlen && qlen > i->max_qlen) {
if (i->qlen < i->max_qlen) {
qlen = i->max_qlen;
}
}
+ if (stfu_log != null_logger && i->debug) {
+ stfu_log(STFU_LOG_EMERG, "%d %s resize %s %u %u\n", line, i->name, incr > 0 ? "up" : "down", i->qlen, i->qlen + incr);
+ }
+
if ((s = stfu_n_resize_aqueue(&i->a_queue, qlen)) == STFU_IT_WORKED) {
stfu_n_resize_aqueue(&i->b_queue, qlen);
s = stfu_n_resize_aqueue(&i->c_queue, qlen);
i->last_frame = NULL;
}
+ if (s == STFU_IT_WORKED) {
+ if (incr < 0) {
+ stfu_n_sync(i, i->qlen);
+ } else {
+ stfu_n_reset_counters(i);
+ }
+ }
+
return s;
}
if (++i->drift_dropped_packets < i->drift_max_dropped) {
stfu_log(STFU_LOG_EMERG, "%s TOO LATE !!! %u \n\n\n", i->name, ts);
stfu_n_reset(i);
+ stfu_n_resize(i, 1);
//stfu_n_sync(i, 1);
//return STFU_ITS_TOO_LATE;
}
if (stfu_log != null_logger && i->debug) {
stfu_log(STFU_LOG_EMERG, "%s TOO LATE !!! %u \n\n\n", i->name, ts);
}
+ stfu_n_resize(i, 1);
stfu_n_sync(i, 1);
return STFU_ITS_TOO_LATE;
}
i->period_need_range_avg = i->period_need_range / least1(i->period_missing_count);
if (i->period_missing_count > i->qlen * 2) {
- if (stfu_log != null_logger && i->debug) {
- stfu_log(STFU_LOG_EMERG, "%s resize up %u %u\n", i->name, i->qlen, i->qlen + 1);
- }
- stfu_n_resize(i, i->qlen + 1);
- stfu_n_reset_counters(i);
+ stfu_n_resize(i, 1);
}
-
i->diff = 0;
stfu_log(STFU_LOG_EMERG, "PERIOD %f jitter missing:%f q:%d/%d\n", i->period_jitter_percent, i->period_missing_percent, i->qlen, i->orig_qlen);
}
- if (i->qlen > i->orig_qlen && i->period_jitter_percent < PERIOD_JITTER_TOLERANCE && i->period_missing_percent < PERIOD_JITTER_TOLERANCE) {
- if (stfu_log != null_logger && i->debug) {
- stfu_log(STFU_LOG_EMERG, "%s resize down %u %u\n", i->name, i->qlen, i->qlen - 1);
+ if (i->qlen > i->orig_qlen) {
+ if (i->period_jitter_percent < PERIOD_JITTER_TOLERANCE && i->period_missing_percent < PERIOD_JITTER_TOLERANCE) {
+ stfu_n_resize(i, -1);
}
- stfu_n_resize(i, i->qlen - 1);
- stfu_n_sync(i, i->qlen);
}
stfu_n_reset_counters(i);
}
- if (stfu_log != null_logger && i->debug) {
+ if (stfu_log != null_logger && (i->debug & DBG_IN)) {
double jitter_percent = (double)(((double)i->period_jitter_count / (double)i->period_packet_in_count) * 100.0f);
double missing_percent = (double)(((double)i->period_missing_count / (double)i->period_packet_in_count) * 100.0f);
}
}
- if (stfu_log != null_logger && i->debug) {
+ if (stfu_log != null_logger && (i->debug & DBG_OUT)) {
if (found) {
- stfu_log(STFU_LOG_EMERG, "%s OUT: %u:%u %u\n", i->name, rframe->ts, rframe->ts / i->samples_per_packet, rframe->plc);
+ stfu_log(STFU_LOG_EMERG, "O: %s %u:%u %u\n", i->name, rframe->ts, rframe->ts / i->samples_per_packet, rframe->plc);
}
}