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.

124 lines
3.7KB

  1. /*
  2. Copyright (C) 2008 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 "JackNetInterface.h"
  18. #include "thread.h"
  19. #include "jack.h"
  20. #include "jslist.h"
  21. #include <list>
  22. namespace Jack
  23. {
  24. class JackNetMasterManager;
  25. /**
  26. \Brief This class describes a Net Master
  27. */
  28. class JackNetMaster : public JackNetMasterInterface
  29. {
  30. friend class JackNetMasterManager;
  31. private:
  32. static int SetProcess ( jack_nframes_t nframes, void* arg );
  33. static void SetTimebaseCallback ( jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg );
  34. //jack client
  35. jack_client_t* fJackClient;
  36. const char* fClientName;
  37. //jack ports
  38. jack_port_t** fAudioCapturePorts;
  39. jack_port_t** fAudioPlaybackPorts;
  40. jack_port_t** fMidiCapturePorts;
  41. jack_port_t** fMidiPlaybackPorts;
  42. //sync and transport
  43. uint32_t fLastTransportState;
  44. net_transport_data_t fTransportData;
  45. //monitoring
  46. #ifdef JACK_MONITOR
  47. jack_time_t fPeriodUsecs;
  48. JackGnuPlotMonitor<float>* fNetTimeMon;
  49. #endif
  50. bool Init();
  51. int AllocPorts();
  52. void FreePorts();
  53. void Exit();
  54. //transport
  55. int EncodeTransportData();
  56. int DecodeTransportData();
  57. //sync packet
  58. int EncodeSyncPacket();
  59. int DecodeSyncPacket();
  60. int Process();
  61. void TimebaseCallback ( jack_position_t* pos );
  62. public:
  63. JackNetMaster ( JackNetSocket& socket, session_params_t& params, const char* multicast_ip );
  64. ~JackNetMaster ();
  65. bool IsSlaveReadyToRoll();
  66. };
  67. typedef std::list<JackNetMaster*> master_list_t;
  68. typedef master_list_t::iterator master_list_it_t;
  69. /**
  70. \Brief This class describer the Network Manager
  71. */
  72. class JackNetMasterManager
  73. {
  74. friend class JackNetMaster;
  75. private:
  76. static int SetSyncCallback ( jack_transport_state_t state, jack_position_t* pos, void* arg );
  77. static void* NetManagerThread ( void* arg );
  78. jack_client_t* fManagerClient;
  79. const char* fManagerName;
  80. const char* fMulticastIP;
  81. JackNetSocket fSocket;
  82. pthread_t fManagerThread;
  83. master_list_t fMasterList;
  84. uint32_t fGlobalID;
  85. bool fRunning;
  86. void Run();
  87. JackNetMaster* MasterInit ( session_params_t& params );
  88. master_list_it_t FindMaster ( uint32_t client_id );
  89. int KillMaster ( session_params_t* params );
  90. void SetSlaveName ( session_params_t& params );
  91. int SyncCallback ( jack_transport_state_t state, jack_position_t* pos );
  92. public:
  93. JackNetMasterManager ( jack_client_t* jack_client, const JSList* params );
  94. ~JackNetMasterManager();
  95. };
  96. }
  97. #endif