From 0c88e6007fe9b2eae5c28a6fb3dca6d9a8a2a9fb Mon Sep 17 00:00:00 2001 From: Tom Briden Date: Wed, 6 Mar 2024 11:43:29 +0000 Subject: [PATCH] MT#55283 dtmf_event_payload: canonicalise DTMF end event ts if start packet send was delayed in some scenarios the start event ts can be before the *pts value, which will result in a shortened DTMF event being transmitted than expected during injection as the end event ts is calculated based on that initial dtmf start value. This change updates the end event ts by the amount the start ts was behind, so that the resulting event has the right duration Change-Id: Ia637d1e1c5d92de8b35317ec552c22eae23c0645 (cherry picked from commit c7fa81c764d4bd74dfd930e9fc6768ebd8936724) --- daemon/dtmf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/daemon/dtmf.c b/daemon/dtmf.c index 85674230b..1bb9c4d42 100644 --- a/daemon/dtmf.c +++ b/daemon/dtmf.c @@ -436,8 +436,8 @@ void dtmf_event_free(void *e) { int dtmf_event_payload(str *buf, uint64_t *pts, uint64_t duration, struct dtmf_event *cur_event, GQueue *events) { // do we have a relevant state change? struct dtmf_event prev_event = *cur_event; + struct dtmf_event *ev = g_queue_peek_head(events); while (events->length) { - struct dtmf_event *ev = g_queue_peek_head(events); ilog(LOG_DEBUG, "Next DTMF event starts at %" PRIu64 ". PTS now %" PRIu64, ev->ts, *pts); if (ev->ts > *pts) break; // future event @@ -447,6 +447,14 @@ int dtmf_event_payload(str *buf, uint64_t *pts, uint64_t duration, struct dtmf_e g_queue_pop_head(events); *cur_event = *ev; dtmf_event_free(ev); + ev = g_queue_peek_head(events); + if (ev && ev->code == 0 && cur_event->ts < *pts) { + // if the start event ts was before *pts we need + // to adjust the end event_ts to ensure we're not shortening + // the event + ilog(LOG_DEBUG, "Delayed send of DTMF, adjusting end event_ts by %lu - %lu = %lu", *pts, cur_event->ts, *pts - cur_event->ts); + ev->ts += *pts - cur_event->ts; + } cur_event->ts = *pts; // canonicalise start TS }