git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2775 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.90
@@ -149,7 +149,6 @@ namespace Jack | |||||
jack_log ( "JackNetSlaveInterface::GetNetMaster()" ); | jack_log ( "JackNetSlaveInterface::GetNetMaster()" ); | ||||
//utility | //utility | ||||
session_params_t params; | session_params_t params; | ||||
int us_timeout = 2000000; | |||||
int rx_bytes = 0; | int rx_bytes = 0; | ||||
unsigned char loop = 0; | unsigned char loop = 0; | ||||
@@ -165,7 +164,7 @@ namespace Jack | |||||
jack_error ( "Can't bind the socket : %s", StrError ( NET_ERROR_CODE ) ); | jack_error ( "Can't bind the socket : %s", StrError ( NET_ERROR_CODE ) ); | ||||
//timeout on receive | //timeout on receive | ||||
if ( fSocket.SetTimeOut ( us_timeout ) == SOCKET_ERROR ) | |||||
if ( fSocket.SetTimeOut ( 2000000 ) == SOCKET_ERROR ) | |||||
jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); | jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); | ||||
//disable local loop | //disable local loop | ||||
@@ -389,7 +388,6 @@ namespace Jack | |||||
jack_log ( "JackNetMasterInterface::Init, ID %u.", fParams.fID ); | jack_log ( "JackNetMasterInterface::Init, ID %u.", fParams.fID ); | ||||
session_params_t params; | session_params_t params; | ||||
int usec_timeout = 1000000; | |||||
uint attempt = 0; | uint attempt = 0; | ||||
int rx_bytes = 0; | int rx_bytes = 0; | ||||
int rx_bufsize = 0; | int rx_bufsize = 0; | ||||
@@ -402,7 +400,7 @@ namespace Jack | |||||
} | } | ||||
//timeout on receive (for init) | //timeout on receive (for init) | ||||
if ( fSocket.SetTimeOut ( usec_timeout ) < 0 ) | |||||
if ( fSocket.SetTimeOut ( 1000000 ) < 0 ) | |||||
jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); | jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); | ||||
//connect | //connect | ||||
@@ -380,7 +380,6 @@ fail: | |||||
{ | { | ||||
jack_log ( "JackNetMasterManager::Run" ); | jack_log ( "JackNetMasterManager::Run" ); | ||||
//utility variables | //utility variables | ||||
int usec_timeout = 2000000; | |||||
int attempt = 0; | int attempt = 0; | ||||
//data | //data | ||||
@@ -419,7 +418,7 @@ fail: | |||||
jack_error ( "Can't set local loop : %s", StrError ( NET_ERROR_CODE ) ); | jack_error ( "Can't set local loop : %s", StrError ( NET_ERROR_CODE ) ); | ||||
//set a timeout on the multicast receive (the thread can now be cancelled) | //set a timeout on the multicast receive (the thread can now be cancelled) | ||||
if ( fSocket.SetTimeOut ( usec_timeout ) == SOCKET_ERROR ) | |||||
if ( fSocket.SetTimeOut ( 2000000 ) == SOCKET_ERROR ) | |||||
jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); | jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); | ||||
jack_info ( "Waiting for a slave..." ); | jack_info ( "Waiting for a slave..." ); | ||||
@@ -380,8 +380,7 @@ namespace Jack | |||||
//slow mode, just try recv during two subcycle audio packets | //slow mode, just try recv during two subcycle audio packets | ||||
else | else | ||||
time = 4000000.f * ( static_cast<float> ( params->fFramesPerPacket ) / static_cast<float> ( params->fSampleRate ) ); | time = 4000000.f * ( static_cast<float> ( params->fFramesPerPacket ) / static_cast<float> ( params->fSampleRate ) ); | ||||
int usec = ( int ) time; | |||||
return socket->SetTimeOut ( usec ); | |||||
return socket->SetTimeOut ( static_cast<int> ( time ) ); | |||||
} | } | ||||
// Packet ******************************************************************************************************* | // Packet ******************************************************************************************************* | ||||
@@ -62,7 +62,7 @@ namespace Jack | |||||
JackNetUnixSocket::JackNetUnixSocket ( const JackNetUnixSocket& socket ) | JackNetUnixSocket::JackNetUnixSocket ( const JackNetUnixSocket& socket ) | ||||
{ | { | ||||
fSockfd = socket.fSockfd; | |||||
fSockfd = 0; | |||||
fPort = socket.fPort; | fPort = socket.fPort; | ||||
fSendAddr = socket.fSendAddr; | fSendAddr = socket.fSendAddr; | ||||
fRecvAddr = socket.fRecvAddr; | fRecvAddr = socket.fRecvAddr; | ||||
@@ -82,6 +82,7 @@ namespace Jack | |||||
fSendAddr = socket.fSendAddr; | fSendAddr = socket.fSendAddr; | ||||
fRecvAddr = socket.fRecvAddr; | fRecvAddr = socket.fRecvAddr; | ||||
} | } | ||||
return *this; | |||||
} | } | ||||
//socket*********************************************************************************************************** | //socket*********************************************************************************************************** | ||||
@@ -218,7 +219,7 @@ namespace Jack | |||||
} | } | ||||
//timeout************************************************************************************************************ | //timeout************************************************************************************************************ | ||||
int JackNetUnixSocket::SetTimeOut ( int& us ) | |||||
int JackNetUnixSocket::SetTimeOut ( int us ) | |||||
{ | { | ||||
//negative timeout, or exceding 10s, return | //negative timeout, or exceding 10s, return | ||||
if ( ( us < 0 ) || ( us > 10000000 ) ) | if ( ( us < 0 ) || ( us > 10000000 ) ) | ||||
@@ -83,7 +83,7 @@ namespace Jack | |||||
int GetOption ( int level, int optname, void* optval, socklen_t* optlen ); | int GetOption ( int level, int optname, void* optval, socklen_t* optlen ); | ||||
//timeout | //timeout | ||||
int SetTimeOut ( int& us ); | |||||
int SetTimeOut ( int us ); | |||||
//local loop | //local loop | ||||
int SetLocalLoop(); | int SetLocalLoop(); | ||||
@@ -15,8 +15,8 @@ | |||||
#endif | #endif | ||||
#include <jack/jack.h> | #include <jack/jack.h> | ||||
jack_port_t *input_port; | |||||
jack_port_t *output_port; | |||||
jack_port_t **input_ports; | |||||
jack_port_t **output_ports; | |||||
jack_client_t *client; | jack_client_t *client; | ||||
static void signal_handler ( int sig ) | static void signal_handler ( int sig ) | ||||
@@ -37,13 +37,14 @@ static void signal_handler ( int sig ) | |||||
int | int | ||||
process ( jack_nframes_t nframes, void *arg ) | process ( jack_nframes_t nframes, void *arg ) | ||||
{ | { | ||||
int i; | |||||
jack_default_audio_sample_t *in, *out; | jack_default_audio_sample_t *in, *out; | ||||
in = jack_port_get_buffer ( input_port, nframes ); | |||||
out = jack_port_get_buffer ( output_port, nframes ); | |||||
memcpy ( out, in, nframes * sizeof ( jack_default_audio_sample_t ) ); | |||||
for ( i = 0; i < 2; i++ ) | |||||
{ | |||||
in = jack_port_get_buffer ( input_ports[i], nframes ); | |||||
out = jack_port_get_buffer ( output_ports[i], nframes ); | |||||
memcpy ( out, in, nframes * sizeof ( jack_default_audio_sample_t ) ); | |||||
} | |||||
return 0; | return 0; | ||||
} | } | ||||
@@ -54,12 +55,15 @@ process ( jack_nframes_t nframes, void *arg ) | |||||
void | void | ||||
jack_shutdown ( void *arg ) | jack_shutdown ( void *arg ) | ||||
{ | { | ||||
free ( input_ports ); | |||||
free ( output_ports ); | |||||
exit ( 1 ); | exit ( 1 ); | ||||
} | } | ||||
int | int | ||||
main ( int argc, char *argv[] ) | main ( int argc, char *argv[] ) | ||||
{ | { | ||||
int i; | |||||
const char **ports; | const char **ports; | ||||
const char *client_name; | const char *client_name; | ||||
const char *server_name = NULL; | const char *server_name = NULL; | ||||
@@ -124,19 +128,22 @@ main ( int argc, char *argv[] ) | |||||
jack_on_shutdown ( client, jack_shutdown, 0 ); | jack_on_shutdown ( client, jack_shutdown, 0 ); | ||||
/* create two ports */ | |||||
input_port = jack_port_register ( client, "input", | |||||
JACK_DEFAULT_AUDIO_TYPE, | |||||
JackPortIsInput, 0 ); | |||||
output_port = jack_port_register ( client, "output", | |||||
JACK_DEFAULT_AUDIO_TYPE, | |||||
JackPortIsOutput, 0 ); | |||||
/* create two ports pairs*/ | |||||
input_ports = ( jack_port_t** ) calloc ( 2, sizeof ( jack_port_t* ) ); | |||||
output_ports = ( jack_port_t** ) calloc ( 2, sizeof ( jack_port_t* ) ); | |||||
if ( ( input_port == NULL ) || ( output_port == NULL ) ) | |||||
char port_name[16]; | |||||
for ( i = 0; i < 2; i++ ) | |||||
{ | { | ||||
fprintf ( stderr, "no more JACK ports available\n" ); | |||||
exit ( 1 ); | |||||
sprintf ( port_name, "input_%d", i + 1 ); | |||||
input_ports[i] = jack_port_register ( client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0 ); | |||||
sprintf ( port_name, "output_%d", i + 1 ); | |||||
output_ports[i] = jack_port_register ( client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 ); | |||||
if ( ( input_ports[i] == NULL ) || ( output_ports[i] == NULL ) ) | |||||
{ | |||||
fprintf ( stderr, "no more JACK ports available\n" ); | |||||
exit ( 1 ); | |||||
} | |||||
} | } | ||||
/* Tell the JACK server that we are ready to roll. Our | /* Tell the JACK server that we are ready to roll. Our | ||||
@@ -156,33 +163,29 @@ main ( int argc, char *argv[] ) | |||||
* it. | * it. | ||||
*/ | */ | ||||
ports = jack_get_ports ( client, NULL, NULL, | |||||
JackPortIsPhysical|JackPortIsOutput ); | |||||
ports = jack_get_ports ( client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput ); | |||||
if ( ports == NULL ) | if ( ports == NULL ) | ||||
{ | { | ||||
fprintf ( stderr, "no physical capture ports\n" ); | fprintf ( stderr, "no physical capture ports\n" ); | ||||
exit ( 1 ); | exit ( 1 ); | ||||
} | } | ||||
if ( jack_connect ( client, ports[0], jack_port_name ( input_port ) ) ) | |||||
{ | |||||
fprintf ( stderr, "cannot connect input ports\n" ); | |||||
} | |||||
for ( i = 0; i < 2; i++ ) | |||||
if ( jack_connect ( client, ports[i], jack_port_name ( input_ports[i] ) ) ) | |||||
fprintf ( stderr, "cannot connect input ports\n" ); | |||||
free ( ports ); | free ( ports ); | ||||
ports = jack_get_ports ( client, NULL, NULL, | |||||
JackPortIsPhysical|JackPortIsInput ); | |||||
ports = jack_get_ports ( client, NULL, NULL, JackPortIsPhysical|JackPortIsInput ); | |||||
if ( ports == NULL ) | if ( ports == NULL ) | ||||
{ | { | ||||
fprintf ( stderr, "no physical playback ports\n" ); | fprintf ( stderr, "no physical playback ports\n" ); | ||||
exit ( 1 ); | exit ( 1 ); | ||||
} | } | ||||
if ( jack_connect ( client, jack_port_name ( output_port ), ports[0] ) ) | |||||
{ | |||||
fprintf ( stderr, "cannot connect output ports\n" ); | |||||
} | |||||
for ( i = 0; i < 2; i++ ) | |||||
if ( jack_connect ( client, jack_port_name ( output_ports[i] ), ports[i] ) ) | |||||
fprintf ( stderr, "cannot connect input ports\n" ); | |||||
free ( ports ); | free ( ports ); | ||||
@@ -151,6 +151,7 @@ namespace Jack | |||||
fSendAddr = socket.fSendAddr; | fSendAddr = socket.fSendAddr; | ||||
fRecvAddr = socket.fRecvAddr; | fRecvAddr = socket.fRecvAddr; | ||||
} | } | ||||
return *this; | |||||
} | } | ||||
//socket*********************************************************************************************************** | //socket*********************************************************************************************************** | ||||
@@ -275,7 +276,7 @@ namespace Jack | |||||
} | } | ||||
//tiemout************************************************************************************************************ | //tiemout************************************************************************************************************ | ||||
int JackNetWinSocket::SetTimeOut ( int& usec ) | |||||
int JackNetWinSocket::SetTimeOut ( int usec ) | |||||
{ | { | ||||
//negative timeout, or exceeding 10s, return | //negative timeout, or exceeding 10s, return | ||||
if ( ( usec < 0 ) || ( usec > 10000000 ) ) | if ( ( usec < 0 ) || ( usec > 10000000 ) ) | ||||
@@ -83,7 +83,7 @@ namespace Jack | |||||
int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen ); | int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen ); | ||||
//timeout | //timeout | ||||
int SetTimeOut ( int& usec ); | |||||
int SetTimeOut ( int usec ); | |||||
//local loop | //local loop | ||||
int SetLocalLoop(); | int SetLocalLoop(); | ||||