From d0ae75c37e100f39013d9bf9aff2a36ee22ca12d Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 21 Sep 2014 19:25:34 +0200 Subject: metric: add metric_init() - metric_init calls tmr_start(). tmr_start must be called from the re_main() thread. --- src/core.h | 1 + src/metric.c | 13 ++++++++++++- src/stream.c | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core.h b/src/core.h index ea2dc37..f8c21ac 100644 --- a/src/core.h +++ b/src/core.h @@ -226,6 +226,7 @@ struct metric { uint32_t n_bytes_last; }; +void metric_init(struct metric *metric); void metric_reset(struct metric *metric); void metric_add_packet(struct metric *metric, size_t packetsize); uint32_t metric_avg_bitrate(const struct metric *metric); diff --git a/src/metric.c b/src/metric.c index f509805..f3e8d06 100644 --- a/src/metric.c +++ b/src/metric.c @@ -17,6 +17,9 @@ static void tmr_handler(void *arg) tmr_start(&metric->tmr, TMR_INTERVAL * 1000, tmr_handler, metric); + if (!metric->started) + return; + if (now <= metric->ts_last) return; @@ -38,12 +41,20 @@ static void metric_start(struct metric *metric) return; metric->ts_start = tmr_jiffies(); - tmr_start(&metric->tmr, 1, tmr_handler, metric); metric->started = true; } +void metric_init(struct metric *metric) +{ + if (!metric) + return; + + tmr_start(&metric->tmr, 100, tmr_handler, metric); +} + + void metric_reset(struct metric *metric) { if (!metric) diff --git a/src/stream.c b/src/stream.c index e9cf871..07f51bd 100644 --- a/src/stream.c +++ b/src/stream.c @@ -310,6 +310,9 @@ int stream_alloc(struct stream **sp, const struct config_avt *cfg, s->pt_enc = -1; + metric_init(&s->metric_tx); + metric_init(&s->metric_rx); + list_append(call_streaml(call), &s->le, s); out: -- cgit v1.2.3