summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am6
-rw-r--r--src/inputPlugin.c94
-rw-r--r--src/inputPlugin.h16
3 files changed, 96 insertions, 20 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 9cfcf6647..5f783e6ac 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,14 +6,16 @@ mpd_headers = buffer2array.h interface.h command.h playlist.h ls.h \
audio.h playerData.h stats.h myfprintf.h sig_handlers.h decode.h log.h \
audiofile_decode.h charConv.h permission.h mpd_types.h pcm_utils.h \
mp4_decode.h aac_decode.h signal_check.h utf8.h inputStream.h \
- outputBuffer.h replayGain.h inputStream_file.h inputStream_http.h
+ outputBuffer.h replayGain.h inputStream_file.h inputStream_http.h \
+ inputPlugin.h
mpd_SOURCES = main.c buffer2array.c interface.c command.c playlist.c ls.c \
song.c list.c directory.c tables.c utils.c path.c mp3_decode.c \
tag.c player.c listen.c conf.c ogg_decode.c volume.c flac_decode.c \
audio.c playerData.c stats.c myfprintf.c sig_handlers.c decode.c log.c \
audiofile_decode.c charConv.c permission.c pcm_utils.c mp4_decode.c \
aac_decode.c signal_check.c utf8.c inputStream.c outputBuffer.c \
- replayGain.c inputStream_file.c inputStream_http.c $(mpd_headers)
+ replayGain.c inputStream_file.c inputStream_http.c inputPlugin.c \
+ $(mpd_headers)
mpd_CFLAGS = $(MPD_CFLAGS)
mpd_LDADD = $(MPD_LIBS) $(ID3_LIB) $(MAD_LIB) $(MP4FF_LIB)
diff --git a/src/inputPlugin.c b/src/inputPlugin.c
index e22b27718..2afe17719 100644
--- a/src/inputPlugin.c
+++ b/src/inputPlugin.c
@@ -1,19 +1,29 @@
-#include "input_plugin.h"
+#include "inputPlugin.h"
+
+#include "list.h"
#include <stdlib.h>
+#include <string.h>
+
+static List * inputPlugin_list = NULL;
-InputPlugin * newInputPlugin() {
+InputPlugin * newInputPlugin(char * name, InputPlugin_streamDecodeFunc
+ streamDecodeFunc, InputPlugin_fileDecodeFunc fileDecodeFunc,
+ InputPlugin_tagDupFunc tagDupFunc, unsigned char streamTypes)
+{
InputPlugin * ret = malloc(sizeof(InputPlugin));
memset(ret->name,0,INPUT_PLUGIN_NAME_LENGTH);
+ strncpy(ret->name, name, INPUT_PLUGIN_NAME_LENGTH-1);
ret->suffixes = NULL;
ret->mimeTypes = NULL;
- ret->streamTypes = 0;
- ret->streamDecodeFunc = NULL;
- ret->fileDeocdeFunc = NULL;
- ret->tagDupFunc = NULL;
+ ret->streamTypes = streamTypes;
+
+ ret->streamDecodeFunc = streamDecodeFunc;
+ ret->fileDecodeFunc = fileDecodeFunc;
+ ret->tagDupFunc = tagDupFunc;
return ret;
}
@@ -32,8 +42,6 @@ static void freeStringArray(char ** ptr) {
}
void freeInputPlugin(InputPlugin * inPlugin) {
- char * temp;
-
freeStringArray(inPlugin->suffixes);
freeStringArray(inPlugin->mimeTypes);
@@ -45,15 +53,16 @@ static char ** AddStringToArray(char ** array, char * string) {
if(array) {
char ** tmp = array;
- while(*array) {
+ while(*tmp) {
arraySize++;
- array++;
+ tmp++;
}
}
- array = realloc(array, arraySize*sizeof(char *));
+ array = realloc(array, (arraySize+1)*sizeof(char *));
array[arraySize-1] = strdup(string);
+ array[arraySize] = NULL;
return array;
}
@@ -65,3 +74,66 @@ void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix) {
void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * mimeType) {
inPlugin->mimeTypes = AddStringToArray(inPlugin->mimeTypes, mimeType);
}
+
+void loadInputPlugin(InputPlugin * inputPlugin) {
+ insertInList(inputPlugin_list, inputPlugin->name, (void *)inputPlugin);
+}
+
+void unloadInputPlugin(InputPlugin * inputPlugin) {
+ deleteFromList(inputPlugin_list, inputPlugin->name);
+}
+
+static int stringFoundInStringArray(char ** array, char * suffix) {
+ while(array && *array) {
+ if(strcmp(*array, suffix) == 0) return 1;
+ array++;
+ }
+
+ return 0;
+}
+
+InputPlugin * getInputPluginFromSuffix(char * suffix) {
+ ListNode * node = inputPlugin_list->firstNode;
+ InputPlugin * plugin = NULL;
+
+ while(node != NULL) {
+ plugin = node->data;
+ if(stringFoundInStringArray(plugin->suffixes, suffix)) {
+ return plugin;
+ }
+ }
+
+ return NULL;
+}
+
+InputPlugin * getInputPluginFromMimeType(char * mimeType) {
+ ListNode * node = inputPlugin_list->firstNode;
+ InputPlugin * plugin = NULL;
+
+ while(node != NULL) {
+ plugin = node->data;
+ if(stringFoundInStringArray(plugin->mimeTypes, mimeType)) {
+ return plugin;
+ }
+ }
+
+ return NULL;
+}
+
+InputPlugin * getInputPluginFromName(char * name) {
+ void * plugin = NULL;
+
+ findInList(inputPlugin_list, name, &plugin);
+
+ return (InputPlugin *)plugin;
+}
+
+void initInputPlugins() {
+ inputPlugin_list = makeList((ListFreeDataFunc *)freeInputPlugin);
+
+ /* load plugins here */
+}
+
+void finishInputPlugins() {
+ freeList(inputPlugin_list);
+}
diff --git a/src/inputPlugin.h b/src/inputPlugin.h
index a84e54944..9f57037fb 100644
--- a/src/inputPlugin.h
+++ b/src/inputPlugin.h
@@ -28,16 +28,20 @@ typedef struct _InputPlugin {
char ** mimeTypes;
} InputPlugin;
-/* interface for adding and removing plugins */
-
-InputPlugin * newInputPlugin();
+/* interface for constructing a plugin */
+InputPlugin * newInputPlugin(char * name, InputPlugin_streamDecodeFunc
+ streamDecodeFunc, InputPlugin_fileDecodeFunc fileDecodeFunc,
+ InputPlugin_tagDupFunc tagDupFunc, unsigned char streamTypes);
void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix);
-
void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * suffix);
-
void freeInputPlugin(InputPlugin * inputPlugin);
+/* individual functions to load/unload plugins */
+void loadInputPlugin(InputPlugin * inputPlugin);
+/* this free's inputPlugin as well! */
+void unloadInputPlugin(InputPlugin * inputPlugin);
+
/* interface for using plugins */
InputPlugin * getInputPluginFromSuffix(char * suffix);
@@ -56,6 +60,4 @@ void initInputPlugins();
/* this is where we "unload" all the "plugins" */
void finishInputPlugins();
-void unloadInputPlugin(InputPlugin * inputPlugin);
-
#endif