diff options
-rw-r--r-- | src/include/ndpi_api.h | 1 | ||||
-rw-r--r-- | src/include/ndpi_typedefs.h | 2 | ||||
-rw-r--r-- | src/lib/ndpi_analyze.c | 15 |
3 files changed, 17 insertions, 1 deletions
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h index 48b225d77..09d7c87cc 100644 --- a/src/include/ndpi_api.h +++ b/src/include/ndpi_api.h @@ -1728,6 +1728,7 @@ extern "C" { float ndpi_data_variance(struct ndpi_analyze_struct *s); float ndpi_data_stddev(struct ndpi_analyze_struct *s); float ndpi_data_mean(struct ndpi_analyze_struct *s); + float ndpi_data_jitter(struct ndpi_analyze_struct *s); u_int64_t ndpi_data_last(struct ndpi_analyze_struct *s); u_int64_t ndpi_data_min(struct ndpi_analyze_struct *s); u_int64_t ndpi_data_max(struct ndpi_analyze_struct *s); diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h index dd9effa95..ad09dfcaa 100644 --- a/src/include/ndpi_typedefs.h +++ b/src/include/ndpi_typedefs.h @@ -1760,7 +1760,7 @@ typedef struct { struct ndpi_analyze_struct { u_int64_t *values; - u_int64_t min_val, max_val, sum_total; + u_int64_t min_val, max_val, sum_total, jitter_total; u_int32_t num_data_entries, next_value_insert_index; u_int16_t num_values_array_len /* length of the values array */; diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index 176f4eeef..ab3da54ab 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -116,6 +116,12 @@ void ndpi_data_add_value(struct ndpi_analyze_struct *s, const u_int64_t value) { if(!s) return; + if(s->num_data_entries > 0) { + u_int64_t last = ndpi_data_last(s); + + s->jitter_total += (last > value) ? (last - value) : (value - last); + } + if(s->sum_total == 0) s->min_val = s->max_val = value; else { @@ -205,6 +211,15 @@ float ndpi_data_mean(struct ndpi_analyze_struct *s) { /* ********************************************************************************* */ +float ndpi_data_jitter(struct ndpi_analyze_struct *s) { + if(s->num_data_entries < 2) + return(0); + else + return((float)s->jitter_total / (float)(s->num_data_entries - 1)); +} + +/* ********************************************************************************* */ + /* Compute the average only on the sliding window */ float ndpi_data_window_average(struct ndpi_analyze_struct *s) { if(s && s->num_values_array_len) { |