summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-01-21 14:29:41 +0100
committerDavid Robillard <d@drobilla.net>2018-01-21 14:29:41 +0100
commit449e40985328b0596b089301137ea1715b583ee6 (patch)
tree1af254c2430ecbf6b22557319f867f05dca410a4 /src/server
parentac778d258e0866d1117aadf576de2ff89df3e84d (diff)
downloadingen-449e40985328b0596b089301137ea1715b583ee6.tar.gz
ingen-449e40985328b0596b089301137ea1715b583ee6.tar.bz2
ingen-449e40985328b0596b089301137ea1715b583ee6.zip
Work around Jack returning NULL buffers
Diffstat (limited to 'src/server')
-rw-r--r--src/server/JackDriver.cpp11
-rw-r--r--src/server/JackDriver.hpp7
2 files changed, 15 insertions, 3 deletions
diff --git a/src/server/JackDriver.cpp b/src/server/JackDriver.cpp
index d022077a..973e3eb7 100644
--- a/src/server/JackDriver.cpp
+++ b/src/server/JackDriver.cpp
@@ -125,6 +125,10 @@ JackDriver::attach(const std::string& server_name,
_block_length = jack_get_buffer_size(_client);
_seq_size = jack_port_type_get_buffer_size(_client, JACK_DEFAULT_MIDI_TYPE);
+ _fallback_buffer = AudioBufPtr(
+ static_cast<float*>(
+ Buffer::aligned_alloc(sizeof(float) * _block_length)));
+
jack_on_shutdown(_client, shutdown_cb, this);
jack_set_thread_init_callback(_client, thread_init_cb, this);
@@ -217,7 +221,12 @@ JackDriver::add_port(RunContext& context, EnginePort* port)
const SampleCount nframes = context.nframes();
jack_port_t* jport = (jack_port_t*)port->handle();
void* jbuf = jack_port_get_buffer(jport, nframes);
- graph_port->set_driver_buffer(jbuf, nframes * sizeof(float));
+
+ /* Jack fails to return a buffer if this is too soon after registering
+ the port, so use a silent fallback buffer if necessary. */
+ graph_port->set_driver_buffer(
+ jbuf ? jbuf : _fallback_buffer.get(),
+ nframes * sizeof(float));
}
}
diff --git a/src/server/JackDriver.hpp b/src/server/JackDriver.hpp
index 678ce483..2a21d96e 100644
--- a/src/server/JackDriver.hpp
+++ b/src/server/JackDriver.hpp
@@ -29,9 +29,9 @@
#include <jack/session.h>
#endif
-#include "raul/Semaphore.hpp"
-
+#include "ingen/types.hpp"
#include "lv2/lv2plug.in/ns/ext/atom/forge.h"
+#include "raul/Semaphore.hpp"
#include "Driver.hpp"
#include "EnginePort.hpp"
@@ -142,8 +142,11 @@ protected:
boost::intrusive::cache_last<true>
> Ports;
+ using AudioBufPtr = UPtr<float, FreeDeleter<float>>;
+
Engine& _engine;
Ports _ports;
+ AudioBufPtr _fallback_buffer;
LV2_Atom_Forge _forge;
Raul::Semaphore _sem;
std::atomic<bool> _flag;