aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-08-03 11:59:04 +0000
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-08-03 23:57:16 +0800
commit3186892771fe8174e42c7e3cddc7baf4c9abb0cd (patch)
tree92a9c02c013ecb8fe83e472529478f40ad0828bb
parentebc824cd2e1777294e71e47dffd8a41a253b2045 (diff)
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.
-rw-r--r--openbsc/include/openbsc/mgcp_internal.h12
-rw-r--r--openbsc/src/mgcp/mgcp_network.c19
-rw-r--r--openbsc/src/mgcp/mgcp_protocol.c4
-rw-r--r--openbsc/src/mgcp/mgcp_vty.c4
4 files changed, 21 insertions, 18 deletions
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index 62161fdc9..adb01f467 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -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)
diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c
index 5923fea79..d2dbeebe4 100644
--- a/openbsc/src/mgcp/mgcp_network.c
+++ b/openbsc/src/mgcp/mgcp_network.c
@@ -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;
@@ -210,14 +209,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,
diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c
index 5883c155c..2a5ce08d0 100644
--- a/openbsc/src/mgcp/mgcp_protocol.c
+++ b/openbsc/src/mgcp/mgcp_protocol.c
@@ -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;
}
diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c
index 45df0a23d..a179b7a09 100644
--- a/openbsc/src/mgcp/mgcp_vty.c
+++ b/openbsc/src/mgcp/mgcp_vty.c
@@ -87,8 +87,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);
}