diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/dfsound/alsa.c | 21 | ||||
-rw-r--r-- | plugins/dfsound/nullsnd.c | 7 | ||||
-rw-r--r-- | plugins/dfsound/oss.c | 28 | ||||
-rw-r--r-- | plugins/dfsound/out.h | 1 | ||||
-rw-r--r-- | plugins/dfsound/pulseaudio.c | 33 | ||||
-rw-r--r-- | plugins/dfsound/sdl.c | 12 | ||||
-rw-r--r-- | plugins/gpulib/gpu.c | 4 |
7 files changed, 62 insertions, 44 deletions
diff --git a/plugins/dfsound/alsa.c b/plugins/dfsound/alsa.c index 6b9f83e..9873655 100644 --- a/plugins/dfsound/alsa.c +++ b/plugins/dfsound/alsa.c @@ -166,20 +166,22 @@ static void alsa_finish(void) } } -// GET BYTES BUFFERED -static int alsa_busy(void) -{ +static float alsa_capacity(void) { int l; - if (handle == NULL) // failed to open? - return 1; + if (handle == NULL) return 0; + if (buffer_size == 0) return 0; + l = snd_pcm_avail(handle); if (l < 0) return 0; - if (l < buffer_size / 2) // can we write in at least the half of fragments? - l = 1; // -> no? wait - else l = 0; // -> else go on - return l; + return (float)l / buffer_size; +} + +// GET BYTES BUFFERED +static int alsa_busy(void) +{ + return alsa_capacity() < 0.5; } // FEED SOUND DATA @@ -219,4 +221,5 @@ void out_register_alsa(struct out_driver *drv) drv->finish = alsa_finish; drv->busy = alsa_busy; drv->feed = alsa_feed; + drv->capacity = alsa_capacity; } diff --git a/plugins/dfsound/nullsnd.c b/plugins/dfsound/nullsnd.c index d8714df..ba6e51a 100644 --- a/plugins/dfsound/nullsnd.c +++ b/plugins/dfsound/nullsnd.c @@ -11,6 +11,12 @@ static void none_finish(void) { } +// GET BUFFER AVAILABLE +static float none_capacity(void) +{ + return 0.3; +} + // GET BYTES BUFFERED static int none_busy(void) { @@ -29,4 +35,5 @@ void out_register_none(struct out_driver *drv) drv->finish = none_finish; drv->busy = none_busy; drv->feed = none_feed; + drv->capacity = none_capacity; } diff --git a/plugins/dfsound/oss.c b/plugins/dfsound/oss.c index 6b1cb4a..67ba4c9 100644 --- a/plugins/dfsound/oss.c +++ b/plugins/dfsound/oss.c @@ -128,25 +128,26 @@ static void oss_finish(void) } //////////////////////////////////////////////////////////////////////// -// GET BUFFERED STATUS +// GET BUFFER AVAILABLE //////////////////////////////////////////////////////////////////////// -static int oss_busy(void) +static float oss_capacity(void) { audio_buf_info info; - unsigned long l; - if(oss_audio_fd == -1) return 1; - if(ioctl(oss_audio_fd,SNDCTL_DSP_GETOSPACE,&info)==-1) - l=0; - else - { - if(info.fragments<(info.fragstotal>>1)) // can we write in at least the half of fragments? - l=1; // -> no? wait - else l=0; // -> else go on - } + if(oss_audio_fd == -1) return 0; + if(ioctl(oss_audio_fd,SNDCTL_DSP_GETOSPACE,&info)==-1) return 0; + if(info.fragstotal == 0) return 0; + return (float)info.fragments / info.fragstotal; +} - return l; +//////////////////////////////////////////////////////////////////////// +// GET BUFFERED STATUS +//////////////////////////////////////////////////////////////////////// + +static int oss_busy(void) +{ + return oss_capacity() < 0.5; } //////////////////////////////////////////////////////////////////////// @@ -186,4 +187,5 @@ void out_register_oss(struct out_driver *drv) drv->finish = oss_finish; drv->busy = oss_busy; drv->feed = oss_feed; + drv->capacity = oss_capacity; } diff --git a/plugins/dfsound/out.h b/plugins/dfsound/out.h index e4878a8..2dcd226 100644 --- a/plugins/dfsound/out.h +++ b/plugins/dfsound/out.h @@ -7,6 +7,7 @@ struct out_driver { void (*finish)(void); int (*busy)(void); void (*feed)(void *data, int bytes); + float (*capacity)(void); }; extern struct out_driver *out_current; diff --git a/plugins/dfsound/pulseaudio.c b/plugins/dfsound/pulseaudio.c index 8ffd58f..0f4e32e 100644 --- a/plugins/dfsound/pulseaudio.c +++ b/plugins/dfsound/pulseaudio.c @@ -288,34 +288,32 @@ static void pulse_finish(void) } //////////////////////////////////////////////////////////////////////// -// GET BYTES BUFFERED +// GET BUFFER AVAILABLE //////////////////////////////////////////////////////////////////////// -static int pulse_busy(void) +static float pulse_capacity(void) { int free_space; if ((device.mainloop == NULL) || (device.api == NULL) || ( device.context == NULL) || (device.stream == NULL)) - return 1; + return 0; pa_threaded_mainloop_lock (device.mainloop); free_space = pa_stream_writable_size (device.stream); pa_threaded_mainloop_unlock (device.mainloop); + if (free_space == 0) return 0; - //fprintf (stderr, "Free space: %d\n", free_space); - //fprintf (stderr, "Used space: %d\n", maxlength - free_space); - if (free_space < mixlen * 3) - { - // Don't buffer anymore, just play - //fprintf (stderr, "Not buffering.\n"); - return 1; - } - else - { - // Buffer some sound - //fprintf (stderr, "Buffering.\n"); - return 0; - } + return (float)free_space / mixlen; +} + + +//////////////////////////////////////////////////////////////////////// +// GET BYTES BUFFERED +//////////////////////////////////////////////////////////////////////// + +static int pulse_busy(void) +{ + return pulse_capacity() < 0.33; } //////////////////////////////////////////////////////////////////////// @@ -346,4 +344,5 @@ void out_register_pulse(struct out_driver *drv) drv->finish = pulse_finish; drv->busy = pulse_busy; drv->feed = pulse_feed; + drv->capacity = pulse_capacity; } diff --git a/plugins/dfsound/sdl.c b/plugins/dfsound/sdl.c index ce92b6e..5a5ca51 100644 --- a/plugins/dfsound/sdl.c +++ b/plugins/dfsound/sdl.c @@ -103,17 +103,20 @@ static void sdl_finish(void) { pSndBuffer = NULL; } -static int sdl_busy(void) { +static float sdl_capacity(void) { int size; - if (pSndBuffer == NULL) return 1; + if (pSndBuffer == NULL) return 0; + if (iBufSize == 0) return 0; size = iReadPos - iWritePos; if (size <= 0) size += iBufSize; - if (size < iBufSize / 2) return 1; + return (float)size / iBufSize; +} - return 0; +static int sdl_busy(void) { + return sdl_capacity() < 0.5; } static void sdl_feed(void *pSound, int lBytes) { @@ -140,4 +143,5 @@ void out_register_sdl(struct out_driver *drv) drv->finish = sdl_finish; drv->busy = sdl_busy; drv->feed = sdl_feed; + drv->capacity = sdl_capacity; } diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index ed37b71..cffb97d 100644 --- a/plugins/gpulib/gpu.c +++ b/plugins/gpulib/gpu.c @@ -97,7 +97,9 @@ static noinline void decide_frameskip(void) gpu.frameskip.frame_ready = 1; } - if (!gpu.frameskip.active && *gpu.frameskip.advice) + if (gpu.frameskip.set < 0 && gpu.frameskip.cnt < 2 && *gpu.frameskip.advice) + gpu.frameskip.active = 1; + else if (!gpu.frameskip.active && *gpu.frameskip.advice) gpu.frameskip.active = 1; else if (gpu.frameskip.set > 0 && gpu.frameskip.cnt < gpu.frameskip.set) gpu.frameskip.active = 1; |