JackNetManager.h 3.64 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
Copyright (C) 2008 Grame

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
sletz's avatar
sletz committed
19

20
21
#ifndef __JACKNETMANAGER_H__
#define __JACKNETMANAGER_H__
sletz's avatar
sletz committed
22

23
#include "JackNetInterface.h"
24
25
#include "thread.h"
#include "jack.h"
26
#include "jslist.h"
moret's avatar
moret committed
27
#include <list>
sletz's avatar
sletz committed
28
29
30

namespace Jack
{
31
32
    class JackNetMasterManager;

moret's avatar
moret committed
33
34
35
    /**
    \Brief This class describes a Net Master
    */
36

37
    class JackNetMaster : public JackNetMasterInterface
38
    {
moret's avatar
moret committed
39
            friend class JackNetMasterManager;
moret's avatar
moret committed
40
41
        private:
            static int SetProcess ( jack_nframes_t nframes, void* arg );
42
            static int SetBufferSize (jack_nframes_t nframes, void* arg);
43
            static void SetTimebaseCallback ( jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg );
moret's avatar
moret committed
44
45
46
47
48
49
50
51
52
53
54
55

            //jack client
            jack_client_t* fJackClient;
            const char* fClientName;

            //jack ports
            jack_port_t** fAudioCapturePorts;
            jack_port_t** fAudioPlaybackPorts;
            jack_port_t** fMidiCapturePorts;
            jack_port_t** fMidiPlaybackPorts;

            //sync and transport
moret's avatar
moret committed
56
            int fLastTransportState;
57
     
moret's avatar
moret committed
58
            //monitoring
59
#ifdef JACK_MONITOR
moret's avatar
moret committed
60
            jack_time_t fPeriodUsecs;
moret's avatar
moret committed
61
            JackGnuPlotMonitor<float>* fNetTimeMon;
moret's avatar
moret committed
62
63
#endif

64
            bool Init(bool auto_connect);
65
            int AllocPorts();
moret's avatar
moret committed
66
            void FreePorts();
67
     
68
            //transport
69
70
            void EncodeTransportData();
            void DecodeTransportData();
71

moret's avatar
moret committed
72
            int Process();
73
            void TimebaseCallback ( jack_position_t* pos );
74
            void ConnectPorts();
75

moret's avatar
moret committed
76
        public:
77
            JackNetMaster ( JackNetSocket& socket, session_params_t& params, const char* multicast_ip);
moret's avatar
moret committed
78
            ~JackNetMaster ();
79
80

            bool IsSlaveReadyToRoll();
81
82
83
84
85
    };

    typedef std::list<JackNetMaster*> master_list_t;
    typedef master_list_t::iterator master_list_it_t;

moret's avatar
moret committed
86
87
88
    /**
    \Brief This class describer the Network Manager
    */
89

90
91
    class JackNetMasterManager
    {
moret's avatar
moret committed
92
93
94
95
96
97
98
            friend class JackNetMaster;
        private:
            static int SetSyncCallback ( jack_transport_state_t state, jack_position_t* pos, void* arg );
            static void* NetManagerThread ( void* arg );

            jack_client_t* fManagerClient;
            const char* fManagerName;
99
            char fMulticastIP[32];
moret's avatar
moret committed
100
101
102
103
104
            JackNetSocket fSocket;
            pthread_t fManagerThread;
            master_list_t fMasterList;
            uint32_t fGlobalID;
            bool fRunning;
105
            bool fAutoConnect;
moret's avatar
moret committed
106
107

            void Run();
108
            JackNetMaster* InitMaster ( session_params_t& params );
moret's avatar
moret committed
109
            master_list_it_t FindMaster ( uint32_t client_id );
110
            int KillMaster ( session_params_t* params );
moret's avatar
moret committed
111
112
113
114
            void SetSlaveName ( session_params_t& params );

            int SyncCallback ( jack_transport_state_t state, jack_position_t* pos );
        public:
115
            JackNetMasterManager ( jack_client_t* jack_client, const JSList* params);
moret's avatar
moret committed
116
            ~JackNetMasterManager();
117
    };
sletz's avatar
sletz committed
118
119
120
}

#endif