diff options
author | Max Kellermann <max@duempel.org> | 2011-09-16 23:31:48 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-09-19 09:41:21 +0200 |
commit | 74617389c88ccf630b8cce4b54d9e2fa5afb2259 (patch) | |
tree | 3d05faad2c2b3b2e9e885f2c391a35fe8f06553a /src/output/httpd_output_plugin.c | |
parent | b4a8b8c0d4bf82fc56572c3f8e79108d22d78132 (diff) | |
download | mpd-74617389c88ccf630b8cce4b54d9e2fa5afb2259.tar.gz mpd-74617389c88ccf630b8cce4b54d9e2fa5afb2259.tar.xz mpd-74617389c88ccf630b8cce4b54d9e2fa5afb2259.zip |
output_plugin: the plugin allocates the audio_output object
Pass audio_output objects around instead of void pointers. This will
give some more control to the plugin, and prepares for non-blocking
audio outputs.
Diffstat (limited to 'src/output/httpd_output_plugin.c')
-rw-r--r-- | src/output/httpd_output_plugin.c | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/src/output/httpd_output_plugin.c b/src/output/httpd_output_plugin.c index abbd78ad2..ab663badf 100644 --- a/src/output/httpd_output_plugin.c +++ b/src/output/httpd_output_plugin.c @@ -79,12 +79,16 @@ httpd_output_unbind(struct httpd_output *httpd) g_mutex_unlock(httpd->mutex); } -static void * -httpd_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, - const struct config_param *param, +static struct audio_output * +httpd_output_init(const struct config_param *param, GError **error) { struct httpd_output *httpd = g_new(struct httpd_output, 1); + if (!ao_base_init(&httpd->base, &httpd_output_plugin, param, error)) { + g_free(httpd); + return NULL; + } + const char *encoder_name, *bind_to_address; const struct encoder_plugin *encoder_plugin; guint port; @@ -104,6 +108,7 @@ httpd_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, if (encoder_plugin == NULL) { g_set_error(error, httpd_output_quark(), 0, "No such encoder: %s", encoder_name); + ao_base_finish(&httpd->base); g_free(httpd); return NULL; } @@ -121,8 +126,11 @@ httpd_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, ? server_socket_add_host(httpd->server_socket, bind_to_address, port, error) : server_socket_add_port(httpd->server_socket, port, error); - if (!success) + if (!success) { + ao_base_finish(&httpd->base); + g_free(httpd); return NULL; + } /* initialize metadata */ httpd->metadata = NULL; @@ -131,8 +139,11 @@ httpd_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, /* initialize encoder */ httpd->encoder = encoder_init(encoder_plugin, param, error); - if (httpd->encoder == NULL) + if (httpd->encoder == NULL) { + ao_base_finish(&httpd->base); + g_free(httpd); return NULL; + } /* determine content type */ httpd->content_type = encoder_get_mime_type(httpd->encoder); @@ -142,13 +153,13 @@ httpd_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, httpd->mutex = g_mutex_new(); - return httpd; + return &httpd->base; } static void -httpd_output_finish(void *data) +httpd_output_finish(struct audio_output *ao) { - struct httpd_output *httpd = data; + struct httpd_output *httpd = (struct httpd_output *)ao; if (httpd->metadata) page_unref(httpd->metadata); @@ -156,6 +167,7 @@ httpd_output_finish(void *data) encoder_finish(httpd->encoder); server_socket_free(httpd->server_socket); g_mutex_free(httpd->mutex); + ao_base_finish(&httpd->base); g_free(httpd); } @@ -287,26 +299,26 @@ httpd_output_encoder_open(struct httpd_output *httpd, } static bool -httpd_output_enable(void *data, GError **error_r) +httpd_output_enable(struct audio_output *ao, GError **error_r) { - struct httpd_output *httpd = data; + struct httpd_output *httpd = (struct httpd_output *)ao; return httpd_output_bind(httpd, error_r); } static void -httpd_output_disable(void *data) +httpd_output_disable(struct audio_output *ao) { - struct httpd_output *httpd = data; + struct httpd_output *httpd = (struct httpd_output *)ao; httpd_output_unbind(httpd); } static bool -httpd_output_open(void *data, struct audio_format *audio_format, +httpd_output_open(struct audio_output *ao, struct audio_format *audio_format, GError **error) { - struct httpd_output *httpd = data; + struct httpd_output *httpd = (struct httpd_output *)ao; bool success; g_mutex_lock(httpd->mutex); @@ -339,9 +351,10 @@ httpd_client_delete(gpointer data, G_GNUC_UNUSED gpointer user_data) httpd_client_free(client); } -static void httpd_output_close(void *data) +static void +httpd_output_close(struct audio_output *ao) { - struct httpd_output *httpd = data; + struct httpd_output *httpd = (struct httpd_output *)ao; g_mutex_lock(httpd->mutex); @@ -380,9 +393,9 @@ httpd_output_send_header(struct httpd_output *httpd, } static unsigned -httpd_output_delay(void *data) +httpd_output_delay(struct audio_output *ao) { - struct httpd_output *httpd = data; + struct httpd_output *httpd = (struct httpd_output *)ao; return httpd->timer->started ? timer_delay(httpd->timer) @@ -458,9 +471,10 @@ httpd_output_encode_and_play(struct httpd_output *httpd, } static size_t -httpd_output_play(void *data, const void *chunk, size_t size, GError **error) +httpd_output_play(struct audio_output *ao, const void *chunk, size_t size, + GError **error) { - struct httpd_output *httpd = data; + struct httpd_output *httpd = (struct httpd_output *)ao; bool has_clients; g_mutex_lock(httpd->mutex); @@ -484,9 +498,9 @@ httpd_output_play(void *data, const void *chunk, size_t size, GError **error) } static bool -httpd_output_pause(void *data) +httpd_output_pause(struct audio_output *ao) { - struct httpd_output *httpd = data; + struct httpd_output *httpd = (struct httpd_output *)ao; g_mutex_lock(httpd->mutex); bool has_clients = httpd->clients != NULL; @@ -494,7 +508,7 @@ httpd_output_pause(void *data) if (has_clients) { static const char silence[1020]; - return httpd_output_play(data, silence, sizeof(silence), + return httpd_output_play(ao, silence, sizeof(silence), NULL) > 0; } else { g_usleep(100000); @@ -512,9 +526,9 @@ httpd_send_metadata(gpointer data, gpointer user_data) } static void -httpd_output_tag(void *data, const struct tag *tag) +httpd_output_tag(struct audio_output *ao, const struct tag *tag) { - struct httpd_output *httpd = data; + struct httpd_output *httpd = (struct httpd_output *)ao; assert(tag != NULL); @@ -571,9 +585,9 @@ httpd_client_cancel_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) } static void -httpd_output_cancel(void *data) +httpd_output_cancel(struct audio_output *ao) { - struct httpd_output *httpd = data; + struct httpd_output *httpd = (struct httpd_output *)ao; g_mutex_lock(httpd->mutex); g_list_foreach(httpd->clients, httpd_client_cancel_callback, NULL); |