From 820ae5ef5c76d511104d01813828cf79b604e100 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Wed, 14 Feb 2018 20:26:04 +0100 Subject: timestamp: new file for timestamp helpers --- src/core.h | 38 ++------------------------------- src/srcs.mk | 1 + src/timestamp.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 36 deletions(-) create mode 100644 src/timestamp.c (limited to 'src') diff --git a/src/core.h b/src/core.h index d08f1f2..4fdc509 100644 --- a/src/core.h +++ b/src/core.h @@ -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 +#include +#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; +} + + -- cgit v1.2.3