aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openbsc/src/libmgcp/mgcp_transcode.c1
-rw-r--r--openbsc/tests/mgcp/mgcp_transcoding_test.c47
2 files changed, 48 insertions, 0 deletions
diff --git a/openbsc/src/libmgcp/mgcp_transcode.c b/openbsc/src/libmgcp/mgcp_transcode.c
index 8e14d7f13..4d4cec8a2 100644
--- a/openbsc/src/libmgcp/mgcp_transcode.c
+++ b/openbsc/src/libmgcp/mgcp_transcode.c
@@ -450,6 +450,7 @@ int mgcp_transcoding_process_rtp(struct mgcp_endpoint *endp,
"0x%x dropping sample buffer due delta=%d sample_cnt=%d\n",
ENDPOINT_NUMBER(endp), delta, state->sample_cnt);
state->sample_cnt = 0;
+ state->next_time = ts_no;
} else if (delta < 0) {
LOGP(DMGCP, LOGL_NOTICE,
"RTP time jumps backwards, delta = %d, "
diff --git a/openbsc/tests/mgcp/mgcp_transcoding_test.c b/openbsc/tests/mgcp/mgcp_transcoding_test.c
index e163f7162..2e857a13f 100644
--- a/openbsc/tests/mgcp/mgcp_transcoding_test.c
+++ b/openbsc/tests/mgcp/mgcp_transcoding_test.c
@@ -384,6 +384,53 @@ static void test_transcode_result(void)
talloc_free(ctx);
}
+
+ {
+ /* from PCMA to GSM with a big time jump */
+ struct rtp_hdr *hdr;
+ uint32_t ts;
+
+ given_configured_endpoint(80, 160, "pcma", "gsm", &ctx, &endp);
+ state = endp->bts_end.rtp_process_data;
+
+ /* Add the first sample */
+ len = audio_packets_pcma[1].len;
+ memcpy(buf, audio_packets_pcma[1].data, len);
+ res = mgcp_transcoding_process_rtp(endp, &endp->bts_end, buf, &len, ARRAY_SIZE(buf));
+ OSMO_ASSERT(state->sample_cnt == 80);
+ OSMO_ASSERT(state->next_time == 232640);
+ OSMO_ASSERT(state->next_seq == 26527);
+ OSMO_ASSERT(res < 0);
+
+ /* Add a skip to the packet to force a 'resync' */
+ len = audio_packets_pcma[2].len;
+ memcpy(buf, audio_packets_pcma[2].data, len);
+ hdr = (struct rtp_hdr *) &buf[0];
+ /* jump the time and add alignment error */
+ ts = ntohl(hdr->timestamp) + 123 * 80 + 2;
+ hdr->timestamp = htonl(ts);
+ res = mgcp_transcoding_process_rtp(endp, &endp->bts_end, buf, &len, ARRAY_SIZE(buf));
+ OSMO_ASSERT(res < 0);
+ OSMO_ASSERT(state->sample_cnt == 80);
+ OSMO_ASSERT(state->next_time == ts);
+ OSMO_ASSERT(state->next_seq == 26527);
+ /* TODO: this can create alignment errors */
+
+
+ /* Now attempt to consume 160 samples */
+ len = audio_packets_pcma[2].len;
+ memcpy(buf, audio_packets_pcma[2].data, len);
+ hdr = (struct rtp_hdr *) &buf[0];
+ ts += 80;
+ hdr->timestamp = htonl(ts);
+ res = mgcp_transcoding_process_rtp(endp, &endp->bts_end, buf, &len, ARRAY_SIZE(buf));
+ OSMO_ASSERT(res == 12);
+ OSMO_ASSERT(state->sample_cnt == 0);
+ OSMO_ASSERT(state->next_time == ts + 160);
+ OSMO_ASSERT(state->next_seq == 26528);
+
+ talloc_free(ctx);
+ }
}
static int test_repacking(int in_samples, int out_samples, int no_transcode)