summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2007-08-22 11:13:27 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2007-08-22 11:13:27 +0000
commit714cd0ab444bd51731131866463f5c565c8a33f6 (patch)
treef253eef15a99fca57faab685bd559321c10366f4 /audio
parentb22d297c0c679b400d7825367e31fed46c552a49 (diff)
Use "unsigned int" instead of "unsigned long long" and reset the point of reference at proper intervals to avoid overflow
Diffstat (limited to 'audio')
-rw-r--r--audio/pcm_bluetooth.c18
1 files 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 <config.h>
#endif
+#include <stdint.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/time.h>
@@ -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();