blob: 4905dd398599704772b1b84055f8f65300b487df [file] [log] [blame]
Max92db1502016-05-25 18:13:51 +02001/*
2 * (C) 2016 by Sysmocom s.f.m.c. GmbH
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23
24#include <osmocom/core/utils.h>
25#include <osmocom/codec/codec.h>
26
27const uint8_t sid_update[] = {0x20, 0x44, 0x29, 0xc2, 0x92, 0x91, 0xf4};
28const uint8_t sid_first[] = {0x20, 0x44, 0x00, 0x00, 0x00, 0x00, 0x04};
29
30#define PAYLOAD_LEN 34
31#define SID_LEN 7
32
33static const char * cmpr(int a, int b)
34{
35 return (a == b) ? "OK" : "BAD";
36}
37
38static void test_sid_dec(const uint8_t *t, size_t len)
39{
40 uint8_t cmr, tmp[SID_LEN];
41 enum osmo_amr_type ft;
42 enum osmo_amr_quality bfi;
43 int8_t sti, cmi;
44 memcpy(tmp, t, SID_LEN);
45 int rc = osmo_amr_rtp_dec(tmp, len, &cmr, &cmi, &ft, &bfi, &sti);
46 printf("[%d] decode RTP %s%s: FT %s, CMR %s, CMI is %d, SID type %s\t",
47 rc, osmo_hexdump(tmp, len), cmpr(bfi, AMR_GOOD),
48 get_value_string(osmo_amr_type_names, ft),
49 get_value_string(osmo_amr_type_names, cmr),
50 cmi, sti ? "UPDATE" : "FIRST");
51 if (sti == -1)
52 printf("FAIL: incompatible STI for SID\n");
53 rc = osmo_amr_rtp_enc(tmp, cmr, ft, bfi);
54 printf("[%d] encode [%d]\n", rc, memcmp(tmp, t, SID_LEN));
55}
56
57static void test_amr_rt(uint8_t _cmr, enum osmo_amr_type _ft,
58 enum osmo_amr_quality _bfi)
59{
60 uint8_t cmr, payload[PAYLOAD_LEN];
61 enum osmo_amr_type ft;
62 enum osmo_amr_quality bfi;
63 int8_t sti, cmi;
64 int rc, re = osmo_amr_rtp_enc(payload, _cmr, _ft, _bfi);
65 rc = osmo_amr_rtp_dec(payload, PAYLOAD_LEN, &cmr, &cmi, &ft, &bfi, &sti);
66 printf("[%d/%d] %s, CMR: %s, FT: %s, BFI: %s, CMI: %d, STI: %d\n", re,
67 rc, get_value_string(osmo_amr_type_names, ft),
68 cmpr(_cmr, cmr), cmpr(_ft, ft), cmpr(_bfi, bfi), cmi, sti);
69}
70
71int main(int argc, char **argv)
72{
73 printf("AMR RTP payload decoder test:\n");
74 test_sid_dec(sid_first, 7);
75 test_sid_dec(sid_update, 7);
76 test_amr_rt(0, AMR_NO_DATA, AMR_BAD);
77 test_amr_rt(0, AMR_NO_DATA, AMR_GOOD);
78 test_amr_rt(AMR_12_2, AMR_12_2, AMR_BAD);
79 test_amr_rt(AMR_12_2, AMR_12_2, AMR_GOOD);
80 test_amr_rt(AMR_7_40, AMR_7_40, AMR_BAD);
81 test_amr_rt(AMR_7_40, AMR_7_40, AMR_GOOD);
82
83 return 0;
84}
85
86