Revert "drop (now) unused code"

This reverts commit 2b30cbdfa83c20045ef92f53e88441dda185591b.

Reason for revert: Older versions of osmo-msc were actually calling map_codec_to_pt().

Change-Id: Ifff31012b327d40ed0b1559d5cf4f320784a4061
Related: https://jenkins.osmocom.org/jenkins/job/Osmocom-build-tags-against-master/1792/console
diff --git a/tests/mgcp_client/mgcp_client_test.c b/tests/mgcp_client/mgcp_client_test.c
index 95a742f..9b356c3 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -571,6 +571,57 @@
 	OSMO_ASSERT(map_str_to_codec("AMR-WB####################################################################################################################") == -1);
 }
 
+static void test_map_codec_to_pt_and_map_pt_to_codec(void)
+{
+	struct ptmap ptmap[10];
+	unsigned int ptmap_len;
+	unsigned int i;
+
+	ptmap[0].codec = CODEC_GSMEFR_8000_1;
+	ptmap[0].pt = 96;
+	ptmap[1].codec = CODEC_GSMHR_8000_1;
+	ptmap[1].pt = 97;
+	ptmap[2].codec = CODEC_AMR_8000_1;
+	ptmap[2].pt = 98;
+	ptmap[3].codec = CODEC_AMRWB_16000_1;
+	ptmap[3].pt = 99;
+	ptmap_len = 4;
+
+	/* Mappings that are covered by the table */
+	for (i = 0; i < ptmap_len; i++)
+		printf(" %u => %u\n", ptmap[i].codec, map_codec_to_pt(ptmap, ptmap_len, ptmap[i].codec));
+	for (i = 0; i < ptmap_len; i++)
+		printf(" %u <= %u\n", ptmap[i].pt, map_pt_to_codec(ptmap, ptmap_len, ptmap[i].pt));
+	printf("\n");
+
+	/* Map some codecs/payload types from the static range, result must
+	 * always be a 1:1 mapping */
+	printf(" %u => %u\n", CODEC_PCMU_8000_1, map_codec_to_pt(ptmap, ptmap_len, CODEC_PCMU_8000_1));
+	printf(" %u => %u\n", CODEC_GSM_8000_1, map_codec_to_pt(ptmap, ptmap_len, CODEC_GSM_8000_1));
+	printf(" %u => %u\n", CODEC_PCMA_8000_1, map_codec_to_pt(ptmap, ptmap_len, CODEC_PCMA_8000_1));
+	printf(" %u => %u\n", CODEC_G729_8000_1, map_codec_to_pt(ptmap, ptmap_len, CODEC_G729_8000_1));
+	printf(" %u <= %u\n", CODEC_PCMU_8000_1, map_pt_to_codec(ptmap, ptmap_len, CODEC_PCMU_8000_1));
+	printf(" %u <= %u\n", CODEC_GSM_8000_1, map_pt_to_codec(ptmap, ptmap_len, CODEC_GSM_8000_1));
+	printf(" %u <= %u\n", CODEC_PCMA_8000_1, map_pt_to_codec(ptmap, ptmap_len, CODEC_PCMA_8000_1));
+	printf(" %u <= %u\n", CODEC_G729_8000_1, map_pt_to_codec(ptmap, ptmap_len, CODEC_G729_8000_1));
+	printf("\n");
+
+	/* Try to do mappings from statically defined range to danymic range and vice versa. This
+	 * is illegal and should result into a 1:1 mapping */
+	ptmap[3].codec = CODEC_AMRWB_16000_1;
+	ptmap[3].pt = 2;
+	ptmap[4].codec = CODEC_PCMU_8000_1;
+	ptmap[4].pt = 100;
+	ptmap_len = 5;
+
+	/* Apply all mappings again, the illegal ones we defined should result into 1:1 mappings */
+	for (i = 0; i < ptmap_len; i++)
+		printf(" %u => %u\n", ptmap[i].codec, map_codec_to_pt(ptmap, ptmap_len, ptmap[i].codec));
+	for (i = 0; i < ptmap_len; i++)
+		printf(" %u <= %u\n", ptmap[i].pt, map_pt_to_codec(ptmap, ptmap_len, ptmap[i].pt));
+	printf("\n");
+}
+
 void test_mgcp_client_e1_epname(void)
 {
 	char *epname;
@@ -857,6 +908,7 @@
 	test_mgcp_msg();
 	test_mgcp_client_cancel();
 	test_sdp_section_start();
+	test_map_codec_to_pt_and_map_pt_to_codec();
 	test_map_str_to_codec();
 	test_mgcp_client_e1_epname();
 
diff --git a/tests/mgcp_client/mgcp_client_test.err b/tests/mgcp_client/mgcp_client_test.err
index 9e98792..94fe351 100644
--- a/tests/mgcp_client/mgcp_client_test.err
+++ b/tests/mgcp_client/mgcp_client_test.err
@@ -128,6 +128,10 @@
 body: "some mgcp header data\r\nand header params\r\n\r\nc=IN IP4 \r\n"
 DLMGCP Failed to parse MGCP response header (audio ip)
 got rc=-22
+DLMGCP ptmap contains illegal mapping: codec=113 maps to pt=2
+DLMGCP ptmap contains illegal mapping: codec=0 maps to pt=100
+DLMGCP ptmap contains illegal mapping: codec=113 maps to pt=2
+DLMGCP ptmap contains illegal mapping: codec=0 maps to pt=100
 DLMGCP MGW(mgw) MGCP client: using endpoint domain '@mgw'
 DLMGCP MGW(mgw) Cannot compose MGCP e1-endpoint name (ds/e1-15/s-1/su128-0@mgw), rate(128)/offset(0) combination is invalid!
 DLMGCP MGW(mgw) Cannot compose MGCP e1-endpoint name (ds/e1-15/s-1/su8-16@mgw), rate(8)/offset(16) combination is invalid!
diff --git a/tests/mgcp_client/mgcp_client_test.ok b/tests/mgcp_client/mgcp_client_test.ok
index b16d1bc..039fbd9 100644
--- a/tests/mgcp_client/mgcp_client_test.ok
+++ b/tests/mgcp_client/mgcp_client_test.ok
@@ -181,6 +181,35 @@
 test_sdp_section_start() test [17]:
 
 test_sdp_section_start() test [18]:
+ 110 => 96
+ 111 => 97
+ 112 => 98
+ 113 => 99
+ 96 <= 110
+ 97 <= 111
+ 98 <= 112
+ 99 <= 113
+
+ 0 => 0
+ 3 => 3
+ 8 => 8
+ 18 => 18
+ 0 <= 0
+ 3 <= 3
+ 8 <= 8
+ 18 <= 18
+
+ 110 => 96
+ 111 => 97
+ 112 => 98
+ 113 => 113
+ 0 => 0
+ 96 <= 110
+ 97 <= 111
+ 98 <= 112
+ 2 <= 2
+ 100 <= 100
+
 ds/e1-1/s-15/su64-0@mgw
 ds/e1-2/s-14/su32-0@mgw
 ds/e1-3/s-13/su32-4@mgw