Commit be046b25 authored by Max Kellermann's avatar Max Kellermann

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.
parent a0103dd0
......@@ -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 \
......
......@@ -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);
......
......@@ -71,5 +71,4 @@ void readAudioDevicesState(FILE *fp);
void saveAudioDevicesState(FILE *fp);
void loadAudioDrivers(void);
#endif
......@@ -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);
}
......@@ -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
......@@ -136,7 +136,6 @@ static void version(void)
LOG("\n");
LOG("Supported outputs:\n");
loadAudioDrivers();
printAllOutputPluginTypes(stdout);
}
......
/* 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;
}
/* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment