Browse Source

Correct NetInterface

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2776 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.90
moret 17 years ago
parent
commit
9c9f0832d8
11 changed files with 490 additions and 467 deletions
  1. +38
    -38
      common/JackNetDriver.cpp
  2. +111
    -82
      common/JackNetInterface.cpp
  3. +88
    -92
      common/JackNetInterface.h
  4. +30
    -32
      common/JackNetManager.cpp
  5. +7
    -7
      common/JackNetManager.h
  6. +2
    -2
      common/JackNetTool.cpp
  7. +18
    -18
      common/JackNetUnixSocket.cpp
  8. +59
    -59
      common/JackNetUnixSocket.h
  9. +2
    -2
      common/JackPlatformNetSocket.h
  10. +78
    -78
      windows/JackNetWinSocket.cpp
  11. +57
    -57
      windows/JackNetWinSocket.h

+ 38
- 38
common/JackNetDriver.cpp View File

@@ -112,9 +112,9 @@ namespace Jack
fParams.fReturnAudioChannels = fPlaybackChannels;
fParams.fSlaveSyncMode = fEngineControl->fSyncMode;

//display some additional infos
jack_info ( "NetAdapter started in %s mode %s Master's transport sync.",
( fParams.fSlaveSyncMode ) ? "sync" : "async", ( fParams.fTransportSync ) ? "with" : "without" );
//display some additional infos
jack_info ( "NetAdapter started in %s mode %s Master's transport sync.",
( fParams.fSlaveSyncMode ) ? "sync" : "async", ( fParams.fTransportSync ) ? "with" : "without" );

if ( !JackNetSlaveInterface::Init() )
return false;;
@@ -130,7 +130,7 @@ namespace Jack
fMidiCapturePortList = new jack_port_id_t [fParams.fSendMidiChannels];
fMidiPlaybackPortList = new jack_port_id_t [fParams.fReturnMidiChannels];

