Jack2  1.9.10
JackNetManager.h
00001 /*
00002 Copyright (C) 2008-2011 Romain Moret at Grame
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 
00018 */
00019 
00020 #ifndef __JACKNETMANAGER_H__
00021 #define __JACKNETMANAGER_H__
00022 
00023 #include "JackNetInterface.h"
00024 #include "jack.h"
00025 #include <list>
00026 #include <map>
00027 
00028 namespace Jack
00029 {
00030     class JackNetMasterManager;
00031 
00036     typedef std::list<std::pair<std::string, std::string> > connections_list_t;
00037 
00038     class JackNetMaster : public JackNetMasterInterface
00039     {
00040             friend class JackNetMasterManager;
00041 
00042         private:
00043       
00044             static int SetProcess(jack_nframes_t nframes, void* arg);
00045             static int SetBufferSize(jack_nframes_t nframes, void* arg);
00046             static int SetSampleRate(jack_nframes_t nframes, void* arg);
00047             static void SetTimebaseCallback(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg);
00048             static void SetConnectCallback(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
00049             static void LatencyCallback(jack_latency_callback_mode_t mode, void* arg);
00050 
00051             //jack client
00052             jack_client_t* fClient;
00053             const char* fName;
00054 
00055             //jack ports
00056             jack_port_t** fAudioCapturePorts;
00057             jack_port_t** fAudioPlaybackPorts;
00058             jack_port_t** fMidiCapturePorts;
00059             jack_port_t** fMidiPlaybackPorts;
00060 
00061             //sync and transport
00062             int fLastTransportState;
00063        
00064             //monitoring
00065 #ifdef JACK_MONITOR
00066             jack_time_t fPeriodUsecs;
00067             JackGnuPlotMonitor<float>* fNetTimeMon;
00068 #endif
00069 
00070             bool Init(bool auto_connect);
00071             int AllocPorts();
00072             void FreePorts();
00073 
00074             //transport
00075             void EncodeTransportData();
00076             void DecodeTransportData();
00077 
00078             int Process();
00079             void TimebaseCallback(jack_position_t* pos);
00080             void ConnectPorts();
00081             void ConnectCallback(jack_port_id_t a, jack_port_id_t b, int connect);
00082             
00083             void SaveConnections(connections_list_t& connections);
00084             void LoadConnections(const connections_list_t& connections);
00085 
00086         public:
00087 
00088             JackNetMaster(JackNetSocket& socket, session_params_t& params, const char* multicast_ip);
00089             ~JackNetMaster();
00090 
00091             bool IsSlaveReadyToRoll();
00092     };
00093 
00094     typedef std::list<JackNetMaster*> master_list_t;
00095     typedef master_list_t::iterator master_list_it_t;
00096     typedef std::map <std::string, connections_list_t> master_connections_list_t;
00097 
00102     class JackNetMasterManager
00103     {
00104             friend class JackNetMaster;
00105 
00106         private:
00107 
00108             static void SetShutDown(void* arg);
00109             static int SetSyncCallback(jack_transport_state_t state, jack_position_t* pos, void* arg);
00110             static void* NetManagerThread(void* arg);
00111 
00112             jack_client_t* fClient;
00113             const char* fName;
00114             char fMulticastIP[32];
00115             JackNetSocket fSocket;
00116             jack_native_thread_t fThread;
00117             master_list_t fMasterList;
00118             master_connections_list_t fMasterConnectionList;
00119             uint32_t fGlobalID;
00120             bool fRunning;
00121             bool fAutoConnect;
00122             bool fAutoSave;
00123 
00124             void Run();
00125             JackNetMaster* InitMaster(session_params_t& params);
00126             master_list_it_t FindMaster(uint32_t client_id);
00127             int KillMaster(session_params_t* params);
00128             int SyncCallback(jack_transport_state_t state, jack_position_t* pos);
00129             int CountIO(const char* type, int flags);
00130             void ShutDown();
00131 
00132         public:
00133 
00134             JackNetMasterManager(jack_client_t* jack_client, const JSList* params);
00135             ~JackNetMasterManager();
00136     };
00137 }
00138 
00139 #endif