DecoderList.cxx 4.22 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 "config/ConfigGlobal.hxx"
#include "config/ConfigData.hxx"
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include "plugins/AudiofileDecoderPlugin.hxx"
#include "plugins/PcmDecoderPlugin.hxx"
#include "plugins/DsdiffDecoderPlugin.hxx"
#include "plugins/DsfDecoderPlugin.hxx"
#include "plugins/FlacDecoderPlugin.h"
#include "plugins/OpusDecoderPlugin.h"
#include "plugins/VorbisDecoderPlugin.h"
#include "plugins/AdPlugDecoderPlugin.h"
#include "plugins/WavpackDecoderPlugin.hxx"
#include "plugins/FfmpegDecoderPlugin.hxx"
#include "plugins/GmeDecoderPlugin.hxx"
#include "plugins/FaadDecoderPlugin.hxx"
#include "plugins/MadDecoderPlugin.hxx"
#include "plugins/SndfileDecoderPlugin.hxx"
#include "plugins/Mpg123DecoderPlugin.hxx"
40
#include "plugins/Mp4v2DecoderPlugin.hxx"
41 42 43 44 45 46
#include "plugins/WildmidiDecoderPlugin.hxx"
#include "plugins/MikmodDecoderPlugin.hxx"
#include "plugins/ModplugDecoderPlugin.hxx"
#include "plugins/MpcdecDecoderPlugin.hxx"
#include "plugins/FluidsynthDecoderPlugin.hxx"
#include "plugins/SidplayDecoderPlugin.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 59 60
#ifdef HAVE_MP4V2
	&mp4v2_decoder_plugin,
#endif
61
#ifdef ENABLE_VORBIS_DECODER
Max Kellermann's avatar
Max Kellermann committed
62
	&vorbis_decoder_plugin,
63
#endif
64
#if defined(HAVE_FLAC)
Max Kellermann's avatar
Max Kellermann committed
65
	&oggflac_decoder_plugin,
66 67
#endif
#ifdef HAVE_FLAC
Max Kellermann's avatar
Max Kellermann committed
68
	&flac_decoder_plugin,
69
#endif
70 71 72
#ifdef HAVE_OPUS
	&opus_decoder_plugin,
#endif
73 74 75
#ifdef ENABLE_SNDFILE
	&sndfile_decoder_plugin,
#endif
76
#ifdef HAVE_AUDIOFILE
77
	&audiofile_decoder_plugin,
78
#endif
79
	&dsdiff_decoder_plugin,
80
	&dsf_decoder_plugin,
81
#ifdef HAVE_FAAD
82
	&faad_decoder_plugin,
83 84
#endif
#ifdef HAVE_MPCDEC
85
	&mpcdec_decoder_plugin,
86 87
#endif
#ifdef HAVE_WAVPACK
88
	&wavpack_decoder_plugin,
89
#endif
90
#ifdef HAVE_MODPLUG
91
	&modplug_decoder_plugin,
92
#endif
93
#ifdef ENABLE_MIKMOD_DECODER
94
	&mikmod_decoder_plugin,
95
#endif
96 97 98
#ifdef ENABLE_SIDPLAY
	&sidplay_decoder_plugin,
#endif
99 100 101
#ifdef ENABLE_WILDMIDI
	&wildmidi_decoder_plugin,
#endif
102 103 104
#ifdef ENABLE_FLUIDSYNTH
	&fluidsynth_decoder_plugin,
#endif
105 106 107
#ifdef HAVE_ADPLUG
	&adplug_decoder_plugin,
#endif
108
#ifdef HAVE_FFMPEG
109
	&ffmpeg_decoder_plugin,
110 111 112
#endif
#ifdef HAVE_GME
	&gme_decoder_plugin,
113
#endif
114
	&pcm_decoder_plugin,
115
	nullptr
116
};
117

118 119
static constexpr unsigned num_decoder_plugins =
	ARRAY_SIZE(decoder_plugins) - 1;
120

121
/** which plugins have been initialized successfully? */
122
bool decoder_plugins_enabled[num_decoder_plugins];
123

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

132
void decoder_plugin_init_all(void)
Avuton Olrich's avatar
Avuton Olrich committed
133
{
134 135
	struct config_param empty;

136
	for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i) {
137
		const DecoderPlugin &plugin = *decoder_plugins[i];
138
		const struct config_param *param =
139
			config_find_block(CONF_DECODER, "plugin", plugin.name);
140

141 142 143
		if (param == nullptr)
			param = &empty;
		else if (!param->GetBlockValue("enabled", true))
144 145 146
			/* the plugin is disabled in mpd.conf */
			continue;

147
		if (plugin.Init(*param))
148 149
			decoder_plugins_enabled[i] = true;
	}
150 151
}

152
void decoder_plugin_deinit_all(void)
Avuton Olrich's avatar
Avuton Olrich committed
153
{
154 155 156
	decoder_plugins_for_each_enabled([=](const DecoderPlugin &plugin){
			plugin.Finish();
		});
157
}
158 159 160 161 162 163 164 165

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