//register jack ports
//register jack ports
if ( AllocPorts() != 0 )
{
jack_error ( "Can't allocate ports." );
@@ -341,12 +341,12 @@ namespace Jack
int JackNetDriver::Read()
{
uint midi_port_index;
int audio_port_index;
uint audio_port_index;

//buffers
for ( midi_port_index = 0; midi_port_index < fParams.fSendMidiChannels; midi_port_index++ )
fNetMidiCaptureBuffer->SetBuffer ( midi_port_index, GetMidiInputBuffer ( midi_port_index ) );
for ( audio_port_index = 0; audio_port_index < fCaptureChannels; audio_port_index++ )
for ( audio_port_index = 0; audio_port_index < fParams.fSendAudioChannels; audio_port_index++ )
fNetAudioCaptureBuffer->SetBuffer ( audio_port_index, GetInputBuffer ( audio_port_index ) );

#ifdef JACK_MONITOR
@@ -396,7 +396,7 @@ namespace Jack
memset ( fTxData, 0, fPayloadSize );
SetSyncPacket();

//send sync
//send sync
if ( SyncSend() == SOCKET_ERROR )
return SOCKET_ERROR;

@@ -404,7 +404,7 @@ namespace Jack
fNetTimeMon->Add ( ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f );
#endif

//send data
//send data
if ( DataSend() == SOCKET_ERROR )
return SOCKET_ERROR;

@@ -540,36 +540,36 @@ namespace Jack
param = ( const jack_driver_param_t* ) node->data;
switch ( param->character )
{
case 'a' :
multicast_ip = strdup ( param->value.str );
break;
case 'p':
udp_port = param->value.ui;
break;
case 'M':
mtu = param->value.i;
break;
case 'C':
audio_capture_ports = param->value.i;
break;
case 'P':
audio_playback_ports = param->value.i;
break;
case 'i':
midi_input_ports = param->value.i;
break;
case 'o':
midi_output_ports = param->value.i;
break;
case 'n' :
strncpy ( name, param->value.str, JACK_CLIENT_NAME_SIZE );
break;
case 't' :
transport_sync = param->value.ui;
break;
case 'f' :
network_mode = 'f';
break;
case 'a' :
multicast_ip = strdup ( param->value.str );
break;
case 'p':
udp_port = param->value.ui;
break;
case 'M':
mtu = param->value.i;
break;
case 'C':
audio_capture_ports = param->value.i;
break;
case 'P':
audio_playback_ports = param->value.i;
break;
case 'i':
midi_input_ports = param->value.i;
break;
case 'o':
midi_output_ports = param->value.i;
break;
case 'n' :
strncpy ( name, param->value.str, JACK_CLIENT_NAME_SIZE );
break;
case 't' :
transport_sync = param->value.ui;
break;
case 'f' :
network_mode = 'f';
break;
}
}



+ 111
- 82
common/JackNetInterface.cpp View File

@@ -32,7 +32,7 @@ namespace Jack

JackNetInterface::JackNetInterface ( const char* ip, int port ) : fSocket ( ip, port )
{
jack_log ( "JackNetInterface::JackNetInterface ip = %s port = %d", ip, port );
jack_log ( "JackNetInterface::JackNetInterface ip = %s port = %d", ip, port );

fMulticastIP = new char[strlen ( ip ) + 1];
strcpy ( fMulticastIP, ip );
@@ -40,17 +40,16 @@ namespace Jack

JackNetInterface::JackNetInterface ( session_params_t& params, JackNetSocket& socket ) : fSocket ( socket )
{
jack_log ( "JackNetInterface::JackNetInterface ID = %d", params.fID );
jack_log ( "JackNetInterface::JackNetInterface ID = %d", params.fID );

fParams = params;
SetParams();
fMulticastIP = new char[strlen ( fSocket.GetSendIP() ) + 1];
strcpy ( fMulticastIP, fSocket.GetSendIP() );
}

JackNetInterface::~JackNetInterface()
{
jack_log ( "JackNetInterface::~JackNetInterface" );
jack_log ( "JackNetInterface::~JackNetInterface" );
fSocket.Close();
SocketAPIEnd();
delete[] fTxBuffer;
@@ -64,8 +63,6 @@ namespace Jack

void JackNetInterface::SetParams()
{
jack_log ( "JackNetInterface::SetParams" );

fNSubProcess = fParams.fPeriodSize / fParams.fFramesPerPacket;

//TX header init
@@ -92,18 +89,6 @@ namespace Jack
fTxData = fTxBuffer + sizeof ( packet_header_t );
fRxData = fRxBuffer + sizeof ( packet_header_t );

//midi net buffers
fNetMidiCaptureBuffer = new NetMidiBuffer ( &fParams, fParams.fSendMidiChannels, fRxData );
fNetMidiPlaybackBuffer = new NetMidiBuffer ( &fParams, fParams.fReturnMidiChannels, fTxData );

//audio net buffers
fNetAudioCaptureBuffer = new NetAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
fNetAudioPlaybackBuffer = new NetAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );

//audio netbuffer length
fAudioTxLen = sizeof ( packet_header_t ) + fNetAudioPlaybackBuffer->GetSize();
fAudioRxLen = sizeof ( packet_header_t ) + fNetAudioCaptureBuffer->GetSize();

//payload size
fPayloadSize = fParams.fMtu - sizeof ( packet_header_t );
}
@@ -112,7 +97,7 @@ namespace Jack

bool JackNetSlaveInterface::Init()
{
jack_log ( "JackNetSlaveInterface::NetInit()" );
jack_log ( "JackNetSlaveInterface::Init()" );

//set the parameters to send
strcpy ( fParams.fPacketType, "params" );
@@ -214,6 +199,28 @@ namespace Jack
return NET_ROLLING;
}

void JackNetSlaveInterface::SetParams()
{
jack_log ( "JackNetSlaveInterface::SetParams" );

JackNetInterface::SetParams();

fTxHeader.fDataStream = 'r';
fRxHeader.fDataStream = 's';

//midi net buffers
fNetMidiCaptureBuffer = new NetMidiBuffer ( &fParams, fParams.fSendMidiChannels, fRxData );
fNetMidiPlaybackBuffer = new NetMidiBuffer ( &fParams, fParams.fReturnMidiChannels, fTxData );

//audio net buffers
fNetAudioCaptureBuffer = new NetAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
fNetAudioPlaybackBuffer = new NetAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );

//audio netbuffer length
fAudioTxLen = sizeof ( packet_header_t ) + fNetAudioPlaybackBuffer->GetSize();
fAudioRxLen = sizeof ( packet_header_t ) + fNetAudioCaptureBuffer->GetSize();
}

int JackNetSlaveInterface::Recv ( size_t size, int flags )
{
int rx_bytes = fSocket.Recv ( fRxBuffer, size, flags );
@@ -291,27 +298,27 @@ namespace Jack
{
switch ( rx_head->fDataType )
{
case 'm': //midi
rx_bytes = Recv ( rx_head->fPacketSize, 0 );
fRxHeader.fCycle = rx_head->fCycle;
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;
fNetMidiCaptureBuffer->RenderFromNetwork ( rx_head->fSubCycle, rx_bytes - sizeof ( packet_header_t ) );
if ( ++recvd_midi_pckt == rx_head->fNMidiPckt )
fNetMidiCaptureBuffer->RenderToJackPorts();
break;
case 'a': //audio
rx_bytes = Recv ( rx_head->fPacketSize, 0 );
if ( !IsNextPacket ( &fRxHeader, rx_head, fNSubProcess ) )
jack_error ( "Packet(s) missing..." );
fRxHeader.fCycle = rx_head->fCycle;
fRxHeader.fSubCycle = rx_head->fSubCycle;
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;
fNetAudioCaptureBuffer->RenderToJackPorts ( rx_head->fSubCycle );
break;
case 's': //sync
jack_info ( "NetSlave : overloaded, skipping receive." );
fRxHeader.fCycle = rx_head->fCycle;
return 0;
case 'm': //midi
rx_bytes = Recv ( rx_head->fPacketSize, 0 );
fRxHeader.fCycle = rx_head->fCycle;
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;
fNetMidiCaptureBuffer->RenderFromNetwork ( rx_head->fSubCycle, rx_bytes - sizeof ( packet_header_t ) );
if ( ++recvd_midi_pckt == rx_head->fNMidiPckt )
fNetMidiCaptureBuffer->RenderToJackPorts();
break;
case 'a': //audio
rx_bytes = Recv ( rx_head->fPacketSize, 0 );
if ( !IsNextPacket ( &fRxHeader, rx_head, fNSubProcess ) )
jack_error ( "Packet(s) missing..." );
fRxHeader.fCycle = rx_head->fCycle;
fRxHeader.fSubCycle = rx_head->fSubCycle;
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;
fNetAudioCaptureBuffer->RenderToJackPorts ( rx_head->fSubCycle );
break;
case 's': //sync
jack_info ( "NetSlave : overloaded, skipping receive." );
fRxHeader.fCycle = rx_head->fCycle;
return 0;
}
}
}
@@ -448,6 +455,28 @@ namespace Jack
return true;
}

void JackNetMasterInterface::SetParams()
{
jack_log ( "JackNetMasterInterface::SetParams" );

JackNetInterface::SetParams();

fTxHeader.fDataStream = 's';
fRxHeader.fDataStream = 'r';

//midi net buffers
fNetMidiCaptureBuffer = new NetMidiBuffer ( &fParams, fParams.fSendMidiChannels, fTxData );
fNetMidiPlaybackBuffer = new NetMidiBuffer ( &fParams, fParams.fReturnMidiChannels, fRxData );

//audio net buffers
fNetAudioCaptureBuffer = new NetAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
fNetAudioPlaybackBuffer = new NetAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData );

//audio netbuffer length
fAudioTxLen = sizeof ( packet_header_t ) + fNetAudioPlaybackBuffer->GetSize();
fAudioRxLen = sizeof ( packet_header_t ) + fNetAudioCaptureBuffer->GetSize();
}

