mgcp: Move the rtp state into a struct

Use a struct to group the rtp state for the up and the down
link of the bts.
This commit is contained in:
Holger Hans Peter Freyther
2010-08-03 11:59:04 +00:00
parent 0577dc1372
commit 0b3ffb1513
4 changed files with 21 additions and 18 deletions

View File

@@ -36,6 +36,12 @@ enum mgcp_connection_mode {
MGCP_CONN_LOOPBACK = 4,
};
struct mgcp_rtp_state {
int initialized;
uint16_t seq_no;
int lost_no;
};
struct mgcp_endpoint {
int ci;
@@ -73,10 +79,8 @@ struct mgcp_endpoint {
unsigned int in_remote;
/* sequence bits */
uint16_t net_seq_no;
uint16_t bts_seq_no;
int net_lost_no;
int bts_lost_no;
struct mgcp_rtp_state net_state;
struct mgcp_rtp_state bts_state;
};
#define ENDPOINT_NUMBER(endp) abs(endp - endp->cfg->endpoints)

View File

@@ -94,7 +94,7 @@ int mgcp_send_dummy(struct mgcp_endpoint *endp)
endp->net_rtp, buf, 1);
}
static void patch_and_count(uint16_t *last_seq, int *lost, int payload, char *data, int len)
static void patch_and_count(struct mgcp_rtp_state *state, int payload, char *data, int len)
{
uint16_t seq;
struct rtp_hdr *rtp_hdr;
@@ -105,14 +105,13 @@ static void patch_and_count(uint16_t *last_seq, int *lost, int payload, char *da
rtp_hdr = (struct rtp_hdr *) data;
seq = ntohs(rtp_hdr->sequence);
/* 0 is assumed to be not set */
if (*last_seq == 0)
*last_seq = seq;
else if (*last_seq + 1 != seq)
*lost = abs(seq - (*last_seq + 1));
*last_seq = seq;
if (!state->initialized) {
state->seq_no = seq;
state->initialized = 1;
} else if (state->seq_no + 1u != seq)
state->lost_no = abs(seq - (state->seq_no + 1));
state->seq_no = seq;
if (payload < 0)
return;
@@ -212,14 +211,14 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
if (dest == DEST_NETWORK) {
if (proto == PROTO_RTP)
patch_and_count(&endp->bts_seq_no, &endp->bts_lost_no,
patch_and_count(&endp->bts_state,
endp->net_payload_type, buf, rc);
return udp_send(fd->fd, &endp->remote,
proto == PROTO_RTP ? endp->net_rtp : endp->net_rtcp,
buf, rc);
} else {
if (proto == PROTO_RTP)
patch_and_count(&endp->net_seq_no, &endp->net_lost_no,
patch_and_count(&endp->net_state,
endp->bts_payload_type, buf, rc);
return udp_send(fd->fd, &endp->bts,
proto == PROTO_RTP ? endp->bts_rtp : endp->bts_rtcp,

View File

@@ -763,8 +763,8 @@ void mgcp_free_endp(struct mgcp_endpoint *endp)
memset(&endp->remote, 0, sizeof(endp->remote));
memset(&endp->bts, 0, sizeof(endp->bts));
endp->net_seq_no = endp->bts_seq_no = 0;
endp->net_lost_no = endp->bts_lost_no = 0;
memset(&endp->net_state, 0, sizeof(endp->net_state));
memset(&endp->bts_state, 0, sizeof(endp->bts_state));
endp->conn_mode = endp->orig_mode = MGCP_CONN_NONE;
}

View File

@@ -86,8 +86,8 @@ DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp",
i, endp->ci,
ntohs(endp->net_rtp), ntohs(endp->net_rtcp),
ntohs(endp->bts_rtp), ntohs(endp->bts_rtcp),
inet_ntoa(endp->bts), endp->in_bts, endp->bts_lost_no,
endp->in_remote, endp->net_lost_no,
inet_ntoa(endp->bts), endp->in_bts, endp->bts_state.lost_no,
endp->in_remote, endp->net_state.lost_no,
VTY_NEWLINE);
}