20 #include "JackMidiPort.h" 21 #include "JackTools.h" 23 #include "transport.h" 25 #include <netinet/in.h> 36 #define htonll(x) ((((uint64_t)htonl(x)) << 32) + htonl(x >> 32)) 37 #define ntohll(x) ((((uint64_t)ntohl(x)) << 32) + ntohl(x >> 32)) 41 #define NETWORK_PROTOCOL 8 43 #define NET_SYNCHING 0 44 #define SYNC_PACKET_ERROR -2 45 #define DATA_PACKET_ERROR -3 47 #define OPTIMIZED_PROTOCOL 1 49 #define UDP_HEADER_SIZE 64 // 40 bytes for IP header in IPV6, 20 in IPV4, 8 for UDP, so take 64 50 #define HEADER_SIZE (sizeof(packet_header_t)) 52 #define PACKET_AVAILABLE_SIZE(params) ((params)->fMtu - UDP_HEADER_SIZE - HEADER_SIZE) 56 typedef struct _session_params session_params_t;
57 typedef struct _packet_header packet_header_t;
58 typedef struct _net_transport_data net_transport_data_t;
59 typedef struct sockaddr socket_address_t;
60 typedef struct in_addr address_t;
61 typedef jack_default_audio_sample_t sample_t;
94 uint32_t fProtocolVersion;
96 char fName[JACK_CLIENT_NAME_SIZE];
97 char fMasterNetName[JACK_SERVER_NAME_SIZE];
98 char fSlaveNetName[JACK_SERVER_NAME_SIZE];
101 uint32_t fTransportSync;
102 int32_t fSendAudioChannels;
103 int32_t fReturnAudioChannels;
104 int32_t fSendMidiChannels;
105 int32_t fReturnMidiChannels;
106 uint32_t fSampleRate;
107 uint32_t fPeriodSize;
108 uint32_t fSampleEncoder;
110 uint32_t fSlaveSyncMode;
111 uint32_t fNetworkLatency;
112 } POST_PACKED_STRUCTURE;
122 NET_SOCKET_ERROR = 0,
131 typedef enum _net_status net_status_t;
139 enum _sync_packet_type
149 typedef enum _sync_packet_type sync_packet_type_t;
178 uint32_t fDataStream;
181 uint32_t fPacketSize;
182 uint32_t fActivePorts;
186 uint32_t fIsLastPckt;
187 } POST_PACKED_STRUCTURE;
195 enum _net_timebase_master
198 RELEASE_TIMEBASEMASTER = 1,
200 CONDITIONAL_TIMEBASEMASTER = 3
203 typedef enum _net_timebase_master net_timebase_master_t;
216 uint32_t fTimebaseMaster;
219 } POST_PACKED_STRUCTURE;
250 size_t fCycleBytesSize;
260 size_t GetCycleSize();
261 int GetNumPackets(
int data_sizen,
int max_size);
267 void DisplayEvents();
270 int RenderFromJackPorts();
271 void RenderToJackPorts();
274 void RenderFromNetwork(
int sub_cycle,
size_t copy_size);
275 int RenderToNetwork(
int sub_cycle,
size_t total_size);
291 sample_t** fPortBuffer;
292 bool* fConnectedPorts;
294 jack_nframes_t fPeriodSize;
295 jack_nframes_t fSubPeriodSize;
296 size_t fSubPeriodBytesSize;
298 float fCycleDuration;
299 size_t fCycleBytesSize;
301 int CheckPacket(
int cycle,
int sub_cycle);
310 bool GetConnected(
int port_index) {
return fConnectedPorts[port_index]; }
311 void SetConnected(
int port_index,
bool state) { fConnectedPorts[port_index] = state; }
314 virtual size_t GetCycleSize() = 0;
317 virtual float GetCycleDuration() = 0;
319 virtual int GetNumPackets(
int active_ports) = 0;
321 virtual void SetBuffer(
int index, sample_t* buffer);
322 virtual sample_t* GetBuffer(
int index);
325 virtual int RenderFromJackPorts(
int nframes);
326 virtual void RenderToJackPorts(
int nframes);
329 virtual int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num) = 0;
330 virtual int RenderToNetwork(
int sub_cycle, uint32_t port_num) = 0;
332 virtual int ActivePortsToNetwork(
char* net_buffer);
333 virtual void ActivePortsFromNetwork(
char* net_buffer, uint32_t port_num);
344 void UpdateParams(
int active_ports);
347 void RenderFromNetwork(
char* net_buffer,
int active_port,
int sub_cycle);
348 void RenderToNetwork(
char* net_buffer,
int active_port,
int sub_cycle);
356 size_t GetCycleSize();
359 float GetCycleDuration();
360 int GetNumPackets(
int active_ports);
363 int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num);
364 int RenderToNetwork(
int sub_cycle, uint32_t port_num);
370 #include <celt/celt.h> 376 CELTMode** fCeltMode;
377 CELTEncoder** fCeltEncoder;
378 CELTDecoder** fCeltDecoder;
380 int fCompressedSizeByte;
381 unsigned char** fCompressedBuffer;
383 size_t fLastSubPeriodBytesSize;
389 NetCeltAudioBuffer(
session_params_t* params, uint32_t nports,
char* net_buffer,
int kbps);
390 virtual ~NetCeltAudioBuffer();
393 size_t GetCycleSize();
396 float GetCycleDuration();
397 int GetNumPackets(
int active_ports);
400 int RenderFromJackPorts(
int nframes);
401 void RenderToJackPorts(
int nframes);
404 int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num);
405 int RenderToNetwork(
int sub_cycle, uint32_t port_num);
412 #include <opus/opus.h> 413 #include <opus/opus_custom.h> 419 OpusCustomMode** fOpusMode;
420 OpusCustomEncoder** fOpusEncoder;
421 OpusCustomDecoder** fOpusDecoder;
423 int fCompressedMaxSizeByte;
424 unsigned short* fCompressedSizesByte;
426 size_t fLastSubPeriodBytesSize;
428 unsigned char** fCompressedBuffer;
433 NetOpusAudioBuffer(
session_params_t* params, uint32_t nports,
char* net_buffer,
int kbps);
434 virtual ~NetOpusAudioBuffer();
437 size_t GetCycleSize();
440 float GetCycleDuration();
441 int GetNumPackets(
int active_ports);
444 int RenderFromJackPorts(
int nframes);
445 void RenderToJackPorts(
int nframes);
448 int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num);
449 int RenderToNetwork(
int sub_cycle, uint32_t port_num);
458 int fCompressedSizeByte;
460 size_t fLastSubPeriodBytesSize;
470 size_t GetCycleSize();
473 float GetCycleDuration();
474 int GetNumPackets(
int active_ports);
477 int RenderFromJackPorts(
int nframes);
478 void RenderToJackPorts(
int nframes);
481 int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num);
482 int RenderToNetwork(
int sub_cycle, uint32_t port_num);
488 SERVER_EXPORT
int SocketAPIInit();
489 SERVER_EXPORT
int SocketAPIEnd();
506 SERVER_EXPORT
int SetPacketType(
session_params_t* params, sync_packet_type_t packet_type);
508 SERVER_EXPORT
const char* GetTransportState(
int transport_state);
This structure containes master/slave connection parameters, it's used to setup the whole system...