Commit dbf9b715 authored by Stephane Letz's avatar Stephane Letz
Browse files

Distinguish SYNC_PACKET_ERROR and DATA_PACKET_ERROR in NetJack2.

parent ddf306b8
......@@ -86,6 +86,7 @@ extern "C"
typedef int (*JackNetSlaveSampleRateCallback) (jack_nframes_t nframes, void *arg);
typedef void (*JackNetSlaveShutdownCallback) (void* data);
typedef int (*JackNetSlaveRestartCallback) (void* data);
typedef int (*JackNetSlaveErrorCallback) (int error_code, void* data);
LIB_EXPORT jack_net_slave_t* jack_net_slave_open(const char* ip, int port, const char* name, jack_slave_t* request, jack_master_t* result);
LIB_EXPORT int jack_net_slave_close(jack_net_slave_t* net);
......@@ -99,6 +100,7 @@ extern "C"
LIB_EXPORT int jack_set_net_slave_sample_rate_callback(jack_net_slave_t* net, JackNetSlaveSampleRateCallback samplerate_callback, void *arg);
LIB_EXPORT int jack_set_net_slave_shutdown_callback(jack_net_slave_t* net, JackNetSlaveShutdownCallback shutdown_callback, void *arg);
LIB_EXPORT int jack_set_net_slave_restart_callback(jack_net_slave_t* net, JackNetSlaveRestartCallback restart_callback, void *arg);
LIB_EXPORT int jack_set_net_slave_error_callback(jack_net_slave_t* net, JackNetSlaveErrorCallback error_callback, void *arg);
// NetJack master API
......@@ -435,7 +437,7 @@ struct JackNetExtMaster : public JackNetMasterInterface {
case SOCKET_ERROR:
return res;
case NET_PACKET_ERROR:
case SYNC_PACKET_ERROR:
// since sync packet is incorrect, don't decode it and continue with data
break;
......@@ -507,7 +509,10 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
void* fShutdownArg;
JackNetSlaveRestartCallback fRestartCallback;
void* fRestartArg;
void* fRestartArg;
JackNetSlaveErrorCallback fErrorCallback;
void* fErrorArg;
JackNetSlaveBufferSizeCallback fBufferSizeCallback;
void* fBufferSizeArg;
......@@ -532,6 +537,7 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
fProcessCallback(NULL),fProcessArg(NULL),
fShutdownCallback(NULL), fShutdownArg(NULL),
fRestartCallback(NULL), fRestartArg(NULL),
fErrorCallback(NULL), fErrorArg(NULL),
fBufferSizeCallback(NULL), fBufferSizeArg(NULL),
fSampleRateCallback(NULL), fSampleRateArg(NULL),
fAudioCaptureBuffer(NULL), fAudioPlaybackBuffer(NULL),
......@@ -806,8 +812,11 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
case SOCKET_ERROR:
return SOCKET_ERROR;
case NET_PACKET_ERROR:
case SYNC_PACKET_ERROR:
// since sync packet is incorrect, don't decode it and continue with data
if (fErrorCallback) {
fErrorCallback(SYNC_PACKET_ERROR, fErrorArg);
}
break;
default:
......@@ -816,7 +825,11 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
break;
}
return DataRecv();
int res = DataRecv();
if (res == DATA_PACKET_ERROR && fErrorCallback) {
fErrorCallback(DATA_PACKET_ERROR, fErrorArg);
}
return res;
}
int Write()
......@@ -911,6 +924,17 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
return 0;
}
}
int SetErrorCallback(JackNetSlaveErrorCallback error_callback, void *arg)
{
if (fThread.GetStatus() == JackThread::kRunning) {
return -1;
} else {
fErrorCallback = error_callback;
fErrorArg = arg;
return 0;
}
}
int SetBufferSizeCallback(JackNetSlaveBufferSizeCallback bufsize_callback, void *arg)
{
......@@ -1077,6 +1101,12 @@ LIB_EXPORT int jack_set_net_slave_restart_callback(jack_net_slave_t *net, JackNe
return slave->SetRestartCallback(restart_callback, arg);
}
LIB_EXPORT int jack_set_net_slave_error_callback(jack_net_slave_t *net, JackNetSlaveErrorCallback error_callback, void *arg)
{
JackNetExtSlave* slave = (JackNetExtSlave*)net;
return slave->SetErrorCallback(error_callback, arg);
}
// Master API
LIB_EXPORT jack_net_master_t* jack_net_master_open(const char* ip, int port, const char* name, jack_master_t* request, jack_slave_t* result)
......
......@@ -355,7 +355,7 @@ namespace Jack
case SOCKET_ERROR:
return 0;
case NET_PACKET_ERROR:
case SYNC_PACKET_ERROR:
// Since sync packet is incorrect, don't decode it and continue with data
break;
......
......@@ -569,7 +569,7 @@ namespace Jack
case SOCKET_ERROR:
return SOCKET_ERROR;
case NET_PACKET_ERROR:
case SYNC_PACKET_ERROR:
// since sync packet is incorrect, don't decode it and continue with data
break;
......@@ -593,7 +593,7 @@ namespace Jack
case SOCKET_ERROR:
return SOCKET_ERROR;
case NET_PACKET_ERROR:
case DATA_PACKET_ERROR:
jack_time_t cur_time = GetMicroSeconds();
NotifyXRun(cur_time, float(cur_time - fBeginDateUst)); // Better this value than nothing...
break;
......
......@@ -227,7 +227,7 @@ namespace Jack
int JackNetInterface::FinishRecv(NetAudioBuffer* buffer)
{
buffer->RenderToJackPorts();
return NET_PACKET_ERROR;
return DATA_PACKET_ERROR;
}
NetAudioBuffer* JackNetInterface::AudioBufferFactory(int nports, char* buffer)
......@@ -488,7 +488,7 @@ namespace Jack
jack_error("Wrong packet type : %c", rx_head->fDataType);
// not the last packet..
fRxHeader.fIsLastPckt = 0;
return NET_PACKET_ERROR;
return SYNC_PACKET_ERROR;
}
fCurrentCycleOffset = fTxHeader.fCycle - rx_head->fCycle;
......@@ -874,7 +874,7 @@ namespace Jack
jack_error("Wrong packet type : %c", rx_head->fDataType);
// not the last packet...
fRxHeader.fIsLastPckt = 0;
return NET_PACKET_ERROR;
return SYNC_PACKET_ERROR;
}
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;
......
......@@ -537,7 +537,7 @@ namespace Jack
case SOCKET_ERROR:
return res;
case NET_PACKET_ERROR:
case SYNC_PACKET_ERROR:
// Since sync packet is incorrect, don't decode it and continue with data
break;
......@@ -559,7 +559,7 @@ namespace Jack
case SOCKET_ERROR:
return res;
case NET_PACKET_ERROR:
case DATA_PACKET_ERROR:
// Well not a real XRun...
JackServerGlobals::fInstance->GetEngine()->NotifyClientXRun(ALL_CLIENTS);
break;
......
......@@ -247,7 +247,7 @@ namespace Jack
if (sub_cycle != fLastSubCycle + 1) {
jack_error("Packet(s) missing from... %d %d", fLastSubCycle, sub_cycle);
res = NET_PACKET_ERROR;
res = DATA_PACKET_ERROR;
} else {
res = 0;
}
......
......@@ -41,7 +41,8 @@ using namespace std;
#define NETWORK_PROTOCOL 7
#define NET_SYNCHING 0
#define NET_PACKET_ERROR -2
#define SYNC_PACKET_ERROR -2
#define DATA_PACKET_ERROR -3
#define OPTIMIZED_PROTOCOL 1
......
......@@ -36,7 +36,8 @@ extern "C"
#define NO_ERROR 0
#define SOCKET_ERROR -1
#define NET_PACKET_ERROR -2
#define SYNC_PACKET_ERROR -2
#define DATA_PACKET_ERROR -3
#define RESTART_CB_API 1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment