finish implementing inputPlugin interface
git-svn-id: https://svn.musicpd.org/mpd/trunk@1244 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
bd41addd9f
commit
d7893a3e76
|
@ -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 \
|
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 \
|
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 \
|
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 \
|
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 \
|
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 \
|
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 \
|
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 \
|
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 \
|
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_CFLAGS = $(MPD_CFLAGS)
|
||||||
mpd_LDADD = $(MPD_LIBS) $(ID3_LIB) $(MAD_LIB) $(MP4FF_LIB)
|
mpd_LDADD = $(MPD_LIBS) $(ID3_LIB) $(MAD_LIB) $(MP4FF_LIB)
|
||||||
|
|
|
@ -1,19 +1,29 @@
|
||||||
#include "input_plugin.h"
|
#include "inputPlugin.h"
|
||||||
|
|
||||||
|
#include "list.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
InputPlugin * newInputPlugin() {
|
static List * inputPlugin_list = NULL;
|
||||||
|
|
||||||
|
InputPlugin * newInputPlugin(char * name, InputPlugin_streamDecodeFunc
|
||||||
|
streamDecodeFunc, InputPlugin_fileDecodeFunc fileDecodeFunc,
|
||||||
|
InputPlugin_tagDupFunc tagDupFunc, unsigned char streamTypes)
|
||||||
|
{
|
||||||
InputPlugin * ret = malloc(sizeof(InputPlugin));
|
InputPlugin * ret = malloc(sizeof(InputPlugin));
|
||||||
|
|
||||||
memset(ret->name,0,INPUT_PLUGIN_NAME_LENGTH);
|
memset(ret->name,0,INPUT_PLUGIN_NAME_LENGTH);
|
||||||
|
strncpy(ret->name, name, INPUT_PLUGIN_NAME_LENGTH-1);
|
||||||
|
|
||||||
ret->suffixes = NULL;
|
ret->suffixes = NULL;
|
||||||
ret->mimeTypes = NULL;
|
ret->mimeTypes = NULL;
|
||||||
ret->streamTypes = 0;
|
|
||||||
|
|
||||||
ret->streamDecodeFunc = NULL;
|
ret->streamTypes = streamTypes;
|
||||||
ret->fileDeocdeFunc = NULL;
|
|
||||||
ret->tagDupFunc = NULL;
|
ret->streamDecodeFunc = streamDecodeFunc;
|
||||||
|
ret->fileDecodeFunc = fileDecodeFunc;
|
||||||
|
ret->tagDupFunc = tagDupFunc;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -32,8 +42,6 @@ static void freeStringArray(char ** ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeInputPlugin(InputPlugin * inPlugin) {
|
void freeInputPlugin(InputPlugin * inPlugin) {
|
||||||
char * temp;
|
|
||||||
|
|
||||||
freeStringArray(inPlugin->suffixes);
|
freeStringArray(inPlugin->suffixes);
|
||||||
freeStringArray(inPlugin->mimeTypes);
|
freeStringArray(inPlugin->mimeTypes);
|
||||||
|
|
||||||
|
@ -45,15 +53,16 @@ static char ** AddStringToArray(char ** array, char * string) {
|
||||||
|
|
||||||
if(array) {
|
if(array) {
|
||||||
char ** tmp = array;
|
char ** tmp = array;
|
||||||
while(*array) {
|
while(*tmp) {
|
||||||
arraySize++;
|
arraySize++;
|
||||||
array++;
|
tmp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
array = realloc(array, arraySize*sizeof(char *));
|
array = realloc(array, (arraySize+1)*sizeof(char *));
|
||||||
|
|
||||||
array[arraySize-1] = strdup(string);
|
array[arraySize-1] = strdup(string);
|
||||||
|
array[arraySize] = NULL;
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
@ -65,3 +74,66 @@ void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix) {
|
||||||
void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * mimeType) {
|
void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * mimeType) {
|
||||||
inPlugin->mimeTypes = AddStringToArray(inPlugin->mimeTypes, 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);
|
||||||
|
}
|
||||||
|
|
|
@ -28,16 +28,20 @@ typedef struct _InputPlugin {
|
||||||
char ** mimeTypes;
|
char ** mimeTypes;
|
||||||
} InputPlugin;
|
} InputPlugin;
|
||||||
|
|
||||||
/* interface for adding and removing plugins */
|
/* interface for constructing a plugin */
|
||||||
|
|
||||||
InputPlugin * newInputPlugin();
|
|
||||||
|
|
||||||
|
InputPlugin * newInputPlugin(char * name, InputPlugin_streamDecodeFunc
|
||||||
|
streamDecodeFunc, InputPlugin_fileDecodeFunc fileDecodeFunc,
|
||||||
|
InputPlugin_tagDupFunc tagDupFunc, unsigned char streamTypes);
|
||||||
void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix);
|
void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix);
|
||||||
|
|
||||||
void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * suffix);
|
void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * suffix);
|
||||||
|
|
||||||
void freeInputPlugin(InputPlugin * inputPlugin);
|
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 */
|
/* interface for using plugins */
|
||||||
|
|
||||||
InputPlugin * getInputPluginFromSuffix(char * suffix);
|
InputPlugin * getInputPluginFromSuffix(char * suffix);
|
||||||
|
@ -56,6 +60,4 @@ void initInputPlugins();
|
||||||
/* this is where we "unload" all the "plugins" */
|
/* this is where we "unload" all the "plugins" */
|
||||||
void finishInputPlugins();
|
void finishInputPlugins();
|
||||||
|
|
||||||
void unloadInputPlugin(InputPlugin * inputPlugin);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue