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"
|
2008-08-26 08:27:08 +02:00
|
|
|
#include "decoder_api.h"
|
2008-08-26 08:41:05 +02:00
|
|
|
#include "list.h"
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2008-08-26 08:27:08 +02:00
|
|
|
extern struct decoder_plugin mp3Plugin;
|
|
|
|
extern struct decoder_plugin oggvorbisPlugin;
|
|
|
|
extern struct decoder_plugin flacPlugin;
|
|
|
|
extern struct decoder_plugin oggflacPlugin;
|
|
|
|
extern struct decoder_plugin audiofilePlugin;
|
|
|
|
extern struct decoder_plugin mp4Plugin;
|
|
|
|
extern struct decoder_plugin aacPlugin;
|
|
|
|
extern struct decoder_plugin mpcPlugin;
|
|
|
|
extern struct decoder_plugin wavpackPlugin;
|
|
|
|
extern struct decoder_plugin modPlugin;
|
2008-10-17 22:27:33 +02:00
|
|
|
extern struct decoder_plugin ffmpegPlugin;
|
2008-08-26 08:27:08 +02:00
|
|
|
|
2007-01-14 04:07:53 +01:00
|
|
|
static List *inputPlugin_list;
|
2004-05-30 21:13:57 +02:00
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
void decoder_plugin_load(struct decoder_plugin * inputPlugin)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
if (!inputPlugin)
|
|
|
|
return;
|
|
|
|
if (!inputPlugin->name)
|
|
|
|
return;
|
2004-05-31 03:21:17 +02:00
|
|
|
|
2008-10-30 08:38:54 +01:00
|
|
|
if (inputPlugin->init != NULL && !inputPlugin->init())
|
2006-07-20 18:02:40 +02:00
|
|
|
return;
|
2004-05-31 22:59:55 +02:00
|
|
|
|
2004-05-30 22:25:08 +02:00
|
|
|
insertInList(inputPlugin_list, inputPlugin->name, (void *)inputPlugin);
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
void decoder_plugin_unload(struct decoder_plugin * inputPlugin)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-29 15:54:27 +02:00
|
|
|
if (inputPlugin->finish != NULL)
|
|
|
|
inputPlugin->finish();
|
2004-05-30 22:25:08 +02:00
|
|
|
deleteFromList(inputPlugin_list, inputPlugin->name);
|
|
|
|
}
|
|
|
|
|
2008-02-05 11:17:33 +01:00
|
|
|
static int stringFoundInStringArray(const char *const*array, const char *suffix)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
while (array && *array) {
|
|
|
|
if (strcasecmp(*array, suffix) == 0)
|
|
|
|
return 1;
|
2004-05-30 22:25:08 +02:00
|
|
|
array++;
|
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2004-05-30 22:25:08 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
struct decoder_plugin *decoder_plugin_from_suffix(const char *suffix,
|
|
|
|
unsigned int next)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2007-01-14 04:07:53 +01:00
|
|
|
static ListNode *pos;
|
2006-07-20 18:02:40 +02:00
|
|
|
ListNode *node;
|
2008-08-26 08:27:08 +02:00
|
|
|
struct decoder_plugin *plugin;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
if (suffix == NULL)
|
|
|
|
return NULL;
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2006-03-16 07:52:46 +01:00
|
|
|
if (next) {
|
2006-07-20 18:02:40 +02:00
|
|
|
if (pos)
|
|
|
|
node = pos;
|
|
|
|
else
|
|
|
|
return NULL;
|
2006-03-16 07:52:46 +01:00
|
|
|
} else
|
|
|
|
node = inputPlugin_list->firstNode;
|
2004-05-31 03:21:17 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
while (node != NULL) {
|
2004-05-30 22:25:08 +02:00
|
|
|
plugin = node->data;
|
2006-07-20 18:02:40 +02:00
|
|
|
if (stringFoundInStringArray(plugin->suffixes, suffix)) {
|
2006-03-16 07:52:46 +01:00
|
|
|
pos = node->nextNode;
|
2004-05-30 22:25:08 +02:00
|
|
|
return plugin;
|
|
|
|
}
|
2004-05-31 03:21:17 +02:00
|
|
|
node = node->nextNode;
|
2004-05-30 22:25:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
struct decoder_plugin *decoder_plugin_from_mime_type(const char *mimeType,
|
|
|
|
unsigned int next)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2007-01-14 04:07:53 +01:00
|
|
|
static ListNode *pos;
|
2006-07-20 18:02:40 +02:00
|
|
|
ListNode *node;
|
2008-08-26 08:27:08 +02:00
|
|
|
struct decoder_plugin *plugin;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
if (mimeType == NULL)
|
|
|
|
return NULL;
|
2004-05-30 22:25:08 +02:00
|
|
|
|
2006-03-16 07:52:46 +01:00
|
|
|
node = (next && pos) ? pos : inputPlugin_list->firstNode;
|
2004-06-01 03:11:44 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
while (node != NULL) {
|
2004-05-30 22:25:08 +02:00
|
|
|
plugin = node->data;
|
2008-08-26 08:27:08 +02:00
|
|
|
if (stringFoundInStringArray(plugin->mime_types, mimeType)) {
|
2006-03-16 07:52:46 +01:00
|
|
|
pos = node->nextNode;
|
2004-05-30 22:25:08 +02:00
|
|
|
return plugin;
|
|
|
|
}
|
2004-05-31 03:21:17 +02:00
|
|
|
node = node->nextNode;
|
2004-05-30 22:25:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
struct decoder_plugin *decoder_plugin_from_name(const char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
void *plugin = NULL;
|
2004-05-30 22:25:08 +02:00
|
|
|
|
|
|
|
findInList(inputPlugin_list, name, &plugin);
|
|
|
|
|
2008-08-26 08:27:08 +02:00
|
|
|
return (struct decoder_plugin *) plugin;
|
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
|
|
|
{
|
|
|
|
ListNode *node = inputPlugin_list->firstNode;
|
2008-08-26 08:27:08 +02:00
|
|
|
struct decoder_plugin *plugin;
|
2008-02-05 11:17:33 +01:00
|
|
|
const char *const*suffixes;
|
2004-06-01 06:29:34 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
while (node) {
|
2008-08-26 08:27:08 +02:00
|
|
|
plugin = (struct decoder_plugin *) node->data;
|
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++;
|
|
|
|
}
|
|
|
|
node = node->nextNode;
|
|
|
|
}
|
2006-07-31 01:32:39 +02:00
|
|
|
fprintf(fp, "\n");
|
|
|
|
fflush(fp);
|
2004-06-01 06:29:34 +02:00
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
void decoder_plugin_init_all(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2004-11-11 03:59:16 +01:00
|
|
|
inputPlugin_list = makeList(NULL, 1);
|
2004-05-30 22:25:08 +02:00
|
|
|
|
|
|
|
/* load plugins here */
|
2008-10-17 21:57:09 +02:00
|
|
|
#ifdef HAVE_MAD
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_load(&mp3Plugin);
|
2008-10-17 21:57:09 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_OGGVORBIS
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_load(&oggvorbisPlugin);
|
2008-10-17 21:57:09 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FLAC_COMMON
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_load(&oggflacPlugin);
|
2008-10-17 21:57:09 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FLAC
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_load(&flacPlugin);
|
2008-10-17 21:57:09 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_AUDIOFILE
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_load(&audiofilePlugin);
|
2008-10-17 21:57:09 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FAAD
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_load(&mp4Plugin);
|
|
|
|
decoder_plugin_load(&aacPlugin);
|
2008-10-17 21:57:09 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_MPCDEC
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_load(&mpcPlugin);
|
2008-10-17 21:57:09 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WAVPACK
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_load(&wavpackPlugin);
|
2008-10-17 21:57:09 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_MIKMOD
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_load(&modPlugin);
|
2008-10-17 21:57:09 +02:00
|
|
|
#endif
|
2008-10-17 22:27:33 +02:00
|
|
|
#ifdef HAVE_FFMPEG
|
|
|
|
decoder_plugin_load(&ffmpegPlugin);
|
|
|
|
#endif
|
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
|
|
|
{
|
2004-05-30 22:25:08 +02:00
|
|
|
freeList(inputPlugin_list);
|
|
|
|
}
|