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-14 12:03:42 +0000
commit002a51e2180cf19bf5e11e16d78271998d0b3f5c (patch)
tree45b36a59669f56dadca201c35075e93d283058ca /tests/amr/amr_test.c
parentb988f2bb36d77684baf780ece950a92b5b7e4bd6 (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: I9fc5fb92e9bada22a47a82fcfb0925e892e50ced
Diffstat (limited to 'tests/amr/amr_test.c')
-rw-r--r--tests/amr/amr_test.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/tests/amr/amr_test.c b/tests/amr/amr_test.c
index fff686c..af10289 100644
--- a/tests/amr/amr_test.c
+++ b/tests/amr/amr_test.c
@@ -44,6 +44,9 @@ char *oa_amr_samples[] = {
"100c4e9ba850e30d5d53d04de41e7c",
"100c6c18e7b7fff53aeb055e7d1c54",
"100c1fb967f7f1fdf547bf2e61c060",
+ "0004f89d67f1160935bde1996840",
+ "0004633cc7f0630439ffe0000000",
+ "0004eb81fc0758973b9edc782552",
"a038ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00fc", /* test pattern */
"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,16 +160,21 @@ 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);
+ ft = oa_hd->ft;
+ 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++;
}