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.

263 lines
8.3KB

  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(jack_nframes_t buffer_size,
  42. jack_nframes_t samplerate,
  43. bool capturing,
  44. bool playing,
  45. int inchannels,
  46. int outchannels,
  47. bool monitor,
  48. const char* capture_driver_name,
  49. const char* playback_driver_name,
  50. jack_nframes_t capture_latency,
  51. jack_nframes_t playback_latency) = 0;
  52. virtual int Attach() = 0;
  53. virtual int Detach() = 0;
  54. virtual int Read() = 0;
  55. virtual int Write() = 0;
  56. virtual int Start() = 0;
  57. virtual int Stop() = 0;
  58. virtual bool IsFixedBufferSize() = 0;
  59. virtual int SetBufferSize(jack_nframes_t buffer_size) = 0;
  60. virtual int SetSampleRate(jack_nframes_t sample_rate) = 0;
  61. virtual int Process() = 0;
  62. virtual void SetMaster(bool onoff) = 0;
  63. virtual bool GetMaster() = 0;
  64. virtual void AddSlave(JackDriverInterface* slave) = 0;
  65. virtual void RemoveSlave(JackDriverInterface* slave) = 0;
  66. virtual std::list<JackDriverInterface*> GetSlaves() = 0;
  67. // For "master" driver
  68. virtual int ProcessReadSlaves() = 0;
  69. virtual int ProcessWriteSlaves() = 0;
  70. // For "slave" driver
  71. virtual int ProcessRead() = 0;
  72. virtual int ProcessWrite() = 0;
  73. // For "slave" driver in "synchronous" mode
  74. virtual int ProcessReadSync() = 0;
  75. virtual int ProcessWriteSync() = 0;
  76. // For "slave" driver in "asynchronous" mode
  77. virtual int ProcessReadAsync() = 0;
  78. virtual int ProcessWriteAsync() = 0;
  79. virtual bool IsRealTime() const = 0;
  80. virtual bool IsRunning() const = 0;
  81. };
  82. /*!
  83. \brief The base interface for drivers clients.
  84. */
  85. class SERVER_EXPORT JackDriverClientInterface : public JackDriverInterface, public JackClientInterface
  86. {};
  87. /*!
  88. \brief The base class for drivers.
  89. */
  90. #define CaptureDriverFlags static_cast<JackPortFlags>(JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal)
  91. #define PlaybackDriverFlags static_cast<JackPortFlags>(JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal)
  92. #define MonitorDriverFlags static_cast<JackPortFlags>(JackPortIsOutput)
  93. typedef std::list<std::pair<std::string, std::pair<std::string, std::string> > > driver_connections_list_t; // [type : (src, dst)]
  94. class SERVER_EXPORT JackDriver : public JackDriverClientInterface
  95. {
  96. protected:
  97. char fCaptureDriverName[JACK_CLIENT_NAME_SIZE+1];
  98. char fPlaybackDriverName[JACK_CLIENT_NAME_SIZE+1];
  99. char fAliasName[JACK_CLIENT_NAME_SIZE+1];
  100. jack_nframes_t fCaptureLatency;
  101. jack_nframes_t fPlaybackLatency;
  102. int fCaptureChannels;
  103. int fPlaybackChannels;
  104. jack_time_t fBeginDateUst;
  105. jack_time_t fEndDateUst;
  106. float fDelayedUsecs;
  107. // Pointers to engine state
  108. JackLockedEngine* fEngine;
  109. JackGraphManager* fGraphManager;
  110. JackSynchro* fSynchroTable;
  111. JackEngineControl* fEngineControl;
  112. JackClientControl fClientControl;
  113. std::list<JackDriverInterface*> fSlaveList;
  114. bool fIsMaster;
  115. bool fIsRunning;
  116. bool fWithMonitorPorts;
  117. // Static tables since the actual number of ports may be changed by the real driver
  118. // thus dynamic allocation is more difficult to handle
  119. jack_port_id_t fCapturePortList[DRIVER_PORT_NUM];
  120. jack_port_id_t fPlaybackPortList[DRIVER_PORT_NUM];
  121. jack_port_id_t fMonitorPortList[DRIVER_PORT_NUM];
  122. driver_connections_list_t fConnections; // Connections list
  123. void CycleIncTime();
  124. void CycleTakeBeginTime();
  125. void CycleTakeEndTime();
  126. void SetupDriverSync(int ref, bool freewheel);
  127. void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs); // XRun notification sent by the driver
  128. void NotifyBufferSize(jack_nframes_t buffer_size); // BufferSize notification sent by the driver
  129. void NotifySampleRate(jack_nframes_t sample_rate); // SampleRate notification sent by the driver
  130. void NotifyFailure(int code, const char* reason); // Failure notification sent by the driver
  131. virtual void SaveConnections(int alias);
  132. virtual void LoadConnections(int alias, bool full_name = true);
  133. std::string MatchPortName(const char* name, const char** ports, int alias, const std::string& type);
  134. virtual int StartSlaves();
  135. virtual int StopSlaves();
  136. virtual int ResumeRefNum();
  137. virtual int SuspendRefNum();
  138. public:
  139. JackDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
  140. virtual ~JackDriver();
  141. void SetMaster(bool onoff);
  142. bool GetMaster();
  143. void AddSlave(JackDriverInterface* slave);
  144. void RemoveSlave(JackDriverInterface* slave);
  145. std::list<JackDriverInterface*> GetSlaves()
  146. {
  147. return fSlaveList;
  148. }
  149. virtual int Open();
  150. virtual int Open(jack_nframes_t buffer_size,
  151. jack_nframes_t samplerate,
  152. bool capturing,
  153. bool playing,
  154. int inchannels,
  155. int outchannels,
  156. bool monitor,
  157. const char* capture_driver_name,
  158. const char* playback_driver_name,
  159. jack_nframes_t capture_latency,
  160. jack_nframes_t playback_latency);
  161. virtual int Close();
  162. virtual int Process();
  163. virtual int Attach();
  164. virtual int Detach();
  165. virtual int Read();
  166. virtual int Write();
  167. virtual int Start();
  168. virtual int Stop();
  169. // For "master" driver
  170. int ProcessReadSlaves();
  171. int ProcessWriteSlaves();
  172. // For "slave" driver with typically decompose a given cycle in separated Read and Write parts.
  173. virtual int ProcessRead();
  174. virtual int ProcessWrite();
  175. // For "slave" driver in "synchronous" mode
  176. virtual int ProcessReadSync();
  177. virtual int ProcessWriteSync();
  178. // For "slave" driver in "asynchronous" mode
  179. virtual int ProcessReadAsync();
  180. virtual int ProcessWriteAsync();
  181. virtual bool IsFixedBufferSize();
  182. virtual int SetBufferSize(jack_nframes_t buffer_size);
  183. virtual int SetSampleRate(jack_nframes_t sample_rate);
  184. virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
  185. virtual JackClientControl* GetClientControl() const;
  186. virtual bool IsRealTime() const;
  187. virtual bool IsRunning() const { return fIsRunning; }
  188. virtual bool Initialize(); // To be called by the wrapping thread Init method when the driver is a "blocking" one
  189. };
  190. } // end of namespace
  191. #endif