From 5a898c15e79ab87d2466e61549fcc20ce115c67e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 23 Feb 2009 09:29:56 +0100 Subject: output_api: play() returns a length The old API required an output plugin to not return until all data passed to the play() method is consumed. Some output plugins have to loop to fulfill that requirement, and may block during that. Simplify these, by letting them consume only part of the buffer: make play() return the length of the consumed data. --- src/output/jack_plugin.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/output/jack_plugin.c') diff --git a/src/output/jack_plugin.c b/src/output/jack_plugin.c index 2bcdf874..22841f8e 100644 --- a/src/output/jack_plugin.c +++ b/src/output/jack_plugin.c @@ -387,7 +387,7 @@ mpd_jack_write_samples(struct jack_data *jd, const void *src, } } -static bool +static size_t mpd_jack_play(void *data, const char *buff, size_t size) { struct jack_data *jd = data; @@ -396,36 +396,33 @@ mpd_jack_play(void *data, const char *buff, size_t size) if (jd->shutdown) { g_warning("Refusing to play, because there is no client thread."); - return false; + return 0; } assert(size % frame_size == 0); size /= frame_size; - while (size > 0 && !jd->shutdown) { + + while (!jd->shutdown) { space = jack_ringbuffer_write_space(jd->ringbuffer[0]); space1 = jack_ringbuffer_write_space(jd->ringbuffer[1]); if (space > space1) /* send data symmetrically */ space = space1; - space /= sample_size; - if (space > 0) { - if (space > size) - space = size; - - mpd_jack_write_samples(jd, buff, space); - - buff += space * frame_size; - size -= space; - } else { - /* XXX do something more intelligent to - synchronize */ - g_usleep(1000); - } + if (space >= frame_size) + break; + /* XXX do something more intelligent to + synchronize */ + g_usleep(1000); } - return true; + space /= sample_size; + if (space < size) + size = space; + + mpd_jack_write_samples(jd, buff, size); + return size * frame_size; } const struct audio_output_plugin jackPlugin = { -- cgit v1.2.3