net.h
/*
Copyright (C) 2009-2010 Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __net_h__
#define __net_h__
#ifdef __cplusplus
extern "C"
{
#endif
#include <jack/systemdeps.h>
#include <jack/types.h>
#include <jack/weakmacros.h>
#define DEFAULT_MULTICAST_IP "225.3.19.154"
#define DEFAULT_PORT 19000
#define DEFAULT_MTU 1500
#define MASTER_NAME_SIZE 256
// Possible error codes
#define NO_ERROR 0
#define SOCKET_ERROR -1
#define SYNC_PACKET_ERROR -2
#define DATA_PACKET_ERROR -3
#define RESTART_CB_API 1
enum JackNetEncoder {
JackFloatEncoder = 0, // samples are transmitted as float
JackIntEncoder = 1, // samples are transmitted as 16 bits integer
JackCeltEncoder = 2, // samples are transmitted using CELT codec (http://www.celt-codec.org/)
JackOpusEncoder = 3, // samples are transmitted using OPUS codec (http://www.opus-codec.org/)
};
typedef struct {
int audio_input; // from master or to slave (-1 to take master audio physical inputs)
int audio_output; // to master or from slave (-1 to take master audio physical outputs)
int midi_input; // from master or to slave (-1 to take master MIDI physical inputs)
int midi_output; // to master or from slave (-1 to take master MIDI physical outputs)
int mtu; // network Maximum Transmission Unit
int time_out; // in second, -1 means infinite
int encoder; // encoder type (one of JackNetEncoder)
int kbps; // KB per second for CELT or OPUS codec
int latency; // network latency in number of buffers
} jack_slave_t;
typedef struct {
int audio_input; // master audio physical outputs (-1 to take slave wanted audio inputs)
int audio_output; // master audio physical inputs (-1 to take slave wanted audio outputs)
int midi_input; // master MIDI physical outputs (-1 to take slave wanted MIDI inputs)
int midi_output; // master MIDI physical inputs (-1 to take slave wanted MIDI outputs)
jack_nframes_t buffer_size; // master buffer size
jack_nframes_t sample_rate; // master sample rate
char master_name[MASTER_NAME_SIZE]; // master machine name
int time_out; // in second, -1 means infinite
int partial_cycle; // if 'true', partial buffers will be used
} jack_master_t;
typedef struct _jack_net_slave jack_net_slave_t;
jack_net_slave_t* jack_net_slave_open(const char* ip, int port, const char* name, jack_slave_t* request, jack_master_t* result);
int jack_net_slave_close(jack_net_slave_t* net);
typedef int (* JackNetSlaveProcessCallback) (jack_nframes_t buffer_size,
int audio_input,
float** audio_input_buffer,
int midi_input,
void** midi_input_buffer,
int audio_output,
float** audio_output_buffer,
int midi_output,
void** midi_output_buffer,
void* data);
int jack_set_net_slave_process_callback(jack_net_slave_t * net, JackNetSlaveProcessCallback net_callback, void *arg);
int jack_net_slave_activate(jack_net_slave_t* net);
int jack_net_slave_deactivate(jack_net_slave_t* net);
int jack_net_slave_is_active(jack_net_slave_t* net);
typedef int (*JackNetSlaveBufferSizeCallback)(jack_nframes_t nframes, void *arg);
int jack_set_net_slave_buffer_size_callback(jack_net_slave_t *net, JackNetSlaveBufferSizeCallback bufsize_callback, void *arg);
typedef int (*JackNetSlaveSampleRateCallback)(jack_nframes_t nframes, void *arg);
int jack_set_net_slave_sample_rate_callback(jack_net_slave_t *net, JackNetSlaveSampleRateCallback samplerate_callback, void *arg);
typedef void (*JackNetSlaveShutdownCallback)(void* arg);
int jack_set_net_slave_shutdown_callback(jack_net_slave_t *net, JackNetSlaveShutdownCallback shutdown_callback, void *arg) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
typedef int (*JackNetSlaveRestartCallback)(void* arg);
int jack_set_net_slave_restart_callback(jack_net_slave_t *net, JackNetSlaveRestartCallback restart_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
typedef void (*JackNetSlaveErrorCallback) (int error_code, void* arg);
int jack_set_net_slave_error_callback(jack_net_slave_t *net, JackNetSlaveErrorCallback error_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
typedef struct _jack_net_master jack_net_master_t;
jack_net_master_t* jack_net_master_open(const char* ip, int port, jack_master_t* request, jack_slave_t* result);
int jack_net_master_close(jack_net_master_t* net);
int jack_net_master_recv(jack_net_master_t* net, int audio_input, float** audio_input_buffer, int midi_input, void** midi_input_buffer);
int jack_net_master_recv_slice(jack_net_master_t* net, int audio_input, float** audio_input_buffer, int midi_input, void** midi_input_buffer, int frames);
int jack_net_master_send(jack_net_master_t* net, int audio_output, float** audio_output_buffer, int midi_output, void** midi_output_buffer);
int jack_net_master_send_slice(jack_net_master_t* net, int audio_output, float** audio_output_buffer, int midi_output, void** midi_output_buffer, int frames);
// Experimental Adapter API
typedef struct _jack_adapter jack_adapter_t;
jack_adapter_t* jack_create_adapter(int input, int output,
jack_nframes_t host_buffer_size,
jack_nframes_t host_sample_rate,
jack_nframes_t adapted_buffer_size,
jack_nframes_t adapted_sample_rate);
int jack_destroy_adapter(jack_adapter_t* adapter);
void jack_flush_adapter(jack_adapter_t* adapter);
int jack_adapter_push_and_pull(jack_adapter_t* adapter, float** input, float** output, unsigned int frames);
int jack_adapter_pull_and_push(jack_adapter_t* adapter, float** input, float** output, unsigned int frames);
#ifdef __cplusplus
}
#endif
#endif /* __net_h__ */
jack_master_t
Definition: JackNetAPI.cpp:57
jack_slave_t
Definition: JackNetAPI.cpp:43