output/shout: move code to my_shout_configure()
Eliminate the evil goto.
This commit is contained in:
parent
eafa432cc6
commit
9a715267ad
@ -105,15 +105,10 @@ static void free_shout_data(struct shout_data *sd)
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct audio_output *
|
static bool
|
||||||
my_shout_init_driver(const struct config_param *param,
|
my_shout_configure(struct shout_data *sd, const struct config_param *param,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
struct shout_data *sd = new_shout_data();
|
|
||||||
if (!ao_base_init(&sd->base, &shout_output_plugin, param, error)) {
|
|
||||||
free_shout_data(sd);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct audio_format *audio_format =
|
const struct audio_format *audio_format =
|
||||||
&sd->base.config_audio_format;
|
&sd->base.config_audio_format;
|
||||||
@ -125,11 +120,6 @@ my_shout_init_driver(const struct config_param *param,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shout_init_count == 0)
|
|
||||||
shout_init();
|
|
||||||
|
|
||||||
shout_init_count++;
|
|
||||||
|
|
||||||
const struct block_param *block_param;
|
const struct block_param *block_param;
|
||||||
check_block_param("host");
|
check_block_param("host");
|
||||||
char *host = block_param->value;
|
char *host = block_param->value;
|
||||||
@ -141,7 +131,7 @@ my_shout_init_driver(const struct config_param *param,
|
|||||||
if (port == 0) {
|
if (port == 0) {
|
||||||
g_set_error(error, shout_output_quark(), 0,
|
g_set_error(error, shout_output_quark(), 0,
|
||||||
"shout port must be configured");
|
"shout port must be configured");
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
check_block_param("password");
|
check_block_param("password");
|
||||||
@ -164,21 +154,21 @@ my_shout_init_driver(const struct config_param *param,
|
|||||||
"shout quality \"%s\" is not a number in the "
|
"shout quality \"%s\" is not a number in the "
|
||||||
"range -1 to 10, line %i",
|
"range -1 to 10, line %i",
|
||||||
value, param->line);
|
value, param->line);
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_get_block_string(param, "bitrate", NULL) != NULL) {
|
if (config_get_block_string(param, "bitrate", NULL) != NULL) {
|
||||||
g_set_error(error, shout_output_quark(), 0,
|
g_set_error(error, shout_output_quark(), 0,
|
||||||
"quality and bitrate are "
|
"quality and bitrate are "
|
||||||
"both defined");
|
"both defined");
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = config_get_block_string(param, "bitrate", NULL);
|
value = config_get_block_string(param, "bitrate", NULL);
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
g_set_error(error, shout_output_quark(), 0,
|
g_set_error(error, shout_output_quark(), 0,
|
||||||
"neither bitrate nor quality defined");
|
"neither bitrate nor quality defined");
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *test;
|
char *test;
|
||||||
@ -187,7 +177,7 @@ my_shout_init_driver(const struct config_param *param,
|
|||||||
if (*test != '\0' || sd->bitrate <= 0) {
|
if (*test != '\0' || sd->bitrate <= 0) {
|
||||||
g_set_error(error, shout_output_quark(), 0,
|
g_set_error(error, shout_output_quark(), 0,
|
||||||
"bitrate must be a positive integer");
|
"bitrate must be a positive integer");
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,12 +189,12 @@ my_shout_init_driver(const struct config_param *param,
|
|||||||
g_set_error(error, shout_output_quark(), 0,
|
g_set_error(error, shout_output_quark(), 0,
|
||||||
"couldn't find shout encoder plugin \"%s\"",
|
"couldn't find shout encoder plugin \"%s\"",
|
||||||
encoding);
|
encoding);
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sd->encoder = encoder_init(encoder_plugin, param, error);
|
sd->encoder = encoder_init(encoder_plugin, param, error);
|
||||||
if (sd->encoder == NULL)
|
if (sd->encoder == NULL)
|
||||||
goto failure;
|
return false;
|
||||||
|
|
||||||
unsigned shout_format;
|
unsigned shout_format;
|
||||||
if (strcmp(encoding, "mp3") == 0 || strcmp(encoding, "lame") == 0)
|
if (strcmp(encoding, "mp3") == 0 || strcmp(encoding, "lame") == 0)
|
||||||
@ -220,7 +210,7 @@ my_shout_init_driver(const struct config_param *param,
|
|||||||
g_set_error(error, shout_output_quark(), 0,
|
g_set_error(error, shout_output_quark(), 0,
|
||||||
"you cannot stream \"%s\" to shoutcast, use mp3",
|
"you cannot stream \"%s\" to shoutcast, use mp3",
|
||||||
encoding);
|
encoding);
|
||||||
goto failure;
|
return false;
|
||||||
} else if (0 == strcmp(value, "shoutcast"))
|
} else if (0 == strcmp(value, "shoutcast"))
|
||||||
protocol = SHOUT_PROTOCOL_ICY;
|
protocol = SHOUT_PROTOCOL_ICY;
|
||||||
else if (0 == strcmp(value, "icecast1"))
|
else if (0 == strcmp(value, "icecast1"))
|
||||||
@ -232,7 +222,7 @@ my_shout_init_driver(const struct config_param *param,
|
|||||||
"shout protocol \"%s\" is not \"shoutcast\" or "
|
"shout protocol \"%s\" is not \"shoutcast\" or "
|
||||||
"\"icecast1\"or \"icecast2\"",
|
"\"icecast1\"or \"icecast2\"",
|
||||||
value);
|
value);
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
protocol = SHOUT_PROTOCOL_HTTP;
|
protocol = SHOUT_PROTOCOL_HTTP;
|
||||||
@ -251,7 +241,7 @@ my_shout_init_driver(const struct config_param *param,
|
|||||||
shout_set_agent(sd->shout_conn, "MPD") != SHOUTERR_SUCCESS) {
|
shout_set_agent(sd->shout_conn, "MPD") != SHOUTERR_SUCCESS) {
|
||||||
g_set_error(error, shout_output_quark(), 0,
|
g_set_error(error, shout_output_quark(), 0,
|
||||||
"%s", shout_get_error(sd->shout_conn));
|
"%s", shout_get_error(sd->shout_conn));
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* optional paramters */
|
/* optional paramters */
|
||||||
@ -262,21 +252,21 @@ my_shout_init_driver(const struct config_param *param,
|
|||||||
if (value != NULL && shout_set_genre(sd->shout_conn, value)) {
|
if (value != NULL && shout_set_genre(sd->shout_conn, value)) {
|
||||||
g_set_error(error, shout_output_quark(), 0,
|
g_set_error(error, shout_output_quark(), 0,
|
||||||
"%s", shout_get_error(sd->shout_conn));
|
"%s", shout_get_error(sd->shout_conn));
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = config_get_block_string(param, "description", NULL);
|
value = config_get_block_string(param, "description", NULL);
|
||||||
if (value != NULL && shout_set_description(sd->shout_conn, value)) {
|
if (value != NULL && shout_set_description(sd->shout_conn, value)) {
|
||||||
g_set_error(error, shout_output_quark(), 0,
|
g_set_error(error, shout_output_quark(), 0,
|
||||||
"%s", shout_get_error(sd->shout_conn));
|
"%s", shout_get_error(sd->shout_conn));
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = config_get_block_string(param, "url", NULL);
|
value = config_get_block_string(param, "url", NULL);
|
||||||
if (value != NULL && shout_set_url(sd->shout_conn, value)) {
|
if (value != NULL && shout_set_url(sd->shout_conn, value)) {
|
||||||
g_set_error(error, shout_output_quark(), 0,
|
g_set_error(error, shout_output_quark(), 0,
|
||||||
"%s", shout_get_error(sd->shout_conn));
|
"%s", shout_get_error(sd->shout_conn));
|
||||||
goto failure;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -301,12 +291,31 @@ my_shout_init_driver(const struct config_param *param,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &sd->base;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
failure:
|
static struct audio_output *
|
||||||
ao_base_finish(&sd->base);
|
my_shout_init_driver(const struct config_param *param,
|
||||||
free_shout_data(sd);
|
GError **error)
|
||||||
return NULL;
|
{
|
||||||
|
struct shout_data *sd = new_shout_data();
|
||||||
|
if (!ao_base_init(&sd->base, &shout_output_plugin, param, error)) {
|
||||||
|
free_shout_data(sd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!my_shout_configure(sd, param, error)) {
|
||||||
|
ao_base_finish(&sd->base);
|
||||||
|
free_shout_data(sd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shout_init_count == 0)
|
||||||
|
shout_init();
|
||||||
|
|
||||||
|
shout_init_count++;
|
||||||
|
|
||||||
|
return &sd->base;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
Loading…
Reference in New Issue
Block a user