mgcp: Add a function to get media info for MGCP responses

This patch adds the get_net_downlink_format_cb() callback to provide
payload_type, subtype_name, and fmtp_extra suitable for use in a MGCP
response sent to the network. Per default, the BTS side values are
returned since these must be honoured by the net peer when sending
audio to the media gateway (unless transcoding is done).

Sponsored-by: On-Waves ehf
diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h
index 34eb429..002dd7c 100644
--- a/openbsc/include/openbsc/mgcp.h
+++ b/openbsc/include/openbsc/mgcp.h
@@ -92,6 +92,12 @@
 typedef int (*mgcp_processing_setup)(struct mgcp_endpoint *endp,
 				     struct mgcp_rtp_end *dst_end,
 				     struct mgcp_rtp_end *src_end);
+
+typedef void (*mgcp_get_format)(struct mgcp_endpoint *endp,
+				int *payload_type,
+				const char**subtype_name,
+				const char**fmtp_extra);
+
 #define PORT_ALLOC_STATIC	0
 #define PORT_ALLOC_DYNAMIC	1
 
@@ -166,6 +172,8 @@
 	mgcp_processing rtp_processing_cb;
 	mgcp_processing_setup setup_rtp_processing_cb;
 
+	mgcp_get_format get_net_downlink_format_cb;
+
 	struct osmo_wqueue gw_fd;
 
 	struct mgcp_port_range bts_ports;
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index dbdc1d9..ac136a3 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -217,6 +217,11 @@
 				      struct mgcp_rtp_end *dst_end,
 				      struct mgcp_rtp_end *src_end);
 
+void mgcp_get_net_downlink_format_default(struct mgcp_endpoint *endp,
+					  int *payload_type,
+					  const char**subtype_name,
+					  const char**fmtp_extra);
+
 enum {
 	MGCP_DEST_NET = 0,
 	MGCP_DEST_BTS,
diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c
index 393a9e5..05c3e77 100644
--- a/openbsc/src/libmgcp/mgcp_network.c
+++ b/openbsc/src/libmgcp/mgcp_network.c
@@ -353,6 +353,19 @@
 	return 0;
 }
 
+void mgcp_get_net_downlink_format_default(struct mgcp_endpoint *endp,
+					  int *payload_type,
+					  const char**audio_name,
+					  const char**fmtp_extra)
+{
+	/* Use the BTS side parameters when passing the SDP data (for
+	 * downlink) to the net peer.
+	 */
+	*payload_type = endp->bts_end.payload_type;
+	*audio_name = endp->bts_end.audio_name;
+	*fmtp_extra = endp->bts_end.fmtp_extra;
+}
+
 /**
  * The RFC 3550 Appendix A assumes there are multiple sources but
  * some of the supported endpoints (e.g. the nanoBTS) can only handle
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index 862bf17..7837378 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -245,12 +245,15 @@
 					     const char *msg, const char *trans_id)
 {
 	const char *addr = endp->cfg->local_ip;
-	const char *fmtp_extra = endp->bts_end.fmtp_extra;
-	const char *audio_name = endp->bts_end.audio_name;
-	int payload_type = endp->bts_end.payload_type;
+	const char *fmtp_extra;
+	const char *audio_name;
+	int payload_type;
 	char sdp_record[4096];
 	int len;
 
+	endp->cfg->get_net_downlink_format_cb(endp, &payload_type,
+					      &audio_name, &fmtp_extra);
+
 	if (!addr)
 		addr = endp->cfg->source_addr;
 
@@ -1268,6 +1271,8 @@
 	cfg->rtp_processing_cb = &mgcp_rtp_processing_default;
 	cfg->setup_rtp_processing_cb = &mgcp_setup_rtp_processing_default;
 
+	cfg->get_net_downlink_format_cb = &mgcp_get_net_downlink_format_default;
+
 	/* default trunk handling */
 	cfg->trunk.cfg = cfg;
 	cfg->trunk.trunk_nr = 0;
@@ -1424,8 +1429,12 @@
 {
 	char buf[2096];
 	int len;
-	const char *audio_name = endp->bts_end.audio_name;
-	int payload_type = endp->bts_end.payload_type;
+	const char *fmtp_extra;
+	const char *audio_name;
+	int payload_type;
+
+	endp->cfg->get_net_downlink_format_cb(endp, &payload_type,
+					      &audio_name, &fmtp_extra);
 
 	/* hardcoded to AMR right now, we do not know the real type at this point */
 	len = snprintf(buf, sizeof(buf),