libmgcp: add enum mgcp_type and use it
This patch replaces the field 'is_transcoded' in the mgcp_endpoint
structure by the enum mgcp_type, that can be further extended with
new types.
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index 455bb53..d5bd3dd 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -96,6 +96,11 @@
struct sockaddr_in forward;
};
+enum mgcp_type {
+ MGCP_RTP_DEFAULT = 0,
+ MGCP_RTP_TRANSCODED,
+};
+
struct mgcp_endpoint {
int allocated;
uint32_t ci;
@@ -119,7 +124,7 @@
*/
struct mgcp_rtp_end trans_bts;
struct mgcp_rtp_end trans_net;
- int is_transcoded;
+ enum mgcp_type type;
/* sequence bits */
struct mgcp_rtp_state net_state;
diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c
index a2cfc23..e9b58b2 100644
--- a/openbsc/src/libmgcp/mgcp_network.c
+++ b/openbsc/src/libmgcp/mgcp_network.c
@@ -371,10 +371,19 @@
endp->net_end.octets += rc;
forward_data(fd->fd, &endp->taps[MGCP_TAP_NET_IN], buf, rc);
- if (endp->is_transcoded)
- return send_transcoder(&endp->trans_net, endp->cfg, proto == PROTO_RTP, &buf[0], rc);
- else
- return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr, &buf[0], rc);
+
+ switch (endp->type) {
+ case MGCP_RTP_DEFAULT:
+ return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr,
+ buf, rc);
+ case MGCP_RTP_TRANSCODED:
+ return send_transcoder(&endp->trans_net, endp->cfg,
+ proto == PROTO_RTP, buf, rc);
+ }
+
+ LOGP(DMGCP, LOGL_ERROR, "Bad MGCP type %u on endpoint %u\n",
+ endp->type, ENDPOINT_NUMBER(endp));
+ return 0;
}
static void discover_bts(struct mgcp_endpoint *endp, int proto, struct sockaddr_in *addr)
@@ -450,10 +459,19 @@
endp->bts_end.octets += rc;
forward_data(fd->fd, &endp->taps[MGCP_TAP_BTS_IN], buf, rc);
- if (endp->is_transcoded)
- return send_transcoder(&endp->trans_bts, endp->cfg, proto == PROTO_RTP, &buf[0], rc);
- else
- return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc);
+
+ switch (endp->type) {
+ case MGCP_RTP_DEFAULT:
+ return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr,
+ buf, rc);
+ case MGCP_RTP_TRANSCODED:
+ return send_transcoder(&endp->trans_bts, endp->cfg,
+ proto == PROTO_RTP, buf, rc);
+ }
+
+ LOGP(DMGCP, LOGL_ERROR, "Bad MGCP type %u on endpoint %u\n",
+ endp->type, ENDPOINT_NUMBER(endp));
+ return 0;
}
static int rtp_data_transcoder(struct mgcp_rtp_end *end, struct mgcp_endpoint *_endp,
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index 8f6861d..616e0a9 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -500,7 +500,7 @@
}
/* remember that we have set up transcoding */
- endp->is_transcoded = 1;
+ endp->type = MGCP_RTP_TRANSCODED;
}
return 0;
@@ -1014,7 +1014,7 @@
mgcp_rtp_end_reset(&endp->net_end);
mgcp_rtp_end_reset(&endp->trans_net);
mgcp_rtp_end_reset(&endp->trans_bts);
- endp->is_transcoded = 0;
+ endp->type = MGCP_RTP_DEFAULT;
memset(&endp->net_state, 0, sizeof(endp->net_state));
memset(&endp->bts_state, 0, sizeof(endp->bts_state));
@@ -1118,7 +1118,7 @@
int in_endp = ENDPOINT_NUMBER(endp);
int out_endp = endp_back_channel(in_endp);
- if (!endp->is_transcoded)
+ if (endp->type != MGCP_RTP_TRANSCODED)
return;
send_msg(endp, in_endp, endp->trans_bts.local_port, "CRCX", "sendrecv");
@@ -1140,7 +1140,7 @@
int in_endp = ENDPOINT_NUMBER(endp);
int out_endp = endp_back_channel(in_endp);
- if (!endp->is_transcoded)
+ if (endp->type != MGCP_RTP_TRANSCODED)
return;
send_dlcx(endp, in_endp);