void JackNetMasterInterface::Exit()
{
jack_log ( "JackNetMaster::Exit, ID %u", fParams.fID );
@@ -538,7 +567,7 @@ namespace Jack
memcpy ( fTxBuffer, &fTxHeader, sizeof ( packet_header_t ) );
//and send
if ( Send ( fTxHeader.fPacketSize, 0 ) == SOCKET_ERROR )
return SOCKET_ERROR;
return SOCKET_ERROR;
}
}

@@ -558,7 +587,7 @@ namespace Jack
fNetAudioCaptureBuffer->RenderFromJackPorts ( subproc );
//and send
if ( Send ( fTxHeader.fPacketSize, 0 ) == SOCKET_ERROR )
return SOCKET_ERROR;
return SOCKET_ERROR;
}
}

@@ -579,25 +608,25 @@ namespace Jack

switch ( fParams.fNetworkMode )
{
case 'n' :
//normal use of the network : allow to use full bandwith
// - extra latency is set to one cycle, what is the time needed to receive streams using full network bandwith
// - if the network is too fast, just wait the next cycle, the benefit here is the master's cycle is shorter
// - indeed, data is supposed to be on the network rx buffer, so we don't have to wait for it
if ( cycle_offset == 0 )
return 0;
else
case 'n' :
//normal use of the network : allow to use full bandwith
// - extra latency is set to one cycle, what is the time needed to receive streams using full network bandwith
// - if the network is too fast, just wait the next cycle, the benefit here is the master's cycle is shorter
// - indeed, data is supposed to be on the network rx buffer, so we don't have to wait for it
if ( cycle_offset == 0 )
return 0;
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
// - here, receive data, we can't keep it queued on the rx buffer,
// - but if there is a cycle offset, tell the user, that means we're not in fast mode anymore, network is too slow
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
// - here, receive data, we can't keep it queued on the rx buffer,
// - but if there is a cycle offset, tell the user, that means we're not in fast mode anymore, network is too slow
rx_bytes = Recv ( rx_head->fPacketSize, 0 );
if ( cycle_offset )
jack_error ( "'%s' can't run in fast network mode, data received too late (%d cycle(s) offset)", fParams.fName, cycle_offset );
break;
if ( cycle_offset )
jack_error ( "'%s' can't run in fast network mode, data received too late (%d cycle(s) offset)", fParams.fName, cycle_offset );
break;
}

return rx_bytes;
@@ -630,28 +659,28 @@ namespace Jack
//read data
switch ( rx_head->fDataType )
{
case 'm': //midi
Recv ( rx_head->fPacketSize, 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 )
fNetMidiPlaybackBuffer->RenderToJackPorts();
jumpcnt = 0;
break;
case 'a': //audio
Recv ( rx_head->fPacketSize, 0 );
if ( !IsNextPacket ( &fRxHeader, rx_head, fNSubProcess ) )
jack_error ( "Packet(s) missing from '%s'...", fParams.fName );
fRxHeader.fCycle = rx_head->fCycle;
fRxHeader.fSubCycle = rx_head->fSubCycle;
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;
fNetAudioPlaybackBuffer->RenderToJackPorts ( rx_head->fSubCycle );
jumpcnt = 0;
break;
case 's': //sync
if ( rx_head->fCycle == fTxHeader.fCycle )
return 0;
case 'm': //midi
Recv ( rx_head->fPacketSize, 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 )
fNetMidiPlaybackBuffer->RenderToJackPorts();
jumpcnt = 0;
break;
case 'a': //audio
Recv ( rx_head->fPacketSize, 0 );
if ( !IsNextPacket ( &fRxHeader, rx_head, fNSubProcess ) )
jack_error ( "Packet(s) missing from '%s'...", fParams.fName );
fRxHeader.fCycle = rx_head->fCycle;
fRxHeader.fSubCycle = rx_head->fSubCycle;
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;
fNetAudioPlaybackBuffer->RenderToJackPorts ( rx_head->fSubCycle );
jumpcnt = 0;
break;
case 's': //sync
if ( rx_head->fCycle == fTxHeader.fCycle )
return 0;
}
}
}


+ 88
- 92
common/JackNetInterface.h View File

@@ -31,53 +31,53 @@ namespace Jack

class EXPORT JackNetInterface
{
protected:
session_params_t fParams;
JackNetSocket fSocket;
char* fMulticastIP;
uint fNSubProcess;
//headers
packet_header_t fTxHeader;
packet_header_t fRxHeader;
//network buffers
char* fTxBuffer;
char* fRxBuffer;
char* fTxData;
char* fRxData;
//jack buffers
NetMidiBuffer* fNetMidiCaptureBuffer;
NetMidiBuffer* fNetMidiPlaybackBuffer;
NetAudioBuffer* fNetAudioCaptureBuffer;
NetAudioBuffer* fNetAudioPlaybackBuffer;
//sizes
int fAudioRxLen;
int fAudioTxLen;
int fPayloadSize;
void SetParams();
//virtual methods : depends on the sub class master/slave
virtual bool Init() = 0;
virtual int SyncRecv() = 0;
virtual int SyncSend() = 0;
virtual int DataRecv() = 0;
virtual int DataSend() = 0;
virtual int Send ( size_t size, int flags ) = 0;
virtual int Recv ( size_t size, int flags ) = 0;
JackNetInterface()
{}
JackNetInterface ( const char* ip, int port );
JackNetInterface ( session_params_t& params, JackNetSocket& socket );
public:
~JackNetInterface();
protected:
session_params_t fParams;
JackNetSocket fSocket;
char* fMulticastIP;
uint fNSubProcess;
//headers
packet_header_t fTxHeader;
packet_header_t fRxHeader;
//network buffers
char* fTxBuffer;
char* fRxBuffer;
char* fTxData;
char* fRxData;
//jack buffers
NetMidiBuffer* fNetMidiCaptureBuffer;
NetMidiBuffer* fNetMidiPlaybackBuffer;
NetAudioBuffer* fNetAudioCaptureBuffer;
NetAudioBuffer* fNetAudioPlaybackBuffer;
//sizes
int fAudioRxLen;
int fAudioTxLen;
int fPayloadSize;
virtual void SetParams();
//virtual methods : depends on the sub class master/slave
virtual bool Init() = 0;
virtual int SyncRecv() = 0;
virtual int SyncSend() = 0;
virtual int DataRecv() = 0;
virtual int DataSend() = 0;
virtual int Send ( size_t size, int flags ) = 0;
virtual int Recv ( size_t size, int flags ) = 0;
JackNetInterface()
{}
JackNetInterface ( const char* ip, int port );
JackNetInterface ( session_params_t& params, JackNetSocket& socket );
public:
virtual ~JackNetInterface();
};

