mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
synced 2025-11-02 13:03:33 +00:00
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
This commit is contained in:
@@ -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 sockaddr_in *addr, char *buf, int rc)
|
||||||
{
|
{
|
||||||
struct mgcp_trunk_config *tcfg = endp->tcfg;
|
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. */
|
/* For loop toggle the destination and then dispatch. */
|
||||||
if (tcfg->audio_loop)
|
if (tcfg->audio_loop)
|
||||||
dest = !dest;
|
dest = !dest;
|
||||||
@@ -546,35 +550,25 @@ static int mgcp_send(struct mgcp_endpoint *endp, int dest, int is_rtp,
|
|||||||
dest = !dest;
|
dest = !dest;
|
||||||
|
|
||||||
if (dest == MGCP_DEST_NET) {
|
if (dest == MGCP_DEST_NET) {
|
||||||
if (is_rtp) {
|
rtp_end = &endp->net_end;
|
||||||
mgcp_patch_and_count(endp, &endp->bts_state,
|
rtp_state = &endp->bts_state;
|
||||||
&endp->net_end,
|
tap_idx = MGCP_TAP_NET_OUT;
|
||||||
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);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (is_rtp) {
|
rtp_end = &endp->bts_end;
|
||||||
mgcp_patch_and_count(endp, &endp->net_state,
|
rtp_state = &endp->net_state;
|
||||||
&endp->bts_end,
|
tap_idx = MGCP_TAP_BTS_OUT;
|
||||||
addr, buf, rc);
|
}
|
||||||
forward_data(endp->bts_end.rtp.fd,
|
|
||||||
&endp->taps[MGCP_TAP_BTS_OUT], buf, rc);
|
if (is_rtp) {
|
||||||
return mgcp_udp_send(endp->bts_end.rtp.fd,
|
mgcp_patch_and_count(endp, rtp_state, rtp_end, addr, buf, rc);
|
||||||
&endp->bts_end.addr,
|
forward_data(rtp_end->rtp.fd, &endp->taps[tap_idx], buf, rc);
|
||||||
endp->bts_end.rtp_port, buf, rc);
|
return mgcp_udp_send(rtp_end->rtp.fd,
|
||||||
} else if (!tcfg->omit_rtcp) {
|
&rtp_end->addr,
|
||||||
return mgcp_udp_send(endp->bts_end.rtcp.fd,
|
rtp_end->rtp_port, buf, rc);
|
||||||
&endp->bts_end.addr,
|
} else if (!tcfg->omit_rtcp) {
|
||||||
endp->bts_end.rtcp_port, buf, rc);
|
return mgcp_udp_send(rtp_end->rtcp.fd,
|
||||||
}
|
&rtp_end->addr,
|
||||||
|
rtp_end->rtcp_port, buf, rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user