mirror of
				https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
				synced 2025-11-03 21:43:32 +00:00 
			
		
		
		
	strct mgcp_rtp_state: Group + document struct members related to patching
Change-Id: I403ddcafe0a11290103bb017568cfacaf5c04412
This commit is contained in:
		@@ -50,14 +50,21 @@ struct mgcp_rtp_stream_state {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct mgcp_rtp_state {
 | 
					struct mgcp_rtp_state {
 | 
				
			||||||
 | 
						/* has this state structure been initialized? */
 | 
				
			||||||
	int 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;
 | 
						/* duration of a packet (FIXME: in which unit?) */
 | 
				
			||||||
 | 
					 | 
				
			||||||
	int32_t  timestamp_offset;
 | 
					 | 
				
			||||||
	uint32_t packet_duration;
 | 
						uint32_t packet_duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct mgcp_rtp_stream_state in_stream;
 | 
						struct mgcp_rtp_stream_state in_stream;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -231,7 +231,7 @@ static int check_rtp_timestamp(struct mgcp_endpoint *endp,
 | 
				
			|||||||
			     "on 0x%x SSRC: %u timestamp: %u "
 | 
								     "on 0x%x SSRC: %u timestamp: %u "
 | 
				
			||||||
			     "from %s:%d\n",
 | 
								     "from %s:%d\n",
 | 
				
			||||||
			     text, seq,
 | 
								     text, seq,
 | 
				
			||||||
			     state->timestamp_offset, state->seq_offset,
 | 
								     state->patch.timestamp_offset, state->patch.seq_offset,
 | 
				
			||||||
			     ENDPOINT_NUMBER(endp), sstate->ssrc, timestamp,
 | 
								     ENDPOINT_NUMBER(endp), sstate->ssrc, timestamp,
 | 
				
			||||||
			     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 | 
								     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -325,15 +325,15 @@ static int adjust_rtp_timestamp_offset(struct mgcp_endpoint *endp,
 | 
				
			|||||||
	out_timestamp = state->out_stream.last_timestamp + delta_seq * tsdelta;
 | 
						out_timestamp = state->out_stream.last_timestamp + delta_seq * tsdelta;
 | 
				
			||||||
	timestamp_offset = out_timestamp - in_timestamp;
 | 
						timestamp_offset = out_timestamp - in_timestamp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (state->timestamp_offset != timestamp_offset) {
 | 
						if (state->patch.timestamp_offset != timestamp_offset) {
 | 
				
			||||||
		state->timestamp_offset = timestamp_offset;
 | 
							state->patch.timestamp_offset = timestamp_offset;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		LOGP(DRTP, LOGL_NOTICE,
 | 
							LOGP(DRTP, LOGL_NOTICE,
 | 
				
			||||||
		     "Timestamp offset change on 0x%x SSRC: %u "
 | 
							     "Timestamp offset change on 0x%x SSRC: %u "
 | 
				
			||||||
		     "SeqNo delta: %d, TS offset: %d, "
 | 
							     "SeqNo delta: %d, TS offset: %d, "
 | 
				
			||||||
		     "from %s:%d\n",
 | 
							     "from %s:%d\n",
 | 
				
			||||||
		     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
 | 
							     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));
 | 
							     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -354,11 +354,11 @@ static int align_rtp_timestamp_offset(struct mgcp_endpoint *endp,
 | 
				
			|||||||
	/* Align according to: T + Toffs - Tlast = k * Tptime */
 | 
						/* Align according to: T + Toffs - Tlast = k * Tptime */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ts_error = ts_alignment_error(&state->out_stream, ptime,
 | 
						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 there is an alignment error, we have to compensate it */
 | 
				
			||||||
	if (ts_error) {
 | 
						if (ts_error) {
 | 
				
			||||||
		state->timestamp_offset += ptime - ts_error;
 | 
							state->patch.timestamp_offset += ptime - ts_error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		LOGP(DRTP, LOGL_NOTICE,
 | 
							LOGP(DRTP, LOGL_NOTICE,
 | 
				
			||||||
		     "Corrected timestamp alignment error of %d on 0x%x SSRC: %u "
 | 
							     "Corrected timestamp alignment error of %d on 0x%x SSRC: %u "
 | 
				
			||||||
@@ -366,7 +366,7 @@ static int align_rtp_timestamp_offset(struct mgcp_endpoint *endp,
 | 
				
			|||||||
		     "from %s:%d\n",
 | 
							     "from %s:%d\n",
 | 
				
			||||||
		     ts_error,
 | 
							     ts_error,
 | 
				
			||||||
		     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
 | 
							     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));
 | 
							     ntohs(addr->sin_port));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -375,7 +375,7 @@ static int align_rtp_timestamp_offset(struct mgcp_endpoint *endp,
 | 
				
			|||||||
	 * here would point to a serous problem with the alingnment
 | 
						 * here would point to a serous problem with the alingnment
 | 
				
			||||||
	 * error computation fuction */
 | 
						 * error computation fuction */
 | 
				
			||||||
	ts_check = ts_alignment_error(&state->out_stream, ptime,
 | 
						ts_check = ts_alignment_error(&state->out_stream, ptime,
 | 
				
			||||||
				      timestamp + state->timestamp_offset);
 | 
									      timestamp + state->patch.timestamp_offset);
 | 
				
			||||||
	OSMO_ASSERT(ts_check == 0);
 | 
						OSMO_ASSERT(ts_check == 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Return alignment error before compensation */
 | 
						/* Return alignment error before compensation */
 | 
				
			||||||
@@ -508,7 +508,7 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp,
 | 
				
			|||||||
	if (!state->initialized) {
 | 
						if (!state->initialized) {
 | 
				
			||||||
		state->initialized = 1;
 | 
							state->initialized = 1;
 | 
				
			||||||
		state->in_stream.last_seq = seq - 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->in_stream.last_tsdelta = 0;
 | 
				
			||||||
		state->packet_duration =
 | 
							state->packet_duration =
 | 
				
			||||||
		    mgcp_rtp_packet_duration(endp, rtp_end);
 | 
							    mgcp_rtp_packet_duration(endp, rtp_end);
 | 
				
			||||||
@@ -519,7 +519,7 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp,
 | 
				
			|||||||
		     "endpoint:0x%x initializing stream, SSRC: %u timestamp: %u "
 | 
							     "endpoint:0x%x initializing stream, SSRC: %u timestamp: %u "
 | 
				
			||||||
		     "pkt-duration: %d, from %s:%d\n",
 | 
							     "pkt-duration: %d, from %s:%d\n",
 | 
				
			||||||
		     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
 | 
							     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));
 | 
							     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 | 
				
			||||||
		if (state->packet_duration == 0) {
 | 
							if (state->packet_duration == 0) {
 | 
				
			||||||
			state->packet_duration =
 | 
								state->packet_duration =
 | 
				
			||||||
@@ -543,7 +543,7 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp,
 | 
				
			|||||||
			int16_t delta_seq;
 | 
								int16_t delta_seq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* Always increment seqno by 1 */
 | 
								/* Always increment seqno by 1 */
 | 
				
			||||||
			state->seq_offset =
 | 
								state->patch.seq_offset =
 | 
				
			||||||
			    (state->out_stream.last_seq + 1) - seq;
 | 
								    (state->out_stream.last_seq + 1) - seq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* Estimate number of packets that would have been sent */
 | 
								/* Estimate number of packets that would have been sent */
 | 
				
			||||||
@@ -555,8 +555,8 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp,
 | 
				
			|||||||
			adjust_rtp_timestamp_offset(endp, state, rtp_end, addr,
 | 
								adjust_rtp_timestamp_offset(endp, state, rtp_end, addr,
 | 
				
			||||||
						    delta_seq, timestamp);
 | 
											    delta_seq, timestamp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			state->patch_ssrc = 1;
 | 
								state->patch.patch_ssrc = 1;
 | 
				
			||||||
			ssrc = state->orig_ssrc;
 | 
								ssrc = state->patch.orig_ssrc;
 | 
				
			||||||
			if (rtp_end->force_constant_ssrc != -1)
 | 
								if (rtp_end->force_constant_ssrc != -1)
 | 
				
			||||||
				rtp_end->force_constant_ssrc -= 1;
 | 
									rtp_end->force_constant_ssrc -= 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -565,7 +565,7 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp,
 | 
				
			|||||||
			     "SeqNo offset: %d, TS offset: %d "
 | 
								     "SeqNo offset: %d, TS offset: %d "
 | 
				
			||||||
			     "from %s:%d\n",
 | 
								     "from %s:%d\n",
 | 
				
			||||||
			     ENDPOINT_NUMBER(endp), state->in_stream.ssrc,
 | 
								     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));
 | 
								     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -576,8 +576,8 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp,
 | 
				
			|||||||
				    addr, seq, timestamp, "input",
 | 
									    addr, seq, timestamp, "input",
 | 
				
			||||||
				    &state->in_stream.last_tsdelta);
 | 
									    &state->in_stream.last_tsdelta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (state->patch_ssrc)
 | 
							if (state->patch.patch_ssrc)
 | 
				
			||||||
			ssrc = state->orig_ssrc;
 | 
								ssrc = state->patch.orig_ssrc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Save before patching */
 | 
						/* Save before patching */
 | 
				
			||||||
@@ -592,15 +592,15 @@ void mgcp_patch_and_count(struct mgcp_endpoint *endp,
 | 
				
			|||||||
					   timestamp);
 | 
										   timestamp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Store the updated SSRC back to the packet */
 | 
						/* Store the updated SSRC back to the packet */
 | 
				
			||||||
	if (state->patch_ssrc)
 | 
						if (state->patch.patch_ssrc)
 | 
				
			||||||
		rtp_hdr->ssrc = htonl(ssrc);
 | 
							rtp_hdr->ssrc = htonl(ssrc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Apply the offset and store it back to the packet.
 | 
						/* Apply the offset and store it back to the packet.
 | 
				
			||||||
	 * This won't change anything if the offset is 0, so the conditional is
 | 
						 * This won't change anything if the offset is 0, so the conditional is
 | 
				
			||||||
	 * omitted. */
 | 
						 * omitted. */
 | 
				
			||||||
	seq += state->seq_offset;
 | 
						seq += state->patch.seq_offset;
 | 
				
			||||||
	rtp_hdr->sequence = htons(seq);
 | 
						rtp_hdr->sequence = htons(seq);
 | 
				
			||||||
	timestamp += state->timestamp_offset;
 | 
						timestamp += state->patch.timestamp_offset;
 | 
				
			||||||
	rtp_hdr->timestamp = htonl(timestamp);
 | 
						rtp_hdr->timestamp = htonl(timestamp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Check again, whether the timestamps are still valid */
 | 
						/* Check again, whether the timestamps are still valid */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user