From b8300080209f2f93d57cf10445ae7558c6281db4 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Thu, 19 Dec 2013 10:00:34 +0100 Subject: mgcp/rtp: Refactor mgcp_send to avoid code duplication Currently there are two symmetric code paths which are selected by the packet destination (NET or BTS). This patch introduces 3 variables that take the different values and unifies both code paths into one. Sponsored-by: On-Waves ehf --- openbsc/src/libmgcp/mgcp_network.c | 50 +++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c index 657019e15..1c7c3dafe 100644 --- a/openbsc/src/libmgcp/mgcp_network.c +++ b/openbsc/src/libmgcp/mgcp_network.c @@ -537,6 +537,10 @@ static int mgcp_send(struct mgcp_endpoint *endp, int dest, int is_rtp, struct sockaddr_in *addr, char *buf, int rc) { struct mgcp_trunk_config *tcfg = endp->tcfg; + struct mgcp_rtp_end *rtp_end; + struct mgcp_rtp_state *rtp_state; + int tap_idx; + /* For loop toggle the destination and then dispatch. */ if (tcfg->audio_loop) dest = !dest; @@ -546,35 +550,25 @@ static int mgcp_send(struct mgcp_endpoint *endp, int dest, int is_rtp, dest = !dest; if (dest == MGCP_DEST_NET) { - if (is_rtp) { - mgcp_patch_and_count(endp, &endp->bts_state, - &endp->net_end, - addr, buf, rc); - forward_data(endp->net_end.rtp.fd, - &endp->taps[MGCP_TAP_NET_OUT], buf, rc); - return mgcp_udp_send(endp->net_end.rtp.fd, - &endp->net_end.addr, - endp->net_end.rtp_port, buf, rc); - } else if (!tcfg->omit_rtcp) { - return mgcp_udp_send(endp->net_end.rtcp.fd, - &endp->net_end.addr, - endp->net_end.rtcp_port, buf, rc); - } + rtp_end = &endp->net_end; + rtp_state = &endp->bts_state; + tap_idx = MGCP_TAP_NET_OUT; } else { - if (is_rtp) { - mgcp_patch_and_count(endp, &endp->net_state, - &endp->bts_end, - addr, buf, rc); - forward_data(endp->bts_end.rtp.fd, - &endp->taps[MGCP_TAP_BTS_OUT], buf, rc); - return mgcp_udp_send(endp->bts_end.rtp.fd, - &endp->bts_end.addr, - endp->bts_end.rtp_port, buf, rc); - } else if (!tcfg->omit_rtcp) { - return mgcp_udp_send(endp->bts_end.rtcp.fd, - &endp->bts_end.addr, - endp->bts_end.rtcp_port, buf, rc); - } + rtp_end = &endp->bts_end; + rtp_state = &endp->net_state; + tap_idx = MGCP_TAP_BTS_OUT; + } + + if (is_rtp) { + mgcp_patch_and_count(endp, rtp_state, rtp_end, addr, buf, rc); + forward_data(rtp_end->rtp.fd, &endp->taps[tap_idx], buf, rc); + return mgcp_udp_send(rtp_end->rtp.fd, + &rtp_end->addr, + rtp_end->rtp_port, buf, rc); + } else if (!tcfg->omit_rtcp) { + return mgcp_udp_send(rtp_end->rtcp.fd, + &rtp_end->addr, + rtp_end->rtcp_port, buf, rc); } return 0; -- cgit v1.2.3