/**
@@ -86,28 +86,26 @@ namespace Jack

class EXPORT JackNetSlaveInterface : public JackNetInterface
{
protected:
bool Init();
net_status_t GetNetMaster();
net_status_t SendMasterStartSync();
int SyncRecv();
int SyncSend();
int DataRecv();
int DataSend();

int Recv ( size_t size, int flags );
int Send ( size_t size, int flags );

public:
JackNetSlaveInterface()
{}
JackNetSlaveInterface ( const char* ip, int port ) : JackNetInterface ( ip, port )
{
fTxHeader.fDataStream = 'r';
fRxHeader.fDataStream = 's';
}
~JackNetSlaveInterface()
{}
protected:
bool Init();
net_status_t GetNetMaster();
net_status_t SendMasterStartSync();
void SetParams();
int SyncRecv();
int SyncSend();
int DataRecv();
int DataSend();

int Recv ( size_t size, int flags );
int Send ( size_t size, int flags );

public:
JackNetSlaveInterface()
{}
JackNetSlaveInterface ( const char* ip, int port ) : JackNetInterface ( ip, port )
{}
~JackNetSlaveInterface()
{}
};

/**
@@ -116,29 +114,27 @@ namespace Jack

class EXPORT JackNetMasterInterface : public JackNetInterface
{
protected:
bool fRunning;

bool Init();
void Exit();
int SyncRecv();
int SyncSend();
int DataRecv();
int DataSend();

int Send ( size_t size, int flags );
int Recv ( size_t size, int flags );

public:
JackNetMasterInterface() : fRunning ( false )
{}
JackNetMasterInterface ( session_params_t& params, JackNetSocket& socket ) : JackNetInterface ( params, socket )
{
fTxHeader.fDataStream = 's';
fRxHeader.fDataStream = 'r';
}
~JackNetMasterInterface()
{}
protected:
bool fRunning;

bool Init();
void SetParams();
void Exit();
int SyncRecv();
int SyncSend();
int DataRecv();
int DataSend();

int Send ( size_t size, int flags );
int Recv ( size_t size, int flags );

public:
JackNetMasterInterface() : fRunning ( false )
{}
JackNetMasterInterface ( session_params_t& params, JackNetSocket& socket ) : JackNetInterface ( params, socket )
{}
~JackNetMasterInterface()
{}
};
}



+ 30
- 32
common/JackNetManager.cpp View File

@@ -57,6 +57,8 @@ namespace Jack
for ( port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
fMidiPlaybackPorts[port_index] = NULL;

SetParams();

//monitor
#ifdef JACK_MONITOR
fPeriodUsecs = ( int ) ( 1000000.f * ( ( float ) fParams.fPeriodSize / ( float ) fParams.fSampleRate ) );
@@ -123,7 +125,7 @@ namespace Jack
goto fail;
}

//process can now run
//process can now run
fRunning = true;

//finally activate jack client
@@ -137,7 +139,7 @@ namespace Jack

return true;

fail:
fail:
FreePorts();
jack_client_close ( fJackClient );
fJackClient = NULL;
@@ -146,7 +148,7 @@ fail:

int JackNetMaster::AllocPorts()
{
jack_log ( "JackNetMaster::AllocPorts" );
jack_log ( "JackNetMaster::AllocPorts" );

uint i;
char name[24];
@@ -240,21 +242,17 @@ fail:

//buffers
for ( port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
fNetMidiCaptureBuffer->SetBuffer ( port_index,
static_cast<JackMidiBuffer*> ( jack_port_get_buffer ( fMidiCapturePorts[port_index],
fParams.fPeriodSize ) ) );
fNetMidiCaptureBuffer->SetBuffer ( port_index, static_cast<JackMidiBuffer*> ( jack_port_get_buffer ( fMidiCapturePorts[port_index],
fParams.fPeriodSize ) ) );
for ( port_index = 0; port_index < fParams.fSendAudioChannels; port_index++ )
fNetAudioCaptureBuffer->SetBuffer ( port_index,
static_cast<sample_t*> ( jack_port_get_buffer ( fAudioCapturePorts[port_index],
fParams.fPeriodSize ) ) );
fNetAudioCaptureBuffer->SetBuffer ( port_index, static_cast<sample_t*> ( jack_port_get_buffer ( fAudioCapturePorts[port_index],
fParams.fPeriodSize ) ) );
for ( port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
fNetMidiPlaybackBuffer->SetBuffer ( port_index,
static_cast<JackMidiBuffer*> ( jack_port_get_buffer ( fMidiPlaybackPorts[port_index],
fParams.fPeriodSize ) ) );
fNetMidiPlaybackBuffer->SetBuffer ( port_index, static_cast<JackMidiBuffer*> ( jack_port_get_buffer ( fMidiPlaybackPorts[port_index],
fParams.fPeriodSize ) ) );
for ( port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++ )
fNetAudioPlaybackBuffer->SetBuffer ( port_index,
static_cast<sample_t*> ( jack_port_get_buffer ( fAudioPlaybackPorts[port_index],
fParams.fPeriodSize ) ) );
fNetAudioPlaybackBuffer->SetBuffer ( port_index, static_cast<sample_t*> ( jack_port_get_buffer ( fAudioPlaybackPorts[port_index],
fParams.fPeriodSize ) ) );

//Set the first packet to send
memset ( fTxData, 0, fPayloadSize );
@@ -315,11 +313,11 @@ fail:
param = ( const jack_driver_param_t* ) node->data;
switch ( param->character )
{
case 'a' :
fMulticastIP = strdup ( param->value.str );
break;
case 'p':
fSocket.SetPort ( param->value.ui );
case 'a' :
fMulticastIP = strdup ( param->value.str );
break;
case 'p':
fSocket.SetPort ( param->value.ui );
}
}

@@ -440,19 +438,19 @@ fail:
{
switch ( GetPacketType ( &params ) )
{
case SLAVE_AVAILABLE:
if ( ( net_master = MasterInit ( params ) ) )
SessionParamsDisplay ( &net_master->fParams );
else
jack_error ( "Can't init new net master..." );
jack_info ( "Waiting for a slave..." );
break;
case KILL_MASTER:
if ( KillMaster ( &params ) )
case SLAVE_AVAILABLE:
if ( ( net_master = MasterInit ( params ) ) )
SessionParamsDisplay ( &net_master->fParams );
else
jack_error ( "Can't init new net master..." );
jack_info ( "Waiting for a slave..." );
break;
default:
break;
break;
case KILL_MASTER:
if ( KillMaster ( &params ) )
jack_info ( "Waiting for a slave..." );
break;
default:
break;
}
}
}


+ 7
- 7
common/JackNetManager.h View File

@@ -30,13 +30,13 @@ namespace Jack
{
class JackNetMasterManager;

/**
\Brief This class describes a Net Master
*/
/**
\Brief This class describes a Net Master
*/

