From 693dc378518552cf84fad13b822efb76fd42c943 Mon Sep 17 00:00:00 2001 From: "J. Alexander Treuman" Date: Wed, 30 May 2007 18:16:35 +0000 Subject: 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 --- src/audioOutputs/audioOutput_null.c | 93 ++++++++----------------------------- 1 file changed, 19 insertions(+), 74 deletions(-) (limited to 'src/audioOutputs/audioOutput_null.c') 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 -#include -#include - -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, -- cgit v1.2.3