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.

246 lines
6.0KB

  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 "JackPlatformSynchro.h"
  22. #include <list>
  23. namespace Jack
  24. {
  25. class JackEngineInterface;
  26. class JackGraphManager;
  27. struct JackEngineControl;
  28. struct JackClientControl;
  29. /*!
  30. \brief The base interface for drivers.
  31. */
  32. class EXPORT JackDriverInterface
  33. {
  34. public:
  35. JackDriverInterface()
  36. {}
  37. virtual ~JackDriverInterface()
  38. {}
  39. virtual int Open() = 0;
  40. virtual int Open(jack_nframes_t nframes,
  41. jack_nframes_t samplerate,
  42. bool capturing,
  43. bool playing,
  44. int inchannels,
  45. int outchannels,
  46. bool monitor,
  47. const char* capture_driver_name,
  48. const char* playback_driver_name,
  49. jack_nframes_t capture_latency,
  50. jack_nframes_t playback_latency) = 0;
  51. virtual int Attach() = 0;
  52. virtual int Detach() = 0;
  53. virtual int Read() = 0;
  54. virtual int Write() = 0;
  55. virtual int Start() = 0;
  56. virtual int Stop() = 0;
  57. virtual int SetBufferSize(jack_nframes_t buffer_size) = 0;
  58. virtual int SetSampleRate(jack_nframes_t sample_rate) = 0;
  59. virtual int Process() = 0;
  60. virtual void SetMaster(bool onoff) = 0;
  61. virtual bool GetMaster() = 0;
  62. virtual void AddSlave(JackDriverInterface* slave) = 0;
  63. virtual void RemoveSlave(JackDriverInterface* slave) = 0;
  64. virtual int ProcessSlaves() = 0;
  65. virtual bool IsRealTime() = 0;
  66. };
  67. /*
  68. \brief The base interface for blocking drivers.
  69. */
  70. class EXPORT JackBlockingInterface
  71. {
  72. public:
  73. JackBlockingInterface()
  74. {}
  75. virtual ~JackBlockingInterface()
  76. {}
  77. virtual bool Init() = 0; /* To be called by the wrapping thread Init method when the driver is a "blocking" one */
  78. };
  79. /*!
  80. \brief The base interface for drivers clients.
  81. */
  82. class EXPORT JackDriverClientInterface : public JackDriverInterface, public JackClientInterface
  83. {};
  84. /*!
  85. \brief The base class for drivers clients.
  86. */
  87. class EXPORT JackDriverClient : public JackDriverClientInterface, public JackBlockingInterface
  88. {
  89. private:
  90. std::list<JackDriverInterface*> fSlaveList;
  91. protected:
  92. bool fIsMaster;
  93. public:
  94. virtual void SetMaster(bool onoff);
  95. virtual bool GetMaster();
  96. virtual void AddSlave(JackDriverInterface* slave);
  97. virtual void RemoveSlave(JackDriverInterface* slave);
  98. virtual int ProcessSlaves();
  99. };
  100. /*!
  101. \brief The base class for drivers.
  102. */
  103. class EXPORT JackDriver : public JackDriverClient
  104. {
  105. protected:
  106. char fCaptureDriverName[JACK_CLIENT_NAME_SIZE + 1];
  107. char fPlaybackDriverName[JACK_CLIENT_NAME_SIZE + 1];
  108. char fAliasName[JACK_CLIENT_NAME_SIZE + 1];
  109. jack_nframes_t fCaptureLatency;
  110. jack_nframes_t fPlaybackLatency;
  111. jack_time_t fLastWaitUst;
  112. float fDelayedUsecs;
  113. JackEngineInterface* fEngine;
  114. JackGraphManager* fGraphManager;
  115. JackSynchro* fSynchroTable;
  116. JackEngineControl* fEngineControl;
  117. JackClientControl* fClientControl;
  118. JackClientControl* GetClientControl() const;
  119. void CycleIncTime();
  120. void CycleTakeTime();
  121. public:
  122. JackDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro* table);
  123. JackDriver();
  124. virtual ~JackDriver();
  125. virtual int Open();
  126. virtual int Open(jack_nframes_t nframes,
  127. jack_nframes_t samplerate,
  128. bool capturing,
  129. bool playing,
  130. int inchannels,
  131. int outchannels,
  132. bool monitor,
  133. const char* capture_driver_name,
  134. const char* playback_driver_name,
  135. jack_nframes_t capture_latency,
  136. jack_nframes_t playback_latency);
  137. virtual int Close();
  138. virtual int Process()
  139. {
  140. return 0;
  141. }
  142. virtual int Attach()
  143. {
  144. return 0;
  145. }
  146. virtual int Detach()
  147. {
  148. return 0;
  149. }
  150. virtual int Read()
  151. {
  152. return 0;
  153. }
  154. virtual int Write()
  155. {
  156. return 0;
  157. }
  158. virtual int Start()
  159. {
  160. return 0;
  161. }
  162. virtual int Stop()
  163. {
  164. return 0;
  165. }
  166. virtual int SetBufferSize(jack_nframes_t buffer_size)
  167. {
  168. return 0;
  169. }
  170. virtual int SetSampleRate(jack_nframes_t sample_rate)
  171. {
  172. return 0;
  173. }
  174. void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs); // XRun notification sent by the driver
  175. virtual bool IsRealTime();
  176. int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2);
  177. void SetupDriverSync(int ref, bool freewheel);
  178. virtual bool Init()
  179. {
  180. return true;
  181. }
  182. };
  183. } // end of namespace
  184. #endif