2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2013-01-30 17:18:48 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2004-06-16 23:52:59 +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.
|
2004-06-16 23:52:59 +02:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-30 17:18:48 +01:00
|
|
|
#include "DecoderList.hxx"
|
2013-07-28 13:18:48 +02:00
|
|
|
#include "DecoderPlugin.hxx"
|
2013-09-05 08:47:10 +02:00
|
|
|
#include "ConfigGlobal.hxx"
|
|
|
|
#include "ConfigData.hxx"
|
2013-07-28 12:37:55 +02:00
|
|
|
#include "decoder/AudiofileDecoderPlugin.hxx"
|
2013-07-28 13:10:05 +02:00
|
|
|
#include "decoder/PcmDecoderPlugin.hxx"
|
2013-07-28 12:20:50 +02:00
|
|
|
#include "decoder/DsdiffDecoderPlugin.hxx"
|
|
|
|
#include "decoder/DsfDecoderPlugin.hxx"
|
2013-05-05 14:19:04 +02:00
|
|
|
#include "decoder/FlacDecoderPlugin.h"
|
2012-09-04 09:26:18 +02:00
|
|
|
#include "decoder/OpusDecoderPlugin.h"
|
2013-01-07 22:04:58 +01:00
|
|
|
#include "decoder/VorbisDecoderPlugin.h"
|
2012-09-25 22:03:44 +02:00
|
|
|
#include "decoder/AdPlugDecoderPlugin.h"
|
2013-01-10 18:18:14 +01:00
|
|
|
#include "decoder/WavpackDecoderPlugin.hxx"
|
2013-01-26 00:37:04 +01:00
|
|
|
#include "decoder/FfmpegDecoderPlugin.hxx"
|
2013-04-08 23:32:53 +02:00
|
|
|
#include "decoder/GmeDecoderPlugin.hxx"
|
2013-04-17 22:33:59 +02:00
|
|
|
#include "decoder/FaadDecoderPlugin.hxx"
|
2013-07-26 11:59:17 +02:00
|
|
|
#include "decoder/MadDecoderPlugin.hxx"
|
2013-07-28 12:42:06 +02:00
|
|
|
#include "decoder/SndfileDecoderPlugin.hxx"
|
2013-07-28 12:45:48 +02:00
|
|
|
#include "decoder/Mpg123DecoderPlugin.hxx"
|
2013-07-28 12:50:37 +02:00
|
|
|
#include "decoder/WildmidiDecoderPlugin.hxx"
|
2013-07-28 12:54:59 +02:00
|
|
|
#include "decoder/MikmodDecoderPlugin.hxx"
|
2013-07-28 12:56:35 +02:00
|
|
|
#include "decoder/ModplugDecoderPlugin.hxx"
|
2013-07-28 13:04:12 +02:00
|
|
|
#include "decoder/MpcdecDecoderPlugin.hxx"
|
2013-07-28 13:12:08 +02:00
|
|
|
#include "decoder/FluidsynthDecoderPlugin.hxx"
|
2013-10-20 13:05:29 +02:00
|
|
|
#include "decoder/SidplayDecoderPlugin.hxx"
|
2013-09-05 18:20:52 +02:00
|
|
|
#include "system/FatalError.hxx"
|
2013-10-15 22:04:17 +02:00
|
|
|
#include "util/Macros.hxx"
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2009-02-15 17:48:37 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-10-21 20:31:34 +02:00
|
|
|
const struct DecoderPlugin *const decoder_plugins[] = {
|
2008-11-01 14:53:30 +01:00
|
|
|
#ifdef HAVE_MAD
|
2009-02-16 19:30:45 +01:00
|
|
|
&mad_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
2009-08-26 20:08:13 +02:00
|
|
|
#ifdef HAVE_MPG123
|
|
|
|
&mpg123_decoder_plugin,
|
|
|
|
#endif
|
2009-04-01 22:45:17 +02:00
|
|
|
#ifdef ENABLE_VORBIS_DECODER
|
2009-01-14 23:09:02 +01:00
|
|
|
&vorbis_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
2011-09-01 19:29:04 +02:00
|
|
|
#if defined(HAVE_FLAC)
|
2009-01-15 19:50:28 +01:00
|
|
|
&oggflac_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FLAC
|
2009-01-15 19:50:28 +01:00
|
|
|
&flac_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
2012-09-04 09:26:18 +02:00
|
|
|
#ifdef HAVE_OPUS
|
|
|
|
&opus_decoder_plugin,
|
|
|
|
#endif
|
2009-07-07 08:58:51 +02:00
|
|
|
#ifdef ENABLE_SNDFILE
|
|
|
|
&sndfile_decoder_plugin,
|
|
|
|
#endif
|
2008-11-01 14:53:30 +01:00
|
|
|
#ifdef HAVE_AUDIOFILE
|
2009-04-03 00:52:13 +02:00
|
|
|
&audiofile_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
2011-10-03 12:52:15 +02:00
|
|
|
&dsdiff_decoder_plugin,
|
2012-06-16 13:46:42 +02:00
|
|
|
&dsf_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#ifdef HAVE_FAAD
|
2009-02-16 19:30:54 +01:00
|
|
|
&faad_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_MPCDEC
|
2009-02-17 08:48:20 +01:00
|
|
|
&mpcdec_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WAVPACK
|
2009-04-03 00:52:13 +02:00
|
|
|
&wavpack_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
2008-12-28 17:11:18 +01:00
|
|
|
#ifdef HAVE_MODPLUG
|
2009-04-03 00:52:13 +02:00
|
|
|
&modplug_decoder_plugin,
|
2008-12-28 17:11:18 +01:00
|
|
|
#endif
|
2009-04-01 22:48:06 +02:00
|
|
|
#ifdef ENABLE_MIKMOD_DECODER
|
2009-01-24 20:18:44 +01:00
|
|
|
&mikmod_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
2009-02-11 20:31:17 +01:00
|
|
|
#ifdef ENABLE_SIDPLAY
|
|
|
|
&sidplay_decoder_plugin,
|
|
|
|
#endif
|
2009-02-12 16:43:18 +01:00
|
|
|
#ifdef ENABLE_WILDMIDI
|
|
|
|
&wildmidi_decoder_plugin,
|
|
|
|
#endif
|
2009-04-05 06:31:55 +02:00
|
|
|
#ifdef ENABLE_FLUIDSYNTH
|
|
|
|
&fluidsynth_decoder_plugin,
|
|
|
|
#endif
|
2012-09-25 22:03:44 +02:00
|
|
|
#ifdef HAVE_ADPLUG
|
|
|
|
&adplug_decoder_plugin,
|
|
|
|
#endif
|
2008-11-01 14:53:30 +01:00
|
|
|
#ifdef HAVE_FFMPEG
|
2009-04-03 00:52:13 +02:00
|
|
|
&ffmpeg_decoder_plugin,
|
2010-04-10 10:05:16 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GME
|
|
|
|
&gme_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
2010-12-22 09:08:12 +01:00
|
|
|
&pcm_decoder_plugin,
|
2013-10-19 18:19:03 +02:00
|
|
|
nullptr
|
2008-11-01 14:53:30 +01:00
|
|
|
};
|
2004-05-31 22:59:55 +02:00
|
|
|
|
2013-10-15 22:04:17 +02:00
|
|
|
static constexpr unsigned num_decoder_plugins =
|
|
|
|
ARRAY_SIZE(decoder_plugins) - 1;
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2008-11-01 14:53:30 +01:00
|
|
|
/** which plugins have been initialized successfully? */
|
2009-11-07 15:46:45 +01:00
|
|
|
bool decoder_plugins_enabled[num_decoder_plugins];
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2009-11-07 15:14:16 +01:00
|
|
|
static unsigned
|
2013-10-21 20:31:34 +02:00
|
|
|
decoder_plugin_index(const struct DecoderPlugin *plugin)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-11-07 15:14:16 +01:00
|
|
|
unsigned i = 0;
|
|
|
|
|
|
|
|
while (decoder_plugins[i] != plugin)
|
|
|
|
++i;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
2013-10-21 20:31:34 +02:00
|
|
|
decoder_plugin_next_index(const struct DecoderPlugin *plugin)
|
2009-11-07 15:14:16 +01:00
|
|
|
{
|
|
|
|
return plugin == 0
|
|
|
|
? 0 /* start with first plugin */
|
|
|
|
: decoder_plugin_index(plugin) + 1;
|
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2013-10-21 20:31:34 +02:00
|
|
|
const struct DecoderPlugin *
|
2009-11-07 15:14:16 +01:00
|
|
|
decoder_plugin_from_suffix(const char *suffix,
|
2013-10-21 20:31:34 +02:00
|
|
|
const struct DecoderPlugin *plugin)
|
2009-11-07 15:14:16 +01:00
|
|
|
{
|
2013-10-19 18:19:03 +02:00
|
|
|
if (suffix == nullptr)
|
|
|
|
return nullptr;
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2009-11-07 15:14:16 +01:00
|
|
|
for (unsigned i = decoder_plugin_next_index(plugin);
|
2013-10-19 18:19:03 +02:00
|
|
|
decoder_plugins[i] != nullptr; ++i) {
|
2009-11-07 15:14:16 +01:00
|
|
|
plugin = decoder_plugins[i];
|
2009-11-07 15:14:11 +01:00
|
|
|
if (decoder_plugins_enabled[i] &&
|
2013-10-21 20:36:34 +02:00
|
|
|
plugin->SupportsSuffix(suffix))
|
2004-05-30 22:25:08 +02:00
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
2013-10-19 18:19:03 +02:00
|
|
|
return nullptr;
|
2004-05-30 22:25:08 +02:00
|
|
|
}
|
|
|
|
|
2013-10-21 20:31:34 +02:00
|
|
|
const struct DecoderPlugin *
|
2008-11-01 14:51:41 +01:00
|
|
|
decoder_plugin_from_mime_type(const char *mimeType, unsigned int next)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-11-01 14:53:30 +01:00
|
|
|
static unsigned i = num_decoder_plugins;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2013-10-19 18:19:03 +02:00
|
|
|
if (mimeType == nullptr)
|
|
|
|
return nullptr;
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2008-11-01 14:53:30 +01:00
|
|
|
if (!next)
|
|
|
|
i = 0;
|
2013-10-19 18:19:03 +02:00
|
|
|
for (; decoder_plugins[i] != nullptr; ++i) {
|
2013-10-21 20:31:34 +02:00
|
|
|
const struct DecoderPlugin *plugin = decoder_plugins[i];
|
2009-11-07 15:14:11 +01:00
|
|
|
if (decoder_plugins_enabled[i] &&
|
2013-10-21 20:36:34 +02:00
|
|
|
plugin->SupportsMimeType(mimeType)) {
|
2008-11-01 14:53:30 +01:00
|
|
|
++i;
|
2004-05-30 22:25:08 +02:00
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-19 18:19:03 +02:00
|
|
|
return nullptr;
|
2004-05-30 22:25:08 +02:00
|
|
|
}
|
|
|
|
|
2013-10-21 20:31:34 +02:00
|
|
|
const struct DecoderPlugin *
|
2008-11-01 14:51:41 +01:00
|
|
|
decoder_plugin_from_name(const char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2013-10-21 22:02:19 +02:00
|
|
|
decoder_plugins_find([=](const DecoderPlugin &plugin){
|
|
|
|
return strcmp(plugin.name, name) == 0;
|
|
|
|
});
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2013-10-19 18:19:03 +02:00
|
|
|
return nullptr;
|
2004-05-30 22:25:08 +02:00
|
|
|
}
|
|
|
|
|
2009-02-15 18:35:19 +01:00
|
|
|
/**
|
|
|
|
* Find the "decoder" configuration block for the specified plugin.
|
|
|
|
*
|
|
|
|
* @param plugin_name the name of the decoder plugin
|
2013-10-19 18:19:03 +02:00
|
|
|
* @return the configuration block, or nullptr if none was configured
|
2009-02-15 18:35:19 +01:00
|
|
|
*/
|
|
|
|
static const struct config_param *
|
|
|
|
decoder_plugin_config(const char *plugin_name)
|
|
|
|
{
|
2013-10-19 18:19:03 +02:00
|
|
|
const struct config_param *param = nullptr;
|
2009-02-15 18:35:19 +01:00
|
|
|
|
2013-10-19 18:19:03 +02:00
|
|
|
while ((param = config_get_next_param(CONF_DECODER, param)) != nullptr) {
|
2013-08-04 11:30:26 +02:00
|
|
|
const char *name = param->GetBlockValue("plugin");
|
2013-10-19 18:19:03 +02:00
|
|
|
if (name == nullptr)
|
2013-09-05 18:20:52 +02:00
|
|
|
FormatFatalError("decoder configuration without 'plugin' name in line %d",
|
|
|
|
param->line);
|
2009-02-15 18:35:19 +01:00
|
|
|
|
|
|
|
if (strcmp(name, plugin_name) == 0)
|
|
|
|
return param;
|
|
|
|
}
|
|
|
|
|
2013-10-19 18:19:03 +02:00
|
|
|
return nullptr;
|
2009-02-15 18:35:19 +01:00
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
void decoder_plugin_init_all(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2013-08-04 11:30:26 +02:00
|
|
|
struct config_param empty;
|
|
|
|
|
2013-10-19 18:19:03 +02:00
|
|
|
for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i) {
|
2013-10-21 20:31:34 +02:00
|
|
|
const DecoderPlugin &plugin = *decoder_plugins[i];
|
2009-02-15 18:35:19 +01:00
|
|
|
const struct config_param *param =
|
2013-10-19 18:48:38 +02:00
|
|
|
decoder_plugin_config(plugin.name);
|
2009-02-15 18:33:28 +01:00
|
|
|
|
2013-08-04 11:30:26 +02:00
|
|
|
if (param == nullptr)
|
|
|
|
param = ∅
|
|
|
|
else if (!param->GetBlockValue("enabled", true))
|
2009-02-15 18:40:47 +01:00
|
|
|
/* the plugin is disabled in mpd.conf */
|
|
|
|
continue;
|
|
|
|
|
2013-10-21 20:36:34 +02:00
|
|
|
if (plugin.Init(*param))
|
2008-11-01 14:53:30 +01:00
|
|
|
decoder_plugins_enabled[i] = true;
|
|
|
|
}
|
2004-05-30 22:25:08 +02:00
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
void decoder_plugin_deinit_all(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2013-10-21 22:02:19 +02:00
|
|
|
decoder_plugins_for_each_enabled([=](const DecoderPlugin &plugin){
|
|
|
|
plugin.Finish();
|
|
|
|
});
|
2004-05-30 22:25:08 +02:00
|
|
|
}
|