From 8e137ddf8184f6eb8e5655b9323e47b2a8f2eef9 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Sun, 30 May 2004 19:13:57 +0000 Subject: start to implement inputPlugin interface git-svn-id: https://svn.musicpd.org/mpd/trunk@1242 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/inputPlugin.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/inputPlugin.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ src/input_plugin.h | 61 ------------------------------------------------- 3 files changed, 128 insertions(+), 61 deletions(-) create mode 100644 src/inputPlugin.c create mode 100644 src/inputPlugin.h delete mode 100644 src/input_plugin.h (limited to 'src') diff --git a/src/inputPlugin.c b/src/inputPlugin.c new file mode 100644 index 000000000..e22b27718 --- /dev/null +++ b/src/inputPlugin.c @@ -0,0 +1,67 @@ +#include "input_plugin.h" + +#include + +InputPlugin * newInputPlugin() { + InputPlugin * ret = malloc(sizeof(InputPlugin)); + + memset(ret->name,0,INPUT_PLUGIN_NAME_LENGTH); + + ret->suffixes = NULL; + ret->mimeTypes = NULL; + ret->streamTypes = 0; + + ret->streamDecodeFunc = NULL; + ret->fileDeocdeFunc = NULL; + ret->tagDupFunc = NULL; + + return ret; +} + +static void freeStringArray(char ** ptr) { + if(ptr) { + char ** tmp = ptr; + + while(*tmp) { + if(*tmp) free(*tmp); + tmp++; + } + + free (ptr); + } +} + +void freeInputPlugin(InputPlugin * inPlugin) { + char * temp; + + freeStringArray(inPlugin->suffixes); + freeStringArray(inPlugin->mimeTypes); + + free(inPlugin); +} + +static char ** AddStringToArray(char ** array, char * string) { + int arraySize = 1; + + if(array) { + char ** tmp = array; + while(*array) { + arraySize++; + array++; + } + } + + array = realloc(array, arraySize*sizeof(char *)); + + array[arraySize-1] = strdup(string); + + return array; +} + +void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix) { + inPlugin->suffixes = AddStringToArray(inPlugin->suffixes, suffix); +} + +void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * mimeType) { + inPlugin->mimeTypes = AddStringToArray(inPlugin->mimeTypes, mimeType); +} diff --git a/src/inputPlugin.h b/src/inputPlugin.h new file mode 100644 index 000000000..a84e54944 --- /dev/null +++ b/src/inputPlugin.h @@ -0,0 +1,61 @@ +#ifndef INPUT_PLUGIN_H +#define INPUT_PLUGIN_H + +#include "inputStream.h" +#include "decode.h" +#include "outputBuffer.h" +#include "tag.h" + +#define INPUT_PLUGIN_STREAM_FILE 0x01 +#define INPUT_PLUGIN_STREAM_URL 0x02 + +#define INPUT_PLUGIN_NAME_LENGTH 64 + +typedef int (* InputPlugin_streamDecodeFunc) (OutputBuffer *, DecoderControl *, + InputStream *); + +typedef int (* InputPlugin_fileDecodeFunc) (OutputBuffer *, DecoderControl *); + +typedef MpdTag * (* InputPlugin_tagDupFunc) (char * utf8file); + +typedef struct _InputPlugin { + char name[INPUT_PLUGIN_NAME_LENGTH]; + InputPlugin_streamDecodeFunc streamDecodeFunc; + InputPlugin_fileDecodeFunc fileDecodeFunc; + InputPlugin_tagDupFunc tagDupFunc; + unsigned char streamTypes; + char ** suffixes; + char ** mimeTypes; +} InputPlugin; + +/* interface for adding and removing plugins */ + +InputPlugin * newInputPlugin(); + +void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix); + +void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * suffix); + +void freeInputPlugin(InputPlugin * inputPlugin); + +/* interface for using plugins */ + +InputPlugin * getInputPluginFromSuffix(char * suffix); + +InputPlugin * getInputPluginFromMimeTypes(char * mimeType); + +InputPlugin * getInputPluginFromName(char * name); + +/* this is needed b/c shoutcast and such don't indicate the proper mime type + and don't have a suffix in the url! */ +InputPlugin * getDefaultInputPlugin(); + +/* this is where we "load" all the "plugins" ;-) */ +void initInputPlugins(); + +/* this is where we "unload" all the "plugins" */ +void finishInputPlugins(); + +void unloadInputPlugin(InputPlugin * inputPlugin); + +#endif diff --git a/src/input_plugin.h b/src/input_plugin.h deleted file mode 100644 index a84e54944..000000000 --- a/src/input_plugin.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef INPUT_PLUGIN_H -#define INPUT_PLUGIN_H - -#include "inputStream.h" -#include "decode.h" -#include "outputBuffer.h" -#include "tag.h" - -#define INPUT_PLUGIN_STREAM_FILE 0x01 -#define INPUT_PLUGIN_STREAM_URL 0x02 - -#define INPUT_PLUGIN_NAME_LENGTH 64 - -typedef int (* InputPlugin_streamDecodeFunc) (OutputBuffer *, DecoderControl *, - InputStream *); - -typedef int (* InputPlugin_fileDecodeFunc) (OutputBuffer *, DecoderControl *); - -typedef MpdTag * (* InputPlugin_tagDupFunc) (char * utf8file); - -typedef struct _InputPlugin { - char name[INPUT_PLUGIN_NAME_LENGTH]; - InputPlugin_streamDecodeFunc streamDecodeFunc; - InputPlugin_fileDecodeFunc fileDecodeFunc; - InputPlugin_tagDupFunc tagDupFunc; - unsigned char streamTypes; - char ** suffixes; - char ** mimeTypes; -} InputPlugin; - -/* interface for adding and removing plugins */ - -InputPlugin * newInputPlugin(); - -void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix); - -void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * suffix); - -void freeInputPlugin(InputPlugin * inputPlugin); - -/* interface for using plugins */ - -InputPlugin * getInputPluginFromSuffix(char * suffix); - -InputPlugin * getInputPluginFromMimeTypes(char * mimeType); - -InputPlugin * getInputPluginFromName(char * name); - -/* this is needed b/c shoutcast and such don't indicate the proper mime type - and don't have a suffix in the url! */ -InputPlugin * getDefaultInputPlugin(); - -/* this is where we "load" all the "plugins" ;-) */ -void initInputPlugins(); - -/* this is where we "unload" all the "plugins" */ -void finishInputPlugins(); - -void unloadInputPlugin(InputPlugin * inputPlugin); - -#endif -- cgit v1.2.3