DecoderList.hxx 2.51 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2013 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 21
#ifndef MPD_DECODER_LIST_HXX
#define MPD_DECODER_LIST_HXX
22

23
struct DecoderPlugin;
Warren Dukes's avatar
Warren Dukes committed
24

25
extern const struct DecoderPlugin *const decoder_plugins[];
26 27
extern bool decoder_plugins_enabled[];

Warren Dukes's avatar
Warren Dukes committed
28 29
/* interface for using plugins */

30 31 32 33
/**
 * Find the next enabled decoder plugin which supports the specified suffix.
 *
 * @param suffix the file name suffix
34 35
 * @param plugin the previous plugin, or nullptr to find the first plugin
 * @return a plugin, or nullptr if none matches
36
 */
37
const struct DecoderPlugin *
38
decoder_plugin_from_suffix(const char *suffix,
39
			   const struct DecoderPlugin *plugin);
Warren Dukes's avatar
Warren Dukes committed
40

41
const struct DecoderPlugin *
42
decoder_plugin_from_mime_type(const char *mimeType, unsigned int next);
Warren Dukes's avatar
Warren Dukes committed
43

44
const struct DecoderPlugin *
45
decoder_plugin_from_name(const char *name);
Warren Dukes's avatar
Warren Dukes committed
46

Warren Dukes's avatar
Warren Dukes committed
47
/* this is where we "load" all the "plugins" ;-) */
48
void decoder_plugin_init_all(void);
Warren Dukes's avatar
Warren Dukes committed
49 50

/* this is where we "unload" all the "plugins" */
51
void decoder_plugin_deinit_all(void);
Warren Dukes's avatar
Warren Dukes committed
52

53 54 55 56 57 58 59 60 61 62 63
template<typename F>
static inline const DecoderPlugin *
decoder_plugins_find(F f)
{
	for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i)
		if (decoder_plugins_enabled[i] && f(*decoder_plugins[i]))
			return decoder_plugins[i];

	return nullptr;
}

64 65 66 67 68 69 70 71 72 73 74
template<typename F>
static inline bool
decoder_plugins_try(F f)
{
	for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i)
		if (decoder_plugins_enabled[i] && f(*decoder_plugins[i]))
			return true;

	return false;
}

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
template<typename F>
static inline void
decoder_plugins_for_each(F f)
{
	for (auto i = decoder_plugins; *i != nullptr; ++i)
		f(**i);
}

template<typename F>
static inline void
decoder_plugins_for_each_enabled(F f)
{
	for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i)
		if (decoder_plugins_enabled[i])
			f(*decoder_plugins[i]);
}

Warren Dukes's avatar
Warren Dukes committed
92
#endif