13
0

ALSA & Dummy: implement port [un]registration_callback

This commit is contained in:
Robin Gareus 2014-06-06 13:53:07 +02:00
parent 5288de3dc0
commit 960a5347f0
4 changed files with 52 additions and 1 deletions

View File

@ -57,6 +57,7 @@ AlsaAudioBackend::AlsaAudioBackend (AudioEngine& e, AudioBackendInfo& info)
, _systemic_input_latency (0)
, _systemic_output_latency (0)
, _processed_samples (0)
, _port_change_flag (false)
{
_instance_name = s_instance_name;
pthread_mutex_init (&_port_callback_mutex, 0);
@ -487,6 +488,7 @@ AlsaAudioBackend::_start (bool for_latency_measurement)
engine.reconnect_ports ();
_run = true;
_port_change_flag = false;
if (_realtime_pthread_create (SCHED_FIFO, -20,
&_main_thread, pthread_process, this))
@ -1286,6 +1288,7 @@ AlsaAudioBackend::main_process_thread ()
_pcmi->pcm_start ();
int no_proc_errors = 0;
manager.registration_callback();
manager.graph_order_callback();
while (_run) {
@ -1396,7 +1399,16 @@ AlsaAudioBackend::main_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);
@ -1405,6 +1417,12 @@ AlsaAudioBackend::main_process_thread ()
}
pthread_mutex_unlock (&_port_callback_mutex);
}
if (ports_changed) {
manager.registration_callback();
}
if (connections_changed) {
manager.graph_order_callback();
}
}
_pcmi->pcm_stop ();

View File

@ -352,6 +352,7 @@ class AlsaAudioBackend : public AudioBackend {
std::vector<PortConnectData *> _port_connection_queue;
pthread_mutex_t _port_callback_mutex;
bool _port_change_flag;
void port_connect_callback (const std::string& a, const std::string& b, bool conn) {
pthread_mutex_lock (&_port_callback_mutex);
@ -359,6 +360,12 @@ class AlsaAudioBackend : public AudioBackend {
pthread_mutex_unlock (&_port_callback_mutex);
}
void port_connect_add_remove_callback () {
pthread_mutex_lock (&_port_callback_mutex);
_port_change_flag = true;
pthread_mutex_unlock (&_port_callback_mutex);
}
bool valid_port (PortHandle port) const {
return std::find (_ports.begin (), _ports.end (), (AlsaPort*)port) != _ports.end ();
}

View File

@ -47,6 +47,7 @@ DummyAudioBackend::DummyAudioBackend (AudioEngine& e, AudioBackendInfo& info)
, _systemic_input_latency (0)
, _systemic_output_latency (0)
, _processed_samples (0)
, _port_change_flag (false)
{
_instance_name = s_instance_name;
pthread_mutex_init (&_port_callback_mutex, 0);
@ -321,6 +322,7 @@ DummyAudioBackend::_start (bool /*for_latency_measurement*/)
}
engine.reconnect_ports ();
_port_change_flag = false;
if (pthread_create (&_main_thread, NULL, pthread_process, this)) {
PBD::error << _("DummyAudioBackend: cannot start.") << endmsg;
@ -671,7 +673,6 @@ DummyAudioBackend::register_system_ports()
if (!p) return -1;
set_latency_range (p, true, lr);
}
return 0;
}
@ -1006,6 +1007,7 @@ DummyAudioBackend::main_process_thread ()
_running = true;
_processed_samples = 0;
manager.registration_callback();
manager.graph_order_callback();
uint64_t clock1, clock2;
@ -1031,7 +1033,16 @@ DummyAudioBackend::main_process_thread ()
}
clock1 = g_get_monotonic_time();
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);
@ -1040,6 +1051,12 @@ DummyAudioBackend::main_process_thread ()
}
pthread_mutex_unlock (&_port_callback_mutex);
}
if (ports_changed) {
manager.registration_callback();
}
if (connections_changed) {
manager.graph_order_callback();
}
}
_running = false;
@ -1109,10 +1126,12 @@ DummyPort::DummyPort (DummyAudioBackend &b, const std::string& name, PortFlags f
_capture_latency_range.max = 0;
_playback_latency_range.min = 0;
_playback_latency_range.max = 0;
_dummy_backend.port_connect_add_remove_callback();
}
DummyPort::~DummyPort () {
disconnect_all ();
_dummy_backend.port_connect_add_remove_callback();
}

View File

@ -328,6 +328,7 @@ class DummyAudioBackend : public AudioBackend {
std::vector<PortConnectData *> _port_connection_queue;
pthread_mutex_t _port_callback_mutex;
bool _port_change_flag;
void port_connect_callback (const std::string& a, const std::string& b, bool conn) {
pthread_mutex_lock (&_port_callback_mutex);
@ -335,6 +336,12 @@ class DummyAudioBackend : public AudioBackend {
pthread_mutex_unlock (&_port_callback_mutex);
}
void port_connect_add_remove_callback () {
pthread_mutex_lock (&_port_callback_mutex);
_port_change_flag = true;
pthread_mutex_unlock (&_port_callback_mutex);
}
bool valid_port (PortHandle port) const {
return std::find (_ports.begin (), _ports.end (), (DummyPort*)port) != _ports.end ();
}