aboutsummaryrefslogtreecommitdiffstats
path: root/src/output/jack_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-02-23 09:29:56 +0100
committerMax Kellermann <max@duempel.org>2009-02-23 09:29:56 +0100
commit5a898c15e79ab87d2466e61549fcc20ce115c67e (patch)
treecb65b88718b0b8f3cf05221816b193833c41fe8a /src/output/jack_plugin.c
parentd50a3d513eb0452e762f1e4eeb717318958cd83c (diff)
downloadmpd-5a898c15e79ab87d2466e61549fcc20ce115c67e.tar.gz
mpd-5a898c15e79ab87d2466e61549fcc20ce115c67e.tar.xz
mpd-5a898c15e79ab87d2466e61549fcc20ce115c67e.zip
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.
Diffstat (limited to '')
-rw-r--r--src/output/jack_plugin.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/output/jack_plugin.c b/src/output/jack_plugin.c
index 2bcdf874f..22841f8ef 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 = {