Browse Source

Add little through example-client

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2762 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.90
moret 17 years ago
parent
commit
b4c4ad7410
4 changed files with 229 additions and 6 deletions
  1. +1
    -1
      common/JackNetDriver.cpp
  2. +5
    -5
      common/JackNetManager.cpp
  3. +222
    -0
      example-clients/through_client.c
  4. +1
    -0
      example-clients/wscript

+ 1
- 1
common/JackNetDriver.cpp View File

@@ -632,7 +632,7 @@ namespace Jack
if ( fEngineControl->fSyncMode )
fTxHeader.fCycle = fRxHeader.fCycle;
else
fTxHeader.fCycle = fRxHeader.fCycle - 1;
fTxHeader.fCycle++;
fTxHeader.fSubCycle = 0;
fTxHeader.fIsLastPckt = 'n';



+ 5
- 5
common/JackNetManager.cpp View File

@@ -340,7 +340,7 @@ namespace Jack
if ( ( tx_bytes = fSocket.Send ( buffer, size, flags ) ) == SOCKET_ERROR )
{
net_error_t error = fSocket.GetError();
if ( error == NET_CONN_ERROR )
if ( fRunning && ( error == NET_CONN_ERROR ) )
{
//fatal connection issue, exit
jack_error ( "'%s' : %s, please check network connection with '%s'.",
@@ -362,7 +362,7 @@ namespace Jack
//no data isn't really a network error, so just return 0 avalaible read bytes
if ( error == NET_NO_DATA )
return 0;
else if ( error == NET_CONN_ERROR )
else if ( fRunning && ( error == NET_CONN_ERROR ) )
{
//fatal connection issue, exit
jack_error ( "'%s' : %s, network connection with '%s' broken, exiting.",
@@ -495,7 +495,7 @@ namespace Jack
if ( ( rx_bytes == 0 ) || ( rx_bytes == SOCKET_ERROR ) )
return rx_bytes;

cycle_offset = rx_head->fCycle - fTxHeader.fCycle;
cycle_offset = fTxHeader.fCycle - rx_head->fCycle;

switch ( fParams.fNetworkMode )
{
@@ -515,8 +515,8 @@ namespace Jack
// - 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 != 0 )
jack_error ( "%s, can't stay in fast network mode, data received too late (%d cycle(s) offset)", fParams.fName, cycle_offset );
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;
}



+ 222
- 0
example-clients/through_client.c View File

@@ -0,0 +1,222 @@
/** @file simple_client.c
*
* @brief This simple through client demonstrates the basic features of JACK
* as they would be used by many applications.
*/

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <signal.h>
#ifndef WIN32
#include <unistd.h>
#endif
#include <jack/jack.h>

jack_port_t *input_port;
jack_port_t *output_port;
jack_client_t *client;

static void signal_handler ( int sig )
{
jack_client_close ( client );
fprintf ( stderr, "signal received, exiting ...\n" );
exit ( 0 );
}

/* a simple state machine for this client */
volatile enum
{
Init,
Run,
Exit
} client_state = Init;

/**
* The process callback for this JACK application is called in a
* special realtime thread once for each audio cycle.
*
* This client follows a simple rule: when the JACK transport is
* running, copy the input port to the output. When it stops, exit.
*/

int
process ( jack_nframes_t nframes, void *arg )
{
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 ) );

return 0;
}

/**
* JACK calls this shutdown_callback if the server ever shuts down or
* decides to disconnect the client.
*/
void
jack_shutdown ( void *arg )
{
exit ( 1 );
}

int
main ( int argc, char *argv[] )
{
const char **ports;
const char *client_name;
const char *server_name = NULL;
jack_options_t options = JackNullOption;
jack_status_t status;

if ( argc >= 2 ) /* client name specified? */
{
client_name = argv[1];
if ( argc >= 3 ) /* server name specified? */
{
server_name = argv[2];
options |= JackServerName;
}
}
else /* use basename of argv[0] */
{
client_name = strrchr ( argv[0], '/' );
if ( client_name == 0 )
{
client_name = argv[0];
}
else
{
client_name++;
}
}

/* open a client connection to the JACK server */

client = jack_client_open ( client_name, options, &status, server_name );
if ( client == NULL )
{
fprintf ( stderr, "jack_client_open() failed, "
"status = 0x%2.0x\n", status );
if ( status & JackServerFailed )
{
fprintf ( stderr, "Unable to connect to JACK server\n" );
}
exit ( 1 );
}
if ( status & JackServerStarted )
{
fprintf ( stderr, "JACK server started\n" );
}
if ( status & JackNameNotUnique )
{
client_name = jack_get_client_name ( client );
fprintf ( stderr, "unique name `%s' assigned\n", client_name );
}

/* tell the JACK server to call `process()' whenever
there is work to be done.
*/

jack_set_process_callback ( client, process, 0 );

/* tell the JACK server to call `jack_shutdown()' if
it ever shuts down, either entirely, or if it
just decides to stop calling us.
*/

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 );

if ( ( input_port == NULL ) || ( output_port == NULL ) )
{
fprintf ( stderr, "no more JACK ports available\n" );
exit ( 1 );
}

/* Tell the JACK server that we are ready to roll. Our
* process() callback will start running now. */

if ( jack_activate ( client ) )
{
fprintf ( stderr, "cannot activate client" );
exit ( 1 );
}

/* Connect the ports. You can't do this before the client is
* activated, because we can't make connections to clients
* that aren't running. Note the confusing (but necessary)
* orientation of the driver backend ports: playback ports are
* "input" to the backend, and capture ports are "output" from
* it.
*/

ports = jack_get_ports ( client, NULL, NULL,
JackPortIsPhysical|JackPortIsOutput );
if ( ports == NULL )
{
fprintf ( stderr, "no physical capture ports\n" );
exit ( 1 );
}

if ( jack_connect ( client, ports[0], jack_port_name ( input_port ) ) )
{
fprintf ( stderr, "cannot connect input ports\n" );
}

free ( ports );

ports = jack_get_ports ( client, NULL, NULL,
JackPortIsPhysical|JackPortIsInput );
if ( ports == NULL )
{
fprintf ( stderr, "no physical playback ports\n" );
exit ( 1 );
}

if ( jack_connect ( client, jack_port_name ( output_port ), ports[0] ) )
{
fprintf ( stderr, "cannot connect output ports\n" );
}

free ( ports );

/* install a signal handler to properly quits jack client */
#ifdef WIN32
signal ( SIGINT, signal_handler );
signal ( SIGABRT, signal_handler );
signal ( SIGTERM, signal_handler );
#else
signal ( SIGQUIT, signal_handler );
signal ( SIGTERM, signal_handler );
signal ( SIGHUP, signal_handler );
signal ( SIGINT, signal_handler );
#endif

/* keep running until the transport stops */

while ( client_state != Exit )
{
#ifdef WIN32
Sleep ( 1000 );
#else
sleep ( 1 );
#endif
}

jack_client_close ( client );
exit ( 0 );
}

+ 1
- 0
example-clients/wscript View File

@@ -18,6 +18,7 @@ example_programs = {
'jack_bufsize' : 'bufsize.c',
'jack_evmon' : 'evmon.c',
'jack_monitor_client' : 'monitor_client.c',
'jack_through' : 'through_client.c',
}

example_libs = {


Loading…
Cancel
Save