2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2008 Romain Moret at Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __JackNetInterface__
22 #define __JackNetInterface__
24 #include "JackNetTool.h"
29 \Brief This class describes the basic Net Interface, used by both master and slave
32 class SERVER_EXPORT JackNetInterface
35 session_params_t fParams
;
36 JackNetSocket fSocket
;
37 char fMulticastIP
[32];
41 packet_header_t fTxHeader
;
42 packet_header_t fRxHeader
;
45 net_transport_data_t fSendTransportData
;
46 net_transport_data_t fReturnTransportData
;
55 NetMidiBuffer
* fNetMidiCaptureBuffer
;
56 NetMidiBuffer
* fNetMidiPlaybackBuffer
;
57 NetAudioBuffer
* fNetAudioCaptureBuffer
;
58 NetAudioBuffer
* fNetAudioPlaybackBuffer
;
66 void SetFramesPerPacket();
67 int SetNetBufferSize();
71 //virtual methods : depends on the sub class master/slave
72 virtual void SetParams();
73 virtual bool Init() = 0;
76 virtual void EncodeTransportData() = 0;
77 virtual void DecodeTransportData() = 0;
80 virtual void EncodeSyncPacket() = 0;
81 virtual void DecodeSyncPacket() = 0;
83 virtual int SyncRecv() = 0;
84 virtual int SyncSend() = 0;
85 virtual int DataRecv() = 0;
86 virtual int DataSend() = 0;
88 virtual int Send ( size_t size
, int flags
) = 0;
89 virtual int Recv ( size_t size
, int flags
) = 0;
92 JackNetInterface ( const char* multicast_ip
, int port
);
93 JackNetInterface ( session_params_t
& params
, JackNetSocket
& socket
, const char* multicast_ip
);
96 virtual ~JackNetInterface();
100 \Brief This class describes the Net Interface for masters (NetMaster)
103 class SERVER_EXPORT JackNetMasterInterface
: public JackNetInterface
122 void EncodeSyncPacket();
123 void DecodeSyncPacket();
125 int Send ( size_t size
, int flags
);
126 int Recv ( size_t size
, int flags
);
131 JackNetMasterInterface() : JackNetInterface(), fRunning(false), fCycleOffset(0)
133 JackNetMasterInterface ( session_params_t
& params
, JackNetSocket
& socket
, const char* multicast_ip
)
134 : JackNetInterface ( params
, socket
, multicast_ip
)
136 ~JackNetMasterInterface()
141 \Brief This class describes the Net Interface for slaves (NetDriver and NetAdapter)
144 class SERVER_EXPORT JackNetSlaveInterface
: public JackNetInterface
148 static uint fSlaveCounter
;
151 bool InitConnection();
152 bool InitRendering();
154 net_status_t
SendAvailableToMaster();
155 net_status_t
SendStartToMaster();
166 void EncodeSyncPacket();
167 void DecodeSyncPacket();
169 int Recv ( size_t size
, int flags
);
170 int Send ( size_t size
, int flags
);
173 JackNetSlaveInterface() : JackNetInterface()
175 //open Socket API with the first slave
176 if ( fSlaveCounter
++ == 0 )
178 if ( SocketAPIInit() < 0 )
180 jack_error ( "Can't init Socket API, exiting..." );
185 JackNetSlaveInterface ( const char* ip
, int port
) : JackNetInterface ( ip
, port
)
187 //open Socket API with the first slave
188 if ( fSlaveCounter
++ == 0 )
190 if ( SocketAPIInit() < 0 )
192 jack_error ( "Can't init Socket API, exiting..." );
197 ~JackNetSlaveInterface()
199 //close Socket API with the last slave
200 if ( --fSlaveCounter
== 0 )
206 #define DEFAULT_MULTICAST_IP "225.3.19.154"
207 #define DEFAULT_PORT 19000
208 #define DEFAULT_MTU 1500
210 #define SLAVE_SETUP_RETRY 5
212 #define MASTER_INIT_TIMEOUT 1000000 // in usec
213 #define SLAVE_INIT_TIMEOUT 2000000 // in usec
215 #define MAX_LATENCY 6