diff options
author | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-02-14 20:26:04 +0100 |
---|---|---|
committer | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-02-14 20:26:04 +0100 |
commit | 820ae5ef5c76d511104d01813828cf79b604e100 (patch) | |
tree | 16a3ec33a8d585e5b3b6b4ad89490133ac724dfb /src | |
parent | 6892b833505808e76660ec4a2057d750e7943091 (diff) |
timestamp: new file for timestamp helpers
Diffstat (limited to 'src')
-rw-r--r-- | src/core.h | 38 | ||||
-rw-r--r-- | src/srcs.mk | 1 | ||||
-rw-r--r-- | src/timestamp.c | 65 |
3 files changed, 68 insertions, 36 deletions
@@ -505,42 +505,8 @@ static inline uint64_t calc_extended_timestamp(uint32_t num_wraps, uint32_t ts) } -static inline uint64_t timestamp_duration(const struct timestamp_recv *ts) -{ - uint64_t last_ext; - - if (!ts || !ts->is_set) - return 0; - - last_ext = calc_extended_timestamp(ts->num_wraps, ts->last); - - return last_ext - ts->first; -} - - -/* - * -1 backwards wrap-around - * 0 no wrap-around - * 1 forward wrap-around - */ -static inline int timestamp_wrap(uint32_t ts_new, uint32_t ts_old) -{ - int32_t delta; - - if (ts_new < ts_old) { - - delta = (int32_t)ts_new - (int32_t)ts_old; - - if (delta > 0) - return 1; - } - else if ((int32_t)(ts_old - ts_new) > 0) { - - return -1; - } - - return 0; -} +int timestamp_wrap(uint32_t ts_new, uint32_t ts_old); +uint64_t timestamp_duration(const struct timestamp_recv *ts); /* diff --git a/src/srcs.mk b/src/srcs.mk index 86cbe8c..be7906c 100644 --- a/src/srcs.mk +++ b/src/srcs.mk @@ -35,6 +35,7 @@ SRCS += sdp.c SRCS += sipreq.c SRCS += stream.c SRCS += timer.c +SRCS += timestamp.c SRCS += ua.c SRCS += ui.c diff --git a/src/timestamp.c b/src/timestamp.c new file mode 100644 index 0000000..dedf8d9 --- /dev/null +++ b/src/timestamp.c @@ -0,0 +1,65 @@ +/** + * @file timestamp.c Timestamp helpers + * + * Copyright (C) 2010 Creytiv.com + */ + +#include <re.h> +#include <baresip.h> +#include "core.h" + + +/** + * Check if a 32-bit timestamp wraps around + * + * @param ts_new Timestamp of the current packet + * @param ts_old Timestamp of the previous packet + * + * @return Integer describing the wrap-around + + * @retval -1 backwards wrap-around + * @retval 0 no wrap-around + * @retval 1 forward wrap-around + */ +int timestamp_wrap(uint32_t ts_new, uint32_t ts_old) +{ + int32_t delta; + + if (ts_new < ts_old) { + + delta = (int32_t)ts_new - (int32_t)ts_old; + + if (delta > 0) + return 1; + } + else if ((int32_t)(ts_old - ts_new) > 0) { + + return -1; + } + + return 0; +} + + +/** + * Calculate the total timestamp duration, in timestamp units. + * The duration is calculated as the delta between the + * last extended timestamp and the first extended timestamp. + * + * @param ts Receiver timestamp struct + * + * @return Timestamp duration + */ +uint64_t timestamp_duration(const struct timestamp_recv *ts) +{ + uint64_t last_ext; + + if (!ts || !ts->is_set) + return 0; + + last_ext = calc_extended_timestamp(ts->num_wraps, ts->last); + + return last_ext - ts->first; +} + + |