From 74ab3b3728d9d261f9e86dfdf43c5cbff0abcd58 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 8 Apr 2017 20:35:58 +0200 Subject: [PATCH] tsproc: Track the validity of the filtered delay explicitly. We will want to test whether a valid filtered delay value has been calculated or not. However, we cannot simply test for zero since that is a legitimate possible delay value. This patch adds a flag that reflects the state of the filtered delay field. Signed-off-by: Richard Cochran --- tsproc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tsproc.c b/tsproc.c index cf5f0dc..1eb24a1 100644 --- a/tsproc.c +++ b/tsproc.c @@ -42,6 +42,7 @@ struct tsproc { /* Current filtered delay */ tmv_t filtered_delay; + int filtered_delay_valid; /* Delay filter */ struct filter *delay_filter; @@ -115,6 +116,7 @@ void tsproc_set_clock_rate_ratio(struct tsproc *tsp, double clock_rate_ratio) void tsproc_set_delay(struct tsproc *tsp, tmv_t delay) { tsp->filtered_delay = delay; + tsp->filtered_delay_valid = 1; } tmv_t get_raw_delay(struct tsproc *tsp) @@ -149,6 +151,7 @@ int tsproc_update_delay(struct tsproc *tsp, tmv_t *delay) raw_delay = get_raw_delay(tsp); tsp->filtered_delay = filter_sample(tsp->delay_filter, raw_delay); + tsp->filtered_delay_valid = 1; pr_debug("delay filtered %10" PRId64 " raw %10" PRId64, tsp->filtered_delay, raw_delay); @@ -199,5 +202,6 @@ void tsproc_reset(struct tsproc *tsp, int full) if (full) { tsp->clock_rate_ratio = 1.0; filter_reset(tsp->delay_filter); + tsp->filtered_delay_valid = 0; } }