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.

281 lines
8.8KB

  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 General Public License as published by
  6. the Free Software Foundation; either version 2 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 General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #ifndef __JackDriver__
  17. #define __JackDriver__
  18. #include "types.h"
  19. #include "JackClientInterface.h"
  20. #include "JackConstants.h"
  21. #include "JackPlatformPlug.h"
  22. #include "JackClientControl.h"
  23. #include <list>
  24. namespace Jack
  25. {
  26. class JackLockedEngine;
  27. class JackGraphManager;
  28. struct JackEngineControl;
  29. class JackSlaveDriverInterface;
  30. /*!
  31. \brief The base interface for drivers.
  32. */
  33. class SERVER_EXPORT JackDriverInterface
  34. {
  35. public:
  36. JackDriverInterface()
  37. {}
  38. virtual ~JackDriverInterface()
  39. {}
  40. virtual int Open() = 0;
  41. virtual int Open (bool capturing,
  42. bool playing,
  43. int inchannels,
  44. int outchannels,
  45. bool monitor,
  46. const char* capture_driver_name,
  47. const char* playback_driver_name,
  48. jack_nframes_t capture_latency,
  49. jack_nframes_t playback_latency) = 0;
  50. virtual int Open(jack_nframes_t buffer_size,
  51. jack_nframes_t samplerate,
  52. bool capturing,
  53. bool playing,
  54. int inchannels,
  55. int outchannels,
  56. bool monitor,
  57. const char* capture_driver_name,
  58. const char* playback_driver_name,
  59. jack_nframes_t capture_latency,
  60. jack_nframes_t playback_latency) = 0;
  61. virtual int Attach() = 0;
  62. virtual int Detach() = 0;
  63. virtual int Read() = 0;
  64. virtual int Write() = 0;
  65. virtual int Start() = 0;
  66. virtual int Stop() = 0;
  67. virtual bool IsFixedBufferSize() = 0;
  68. virtual int SetBufferSize(jack_nframes_t buffer_size) = 0;
  69. virtual int SetSampleRate(jack_nframes_t sample_rate) = 0;
  70. virtual int Process() = 0;
  71. virtual void SetMaster(bool onoff) = 0;
  72. virtual bool GetMaster() = 0;
  73. virtual void AddSlave(JackDriverInterface* slave) = 0;
  74. virtual void RemoveSlave(JackDriverInterface* slave) = 0;
  75. virtual std::list<JackDriverInterface*> GetSlaves() = 0;
  76. // For "master" driver
  77. virtual int ProcessReadSlaves() = 0;
  78. virtual int ProcessWriteSlaves() = 0;
  79. // For "slave" driver
  80. virtual int ProcessRead() = 0;
  81. virtual int ProcessWrite() = 0;
  82. virtual int ProcessReadSync() = 0;
  83. virtual int ProcessWriteSync() = 0;
  84. virtual int ProcessReadAsync() = 0;
  85. virtual int ProcessWriteAsync() = 0;
  86. virtual bool IsRealTime() const = 0;
  87. virtual bool IsRunning() const = 0;
  88. };
  89. /*!
  90. \brief The base interface for drivers clients.
  91. */
  92. class SERVER_EXPORT JackDriverClientInterface : public JackDriverInterface, public JackClientInterface
  93. {};
  94. /*!
  95. \brief The base class for drivers.
  96. */
  97. #define CaptureDriverFlags static_cast<JackPortFlags>(JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal)
  98. #define PlaybackDriverFlags static_cast<JackPortFlags>(JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal)
  99. #define MonitorDriverFlags static_cast<JackPortFlags>(JackPortIsOutput)
  100. typedef std::list<std::pair<std::string, std::pair<std::string, std::string> > > driver_connections_list_t; // [type : (src, dst)]
  101. class SERVER_EXPORT JackDriver : public JackDriverClientInterface
  102. {
  103. protected:
  104. char fCaptureDriverName[JACK_CLIENT_NAME_SIZE + 1];
  105. char fPlaybackDriverName[JACK_CLIENT_NAME_SIZE + 1];
  106. char fAliasName[JACK_CLIENT_NAME_SIZE + 1];
  107. jack_nframes_t fCaptureLatency;
  108. jack_nframes_t fPlaybackLatency;
  109. int fCaptureChannels;
  110. int fPlaybackChannels;
  111. jack_time_t fBeginDateUst;
  112. jack_time_t fEndDateUst;
  113. float fDelayedUsecs;
  114. // Pointers to engine state
  115. JackLockedEngine* fEngine;
  116. JackGraphManager* fGraphManager;
  117. JackSynchro* fSynchroTable;
  118. JackEngineControl* fEngineControl;
  119. JackClientControl fClientControl;
  120. std::list<JackDriverInterface*> fSlaveList;
  121. bool fIsMaster;
  122. bool fIsRunning;
  123. bool fWithMonitorPorts;
  124. // Static tables since the actual number of ports may be changed by the real driver
  125. // thus dynamic allocation is more difficult to handle
  126. jack_port_id_t fCapturePortList[DRIVER_PORT_NUM];
  127. jack_port_id_t fPlaybackPortList[DRIVER_PORT_NUM];
  128. jack_port_id_t fMonitorPortList[DRIVER_PORT_NUM];
  129. driver_connections_list_t fConnections; // Connections list
  130. void CycleIncTime();
  131. void CycleTakeBeginTime();
  132. void CycleTakeEndTime();
  133. void SetupDriverSync(int ref, bool freewheel);
  134. void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs); // XRun notification sent by the driver
  135. void NotifyBufferSize(jack_nframes_t buffer_size); // BufferSize notification sent by the driver
  136. void NotifySampleRate(jack_nframes_t sample_rate); // SampleRate notification sent by the driver
  137. void NotifyFailure(int code, const char* reason); // Failure notification sent by the driver
  138. virtual void SaveConnections(int alias);
  139. virtual void LoadConnections(int alias, bool full_name = true);
  140. std::string MatchPortName(const char* name, const char** ports, int alias, const std::string& type);
  141. virtual int StartSlaves();
  142. virtual int StopSlaves();
  143. virtual int ResumeRefNum();
  144. virtual int SuspendRefNum();
  145. public:
  146. JackDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
  147. JackDriver();
  148. virtual ~JackDriver();
  149. void SetMaster(bool onoff);
  150. bool GetMaster();
  151. void AddSlave(JackDriverInterface* slave);
  152. void RemoveSlave(JackDriverInterface* slave);
  153. std::list<JackDriverInterface*> GetSlaves()
  154. {
  155. return fSlaveList;
  156. }
  157. virtual int Open();
  158. virtual int Open(bool capturing,
  159. bool playing,
  160. int inchannels,
  161. int outchannels,
  162. bool monitor,
  163. const char* capture_driver_name,
  164. const char* playback_driver_name,
  165. jack_nframes_t capture_latency,
  166. jack_nframes_t playback_latency);
  167. virtual int Open(jack_nframes_t buffer_size,
  168. jack_nframes_t samplerate,
  169. bool capturing,
  170. bool playing,
  171. int inchannels,
  172. int outchannels,
  173. bool monitor,
  174. const char* capture_driver_name,
  175. const char* playback_driver_name,
  176. jack_nframes_t capture_latency,
  177. jack_nframes_t playback_latency);
  178. virtual int Close();
  179. virtual int Process();
  180. virtual int Attach();
  181. virtual int Detach();
  182. virtual int Read();
  183. virtual int Write();
  184. virtual int Start();
  185. virtual int Stop();
  186. // For "master" driver
  187. int ProcessReadSlaves();
  188. int ProcessWriteSlaves();
  189. // For "slave" driver
  190. int ProcessRead();
  191. int ProcessWrite();
  192. int ProcessReadSync();
  193. int ProcessWriteSync();
  194. int ProcessReadAsync();
  195. int ProcessWriteAsync();
  196. virtual bool IsFixedBufferSize();
  197. virtual int SetBufferSize(jack_nframes_t buffer_size);
  198. virtual int SetSampleRate(jack_nframes_t sample_rate);
  199. virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
  200. virtual JackClientControl* GetClientControl() const;
  201. virtual bool IsRealTime() const;
  202. virtual bool IsRunning() const { return fIsRunning; }
  203. virtual bool Initialize(); // To be called by the wrapping thread Init method when the driver is a "blocking" one
  204. };
  205. } // end of namespace
  206. #endif