| @@ -423,11 +423,11 @@ struct JackNetExtMaster : public JackNetMasterInterface { | |||
| return res; | |||
| case NET_PACKET_ERROR: | |||
| // Since sync packet is incorrect, don't decode it and continue with data | |||
| // since sync packet is incorrect, don't decode it and continue with data | |||
| break; | |||
| default: | |||
| //decode sync | |||
| // decode sync | |||
| DecodeSyncPacket(); | |||
| break; | |||
| } | |||
| @@ -731,7 +731,7 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf | |||
| bool Execute() | |||
| { | |||
| try { | |||
| // Keep running even in case of error | |||
| // keep running even in case of error | |||
| while (fThread.GetStatus() == JackThread::kRunning) { | |||
| if (Process() == SOCKET_ERROR) { | |||
| return false; | |||
| @@ -739,7 +739,7 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf | |||
| } | |||
| return false; | |||
| } catch (JackNetException& e) { | |||
| // Otherwise just restart... | |||
| // otherwise just restart... | |||
| e.PrintMessage(); | |||
| jack_info("NetSlave is restarted"); | |||
| fThread.DropRealTime(); | |||
| @@ -756,18 +756,18 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf | |||
| int Read() | |||
| { | |||
| //receive sync (launch the cycle) | |||
| // receive sync (launch the cycle) | |||
| switch (SyncRecv()) { | |||
| case SOCKET_ERROR: | |||
| return SOCKET_ERROR; | |||
| case NET_PACKET_ERROR: | |||
| // Since sync packet is incorrect, don't decode it and continue with data | |||
| // since sync packet is incorrect, don't decode it and continue with data | |||
| break; | |||
| default: | |||
| //decode sync | |||
| // decode sync | |||
| DecodeSyncPacket(); | |||
| break; | |||
| } | |||
| @@ -557,11 +557,11 @@ namespace Jack | |||
| return SOCKET_ERROR; | |||
| case NET_PACKET_ERROR: | |||
| // Since sync packet is incorrect, don't decode it and continue with data | |||
| // since sync packet is incorrect, don't decode it and continue with data | |||
| break; | |||
| default: | |||
| //decode sync | |||
| // decode sync | |||
| DecodeSyncPacket(); | |||
| break; | |||
| } | |||
| @@ -485,17 +485,24 @@ namespace Jack | |||
| if (rx_head->fDataType != 's') { | |||
| jack_error("Wrong packet type : %c", rx_head->fDataType); | |||
| // Not the last packet.. | |||
| // not the last packet.. | |||
| fRxHeader.fIsLastPckt = 0; | |||
| return NET_PACKET_ERROR; | |||
| } | |||
| fCurrentCycleOffset = fTxHeader.fCycle - rx_head->fCycle; | |||
| if (fCurrentCycleOffset < fMaxCycleOffset) { | |||
| if (fCurrentCycleOffset < fMaxCycleOffset && !fSynched) { | |||
| jack_info("Synching with latency = %d", fCurrentCycleOffset); | |||
| return 0; | |||
| } else { | |||
| if (fCurrentCycleOffset == fMaxCycleOffset) { | |||
| // when the sync offset is reached | |||
| fSynched = true; | |||
| } else if (abs(fCurrentCycleOffset - fMaxCycleOffset) >= NETWORK_RESYNCH_LATENCY) { | |||
| jack_info("Resync connection..."); | |||
| fSynched = false; | |||
| } | |||
| rx_bytes = Recv(rx_head->fPacketSize, 0); | |||
| fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; | |||
| return rx_bytes; | |||
| @@ -732,7 +739,7 @@ namespace Jack | |||
| } | |||
| while (strcmp(host_params.fPacketType, fParams.fPacketType) && (GetPacketType(&host_params) != SLAVE_SETUP) && (--try_count > 0)); | |||
| // Time out failure.. | |||
| // time out failure.. | |||
| if (try_count == 0) { | |||
| jack_error("Time out error in connect"); | |||
| return NET_CONNECT_ERROR; | |||
| @@ -873,7 +880,7 @@ namespace Jack | |||
| if (rx_head->fDataType != 's') { | |||
| jack_error("Wrong packet type : %c", rx_head->fDataType); | |||
| // Not the last packet... | |||
| // not the last packet... | |||
| fRxHeader.fIsLastPckt = 0; | |||
| return NET_PACKET_ERROR; | |||
| } | |||
| @@ -32,12 +32,13 @@ namespace Jack | |||
| #define SLAVE_SETUP_RETRY 5 | |||
| #define MANAGER_INIT_TIMEOUT 2000000 // in usec | |||
| #define MASTER_INIT_TIMEOUT 1000000 * 10 // in usec | |||
| #define SLAVE_INIT_TIMEOUT 1000000 * 10 // in usec | |||
| #define PACKET_TIMEOUT 500000 // in usec | |||
| #define MANAGER_INIT_TIMEOUT 1000000 * 2 // in usec | |||
| #define MASTER_INIT_TIMEOUT 1000000 * 10 // in usec | |||
| #define SLAVE_INIT_TIMEOUT 1000000 * 10 // in usec | |||
| #define PACKET_TIMEOUT 500000 // in usec | |||
| #define NETWORK_MAX_LATENCY 20 | |||
| #define NETWORK_MAX_LATENCY 20 // maximun possile latency in network master/slave loop | |||
| #define NETWORK_RESYNCH_LATENCY 3 // number of cycles offset before a resync is done.... | |||
| /** | |||
| \Brief This class describes the basic Net Interface, used by both master and slave. | |||
| @@ -137,6 +138,7 @@ namespace Jack | |||
| bool fRunning; | |||
| int fCurrentCycleOffset; | |||
| int fMaxCycleOffset; | |||
| bool fSynched; | |||
| bool Init(); | |||
| bool SetParams(); | |||
| @@ -161,10 +163,19 @@ namespace Jack | |||
| public: | |||
| JackNetMasterInterface() : JackNetInterface(), fRunning(false), fCurrentCycleOffset(0), fMaxCycleOffset(0) | |||
| JackNetMasterInterface() | |||
| : JackNetInterface(), | |||
| fRunning(false), | |||
| fCurrentCycleOffset(0), | |||
| fMaxCycleOffset(0), | |||
| fSynched(false) | |||
| {} | |||
| JackNetMasterInterface(session_params_t& params, JackNetSocket& socket, const char* multicast_ip) | |||
| : JackNetInterface(params, socket, multicast_ip), fRunning(false), fCurrentCycleOffset(0), fMaxCycleOffset(0) | |||
| : JackNetInterface(params, socket, multicast_ip), | |||
| fRunning(false), | |||
| fCurrentCycleOffset(0), | |||
| fMaxCycleOffset(0), | |||
| fSynched(false) | |||
| {} | |||
| virtual~JackNetMasterInterface() | |||
| @@ -524,7 +524,7 @@ namespace Jack | |||
| return res; | |||
| case NET_PACKET_ERROR: | |||
| // Since sync packet is incorrect, don't decode it and continue with data | |||
| // Since sync packet is incorrect, don't decode it and continue with data | |||
| break; | |||
| default: | |||
| @@ -680,7 +680,7 @@ namespace Jack | |||
| Cleanup(); | |||
| } | |||
| if (port_num > 0) { | |||
| if (port_num > 0) { | |||
| int sub_period_bytes_size; | |||
| @@ -937,7 +937,6 @@ namespace Jack | |||
| #endif | |||
| NetIntAudioBuffer::NetIntAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer) | |||
| : NetAudioBuffer(params, nports, net_buffer) | |||
| { | |||
| @@ -38,8 +38,8 @@ using namespace std; | |||
| #endif | |||
| #endif | |||
| #define MASTER_PROTOCOL 6 | |||
| #define SLAVE_PROTOCOL 6 | |||
| #define MASTER_PROTOCOL 6 | |||
| #define SLAVE_PROTOCOL 6 | |||
| #define NET_PACKET_ERROR -2 | |||