in ran_msg, return gsm0808_speech_codec (inter-MSC)

Get rid of enum mgcp_codecs in inter-MSC handover related code.

Change-Id: I9c649f98738a55b8637ae600d5cdf81099fd08e5
diff --git a/src/libmsc/msc_ho.c b/src/libmsc/msc_ho.c
index d53bb9e..e11abcf 100644
--- a/src/libmsc/msc_ho.c
+++ b/src/libmsc/msc_ho.c
@@ -681,7 +681,7 @@
 	msc_a->ho.new_cell.codec = hra->ran_dec->handover_request_ack.codec;
 	if (hra->ran_dec->handover_request_ack.codec_present) {
 		LOG_HO(msc_a, LOGL_DEBUG, "Request Ack contains codec %s\n",
-		       osmo_mgcpc_codec_name(msc_a->ho.new_cell.codec));
+		       gsm0808_speech_codec_type_name(msc_a->ho.new_cell.codec.type));
 	}
 }
 
@@ -728,13 +728,14 @@
 	/* Switch over to the new peer */
 	rtp_stream_set_remote_addr(rtp_to_ran, &msc_a->ho.new_cell.ran_remote_rtp);
 	if (msc_a->ho.new_cell.codec_present) {
-		struct sdp_audio_codecs codecs = {};
-		if (!sdp_audio_codecs_add_mgcp_codec(&codecs, msc_a->ho.new_cell.codec)) {
-			LOG_HO(msc_a, LOGL_ERROR,
-			       "Cannot resolve codec: %s\n", osmo_mgcpc_codec_name(msc_a->ho.new_cell.codec));
-		} else {
-			rtp_stream_set_codecs(rtp_to_ran, &codecs);
-		}
+		const struct codec_mapping *m;
+		m = codec_mapping_by_gsm0808_speech_codec_type(msc_a->ho.new_cell.codec.type);
+		/* TODO: use codec_mapping_by_gsm0808_speech_codec() to also match on codec.cfg */
+		if (!m)
+			LOG_HO(msc_a, LOGL_ERROR, "Cannot resolve codec: %s\n",
+			       gsm0808_speech_codec_type_name(msc_a->ho.new_cell.codec.type));
+		else
+			rtp_stream_set_one_codec(rtp_to_ran, &m->sdp);
 	} else {
 		LOG_HO(msc_a, LOGL_ERROR, "No codec is set\n");
 	}
diff --git a/src/libmsc/msc_t.c b/src/libmsc/msc_t.c
index 787d736..7f316a7 100644
--- a/src/libmsc/msc_t.c
+++ b/src/libmsc/msc_t.c
@@ -38,6 +38,7 @@
 #include <osmocom/msc/vlr.h>
 #include <osmocom/msc/msc_i.h>
 #include <osmocom/msc/gsm_data.h>
+#include <osmocom/msc/codec_mapping.h>
 
 static struct osmo_fsm msc_t_fsm;
 
@@ -448,11 +449,20 @@
 			LOG_MSC_T(msc_t, LOGL_DEBUG, "No RTP IP:port in Handover Request Ack\n");
 		}
 		if (r->codec_present) {
-			LOG_MSC_T(msc_t, LOGL_DEBUG, "From Handover Request Ack, got %s\n",
-				  osmo_mgcpc_codec_name(r->codec));
-			rtp_stream_set_codecs_from_mgcp_codec(rtp_ran, r->codec);
-			if (rtp_cn)
-				rtp_stream_set_codecs_from_mgcp_codec(rtp_cn, r->codec);
+			const struct codec_mapping *m = codec_mapping_by_gsm0808_speech_codec_type(r->codec.type);
+			/* TODO: use codec_mapping_by_gsm0808_speech_codec() to also match on codec.cfg */
+			if (!m) {
+				LOG_MSC_T(msc_t, LOGL_ERROR, "Cannot resolve codec in Handover Request Ack: %s / %s\n",
+					  gsm0808_speech_codec_type_name(r->codec.type),
+					  m ? sdp_audio_codec_to_str(&m->sdp) : "(unknown)");
+			} else {
+				LOG_MSC_T(msc_t, LOGL_DEBUG, "From Handover Request Ack, got codec %s / %s\n",
+					  gsm0808_speech_codec_type_name(r->codec.type),
+					  sdp_audio_codec_to_str(&m->sdp));
+				rtp_stream_set_one_codec(rtp_ran, &m->sdp);
+				if (rtp_cn)
+					rtp_stream_set_one_codec(rtp_cn, &m->sdp);
+			}
 		} else {
 			LOG_MSC_T(msc_t, LOGL_DEBUG, "No codec in Handover Request Ack\n");
 		}
diff --git a/src/libmsc/ran_msg_a.c b/src/libmsc/ran_msg_a.c
index 56252f1..19402bc 100644
--- a/src/libmsc/ran_msg_a.c
+++ b/src/libmsc/ran_msg_a.c
@@ -671,13 +671,12 @@
 	}
 
 	if (ie_chosen_speech_version) {
-		struct gsm0808_speech_codec sc;
 		ran_dec_msg.handover_request_ack.chosen_speech_version = ie_chosen_speech_version->val[0];
 
 		/* the codec may be extrapolated from this Speech Version or below from Speech Codec */
-		gsm0808_speech_codec_from_chan_type(&sc, ran_dec_msg.handover_request_ack.chosen_speech_version);
-		ran_dec_msg.handover_request_ack.codec_present = true;
-		ran_dec_msg.handover_request_ack.codec = ran_a_mgcp_codec_from_sc(&sc);
+		if (gsm0808_speech_codec_from_chan_type(&ran_dec_msg.handover_request_ack.codec,
+							ran_dec_msg.handover_request_ack.chosen_speech_version) == 0)
+			ran_dec_msg.handover_request_ack.codec_present = true;
 	}
 
 	if (ie_aoip_transp_addr) {
@@ -692,14 +691,12 @@
 	}
 
 	if (ie_speech_codec) {
-		struct gsm0808_speech_codec sc;
-		if (gsm0808_dec_speech_codec(&sc, ie_speech_codec->val, ie_speech_codec->len) < 0)
+		/* the codec may be extrapolated from above Speech Version or from this Speech Codec */
+		if (gsm0808_dec_speech_codec(&ran_dec_msg.handover_request_ack.codec,
+					     ie_speech_codec->val, ie_speech_codec->len) < 0)
 			LOG_RAN_A_DEC_MSG(LOGL_ERROR, "unable to decode IE Speech Codec (Chosen)\n");
-		else {
-			/* the codec may be extrapolated from above Speech Version or from this Speech Codec */
+		else
 			ran_dec_msg.handover_request_ack.codec_present = true;
-			ran_dec_msg.handover_request_ack.codec = ran_a_mgcp_codec_from_sc(&sc);
-		}
 	}
 
 	return ran_decoded(ran_dec, &ran_dec_msg);