[PATCH] osmo-mgw[master]: strct mgcp_rtp_state: Group + document struct members relate...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Mon Dec 25 09:04:04 UTC 2017


Review at  https://gerrit.osmocom.org/5581

strct mgcp_rtp_state: Group + document struct members related to patching

Change-Id: I403ddcafe0a11290103bb017568cfacaf5c04412
---
M include/osmocom/mgcp/mgcp_internal.h
M src/libosmo-mgcp/mgcp_network.c
2 files changed, 31 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/81/5581/1

diff --git a/include/osmocom/mgcp/mgcp_internal.h b/include/osmocom/mgcp/mgcp_internal.h
index c3f9ba1..8d82b14 100644
--- a/include/osmocom/mgcp/mgcp_internal.h
+++ b/include/osmocom/mgcp/mgcp_internal.h
@@ -50,14 +50,21 @@
 };
 
 struct mgcp_rtp_state {
+	/* has this state structure been initialized? */
 	int initialized;
-	int patch_ssrc;
 
-	uint32_t orig_ssrc;
+	struct {
+		/* are we patching the SSRC value? */
+		int patch_ssrc;
+		/* original SSRC (to which we shall patch any different SSRC) */
+		uint32_t orig_ssrc;
+		/* offset to apply on the sequence number */
+		int seq_offset;
+		/* offset to apply on the timestamp number */
+		int32_t timestamp_offset;
+	} patch;
 
-	int seq_offset;
-
-	int32_t  timestamp_offset;
+	/* duration of a packet (FIXME: in which unit?) */
 	uint32_t packet_duration;
 
 	struct mgcp_rtp_stream_state in_stream;
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index fc6a1c8..877ce98 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -230,7 +230,7 @@
 			     "on 0x%x SSRC: %u timestamp: %u "
 			     "from %s:%d\n",
 			     text, seq,
-			     state->timestamp_offset, state->seq_offset,
+			     state->patch.timestamp_offset, state->patch.seq_offset,
 			     ENDPOINT_NUMBER(endp), sstate->ssrc, timestamp,
 			     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 		}
@@ -324,15 +324,15 @@
 	out_timestamp = state->out_stream.last_timestamp + delta_seq * tsdelta;
 	timestamp_offset = out_timestamp - in_timestamp;
 
-	if (state->timestamp_offset != timestamp_offset) {
-		state->timestamp_offset = timestamp_offset;
+	if (state->patch.timestamp_offset != timestamp_offset) {
+		state->patch.timestamp_offset = timestamp_offset;
 
 		LOGP(DRTP, LOGL_NOTICE,
 		     "Timestamp offset change on 0x%x SSRC: %u "
 		     "SeqNo delta: %d, TS offset: %d, "
 		     "from %s:%d\n",
 		     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
-		     delta_seq, state->timestamp_offset,
+		     delta_seq, state->patch.timestamp_offset,
 		     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 	}
 
@@ -353,11 +353,11 @@
 	/* Align according to: T + Toffs - Tlast = k * Tptime */
 
 	ts_error = ts_alignment_error(&state->out_stream, ptime,
-				      timestamp + state->timestamp_offset);
+				      timestamp + state->patch.timestamp_offset);
 
 	/* If there is an alignment error, we have to compensate it */
 	if (ts_error) {
-		state->timestamp_offset += ptime - ts_error;
+		state->patch.timestamp_offset += ptime - ts_error;
 
 		LOGP(DRTP, LOGL_NOTICE,
 		     "Corrected timestamp alignment error of %d on 0x%x SSRC: %u "
@@ -365,7 +365,7 @@
 		     "from %s:%d\n",
 		     ts_error,
 		     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
-		     state->timestamp_offset, inet_ntoa(addr->sin_addr),
+		     state->patch.timestamp_offset, inet_ntoa(addr->sin_addr),
 		     ntohs(addr->sin_port));
 	}
 
@@ -374,7 +374,7 @@
 	 * here would point to a serous problem with the alingnment
 	 * error computation fuction */
 	ts_check = ts_alignment_error(&state->out_stream, ptime,
-				      timestamp + state->timestamp_offset);
+				      timestamp + state->patch.timestamp_offset);
 	OSMO_ASSERT(ts_check == 0);
 
 	/* Return alignment error before compensation */
@@ -507,7 +507,7 @@
 	if (!state->initialized) {
 		state->initialized = 1;
 		state->in_stream.last_seq = seq - 1;
-		state->in_stream.ssrc = state->orig_ssrc = ssrc;
+		state->in_stream.ssrc = state->patch.orig_ssrc = ssrc;
 		state->in_stream.last_tsdelta = 0;
 		state->packet_duration =
 		    mgcp_rtp_packet_duration(endp, rtp_end);
@@ -518,7 +518,7 @@
 		     "endpoint:0x%x initializing stream, SSRC: %u timestamp: %u "
 		     "pkt-duration: %d, from %s:%d\n",
 		     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
-		     state->seq_offset, state->packet_duration,
+		     state->patch.seq_offset, state->packet_duration,
 		     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 		if (state->packet_duration == 0) {
 			state->packet_duration =
@@ -542,7 +542,7 @@
 			int16_t delta_seq;
 
 			/* Always increment seqno by 1 */
-			state->seq_offset =
+			state->patch.seq_offset =
 			    (state->out_stream.last_seq + 1) - seq;
 
 			/* Estimate number of packets that would have been sent */
@@ -554,8 +554,8 @@
 			adjust_rtp_timestamp_offset(endp, state, rtp_end, addr,
 						    delta_seq, timestamp);
 
-			state->patch_ssrc = 1;
-			ssrc = state->orig_ssrc;
+			state->patch.patch_ssrc = 1;
+			ssrc = state->patch.orig_ssrc;
 			if (rtp_end->force_constant_ssrc != -1)
 				rtp_end->force_constant_ssrc -= 1;
 
@@ -564,7 +564,7 @@
 			     "SeqNo offset: %d, TS offset: %d "
 			     "from %s:%d\n",
 			     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
-			     state->seq_offset, state->timestamp_offset,
+			     state->patch.seq_offset, state->patch.timestamp_offset,
 			     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 		}
 
@@ -575,8 +575,8 @@
 				    addr, seq, timestamp, "input",
 				    &state->in_stream.last_tsdelta);
 
-		if (state->patch_ssrc)
-			ssrc = state->orig_ssrc;
+		if (state->patch.patch_ssrc)
+			ssrc = state->patch.orig_ssrc;
 	}
 
 	/* Save before patching */
@@ -591,15 +591,15 @@
 					   timestamp);
 
 	/* Store the updated SSRC back to the packet */
-	if (state->patch_ssrc)
+	if (state->patch.patch_ssrc)
 		rtp_hdr->ssrc = htonl(ssrc);
 
 	/* Apply the offset and store it back to the packet.
 	 * This won't change anything if the offset is 0, so the conditional is
 	 * omitted. */
-	seq += state->seq_offset;
+	seq += state->patch.seq_offset;
 	rtp_hdr->sequence = htons(seq);
-	timestamp += state->timestamp_offset;
+	timestamp += state->patch.timestamp_offset;
 	rtp_hdr->timestamp = htonl(timestamp);
 
 	/* Check again, whether the timestamps are still valid */

-- 
To view, visit https://gerrit.osmocom.org/5581
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I403ddcafe0a11290103bb017568cfacaf5c04412
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list