diff options
author | J. Alexander Treuman <jat@spatialrift.net> | 2007-05-30 18:16:35 +0000 |
---|---|---|
committer | J. Alexander Treuman <jat@spatialrift.net> | 2007-05-30 18:16:35 +0000 |
commit | 693dc378518552cf84fad13b822efb76fd42c943 (patch) | |
tree | 091f0908a989c1efd99a08b951ac2166349ce15e /src/audioOutputs/audioOutput_null.c | |
parent | 41d65da4bd4c542370ed794db8a43bf1d866c385 (diff) | |
download | mpd-693dc378518552cf84fad13b822efb76fd42c943.tar.gz mpd-693dc378518552cf84fad13b822efb76fd42c943.tar.xz mpd-693dc378518552cf84fad13b822efb76fd42c943.zip |
Move the timing code from the null plugin to timer.c, so it can be easily
used in other plugins (fifo, shout, etc.).
git-svn-id: https://svn.musicpd.org/mpd/trunk@6397 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/audioOutputs/audioOutput_null.c | 93 |
1 files changed, 19 insertions, 74 deletions
diff --git a/src/audioOutputs/audioOutput_null.c b/src/audioOutputs/audioOutput_null.c index df58c7139..7dc3f1756 100644 --- a/src/audioOutputs/audioOutput_null.c +++ b/src/audioOutputs/audioOutput_null.c @@ -17,110 +17,55 @@ */ #include "../audioOutput.h" - -#include <stdlib.h> -#include <limits.h> -#include <sys/time.h> - -typedef struct _NullData { - uint64_t nextPlay; - int rate; -} NullData; - -static NullData *newNullData(void) -{ - NullData *ret; - - ret = xmalloc(sizeof(NullData)); - ret->nextPlay = 0; - ret->rate = 0; - - return ret; -} - -static void freeNullData(NullData *nd) -{ - free(nd); -} - -static uint64_t null_getTime(void) -{ - struct timeval tv; - - gettimeofday(&tv, NULL); - - return ((uint64_t)tv.tv_sec * 1000000) + tv.tv_usec; -} +#include "../timer.h" static int null_initDriver(AudioOutput *audioOutput, ConfigParam *param) { - NullData *nd; - - nd = newNullData(); - audioOutput->data = nd; - + audioOutput->data = NULL; return 0; } -static void null_finishDriver(AudioOutput *audioOutput) -{ - freeNullData((NullData *)audioOutput->data); -} - static int null_openDevice(AudioOutput *audioOutput) { - NullData *nd; - AudioFormat *af; - - nd = audioOutput->data; - af = &audioOutput->outAudioFormat; - nd->rate = af->sampleRate * (af->bits / CHAR_BIT) * af->channels; + audioOutput->data = timer_new(&audioOutput->outAudioFormat); audioOutput->open = 1; - return 0; } -static void null_dropBufferedAudio(AudioOutput *audioOutput) -{ - NullData *nd; - - nd = audioOutput->data; - nd->nextPlay = 0; -} - static void null_closeDevice(AudioOutput *audioOutput) { - NullData *nd; + if (audioOutput->data) { + timer_free(audioOutput->data); + audioOutput->data = NULL; + } - nd = audioOutput->data; - nd->nextPlay = 0; - nd->rate = 0; audioOutput->open = 0; } static int null_playAudio(AudioOutput *audioOutput, char *playChunk, int size) { - NullData *nd; - uint64_t now; + Timer *timer = audioOutput->data; - nd = audioOutput->data; - now = null_getTime(); + if (!timer->started) + timer_start(timer); + else + timer_sync(timer); - if (nd->nextPlay == 0) - nd->nextPlay = now; - else if (nd->nextPlay > now) - my_usleep(nd->nextPlay - now); - - nd->nextPlay += ((uint64_t)size * 1000000) / nd->rate; + timer_add(timer, size); return 0; } +static void null_dropBufferedAudio(AudioOutput *audioOutput) +{ + timer_reset(audioOutput->data); +} + AudioOutputPlugin nullPlugin = { "null", NULL, null_initDriver, - null_finishDriver, + NULL, null_openDevice, null_playAudio, null_dropBufferedAudio, |