From 38cc8459237f04f2439d1231fc058199447dab0b Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 20 Feb 2024 09:25:00 -0500 Subject: [PATCH] MT#40962 replace usleep with waitForEventTimed Change-Id: I3dfdcd70d7f33f377bcdd76e72854525070c09ab --- core/AmMediaProcessor.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/AmMediaProcessor.cpp b/core/AmMediaProcessor.cpp index d36eeca3..e86b34a0 100644 --- a/core/AmMediaProcessor.cpp +++ b/core/AmMediaProcessor.cpp @@ -250,15 +250,21 @@ void AmMediaProcessorThread::run() uint64_t diff = next_tick - now; if(diff) - usleep(diff); + events.waitForEventTimed(diff / 1000); } - processAudio(ts); events.processEvents(); - processDtmfEvents(); - ts = (ts + WC_INC) & WALLCLOCK_MASK; - next_tick += tick; + // recheck time as we may have been woken up too soon + now = gettimeofday_us(); + + if (now >= next_tick) { + processAudio(ts); + processDtmfEvents(); + + ts = (ts + WC_INC) & WALLCLOCK_MASK; + next_tick += tick; + } } }