aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-08 11:43:13 +0200
committerMax Kellermann <max@duempel.org>2008-09-08 11:43:13 +0200
commitbe046b25a4e2583f63d6b3da680e6451957750e4 (patch)
treef295ed51a8e2ab4f7eb504ee2d2ea2e471ad7e2c /src
parenta0103dd05ce4f42f3be2ff951ea44d6e76dadc2f (diff)
downloadmpd-be046b25a4e2583f63d6b3da680e6451957750e4.tar.gz
mpd-be046b25a4e2583f63d6b3da680e6451957750e4.tar.xz
mpd-be046b25a4e2583f63d6b3da680e6451957750e4.zip
output: static audio_output_plugin list as array
Instead of having to register each output plugin, store them statically in an array. This eliminates the need for the List library here, and saves some small allocations during startup.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/audio.c17
-rw-r--r--src/audio.h1
-rw-r--r--src/audioOutput.c55
-rw-r--r--src/audioOutput.h17
-rw-r--r--src/main.c1
-rw-r--r--src/output_list.c59
-rw-r--r--src/output_list.h32
8 files changed, 104 insertions, 80 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 075dd75e7..30408288c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,6 +34,7 @@ mpd_headers = \
audio.h \
audioOutput.h \
output_api.h \
+ output_list.h \
buffer2array.h \
charConv.h \
command.h \
@@ -107,6 +108,7 @@ mpd_SOURCES = \
notify.c \
audio.c \
audioOutput.c \
+ output_list.c \
buffer2array.c \
charConv.c \
command.c \
diff --git a/src/audio.c b/src/audio.c
index b6242b425..44a97e65a 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -82,29 +82,12 @@ int cmpAudioFormat(const struct audio_format *f1, const struct audio_format *f2)
return 1;
}
-void loadAudioDrivers(void)
-{
- initAudioOutputPlugins();
- loadAudioOutputPlugin(&shoutPlugin);
- loadAudioOutputPlugin(&nullPlugin);
- loadAudioOutputPlugin(&fifoPlugin);
- loadAudioOutputPlugin(&alsaPlugin);
- loadAudioOutputPlugin(&aoPlugin);
- loadAudioOutputPlugin(&ossPlugin);
- loadAudioOutputPlugin(&osxPlugin);
- loadAudioOutputPlugin(&pulsePlugin);
- loadAudioOutputPlugin(&mvpPlugin);
- loadAudioOutputPlugin(&jackPlugin);
-}
-
/* make sure initPlayerData is called before this function!! */
void initAudioDriver(void)
{
ConfigParam *param = NULL;
unsigned int i;
- loadAudioDrivers();
-
audioOutputArraySize = audio_output_count();
audioDeviceStates = xmalloc(sizeof(enum ad_state) *
audioOutputArraySize);
diff --git a/src/audio.h b/src/audio.h
index bad9c2592..54c91fa3f 100644
--- a/src/audio.h
+++ b/src/audio.h
@@ -71,5 +71,4 @@ void readAudioDevicesState(FILE *fp);
void saveAudioDevicesState(FILE *fp);
-void loadAudioDrivers(void);
#endif
diff --git a/src/audioOutput.c b/src/audioOutput.c
index 0991d55d0..0a3e9abd8 100644
--- a/src/audioOutput.c
+++ b/src/audioOutput.c
@@ -18,8 +18,8 @@
#include "audioOutput.h"
#include "output_api.h"
+#include "output_list.h"
-#include "list.h"
#include "log.h"
#include "pcm_utils.h"
#include "utils.h"
@@ -30,33 +30,6 @@
#define AUDIO_OUTPUT_NAME "name"
#define AUDIO_OUTPUT_FORMAT "format"
-static List *audioOutputPluginList;
-
-void loadAudioOutputPlugin(struct audio_output_plugin *audioOutputPlugin)
-{
- if (!audioOutputPlugin->name)
- return;
- insertInList(audioOutputPluginList, audioOutputPlugin->name,
- audioOutputPlugin);
-}
-
-void unloadAudioOutputPlugin(struct audio_output_plugin *audioOutputPlugin)
-{
- if (!audioOutputPlugin->name)
- return;
- deleteFromList(audioOutputPluginList, audioOutputPlugin->name);
-}
-
-void initAudioOutputPlugins(void)
-{
- audioOutputPluginList = makeList(NULL, 0);
-}
-
-void finishAudioOutputPlugins(void)
-{
- freeList(audioOutputPluginList);
-}
-
#define getBlockParam(name, str, force) { \
bp = getBlockParam(param, name); \
if(force && bp == NULL) { \
@@ -69,11 +42,10 @@ void finishAudioOutputPlugins(void)
int initAudioOutput(struct audio_output *ao, ConfigParam * param)
{
- void *data = NULL;
const char *name = NULL;
char *format = NULL;
BlockParam *bp = NULL;
- struct audio_output_plugin *plugin = NULL;
+ const struct audio_output_plugin *plugin = NULL;
if (param) {
const char *type = NULL;
@@ -82,21 +54,19 @@ int initAudioOutput(struct audio_output *ao, ConfigParam * param)
getBlockParam(AUDIO_OUTPUT_TYPE, type, 1);
getBlockParam(AUDIO_OUTPUT_FORMAT, format, 0);
- if (!findInList(audioOutputPluginList, type, &data)) {
+ plugin = audio_output_plugin_get(type);
+ if (plugin == NULL) {
FATAL("couldn't find audio output plugin for type "
"\"%s\" at line %i\n", type, param->line);
}
-
- plugin = (struct audio_output_plugin *) data;
} else {
- ListNode *node = audioOutputPluginList->firstNode;
+ unsigned i;
WARNING("No \"%s\" defined in config file\n",
CONF_AUDIO_OUTPUT);
WARNING("Attempt to detect audio output device\n");
- while (node) {
- plugin = (struct audio_output_plugin *) node->data;
+ audio_output_plugins_for_each(plugin, i) {
if (plugin->testDefaultDeviceFunc) {
WARNING("Attempting to detect a %s audio "
"device\n", plugin->name);
@@ -106,10 +76,9 @@ int initAudioOutput(struct audio_output *ao, ConfigParam * param)
break;
}
}
- node = node->nextNode;
}
- if (!node) {
+ if (plugin == NULL) {
WARNING("Unable to detect an audio device\n");
return 0;
}
@@ -250,14 +219,12 @@ void sendMetadataToAudioOutput(struct audio_output *audioOutput,
void printAllOutputPluginTypes(FILE * fp)
{
- ListNode *node = audioOutputPluginList->firstNode;
- struct audio_output_plugin *plugin;
+ unsigned i;
+ const struct audio_output_plugin *plugin;
- while (node) {
- plugin = (struct audio_output_plugin *) node->data;
+ audio_output_plugins_for_each(plugin, i)
fprintf(fp, "%s ", plugin->name);
- node = node->nextNode;
- }
+
fprintf(fp, "\n");
fflush(fp);
}
diff --git a/src/audioOutput.h b/src/audioOutput.h
index fa8c9824d..d50ae9bbd 100644
--- a/src/audioOutput.h
+++ b/src/audioOutput.h
@@ -29,12 +29,6 @@ struct audio_output_plugin;
struct audio_format;
struct tag;
-void initAudioOutputPlugins(void);
-void finishAudioOutputPlugins(void);
-
-void loadAudioOutputPlugin(struct audio_output_plugin *audioOutputPlugin);
-void unloadAudioOutputPlugin(struct audio_output_plugin *audioOutputPlugin);
-
int initAudioOutput(struct audio_output *, ConfigParam * param);
int openAudioOutput(struct audio_output *audioOutput,
const struct audio_format *audioFormat);
@@ -49,15 +43,4 @@ void sendMetadataToAudioOutput(struct audio_output *audioOutput,
void printAllOutputPluginTypes(FILE * fp);
-extern struct audio_output_plugin shoutPlugin;
-extern struct audio_output_plugin nullPlugin;
-extern struct audio_output_plugin fifoPlugin;
-extern struct audio_output_plugin alsaPlugin;
-extern struct audio_output_plugin aoPlugin;
-extern struct audio_output_plugin ossPlugin;
-extern struct audio_output_plugin osxPlugin;
-extern struct audio_output_plugin pulsePlugin;
-extern struct audio_output_plugin mvpPlugin;
-extern struct audio_output_plugin jackPlugin;
-
#endif
diff --git a/src/main.c b/src/main.c
index d484a4406..2ca5a56d9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -136,7 +136,6 @@ static void version(void)
LOG("\n");
LOG("Supported outputs:\n");
- loadAudioDrivers();
printAllOutputPluginTypes(stdout);
}
diff --git a/src/output_list.c b/src/output_list.c
new file mode 100644
index 000000000..7f597b687
--- /dev/null
+++ b/src/output_list.c
@@ -0,0 +1,59 @@
+/* the Music Player Daemon (MPD)
+ * Copyright (C) 2008 Max Kellermann <max@duempel.org>
+ * 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
+ */
+
+#include "output_list.h"
+#include "output_api.h"
+#include "os_compat.h"
+
+extern const struct audio_output_plugin shoutPlugin;
+extern const struct audio_output_plugin nullPlugin;
+extern const struct audio_output_plugin fifoPlugin;
+extern const struct audio_output_plugin alsaPlugin;
+extern const struct audio_output_plugin aoPlugin;
+extern const struct audio_output_plugin ossPlugin;
+extern const struct audio_output_plugin osxPlugin;
+extern const struct audio_output_plugin pulsePlugin;
+extern const struct audio_output_plugin mvpPlugin;
+extern const struct audio_output_plugin jackPlugin;
+
+const struct audio_output_plugin *audio_output_plugins[] = {
+ &shoutPlugin,
+ &nullPlugin,
+ &fifoPlugin,
+ &alsaPlugin,
+ &aoPlugin,
+ &ossPlugin,
+ &osxPlugin,
+ &pulsePlugin,
+ &mvpPlugin,
+ &jackPlugin,
+ NULL
+};
+
+const struct audio_output_plugin *
+audio_output_plugin_get(const char *name)
+{
+ unsigned int i;
+ const struct audio_output_plugin *plugin;
+
+ audio_output_plugins_for_each(plugin, i)
+ if (strcmp(audio_output_plugins[i]->name, name) == 0)
+ return audio_output_plugins[i];
+
+ return NULL;
+}
diff --git a/src/output_list.h b/src/output_list.h
new file mode 100644
index 000000000..d0fcf1285
--- /dev/null
+++ b/src/output_list.h
@@ -0,0 +1,32 @@
+/* the Music Player Daemon (MPD)
+ * Copyright (C) 2008 Max Kellermann <max@duempel.org>
+ * 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
+ */
+
+#ifndef OUTPUT_LIST_H
+#define OUTPUT_LIST_H
+
+extern const struct audio_output_plugin *audio_output_plugins[];
+
+const struct audio_output_plugin *
+audio_output_plugin_get(const char *name);
+
+#define audio_output_plugins_for_each(plugin, i) \
+ for (i = 0; (plugin = audio_output_plugins[i]) != NULL; ++i) \
+ if (plugin->name != NULL)
+
+
+#endif