aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libmgcp
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-08-14 15:43:06 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-08-14 15:43:06 +0200
commitaeadf261e54d4e3987797b5818a8356441512568 (patch)
treef7a50b71838b0f868e9d8d4ad6871c4f3d4d9029 /openbsc/src/libmgcp
parentca7d05bdb9e5be89442d6a2870e87919fdb11b98 (diff)
mgcp: Allow to enforce that the codecs need to match
We have a lot of legacy that I am afraid to break. We have everything in place to make a good codec selection (e.g. if we can avoid transcoding, pick the one with best quality or the lowest speed). Right now I have a specific case where from all options I want to pick GSM. Guard the codec compat check behind the disallow transcoding option to make sure to not break legacy application.
Diffstat (limited to 'openbsc/src/libmgcp')
-rw-r--r--openbsc/src/libmgcp/mgcp_protocol.c4
-rw-r--r--openbsc/src/libmgcp/mgcp_sdp.c25
2 files changed, 26 insertions, 3 deletions
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index 5f3eb3a6..40ea7916 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -828,7 +828,7 @@ mgcp_header_done:
endp->bts_end.fmtp_extra = talloc_strdup(tcfg->endpoints,
tcfg->audio_fmtp_extra);
if (have_sdp)
- mgcp_parse_sdp_data(&endp->net_end, p);
+ mgcp_parse_sdp_data(endp, &endp->net_end, p);
else if (endp->local_options.codec)
mgcp_set_audio_info(p->cfg, &endp->net_end.codec,
PTYPE_UNDEFINED, endp->local_options.codec);
@@ -931,7 +931,7 @@ static struct msgb *handle_modify_con(struct mgcp_parse_data *p)
case '\0':
/* SDP file begins */
have_sdp = 1;
- mgcp_parse_sdp_data(&endp->net_end, p);
+ mgcp_parse_sdp_data(endp, &endp->net_end, p);
/* This will exhaust p->save, so the loop will
* terminate next time.
*/
diff --git a/openbsc/src/libmgcp/mgcp_sdp.c b/openbsc/src/libmgcp/mgcp_sdp.c
index dc870893..33837b9a 100644
--- a/openbsc/src/libmgcp/mgcp_sdp.c
+++ b/openbsc/src/libmgcp/mgcp_sdp.c
@@ -154,8 +154,23 @@ void codecs_update(void *ctx, struct sdp_rtp_map *codecs, int used, int payload,
LOGP(DMGCP, LOGL_ERROR, "Unconfigured PT(%d) with %s\n", payload, audio_name);
}
+int is_codec_compatible(struct mgcp_endpoint *endp, struct sdp_rtp_map *codec)
+{
+ char *bts_codec;
+ char audio_codec[64];
+
+ /*
+ * GSM, GSM/8000 and GSM/8000/1 should all be compatible.. let's go
+ * by name first.
+ */
+ bts_codec = endp->tcfg->audio_name;
+ if (sscanf(bts_codec, "%63[^/]/%*d/%*d", audio_codec) < 1)
+ return 0;
+
+ return strcasecmp(audio_codec, codec->codec_name) == 0;
+}
-int mgcp_parse_sdp_data(struct mgcp_rtp_end *rtp, struct mgcp_parse_data *p)
+int mgcp_parse_sdp_data(struct mgcp_endpoint *endp, struct mgcp_rtp_end *rtp, struct mgcp_parse_data *p)
{
struct sdp_rtp_map codecs[10];
int codecs_used = 0;
@@ -243,6 +258,14 @@ int mgcp_parse_sdp_data(struct mgcp_rtp_end *rtp, struct mgcp_parse_data *p)
for (i = 0; i < codecs_used && codecs_assigned < 2; ++i) {
struct mgcp_rtp_codec *codec = codecs_assigned == 0 ?
&rtp->codec : &rtp->alt_codec;
+
+ if (endp->tcfg->no_audio_transcoding &&
+ !is_codec_compatible(endp, &codecs[i])) {
+ LOGP(DMGCP, LOGL_NOTICE, "Skipping codec %s\n",
+ codecs[i].codec_name);
+ continue;
+ }
+
mgcp_set_audio_info(p->cfg, codec,
codecs[i].payload_type,
codecs[i].map_line);