From 7b23f80b031ee2a584c1df1b444118a7d2f1835b Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Wed, 26 Aug 2015 22:17:37 +1000 Subject: [PATCH] Refactor port change handling part of PA Backend process function into new method --- libs/backends/portaudio/portaudio_backend.cc | 62 +++++++++++--------- libs/backends/portaudio/portaudio_backend.h | 2 + 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/libs/backends/portaudio/portaudio_backend.cc b/libs/backends/portaudio/portaudio_backend.cc index c91cff2b86..011b8d4474 100644 --- a/libs/backends/portaudio/portaudio_backend.cc +++ b/libs/backends/portaudio/portaudio_backend.cc @@ -1601,35 +1601,7 @@ PortAudioBackend::main_blocking_process_thread () Glib::usleep (100); // don't hog cpu } - bool connections_changed = false; - bool ports_changed = false; - if (!pthread_mutex_trylock (&_port_callback_mutex)) { - if (_port_change_flag) { - ports_changed = true; - _port_change_flag = false; - } - if (!_port_connection_queue.empty ()) { - connections_changed = true; - } - while (!_port_connection_queue.empty ()) { - PortConnectData *c = _port_connection_queue.back (); - manager.connect_callback (c->a, c->b, c->c); - _port_connection_queue.pop_back (); - delete c; - } - pthread_mutex_unlock (&_port_callback_mutex); - } - if (ports_changed) { - manager.registration_callback(); - } - if (connections_changed) { - manager.graph_order_callback(); - } - if (connections_changed || ports_changed) { - engine.latency_callback(false); - engine.latency_callback(true); - } - + process_port_connection_changes(); } _pcmio->close_stream(); _active = false; @@ -1644,6 +1616,38 @@ PortAudioBackend::main_blocking_process_thread () return 0; } +void +PortAudioBackend::process_port_connection_changes () +{ + bool connections_changed = false; + bool ports_changed = false; + if (!pthread_mutex_trylock (&_port_callback_mutex)) { + if (_port_change_flag) { + ports_changed = true; + _port_change_flag = false; + } + if (!_port_connection_queue.empty ()) { + connections_changed = true; + } + while (!_port_connection_queue.empty ()) { + PortConnectData *c = _port_connection_queue.back (); + manager.connect_callback (c->a, c->b, c->c); + _port_connection_queue.pop_back (); + delete c; + } + pthread_mutex_unlock (&_port_callback_mutex); + } + if (ports_changed) { + manager.registration_callback(); + } + if (connections_changed) { + manager.graph_order_callback(); + } + if (connections_changed || ports_changed) { + engine.latency_callback(false); + engine.latency_callback(true); + } +} /******************************************************************************/ diff --git a/libs/backends/portaudio/portaudio_backend.h b/libs/backends/portaudio/portaudio_backend.h index 498a3d9944..cbef7508df 100644 --- a/libs/backends/portaudio/portaudio_backend.h +++ b/libs/backends/portaudio/portaudio_backend.h @@ -323,6 +323,8 @@ class PortAudioBackend : public AudioBackend { bool start_blocking_process_thread (); bool stop_blocking_process_thread (); + void process_port_connection_changes (); + private: std::string _instance_name; PortAudioIO *_pcmio;