Commit d9f170b5 authored by Max Kellermann's avatar Max Kellermann

shout: static encoder plugin list

Shout encoder plugins are known at compile time. There is no reason to use a complex data structure as "List" to manage them at runtime - just put the pointers into a static array.
parent a84de9b0
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#ifdef HAVE_SHOUT #ifdef HAVE_SHOUT
#include "../list.h"
#include "../utils.h" #include "../utils.h"
#define CONN_ATTEMPT_INTERVAL 60 #define CONN_ATTEMPT_INTERVAL 60
...@@ -29,32 +28,23 @@ ...@@ -29,32 +28,23 @@
#define SHOUT_BUF_SIZE 8192 #define SHOUT_BUF_SIZE 8192
static int shout_init_count; static int shout_init_count;
static List *shout_encoder_plugin_list;
mpd_unused static struct shout_encoder_plugin *const shout_encoder_plugins[] = {
static void finish_shout_encoder_plugins(void) &shout_mp3_encoder,
{ &shout_ogg_encoder,
freeList(shout_encoder_plugin_list); NULL
} };
static void init_shout_encoder_plugins(void) static struct shout_encoder_plugin *
shout_encoder_plugin_get(const char *name)
{ {
shout_encoder_plugin_list = makeList(NULL, 0); unsigned i;
}
static void load_shout_encoder_plugin(struct shout_encoder_plugin * plugin) for (i = 0; shout_encoder_plugins[i] != NULL; ++i)
{ if (strcmp(shout_encoder_plugins[i]->name, name) == 0)
if (!plugin->name) return shout_encoder_plugins[i];
return;
insertInList(shout_encoder_plugin_list, plugin->name, plugin);
}
mpd_unused return NULL;
static void unload_shout_encoder_plugin(struct shout_encoder_plugin * plugin)
{
if (!plugin->name)
return;
deleteFromList(shout_encoder_plugin_list, plugin->name);
} }
static void clear_shout_buffer(struct shout_data * sd) static void clear_shout_buffer(struct shout_data * sd)
...@@ -110,13 +100,6 @@ static void free_shout_data(struct shout_data *sd) ...@@ -110,13 +100,6 @@ static void free_shout_data(struct shout_data *sd)
} \ } \
} }
static void load_shout_plugins(void)
{
init_shout_encoder_plugins();
load_shout_encoder_plugin(&shout_mp3_encoder);
load_shout_encoder_plugin(&shout_ogg_encoder);
}
static int my_shout_init_driver(struct audio_output *audio_output, static int my_shout_init_driver(struct audio_output *audio_output,
ConfigParam * param) ConfigParam * param)
{ {
...@@ -131,9 +114,6 @@ static int my_shout_init_driver(struct audio_output *audio_output, ...@@ -131,9 +114,6 @@ static int my_shout_init_driver(struct audio_output *audio_output,
char *name; char *name;
BlockParam *block_param; BlockParam *block_param;
int public; int public;
void *data = NULL;
load_shout_plugins();
sd = new_shout_data(); sd = new_shout_data();
...@@ -225,11 +205,11 @@ static int my_shout_init_driver(struct audio_output *audio_output, ...@@ -225,11 +205,11 @@ static int my_shout_init_driver(struct audio_output *audio_output,
} else { } else {
encoding = "ogg"; encoding = "ogg";
} }
if (!findInList(shout_encoder_plugin_list, encoding, &data)) {
sd->encoder = shout_encoder_plugin_get(encoding);
if (sd->encoder == NULL)
FATAL("couldn't find shout encoder plugin for \"%s\" " FATAL("couldn't find shout encoder plugin for \"%s\" "
"at line %i\n", encoding, block_param->line); "at line %i\n", encoding, block_param->line);
}
sd->encoder = (struct shout_encoder_plugin *) data;
if (shout_set_host(sd->shout_conn, host) != SHOUTERR_SUCCESS || if (shout_set_host(sd->shout_conn, host) != SHOUTERR_SUCCESS ||
shout_set_port(sd->shout_conn, port) != SHOUTERR_SUCCESS || shout_set_port(sd->shout_conn, port) != SHOUTERR_SUCCESS ||
......
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