output/httpd: make variables more local

This commit is contained in:
Max Kellermann 2012-10-01 23:52:40 +02:00
parent d115507502
commit 4227a325a5

View File

@ -114,10 +114,6 @@ httpd_output_init(const struct config_param *param,
return NULL; return NULL;
} }
const char *encoder_name, *bind_to_address;
const struct encoder_plugin *encoder_plugin;
guint port;
/* read configuration */ /* read configuration */
httpd->name = httpd->name =
config_get_block_string(param, "name", "Set name in config"); config_get_block_string(param, "name", "Set name in config");
@ -126,10 +122,12 @@ httpd_output_init(const struct config_param *param,
httpd->website = httpd->website =
config_get_block_string(param, "website", "Set website in config"); config_get_block_string(param, "website", "Set website in config");
port = config_get_block_unsigned(param, "port", 8000); guint port = config_get_block_unsigned(param, "port", 8000);
encoder_name = config_get_block_string(param, "encoder", "vorbis"); const char *encoder_name =
encoder_plugin = encoder_plugin_get(encoder_name); config_get_block_string(param, "encoder", "vorbis");
const struct encoder_plugin *encoder_plugin =
encoder_plugin_get(encoder_name);
if (encoder_plugin == NULL) { if (encoder_plugin == NULL) {
g_set_error(error, httpd_output_quark(), 0, g_set_error(error, httpd_output_quark(), 0,
"No such encoder: %s", encoder_name); "No such encoder: %s", encoder_name);
@ -144,7 +142,7 @@ httpd_output_init(const struct config_param *param,
httpd->server_socket = server_socket_new(httpd_listen_in_event, httpd); httpd->server_socket = server_socket_new(httpd_listen_in_event, httpd);
bind_to_address = const char *bind_to_address =
config_get_block_string(param, "bind_to_address", NULL); config_get_block_string(param, "bind_to_address", NULL);
bool success = bind_to_address != NULL && bool success = bind_to_address != NULL &&
strcmp(bind_to_address, "any") != 0 strcmp(bind_to_address, "any") != 0
@ -275,8 +273,6 @@ httpd_listen_in_event(int fd, const struct sockaddr *address,
static struct page * static struct page *
httpd_output_read_page(struct httpd_output *httpd) httpd_output_read_page(struct httpd_output *httpd)
{ {
size_t size = 0, nbytes;
if (httpd->unflushed_input >= 65536) { if (httpd->unflushed_input >= 65536) {
/* we have fed a lot of input into the encoder, but it /* we have fed a lot of input into the encoder, but it
didn't give anything back yet - flush now to avoid didn't give anything back yet - flush now to avoid
@ -285,8 +281,10 @@ httpd_output_read_page(struct httpd_output *httpd)
httpd->unflushed_input = 0; httpd->unflushed_input = 0;
} }
size_t size = 0;
do { do {
nbytes = encoder_read(httpd->encoder, httpd->buffer + size, size_t nbytes = encoder_read(httpd->encoder,
httpd->buffer + size,
sizeof(httpd->buffer) - size); sizeof(httpd->buffer) - size);
if (nbytes == 0) if (nbytes == 0)
break; break;
@ -307,10 +305,7 @@ httpd_output_encoder_open(struct httpd_output *httpd,
struct audio_format *audio_format, struct audio_format *audio_format,
GError **error) GError **error)
{ {
bool success; if (!encoder_open(httpd->encoder, audio_format, error))
success = encoder_open(httpd->encoder, audio_format, error);
if (!success)
return false; return false;
/* we have to remember the encoder header, i.e. the first /* we have to remember the encoder header, i.e. the first
@ -344,14 +339,12 @@ httpd_output_open(struct audio_output *ao, struct audio_format *audio_format,
GError **error) GError **error)
{ {
struct httpd_output *httpd = (struct httpd_output *)ao; struct httpd_output *httpd = (struct httpd_output *)ao;
bool success;
g_mutex_lock(httpd->mutex); g_mutex_lock(httpd->mutex);
/* open the encoder */ /* open the encoder */
success = httpd_output_encoder_open(httpd, audio_format, error); if (!httpd_output_encoder_open(httpd, audio_format, error)) {
if (!success) {
g_mutex_unlock(httpd->mutex); g_mutex_unlock(httpd->mutex);
return false; return false;
} }
@ -495,10 +488,7 @@ static bool
httpd_output_encode_and_play(struct httpd_output *httpd, httpd_output_encode_and_play(struct httpd_output *httpd,
const void *chunk, size_t size, GError **error) const void *chunk, size_t size, GError **error)
{ {
bool success; if (!encoder_write(httpd->encoder, chunk, size, error))
success = encoder_write(httpd->encoder, chunk, size, error);
if (!success)
return false; return false;
httpd->unflushed_input += size; httpd->unflushed_input += size;
@ -510,16 +500,12 @@ httpd_output_encode_and_play(struct httpd_output *httpd,
static size_t static size_t
httpd_output_play(struct audio_output *ao, const void *chunk, size_t size, httpd_output_play(struct audio_output *ao, const void *chunk, size_t size,
GError **error) GError **error_r)
{ {
struct httpd_output *httpd = (struct httpd_output *)ao; struct httpd_output *httpd = (struct httpd_output *)ao;
if (httpd_output_lock_has_clients(httpd)) { if (httpd_output_lock_has_clients(httpd)) {
bool success; if (!httpd_output_encode_and_play(httpd, chunk, size, error_r))
success = httpd_output_encode_and_play(httpd, chunk, size,
error);
if (!success)
return 0; return 0;
} }
@ -562,7 +548,6 @@ httpd_output_tag(struct audio_output *ao, const struct tag *tag)
if (httpd->encoder->plugin->tag != NULL) { if (httpd->encoder->plugin->tag != NULL) {
/* embed encoder tags */ /* embed encoder tags */
struct page *page;
/* flush the current stream, and end it */ /* flush the current stream, and end it */
@ -578,7 +563,7 @@ httpd_output_tag(struct audio_output *ao, const struct tag *tag)
used as the new "header" page, which is sent to all used as the new "header" page, which is sent to all
new clients */ new clients */
page = httpd_output_read_page(httpd); struct page *page = httpd_output_read_page(httpd);
if (page != NULL) { if (page != NULL) {
if (httpd->header != NULL) if (httpd->header != NULL)
page_unref(httpd->header); page_unref(httpd->header);