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.

147 lines
5.5KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __JackGraphManager__
  17. #define __JackGraphManager__
  18. #include "JackShmMem.h"
  19. #include "JackPort.h"
  20. #include "JackConstants.h"
  21. #include "JackConnectionManager.h"
  22. #include "JackAtomicState.h"
  23. #include "JackPlatformPlug.h"
  24. #include "JackSystemDeps.h"
  25. namespace Jack
  26. {
  27. /*!
  28. \brief Graph manager: contains the connection manager and the port array.
  29. */
  30. PRE_PACKED_STRUCTURE
  31. class SERVER_EXPORT JackGraphManager : public JackShmMem, public JackAtomicState<JackConnectionManager>
  32. {
  33. private:
  34. unsigned int fPortMax;
  35. JackClientTiming fClientTiming[CLIENT_NUM];
  36. JackPort fPortArray[0]; // The actual size depends of port_max, it will be dynamically computed and allocated using "placement" new
  37. void AssertPort(jack_port_id_t port_index);
  38. jack_port_id_t AllocatePortAux(int refnum, const char* port_name, const char* port_type, JackPortFlags flags);
  39. void GetConnectionsAux(JackConnectionManager* manager, const char** res, jack_port_id_t port_index);
  40. void GetPortsAux(const char** matching_ports, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);
  41. jack_default_audio_sample_t* GetBuffer(jack_port_id_t port_index);
  42. void* GetBufferAux(JackConnectionManager* manager, jack_port_id_t port_index, jack_nframes_t frames);
  43. jack_nframes_t ComputeTotalLatencyAux(jack_port_id_t port_index, jack_port_id_t src_port_index, JackConnectionManager* manager, int hop_count);
  44. void RecalculateLatencyAux(jack_port_id_t port_index, jack_latency_callback_mode_t mode);
  45. public:
  46. JackGraphManager(int port_max);
  47. ~JackGraphManager()
  48. {}
  49. void SetBufferSize(jack_nframes_t buffer_size);
  50. // Ports management
  51. jack_port_id_t AllocatePort(int refnum, const char* port_name, const char* port_type, JackPortFlags flags, jack_nframes_t buffer_size);
  52. int ReleasePort(int refnum, jack_port_id_t port_index);
  53. void GetInputPorts(int refnum, jack_int_t* res);
  54. void GetOutputPorts(int refnum, jack_int_t* res);
  55. void RemoveAllPorts(int refnum);
  56. void DisconnectAllPorts(int refnum);
  57. JackPort* GetPort(jack_port_id_t index);
  58. jack_port_id_t GetPort(const char* name);
  59. int ComputeTotalLatency(jack_port_id_t port_index);
  60. int ComputeTotalLatencies();
  61. void RecalculateLatency(jack_port_id_t port_index, jack_latency_callback_mode_t mode);
  62. int RequestMonitor(jack_port_id_t port_index, bool onoff);
  63. // Connections management
  64. int Connect(jack_port_id_t src_index, jack_port_id_t dst_index);
  65. int Disconnect(jack_port_id_t src_index, jack_port_id_t dst_index);
  66. int IsConnected(jack_port_id_t port_src, jack_port_id_t port_dst);
  67. // RT, client
  68. int GetConnectionsNum(jack_port_id_t port_index)
  69. {
  70. JackConnectionManager* manager = ReadCurrentState();
  71. return manager->Connections(port_index);
  72. }
  73. const char** GetConnections(jack_port_id_t port_index);
  74. void GetConnections(jack_port_id_t port_index, jack_int_t* connections); // TODO
  75. const char** GetPorts(const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);
  76. int GetTwoPorts(const char* src, const char* dst, jack_port_id_t* src_index, jack_port_id_t* dst_index);
  77. int CheckPorts(jack_port_id_t port_src, jack_port_id_t port_dst);
  78. void DisconnectAllInput(jack_port_id_t port_index);
  79. void DisconnectAllOutput(jack_port_id_t port_index);
  80. int DisconnectAll(jack_port_id_t port_index);
  81. bool IsDirectConnection(int ref1, int ref2);
  82. void DirectConnect(int ref1, int ref2);
  83. void DirectDisconnect(int ref1, int ref2);
  84. void Activate(int refnum);
  85. void Deactivate(int refnum);
  86. int GetInputRefNum(jack_port_id_t port_index);
  87. int GetOutputRefNum(jack_port_id_t port_index);
  88. // Buffer management
  89. void* GetBuffer(jack_port_id_t port_index, jack_nframes_t frames);
  90. // Activation management
  91. void RunCurrentGraph();
  92. bool RunNextGraph();
  93. bool IsFinishedGraph();
  94. void InitRefNum(int refnum);
  95. int ResumeRefNum(JackClientControl* control, JackSynchro* table);
  96. int SuspendRefNum(JackClientControl* control, JackSynchro* table, long usecs);
  97. void TopologicalSort(std::vector<jack_int_t>& sorted);
  98. JackClientTiming* GetClientTiming(int refnum)
  99. {
  100. return &fClientTiming[refnum];
  101. }
  102. void Save(JackConnectionManager* dst);
  103. void Restore(JackConnectionManager* src);
  104. static JackGraphManager* Allocate(int port_max);
  105. static void Destroy(JackGraphManager* manager);
  106. } POST_PACKED_STRUCTURE;
  107. } // end of namespace
  108. #endif