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.

151 lines
4.3KB

  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 "JackNetTool.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
  29. {
  30. friend class JackNetMasterManager;
  31. private:
  32. static int SetProcess ( jack_nframes_t nframes, void* arg );
  33. JackNetMasterManager* fMasterManager;
  34. session_params_t fParams;
  35. JackNetSocket fSocket;
  36. uint fNSubProcess;
  37. int fNetJumpCnt;
  38. bool fRunning;
  39. //jack client
  40. jack_client_t* fJackClient;
  41. const char* fClientName;
  42. //jack ports
  43. jack_port_t** fAudioCapturePorts;
  44. jack_port_t** fAudioPlaybackPorts;
  45. jack_port_t** fMidiCapturePorts;
  46. jack_port_t** fMidiPlaybackPorts;
  47. //sync and transport
  48. int fSyncState;
  49. net_transport_data_t fTransportData;
  50. //network headers
  51. packet_header_t fTxHeader;
  52. packet_header_t fRxHeader;
  53. //network buffers
  54. char* fTxBuffer;
  55. char* fRxBuffer;
  56. char* fTxData;
  57. char* fRxData;
  58. //jack buffers
  59. NetAudioBuffer* fNetAudioCaptureBuffer;
  60. NetAudioBuffer* fNetAudioPlaybackBuffer;
  61. NetMidiBuffer* fNetMidiCaptureBuffer;
  62. NetMidiBuffer* fNetMidiPlaybackBuffer;
  63. //sizes
  64. int fAudioTxLen;
  65. int fAudioRxLen;
  66. int fPayloadSize;
  67. //monitoring
  68. #ifdef JACK_MONITOR
  69. static uint fMeasureCnt;
  70. static uint fMeasurePoints;
  71. static uint fMonitorPlotOptionsCnt;
  72. static std::string fMonitorPlotOptions[];
  73. static std::string fMonitorFieldNames[];
  74. jack_time_t fPeriodUsecs;
  75. float* fMeasure;
  76. int fMeasureId;
  77. JackGnuPlotMonitor<float>* fMonitor;
  78. #endif
  79. bool Init();
  80. void FreePorts();
  81. void Exit();
  82. int SetSyncPacket();
  83. int Send ( char* buffer, size_t size, int flags );
  84. int Recv ( size_t size, int flags );
  85. int Process();
  86. public:
  87. JackNetMaster ( JackNetMasterManager* manager, session_params_t& params );
  88. ~JackNetMaster ();
  89. };
  90. typedef std::list<JackNetMaster*> master_list_t;
  91. typedef master_list_t::iterator master_list_it_t;
  92. /**
  93. \Brief This class describer the Network Manager
  94. */
  95. class JackNetMasterManager
  96. {
  97. friend class JackNetMaster;
  98. private:
  99. static int SetSyncCallback ( jack_transport_state_t state, jack_position_t* pos, void* arg );
  100. static void* NetManagerThread ( void* arg );
  101. jack_client_t* fManagerClient;
  102. const char* fManagerName;
  103. const char* fMulticastIP;
  104. JackNetSocket fSocket;
  105. pthread_t fManagerThread;
  106. master_list_t fMasterList;
  107. uint32_t fGlobalID;
  108. bool fRunning;
  109. void Run();
  110. JackNetMaster* MasterInit ( session_params_t& params );
  111. master_list_it_t FindMaster ( uint32_t client_id );
  112. int KillMaster ( session_params_t* params );
  113. void SetSlaveName ( session_params_t& params );
  114. int SyncCallback ( jack_transport_state_t state, jack_position_t* pos );
  115. public:
  116. JackNetMasterManager ( jack_client_t* jack_client, const JSList* params );
  117. ~JackNetMasterManager();
  118. void Exit();
  119. };
  120. }
  121. #endif