From 8a2e1e2e918c4fe3ab3bfcf85cdd0f3c3b53a325 Mon Sep 17 00:00:00 2001 From: sletz Date: Wed, 21 May 2008 07:49:42 +0000 Subject: [PATCH] Correct JackEngine::PortUnRegister, JackEngine::ClientCloseAux and JackEngine::ClientDeactivate to correctly send notifications. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2298 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 5 ++++- common/JackClient.cpp | 10 ++++------ common/JackEngine.cpp | 30 ++++++++++++++++++++++++------ common/JackGraphManager.cpp | 14 ++++++-------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f5a8eb0..16357e60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,10 @@ Fernando Lopez-Lezcano Jackdmp changes log --------------------------- +2008-05-21 Stephane Letz + + * Correct JackEngine::PortUnRegister, JackEngine::ClientCloseAux and JackEngine::ClientDeactivate to correctly send notifications. + 2008-05-20 Stephane Letz * Package number bumped to 1.90 everywhere. @@ -28,7 +32,6 @@ Fernando Lopez-Lezcano 2008-05-19 Stephane Letz * Use of placement new for dynamic port allocation is possibly not safe... so avoid that until a definitive answer is found. - * Cleanup. * JackAudioDriver::ProcessAsync and JackAudioDriver::ProcessSync were broken at some point : 0 has to be returned in all cases. 2008-05-16 Stephane Letz diff --git a/common/JackClient.cpp b/common/JackClient.cpp index 6ada2e2e..fa537465 100644 --- a/common/JackClient.cpp +++ b/common/JackClient.cpp @@ -279,16 +279,14 @@ int JackClient::Deactivate() GetClientControl()->fTransportSync = false; GetClientControl()->fTransportTimebase = false; + // We need to wait for the new engine cycle before stopping the RT thread, but this is done by ClientDeactivate int result = -1; fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result); - - jack_log("JackClient::Deactivate res = %ld ", result); - // We need to wait for the new engine cycle before stopping the RT thread, but this is done by ClientDeactivate - + jack_log("JackClient::Deactivate res = %ld", result); + // RT thread is stopped only when needed... - if (IsRealTime()) { + if (IsRealTime()) fThread->Kill(); - } return result; } diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index 75cec372..f561e371 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -560,22 +560,22 @@ int JackEngine::ClientCloseAux(int refnum, JackClientInterface* client, bool wai refnum, (client->GetClientControl()) ? client->GetClientControl()->fName : "No name"); - // Remove the client from the table - ReleaseRefnum(refnum); - - // Notify unregister + // Unregister all ports ==> notifications are sent jack_int_t ports[PORT_NUM_FOR_CLIENT]; int i; fGraphManager->GetInputPorts(refnum, ports); for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) { - NotifyPortRegistation(ports[i], false); + PortUnRegister(refnum, ports[i]); } fGraphManager->GetOutputPorts(refnum, ports); for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) { - NotifyPortRegistation(ports[i], false); + PortUnRegister(refnum, ports[i]); } + + // Remove the client from the table + ReleaseRefnum(refnum); // Remove all ports fGraphManager->RemoveAllPorts(refnum); @@ -624,6 +624,21 @@ int JackEngine::ClientDeactivate(int refnum) return -1; jack_log("JackEngine::ClientDeactivate ref = %ld name = %s", refnum, client->GetClientControl()->fName); + + // Disconnect all ports ==> notifications are sent + jack_int_t ports[PORT_NUM_FOR_CLIENT]; + int i; + + fGraphManager->GetInputPorts(refnum, ports); + for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) { + PortDisconnect(refnum, ports[i], ALL_PORTS); + } + + fGraphManager->GetOutputPorts(refnum, ports); + for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) { + PortDisconnect(refnum, ports[i], ALL_PORTS); + } + fGraphManager->Deactivate(refnum); fLastSwitchUsecs = 0; // Force switch to occur next cycle, even when called with "dead" clients @@ -664,6 +679,9 @@ int JackEngine::PortUnRegister(int refnum, jack_port_id_t port_index) { jack_log("JackEngine::PortUnRegister ref = %ld port_index = %ld", refnum, port_index); assert(fClientTable[refnum]); + + // Disconnect port ==> notification is sent + PortDisconnect(refnum, port_index, ALL_PORTS); if (fGraphManager->ReleasePort(refnum, port_index) == 0) { NotifyPortRegistation(port_index, false); diff --git a/common/JackGraphManager.cpp b/common/JackGraphManager.cpp index 850f5c91..b916b0e0 100644 --- a/common/JackGraphManager.cpp +++ b/common/JackGraphManager.cpp @@ -413,7 +413,7 @@ void JackGraphManager::DisconnectAllPorts(int refnum) // Server void JackGraphManager::DisconnectAllInput(jack_port_id_t port_index) { - jack_log("JackGraphManager::DisconnectAllInput port_index = %ld ", port_index); + jack_log("JackGraphManager::DisconnectAllInput port_index = %ld", port_index); JackConnectionManager* manager = WriteNextStateStart(); for (int i = 0; i < PORT_NUM; i++) { @@ -476,20 +476,18 @@ void JackGraphManager::Activate(int refnum) // Server void JackGraphManager::Deactivate(int refnum) { - DisconnectAllPorts(refnum); - // Disconnect only when needed if (IsDirectConnection(refnum, FREEWHEEL_DRIVER_REFNUM)) { DirectDisconnect(refnum, FREEWHEEL_DRIVER_REFNUM); } else { - jack_log("JackServer::Deactivate: client = %ld was not activated ", refnum); + jack_log("JackServer::Deactivate client = %ld was not activated", refnum); } // Disconnect only when needed if (IsDirectConnection(FREEWHEEL_DRIVER_REFNUM, refnum)) { DirectDisconnect(FREEWHEEL_DRIVER_REFNUM, refnum); } else { - jack_log("JackServer::Deactivate: client = %ld was not activated ", refnum); + jack_log("JackServer::Deactivate client = %ld was not activated", refnum); } } @@ -523,14 +521,14 @@ int JackGraphManager::Connect(jack_port_id_t port_src, jack_port_id_t port_dst) if (!src->fInUse || !dst->fInUse) { if (!src->fInUse) - jack_error("JackGraphManager::Connect: port_src = %ld not used name = %s", port_src, GetPort(port_src)->fName); + jack_error("JackGraphManager::Connect port_src = %ld not used name = %s", port_src, GetPort(port_src)->fName); if (!dst->fInUse) - jack_error("JackGraphManager::Connect: port_dst = %ld not used name = %s", port_dst, GetPort(port_dst)->fName); + jack_error("JackGraphManager::Connect port_dst = %ld not used name = %s", port_dst, GetPort(port_dst)->fName); res = -1; goto end; } if (src->fTypeId != dst->fTypeId) { - jack_error("JackGraphManager::Connect: different port types: port_src = %ld port_dst = %ld", port_src, port_dst); + jack_error("JackGraphManager::Connect different port types port_src = %ld port_dst = %ld", port_src, port_dst); res = -1; goto end; }