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 MASTER_PROTOCOL 6
42 #define SLAVE_PROTOCOL 6
44 #define NET_PACKET_ERROR -2
46 #define OPTIMIZED_PROTOCOL
48 #define HEADER_SIZE (sizeof(packet_header_t))
49 #define PACKET_AVAILABLE_SIZE(params) ((params)->fMtu - sizeof(packet_header_t))
53 typedef struct _session_params session_params_t;
54 typedef struct _packet_header packet_header_t;
55 typedef struct _net_transport_data net_transport_data_t;
56 typedef struct sockaddr socket_address_t;
57 typedef struct in_addr address_t;
58 typedef jack_default_audio_sample_t sample_t;
91 uint32_t fProtocolVersion;
93 char fName[JACK_CLIENT_NAME_SIZE];
94 char fMasterNetName[256];
95 char fSlaveNetName[256];
98 uint32_t fTransportSync;
99 int32_t fSendAudioChannels;
100 int32_t fReturnAudioChannels;
101 int32_t fSendMidiChannels;
102 int32_t fReturnMidiChannels;
103 uint32_t fSampleRate;
104 uint32_t fPeriodSize;
105 uint32_t fSampleEncoder;
107 uint32_t fSlaveSyncMode;
108 uint32_t fNetworkLatency;
109 } POST_PACKED_STRUCTURE;
119 NET_SOCKET_ERROR = 0,
128 typedef enum _net_status net_status_t;
136 enum _sync_packet_type
146 typedef enum _sync_packet_type sync_packet_type_t;
175 uint32_t fDataStream;
178 uint32_t fPacketSize;
179 uint32_t fActivePorts;
182 uint32_t fIsLastPckt;
183 } POST_PACKED_STRUCTURE;
191 enum _net_timebase_master
194 RELEASE_TIMEBASEMASTER = 1,
196 CONDITIONAL_TIMEBASEMASTER = 3
199 typedef enum _net_timebase_master net_timebase_master_t;
212 uint32_t fTimebaseMaster;
215 } POST_PACKED_STRUCTURE;
246 size_t fCycleBytesSize;
256 size_t GetCycleSize();
257 int GetNumPackets(
int data_sizen,
int max_size);
263 void DisplayEvents();
266 int RenderFromJackPorts();
267 void RenderToJackPorts();
270 void RenderFromNetwork(
int sub_cycle,
size_t copy_size);
271 int RenderToNetwork(
int sub_cycle,
size_t total_size);
286 sample_t** fPortBuffer;
287 bool* fConnectedPorts;
289 jack_nframes_t fPeriodSize;
290 jack_nframes_t fSubPeriodSize;
291 size_t fSubPeriodBytesSize;
293 float fCycleDuration;
294 size_t fCycleBytesSize;
296 int CheckPacket(
int cycle,
int sub_cycle);
305 bool GetConnected(
int port_index) {
return fConnectedPorts[port_index]; }
306 void SetConnected(
int port_index,
bool state) { fConnectedPorts[port_index] = state; }
309 virtual size_t GetCycleSize() = 0;
312 virtual float GetCycleDuration() = 0;
314 virtual int GetNumPackets(
int active_ports) = 0;
316 virtual void SetBuffer(
int index, sample_t* buffer);
317 virtual sample_t* GetBuffer(
int index);
320 virtual int RenderFromJackPorts();
321 virtual void RenderToJackPorts();
324 virtual int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num) = 0;
325 virtual int RenderToNetwork(
int sub_cycle, uint32_t port_num) = 0;
327 virtual void RenderFromNetwork(
char* net_buffer,
int active_port,
int sub_cycle,
size_t copy_size) {}
328 virtual void RenderToNetwork(
char* net_buffer,
int active_port,
int sub_cycle,
size_t copy_size) {}
330 virtual int ActivePortsToNetwork(
char* net_buffer);
331 virtual void ActivePortsFromNetwork(
char* net_buffer, uint32_t port_num);
342 void UpdateParams(
int active_ports);
350 size_t GetCycleSize();
353 float GetCycleDuration();
354 int GetNumPackets(
int active_ports);
357 int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num);
358 int RenderToNetwork(
int sub_cycle, uint32_t port_num);
360 void RenderFromNetwork(
char* net_buffer,
int active_port,
int sub_cycle);
361 void RenderToNetwork(
char* net_buffer,
int active_port,
int sub_cycle);
367 #include <celt/celt.h>
373 CELTMode** fCeltMode;
374 CELTEncoder** fCeltEncoder;
375 CELTDecoder** fCeltDecoder;
377 int fCompressedSizeByte;
380 size_t fLastSubPeriodBytesSize;
382 unsigned char** fCompressedBuffer;
388 NetCeltAudioBuffer(
session_params_t* params, uint32_t nports,
char* net_buffer,
int kbps);
389 virtual ~NetCeltAudioBuffer();
392 size_t GetCycleSize();
395 float GetCycleDuration();
396 int GetNumPackets(
int active_ports);
399 int RenderFromJackPorts();
400 void RenderToJackPorts();
403 int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num);
404 int RenderToNetwork(
int sub_cycle, uint32_t port_num);
411 #include <opus/opus.h>
412 #include <opus/opus_custom.h>
414 class SERVER_EXPORT NetOpusAudioBuffer :
public NetAudioBuffer
418 OpusCustomMode** fOpusMode;
419 OpusCustomEncoder** fOpusEncoder;
420 OpusCustomDecoder** fOpusDecoder;
422 unsigned short *fCompressedSizesByte;
423 int fCompressedMaxSizeByte;
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();
445 void RenderToJackPorts();
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;
461 size_t fLastSubPeriodBytesSize;
471 size_t GetCycleSize();
474 float GetCycleDuration();
475 int GetNumPackets(
int active_ports);
478 int RenderFromJackPorts();
479 void RenderToJackPorts();
482 int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num);
483 int RenderToNetwork(
int sub_cycle, uint32_t port_num);
489 SERVER_EXPORT
int SocketAPIInit();
490 SERVER_EXPORT
int SocketAPIEnd();
507 SERVER_EXPORT
int SetPacketType(
session_params_t* params, sync_packet_type_t packet_type);
509 SERVER_EXPORT
const char* GetTransportState(
int transport_state);
This structure containes master/slave connection parameters, it's used to setup the whole system...