Jack2 1.9.8

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 "thread.h"
00025 #include "jack.h"
00026 #include "jslist.h"
00027 #include <list>
00028 
00029 namespace Jack
00030 {
00031     class JackNetMasterManager;
00032 
00037     class JackNetMaster : public JackNetMasterInterface
00038     {
00039             friend class JackNetMasterManager;
00040 
00041         private:
00042 
00043             static int SetProcess(jack_nframes_t nframes, void* arg);
00044             static int SetBufferSize(jack_nframes_t nframes, void* arg);
00045             static void SetTimebaseCallback(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg);
00046 
00047             //jack client
00048             jack_client_t* fJackClient;
00049             const char* fClientName;
00050 
00051             //jack ports
00052             jack_port_t** fAudioCapturePorts;
00053             jack_port_t** fAudioPlaybackPorts;
00054             jack_port_t** fMidiCapturePorts;
00055             jack_port_t** fMidiPlaybackPorts;
00056 
00057             //sync and transport
00058             int fLastTransportState;
00059 
00060             //monitoring
00061 #ifdef JACK_MONITOR
00062             jack_time_t fPeriodUsecs;
00063             JackGnuPlotMonitor<float>* fNetTimeMon;
00064 #endif
00065 
00066             bool Init(bool auto_connect);
00067             int AllocPorts();
00068             void FreePorts();
00069 
00070             //transport
00071             void EncodeTransportData();
00072             void DecodeTransportData();
00073 
00074             int Process();
00075             void TimebaseCallback(jack_position_t* pos);
00076             void ConnectPorts();
00077 
00078         public:
00079 
00080             JackNetMaster(JackNetSocket& socket, session_params_t& params, const char* multicast_ip);
00081             ~JackNetMaster();
00082 
00083             bool IsSlaveReadyToRoll();
00084     };
00085 
00086     typedef std::list<JackNetMaster*> master_list_t;
00087     typedef master_list_t::iterator master_list_it_t;
00088 
00093     class JackNetMasterManager
00094     {
00095             friend class JackNetMaster;
00096 
00097         private:
00098 
00099             static int SetSyncCallback(jack_transport_state_t state, jack_position_t* pos, void* arg);
00100             static void* NetManagerThread(void* arg);
00101 
00102             jack_client_t* fManagerClient;
00103             const char* fManagerName;
00104             char fMulticastIP[32];
00105             JackNetSocket fSocket;
00106             jack_native_thread_t fManagerThread;
00107             master_list_t fMasterList;
00108             uint32_t fGlobalID;
00109             bool fRunning;
00110             bool fAutoConnect;
00111 
00112             void Run();
00113             JackNetMaster* InitMaster(session_params_t& params);
00114             master_list_it_t FindMaster(uint32_t client_id);
00115             int KillMaster(session_params_t* params);
00116             int SyncCallback(jack_transport_state_t state, jack_position_t* pos);
00117             int CountIO(int flags);
00118 
00119         public:
00120 
00121             JackNetMasterManager(jack_client_t* jack_client, const JSList* params);
00122             ~JackNetMasterManager();
00123     };
00124 }
00125 
00126 #endif