@@ -423,11 +423,11 @@ struct JackNetExtMaster : public JackNetMasterInterface { | |||||
return res; | return res; | ||||
case NET_PACKET_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; | break; | ||||
default: | default: | ||||
//decode sync | |||||
// decode sync | |||||
DecodeSyncPacket(); | DecodeSyncPacket(); | ||||
break; | break; | ||||
} | } | ||||
@@ -731,7 +731,7 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf | |||||
bool Execute() | bool Execute() | ||||
{ | { | ||||
try { | try { | ||||
// Keep running even in case of error | |||||
// keep running even in case of error | |||||
while (fThread.GetStatus() == JackThread::kRunning) { | while (fThread.GetStatus() == JackThread::kRunning) { | ||||
if (Process() == SOCKET_ERROR) { | if (Process() == SOCKET_ERROR) { | ||||
return false; | return false; | ||||
@@ -739,7 +739,7 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf | |||||
} | } | ||||
return false; | return false; | ||||
} catch (JackNetException& e) { | } catch (JackNetException& e) { | ||||
// Otherwise just restart... | |||||
// otherwise just restart... | |||||
e.PrintMessage(); | e.PrintMessage(); | ||||
jack_info("NetSlave is restarted"); | jack_info("NetSlave is restarted"); | ||||
fThread.DropRealTime(); | fThread.DropRealTime(); | ||||
@@ -756,18 +756,18 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf | |||||
int Read() | int Read() | ||||
{ | { | ||||
//receive sync (launch the cycle) | |||||
// receive sync (launch the cycle) | |||||
switch (SyncRecv()) { | switch (SyncRecv()) { | ||||
case SOCKET_ERROR: | case SOCKET_ERROR: | ||||
return SOCKET_ERROR; | return SOCKET_ERROR; | ||||
case NET_PACKET_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; | break; | ||||
default: | default: | ||||
//decode sync | |||||
// decode sync | |||||
DecodeSyncPacket(); | DecodeSyncPacket(); | ||||
break; | break; | ||||
} | } | ||||
@@ -557,11 +557,11 @@ namespace Jack | |||||
return SOCKET_ERROR; | return SOCKET_ERROR; | ||||
case NET_PACKET_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; | break; | ||||
default: | default: | ||||
//decode sync | |||||
// decode sync | |||||
DecodeSyncPacket(); | DecodeSyncPacket(); | ||||
break; | break; | ||||
} | } | ||||
@@ -485,17 +485,24 @@ namespace Jack | |||||
if (rx_head->fDataType != 's') { | if (rx_head->fDataType != 's') { | ||||
jack_error("Wrong packet type : %c", rx_head->fDataType); | jack_error("Wrong packet type : %c", rx_head->fDataType); | ||||
// Not the last packet.. | |||||
// not the last packet.. | |||||
fRxHeader.fIsLastPckt = 0; | fRxHeader.fIsLastPckt = 0; | ||||
return NET_PACKET_ERROR; | return NET_PACKET_ERROR; | ||||
} | } | ||||
fCurrentCycleOffset = fTxHeader.fCycle - rx_head->fCycle; | fCurrentCycleOffset = fTxHeader.fCycle - rx_head->fCycle; | ||||
if (fCurrentCycleOffset < fMaxCycleOffset) { | |||||
if (fCurrentCycleOffset < fMaxCycleOffset && !fSynched) { | |||||
jack_info("Synching with latency = %d", fCurrentCycleOffset); | jack_info("Synching with latency = %d", fCurrentCycleOffset); | ||||
return 0; | return 0; | ||||
} else { | } 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); | rx_bytes = Recv(rx_head->fPacketSize, 0); | ||||
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; | fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; | ||||
return rx_bytes; | return rx_bytes; | ||||
@@ -732,7 +739,7 @@ namespace Jack | |||||
} | } | ||||
while (strcmp(host_params.fPacketType, fParams.fPacketType) && (GetPacketType(&host_params) != SLAVE_SETUP) && (--try_count > 0)); | 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) { | if (try_count == 0) { | ||||
jack_error("Time out error in connect"); | jack_error("Time out error in connect"); | ||||
return NET_CONNECT_ERROR; | return NET_CONNECT_ERROR; | ||||
@@ -873,7 +880,7 @@ namespace Jack | |||||
if (rx_head->fDataType != 's') { | if (rx_head->fDataType != 's') { | ||||
jack_error("Wrong packet type : %c", rx_head->fDataType); | jack_error("Wrong packet type : %c", rx_head->fDataType); | ||||
// Not the last packet... | |||||
// not the last packet... | |||||
fRxHeader.fIsLastPckt = 0; | fRxHeader.fIsLastPckt = 0; | ||||
return NET_PACKET_ERROR; | return NET_PACKET_ERROR; | ||||
} | } | ||||
@@ -32,12 +32,13 @@ namespace Jack | |||||
#define SLAVE_SETUP_RETRY 5 | #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. | \Brief This class describes the basic Net Interface, used by both master and slave. | ||||
@@ -137,6 +138,7 @@ namespace Jack | |||||
bool fRunning; | bool fRunning; | ||||
int fCurrentCycleOffset; | int fCurrentCycleOffset; | ||||
int fMaxCycleOffset; | int fMaxCycleOffset; | ||||
bool fSynched; | |||||
bool Init(); | bool Init(); | ||||
bool SetParams(); | bool SetParams(); | ||||
@@ -161,10 +163,19 @@ namespace Jack | |||||
public: | 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) | 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() | virtual~JackNetMasterInterface() | ||||
@@ -524,7 +524,7 @@ namespace Jack | |||||
return res; | return res; | ||||
case NET_PACKET_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; | break; | ||||
default: | default: | ||||
@@ -680,7 +680,7 @@ namespace Jack | |||||
Cleanup(); | Cleanup(); | ||||
} | } | ||||
if (port_num > 0) { | |||||
if (port_num > 0) { | |||||
int sub_period_bytes_size; | int sub_period_bytes_size; | ||||
@@ -937,7 +937,6 @@ namespace Jack | |||||
#endif | #endif | ||||
NetIntAudioBuffer::NetIntAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer) | NetIntAudioBuffer::NetIntAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer) | ||||
: NetAudioBuffer(params, nports, net_buffer) | : NetAudioBuffer(params, nports, net_buffer) | ||||
{ | { | ||||
@@ -38,8 +38,8 @@ using namespace std; | |||||
#endif | #endif | ||||
#endif | #endif | ||||
#define MASTER_PROTOCOL 6 | |||||
#define SLAVE_PROTOCOL 6 | |||||
#define MASTER_PROTOCOL 6 | |||||
#define SLAVE_PROTOCOL 6 | |||||
#define NET_PACKET_ERROR -2 | #define NET_PACKET_ERROR -2 | ||||