The tsdelta computation and error detection didn't handle the
intialisation phase properly.

This patches fixes this by skipping the output timing validation for
the first packet.

Sponsored-by: On-Waves ehf
---
 openbsc/src/libmgcp/mgcp_network.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/openbsc/src/libmgcp/mgcp_network.c 
b/openbsc/src/libmgcp/mgcp_network.c
index 75d39c1..1ce9cc2 100644
--- a/openbsc/src/libmgcp/mgcp_network.c
+++ b/openbsc/src/libmgcp/mgcp_network.c
@@ -219,6 +219,7 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, 
struct mgcp_rtp_state *sta
        uint32_t timestamp;
        struct rtp_hdr *rtp_hdr;
        int payload = rtp_end->payload_type;
+       int initializing = 0;
 
        if (len < sizeof(*rtp_hdr))
                return;
@@ -229,6 +230,7 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, 
struct mgcp_rtp_state *sta
        arrival_time = get_current_ts();
 
        if (!state->initialized) {
+               initializing = 1;
                state->in_stream.last_seq = seq - 1;
                state->in_stream.ssrc = state->orig_ssrc = rtp_hdr->ssrc;
                state->in_stream.last_tsdelta = 0;
@@ -237,6 +239,14 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, 
struct mgcp_rtp_state *sta
                state->jitter = 0;
                state->transit = arrival_time - timestamp;
                state->out_stream = state->in_stream;
+               state->out_stream.last_timestamp = timestamp;
+               LOGP(DMGCP, LOGL_INFO,
+                       "Initializing stream on 0x%x SSRC: %u timestamp: %u "
+                       "from %s:%d in %d\n",
+                       ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
+                       state->seq_offset,
+                       inet_ntoa(addr->sin_addr), ntohs(addr->sin_port),
+                       endp->conn_mode);
        } else if (state->in_stream.ssrc != rtp_hdr->ssrc) {
                int32_t tsdelta = state->out_stream.last_tsdelta;
                if (tsdelta == 0) {
@@ -286,9 +296,10 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, 
struct mgcp_rtp_state *sta
        }
 
        /* Check again, whether the timestamps are still valid */
-       check_rtp_timestamp(endp, &state->out_stream, rtp_end, addr,
-                           seq, timestamp, "output",
-                           &state->out_stream.last_tsdelta);
+       if (!initializing)
+               check_rtp_timestamp(endp, &state->out_stream, rtp_end, addr,
+                                   seq, timestamp, "output",
+                                   &state->out_stream.last_tsdelta);
 
        /*
         * The below takes the shape of the validation from Appendix A. Check
-- 
1.7.9.5


Reply via email to