class JackNetMaster : public JackNetMasterInterface
{
friend class JackNetMasterManager;
friend class JackNetMasterManager;
private:
static int SetProcess ( jack_nframes_t nframes, void* arg );

@@ -76,9 +76,9 @@ namespace Jack
typedef std::list<JackNetMaster*> master_list_t;
typedef master_list_t::iterator master_list_it_t;

/**
\Brief This class describer the Network Manager
*/
/**
\Brief This class describer the Network Manager
*/

class JackNetMasterManager
{


+ 2
- 2
common/JackNetTool.cpp View File

@@ -342,7 +342,7 @@ namespace Jack
if ( !params->fSendAudioChannels && !params->fReturnAudioChannels )
return ( params->fFramesPerPacket = params->fPeriodSize );
jack_nframes_t period = ( int ) powf ( 2.f, ( int ) ( log ( ( params->fMtu - sizeof ( packet_header_t ) )
/ ( max ( params->fReturnAudioChannels, params->fSendAudioChannels ) * sizeof ( sample_t ) ) ) / log ( 2 ) ) );
/ ( max ( params->fReturnAudioChannels, params->fSendAudioChannels ) * sizeof ( sample_t ) ) ) / log ( 2 ) ) );
( period > params->fPeriodSize ) ? params->fFramesPerPacket = params->fPeriodSize : params->fFramesPerPacket = period;
return params->fFramesPerPacket;
}
@@ -353,7 +353,7 @@ namespace Jack
float audio_size = params->fMtu * ( params->fPeriodSize / params->fFramesPerPacket );
//midi
float midi_size = params->fMtu * ( max ( params->fSendMidiChannels, params->fReturnMidiChannels ) *
params->fPeriodSize * sizeof ( sample_t ) / ( params->fMtu - sizeof ( packet_header_t ) ) );
params->fPeriodSize * sizeof ( sample_t ) / ( params->fMtu - sizeof ( packet_header_t ) ) );
//return : sizes of sync + audio + midi
return ( params->fMtu + ( int ) audio_size + ( int ) midi_size );
}


+ 18
- 18
common/JackNetUnixSocket.cpp View File

