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.

207 lines
6.7KB

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