From 714cd0ab444bd51731131866463f5c565c8a33f6 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 22 Aug 2007 11:13:27 +0000 Subject: Use "unsigned int" instead of "unsigned long long" and reset the point of reference at proper intervals to avoid overflow --- audio/pcm_bluetooth.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c index 495f1521..77c8045e 100644 --- a/audio/pcm_bluetooth.c +++ b/audio/pcm_bluetooth.c @@ -25,6 +25,7 @@ #include #endif +#include #include #include #include @@ -43,6 +44,10 @@ //#define ENABLE_DEBUG +#define UINT_SECS_MAX (UINT_MAX / 1000000 - 1) + +#define MIN_PERIOD_TIME 1000 + #define BUFFER_SIZE 2048 #ifdef ENABLE_DEBUG @@ -136,8 +141,7 @@ static void *a2dp_playback_hw_thread(void *param) gettimeofday(&start, 0); while (1) { - unsigned long long dtime; - unsigned int periods; + unsigned int dtime, periods; struct timeval cur, delta; gettimeofday(&cur, 0); @@ -160,10 +164,16 @@ static void *a2dp_playback_hw_thread(void *param) if (write(data->a2dp.pipefd[1], &c, 1) < 0) pthread_testcancel(); - prev_periods = periods; + /* Reset point of reference to avoid too big values + * that wont fit an unsigned int */ + if (delta.tv_sec > UINT_SECS_MAX) { + prev_periods = 0; + gettimeofday(&start, 0); + } else + prev_periods = periods; } - usleep(period_time); + usleep(MIN_PERIOD_TIME); /* Offer opportunity to be canceled by main thread */ pthread_testcancel(); -- cgit