MT#40962 change media timer math to ints

Makes the math easier with enough room in a 64-bit int for millennia.

Change-Id: Ie42705d24663de7d67637158192c90ddb3160da0
mr12.3.1
Richard Fuchs 3 years ago
parent 8d3912b3ec
commit 2b53f6c9ac

@ -230,31 +230,27 @@ void AmMediaProcessorThread::on_stop()
void AmMediaProcessorThread::run()
{
stop_requested = false;
struct timeval now,next_tick,diff,tick;
// wallclock time
unsigned long long ts = 0;//4294417296;
tick.tv_sec = 0;
tick.tv_usec = 1000*WC_INC_MS;
// everything else in microseconds
uint64_t tick = 1000*WC_INC_MS;
gettimeofday(&now,NULL);
timeradd(&tick,&now,&next_tick);
uint64_t now = gettimeofday_us();
uint64_t next_tick = now + tick;
while(!stop_requested.get()){
gettimeofday(&now,NULL);
if(timercmp(&now,&next_tick,<)){
now = gettimeofday_us();
struct timespec sdiff,rem;
timersub(&next_tick,&now,&diff);
if(now < next_tick){
sdiff.tv_sec = diff.tv_sec;
sdiff.tv_nsec = diff.tv_usec * 1000;
uint64_t diff = next_tick - now;
if(sdiff.tv_nsec > 2000000) // 2 ms
nanosleep(&sdiff,&rem);
if(diff > 2000) // 2 ms
usleep(diff);
}
processAudio(ts);
@ -262,7 +258,7 @@ void AmMediaProcessorThread::run()
processDtmfEvents();
ts = (ts + WC_INC) & WALLCLOCK_MASK;
timeradd(&tick,&next_tick,&next_tick);
next_tick += tick;
}
}

@ -34,6 +34,8 @@
#include <sys/types.h>
#include <regex.h>
#include <sys/socket.h>
#include <stdint.h>
#include <sys/time.h>
#include <string>
using std::string;
@ -290,6 +292,13 @@ void cvt_hex(HASH bin, HASHHEX hex);
/** get an MD5 hash of a string */
string calculateMD5(const string& input);
/** return current time (unixtime / wall clock) as scalar microseconds */
inline uint64_t gettimeofday_us() {
struct timeval now_tv;
gettimeofday(&now_tv,NULL);
return now_tv.tv_sec * 1000000LL + now_tv.tv_usec;
}
#endif
// Local Variables:

Loading…
Cancel
Save