git-svn-id: http://subversion.jackaudio.org/jack/jack2/branches/libjacknet@3954 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.9.8
| @@ -46,7 +46,7 @@ extern "C" | |||
| int audio_input; | |||
| int audio_output; | |||
| int midi_input; | |||
| int midi_ouput; | |||
| int midi_output; | |||
| int mtu; | |||
| int time_out; // in millisecond, -1 means in infinite | |||
| char mode; | |||
| @@ -230,8 +230,8 @@ struct JackNetExtMaster : public JackNetMasterInterface { | |||
| result->audio_input = fParams.fSendAudioChannels; | |||
| result->audio_output = fParams.fReturnAudioChannels; | |||
| result->midi_input = fParams.fSendMidiChannels; | |||
| result->midi_ouput = fParams.fReturnMidiChannels; | |||
| result->midi_ouput = fParams.fMtu; | |||
| result->midi_output = fParams.fReturnMidiChannels; | |||
| result->mtu = fParams.fMtu; | |||
| result->mode = fParams.fNetworkMode; | |||
| return 0; | |||
| @@ -425,6 +425,8 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf | |||
| JackMidiBuffer** fMidiCaptureBuffer; | |||
| JackMidiBuffer** fMidiPlaybackBuffer; | |||
| int fConnectTimeOut; | |||
| JackNetExtSlave(const char* ip, | |||
| int port, | |||
| const char* name, | |||
| @@ -448,9 +450,10 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf | |||
| fParams.fSendAudioChannels = request->audio_input; | |||
| fParams.fReturnAudioChannels = request->audio_output; | |||
| fParams.fSendMidiChannels = request->midi_input; | |||
| fParams.fReturnMidiChannels = request->midi_ouput; | |||
| fParams.fReturnMidiChannels = request->midi_output; | |||
| fParams.fNetworkMode = request->mode; | |||
| fParams.fSlaveSyncMode = 1; | |||
| fConnectTimeOut = request->time_out; | |||
| // Create name with hostname and client name | |||
| GetHostName(host_name, JACK_CLIENT_NAME_SIZE); | |||
| @@ -468,7 +471,7 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf | |||
| int Open(jack_master_t* result) | |||
| { | |||
| // Init network connection | |||
| if (!JackNetSlaveInterface::InitConnection()) | |||
| if (!JackNetSlaveInterface::InitConnection(fConnectTimeOut)) | |||
| return -1; | |||
| // Then set global parameters | |||
| @@ -609,10 +609,11 @@ namespace Jack | |||
| // Separate the connection protocol into two separated step | |||
| bool JackNetSlaveInterface::InitConnection() | |||
| bool JackNetSlaveInterface::InitConnection(int time_out) | |||
| { | |||
| jack_log ( "JackNetSlaveInterface::InitConnection()" ); | |||
| jack_log("JackNetSlaveInterface::InitConnection()"); | |||
| int try_count = (time_out > 0) ? ((1000000 * time_out) / SLAVE_INIT_TIMEOUT) : LONG_MAX; | |||
| //set the parameters to send | |||
| strcpy (fParams.fPacketType, "params"); | |||
| fParams.fProtocolVersion = SLAVE_PROTOCOL; | |||
| @@ -622,13 +623,13 @@ namespace Jack | |||
| do | |||
| { | |||
| //get a master | |||
| status = SendAvailableToMaster(); | |||
| status = SendAvailableToMaster(try_count); | |||
| if (status == NET_SOCKET_ERROR) | |||
| return false; | |||
| } | |||
| while (status != NET_CONNECTED); | |||
| while (status != NET_CONNECTED && --try_count > 0); | |||
| return true; | |||
| return (try_count != 0); | |||
| } | |||
| bool JackNetSlaveInterface::InitRendering() | |||
| @@ -649,7 +650,7 @@ namespace Jack | |||
| return true; | |||
| } | |||
| net_status_t JackNetSlaveInterface::SendAvailableToMaster() | |||
| net_status_t JackNetSlaveInterface::SendAvailableToMaster(int count) | |||
| { | |||
| jack_log ( "JackNetSlaveInterface::SendAvailableToMaster()" ); | |||
| //utility | |||
| @@ -697,7 +698,12 @@ namespace Jack | |||
| return NET_RECV_ERROR; | |||
| } | |||
| } | |||
| while ( strcmp ( host_params.fPacketType, fParams.fPacketType ) && ( GetPacketType ( &host_params ) != SLAVE_SETUP ) ); | |||
| while (strcmp(host_params.fPacketType, fParams.fPacketType) && (GetPacketType(&host_params) != SLAVE_SETUP) && (--count > 0)); | |||
| // Time out failure.. | |||
| if (count == 0) { | |||
| return NET_CONNECT_ERROR; | |||
| } | |||
| //everything is OK, copy parameters | |||
| SessionParamsDisplay(&host_params); | |||
| @@ -145,10 +145,10 @@ namespace Jack | |||
| static uint fSlaveCounter; | |||
| bool Init(); | |||
| bool InitConnection(); | |||
| bool InitConnection(int time_out); | |||
| bool InitRendering(); | |||
| net_status_t SendAvailableToMaster(); | |||
| net_status_t SendAvailableToMaster(int count = LONG_MAX); | |||
| net_status_t SendStartToMaster(); | |||
| bool SetParams(); | |||
| @@ -207,7 +207,7 @@ namespace Jack | |||
| #define SLAVE_SETUP_RETRY 5 | |||
| #define MASTER_INIT_TIMEOUT 1000000 // in usec | |||
| #define SLAVE_INIT_TIMEOUT 2000000 // in usec | |||
| #define SLAVE_INIT_TIMEOUT 1000000 // in usec | |||
| #define CYCLE_OFFSET_FAST 0 | |||
| #define CYCLE_OFFSET_NORMAL 1 | |||
| @@ -49,7 +49,7 @@ typedef struct { | |||
| int midi_input; // from master or to slave | |||
| int midi_output; // to master or from slave | |||
| int mtu; | |||
| int time_out; // in millisecond, -1 means in infinite | |||
| int time_out; // in second, -1 means in infinite | |||
| char mode; | |||
| } jack_slave_t; | |||