@@ -24,7 +24,7 @@ namespace Jack
//utility *********************************************************************************************************
int GetHostName ( char * name, int size )
{
if ( gethostname ( name, size) == SOCKET_ERROR )
if ( gethostname ( name, size ) == SOCKET_ERROR )
{
jack_error ( "Can't get 'hostname' : %s", strerror ( NET_ERROR_CODE ) );
strcpy ( name, "default" );
@@ -234,7 +234,7 @@ namespace Jack
//more than 1sec
else
{
float sec = static_cast<float>( us ) / 1000000.f;
float sec = static_cast<float> ( us ) / 1000000.f;
timeout.tv_sec = ( int ) sec;
float usec = ( sec - static_cast<float> ( timeout.tv_sec ) ) * 1000000;
timeout.tv_usec = ( int ) usec;
@@ -289,22 +289,22 @@ namespace Jack
{
switch ( errno )
{
case EAGAIN:
return NET_NO_DATA;
case ECONNABORTED:
return NET_CONN_ERROR;
case EINVAL:
return NET_CONN_ERROR;
case ECONNREFUSED:
return NET_CONN_ERROR;
case ECONNRESET:
return NET_CONN_ERROR;
case EHOSTDOWN:
return NET_CONN_ERROR;
case EHOSTUNREACH:
return NET_CONN_ERROR;
default:
return NET_OP_ERROR;
case EAGAIN:
return NET_NO_DATA;
case ECONNABORTED:
return NET_CONN_ERROR;
case EINVAL:
return NET_CONN_ERROR;
case ECONNREFUSED:
return NET_CONN_ERROR;
case ECONNRESET:
return NET_CONN_ERROR;
case EHOSTDOWN:
return NET_CONN_ERROR;
case EHOSTUNREACH:
return NET_CONN_ERROR;
default:
return NET_OP_ERROR;
}
}
}

+ 59
- 59
common/JackNetUnixSocket.h View File

@@ -39,65 +39,65 @@ namespace Jack
//JackNetUnixSocket********************************************
class EXPORT JackNetUnixSocket
{
private:
int fSockfd;
int fPort;
struct sockaddr_in fSendAddr;
struct sockaddr_in fRecvAddr;
public:
JackNetUnixSocket();
JackNetUnixSocket ( const char* ip, int port );
JackNetUnixSocket ( const JackNetUnixSocket& );
~JackNetUnixSocket();
JackNetUnixSocket& operator= ( const JackNetUnixSocket& socket );
//socket management
int NewSocket();
int Bind();
int BindWith ( const char* ip );
int BindWith ( int port );
int Connect();
int ConnectTo ( const char* ip );
void Close();
void Reset();
bool IsSocket();
//IP/PORT management
void SetPort ( int port );
int GetPort();
//address management
int SetAddress ( const char* ip, int port );
char* GetSendIP();
char* GetRecvIP();
//utility
int GetName ( char* name );
int JoinMCastGroup ( const char* mcast_ip );
void CopyParams ( JackNetUnixSocket* socket );
//options management
int SetOption ( int level, int optname, const void* optval, socklen_t optlen );
int GetOption ( int level, int optname, void* optval, socklen_t* optlen );
//timeout
int SetTimeOut ( int us );
//local loop
int SetLocalLoop();
//network operations
int SendTo ( const void* buffer, size_t nbytes, int flags );
int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip );
int Send ( const void* buffer, size_t nbytes, int flags );
int RecvFrom ( void* buffer, size_t nbytes, int flags );
int Recv ( void* buffer, size_t nbytes, int flags );
int CatchHost ( void* buffer, size_t nbytes, int flags );
//error management
net_error_t GetError();
private:
int fSockfd;
int fPort;
struct sockaddr_in fSendAddr;
struct sockaddr_in fRecvAddr;
public:
JackNetUnixSocket();
JackNetUnixSocket ( const char* ip, int port );
JackNetUnixSocket ( const JackNetUnixSocket& );
~JackNetUnixSocket();
JackNetUnixSocket& operator= ( const JackNetUnixSocket& socket );
//socket management
int NewSocket();
int Bind();
int BindWith ( const char* ip );
int BindWith ( int port );
int Connect();
int ConnectTo ( const char* ip );
void Close();
void Reset();
bool IsSocket();
//IP/PORT management
void SetPort ( int port );
int GetPort();
//address management
int SetAddress ( const char* ip, int port );
char* GetSendIP();
char* GetRecvIP();
//utility
int GetName ( char* name );
int JoinMCastGroup ( const char* mcast_ip );
void CopyParams ( JackNetUnixSocket* socket );
//options management
int SetOption ( int level, int optname, const void* optval, socklen_t optlen );
int GetOption ( int level, int optname, void* optval, socklen_t* optlen );
//timeout
int SetTimeOut ( int us );
//local loop
int SetLocalLoop();
//network operations
int SendTo ( const void* buffer, size_t nbytes, int flags );
int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip );
int Send ( const void* buffer, size_t nbytes, int flags );
int RecvFrom ( void* buffer, size_t nbytes, int flags );
int Recv ( void* buffer, size_t nbytes, int flags );
int CatchHost ( void* buffer, size_t nbytes, int flags );
//error management
net_error_t GetError();
};
}



+ 2
- 2
common/JackPlatformNetSocket.h View File

@@ -38,11 +38,11 @@ namespace Jack
{

#if defined(__APPLE__) || defined(__linux__)
typedef JackNetUnixSocket JackNetSocket;
typedef JackNetUnixSocket JackNetSocket;
#endif

#ifdef WIN32
typedef JackNetWinSocket JackNetSocket;
typedef JackNetWinSocket JackNetSocket;
#endif

} // end of namespace


+ 78
- 78
windows/JackNetWinSocket.cpp View File

