Jack2 1.9.6

JackNetManager.h

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