summaryrefslogtreecommitdiffstats
path: root/tests/codec
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2016-05-25 18:13:51 +0200
committerHolger Freyther <holger@freyther.de>2016-05-31 10:11:51 +0000
commit92db150488bdadf6577a4968feabd5a3ab694c5e (patch)
treebbe91ee76c6dd6e41077ba22d29dc9c574b13516 /tests/codec
parentadef12a3497d14aafe677b77b468b952f4c6b5d5 (diff)
Add helper functions for AMR codec
* add functions to encode/decode various codec paramters from RTP payload with AMR frame according to RFC 4867 * those functions are extended version based on code from osmo-bts' amr.c by Andreas Eversberg * add corresponding enum types and strings for logging * add regression tests It's useful both to replace manual parsing in osmo-bts with fuctions covered by test suite and as a debugging helpers for issues related to AMR. Change-Id: Ia217679a07d3fbc970f435e20f6eac33d34bd597 Related: OS#1562 Reviewed-on: https://gerrit.osmocom.org/118 Tested-by: Jenkins Builder Reviewed-by: Holger Freyther <holger@freyther.de>
Diffstat (limited to 'tests/codec')
-rw-r--r--tests/codec/codec_test.c86
-rw-r--r--tests/codec/codec_test.ok9
2 files changed, 95 insertions, 0 deletions
diff --git a/tests/codec/codec_test.c b/tests/codec/codec_test.c
new file mode 100644
index 00000000..4905dd39
--- /dev/null
+++ b/tests/codec/codec_test.c
@@ -0,0 +1,86 @@
+/*
+ * (C) 2016 by Sysmocom s.f.m.c. GmbH
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <osmocom/core/utils.h>
+#include <osmocom/codec/codec.h>
+
+const uint8_t sid_update[] = {0x20, 0x44, 0x29, 0xc2, 0x92, 0x91, 0xf4};
+const uint8_t sid_first[] = {0x20, 0x44, 0x00, 0x00, 0x00, 0x00, 0x04};
+
+#define PAYLOAD_LEN 34
+#define SID_LEN 7
+
+static const char * cmpr(int a, int b)
+{
+ return (a == b) ? "OK" : "BAD";
+}
+
+static void test_sid_dec(const uint8_t *t, size_t len)
+{
+ uint8_t cmr, tmp[SID_LEN];
+ enum osmo_amr_type ft;
+ enum osmo_amr_quality bfi;
+ int8_t sti, cmi;
+ memcpy(tmp, t, SID_LEN);
+ int rc = osmo_amr_rtp_dec(tmp, len, &cmr, &cmi, &ft, &bfi, &sti);
+ printf("[%d] decode RTP %s%s: FT %s, CMR %s, CMI is %d, SID type %s\t",
+ rc, osmo_hexdump(tmp, len), cmpr(bfi, AMR_GOOD),
+ get_value_string(osmo_amr_type_names, ft),
+ get_value_string(osmo_amr_type_names, cmr),
+ cmi, sti ? "UPDATE" : "FIRST");
+ if (sti == -1)
+ printf("FAIL: incompatible STI for SID\n");
+ rc = osmo_amr_rtp_enc(tmp, cmr, ft, bfi);
+ printf("[%d] encode [%d]\n", rc, memcmp(tmp, t, SID_LEN));
+}
+
+static void test_amr_rt(uint8_t _cmr, enum osmo_amr_type _ft,
+ enum osmo_amr_quality _bfi)
+{
+ uint8_t cmr, payload[PAYLOAD_LEN];
+ enum osmo_amr_type ft;
+ enum osmo_amr_quality bfi;
+ int8_t sti, cmi;
+ int rc, re = osmo_amr_rtp_enc(payload, _cmr, _ft, _bfi);
+ rc = osmo_amr_rtp_dec(payload, PAYLOAD_LEN, &cmr, &cmi, &ft, &bfi, &sti);
+ printf("[%d/%d] %s, CMR: %s, FT: %s, BFI: %s, CMI: %d, STI: %d\n", re,
+ rc, get_value_string(osmo_amr_type_names, ft),
+ cmpr(_cmr, cmr), cmpr(_ft, ft), cmpr(_bfi, bfi), cmi, sti);
+}
+
+int main(int argc, char **argv)
+{
+ printf("AMR RTP payload decoder test:\n");
+ test_sid_dec(sid_first, 7);
+ test_sid_dec(sid_update, 7);
+ test_amr_rt(0, AMR_NO_DATA, AMR_BAD);
+ test_amr_rt(0, AMR_NO_DATA, AMR_GOOD);
+ test_amr_rt(AMR_12_2, AMR_12_2, AMR_BAD);
+ test_amr_rt(AMR_12_2, AMR_12_2, AMR_GOOD);
+ test_amr_rt(AMR_7_40, AMR_7_40, AMR_BAD);
+ test_amr_rt(AMR_7_40, AMR_7_40, AMR_GOOD);
+
+ return 0;
+}
+
+
diff --git a/tests/codec/codec_test.ok b/tests/codec/codec_test.ok
new file mode 100644
index 00000000..0f76fefc
--- /dev/null
+++ b/tests/codec/codec_test.ok
@@ -0,0 +1,9 @@
+AMR RTP payload decoder test:
+[2] decode RTP 20 44 00 00 00 00 04 OK: FT AMR SID, CMR AMR 5,90 kbit/s, CMI is 2, SID type FIRST [2] encode [0]
+[2] decode RTP 20 44 29 c2 92 91 f4 OK: FT AMR SID, CMR AMR 5,90 kbit/s, CMI is 2, SID type UPDATE [2] encode [0]
+[2/2] No Data/NA, CMR: OK, FT: OK, BFI: OK, CMI: -1, STI: -1
+[2/2] No Data/NA, CMR: OK, FT: OK, BFI: OK, CMI: -1, STI: -1
+[33/33] AMR 12,2 kbit/s (GSM-EFR), CMR: OK, FT: OK, BFI: OK, CMI: -1, STI: -1
+[33/33] AMR 12,2 kbit/s (GSM-EFR), CMR: OK, FT: OK, BFI: OK, CMI: -1, STI: -1
+[21/21] AMR 7,40 kbit/s (TDMA-EFR), CMR: OK, FT: OK, BFI: OK, CMI: -1, STI: -1
+[21/21] AMR 7,40 kbit/s (TDMA-EFR), CMR: OK, FT: OK, BFI: OK, CMI: -1, STI: -1