Skip to content

Commit dd4be0a

Browse files
committed
Added ndpi_data_jitter() API call
1 parent 678697b commit dd4be0a

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/include/ndpi_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,7 @@ extern "C" {
17281728
float ndpi_data_variance(struct ndpi_analyze_struct *s);
17291729
float ndpi_data_stddev(struct ndpi_analyze_struct *s);
17301730
float ndpi_data_mean(struct ndpi_analyze_struct *s);
1731+
float ndpi_data_jitter(struct ndpi_analyze_struct *s);
17311732
u_int64_t ndpi_data_last(struct ndpi_analyze_struct *s);
17321733
u_int64_t ndpi_data_min(struct ndpi_analyze_struct *s);
17331734
u_int64_t ndpi_data_max(struct ndpi_analyze_struct *s);

src/include/ndpi_typedefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ typedef struct {
17601760

17611761
struct ndpi_analyze_struct {
17621762
u_int64_t *values;
1763-
u_int64_t min_val, max_val, sum_total;
1763+
u_int64_t min_val, max_val, sum_total, jitter_total;
17641764
u_int32_t num_data_entries, next_value_insert_index;
17651765
u_int16_t num_values_array_len /* length of the values array */;
17661766

src/lib/ndpi_analyze.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ void ndpi_data_add_value(struct ndpi_analyze_struct *s, const u_int64_t value) {
116116
if(!s)
117117
return;
118118

119+
if(s->num_data_entries > 0) {
120+
u_int64_t last = ndpi_data_last(s);
121+
122+
s->jitter_total += (last > value) ? (last - value) : (value - last);
123+
}
124+
119125
if(s->sum_total == 0)
120126
s->min_val = s->max_val = value;
121127
else {
@@ -205,6 +211,15 @@ float ndpi_data_mean(struct ndpi_analyze_struct *s) {
205211

206212
/* ********************************************************************************* */
207213

214+
float ndpi_data_jitter(struct ndpi_analyze_struct *s) {
215+
if(s->num_data_entries < 2)
216+
return(0);
217+
else
218+
return((float)s->jitter_total / (float)(s->num_data_entries - 1));
219+
}
220+
221+
/* ********************************************************************************* */
222+
208223
/* Compute the average only on the sliding window */
209224
float ndpi_data_window_average(struct ndpi_analyze_struct *s) {
210225
if(s && s->num_values_array_len) {

0 commit comments

Comments
 (0)