From d5516dee005075a7569890c0cea4235659687ea1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 10 Jan 2013 10:15:09 +0100 Subject: input_stream: convert to C++ (internally) --- src/CommandLine.cxx | 2 +- src/InputInit.cxx | 104 +++++++++++++++++++++ src/InputInit.hxx | 39 ++++++++ src/InputRegistry.cxx | 80 ++++++++++++++++ src/InputRegistry.hxx | 43 +++++++++ src/InputStream.cxx | 253 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/Main.cxx | 2 +- src/input_init.c | 104 --------------------- src/input_init.h | 41 -------- src/input_registry.c | 80 ---------------- src/input_registry.h | 45 --------- src/input_stream.c | 250 ------------------------------------------------- 12 files changed, 521 insertions(+), 522 deletions(-) create mode 100644 src/InputInit.cxx create mode 100644 src/InputInit.hxx create mode 100644 src/InputRegistry.cxx create mode 100644 src/InputRegistry.hxx create mode 100644 src/InputStream.cxx delete mode 100644 src/input_init.c delete mode 100644 src/input_init.h delete mode 100644 src/input_registry.c delete mode 100644 src/input_registry.h delete mode 100644 src/input_stream.c (limited to 'src') diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx index 6f9528a4..a8608af9 100644 --- a/src/CommandLine.cxx +++ b/src/CommandLine.cxx @@ -27,7 +27,7 @@ #include "decoder_plugin.h" #include "OutputList.hxx" #include "output_plugin.h" -#include "input_registry.h" +#include "InputRegistry.hxx" #include "input_plugin.h" #include "playlist_list.h" #include "playlist_plugin.h" diff --git a/src/InputInit.cxx b/src/InputInit.cxx new file mode 100644 index 00000000..6714cc72 --- /dev/null +++ b/src/InputInit.cxx @@ -0,0 +1,104 @@ +/* + * 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 "InputInit.hxx" +#include "InputRegistry.hxx" +#include "input_plugin.h" +#include "conf.h" + +#include +#include + +static inline GQuark +input_quark(void) +{ + return g_quark_from_static_string("input"); +} + +/** + * Find the "input" configuration block for the specified plugin. + * + * @param plugin_name the name of the input plugin + * @return the configuration block, or NULL if none was configured + */ +static const struct config_param * +input_plugin_config(const char *plugin_name, GError **error_r) +{ + const struct config_param *param = NULL; + + while ((param = config_get_next_param(CONF_INPUT, param)) != NULL) { + const char *name = + config_get_block_string(param, "plugin", NULL); + if (name == NULL) { + g_set_error(error_r, input_quark(), 0, + "input configuration without 'plugin' name in line %d", + param->line); + return NULL; + } + + if (strcmp(name, plugin_name) == 0) + return param; + } + + return NULL; +} + +bool +input_stream_global_init(GError **error_r) +{ + GError *error = NULL; + + for (unsigned i = 0; input_plugins[i] != NULL; ++i) { + const struct input_plugin *plugin = input_plugins[i]; + + assert(plugin->name != NULL); + assert(*plugin->name != 0); + assert(plugin->open != NULL); + + const struct config_param *param = + input_plugin_config(plugin->name, &error); + if (param == NULL && error != NULL) { + g_propagate_error(error_r, error); + return false; + } + + if (!config_get_block_bool(param, "enabled", true)) + /* the plugin is disabled in mpd.conf */ + continue; + + if (plugin->init == NULL || plugin->init(param, &error)) + input_plugins_enabled[i] = true; + else { + g_propagate_prefixed_error(error_r, error, + "Failed to initialize input plugin '%s': ", + plugin->name); + return false; + } + } + + return true; +} + +void input_stream_global_finish(void) +{ + input_plugins_for_each_enabled(plugin) + if (plugin->finish != NULL) + plugin->finish(); +} diff --git a/src/InputInit.hxx b/src/InputInit.hxx new file mode 100644 index 00000000..9d503e5a --- /dev/null +++ b/src/InputInit.hxx @@ -0,0 +1,39 @@ +/* + * 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_INPUT_INIT_HXX +#define MPD_INPUT_INIT_HXX + +#include "gerror.h" + +/** + * Initializes this library and all input_stream implementations. + * + * @param error_r location to store the error occurring, or NULL to + * ignore errors + */ +bool +input_stream_global_init(GError **error_r); + +/** + * Deinitializes this library and all input_stream implementations. + */ +void input_stream_global_finish(void); + +#endif diff --git a/src/InputRegistry.cxx b/src/InputRegistry.cxx new file mode 100644 index 00000000..ef8fe5df --- /dev/null +++ b/src/InputRegistry.cxx @@ -0,0 +1,80 @@ +/* + * 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 "InputRegistry.hxx" +#include "input/file_input_plugin.h" + +#ifdef ENABLE_ARCHIVE +#include "input/archive_input_plugin.h" +#endif + +#ifdef ENABLE_CURL +#include "input/curl_input_plugin.h" +#endif + +#ifdef ENABLE_SOUP +#include "input/soup_input_plugin.h" +#endif + +#ifdef HAVE_FFMPEG +#include "input/ffmpeg_input_plugin.h" +#endif + +#ifdef ENABLE_MMS +#include "input/mms_input_plugin.h" +#endif + +#ifdef ENABLE_CDIO_PARANOIA +#include "input/cdio_paranoia_input_plugin.h" +#endif + +#ifdef ENABLE_DESPOTIFY +#include "input/despotify_input_plugin.h" +#endif + +#include + +const struct input_plugin *const input_plugins[] = { + &input_plugin_file, +#ifdef ENABLE_ARCHIVE + &input_plugin_archive, +#endif +#ifdef ENABLE_CURL + &input_plugin_curl, +#endif +#ifdef ENABLE_SOUP + &input_plugin_soup, +#endif +#ifdef HAVE_FFMPEG + &input_plugin_ffmpeg, +#endif +#ifdef ENABLE_MMS + &input_plugin_mms, +#endif +#ifdef ENABLE_CDIO_PARANOIA + &input_plugin_cdio_paranoia, +#endif +#ifdef ENABLE_DESPOTIFY + &input_plugin_despotify, +#endif + NULL +}; + +bool input_plugins_enabled[G_N_ELEMENTS(input_plugins) - 1]; diff --git a/src/InputRegistry.hxx b/src/InputRegistry.hxx new file mode 100644 index 00000000..a080d108 --- /dev/null +++ b/src/InputRegistry.hxx @@ -0,0 +1,43 @@ +/* + * 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_INPUT_REGISTRY_HXX +#define MPD_INPUT_REGISTRY_HXX + +#include "check.h" + +/** + * NULL terminated list of all input plugins which were enabled at + * compile time. + */ +extern const struct input_plugin *const input_plugins[]; + +extern bool input_plugins_enabled[]; + +#define input_plugins_for_each(plugin) \ + for (const struct input_plugin *plugin, \ + *const*input_plugin_iterator = &input_plugins[0]; \ + (plugin = *input_plugin_iterator) != NULL; \ + ++input_plugin_iterator) + +#define input_plugins_for_each_enabled(plugin) \ + input_plugins_for_each(plugin) \ + if (input_plugins_enabled[input_plugin_iterator - input_plugins]) + +#endif diff --git a/src/InputStream.cxx b/src/InputStream.cxx new file mode 100644 index 00000000..64f34755 --- /dev/null +++ b/src/InputStream.cxx @@ -0,0 +1,253 @@ +/* + * 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 "input_stream.h" +#include "InputRegistry.hxx" +#include "input_plugin.h" + +extern "C" { +#include "input/rewind_input_plugin.h" +#include "uri.h" +} + +#include +#include + +static inline GQuark +input_quark(void) +{ + return g_quark_from_static_string("input"); +} + +struct input_stream * +input_stream_open(const char *url, + GMutex *mutex, GCond *cond, + GError **error_r) +{ + GError *error = NULL; + + assert(mutex != NULL); + assert(error_r == NULL || *error_r == NULL); + + input_plugins_for_each_enabled(plugin) { + struct input_stream *is; + + is = plugin->open(url, mutex, cond, &error); + if (is != NULL) { + assert(is->plugin != NULL); + assert(is->plugin->close != NULL); + assert(is->plugin->read != NULL); + assert(is->plugin->eof != NULL); + assert(!is->seekable || is->plugin->seek != NULL); + + is = input_rewind_open(is); + + return is; + } else if (error != NULL) { + g_propagate_error(error_r, error); + return NULL; + } + } + + g_set_error(error_r, input_quark(), 0, "Unrecognized URI"); + return NULL; +} + +bool +input_stream_check(struct input_stream *is, GError **error_r) +{ + assert(is != NULL); + assert(is->plugin != NULL); + + return is->plugin->check == NULL || + is->plugin->check(is, error_r); +} + +void +input_stream_update(struct input_stream *is) +{ + assert(is != NULL); + assert(is->plugin != NULL); + + if (is->plugin->update != NULL) + is->plugin->update(is); +} + +void +input_stream_wait_ready(struct input_stream *is) +{ + assert(is != NULL); + assert(is->mutex != NULL); + assert(is->cond != NULL); + + while (true) { + input_stream_update(is); + if (is->ready) + break; + + g_cond_wait(is->cond, is->mutex); + } +} + +void +input_stream_lock_wait_ready(struct input_stream *is) +{ + assert(is != NULL); + assert(is->mutex != NULL); + assert(is->cond != NULL); + + g_mutex_lock(is->mutex); + input_stream_wait_ready(is); + g_mutex_unlock(is->mutex); +} + +bool +input_stream_cheap_seeking(const struct input_stream *is) +{ + return is->seekable && (is->uri == NULL || !uri_has_scheme(is->uri)); +} + +bool +input_stream_seek(struct input_stream *is, goffset offset, int whence, + GError **error_r) +{ + assert(is != NULL); + assert(is->plugin != NULL); + + if (is->plugin->seek == NULL) + return false; + + return is->plugin->seek(is, offset, whence, error_r); +} + +bool +input_stream_lock_seek(struct input_stream *is, goffset offset, int whence, + GError **error_r) +{ + assert(is != NULL); + assert(is->plugin != NULL); + + if (is->plugin->seek == NULL) + return false; + + if (is->mutex == NULL) + /* no locking */ + return input_stream_seek(is, offset, whence, error_r); + + g_mutex_lock(is->mutex); + bool success = input_stream_seek(is, offset, whence, error_r); + g_mutex_unlock(is->mutex); + return success; +} + +struct tag * +input_stream_tag(struct input_stream *is) +{ + assert(is != NULL); + assert(is->plugin != NULL); + + return is->plugin->tag != NULL + ? is->plugin->tag(is) + : NULL; +} + +struct tag * +input_stream_lock_tag(struct input_stream *is) +{ + assert(is != NULL); + assert(is->plugin != NULL); + + if (is->plugin->tag == NULL) + return nullptr; + + if (is->mutex == NULL) + /* no locking */ + return input_stream_tag(is); + + g_mutex_lock(is->mutex); + struct tag *tag = input_stream_tag(is); + g_mutex_unlock(is->mutex); + return tag; +} + +bool +input_stream_available(struct input_stream *is) +{ + assert(is != NULL); + assert(is->plugin != NULL); + + return is->plugin->available != NULL + ? is->plugin->available(is) + : true; +} + +size_t +input_stream_read(struct input_stream *is, void *ptr, size_t size, + GError **error_r) +{ + assert(ptr != NULL); + assert(size > 0); + + return is->plugin->read(is, ptr, size, error_r); +} + +size_t +input_stream_lock_read(struct input_stream *is, void *ptr, size_t size, + GError **error_r) +{ + assert(ptr != NULL); + assert(size > 0); + + if (is->mutex == NULL) + /* no locking */ + return input_stream_read(is, ptr, size, error_r); + + g_mutex_lock(is->mutex); + size_t nbytes = input_stream_read(is, ptr, size, error_r); + g_mutex_unlock(is->mutex); + return nbytes; +} + +void input_stream_close(struct input_stream *is) +{ + is->plugin->close(is); +} + +bool input_stream_eof(struct input_stream *is) +{ + return is->plugin->eof(is); +} + +bool +input_stream_lock_eof(struct input_stream *is) +{ + assert(is != NULL); + assert(is->plugin != NULL); + + if (is->mutex == NULL) + /* no locking */ + return input_stream_eof(is); + + g_mutex_lock(is->mutex); + bool eof = input_stream_eof(is); + g_mutex_unlock(is->mutex); + return eof; +} + diff --git a/src/Main.cxx b/src/Main.cxx index bece3720..d091b964 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -44,6 +44,7 @@ #include "SignalHandlers.hxx" #include "Log.hxx" #include "GlobalEvents.hxx" +#include "InputInit.hxx" extern "C" { #include "daemon.h" @@ -53,7 +54,6 @@ extern "C" { #include "audio_config.h" #include "pcm_resample.h" #include "decoder_list.h" -#include "input_init.h" #include "playlist_list.h" #include "zeroconf.h" } diff --git a/src/input_init.c b/src/input_init.c deleted file mode 100644 index 771d648d..00000000 --- a/src/input_init.c +++ /dev/null @@ -1,104 +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 "input_init.h" -#include "input_plugin.h" -#include "input_registry.h" -#include "conf.h" - -#include -#include - -static inline GQuark -input_quark(void) -{ - return g_quark_from_static_string("input"); -} - -/** - * Find the "input" configuration block for the specified plugin. - * - * @param plugin_name the name of the input plugin - * @return the configuration block, or NULL if none was configured - */ -static const struct config_param * -input_plugin_config(const char *plugin_name, GError **error_r) -{ - const struct config_param *param = NULL; - - while ((param = config_get_next_param(CONF_INPUT, param)) != NULL) { - const char *name = - config_get_block_string(param, "plugin", NULL); - if (name == NULL) { - g_set_error(error_r, input_quark(), 0, - "input configuration without 'plugin' name in line %d", - param->line); - return NULL; - } - - if (strcmp(name, plugin_name) == 0) - return param; - } - - return NULL; -} - -bool -input_stream_global_init(GError **error_r) -{ - GError *error = NULL; - - for (unsigned i = 0; input_plugins[i] != NULL; ++i) { - const struct input_plugin *plugin = input_plugins[i]; - - assert(plugin->name != NULL); - assert(*plugin->name != 0); - assert(plugin->open != NULL); - - const struct config_param *param = - input_plugin_config(plugin->name, &error); - if (param == NULL && error != NULL) { - g_propagate_error(error_r, error); - return false; - } - - if (!config_get_block_bool(param, "enabled", true)) - /* the plugin is disabled in mpd.conf */ - continue; - - if (plugin->init == NULL || plugin->init(param, &error)) - input_plugins_enabled[i] = true; - else { - g_propagate_prefixed_error(error_r, error, - "Failed to initialize input plugin '%s': ", - plugin->name); - return false; - } - } - - return true; -} - -void input_stream_global_finish(void) -{ - input_plugins_for_each_enabled(plugin) - if (plugin->finish != NULL) - plugin->finish(); -} diff --git a/src/input_init.h b/src/input_init.h deleted file mode 100644 index 1a73e5ef..00000000 --- a/src/input_init.h +++ /dev/null @@ -1,41 +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_INPUT_INIT_H -#define MPD_INPUT_INIT_H - -#include "gerror.h" - -#include - -/** - * Initializes this library and all input_stream implementations. - * - * @param error_r location to store the error occurring, or NULL to - * ignore errors - */ -bool -input_stream_global_init(GError **error_r); - -/** - * Deinitializes this library and all input_stream implementations. - */ -void input_stream_global_finish(void); - -#endif diff --git a/src/input_registry.c b/src/input_registry.c deleted file mode 100644 index 5987d5da..00000000 --- a/src/input_registry.c +++ /dev/null @@ -1,80 +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 "input_registry.h" -#include "input/file_input_plugin.h" - -#ifdef ENABLE_ARCHIVE -#include "input/archive_input_plugin.h" -#endif - -#ifdef ENABLE_CURL -#include "input/curl_input_plugin.h" -#endif - -#ifdef ENABLE_SOUP -#include "input/soup_input_plugin.h" -#endif - -#ifdef HAVE_FFMPEG -#include "input/ffmpeg_input_plugin.h" -#endif - -#ifdef ENABLE_MMS -#include "input/mms_input_plugin.h" -#endif - -#ifdef ENABLE_CDIO_PARANOIA -#include "input/cdio_paranoia_input_plugin.h" -#endif - -#ifdef ENABLE_DESPOTIFY -#include "input/despotify_input_plugin.h" -#endif - -#include - -const struct input_plugin *const input_plugins[] = { - &input_plugin_file, -#ifdef ENABLE_ARCHIVE - &input_plugin_archive, -#endif -#ifdef ENABLE_CURL - &input_plugin_curl, -#endif -#ifdef ENABLE_SOUP - &input_plugin_soup, -#endif -#ifdef HAVE_FFMPEG - &input_plugin_ffmpeg, -#endif -#ifdef ENABLE_MMS - &input_plugin_mms, -#endif -#ifdef ENABLE_CDIO_PARANOIA - &input_plugin_cdio_paranoia, -#endif -#ifdef ENABLE_DESPOTIFY - &input_plugin_despotify, -#endif - NULL -}; - -bool input_plugins_enabled[G_N_ELEMENTS(input_plugins) - 1]; diff --git a/src/input_registry.h b/src/input_registry.h deleted file mode 100644 index 4f5fff8d..00000000 --- a/src/input_registry.h +++ /dev/null @@ -1,45 +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_INPUT_REGISTRY_H -#define MPD_INPUT_REGISTRY_H - -#include "check.h" - -#include - -/** - * NULL terminated list of all input plugins which were enabled at - * compile time. - */ -extern const struct input_plugin *const input_plugins[]; - -extern bool input_plugins_enabled[]; - -#define input_plugins_for_each(plugin) \ - for (const struct input_plugin *plugin, \ - *const*input_plugin_iterator = &input_plugins[0]; \ - (plugin = *input_plugin_iterator) != NULL; \ - ++input_plugin_iterator) - -#define input_plugins_for_each_enabled(plugin) \ - input_plugins_for_each(plugin) \ - if (input_plugins_enabled[input_plugin_iterator - input_plugins]) - -#endif diff --git a/src/input_stream.c b/src/input_stream.c deleted file mode 100644 index c82788f3..00000000 --- a/src/input_stream.c +++ /dev/null @@ -1,250 +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 "input_stream.h" -#include "input_registry.h" -#include "input_plugin.h" -#include "input/rewind_input_plugin.h" -#include "uri.h" - -#include -#include - -static inline GQuark -input_quark(void) -{ - return g_quark_from_static_string("input"); -} - -struct input_stream * -input_stream_open(const char *url, - GMutex *mutex, GCond *cond, - GError **error_r) -{ - GError *error = NULL; - - assert(mutex != NULL); - assert(error_r == NULL || *error_r == NULL); - - input_plugins_for_each_enabled(plugin) { - struct input_stream *is; - - is = plugin->open(url, mutex, cond, &error); - if (is != NULL) { - assert(is->plugin != NULL); - assert(is->plugin->close != NULL); - assert(is->plugin->read != NULL); - assert(is->plugin->eof != NULL); - assert(!is->seekable || is->plugin->seek != NULL); - - is = input_rewind_open(is); - - return is; - } else if (error != NULL) { - g_propagate_error(error_r, error); - return NULL; - } - } - - g_set_error(error_r, input_quark(), 0, "Unrecognized URI"); - return NULL; -} - -bool -input_stream_check(struct input_stream *is, GError **error_r) -{ - assert(is != NULL); - assert(is->plugin != NULL); - - return is->plugin->check == NULL || - is->plugin->check(is, error_r); -} - -void -input_stream_update(struct input_stream *is) -{ - assert(is != NULL); - assert(is->plugin != NULL); - - if (is->plugin->update != NULL) - is->plugin->update(is); -} - -void -input_stream_wait_ready(struct input_stream *is) -{ - assert(is != NULL); - assert(is->mutex != NULL); - assert(is->cond != NULL); - - while (true) { - input_stream_update(is); - if (is->ready) - break; - - g_cond_wait(is->cond, is->mutex); - } -} - -void -input_stream_lock_wait_ready(struct input_stream *is) -{ - assert(is != NULL); - assert(is->mutex != NULL); - assert(is->cond != NULL); - - g_mutex_lock(is->mutex); - input_stream_wait_ready(is); - g_mutex_unlock(is->mutex); -} - -bool -input_stream_cheap_seeking(const struct input_stream *is) -{ - return is->seekable && (is->uri == NULL || !uri_has_scheme(is->uri)); -} - -bool -input_stream_seek(struct input_stream *is, goffset offset, int whence, - GError **error_r) -{ - assert(is != NULL); - assert(is->plugin != NULL); - - if (is->plugin->seek == NULL) - return false; - - return is->plugin->seek(is, offset, whence, error_r); -} - -bool -input_stream_lock_seek(struct input_stream *is, goffset offset, int whence, - GError **error_r) -{ - assert(is != NULL); - assert(is->plugin != NULL); - - if (is->plugin->seek == NULL) - return false; - - if (is->mutex == NULL) - /* no locking */ - return input_stream_seek(is, offset, whence, error_r); - - g_mutex_lock(is->mutex); - bool success = input_stream_seek(is, offset, whence, error_r); - g_mutex_unlock(is->mutex); - return success; -} - -struct tag * -input_stream_tag(struct input_stream *is) -{ - assert(is != NULL); - assert(is->plugin != NULL); - - return is->plugin->tag != NULL - ? is->plugin->tag(is) - : NULL; -} - -struct tag * -input_stream_lock_tag(struct input_stream *is) -{ - assert(is != NULL); - assert(is->plugin != NULL); - - if (is->plugin->tag == NULL) - return false; - - if (is->mutex == NULL) - /* no locking */ - return input_stream_tag(is); - - g_mutex_lock(is->mutex); - struct tag *tag = input_stream_tag(is); - g_mutex_unlock(is->mutex); - return tag; -} - -bool -input_stream_available(struct input_stream *is) -{ - assert(is != NULL); - assert(is->plugin != NULL); - - return is->plugin->available != NULL - ? is->plugin->available(is) - : true; -} - -size_t -input_stream_read(struct input_stream *is, void *ptr, size_t size, - GError **error_r) -{ - assert(ptr != NULL); - assert(size > 0); - - return is->plugin->read(is, ptr, size, error_r); -} - -size_t -input_stream_lock_read(struct input_stream *is, void *ptr, size_t size, - GError **error_r) -{ - assert(ptr != NULL); - assert(size > 0); - - if (is->mutex == NULL) - /* no locking */ - return input_stream_read(is, ptr, size, error_r); - - g_mutex_lock(is->mutex); - size_t nbytes = input_stream_read(is, ptr, size, error_r); - g_mutex_unlock(is->mutex); - return nbytes; -} - -void input_stream_close(struct input_stream *is) -{ - is->plugin->close(is); -} - -bool input_stream_eof(struct input_stream *is) -{ - return is->plugin->eof(is); -} - -bool -input_stream_lock_eof(struct input_stream *is) -{ - assert(is != NULL); - assert(is->plugin != NULL); - - if (is->mutex == NULL) - /* no locking */ - return input_stream_eof(is); - - g_mutex_lock(is->mutex); - bool eof = input_stream_eof(is); - g_mutex_unlock(is->mutex); - return eof; -} - -- cgit v1.2.3