Jack2  1.9.8
JackNetManager.h
1 /*
2 Copyright (C) 2008-2011 Romain Moret at Grame
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #ifndef __JACKNETMANAGER_H__
21 #define __JACKNETMANAGER_H__
22 
23 #include "JackNetInterface.h"
24 #include "thread.h"
25 #include "jack.h"
26 #include "jslist.h"
27 #include <list>
28 
29 namespace Jack
30 {
31  class JackNetMasterManager;
32 
38  {
39  friend class JackNetMasterManager;
40 
41  private:
42 
43  static int SetProcess(jack_nframes_t nframes, void* arg);
44  static int SetBufferSize(jack_nframes_t nframes, void* arg);
45  static void SetTimebaseCallback(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg);
46 
47  //jack client
48  jack_client_t* fJackClient;
49  const char* fClientName;
50 
51  //jack ports
52  jack_port_t** fAudioCapturePorts;
53  jack_port_t** fAudioPlaybackPorts;
54  jack_port_t** fMidiCapturePorts;
55  jack_port_t** fMidiPlaybackPorts;
56 
57  //sync and transport
58  int fLastTransportState;
59 
60  //monitoring
61 #ifdef JACK_MONITOR
62  jack_time_t fPeriodUsecs;
63  JackGnuPlotMonitor<float>* fNetTimeMon;
64 #endif
65 
66  bool Init(bool auto_connect);
67  int AllocPorts();
68  void FreePorts();
69 
70  //transport
71  void EncodeTransportData();
72  void DecodeTransportData();
73 
74  int Process();
75  void TimebaseCallback(jack_position_t* pos);
76  void ConnectPorts();
77 
78  public:
79 
80  JackNetMaster(JackNetSocket& socket, session_params_t& params, const char* multicast_ip);
81  ~JackNetMaster();
82 
83  bool IsSlaveReadyToRoll();
84  };
85 
86  typedef std::list<JackNetMaster*> master_list_t;
87  typedef master_list_t::iterator master_list_it_t;
88 
94  {
95  friend class JackNetMaster;
96 
97  private:
98 
99  static int SetSyncCallback(jack_transport_state_t state, jack_position_t* pos, void* arg);
100  static void* NetManagerThread(void* arg);
101 
102  jack_client_t* fManagerClient;
103  const char* fManagerName;
104  char fMulticastIP[32];
105  JackNetSocket fSocket;
106  jack_native_thread_t fManagerThread;
107  master_list_t fMasterList;
108  uint32_t fGlobalID;
109  bool fRunning;
110  bool fAutoConnect;
111 
112  void Run();
113  JackNetMaster* InitMaster(session_params_t& params);
114  master_list_it_t FindMaster(uint32_t client_id);
115  int KillMaster(session_params_t* params);
116  int SyncCallback(jack_transport_state_t state, jack_position_t* pos);
117  int CountIO(int flags);
118 
119  public:
120 
121  JackNetMasterManager(jack_client_t* jack_client, const JSList* params);
123  };
124 }
125 
126 #endif