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.

119 lines
3.7KB

  1. /***************************************************************************
  2. * Copyright (C) 2008 by Romain Moret *
  3. * moret@grame.fr *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifndef __JACKNETMASTER_H__
  21. #define __JACKNETMASTER_H__
  22. #include "JackNetTool.h"
  23. #include <list>
  24. #include <algorithm>
  25. #include "thread.h"
  26. #include <unistd.h>
  27. #include "jack.h"
  28. namespace Jack
  29. {
  30. class JackNetMasterManager;
  31. class JackNetMaster
  32. {
  33. friend class JackNetMasterManager;
  34. private:
  35. static int SetProcess ( jack_nframes_t nframes, void* arg );
  36. JackNetMasterManager* fMasterManager;
  37. session_params_t fParams;
  38. struct sockaddr_in fAddr;
  39. struct sockaddr_in fMcastAddr;
  40. int fSockfd;
  41. unsigned int fNSubProcess;
  42. unsigned int fNetJumpCnt;
  43. bool fRunning;
  44. jack_client_t* fJackClient;
  45. const char* fClientName;
  46. jack_port_t** fAudioCapturePorts;
  47. jack_port_t** fAudioPlaybackPorts;
  48. jack_port_t** fMidiCapturePorts;
  49. jack_port_t** fMidiPlaybackPorts;
  50. packet_header_t fTxHeader;
  51. packet_header_t fRxHeader;
  52. char* fTxBuffer;
  53. char* fRxBuffer;
  54. char* fTxData;
  55. char* fRxData;
  56. NetAudioBuffer* fNetAudioCaptureBuffer;
  57. NetAudioBuffer* fNetAudioPlaybackBuffer;
  58. NetMidiBuffer* fNetMidiCaptureBuffer;
  59. NetMidiBuffer* fNetMidiPlaybackBuffer;
  60. int fAudioTxLen;
  61. int fAudioRxLen;
  62. bool Init();
  63. void FreePorts();
  64. void Exit();
  65. int Send ( char* buffer, unsigned int size, int flags );
  66. int Recv ( unsigned int size, int flags );
  67. int Process();
  68. public:
  69. JackNetMaster ( JackNetMasterManager* manager, session_params_t& params, struct sockaddr_in& address, struct sockaddr_in& mcast_addr );
  70. ~JackNetMaster ();
  71. };
  72. typedef std::list<JackNetMaster*> master_list_t;
  73. typedef master_list_t::iterator master_list_it_t;
  74. class JackNetMasterManager
  75. {
  76. private:
  77. static void* NetManagerThread ( void* arg );
  78. static int SetProcess ( jack_nframes_t nframes, void* arg );
  79. jack_client_t* fManagerClient;
  80. const char* fManagerName;
  81. const char* fMCastIP;
  82. pthread_t fManagerThread;
  83. master_list_t fMasterList;
  84. unsigned int fGlobalID;
  85. bool fRunning;
  86. unsigned int fPort;
  87. void Run();
  88. JackNetMaster* MasterInit ( session_params_t& params, struct sockaddr_in& address, struct sockaddr_in& mcast_addr );
  89. master_list_it_t FindMaster ( unsigned int client_id );
  90. void KillMaster ( session_params_t* params );
  91. void SetSlaveName ( session_params_t& params );
  92. int Process();
  93. public:
  94. JackNetMasterManager ( jack_client_t* jack_client );
  95. ~JackNetMasterManager();
  96. void Exit();
  97. };
  98. }
  99. #endif