diff mbox

[03/11] mgcp: Add a function to get media info for MGCP responses

Message ID 1400142559-26788-3-git-send-email-jerlbeck@sysmocom.de
State Superseded
Headers show

Commit Message

Jacob Erlbeck May 15, 2014, 8:29 a.m. UTC
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
---
 openbsc/include/openbsc/mgcp.h          |    8 ++++++++
 openbsc/include/openbsc/mgcp_internal.h |    5 +++++
 openbsc/src/libmgcp/mgcp_network.c      |   13 +++++++++++++
 openbsc/src/libmgcp/mgcp_protocol.c     |   20 ++++++++++++++------
 4 files changed, 40 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h
index 6ba0769..b595aba 100644
--- a/openbsc/include/openbsc/mgcp.h
+++ b/openbsc/include/openbsc/mgcp.h
@@ -92,6 +92,12 @@  typedef int (*mgcp_processing)(struct mgcp_rtp_end *dst_end,
 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 @@  struct mgcp_config {
 	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 72ac8e9..e74b9fa 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -209,4 +209,9 @@  int mgcp_setup_rtp_processing_default(struct mgcp_endpoint *endp,
 				      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);
+
 #endif
diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c
index 4d1ad35..dcbb97a 100644
--- a/openbsc/src/libmgcp/mgcp_network.c
+++ b/openbsc/src/libmgcp/mgcp_network.c
@@ -361,6 +361,19 @@  int mgcp_setup_rtp_processing_default(struct mgcp_endpoint *endp,
 	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 3960c88..215c2ee 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -232,12 +232,15 @@  static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp,
 					     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;
 
@@ -1213,6 +1216,8 @@  struct mgcp_config *mgcp_config_alloc(void)
 	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;
@@ -1365,9 +1370,12 @@  static void send_msg(struct mgcp_endpoint *endp, int endpoint, int port,
 {
 	char buf[2096];
 	int len;
-	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;
+
+	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),