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
|
|
|
|
*/
|
|
|
|
|
2004-05-30 22:25:08 +02:00
|
|
|
#include "inputPlugin.h"
|
2008-08-26 08:27:08 +02:00
|
|
|
#include "decoder_api.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;
|
|
|
|
|
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:08 +02:00
|
|
|
void loadInputPlugin(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
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (inputPlugin->initFunc && inputPlugin->initFunc() < 0)
|
|
|
|
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:08 +02:00
|
|
|
void unloadInputPlugin(struct decoder_plugin * inputPlugin)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
if (inputPlugin->finishFunc)
|
|
|
|
inputPlugin->finishFunc();
|
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:08 +02:00
|
|
|
struct decoder_plugin *getInputPluginFromSuffix(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:08 +02:00
|
|
|
struct decoder_plugin *getInputPluginFromMimeType(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;
|
2006-07-20 18:02:40 +02:00
|
|
|
if (stringFoundInStringArray(plugin->mimeTypes, 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:08 +02:00
|
|
|
struct decoder_plugin *getInputPluginFromName(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
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void printAllInputPluginSuffixes(FILE * fp)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void initInputPlugins(void)
|
|
|
|
{
|
2004-11-11 03:59:16 +01:00
|
|
|
inputPlugin_list = makeList(NULL, 1);
|
2004-05-30 22:25:08 +02:00
|
|
|
|
|
|
|
/* load plugins here */
|
2004-05-31 03:21:17 +02:00
|
|
|
loadInputPlugin(&mp3Plugin);
|
2006-03-16 07:52:46 +01:00
|
|
|
loadInputPlugin(&oggvorbisPlugin);
|
|
|
|
loadInputPlugin(&oggflacPlugin);
|
2004-05-31 03:54:10 +02:00
|
|
|
loadInputPlugin(&flacPlugin);
|
2004-05-31 04:31:55 +02:00
|
|
|
loadInputPlugin(&audiofilePlugin);
|
2004-05-31 04:42:22 +02:00
|
|
|
loadInputPlugin(&mp4Plugin);
|
2007-06-04 20:54:46 +02:00
|
|
|
loadInputPlugin(&aacPlugin);
|
2005-02-01 04:20:16 +01:00
|
|
|
loadInputPlugin(&mpcPlugin);
|
2007-06-24 22:40:04 +02:00
|
|
|
loadInputPlugin(&wavpackPlugin);
|
2004-05-31 22:59:55 +02:00
|
|
|
loadInputPlugin(&modPlugin);
|
2004-05-30 22:25:08 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void finishInputPlugins(void)
|
|
|
|
{
|
2004-05-30 22:25:08 +02:00
|
|
|
freeList(inputPlugin_list);
|
|
|
|
}
|