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.

178 lines
4.9KB

  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. In jack1 implementation, transport code (jack_transport_cycle_end) was not called if the graph could not be locked (see jack_run_one_cycle).
  40. Here transport cycle (CycleBegin, CycleEnd) has to run in the RT thread concurrently with code executed from the "command" thread.
  41. Each client maintains a state in it's shared memory area defined by:
  42. - it's current transport state
  43. - a boolean that is "true" when slow-sync cb has to be called
  44. - a boolean that is "true" when timebase cb is called with new_pos on
  45. Several operations set the "slow-sync cb" flag to true:
  46. - setting a new cb (client)
  47. - activate (client)
  48. - transport start (server)
  49. - new pos (server)
  50. Slow-sync cb calls stops when:
  51. - the cb return true (client)
  52. - desactivate (client)
  53. - transport stop (server)
  54. Several operations set the "timebase cb" flag to true:
  55. - setting a new cb (client)
  56. - activate (client)
  57. - transport start (server) ??
  58. - new pos (server)
  59. Timebase cb "new_pos" argument calls stops when:
  60. - after one cb call with "new_pos" argument true (client)
  61. - desactivate (client)
  62. - release (client)
  63. - transport stop (server)
  64. */
  65. class JackTransportEngine : public JackAtomicArrayState<jack_position_t>
  66. {
  67. private:
  68. jack_transport_state_t fTransportState;
  69. volatile transport_command_t fTransportCmd;
  70. transport_command_t fPreviousCmd; /* previous transport_cmd */
  71. jack_time_t fSyncTimeout;
  72. int fSyncTimeLeft;
  73. int fTimeBaseMaster;
  74. bool fPendingPos;
  75. SInt32 fWriteCounter;
  76. bool CheckAllRolling(JackClientInterface** table);
  77. void MakeAllStartingLocating(JackClientInterface** table);
  78. void MakeAllStopping(JackClientInterface** table);
  79. void MakeAllLocating(JackClientInterface** table);
  80. void SyncTimeout(jack_nframes_t frame_rate, jack_nframes_t buffer_size);
  81. public:
  82. JackTransportEngine();
  83. ~JackTransportEngine()
  84. {}
  85. void SetCommand(transport_command_t state)
  86. {
  87. fTransportCmd = state;
  88. }
  89. jack_transport_state_t GetState() const
  90. {
  91. return fTransportState;
  92. }
  93. int GetTimebaseMaster() const
  94. {
  95. return fTimeBaseMaster;
  96. }
  97. /*
  98. \brief
  99. */
  100. int ResetTimebase(int refnum);
  101. /*
  102. \brief
  103. */
  104. int SetTimebase(int refnum, bool conditionnal);
  105. /*
  106. \brief
  107. */
  108. void CycleBegin(jack_nframes_t frame_rate, jack_time_t time);
  109. /*
  110. \brief
  111. */
  112. void CycleEnd(JackClientInterface** table, jack_nframes_t frame_rate, jack_nframes_t buffer_size);
  113. /*
  114. \brief
  115. */
  116. void SetSyncTimeout(jack_time_t timeout)
  117. {
  118. fSyncTimeout = timeout;
  119. }
  120. void ReadCurrentPos(jack_position_t* pos);
  121. jack_unique_t GenerateUniqueID()
  122. {
  123. return (jack_unique_t)INC_ATOMIC(&fWriteCounter);
  124. }
  125. static void TransportCopyPosition(jack_position_t* from, jack_position_t* to);
  126. };
  127. } // end of namespace
  128. #endif