summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-25 18:31:06 +0200
committerwm4 <wm4@nowhere>2013-05-26 16:44:20 +0200
commite56d8a200d900066c3da571d92733f66ce6a13ab (patch)
treef43862ec12beee05380da82ebef23bcce83401e7 /audio
parent51254a678c386cf48f2caa51e06ad34065c8693a (diff)
downloadmpv-e56d8a200d900066c3da571d92733f66ce6a13ab.tar.bz2
mpv-e56d8a200d900066c3da571d92733f66ce6a13ab.tar.xz
Replace all calls to GetTimer()/GetTimerMS()
GetTimer() is generally replaced with mp_time_us(). Both calls return microseconds, but the latter uses int64_t, us defined to never wrap, and never returns 0 or negative values. GetTimerMS() has no direct replacement. Instead the other functions are used. For some code, switch to mp_time_sec(), which returns the time as double float value in seconds. The returned time is offset to program start time, so there is enough precision left to deliver microsecond resolution for at least 100 years. Unless it's casted to a float (or the CPU reduces precision), which is why we still use mp_time_us() out of paranoia in places where precision is clearly needed. Always switch to the correct time. The whole point of the new timer calls is that they don't wrap, and storing microseconds in unsigned int variables would negate this. In some cases, remove wrap-around handling for time values.
Diffstat (limited to 'audio')
-rw-r--r--audio/out/ao_jack.c4
-rw-r--r--audio/out/ao_null.c8
-rw-r--r--audio/out/ao_sdl.c20
3 files changed, 16 insertions, 16 deletions
diff --git a/audio/out/ao_jack.c b/audio/out/ao_jack.c
index 0f8baeab86..1807a11c44 100644
--- a/audio/out/ao_jack.c
+++ b/audio/out/ao_jack.c
@@ -170,7 +170,7 @@ static int outputaudio(jack_nframes_t nframes, void *arg) {
if (read_buffer(bufs, nframes, num_ports) < nframes)
underrun = 1;
if (estimate) {
- float now = (float)GetTimer() / 1000000.0;
+ float now = mp_time_us() / 1000000.0;
float diff = callback_time + callback_interval - now;
if ((diff > -0.002) && (diff < 0.002))
callback_time += callback_interval;
@@ -361,7 +361,7 @@ static float get_delay(void) {
int buffered = av_fifo_size(buffer); // could be less
float in_jack = jack_latency;
if (estimate && callback_interval > 0) {
- float elapsed = (float)GetTimer() / 1000000.0 - callback_time;
+ float elapsed = mp_time_us() / 1000000.0 - callback_time;
in_jack += callback_interval - elapsed;
if (in_jack < 0) in_jack = 0;
}
diff --git a/audio/out/ao_null.c b/audio/out/ao_null.c
index 53ec2a9a83..32d02bea31 100644
--- a/audio/out/ao_null.c
+++ b/audio/out/ao_null.c
@@ -29,7 +29,7 @@
#include "ao.h"
struct priv {
- unsigned last_time;
+ double last_time;
float buffered_bytes;
};
@@ -37,8 +37,8 @@ static void drain(struct ao *ao)
{
struct priv *priv = ao->priv;
- unsigned now = GetTimer();
- priv->buffered_bytes -= (now - priv->last_time) / 1e6 * ao->bps;
+ double now = mp_time_sec();
+ priv->buffered_bytes -= (now - priv->last_time) * ao->bps;
if (priv->buffered_bytes < 0)
priv->buffered_bytes = 0;
priv->last_time = now;
@@ -59,7 +59,7 @@ static int init(struct ao *ao, char *params)
// A "buffer" for about 0.2 seconds of audio
ao->buffersize = (int)(ao->samplerate * 0.2 / 256 + 1) * ao->outburst;
ao->bps = ao->channels.num * ao->samplerate * samplesize;
- priv->last_time = GetTimer();
+ priv->last_time = mp_time_sec();
return 0;
}
diff --git a/audio/out/ao_sdl.c b/audio/out/ao_sdl.c
index 6678cd3bd3..63b1f3963d 100644
--- a/audio/out/ao_sdl.c
+++ b/audio/out/ao_sdl.c
@@ -42,8 +42,8 @@ struct priv
bool unpause;
bool paused;
#ifdef ESTIMATE_DELAY
- unsigned int callback_time0;
- unsigned int callback_time1;
+ int64_t callback_time0;
+ int64_t callback_time1;
#endif
};
@@ -56,7 +56,7 @@ static void audio_callback(void *userdata, Uint8 *stream, int len)
#ifdef ESTIMATE_DELAY
priv->callback_time1 = priv->callback_time0;
- priv->callback_time0 = GetTimer();
+ priv->callback_time0 = mp_time_us();
#endif
while (len > 0 && !priv->paused) {
@@ -268,7 +268,7 @@ static int init(struct ao *ao, char *params)
priv->unpause = 1;
priv->paused = 1;
- priv->callback_time0 = priv->callback_time1 = GetTimer();
+ priv->callback_time0 = priv->callback_time1 = mp_time_us();
return 1;
}
@@ -340,8 +340,8 @@ static float get_delay(struct ao *ao)
SDL_LockMutex(priv->buffer_mutex);
int sz = av_fifo_size(priv->buffer);
#ifdef ESTIMATE_DELAY
- unsigned int callback_time0 = priv->callback_time0;
- unsigned int callback_time1 = priv->callback_time1;
+ int64_t callback_time0 = priv->callback_time0;
+ int64_t callback_time1 = priv->callback_time1;
#endif
SDL_UnlockMutex(priv->buffer_mutex);
@@ -351,16 +351,16 @@ static float get_delay(struct ao *ao)
#ifdef ESTIMATE_DELAY
// delay component: outstanding audio living in SDL
- unsigned int current_time = GetTimer();
+ int64_t current_time = mp_time_us();
// interval between callbacks
- unsigned int callback_interval = callback_time0 - callback_time1;
- unsigned int elapsed_interval = current_time - callback_time0;
+ int64_t callback_interval = callback_time0 - callback_time1;
+ int64_t elapsed_interval = current_time - callback_time0;
if (elapsed_interval > callback_interval)
elapsed_interval = callback_interval;
// delay subcomponent: remaining audio from the currently played buffer
- unsigned int buffer_interval = callback_interval - elapsed_interval;
+ int64_t buffer_interval = callback_interval - elapsed_interval;
// delay subcomponent: remaining audio from the next played buffer, as
// provided by the callback