Skip to content

Commit

Permalink
Added ndpi_data_jitter() API call
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Jan 29, 2025
1 parent 678697b commit dd4be0a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/include/ndpi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;

Expand Down
15 changes: 15 additions & 0 deletions src/lib/ndpi_analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit dd4be0a

Please sign in to comment.