2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2007-05-30 18:52:56 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-05-30 18:52:56 +02:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2011-09-17 08:54:28 +02:00
|
|
|
#include "null_output_plugin.h"
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "output_api.h"
|
|
|
|
#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 {
|
2011-09-16 23:31:48 +02:00
|
|
|
struct audio_output base;
|
|
|
|
|
2009-01-22 16:06:47 +01:00
|
|
|
bool sync;
|
|
|
|
|
2011-07-25 21:55:43 +02:00
|
|
|
struct timer *timer;
|
2008-09-24 07:20:55 +02:00
|
|
|
};
|
|
|
|
|
2011-09-16 23:31:48 +02:00
|
|
|
static struct audio_output *
|
|
|
|
null_init(const struct config_param *param, GError **error_r)
|
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
|
|
|
|
2011-09-16 23:31:48 +02:00
|
|
|
if (!ao_base_init(&nd->base, &null_output_plugin, param, error_r)) {
|
|
|
|
g_free(nd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-22 16:06:47 +01:00
|
|
|
nd->sync = config_get_block_bool(param, "sync", true);
|
2009-01-22 16:06:43 +01:00
|
|
|
|
2011-09-16 23:31:48 +02:00
|
|
|
return &nd->base;
|
2007-05-30 18:52:56 +02:00
|
|
|
}
|
|
|
|
|
2009-01-22 16:06:45 +01:00
|
|
|
static void
|
2011-09-16 23:31:48 +02:00
|
|
|
null_finish(struct audio_output *ao)
|
2009-01-22 16:06:45 +01:00
|
|
|
{
|
2011-09-16 23:31:48 +02:00
|
|
|
struct null_data *nd = (struct null_data *)ao;
|
2009-01-22 16:06:45 +01:00
|
|
|
|
2011-09-16 23:31:48 +02:00
|
|
|
ao_base_finish(&nd->base);
|
2009-01-22 16:06:45 +01:00
|
|
|
g_free(nd);
|
|
|
|
}
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
static bool
|
2011-09-16 23:31:48 +02:00
|
|
|
null_open(struct audio_output *ao, struct audio_format *audio_format,
|
2009-02-26 22:04:59 +01:00
|
|
|
G_GNUC_UNUSED GError **error)
|
2007-05-30 18:52:56 +02:00
|
|
|
{
|
2011-09-16 23:31:48 +02:00
|
|
|
struct null_data *nd = (struct null_data *)ao;
|
2008-09-24 07:20:55 +02:00
|
|
|
|
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
|
2011-09-16 23:31:48 +02:00
|
|
|
null_close(struct audio_output *ao)
|
2007-05-30 18:52:56 +02:00
|
|
|
{
|
2011-09-16 23:31:48 +02:00
|
|
|
struct null_data *nd = (struct null_data *)ao;
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2011-12-13 21:08:15 +01:00
|
|
|
if (nd->sync)
|
2008-09-24 07:20:55 +02:00
|
|
|
timer_free(nd->timer);
|
2007-05-30 18:52:56 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 21:11:04 +01:00
|
|
|
static unsigned
|
|
|
|
null_delay(struct audio_output *ao)
|
|
|
|
{
|
|
|
|
struct null_data *nd = (struct null_data *)ao;
|
|
|
|
|
|
|
|
return nd->sync && nd->timer->started
|
|
|
|
? timer_delay(nd->timer)
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
2009-02-23 09:29:56 +01:00
|
|
|
static size_t
|
2011-09-16 23:31:48 +02:00
|
|
|
null_play(struct audio_output *ao, G_GNUC_UNUSED const void *chunk, size_t size,
|
2009-02-26 22:04:59 +01:00
|
|
|
G_GNUC_UNUSED GError **error)
|
2007-05-30 18:52:56 +02:00
|
|
|
{
|
2011-09-16 23:31:48 +02:00
|
|
|
struct null_data *nd = (struct null_data *)ao;
|
2011-07-25 21:55:43 +02:00
|
|
|
struct 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);
|
|
|
|
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
|
2011-09-16 23:31:48 +02:00
|
|
|
null_cancel(struct audio_output *ao)
|
2007-05-30 20:16:35 +02:00
|
|
|
{
|
2011-09-16 23:31:48 +02:00
|
|
|
struct null_data *nd = (struct null_data *)ao;
|
2008-09-24 07:20:55 +02:00
|
|
|
|
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,
|
2011-12-13 21:11:04 +01:00
|
|
|
.delay = null_delay,
|
2009-01-22 16:06:43 +01:00
|
|
|
.play = null_play,
|
|
|
|
.cancel = null_cancel,
|
2007-05-30 18:52:56 +02:00
|
|
|
};
|