jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.4KB

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