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.

133 lines
3.2KB

  1. /*
  2. Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
  3. Copyright (C) 2008 Grame & RTL 2008
  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 __JackOSSChannel__
  17. #define __JackOSSChannel__
  18. #include "JackMutex.h"
  19. #include "JackThread.h"
  20. #include "sosso/Correction.hpp"
  21. #include "sosso/DoubleBuffer.hpp"
  22. #include "sosso/FrameClock.hpp"
  23. #include "sosso/ReadChannel.hpp"
  24. #include "sosso/WriteChannel.hpp"
  25. namespace Jack
  26. {
  27. typedef jack_default_audio_sample_t jack_sample_t;
  28. /*!
  29. \brief The OSS driver.
  30. */
  31. class JackOSSChannel : public JackRunnableInterface
  32. {
  33. private:
  34. JackThread fAssistThread;
  35. JackProcessSync fMutex;
  36. sosso::FrameClock fFrameClock;
  37. sosso::DoubleBuffer<sosso::ReadChannel> fReadChannel;
  38. sosso::DoubleBuffer<sosso::WriteChannel> fWriteChannel;
  39. sosso::Correction fCorrection;
  40. std::int64_t fFrameStamp = 0;
  41. public:
  42. JackOSSChannel() : fAssistThread(this)
  43. {}
  44. virtual ~JackOSSChannel()
  45. {}
  46. sosso::DoubleBuffer<sosso::ReadChannel> &Capture()
  47. {
  48. return fReadChannel;
  49. }
  50. sosso::DoubleBuffer<sosso::WriteChannel> &Playback()
  51. {
  52. return fWriteChannel;
  53. }
  54. sosso::FrameClock &FrameClock()
  55. {
  56. return fFrameClock;
  57. }
  58. bool Lock()
  59. {
  60. return fMutex.Lock();
  61. }
  62. bool Unlock()
  63. {
  64. return fMutex.Unlock();
  65. }
  66. void SignalWork()
  67. {
  68. fMutex.SignalAll();
  69. }
  70. bool InitialSetup(unsigned sample_rate);
  71. bool OpenCapture(const char* device, bool exclusive, int bits, int &channels);
  72. bool OpenPlayback(const char* device, bool exclusive, int bits, int &channels);
  73. bool Read(jack_sample_t** sample_buffers, jack_nframes_t length, std::int64_t end);
  74. bool Write(jack_sample_t** sample_buffers, jack_nframes_t length, std::int64_t end);
  75. bool StartChannels(unsigned buffer_frames);
  76. bool StopChannels();
  77. bool StartAssistThread(bool realtime, int priority);
  78. bool StopAssistThread();
  79. bool CheckTimeAndRun();
  80. bool Sleep() const;
  81. bool CaptureFinished() const;
  82. bool PlaybackFinished() const;
  83. std::int64_t PlaybackCorrection();
  84. virtual bool Init();
  85. virtual bool Execute();
  86. std::int64_t XRunGap() const;
  87. void ResetBuffers(std::int64_t offset);
  88. std::int64_t FrameStamp() const
  89. {
  90. return fFrameStamp;
  91. }
  92. std::int64_t NextWakeup() const;
  93. };
  94. } // end of namespace
  95. #endif