jack1 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.

250 lines
9.2KB

  1. /*
  2. * This file documents the JACK transport design. It is part of the
  3. * JACK reference manual, built using doxygen.
  4. */
  5. /**
  6. @page transport-design JACK Transport Design
  7. The @ref index provides simple transport interfaces for starting,
  8. stopping and repositioning a set of clients. This document describes
  9. the overall design of these interfaces, their detailed specifications
  10. are in <jack/transport.h>
  11. - @ref requirements
  12. - @ref overview
  13. - @ref timebase
  14. - @ref transportcontrol
  15. - @ref transportclients
  16. - @ref compatibility
  17. - @ref issues
  18. @section requirements Requirements
  19. - We need sample-level accuracy for transport control. This implies
  20. that the transport client logic has to be part of the realtime
  21. process chain.
  22. - We don't want to add another context switch. So, the transport
  23. client logic has to run in the context of the client's process
  24. thread. To avoid making an extra pass through the process graph, no
  25. transport changes take effect until the following process cycle.
  26. That way, the transport info is stable throughout each cycle.
  27. - We want to allow multiple clients to change the transport state.
  28. This is mostly a usability issue. Any client can start or stop
  29. playback, or seek to a new location. The user need not switch
  30. windows to accomplish these tasks.
  31. - We want a way for clients with heavyweight state to sync up when
  32. the user presses "play", before the transport starts rolling.
  33. - We want to provide for ongoing binary compatibility as the
  34. transport design evolves.
  35. @section overview Overview
  36. The former transport master role has been divided into two layers:
  37. - @ref timebase - counting beats, frames, etc. on every cycle.
  38. - @ref transportcontrol - start, stop and reposition the playback.
  39. Existing transport clients continue to work in compatibility mode.
  40. But, old-style timebase masters will no longer control the transport.
  41. @section timebase Timebase Master
  42. The timebase master continuously updates extended position
  43. information, counting beats, timecode, etc. Without this extended
  44. information, there is no need for this function. There is at most one
  45. master active at a time. If no client is registered as timebase
  46. master, frame numbers will be the only position information available.
  47. The timebase master registers a callback that updates position
  48. information while the transport is rolling. Its output affects the
  49. following process cycle. This function is called immediately after
  50. the process callback in the same thread whenever the transport is
  51. rolling, or when any client has set a new position in the previous
  52. cycle. The first cycle after jack_set_timebase_callback() is also
  53. treated as a new position, or the first cycle after jack_activate() if
  54. the client had been inactive.
  55. @code
  56. typedef int (*JackTimebaseCallback)(jack_transport_state_t state,
  57. jack_nframes_t nframes,
  58. jack_position_t *pos,
  59. int new_pos,
  60. void *arg);
  61. @endcode
  62. When a new client takes over, the former timebase callback is no
  63. longer called. Taking over the timebase may be done conditionally, in
  64. which case the takeover fails when there is a master already. The
  65. existing master can release it voluntarily, if desired.
  66. @code
  67. int jack_set_timebase_callback (jack_client_t *client,
  68. int conditional,
  69. JackTimebaseCallback timebase_callback,
  70. void *arg);
  71. int jack_release_timebase(jack_client_t *client);
  72. @endcode
  73. If the timebase master releases the timebase or exits the JACK graph
  74. for any reason, the JACK engine takes over at the start of the next
  75. process cycle. The transport state does not change. If rolling, it
  76. continues to play, with frame numbers as the only available position
  77. information.
  78. @section transportcontrol Transport Control
  79. The JACK engine itself manages stopping and starting of the transport.
  80. Any client can make transport control requests at any time. These
  81. requests take effect no sooner than the next process cycle, sometimes
  82. later. The transport state is always valid, initially it is
  83. ::JackTransportStopped.
  84. @code
  85. void jack_transport_start (jack_client_t *client);
  86. void jack_transport_stop (jack_client_t *client);
  87. @endcode
  88. @subsection slowsyncclients Slow-sync clients
  89. The engine handles polling of slow-sync clients. When someone calls
  90. jack_transport_start(), the engine resets the poll bits and changes to
  91. a new state, ::JackTransportStarting. The @a sync_callback function
  92. for each slow-sync client will be invoked in the JACK process thread
  93. while the transport is starting. If it has not already done so, the
  94. client needs to initiate a seek to reach the starting position. The
  95. @a sync_callback returns false until the seek completes and the client
  96. is ready to play. When all slow-sync clients are ready, the state
  97. changes to ::JackTransportRolling.
  98. @code
  99. typedef int (*JackSyncCallback)(jack_transport_state_t state,
  100. jack_position_t *pos, void *arg);
  101. @endcode
  102. This callback is a realtime function that runs in the JACK process
  103. thread.
  104. @code
  105. int jack_set_sync_callback (jack_client_t *client,
  106. JackSyncCallback sync_callback, void *arg);
  107. @endcode
  108. Clients that don't declare a @a sync_callback are assumed to be ready
  109. immediately, any time the transport wants to start. If a client no
  110. longer requires slow-sync processing, it can set its @a sync_callback
  111. to NULL.
  112. @code
  113. int jack_set_sync_timeout (jack_client_t *client,
  114. jack_time_t usecs);
  115. @endcode
  116. There must be a @a timeout to prevent unresponsive slow-sync clients
  117. from completely halting the transport mechanism. Two seconds is the
  118. default. When this @a timeout expires, the transport will start
  119. rolling, even if some slow-sync clients are still unready. The @a
  120. sync_callback for these clients continues being invoked, giving them
  121. an opportunity to catch up.
  122. @subsection repositioning Repositioning
  123. @code
  124. int jack_transport_reposition (jack_client_t *client,
  125. jack_position_t *pos);
  126. int jack_transport_locate (jack_client_t *client,
  127. jack_nframes_t frame);
  128. @endcode
  129. These request a new transport position. They can be called at any
  130. time by any client. Even the timebase master must use them. If the
  131. request is valid, it goes into effect in two process cycles. If there
  132. are slow-sync clients and the transport is already rolling, it will
  133. enter the ::JackTransportStarting state and begin invoking their @a
  134. sync_callbacks until ready.
  135. @subsection transportstatetransitiondiagram Transport State Transition Diagram
  136. @image html fsm.png "Transport State Transition Diagram"
  137. @image latex fsm.eps "Transport State Transition Diagram"
  138. @section transportclients Transport Clients
  139. Transport clients were formerly known as "transport slaves". We want
  140. to make it easy for almost every JACK client to be a transport client.
  141. @code
  142. jack_transport_state_t jack_transport_query (jack_client_t *client,
  143. jack_position_t *pos);
  144. @endcode
  145. This function can be called from any thread. If called from the
  146. process thread, @a pos corresponds to the first frame of the current
  147. cycle and the state returned is valid for the entire cycle.
  148. @section compatibility Compatibility
  149. During the transition period we will support the old-style interfaces
  150. in compatibility mode as deprecated interfaces. This compatibility is
  151. not 100%, there are limitations.
  152. The main reasons for doing this are:
  153. - facilitate testing with clients that already have transport
  154. support
  155. - provide a clean migration path, so application developers are
  156. not discouraged from supporting the transport interface
  157. These deprecated interfaces continue to work:
  158. @code
  159. typedef struct jack_transport_info_t;
  160. void jack_get_transport_info (jack_client_t *client,
  161. jack_transport_info_t *tinfo);
  162. @endcode
  163. Unfortunately, the old-style timebase master interface cannot coexist
  164. cleanly with such new features as jack_transport_locate() and
  165. slow-sync clients. So, these interfaces are only present as stubs:
  166. @code
  167. void jack_set_transport_info (jack_client_t *client,
  168. jack_transport_info_t *tinfo);
  169. int jack_engine_takeover_timebase (jack_client_t *);
  170. @endcode
  171. For compatibility with future changes, it would be good to avoid
  172. structures entirely. Nevertheless, the jack_position_t structure
  173. provides a convenient way to collect timebase information in several
  174. formats that clearly all refer to a single moment. To minimize future
  175. binary compatibility problems, this structure has some padding at the
  176. end, making it possible to extend it without necessarily breaking
  177. compatibility. New fields can be allocated from the padding area,
  178. with access controlled by newly defined valid bits, all of which are
  179. currently forced to zero. That allows the structure size and offsets
  180. to remain constant.
  181. @section issues Issues Not Addressed
  182. This design currently does not address several issues. This means they
  183. will probably not be included in JACK release 1.0.
  184. - variable speed
  185. - reverse play
  186. - looping
  187. */