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.

140 lines
3.8KB

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