@@ -39,63 +39,63 @@ namespace Jack
char* msg;
} NetErrorList[] =
{
E(0, "No error"),
E(WSAEINTR, "Interrupted system call"),
E(WSAEBADF, "Bad file number"),
E(WSAEACCES, "Permission denied"),
E(WSAEFAULT, "Bad address"),
E(WSAEINVAL, "Invalid argument"),
E(WSAEMFILE, "Too many open sockets"),
E(WSAEWOULDBLOCK, "Operation would block"),
E(WSAEINPROGRESS, "Operation now in progress"),
E(WSAEALREADY, "Operation already in progress"),
E(WSAENOTSOCK, "Socket operation on non-socket"),
E(WSAEDESTADDRREQ, "Destination address required"),
E(WSAEMSGSIZE, "Message too long"),
E(WSAEPROTOTYPE, "Protocol wrong type for socket"),
E(WSAENOPROTOOPT, "Bad protocol option"),
E(WSAEPROTONOSUPPORT, "Protocol not supported"),
E(WSAESOCKTNOSUPPORT, "Socket type not supported"),
E(WSAEOPNOTSUPP, "Operation not supported on socket"),
E(WSAEPFNOSUPPORT, "Protocol family not supported"),
E(WSAEAFNOSUPPORT, "Address family not supported"),
E(WSAEADDRINUSE, "Address already in use"),
E(WSAEADDRNOTAVAIL, "Can't assign requested address"),
E(WSAENETDOWN, "Network is down"),
E(WSAENETUNREACH, "Network is unreachable"),
E(WSAENETRESET, "Net connection reset"),
E(WSAECONNABORTED, "Software caused connection abort"),
E(WSAECONNRESET, "Connection reset by peer"),
E(WSAENOBUFS, "No buffer space available"),
E(WSAEISCONN, "Socket is already connected"),
E(WSAENOTCONN, "Socket is not connected"),
E(WSAESHUTDOWN, "Can't send after socket shutdown"),
E(WSAETOOMANYREFS, "Too many references, can't splice"),
E(WSAETIMEDOUT, "Connection timed out"),
E(WSAECONNREFUSED, "Connection refused"),
E(WSAELOOP, "Too many levels of symbolic links"),
E(WSAENAMETOOLONG, "File name too long"),
E(WSAEHOSTDOWN, "Host is down"),
E(WSAEHOSTUNREACH, "No route to host"),
E(WSAENOTEMPTY, "Directory not empty"),
E(WSAEPROCLIM, "Too many processes"),
E(WSAEUSERS, "Too many users"),
E(WSAEDQUOT, "Disc quota exceeded"),
E(WSAESTALE, "Stale NFS file handle"),
E(WSAEREMOTE, "Too many levels of remote in path"),
E(WSASYSNOTREADY, "Network system is unavailable"),
E(WSAVERNOTSUPPORTED, "Winsock version out of range"),
E(WSANOTINITIALISED, "WSAStartup not yet called"),
E(WSAEDISCON, "Graceful shutdown in progress"),
E(WSAHOST_NOT_FOUND, "Host not found"),
E(WSANO_DATA, "No host data of that type was found"),
E ( 0, "No error" ),
E ( WSAEINTR, "Interrupted system call" ),
E ( WSAEBADF, "Bad file number" ),
E ( WSAEACCES, "Permission denied" ),
E ( WSAEFAULT, "Bad address" ),
E ( WSAEINVAL, "Invalid argument" ),
E ( WSAEMFILE, "Too many open sockets" ),
E ( WSAEWOULDBLOCK, "Operation would block" ),
E ( WSAEINPROGRESS, "Operation now in progress" ),
E ( WSAEALREADY, "Operation already in progress" ),
E ( WSAENOTSOCK, "Socket operation on non-socket" ),
E ( WSAEDESTADDRREQ, "Destination address required" ),
E ( WSAEMSGSIZE, "Message too long" ),
E ( WSAEPROTOTYPE, "Protocol wrong type for socket" ),
E ( WSAENOPROTOOPT, "Bad protocol option" ),
E ( WSAEPROTONOSUPPORT, "Protocol not supported" ),
E ( WSAESOCKTNOSUPPORT, "Socket type not supported" ),
E ( WSAEOPNOTSUPP, "Operation not supported on socket" ),
E ( WSAEPFNOSUPPORT, "Protocol family not supported" ),
E ( WSAEAFNOSUPPORT, "Address family not supported" ),
E ( WSAEADDRINUSE, "Address already in use" ),
E ( WSAEADDRNOTAVAIL, "Can't assign requested address" ),
E ( WSAENETDOWN, "Network is down" ),
E ( WSAENETUNREACH, "Network is unreachable" ),
E ( WSAENETRESET, "Net connection reset" ),
E ( WSAECONNABORTED, "Software caused connection abort" ),
E ( WSAECONNRESET, "Connection reset by peer" ),
E ( WSAENOBUFS, "No buffer space available" ),
E ( WSAEISCONN, "Socket is already connected" ),
E ( WSAENOTCONN, "Socket is not connected" ),
E ( WSAESHUTDOWN, "Can't send after socket shutdown" ),
E ( WSAETOOMANYREFS, "Too many references, can't splice" ),
E ( WSAETIMEDOUT, "Connection timed out" ),
E ( WSAECONNREFUSED, "Connection refused" ),
E ( WSAELOOP, "Too many levels of symbolic links" ),
E ( WSAENAMETOOLONG, "File name too long" ),
E ( WSAEHOSTDOWN, "Host is down" ),
E ( WSAEHOSTUNREACH, "No route to host" ),
E ( WSAENOTEMPTY, "Directory not empty" ),
E ( WSAEPROCLIM, "Too many processes" ),
E ( WSAEUSERS, "Too many users" ),
E ( WSAEDQUOT, "Disc quota exceeded" ),
E ( WSAESTALE, "Stale NFS file handle" ),
E ( WSAEREMOTE, "Too many levels of remote in path" ),
E ( WSASYSNOTREADY, "Network system is unavailable" ),
E ( WSAVERNOTSUPPORTED, "Winsock version out of range" ),
E ( WSANOTINITIALISED, "WSAStartup not yet called" ),
E ( WSAEDISCON, "Graceful shutdown in progress" ),
E ( WSAHOST_NOT_FOUND, "Host not found" ),
E ( WSANO_DATA, "No host data of that type was found" ),
{ -1, NULL },
};

