From 7bb5a960fde46363adf888db5b05b7b883d2b16b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 2 Feb 2013 09:30:29 +0100 Subject: output/null: convert to C++ --- Makefile.am | 4 +- src/OutputList.cxx | 2 +- src/output/NullOutputPlugin.cxx | 136 ++++++++++++++++++++++++++++++++++++++++ src/output/NullOutputPlugin.hxx | 25 ++++++++ src/output/null_output_plugin.c | 129 ------------------------------------- src/output/null_output_plugin.h | 25 -------- 6 files changed, 164 insertions(+), 157 deletions(-) create mode 100644 src/output/NullOutputPlugin.cxx create mode 100644 src/output/NullOutputPlugin.hxx delete mode 100644 src/output/null_output_plugin.c delete mode 100644 src/output/null_output_plugin.h diff --git a/Makefile.am b/Makefile.am index 0e770efe..fd4ff377 100644 --- a/Makefile.am +++ b/Makefile.am @@ -790,8 +790,8 @@ OUTPUT_API_SRC = \ src/OutputInit.cxx liboutput_plugins_a_SOURCES = \ - src/output/null_output_plugin.h \ - src/output/null_output_plugin.c + src/output/NullOutputPlugin.cxx \ + src/output/NullOutputPlugin.hxx MIXER_LIBS = \ libmixer_plugins.a \ diff --git a/src/OutputList.cxx b/src/OutputList.cxx index f50f5cee..72f241bd 100644 --- a/src/OutputList.cxx +++ b/src/OutputList.cxx @@ -27,7 +27,7 @@ #include "output/HttpdOutputPlugin.hxx" #include "output/jack_output_plugin.h" #include "output/mvp_output_plugin.h" -#include "output/null_output_plugin.h" +#include "output/NullOutputPlugin.hxx" #include "output/openal_output_plugin.h" #include "output/OssOutputPlugin.hxx" #include "output/OSXOutputPlugin.hxx" diff --git a/src/output/NullOutputPlugin.cxx b/src/output/NullOutputPlugin.cxx new file mode 100644 index 00000000..3596cbdc --- /dev/null +++ b/src/output/NullOutputPlugin.cxx @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "NullOutputPlugin.hxx" +#include "output_api.h" +#include "timer.h" + +#include + +#include + +struct NullOutput { + struct audio_output base; + + bool sync; + + struct timer *timer; +}; + +static struct audio_output * +null_init(const struct config_param *param, GError **error_r) +{ + NullOutput *nd = g_new(NullOutput, 1); + + if (!ao_base_init(&nd->base, &null_output_plugin, param, error_r)) { + g_free(nd); + return NULL; + } + + nd->sync = config_get_block_bool(param, "sync", true); + + return &nd->base; +} + +static void +null_finish(struct audio_output *ao) +{ + NullOutput *nd = (NullOutput *)ao; + + ao_base_finish(&nd->base); + g_free(nd); +} + +static bool +null_open(struct audio_output *ao, struct audio_format *audio_format, + G_GNUC_UNUSED GError **error) +{ + NullOutput *nd = (NullOutput *)ao; + + if (nd->sync) + nd->timer = timer_new(audio_format); + + return true; +} + +static void +null_close(struct audio_output *ao) +{ + NullOutput *nd = (NullOutput *)ao; + + if (nd->sync) + timer_free(nd->timer); +} + +static unsigned +null_delay(struct audio_output *ao) +{ + NullOutput *nd = (NullOutput *)ao; + + return nd->sync && nd->timer->started + ? timer_delay(nd->timer) + : 0; +} + +static size_t +null_play(struct audio_output *ao, G_GNUC_UNUSED const void *chunk, size_t size, + G_GNUC_UNUSED GError **error) +{ + NullOutput *nd = (NullOutput *)ao; + struct timer *timer = nd->timer; + + if (!nd->sync) + return size; + + if (!timer->started) + timer_start(timer); + timer_add(timer, size); + + return size; +} + +static void +null_cancel(struct audio_output *ao) +{ + NullOutput *nd = (NullOutput *)ao; + + if (!nd->sync) + return; + + timer_reset(nd->timer); +} + +const struct audio_output_plugin null_output_plugin = { + "null", + nullptr, + null_init, + null_finish, + nullptr, + nullptr, + null_open, + null_close, + null_delay, + nullptr, + null_play, + nullptr, + null_cancel, + nullptr, + nullptr, +}; diff --git a/src/output/NullOutputPlugin.hxx b/src/output/NullOutputPlugin.hxx new file mode 100644 index 00000000..a58f1cb1 --- /dev/null +++ b/src/output/NullOutputPlugin.hxx @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_NULL_OUTPUT_PLUGIN_HXX +#define MPD_NULL_OUTPUT_PLUGIN_HXX + +extern const struct audio_output_plugin null_output_plugin; + +#endif diff --git a/src/output/null_output_plugin.c b/src/output/null_output_plugin.c deleted file mode 100644 index 9d7588ff..00000000 --- a/src/output/null_output_plugin.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" -#include "null_output_plugin.h" -#include "output_api.h" -#include "timer.h" - -#include - -#include - -struct null_data { - struct audio_output base; - - bool sync; - - struct timer *timer; -}; - -static struct audio_output * -null_init(const struct config_param *param, GError **error_r) -{ - struct null_data *nd = g_new(struct null_data, 1); - - if (!ao_base_init(&nd->base, &null_output_plugin, param, error_r)) { - g_free(nd); - return NULL; - } - - nd->sync = config_get_block_bool(param, "sync", true); - - return &nd->base; -} - -static void -null_finish(struct audio_output *ao) -{ - struct null_data *nd = (struct null_data *)ao; - - ao_base_finish(&nd->base); - g_free(nd); -} - -static bool -null_open(struct audio_output *ao, struct audio_format *audio_format, - G_GNUC_UNUSED GError **error) -{ - struct null_data *nd = (struct null_data *)ao; - - if (nd->sync) - nd->timer = timer_new(audio_format); - - return true; -} - -static void -null_close(struct audio_output *ao) -{ - struct null_data *nd = (struct null_data *)ao; - - if (nd->sync) - timer_free(nd->timer); -} - -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; -} - -static size_t -null_play(struct audio_output *ao, G_GNUC_UNUSED const void *chunk, size_t size, - G_GNUC_UNUSED GError **error) -{ - struct null_data *nd = (struct null_data *)ao; - struct timer *timer = nd->timer; - - if (!nd->sync) - return size; - - if (!timer->started) - timer_start(timer); - timer_add(timer, size); - - return size; -} - -static void -null_cancel(struct audio_output *ao) -{ - struct null_data *nd = (struct null_data *)ao; - - if (!nd->sync) - return; - - timer_reset(nd->timer); -} - -const struct audio_output_plugin null_output_plugin = { - .name = "null", - .init = null_init, - .finish = null_finish, - .open = null_open, - .close = null_close, - .delay = null_delay, - .play = null_play, - .cancel = null_cancel, -}; diff --git a/src/output/null_output_plugin.h b/src/output/null_output_plugin.h deleted file mode 100644 index 392bf0aa..00000000 --- a/src/output/null_output_plugin.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_NULL_OUTPUT_PLUGIN_H -#define MPD_NULL_OUTPUT_PLUGIN_H - -extern const struct audio_output_plugin null_output_plugin; - -#endif -- cgit v1.2.3