From 68ec29c2d0df9b08e44cef8747bdc607e1744087 Mon Sep 17 00:00:00 2001 From: sletz Date: Fri, 10 Jun 2011 13:59:17 +0000 Subject: [PATCH] SaveConnections/RestoreConnections moved in JackAudioDriver. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4454 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 1 + common/JackAudioDriver.cpp | 40 +++++++++++++++++++++++++++++++++++++ common/JackAudioDriver.h | 5 +++++ common/JackNetDriver.cpp | 11 ---------- common/JackNetDriver.h | 3 --- common/JackNetInterface.cpp | 39 +++++++++++++----------------------- 6 files changed, 60 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a33e237..a0ac6434 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,7 @@ Chris Caudle 2011-06-10 Stephane Letz * SaveConnections/RestoreConnections in NetDriver. + * SaveConnections/RestoreConnections moved in JackAudioDriver. 2011-06-09 Stephane Letz diff --git a/common/JackAudioDriver.cpp b/common/JackAudioDriver.cpp index 00b004f7..b96130a1 100644 --- a/common/JackAudioDriver.cpp +++ b/common/JackAudioDriver.cpp @@ -29,6 +29,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackException.h" #include +using namespace std; + namespace Jack { @@ -448,4 +450,42 @@ void JackAudioDriver::HandleLatencyCallback(int status) } } +void JackAudioDriver::SaveConnections() +{ + const char** connections; + fConnections.clear(); + + for (int i = 0; i < fCaptureChannels; ++i) { + if (fCapturePortList[i] && (connections = fGraphManager->GetConnections(fCapturePortList[i])) != 0) { + for (int j = 0; connections[j]; j++) { + fConnections.push_back(make_pair(fGraphManager->GetPort(fCapturePortList[i])->GetName(), connections[j])); + jack_info("Save connection: %s %s", fGraphManager->GetPort(fCapturePortList[i])->GetName(), connections[j]); + } + free(connections); + } + } + + for (int i = 0; i < fPlaybackChannels; ++i) { + if (fPlaybackPortList[i] && (connections = fGraphManager->GetConnections(fPlaybackPortList[i])) != 0) { + for (int j = 0; connections[j]; j++) { + fConnections.push_back(make_pair(connections[j], fGraphManager->GetPort(fPlaybackPortList[i])->GetName())); + jack_info("Save connection: %s %s", connections[j], fGraphManager->GetPort(fPlaybackPortList[i])->GetName()); + } + free(connections); + } + } +} + +void JackAudioDriver::RestoreConnections() +{ + list >::const_iterator it; + + for (it = fConnections.begin(); it != fConnections.end(); it++) { + pair connection = *it; + jack_info("Restore connection: %s %s", connection.first.c_str(), connection.second.c_str()); + fEngine->PortConnect(fClientControl.fRefNum, connection.first.c_str(), connection.second.c_str()); + } +} + + } // end of namespace diff --git a/common/JackAudioDriver.h b/common/JackAudioDriver.h index 83b0ba53..40c033d6 100644 --- a/common/JackAudioDriver.h +++ b/common/JackAudioDriver.h @@ -57,6 +57,8 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver bool fWithMonitorPorts; + std::list > fConnections; // Connections list + jack_default_audio_sample_t* GetInputBuffer(int port_index); jack_default_audio_sample_t* GetOutputBuffer(int port_index); jack_default_audio_sample_t* GetMonitorBuffer(int port_index); @@ -105,6 +107,9 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver virtual int SetBufferSize(jack_nframes_t buffer_size); virtual int SetSampleRate(jack_nframes_t sample_rate); + virtual void SaveConnections(); + virtual void RestoreConnections(); + virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2); }; diff --git a/common/JackNetDriver.cpp b/common/JackNetDriver.cpp index cdde0abb..72f01226 100644 --- a/common/JackNetDriver.cpp +++ b/common/JackNetDriver.cpp @@ -450,17 +450,6 @@ namespace Jack free(connections); } } - } - - void JackNetDriver::RestoreConnections() - { - list >::const_iterator it; - - for (it = fConnections.begin(); it != fConnections.end(); it++) { - pair connection = *it; - jack_info("Restore connection: %s %s", connection.first.c_str(), connection.second.c_str()); - fEngine->PortConnect(fClientControl.fRefNum, connection.first.c_str(), connection.second.c_str()); - } } JackMidiBuffer* JackNetDriver::GetMidiInputBuffer(int port_index) diff --git a/common/JackNetDriver.h b/common/JackNetDriver.h index f70039ac..8417ab34 100644 --- a/common/JackNetDriver.h +++ b/common/JackNetDriver.h @@ -47,8 +47,6 @@ namespace Jack int fLastTransportState; int fLastTimebaseMaster; - std::list > fConnections; // Connections list - //monitoring #ifdef JACK_MONITOR JackGnuPlotMonitor* fNetTimeMon; @@ -69,7 +67,6 @@ namespace Jack JackMidiBuffer* GetMidiOutputBuffer(int port_index); void SaveConnections(); - void RestoreConnections(); public: diff --git a/common/JackNetInterface.cpp b/common/JackNetInterface.cpp index 9bd5ddff..1ab7c513 100644 --- a/common/JackNetInterface.cpp +++ b/common/JackNetInterface.cpp @@ -618,11 +618,9 @@ namespace Jack //init loop : get a master and start, do it until connection is ok net_status_t status; - do - { + do { //first, get a master, do it until a valid connection is running - do - { + do { status = SendAvailableToMaster(); if (status == NET_SOCKET_ERROR) return false; @@ -652,8 +650,7 @@ namespace Jack SetPacketType(&fParams, SLAVE_AVAILABLE); net_status_t status; - do - { + do { //get a master status = SendAvailableToMaster(try_count); if (status == NET_SOCKET_ERROR) @@ -669,8 +666,7 @@ namespace Jack jack_log("JackNetSlaveInterface::InitRendering()"); net_status_t status; - do - { + do { //then tell the master we are ready jack_info("Initializing connection with %s...", fParams.fMasterNetName); status = SendStartToMaster(); @@ -711,8 +707,7 @@ namespace Jack //send 'AVAILABLE' until 'SLAVE_SETUP' received jack_info("Waiting for a master..."); - do - { + do { //send 'available' session_params_t net_params; memset(&net_params, 0, sizeof(session_params_t)); @@ -724,8 +719,7 @@ namespace Jack memset(&net_params, 0, sizeof(session_params_t)); rx_bytes = fSocket.CatchHost(&net_params, sizeof(session_params_t), 0); SessionParamsNToH(&net_params, &host_params); - if ((rx_bytes == SOCKET_ERROR) && (fSocket.GetError() != NET_NO_DATA)) - { + if ((rx_bytes == SOCKET_ERROR) && (fSocket.GetError() != NET_NO_DATA)) { jack_error("Can't receive : %s", StrError(NET_ERROR_CODE)); return NET_RECV_ERROR; } @@ -758,8 +752,7 @@ namespace Jack memset(&net_params, 0, sizeof(session_params_t)); SetPacketType(&fParams, START_MASTER); SessionParamsHToN(&fParams, &net_params); - if (fSocket.Send(&net_params, sizeof(session_params_t), 0) == SOCKET_ERROR) - { + if (fSocket.Send(&net_params, sizeof(session_params_t), 0) == SOCKET_ERROR) { jack_error("Error in send : %s", StrError(NET_ERROR_CODE)); return (fSocket.GetError() == NET_CONN_ERROR) ? NET_ERROR : NET_SEND_ERROR; } @@ -852,8 +845,7 @@ namespace Jack { int rx_bytes = fSocket.Recv(fRxBuffer, size, flags); //handle errors - if (rx_bytes == SOCKET_ERROR) - { + if (rx_bytes == SOCKET_ERROR) { net_error_t error = fSocket.GetError(); //no data isn't really an error in realtime processing, so just return 0 if (error == NET_NO_DATA) { @@ -879,8 +871,7 @@ namespace Jack int tx_bytes = fSocket.Send(fTxBuffer, size, flags); //handle errors - if (tx_bytes == SOCKET_ERROR) - { + if (tx_bytes == SOCKET_ERROR) { net_error_t error = fSocket.GetError(); //if a network error occurs, this exception will restart the driver if (error == NET_CONN_ERROR) { @@ -899,8 +890,7 @@ namespace Jack packet_header_t* rx_head = reinterpret_cast(fRxBuffer); //receive sync (launch the cycle) - do - { + do { rx_bytes = Recv(fParams.fMtu, 0); //connection issue, send will detect it, so don't skip the cycle (return 0) if (rx_bytes == SOCKET_ERROR) @@ -918,8 +908,7 @@ namespace Jack uint recvd_midi_pckt = 0; packet_header_t* rx_head = reinterpret_cast(fRxBuffer); - while (!fRxHeader.fIsLastPckt) - { + while (!fRxHeader.fIsLastPckt) { //how much data is queued on the rx buffer ? rx_bytes = Recv(fParams.fMtu, MSG_PEEK); @@ -975,7 +964,7 @@ namespace Jack } fTxHeader.fSubCycle = 0; fTxHeader.fDataType = 's'; - fTxHeader.fIsLastPckt = (fParams.fReturnMidiChannels == 0 && fParams.fReturnAudioChannels == 0) ? 1 : 0; + fTxHeader.fIsLastPckt = (fParams.fReturnMidiChannels == 0 && fParams.fReturnAudioChannels == 0) ? 1 : 0; fTxHeader.fPacketSize = fParams.fMtu; memcpy(fTxBuffer, &fTxHeader, HEADER_SIZE); @@ -984,8 +973,7 @@ namespace Jack int JackNetSlaveInterface::DataSend() { - uint subproc; - uint data_size; + uint subproc, data_size; //midi if (fParams.fReturnMidiChannels > 0) { @@ -1009,6 +997,7 @@ namespace Jack fTxHeader.fDataType = 'a'; data_size = fNetAudioPlaybackBuffer->RenderFromJackPorts(); fTxHeader.fNumPacket = fNetAudioPlaybackBuffer->GetNumPackets(); + for (subproc = 0; subproc < fTxHeader.fNumPacket; subproc++) { fTxHeader.fSubCycle = subproc; fTxHeader.fIsLastPckt = (subproc == (fTxHeader.fNumPacket - 1)) ? 1 : 0;