From 495e1cb78b964b2fee305ffe48a82652567e47c1 Mon Sep 17 00:00:00 2001 From: sletz Date: Sat, 30 Aug 2008 07:46:31 +0000 Subject: [PATCH] Correct JackNetAdapter RT thread handling, cleanup. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2845 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackNetAdapter.cpp | 14 +++++++------- common/JackNetDriver.cpp | 4 ---- common/JackNetInterface.cpp | 19 +++++++++++-------- common/JackNetInterface.h | 6 ++++++ common/JackNetManager.cpp | 4 ---- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/common/JackNetAdapter.cpp b/common/JackNetAdapter.cpp index e00da30f..0afcfe54 100644 --- a/common/JackNetAdapter.cpp +++ b/common/JackNetAdapter.cpp @@ -14,7 +14,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #include "JackNetAdapter.h" @@ -22,9 +21,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackServer.h" #include "JackEngineControl.h" -#define DEFAULT_MULTICAST_IP "225.3.19.154" -#define DEFAULT_PORT 19000 - namespace Jack { JackNetAdapter::JackNetAdapter ( jack_client_t* jack_client, jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params ) @@ -150,7 +146,6 @@ namespace Jack return -1; } - fThread.AcquireRealTime ( JackServer::fInstance->GetEngineControl()->fPriority - 1 ); return 0; } @@ -221,10 +216,15 @@ namespace Jack //set audio adapter parameters SetAdaptedBufferSize ( fParams.fPeriodSize ); SetAdaptedSampleRate ( fParams.fSampleRate ); - + + if (fThread.AcquireRealTime ( JackServer::fInstance->GetEngineControl()->fPriority - 1 ) < 0) { + jack_error("AcquireRealTime error"); + } else { + set_threaded_log_function(); + } + //init done, display parameters SessionParamsDisplay ( &fParams ); - return true; } diff --git a/common/JackNetDriver.cpp b/common/JackNetDriver.cpp index bf4683e1..9a3ec943 100644 --- a/common/JackNetDriver.cpp +++ b/common/JackNetDriver.cpp @@ -15,7 +15,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #include "JackNetDriver.h" @@ -26,9 +25,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackThreadedDriver.h" #include "JackWaitThreadedDriver.h" -#define DEFAULT_MULTICAST_IP "225.3.19.154" -#define DEFAULT_PORT 19000 - using namespace std; namespace Jack diff --git a/common/JackNetInterface.cpp b/common/JackNetInterface.cpp index 6b102b28..47367e2d 100644 --- a/common/JackNetInterface.cpp +++ b/common/JackNetInterface.cpp @@ -15,15 +15,11 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #include "JackNetInterface.h" #include "JackException.h" -#define DEFAULT_MULTICAST_IP "225.3.19.154" -#define DEFAULT_PORT 19000 - using namespace std; namespace Jack @@ -196,7 +192,7 @@ namespace Jack } //timeout on receive (for init) - if ( fSocket.SetTimeOut ( 1000000 ) < 0 ) + if ( fSocket.SetTimeOut ( MASTER_INIT_TIMEOUT ) < 0 ) jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); //connect @@ -222,8 +218,8 @@ namespace Jack return false; } } - while ( ( GetPacketType ( ¶ms ) != START_MASTER ) && ( ++attempt < 5 ) ); - if ( attempt == 5 ) + while ( ( GetPacketType ( ¶ms ) != START_MASTER ) && ( ++attempt < SLAVE_SETUP_RETRY ) ); + if ( attempt == SLAVE_SETUP_RETRY ) { jack_error ( "Slave doesn't respond, exiting." ); return false; @@ -415,6 +411,7 @@ namespace Jack else rx_bytes = Recv ( rx_head->fPacketSize, 0 ); break; + case 'n' : //normal use of the network : // - extra latency is set to one cycle, what is the time needed to receive streams using full network bandwidth @@ -425,6 +422,7 @@ namespace Jack else rx_bytes = Recv ( rx_head->fPacketSize, 0 ); break; + case 'f' : //fast mode suppose the network bandwith is larger than required for the transmission (only a few channels for example) // - packets can be quickly received, quickly is here relative to the cycle duration @@ -435,6 +433,7 @@ namespace Jack jack_error ( "'%s' can't run in fast network mode, data received too late (%d cycle(s) offset)", fParams.fName, cycle_offset ); break; } + fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; return rx_bytes; } @@ -473,6 +472,7 @@ namespace Jack fNetMidiPlaybackBuffer->RenderToJackPorts(); jumpcnt = 0; break; + case 'a': //audio Recv ( rx_head->fPacketSize, 0 ); if ( !IsNextPacket() ) @@ -483,6 +483,7 @@ namespace Jack fNetAudioPlaybackBuffer->RenderToJackPorts ( rx_head->fSubCycle ); jumpcnt = 0; break; + case 's': //sync if ( rx_head->fCycle == fTxHeader.fCycle ) return 0; @@ -548,7 +549,7 @@ namespace Jack jack_error ( "Can't bind the socket : %s", StrError ( NET_ERROR_CODE ) ); //timeout on receive - if ( fSocket.SetTimeOut ( 2000000 ) == SOCKET_ERROR ) + if ( fSocket.SetTimeOut ( SLAVE_INIT_TIMEOUT ) == SOCKET_ERROR ) jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); //disable local loop @@ -708,6 +709,7 @@ namespace Jack if ( ++recvd_midi_pckt == rx_head->fNMidiPckt ) fNetMidiCaptureBuffer->RenderToJackPorts(); break; + case 'a': //audio rx_bytes = Recv ( rx_head->fPacketSize, 0 ); if ( !IsNextPacket() ) @@ -717,6 +719,7 @@ namespace Jack fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; fNetAudioCaptureBuffer->RenderToJackPorts ( rx_head->fSubCycle ); break; + case 's': //sync jack_info ( "NetSlave : overloaded, skipping receive." ); return 0; diff --git a/common/JackNetInterface.h b/common/JackNetInterface.h index a0ae39ae..20f5a326 100644 --- a/common/JackNetInterface.h +++ b/common/JackNetInterface.h @@ -162,4 +162,10 @@ namespace Jack }; } +#define DEFAULT_MULTICAST_IP "225.3.19.154" +#define DEFAULT_PORT 19000 +#define SLAVE_SETUP_RETRY 5 +#define MASTER_INIT_TIMEOUT 1000000 // in usec +#define SLAVE_INIT_TIMEOUT 2000000 // in usec + #endif diff --git a/common/JackNetManager.cpp b/common/JackNetManager.cpp index 3d64e9e7..f32f10f7 100644 --- a/common/JackNetManager.cpp +++ b/common/JackNetManager.cpp @@ -14,7 +14,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #if defined(HAVE_CONFIG_H) @@ -23,9 +22,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackNetManager.h" -#define DEFAULT_MULTICAST_IP "225.3.19.154" -#define DEFAULT_PORT 19000 - using namespace std; namespace Jack