aboutsummaryrefslogtreecommitdiffstats
path: root/tests/amr/amr_test.c
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2020-05-02 18:05:23 +0300
committerlaforge <laforge@osmocom.org>2020-05-16 20:21:48 +0000
commit4752930972ef727b2f1688fb84b158ed24e1ac09 (patch)
tree9aa5970681dbc44cb7a0089d84836bf77b773b81 /tests/amr/amr_test.c
parent0a918f028cc9af36dcf997827925355e2b0cad43 (diff)
amr: Fix OA<->BWE conversion.
Size of a single AMR frame doesn't always shrink by a byte when converted from octet-aligned to bandwidth-efficient mode. It does shrink for AMR modes 2, 3, 4, 6, and 7 but doesn't shrink for AMR modes 0, 1, 5, and SID frames because we only remove 6 bits. So old code generated truncated AMR packets for those AMR modes. This patch fixes the length calculation by properly counting bits. Proper bit counting is also bringing us one small step closer to properly handlig multi-frame AMR packets. Change-Id: I0462e054a0adc9080456f3eeea9cab7c229cdb70
Diffstat (limited to 'tests/amr/amr_test.c')
-rw-r--r--tests/amr/amr_test.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/tests/amr/amr_test.c b/tests/amr/amr_test.c
index fff686c..2f41fe9 100644
--- a/tests/amr/amr_test.c
+++ b/tests/amr/amr_test.c
@@ -44,7 +44,10 @@ char *oa_amr_samples[] = {
"100c4e9ba850e30d5d53d04de41e7c",
"100c6c18e7b7fff53aeb055e7d1c54",
"100c1fb967f7f1fdf547bf2e61c060",
- "a038ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00fc", /* test pattern */
+ "0004f89d67f1160935bde1996840",
+ "0004633cc7f0630439ffe0000000",
+ "0004eb81fc0758973b9edc782552",
+ "a078ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00fc", /* sample with invalid FT */
"END",
};
@@ -56,7 +59,7 @@ char *bwe_amr_samples[] = {
"f3d39a49a09e7a802852e297e8c9246aadf5a45928bfc27177fed8404d97d3b8",
"f3c2155b65131c68682079fab4810911200003b360ae0446000025f11e539dd0",
"f3c381bc7061c9f8507f6029de6115c16e5fa470c243b21b6e35dbb48bd84c00",
- "a7bfc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03f", /* test pattern */
+ "a7bfc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03f", /* sample with invalid FT */
"END",
};
@@ -87,7 +90,6 @@ void osmo_amr_oa_to_bwe_test(void)
return;
printf("\n");
printf("Sample No.: %i\n", i);
- len = strlen(oa_amr_samples[i]);
len = osmo_hexparse(oa_amr_samples[i], buf, sizeof(buf));
OSMO_ASSERT(len > 0);
@@ -102,11 +104,6 @@ void osmo_amr_oa_to_bwe_test(void)
dump_bits(buf, rc);
printf("\n");
printf(" rc: %i\n", rc);
-
- if (rc > 0) {
- OSMO_ASSERT(rc == len - 1);
- OSMO_ASSERT(buf[len - 1] == 0x00);
- }
i++;
}
}
@@ -126,7 +123,6 @@ void osmo_amr_bwe_to_oa_test(void)
return;
printf("\n");
printf("Sample No.: %i\n", i);
- len = strlen(bwe_amr_samples[i]);
len = osmo_hexparse(bwe_amr_samples[i], buf, sizeof(buf));
OSMO_ASSERT(len > 0);
@@ -142,7 +138,6 @@ void osmo_amr_bwe_to_oa_test(void)
printf("\n");
printf(" rc: %i\n", rc);
- OSMO_ASSERT(rc == len + 1);
i++;
}
}
@@ -151,6 +146,8 @@ void osmo_amr_oa_to_bwe_and_inverse_test(void)
{
uint8_t buf[256];
uint8_t buf_chk[256];
+ struct amr_hdr *oa_hd = (struct amr_hdr *)buf;
+ unsigned int ft;
unsigned int i = 0;
int len;
@@ -163,18 +160,28 @@ void osmo_amr_oa_to_bwe_and_inverse_test(void)
while (1) {
if (strcmp(oa_amr_samples[i], "END") == 0)
return;
- printf("Sample No.: %i...\n", i);
- len = strlen(oa_amr_samples[i]);
+ printf("Sample No.: %i...", i);
len = osmo_hexparse(oa_amr_samples[i], buf, sizeof(buf));
OSMO_ASSERT(len > 0);
+ i++;
+
+ ft = oa_hd->ft;
+ if (!osmo_amr_ft_valid(ft)) {
+ printf(" skipping a sample with a wrong FT\n");
+ continue;
+ }
+ OSMO_ASSERT(osmo_amr_bytes(ft) + 2 == len);
+ printf(" AMR mode: %d, OA: %d bytes,", ft, len);
memcpy(buf_chk, buf, sizeof(buf));
rc = osmo_amr_oa_to_bwe(buf, len);
OSMO_ASSERT(rc > 0);
+ printf(" BE: %d bytes,", rc);
rc = osmo_amr_bwe_to_oa(buf, rc, sizeof(buf));
+ printf(" OA: %d bytes\n", rc);
+ OSMO_ASSERT(len == rc);
OSMO_ASSERT(memcmp(buf, buf_chk, len) == 0);
- i++;
}
}