DecoderList.cxx 4.77 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2014 The Music Player Daemon Project
3
 * http://www.musicpd.org
Warren Dukes's avatar
Warren Dukes committed
4 5 6 7 8 9 10 11 12 13
 *
 * 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.
14 15 16 17
 *
 * 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.
Warren Dukes's avatar
Warren Dukes committed
18 19
 */

20
#include "config.h"
21
#include "DecoderList.hxx"
22
#include "DecoderPlugin.hxx"
23 24
#include "ConfigGlobal.hxx"
#include "ConfigData.hxx"
25
#include "decoder/AudiofileDecoderPlugin.hxx"
26
#include "decoder/PcmDecoderPlugin.hxx"
27 28
#include "decoder/DsdiffDecoderPlugin.hxx"
#include "decoder/DsfDecoderPlugin.hxx"
29
#include "decoder/FlacDecoderPlugin.h"
30
#include "decoder/OpusDecoderPlugin.h"
31
#include "decoder/VorbisDecoderPlugin.h"
32
#include "decoder/AdPlugDecoderPlugin.h"
33
#include "decoder/WavpackDecoderPlugin.hxx"
34
#include "decoder/FfmpegDecoderPlugin.hxx"
35
#include "decoder/GmeDecoderPlugin.hxx"
36
#include "decoder/FaadDecoderPlugin.hxx"
37
#include "decoder/MadDecoderPlugin.hxx"
38
#include "decoder/SndfileDecoderPlugin.hxx"
39
#include "decoder/Mpg123DecoderPlugin.hxx"
40
#include "decoder/WildmidiDecoderPlugin.hxx"
41
#include "decoder/MikmodDecoderPlugin.hxx"
42
#include "decoder/ModplugDecoderPlugin.hxx"
43
#include "decoder/MpcdecDecoderPlugin.hxx"
44
#include "decoder/FluidsynthDecoderPlugin.hxx"
45
#include "decoder/SidplayDecoderPlugin.hxx"
46
#include "system/FatalError.hxx"
47
#include "util/Macros.hxx"
48

49 50
#include <string.h>

51
const struct DecoderPlugin *const decoder_plugins[] = {
52
#ifdef HAVE_MAD
53
	&mad_decoder_plugin,
54
#endif
55 56 57
#ifdef HAVE_MPG123
	&mpg123_decoder_plugin,
#endif
58
#ifdef ENABLE_VORBIS_DECODER
Max Kellermann's avatar
Max Kellermann committed
59
	&vorbis_decoder_plugin,
60
#endif
61
#if defined(HAVE_FLAC)
Max Kellermann's avatar
Max Kellermann committed
62
	&oggflac_decoder_plugin,
63 64
#endif
#ifdef HAVE_FLAC
Max Kellermann's avatar
Max Kellermann committed
65
	&flac_decoder_plugin,
66
#endif
67 68 69
#ifdef HAVE_OPUS
	&opus_decoder_plugin,
#endif
70 71 72
#ifdef ENABLE_SNDFILE
	&sndfile_decoder_plugin,
#endif
73
#ifdef HAVE_AUDIOFILE
74
	&audiofile_decoder_plugin,
75
#endif
76
	&dsdiff_decoder_plugin,
77
	&dsf_decoder_plugin,
78
#ifdef HAVE_FAAD
79
	&faad_decoder_plugin,
80 81
#endif
#ifdef HAVE_MPCDEC
82
	&mpcdec_decoder_plugin,
83 84
#endif
#ifdef HAVE_WAVPACK
85
	&wavpack_decoder_plugin,
86
#endif
87
#ifdef HAVE_MODPLUG
88
	&modplug_decoder_plugin,
89
#endif
90
#ifdef ENABLE_MIKMOD_DECODER
91
	&mikmod_decoder_plugin,
92
#endif
93 94 95
#ifdef ENABLE_SIDPLAY
	&sidplay_decoder_plugin,
#endif
96 97 98
#ifdef ENABLE_WILDMIDI
	&wildmidi_decoder_plugin,
#endif
99 100 101
#ifdef ENABLE_FLUIDSYNTH
	&fluidsynth_decoder_plugin,
#endif
102 103 104
#ifdef HAVE_ADPLUG
	&adplug_decoder_plugin,
#endif
105
#ifdef HAVE_FFMPEG
106
	&ffmpeg_decoder_plugin,
107 108 109
#endif
#ifdef HAVE_GME
	&gme_decoder_plugin,
110
#endif
111
	&pcm_decoder_plugin,
112
	nullptr
113
};
114

115 116
static constexpr unsigned num_decoder_plugins =
	ARRAY_SIZE(decoder_plugins) - 1;
117

118
/** which plugins have been initialized successfully? */
119
bool decoder_plugins_enabled[num_decoder_plugins];
120

121
const struct DecoderPlugin *
122
decoder_plugin_from_name(const char *name)
Avuton Olrich's avatar
Avuton Olrich committed
123
{
124
	return decoder_plugins_find([=](const DecoderPlugin &plugin){
125 126
			return strcmp(plugin.name, name) == 0;
		});
127 128
}

129 130 131 132
/**
 * Find the "decoder" configuration block for the specified plugin.
 *
 * @param plugin_name the name of the decoder plugin
133
 * @return the configuration block, or nullptr if none was configured
134 135 136 137
 */
static const struct config_param *
decoder_plugin_config(const char *plugin_name)
{
138
	const struct config_param *param = nullptr;
139

140
	while ((param = config_get_next_param(CONF_DECODER, param)) != nullptr) {
141
		const char *name = param->GetBlockValue("plugin");
142
		if (name == nullptr)
143 144
			FormatFatalError("decoder configuration without 'plugin' name in line %d",
					 param->line);
145 146 147 148 149

		if (strcmp(name, plugin_name) == 0)
			return param;
	}

150
	return nullptr;
151 152
}

153
void decoder_plugin_init_all(void)
Avuton Olrich's avatar
Avuton Olrich committed
154
{
155 156
	struct config_param empty;

157
	for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i) {
158
		const DecoderPlugin &plugin = *decoder_plugins[i];
159
		const struct config_param *param =
160
			decoder_plugin_config(plugin.name);
161

162 163 164
		if (param == nullptr)
			param = &empty;
		else if (!param->GetBlockValue("enabled", true))
165 166 167
			/* the plugin is disabled in mpd.conf */
			continue;

168
		if (plugin.Init(*param))
169 170
			decoder_plugins_enabled[i] = true;
	}
171 172
}

173
void decoder_plugin_deinit_all(void)
Avuton Olrich's avatar
Avuton Olrich committed
174
{
175 176 177
	decoder_plugins_for_each_enabled([=](const DecoderPlugin &plugin){
			plugin.Finish();
		});
178
}
179 180 181 182 183 184 185 186

bool
decoder_plugins_supports_suffix(const char *suffix)
{
	return decoder_plugins_try([suffix](const DecoderPlugin &plugin){
			return plugin.SupportsSuffix(suffix);
		});
}