From 303b54a2a42bfcd6d2dd509c6e092899e3c6a85b Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Thu, 30 Jan 2014 21:01:34 +0100 Subject: mgcp/rtp: Fix transit computation units Currently micro-secs and RTP rate get mixed when the transit value is computed in mgcp_patch_and_count(). This patch changes get_current_ts() to accept the desired rate as argument and to use it for the time conversion instead of always converting to microseconds. If microseconds are needed, get_current_ts(1000) can be used. The arrival_time is now measured in 1/rtp_end->rate seconds so that it can be directly compared to RTP timestamps as required by RFC3550 (section 6.4.1, see definition of 'interarrival jitter'). Sponsored-by: On-Waves ehf --- openbsc/src/libmgcp/mgcp_network.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'openbsc/src') diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c index b55ac0450..39d58073d 100644 --- a/openbsc/src/libmgcp/mgcp_network.c +++ b/openbsc/src/libmgcp/mgcp_network.c @@ -95,22 +95,25 @@ enum { /** * This does not need to be a precision timestamp and * is allowed to wrap quite fast. The returned value is - * milli seconds now. + * 1/unit seconds. */ -uint32_t get_current_ts(void) +static uint32_t get_current_ts(unsigned unit) { struct timespec tp; uint64_t ret; + if (!unit) + return 0; + memset(&tp, 0, sizeof(tp)); if (clock_gettime(CLOCK_MONOTONIC, &tp) != 0) LOGP(DMGCP, LOGL_NOTICE, "Getting the clock failed.\n"); - /* convert it to useconds */ + /* convert it to 1/unit seconds */ ret = tp.tv_sec; - ret *= 1000; - ret += tp.tv_nsec / 1000 / 1000; + ret *= unit; + ret += (int64_t)tp.tv_nsec * unit / 1000 / 1000 / 1000; return ret; } @@ -370,7 +373,7 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, struct mgcp_rtp_state *sta rtp_hdr = (struct rtp_hdr *) data; seq = ntohs(rtp_hdr->sequence); timestamp = ntohl(rtp_hdr->timestamp); - arrival_time = get_current_ts(); + arrival_time = get_current_ts(rtp_end->rate); ssrc = ntohl(rtp_hdr->ssrc); if (!state->initialized) { @@ -491,9 +494,10 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, struct mgcp_rtp_state *sta } /* - * calculate the jitter between the two packages. The TS should be + * Calculate the jitter between the two packages. The TS should be * taken closer to the read function. This was taken from the - * Appendix A of RFC 3550. The local timestamp has a usec resolution. + * Appendix A of RFC 3550. Timestamp and arrival_time have a 1/rate + * resolution. */ transit = arrival_time - timestamp; d = transit - state->transit; -- cgit v1.2.3