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.

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