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.

138 lines
3.5KB

  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 __JackTransportEngine__
  17. #define __JackTransportEngine__
  18. #include "transport_types.h"
  19. #include "JackClientInterface.h"
  20. #include "JackConstants.h"
  21. #include "JackAtomicArrayState.h"
  22. namespace Jack
  23. {
  24. typedef enum {
  25. TransportCommandNone = 0,
  26. TransportCommandStart = 1,
  27. TransportCommandStop = 2,
  28. } transport_command_t;
  29. /*!
  30. \brief The client transport structure.
  31. We have:
  32. - a "current" position
  33. - a "pending" position prepared by the server at each cycle
  34. - a "request" position wanted by a client
  35. At the beginning of a cycle the server needs to select a new current position. When a request and a pending position are available,
  36. the resquest takes precedence on the pending one. The server atomically switches to the new position.
  37. The current position can be read by clients.
  38. We use a JackAtomicArrayState pattern that allows to manage several "next" states independantly.
  39. */
  40. class JackTransportEngine : public JackAtomicArrayState<jack_position_t>
  41. {
  42. private:
  43. jack_transport_state_t fTransportState;
  44. volatile transport_command_t fTransportCmd;
  45. transport_command_t fPreviousCmd; /* previous transport_cmd */
  46. jack_time_t fSyncTimeout;
  47. int fSyncTimeLeft;
  48. int fTimeBaseMaster;
  49. bool fPendingPos;
  50. SInt32 fWriteCounter;
  51. bool CheckOneSynching(JackClientInterface** table);
  52. bool CheckAllRolling(JackClientInterface** table);
  53. void MakeAllStarting(JackClientInterface** table);
  54. void SyncTimeout(jack_nframes_t frame_rate, jack_nframes_t buffer_size);
  55. public:
  56. JackTransportEngine();
  57. ~JackTransportEngine()
  58. {}
  59. void SetCommand(transport_command_t state)
  60. {
  61. fTransportCmd = state;
  62. }
  63. jack_transport_state_t GetState() const
  64. {
  65. return fTransportState;
  66. }
  67. int GetTimebaseMaster() const
  68. {
  69. return fTimeBaseMaster;
  70. }
  71. /*
  72. \brief
  73. */
  74. int ResetTimebase(int refnum);
  75. /*
  76. \brief
  77. */
  78. int SetTimebase(int refnum, bool conditionnal);
  79. /*
  80. \brief
  81. */
  82. void CycleBegin(jack_nframes_t frame_rate, jack_time_t time);
  83. /*
  84. \brief
  85. */
  86. void CycleEnd(JackClientInterface** table, jack_nframes_t frame_rate, jack_nframes_t buffer_size);
  87. /*
  88. \brief
  89. */
  90. void SetSyncTimeout(jack_time_t timeout)
  91. {
  92. fSyncTimeout = timeout;
  93. }
  94. void ReadCurrentPos(jack_position_t* pos);
  95. jack_unique_t GenerateUniqueID()
  96. {
  97. return (jack_unique_t)INC_ATOMIC(&fWriteCounter);
  98. }
  99. static void TransportCopyPosition(jack_position_t* from, jack_position_t* to);
  100. };
  101. } // end of namespace
  102. #endif