From 760aee2e54571f8e4a0cb76c4228f2f28744e8dd Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 1 Sep 2015 17:14:56 -0700 Subject: [PATCH] JACK: better pause/resume behavior See #3 --- src/jack.cpp | 36 ++++++++++++++++++++++-------------- src/jack.hpp | 1 + 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/jack.cpp b/src/jack.cpp index b1df8db..dd51fdf 100644 --- a/src/jack.cpp +++ b/src/jack.cpp @@ -426,6 +426,8 @@ static int outstream_open_jack(struct SoundIoPrivate *si, struct SoundIoOutStrea SoundIoDevicePrivate *dev = (SoundIoDevicePrivate *)device; SoundIoDeviceJack *dj = &dev->backend_data.jack; + osj->is_paused = true; + if (sij->is_shutdown) return SoundIoErrorBackendDisconnected; @@ -516,21 +518,27 @@ static int outstream_pause_jack(struct SoundIoPrivate *si, struct SoundIoOutStre int err; if (pause) { - if ((err = jack_deactivate(osj->client))) - return SoundIoErrorStreaming; - } else { - if ((err = jack_activate(osj->client))) - return SoundIoErrorStreaming; - - for (int ch = 0; ch < outstream->layout.channel_count; ch += 1) { - SoundIoOutStreamJackPort *osjp = &osj->ports[ch]; - const char *dest_port_name = osjp->dest_port_name; - // allow unconnected ports - if (!dest_port_name) - continue; - const char *source_port_name = jack_port_name(osjp->source_port); - if ((err = jack_connect(osj->client, source_port_name, dest_port_name))) + if (!osj->is_paused) { + if ((err = jack_deactivate(osj->client))) return SoundIoErrorStreaming; + osj->is_paused = true; + } + } else { + if (osj->is_paused) { + if ((err = jack_activate(osj->client))) + return SoundIoErrorStreaming; + + for (int ch = 0; ch < outstream->layout.channel_count; ch += 1) { + SoundIoOutStreamJackPort *osjp = &osj->ports[ch]; + const char *dest_port_name = osjp->dest_port_name; + // allow unconnected ports + if (!dest_port_name) + continue; + const char *source_port_name = jack_port_name(osjp->source_port); + if ((err = jack_connect(osj->client, source_port_name, dest_port_name))) + return SoundIoErrorStreaming; + } + osj->is_paused = false; } } diff --git a/src/jack.hpp b/src/jack.hpp index 4b6b17d..d535b41 100644 --- a/src/jack.hpp +++ b/src/jack.hpp @@ -48,6 +48,7 @@ struct SoundIoOutStreamJack { jack_client_t *client; int period_size; int frames_left; + bool is_paused; SoundIoOutStreamJackPort ports[SOUNDIO_MAX_CHANNELS]; SoundIoChannelArea areas[SOUNDIO_MAX_CHANNELS]; };