aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutputs/audioOutput_null.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/audioOutputs/audioOutput_null.c93
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,