2004-06-16 23:52:59 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
2004-06-16 23:52:59 +02:00
|
|
|
* This project's homepage is: 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2008-08-26 08:27:08 +02:00
|
|
|
#include "decoder_list.h"
|
2009-02-15 17:48:37 +01:00
|
|
|
#include "decoder_plugin.h"
|
2008-12-09 17:36:10 +01:00
|
|
|
#include "utils.h"
|
2009-01-08 21:37:02 +01:00
|
|
|
#include "config.h"
|
2008-11-01 14:53:30 +01:00
|
|
|
|
|
|
|
#include <glib.h>
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2009-02-15 17:48:37 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-11-01 14:54:09 +01:00
|
|
|
extern const struct decoder_plugin mp3Plugin;
|
2009-01-14 23:09:02 +01:00
|
|
|
extern const struct decoder_plugin vorbis_decoder_plugin;
|
2009-01-15 19:50:28 +01:00
|
|
|
extern const struct decoder_plugin flac_decoder_plugin;
|
|
|
|
extern const struct decoder_plugin oggflac_decoder_plugin;
|
2008-11-01 14:54:09 +01:00
|
|
|
extern const struct decoder_plugin audiofilePlugin;
|
2008-11-04 16:55:12 +01:00
|
|
|
extern const struct decoder_plugin mp4_plugin;
|
2008-11-01 14:54:09 +01:00
|
|
|
extern const struct decoder_plugin aacPlugin;
|
|
|
|
extern const struct decoder_plugin mpcPlugin;
|
2008-11-04 17:08:59 +01:00
|
|
|
extern const struct decoder_plugin wavpack_plugin;
|
2008-12-28 17:11:18 +01:00
|
|
|
extern const struct decoder_plugin modplug_plugin;
|
2009-01-24 20:18:44 +01:00
|
|
|
extern const struct decoder_plugin mikmod_decoder_plugin;
|
2009-02-11 20:31:17 +01:00
|
|
|
extern const struct decoder_plugin sidplay_decoder_plugin;
|
2009-02-12 08:43:26 +01:00
|
|
|
extern const struct decoder_plugin fluidsynth_decoder_plugin;
|
2009-02-12 16:43:18 +01:00
|
|
|
extern const struct decoder_plugin wildmidi_decoder_plugin;
|
2008-11-04 16:55:11 +01:00
|
|
|
extern const struct decoder_plugin ffmpeg_plugin;
|
2008-08-26 08:27:08 +02:00
|
|
|
|
2008-11-01 14:53:30 +01:00
|
|
|
static const struct decoder_plugin *const decoder_plugins[] = {
|
|
|
|
#ifdef HAVE_MAD
|
|
|
|
&mp3Plugin,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_OGGVORBIS
|
2009-01-14 23:09:02 +01:00
|
|
|
&vorbis_decoder_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
2008-11-10 14:37:37 +01:00
|
|
|
#if defined(HAVE_FLAC) || defined(HAVE_OGGFLAC)
|
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
|
|
|
|
#ifdef HAVE_AUDIOFILE
|
|
|
|
&audiofilePlugin,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FAAD
|
|
|
|
&aacPlugin,
|
|
|
|
#endif
|
2008-11-03 16:48:12 +01:00
|
|
|
#ifdef HAVE_MP4
|
2008-11-04 16:55:12 +01:00
|
|
|
&mp4_plugin,
|
2008-11-03 16:48:12 +01:00
|
|
|
#endif
|
2008-11-01 14:53:30 +01:00
|
|
|
#ifdef HAVE_MPCDEC
|
|
|
|
&mpcPlugin,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WAVPACK
|
2008-11-04 17:08:59 +01:00
|
|
|
&wavpack_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
2008-12-28 17:11:18 +01:00
|
|
|
#ifdef HAVE_MODPLUG
|
|
|
|
&modplug_plugin,
|
|
|
|
#endif
|
2008-11-01 14:53:30 +01:00
|
|
|
#ifdef HAVE_MIKMOD
|
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 08:43:26 +01:00
|
|
|
#ifdef ENABLE_FLUIDSYNTH
|
|
|
|
&fluidsynth_decoder_plugin,
|
|
|
|
#endif
|
2009-02-12 16:43:18 +01:00
|
|
|
#ifdef ENABLE_WILDMIDI
|
|
|
|
&wildmidi_decoder_plugin,
|
|
|
|
#endif
|
2008-11-01 14:53:30 +01:00
|
|
|
#ifdef HAVE_FFMPEG
|
2008-11-04 16:55:11 +01:00
|
|
|
&ffmpeg_plugin,
|
2008-11-01 14:53:30 +01:00
|
|
|
#endif
|
|
|
|
};
|
2004-05-31 22:59:55 +02:00
|
|
|
|
2008-11-01 14:53:30 +01:00
|
|
|
enum {
|
|
|
|
num_decoder_plugins = G_N_ELEMENTS(decoder_plugins),
|
|
|
|
};
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2008-11-01 14:53:30 +01:00
|
|
|
/** which plugins have been initialized successfully? */
|
|
|
|
static bool decoder_plugins_enabled[num_decoder_plugins];
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2008-11-01 14:51:41 +01:00
|
|
|
const struct decoder_plugin *
|
|
|
|
decoder_plugin_from_suffix(const char *suffix, 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
|
|
|
|
|
|
|
if (suffix == NULL)
|
|
|
|
return NULL;
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2008-11-01 14:53:30 +01:00
|
|
|
if (!next)
|
|
|
|
i = 0;
|
|
|
|
for (; i < num_decoder_plugins; ++i) {
|
|
|
|
const struct decoder_plugin *plugin = decoder_plugins[i];
|
|
|
|
if (decoder_plugins_enabled[i] &&
|
|
|
|
stringFoundInStringArray(plugin->suffixes, suffix)) {
|
|
|
|
++i;
|
2004-05-30 22:25:08 +02:00
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-11-01 14:51:41 +01:00
|
|
|
const struct decoder_plugin *
|
|
|
|
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
|
|
|
|
|
|
|
if (mimeType == NULL)
|
|
|
|
return NULL;
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2008-11-01 14:53:30 +01:00
|
|
|
if (!next)
|
|
|
|
i = 0;
|
|
|
|
for (; i < num_decoder_plugins; ++i) {
|
|
|
|
const struct decoder_plugin *plugin = decoder_plugins[i];
|
|
|
|
if (decoder_plugins_enabled[i] &&
|
|
|
|
stringFoundInStringArray(plugin->mime_types, mimeType)) {
|
|
|
|
++i;
|
2004-05-30 22:25:08 +02:00
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-11-01 14:51:41 +01:00
|
|
|
const struct decoder_plugin *
|
|
|
|
decoder_plugin_from_name(const char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-11-01 14:53:30 +01:00
|
|
|
for (unsigned i = 0; i < num_decoder_plugins; ++i) {
|
|
|
|
const struct decoder_plugin *plugin = decoder_plugins[i];
|
|
|
|
if (decoder_plugins_enabled[i] &&
|
|
|
|
strcmp(plugin->name, name) == 0)
|
|
|
|
return plugin;
|
|
|
|
}
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2008-11-01 14:53:30 +01:00
|
|
|
return NULL;
|
2004-05-30 22:25:08 +02:00
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
void decoder_plugin_print_all_suffixes(FILE * fp)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-02-05 11:17:33 +01:00
|
|
|
const char *const*suffixes;
|
2004-06-01 06:29:34 +02:00
|
|
|
|
2008-11-01 14:53:30 +01:00
|
|
|
for (unsigned i = 0; i < num_decoder_plugins; ++i) {
|
|
|
|
const struct decoder_plugin *plugin = decoder_plugins[i];
|
|
|
|
if (!decoder_plugins_enabled[i])
|
|
|
|
continue;
|
|
|
|
|
2004-06-01 06:29:34 +02:00
|
|
|
suffixes = plugin->suffixes;
|
2006-07-20 18:02:40 +02:00
|
|
|
while (suffixes && *suffixes) {
|
2006-07-31 01:32:39 +02:00
|
|
|
fprintf(fp, "%s ", *suffixes);
|
2004-06-01 06:29:34 +02:00
|
|
|
suffixes++;
|
|
|
|
}
|
|
|
|
}
|
2006-07-31 01:32:39 +02:00
|
|
|
fprintf(fp, "\n");
|
|
|
|
fflush(fp);
|
2004-06-01 06:29:34 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 14:08:59 +01:00
|
|
|
void decoder_plugin_print_all_decoders(FILE * fp)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < num_decoder_plugins; ++i) {
|
|
|
|
const struct decoder_plugin *plugin = decoder_plugins[i];
|
|
|
|
if (!decoder_plugins_enabled[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fprintf(fp, "%s ", plugin->name);
|
|
|
|
}
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
fflush(fp);
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
void decoder_plugin_init_all(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-11-01 14:53:30 +01:00
|
|
|
for (unsigned i = 0; i < num_decoder_plugins; ++i) {
|
|
|
|
const struct decoder_plugin *plugin = decoder_plugins[i];
|
2009-02-15 18:33:28 +01:00
|
|
|
|
2009-02-15 18:34:14 +01:00
|
|
|
if (decoder_plugin_init(plugin, NULL))
|
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
|
|
|
{
|
2008-11-01 14:53:30 +01:00
|
|
|
for (unsigned i = 0; i < num_decoder_plugins; ++i) {
|
|
|
|
const struct decoder_plugin *plugin = decoder_plugins[i];
|
2009-02-15 18:33:28 +01:00
|
|
|
|
|
|
|
if (decoder_plugins_enabled[i])
|
|
|
|
decoder_plugin_finish(plugin);
|
2008-11-01 14:53:30 +01:00
|
|
|
}
|
2004-05-30 22:25:08 +02:00
|
|
|
}
|