mgcp: Make transcoding a per Endpoint configuration

This allows to switch off transcoding on the fly, or only enable
it for certain vessels with known problems.
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index 7c5badc..473ee31 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -99,6 +99,7 @@
 	struct mgcp_rtp_end bts_end;
 	struct mgcp_rtp_end net_end;
 	struct mgcp_rtp_end transcoder_end;
+	int is_transcoded;
 
 	/* sequence bits */
 	struct mgcp_rtp_state net_state;
diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c
index 28a27ca..6c6c336 100644
--- a/openbsc/src/mgcp/mgcp_network.c
+++ b/openbsc/src/mgcp/mgcp_network.c
@@ -383,7 +383,7 @@
 	endp->bts_end.packets += 1;
 
 	forward_data(fd->fd, &endp->taps[MGCP_TAP_BTS_IN], buf, rc);
-	if (cfg->transcoder_ip)
+	if (endp->is_transcoded)
 		return send_transcoder(endp, proto == PROTO_RTP, &buf[0], rc);
 	else
 		return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc);
diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c
index c73031c..4e7ebf8 100644
--- a/openbsc/src/mgcp/mgcp_protocol.c
+++ b/openbsc/src/mgcp/mgcp_protocol.c
@@ -421,12 +421,17 @@
 		return -1;
 	}
 
-	if (endp->cfg->transcoder_ip &&
-		allocate_port(endp, &endp->transcoder_end, &endp->cfg->transcoder_ports,
-			  mgcp_bind_transcoder_rtp_port) != 0) {
-		mgcp_rtp_end_reset(&endp->net_end);
-		mgcp_rtp_end_reset(&endp->bts_end);
-		return -1;
+	if (endp->cfg->transcoder_ip) {
+		if (allocate_port(endp, &endp->transcoder_end,
+				  &endp->cfg->transcoder_ports,
+				  mgcp_bind_transcoder_rtp_port) != 0) {
+			mgcp_rtp_end_reset(&endp->net_end);
+			mgcp_rtp_end_reset(&endp->bts_end);
+			return -1;
+		}
+
+		/* remember that we have set up transcoding */
+		endp->is_transcoded = 1;
 	}
 
 	return 0;
@@ -848,6 +853,7 @@
 	mgcp_rtp_end_reset(&endp->bts_end);
 	mgcp_rtp_end_reset(&endp->net_end);
 	mgcp_rtp_end_reset(&endp->transcoder_end);
+	endp->is_transcoded = 0;
 
 	memset(&endp->net_state, 0, sizeof(endp->net_state));
 	memset(&endp->bts_state, 0, sizeof(endp->bts_state));
@@ -927,7 +933,7 @@
 	int in_endp = ENDPOINT_NUMBER(endp);
 	int out_endp = back_channel(in_endp);
 
-	if (!endp->cfg->transcoder_ip)
+	if (!endp->is_transcoded)
 		return;
 
 	send_msg(endp, in_endp, endp->bts_end.local_port, "CRCX", "recvonly");
@@ -945,7 +951,7 @@
 	int in_endp = ENDPOINT_NUMBER(endp);
 	int out_endp = back_channel(in_endp);
 
-	if (!endp->cfg->transcoder_ip)
+	if (!endp->is_transcoded)
 		return;
 
 	send_dlcx(endp, in_endp);