Commit a29992c5 authored by moret's avatar moret
Browse files

Fix NetMaster sync - Add header info for NetSlave's wrong async cycles

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2733 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 774907a2
......@@ -481,7 +481,7 @@ namespace Jack
do
{
rx_bytes = Recv ( fParams.fMtu, 0 );
if ( ( rx_bytes == 0 ) || ( rx_bytes == SOCKET_ERROR ) )
if ( rx_bytes == SOCKET_ERROR )
return rx_bytes;
}
while ( !rx_bytes && ( rx_head->fDataType != 's' ) );
......@@ -502,6 +502,7 @@ namespace Jack
{
case 'm': //midi
rx_bytes = Recv ( rx_bytes, 0 );
fRxHeader.fCycle = rx_head->fCycle;
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;
fNetMidiPlaybackBuffer->RenderFromNetwork ( rx_head->fSubCycle, rx_bytes - sizeof ( packet_header_t ) );
if ( ++midi_recvd_pckt == rx_head->fNMidiPckt )
......@@ -519,10 +520,9 @@ namespace Jack
fNetJumpCnt = 0;
break;
case 's': //sync
rx_bytes = Recv ( rx_bytes, 0 );
jack_error ( "NetMaster receive sync packets instead of data." );
fRxHeader.fCycle = rx_head->fCycle;
return 0;
break;
}
}
}
......
......@@ -48,7 +48,7 @@ namespace Jack
return fMaxBufsize;
}
void NetMidiBuffer::SetBuffer(int index, JackMidiBuffer* buffer)
void NetMidiBuffer::SetBuffer ( int index, JackMidiBuffer* buffer )
{
fPortBuffer[index] = buffer;
}
......@@ -225,16 +225,16 @@ namespace Jack
{
switch ( params->fPacketID )
{
case 0:
return SLAVE_AVAILABLE;
case 1:
return SLAVE_SETUP;
case 2:
return START_MASTER;
case 3:
return START_SLAVE;
case 4:
return KILL_MASTER;
case 0:
return SLAVE_AVAILABLE;
case 1:
return SLAVE_SETUP;
case 2:
return START_MASTER;
case 3:
return START_SLAVE;
case 4:
return KILL_MASTER;
}
return INVALID;
}
......@@ -243,22 +243,22 @@ namespace Jack
{
switch ( packet_type )
{
case INVALID:
return -1;
case SLAVE_AVAILABLE:
params->fPacketID = 0;
break;
case SLAVE_SETUP:
params->fPacketID = 1;
break;
case START_MASTER:
params->fPacketID = 2;
break;
case START_SLAVE:
params->fPacketID = 3;
break;
case KILL_MASTER:
params->fPacketID = 4;
case INVALID:
return -1;
case SLAVE_AVAILABLE:
params->fPacketID = 0;
break;
case SLAVE_SETUP:
params->fPacketID = 1;
break;
case START_MASTER:
params->fPacketID = 2;
break;
case START_SLAVE:
params->fPacketID = 3;
break;
case KILL_MASTER:
params->fPacketID = 4;
}
return 0;
}
......@@ -310,7 +310,7 @@ namespace Jack
WORD wVersionRequested = MAKEWORD ( 2, 2 );
WSADATA wsaData;
if ( WSAStartup(wVersionRequested, &wsaData) != 0 )
if ( WSAStartup ( wVersionRequested, &wsaData ) != 0 )
{
jack_error ( "WSAStartup error : %s", strerror ( NET_ERROR_CODE ) );
return -1;
......
......@@ -80,12 +80,12 @@ namespace Jack
enum _sync_packet_type
{
INVALID = 0, //...
SLAVE_AVAILABLE, //a slave is available
SLAVE_SETUP, //slave configuration
START_MASTER, //slave is ready, start master
START_SLAVE, //master is ready, activate slave
KILL_MASTER //master must stop
INVALID = 0, //...
SLAVE_AVAILABLE, //a slave is available
SLAVE_SETUP, //slave configuration
START_MASTER, //slave is ready, start master
START_SLAVE, //master is ready, activate slave
KILL_MASTER //master must stop
};
typedef enum _sync_packet_type sync_packet_type_t;
......@@ -95,24 +95,24 @@ namespace Jack
struct _packet_header
{
char fPacketType[7]; //packet type ( 'headr' )
char fDataType; //a for audio, m for midi
char fDataStream; //s for send, r for return
uint32_t fID; //to identify the slave
uint32_t fBitdepth; //bitdepth of the data samples
uint32_t fMidiDataSize; //size of midi data (if packet is 'midi typed') in bytes
uint32_t fNMidiPckt; //number of midi packets of the cycle
uint32_t fCycle; //process cycle counter
uint32_t fSubCycle; //midi/audio subcycle counter
char fIsLastPckt; //is it the last packet of a given cycle ('y' or 'n')
char fFree[13]; //unused
char fPacketType[7]; //packet type ( 'headr' )
char fDataType; //a for audio, m for midi
char fDataStream; //s for send, r for return
uint32_t fID; //to identify the slave
uint32_t fBitdepth; //bitdepth of the data samples
uint32_t fMidiDataSize; //size of midi data (if packet is 'midi typed') in bytes
uint32_t fNMidiPckt; //number of midi packets of the cycle
uint32_t fCycle; //process cycle counter
uint32_t fSubCycle; //midi/audio subcycle counter
char fIsLastPckt; //is it the last packet of a given cycle ('y' or 'n')
char fASyncWrongCycle; //is the current async cycle wrong (slave's side; 'y' or 'n')
char fFree[29]; //unused
};
//transport data ******************************************************************************
struct _net_transport_data
{
char fTransportType[10]; //test value ('transport')
jack_position_t fCurPos;
jack_transport_state_t fCurState;
};
......@@ -121,55 +121,55 @@ namespace Jack
class EXPORT NetMidiBuffer
{
private:
int fNPorts;
size_t fMaxBufsize;
int fMaxPcktSize;
char* fBuffer;
char* fNetBuffer;
JackMidiBuffer** fPortBuffer;
public:
NetMidiBuffer ( session_params_t* params, uint32_t nports, char* net_buffer );
~NetMidiBuffer();
void Reset();
size_t GetSize();
//utility
void DisplayEvents();
//jack<->buffer
int RenderFromJackPorts();
int RenderToJackPorts();
//network<->buffer
int RenderFromNetwork ( int subcycle, size_t copy_size );
int RenderToNetwork ( int subcycle, size_t total_size );
void SetBuffer ( int index, JackMidiBuffer* buffer );
JackMidiBuffer* GetBuffer ( int index );
private:
int fNPorts;
size_t fMaxBufsize;
int fMaxPcktSize;
char* fBuffer;
char* fNetBuffer;
JackMidiBuffer** fPortBuffer;
public:
NetMidiBuffer ( session_params_t* params, uint32_t nports, char* net_buffer );
~NetMidiBuffer();
void Reset();
size_t GetSize();
//utility
void DisplayEvents();
//jack<->buffer
int RenderFromJackPorts();
int RenderToJackPorts();
//network<->buffer
int RenderFromNetwork ( int subcycle, size_t copy_size );
int RenderToNetwork ( int subcycle, size_t total_size );
void SetBuffer ( int index, JackMidiBuffer* buffer );
JackMidiBuffer* GetBuffer ( int index );
};
// audio data *********************************************************************************
class EXPORT NetAudioBuffer
{
private:
int fNPorts;
jack_nframes_t fPeriodSize;
jack_nframes_t fSubPeriodSize;
size_t fSubPeriodBytesSize;
char* fNetBuffer;
sample_t** fPortBuffer;
public:
NetAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer );
~NetAudioBuffer();
size_t GetSize();
//jack<->buffer
void RenderFromJackPorts ( int subcycle );
void RenderToJackPorts ( int subcycle );
void SetBuffer ( int index, sample_t* buffer );
sample_t* GetBuffer ( int index );
private:
int fNPorts;
jack_nframes_t fPeriodSize;
jack_nframes_t fSubPeriodSize;
size_t fSubPeriodBytesSize;
char* fNetBuffer;
sample_t** fPortBuffer;
public:
NetAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer );
~NetAudioBuffer();
size_t GetSize();
//jack<->buffer
void RenderFromJackPorts ( int subcycle );
void RenderToJackPorts ( int subcycle );
void SetBuffer ( int index, sample_t* buffer );
sample_t* GetBuffer ( int index );
};
//utility *************************************************************************************
......
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