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 5
42 #define SLAVE_PROTOCOL 5
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;
89 char fProtocolVersion;
91 char fName[JACK_CLIENT_NAME_SIZE];
92 char fMasterNetName[256];
93 char fSlaveNetName[256];
96 uint32_t fTransportSync;
97 int32_t fSendAudioChannels;
98 int32_t fReturnAudioChannels;
99 int32_t fSendMidiChannels;
100 int32_t fReturnMidiChannels;
101 uint32_t fSampleRate;
102 uint32_t fPeriodSize;
103 uint32_t fSampleEncoder;
105 uint32_t fSlaveSyncMode;
106 uint32_t fNetworkLatency;
117 NET_SOCKET_ERROR = 0,
126 typedef enum _net_status net_status_t;
134 enum _sync_packet_type
144 typedef enum _sync_packet_type sync_packet_type_t;
175 uint32_t fPacketSize;
176 uint32_t fActivePorts;
179 uint32_t fIsLastPckt;
188 enum _net_timebase_master
191 RELEASE_TIMEBASEMASTER = 1,
193 CONDITIONAL_TIMEBASEMASTER = 3
196 typedef enum _net_timebase_master net_timebase_master_t;
208 uint32_t fTimebaseMaster;
242 size_t fCycleBytesSize;
252 size_t GetCycleSize();
253 int GetNumPackets(
int data_sizen,
int max_size);
259 void DisplayEvents();
262 int RenderFromJackPorts();
263 void RenderToJackPorts();
266 void RenderFromNetwork(
int sub_cycle,
size_t copy_size);
267 int RenderToNetwork(
int sub_cycle,
size_t total_size);
282 sample_t** fPortBuffer;
283 bool* fConnectedPorts;
285 jack_nframes_t fPeriodSize;
286 jack_nframes_t fSubPeriodSize;
287 size_t fSubPeriodBytesSize;
289 float fCycleDuration;
290 size_t fCycleBytesSize;
292 int CheckPacket(
int cycle,
int sub_cycle);
301 bool GetConnected(
int port_index) {
return fConnectedPorts[port_index]; }
302 void SetConnected(
int port_index,
bool state) { fConnectedPorts[port_index] = state; }
305 virtual size_t GetCycleSize() = 0;
308 virtual float GetCycleDuration() = 0;
310 virtual int GetNumPackets(
int active_ports) = 0;
312 virtual void SetBuffer(
int index, sample_t* buffer);
313 virtual sample_t* GetBuffer(
int index);
316 virtual int RenderFromJackPorts();
317 virtual void RenderToJackPorts();
320 virtual int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num) = 0;
321 virtual int RenderToNetwork(
int sub_cycle, uint32_t port_num) = 0;
323 virtual void RenderFromNetwork(
char* net_buffer,
int active_port,
int sub_cycle,
size_t copy_size) {}
324 virtual void RenderToNetwork(
char* net_buffer,
int active_port,
int sub_cycle,
size_t copy_size) {}
326 virtual int ActivePortsToNetwork(
char* net_buffer);
327 virtual void ActivePortsFromNetwork(
char* net_buffer, uint32_t port_num);
338 void UpdateParams(
int active_ports);
346 size_t GetCycleSize();
349 float GetCycleDuration();
350 int GetNumPackets(
int active_ports);
353 int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num);
354 int RenderToNetwork(
int sub_cycle, uint32_t port_num);
356 void RenderFromNetwork(
char* net_buffer,
int active_port,
int sub_cycle);
357 void RenderToNetwork(
char* net_buffer,
int active_port,
int sub_cycle);
363 #include <celt/celt.h>
369 CELTMode** fCeltMode;
370 CELTEncoder** fCeltEncoder;
371 CELTDecoder** fCeltDecoder;
373 int fCompressedSizeByte;
376 size_t fLastSubPeriodBytesSize;
378 unsigned char** fCompressedBuffer;
384 NetCeltAudioBuffer(
session_params_t* params, uint32_t nports,
char* net_buffer,
int kbps);
385 virtual ~NetCeltAudioBuffer();
388 size_t GetCycleSize();
391 float GetCycleDuration();
392 int GetNumPackets(
int active_ports);
395 int RenderFromJackPorts();
396 void RenderToJackPorts();
399 int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num);
400 int RenderToNetwork(
int sub_cycle, uint32_t port_num);
409 int fCompressedSizeByte;
412 size_t fLastSubPeriodBytesSize;
422 size_t GetCycleSize();
425 float GetCycleDuration();
426 int GetNumPackets(
int active_ports);
429 int RenderFromJackPorts();
430 void RenderToJackPorts();
433 int RenderFromNetwork(
int cycle,
int sub_cycle, uint32_t port_num);
434 int RenderToNetwork(
int sub_cycle, uint32_t port_num);
440 SERVER_EXPORT
int SocketAPIInit();
441 SERVER_EXPORT
int SocketAPIEnd();
458 SERVER_EXPORT
int SetPacketType(
session_params_t* params, sync_packet_type_t packet_type);
460 SERVER_EXPORT
const char* GetTransportState(
int transport_state);