EXPORT const char* PrintError ( int error )
{
int i;
for ( i = 0; NetErrorList[i].code >= 0; ++i)
for ( i = 0; NetErrorList[i].code >= 0; ++i )
{
if ( error == NetErrorList[i].code )
return NetErrorList[i].msg;
@@ -267,12 +267,12 @@ namespace Jack
//options************************************************************************************************************
int JackNetWinSocket::SetOption ( int level, int optname, const void* optval, SOCKLEN optlen )
{
return setsockopt ( fSockfd, level, optname, static_cast<const char*>(optval), optlen );
return setsockopt ( fSockfd, level, optname, static_cast<const char*> ( optval ), optlen );
}

int JackNetWinSocket::GetOption ( int level, int optname, void* optval, SOCKLEN* optlen )
{
return getsockopt ( fSockfd, level, optname, static_cast<char*>(optval), optlen );
return getsockopt ( fSockfd, level, optname, static_cast<char*> ( optval ), optlen );
}

//tiemout************************************************************************************************************
@@ -295,7 +295,7 @@ namespace Jack
//network operations*************************************************************************************************
int JackNetWinSocket::SendTo ( const void* buffer, size_t nbytes, int flags )
{
return sendto ( fSockfd, reinterpret_cast<const char*>(buffer), nbytes, flags, reinterpret_cast<SOCKADDR*> ( &fSendAddr ), sizeof ( SOCKADDR ) );
return sendto ( fSockfd, reinterpret_cast<const char*> ( buffer ), nbytes, flags, reinterpret_cast<SOCKADDR*> ( &fSendAddr ), sizeof ( SOCKADDR ) );
}

int JackNetWinSocket::SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip )
@@ -306,50 +306,50 @@ namespace Jack

int JackNetWinSocket::Send ( const void* buffer, size_t nbytes, int flags )
{
return send ( fSockfd, reinterpret_cast<const char*>(buffer), nbytes, flags );
return send ( fSockfd, reinterpret_cast<const char*> ( buffer ), nbytes, flags );
}

int JackNetWinSocket::RecvFrom ( void* buffer, size_t nbytes, int flags )
{
SOCKLEN addr_len = sizeof ( SOCKADDR );
return recvfrom ( fSockfd, reinterpret_cast<char*>(buffer), nbytes, flags, reinterpret_cast<SOCKADDR*> ( &fRecvAddr ), &addr_len );
return recvfrom ( fSockfd, reinterpret_cast<char*> ( buffer ), nbytes, flags, reinterpret_cast<SOCKADDR*> ( &fRecvAddr ), &addr_len );
}

int JackNetWinSocket::Recv ( void* buffer, size_t nbytes, int flags )
{
return recv ( fSockfd, reinterpret_cast<char*>(buffer), nbytes, flags );
return recv ( fSockfd, reinterpret_cast<char*> ( buffer ), nbytes, flags );
}

int JackNetWinSocket::CatchHost ( void* buffer, size_t nbytes, int flags )
{
SOCKLEN addr_len = sizeof ( SOCKADDR );
return recvfrom ( fSockfd, reinterpret_cast<char*>(buffer), nbytes, flags, reinterpret_cast<SOCKADDR*> ( &fSendAddr ), &addr_len );
return recvfrom ( fSockfd, reinterpret_cast<char*> ( buffer ), nbytes, flags, reinterpret_cast<SOCKADDR*> ( &fSendAddr ), &addr_len );
}

net_error_t JackNetWinSocket::GetError()
{
switch ( NET_ERROR_CODE )
{
case WSABASEERR:
return NET_NO_ERROR;
case WSAETIMEDOUT:
return NET_NO_DATA;
case WSAEWOULDBLOCK:
return NET_NO_DATA;
case WSAECONNREFUSED:
return NET_CONN_ERROR;
case WSAECONNRESET:
return NET_CONN_ERROR;
case WSAEACCES:
return NET_CONN_ERROR;
case WSAECONNABORTED:
return NET_CONN_ERROR;
case WSAEHOSTDOWN:
return NET_CONN_ERROR;
case WSAEHOSTUNREACH:
return NET_CONN_ERROR;
default:
return NET_OP_ERROR;
case WSABASEERR:
return NET_NO_ERROR;
case WSAETIMEDOUT:
return NET_NO_DATA;
case WSAEWOULDBLOCK:
return NET_NO_DATA;
case WSAECONNREFUSED:
return NET_CONN_ERROR;
case WSAECONNRESET:
return NET_CONN_ERROR;
case WSAEACCES:
return NET_CONN_ERROR;
case WSAECONNABORTED:
return NET_CONN_ERROR;
case WSAEHOSTDOWN:
return NET_CONN_ERROR;
case WSAEHOSTUNREACH:
return NET_CONN_ERROR;
default:
return NET_OP_ERROR;
}
}
}


+ 57
- 57
windows/JackNetWinSocket.h View File

@@ -41,63 +41,63 @@ namespace Jack
//JeckNetWinSocket***************************************************************************
class EXPORT JackNetWinSocket
{
private:
int fSockfd;
int fPort;
SOCKADDR_IN fSendAddr;
SOCKADDR_IN fRecvAddr;
public:
JackNetWinSocket();
JackNetWinSocket ( const char* ip, int port );
JackNetWinSocket ( const JackNetWinSocket& );
~JackNetWinSocket();
JackNetWinSocket& operator= ( const JackNetWinSocket& );
//socket management
int NewSocket();
int Bind();
int BindWith ( const char* ip );
int BindWith ( int port );
int Connect();
int ConnectTo ( const char* ip );
void Close();
void Reset();
bool IsSocket();
//IP/PORT management
void SetPort ( int port );
int GetPort();
//address management
int SetAddress ( const char* ip, int port );
char* GetSendIP();
char* GetRecvIP();
//utility
int GetName ( char* name );
int JoinMCastGroup ( const char* mcast_ip );
//options management
int SetOption ( int level, int optname, const void* optval, SOCKLEN optlen );
int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen );
//timeout
int SetTimeOut ( int usec );
//local loop
int SetLocalLoop();
//network operations
int SendTo ( const void* buffer, size_t nbytes, int flags );
int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip );
int Send ( const void* buffer, size_t nbytes, int flags );
int RecvFrom ( void* buffer, size_t nbytes, int flags );
int Recv ( void* buffer, size_t nbytes, int flags );
int CatchHost ( void* buffer, size_t nbytes, int flags );
//error management
net_error_t GetError();
private:
int fSockfd;
int fPort;
SOCKADDR_IN fSendAddr;
SOCKADDR_IN fRecvAddr;
public:
JackNetWinSocket();
JackNetWinSocket ( const char* ip, int port );
JackNetWinSocket ( const JackNetWinSocket& );
~JackNetWinSocket();
JackNetWinSocket& operator= ( const JackNetWinSocket& );
//socket management
int NewSocket();
int Bind();
int BindWith ( const char* ip );
int BindWith ( int port );
int Connect();
int ConnectTo ( const char* ip );
void Close();
void Reset();
bool IsSocket();
//IP/PORT management
void SetPort ( int port );
int GetPort();
//address management
int SetAddress ( const char* ip, int port );
char* GetSendIP();
char* GetRecvIP();
//utility
int GetName ( char* name );
int JoinMCastGroup ( const char* mcast_ip );
//options management
int SetOption ( int level, int optname, const void* optval, SOCKLEN optlen );
int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen );
//timeout
int SetTimeOut ( int usec );
//local loop
int SetLocalLoop();
//network operations
int SendTo ( const void* buffer, size_t nbytes, int flags );
int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip );
int Send ( const void* buffer, size_t nbytes, int flags );
int RecvFrom ( void* buffer, size_t nbytes, int flags );
int Recv ( void* buffer, size_t nbytes, int flags );
int CatchHost ( void* buffer, size_t nbytes, int flags );
//error management
net_error_t GetError();
};
}



Loading…
Cancel
Save