2007-05-30 18:52:56 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2008-09-07 22:41:17 +02:00
|
|
|
#include "../output_api.h"
|
2007-05-30 20:16:35 +02:00
|
|
|
#include "../timer.h"
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2009-01-01 18:00:46 +01:00
|
|
|
#include <glib.h>
|
|
|
|
|
2009-01-22 16:06:45 +01:00
|
|
|
#include <assert.h>
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
struct null_data {
|
2009-01-22 16:06:47 +01:00
|
|
|
bool sync;
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
Timer *timer;
|
|
|
|
};
|
|
|
|
|
2009-01-01 18:00:46 +01:00
|
|
|
static void *
|
2009-02-25 18:34:02 +01:00
|
|
|
null_init(G_GNUC_UNUSED const struct audio_format *audio_format,
|
2009-02-26 22:04:59 +01:00
|
|
|
G_GNUC_UNUSED const struct config_param *param,
|
|
|
|
G_GNUC_UNUSED GError **error)
|
2007-05-30 18:52:56 +02:00
|
|
|
{
|
2009-01-03 14:51:34 +01:00
|
|
|
struct null_data *nd = g_new(struct null_data, 1);
|
2009-01-22 16:06:43 +01:00
|
|
|
|
2009-01-22 16:06:47 +01:00
|
|
|
nd->sync = config_get_block_bool(param, "sync", true);
|
2008-09-24 07:20:55 +02:00
|
|
|
nd->timer = NULL;
|
2009-01-22 16:06:43 +01:00
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
return nd;
|
2007-05-30 18:52:56 +02:00
|
|
|
}
|
|
|
|
|
2009-01-22 16:06:45 +01:00
|
|
|
static void
|
|
|
|
null_finish(void *data)
|
|
|
|
{
|
|
|
|
struct null_data *nd = data;
|
|
|
|
|
|
|
|
assert(nd->timer == NULL);
|
|
|
|
|
|
|
|
g_free(nd);
|
|
|
|
}
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
static bool
|
2009-02-26 22:04:59 +01:00
|
|
|
null_open(void *data, struct audio_format *audio_format,
|
|
|
|
G_GNUC_UNUSED GError **error)
|
2007-05-30 18:52:56 +02:00
|
|
|
{
|
2008-09-24 07:20:55 +02:00
|
|
|
struct null_data *nd = data;
|
|
|
|
|
2009-01-22 16:06:47 +01:00
|
|
|
if (nd->sync)
|
|
|
|
nd->timer = timer_new(audio_format);
|
2009-01-22 16:06:43 +01:00
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
return true;
|
2007-05-30 18:52:56 +02:00
|
|
|
}
|
|
|
|
|
2009-01-22 16:06:43 +01:00
|
|
|
static void
|
|
|
|
null_close(void *data)
|
2007-05-30 18:52:56 +02:00
|
|
|
{
|
2008-09-24 07:20:55 +02:00
|
|
|
struct null_data *nd = data;
|
|
|
|
|
|
|
|
if (nd->timer != NULL) {
|
|
|
|
timer_free(nd->timer);
|
|
|
|
nd->timer = NULL;
|
2007-05-30 20:16:35 +02:00
|
|
|
}
|
2007-05-30 18:52:56 +02:00
|
|
|
}
|
|
|
|
|
2009-02-23 09:29:56 +01:00
|
|
|
static size_t
|
2009-02-26 22:04:59 +01:00
|
|
|
null_play(void *data, G_GNUC_UNUSED const void *chunk, size_t size,
|
|
|
|
G_GNUC_UNUSED GError **error)
|
2007-05-30 18:52:56 +02:00
|
|
|
{
|
2008-09-24 07:20:55 +02:00
|
|
|
struct null_data *nd = data;
|
|
|
|
Timer *timer = nd->timer;
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2009-01-22 16:06:47 +01:00
|
|
|
if (!nd->sync)
|
2009-02-23 09:29:56 +01:00
|
|
|
return size;
|
2009-01-22 16:06:47 +01:00
|
|
|
|
2007-05-30 20:16:35 +02:00
|
|
|
if (!timer->started)
|
|
|
|
timer_start(timer);
|
|
|
|
else
|
|
|
|
timer_sync(timer);
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2007-05-30 20:16:35 +02:00
|
|
|
timer_add(timer, size);
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2009-02-23 09:29:56 +01:00
|
|
|
return size;
|
2007-05-30 18:52:56 +02:00
|
|
|
}
|
|
|
|
|
2009-01-22 16:06:43 +01:00
|
|
|
static void
|
|
|
|
null_cancel(void *data)
|
2007-05-30 20:16:35 +02:00
|
|
|
{
|
2008-09-24 07:20:55 +02:00
|
|
|
struct null_data *nd = data;
|
|
|
|
|
2009-01-22 16:06:47 +01:00
|
|
|
if (!nd->sync)
|
|
|
|
return;
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
timer_reset(nd->timer);
|
2007-05-30 20:16:35 +02:00
|
|
|
}
|
|
|
|
|
2009-01-22 16:06:43 +01:00
|
|
|
const struct audio_output_plugin null_output_plugin = {
|
2008-09-29 15:55:17 +02:00
|
|
|
.name = "null",
|
2009-01-22 16:06:43 +01:00
|
|
|
.init = null_init,
|
2009-01-22 16:06:45 +01:00
|
|
|
.finish = null_finish,
|
2009-01-22 16:06:43 +01:00
|
|
|
.open = null_open,
|
|
|
|
.close = null_close,
|
|
|
|
.play = null_play,
|
|
|
|
.cancel = null_cancel,
|
2007-05-30 18:52:56 +02:00
|
|
|
};
|