Currently seq_offset and timestamp_offset are updated on each SSRC
change even when SSRC patching is not allowed.

This patch fixes this by changing mgcp_patch_and_count() to only
update these fields when SSRC patching is allowed.

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

diff --git a/openbsc/src/libmgcp/mgcp_network.c 
b/openbsc/src/libmgcp/mgcp_network.c
index d19b56e..c14b913 100644
--- a/openbsc/src/libmgcp/mgcp_network.c
+++ b/openbsc/src/libmgcp/mgcp_network.c
@@ -248,8 +248,6 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, 
struct mgcp_rtp_state *sta
                        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;
-
                LOGP(DMGCP, LOGL_NOTICE,
                        "The SSRC changed on 0x%x: %u -> %u  "
                        "from %s:%d in %d\n",
@@ -258,22 +256,36 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp, 
struct mgcp_rtp_state *sta
                        inet_ntoa(addr->sin_addr), ntohs(addr->sin_port),
                        endp->conn_mode);
 
-               if (tsdelta == 0) {
-                       tsdelta = rtp_end->rate * rtp_end->frames_per_packet *
-                               rtp_end->frame_duration_num /
-                               rtp_end->frame_duration_den;
+               state->in_stream.ssrc = rtp_hdr->ssrc;
+               if (rtp_end->force_constant_ssrc) {
+                       int32_t tsdelta = state->out_stream.last_tsdelta;
+                       if (tsdelta == 0) {
+                               tsdelta = rtp_end->rate * 
rtp_end->frames_per_packet *
+                                       rtp_end->frame_duration_num /
+                                       rtp_end->frame_duration_den;
+                               LOGP(DMGCP, LOGL_NOTICE,
+                                    "Computed timestamp delta %d based on "
+                                    "rate %d, num frames %d, frame duration 
%d/%d\n",
+                                    tsdelta, rtp_end->rate, 
rtp_end->frames_per_packet,
+                                    rtp_end->frame_duration_num,
+                                    rtp_end->frame_duration_den);
+                       }
+                       state->seq_offset =
+                               (state->out_stream.last_seq + 1) - seq;
+                       state->timestamp_offset =
+                               (state->out_stream.last_timestamp + tsdelta) -
+                               timestamp;
+                       state->patch = 1;
+
                        LOGP(DMGCP, LOGL_NOTICE,
-                            "Computed timestamp delta %d based on "
-                            "rate %d, num frames %d, frame duration %d/%d\n",
-                            tsdelta, rtp_end->rate, rtp_end->frames_per_packet,
-                            rtp_end->frame_duration_num,
-                            rtp_end->frame_duration_den);
+                            "SSRC patching enabled on 0x%x SSRC: %u "
+                            "offset: %d tsdelta: %d "
+                            "from %s:%d in %d\n",
+                            ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
+                            state->seq_offset, tsdelta,
+                            inet_ntoa(addr->sin_addr), ntohs(addr->sin_port),
+                            endp->conn_mode);
                }
-               state->in_stream.ssrc = rtp_hdr->ssrc;
-               state->seq_offset = (state->out_stream.last_seq + 1) - seq;
-               state->timestamp_offset =
-                       (state->out_stream.last_timestamp + tsdelta) - 
timestamp;
-               state->patch = rtp_end->force_constant_ssrc;
 
                state->in_stream.last_tsdelta = 0;
        } else {
-- 
1.7.9.5


Reply via email to