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.

219 lines
7.1KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. $Id$
  15. */
  16. #ifndef __jack_driver_h__
  17. #define __jack_driver_h__
  18. #include <pthread.h>
  19. #include <jack/types.h>
  20. #include <jack/port.h>
  21. typedef float gain_t;
  22. typedef long channel_t;
  23. typedef enum {
  24. Lock = 0x1,
  25. NoLock = 0x2,
  26. Sync = 0x4,
  27. NoSync = 0x8
  28. } ClockSyncStatus;
  29. typedef void (*ClockSyncListenerFunction)(channel_t,ClockSyncStatus,void*);
  30. typedef struct {
  31. unsigned long id;
  32. ClockSyncListenerFunction function;
  33. void *arg;
  34. } ClockSyncListener;
  35. struct _jack_engine;
  36. struct _jack_driver;
  37. typedef int (*JackDriverAttachFunction)(struct _jack_driver *, struct _jack_engine *);
  38. typedef int (*JackDriverDetachFunction)(struct _jack_driver *, struct _jack_engine *);
  39. typedef int (*JackDriverReadFunction)(struct _jack_driver *, jack_nframes_t nframes);
  40. typedef int (*JackDriverWriteFunction)(struct _jack_driver *, jack_nframes_t nframes);
  41. typedef int (*JackDriverNullCycleFunction)(struct _jack_driver *, jack_nframes_t nframes);
  42. typedef int (*JackDriverStopFunction)(struct _jack_driver *);
  43. typedef int (*JackDriverStartFunction)(struct _jack_driver *);
  44. typedef jack_nframes_t (*JackDriverWaitFunction)(struct _jack_driver *, int fd, int *status, float *delayed_usecs);
  45. /*
  46. Call sequence summary:
  47. 1) engine loads driver via runtime dynamic linking
  48. - calls jack_driver_load
  49. - we lookup "driver_initialize" and execute it
  50. 2) engine attaches to driver
  51. 3) engine starts driver
  52. 4) while (1) {
  53. engine->wait ();
  54. engine->audio_cycle ();
  55. }
  56. 5) engine stops driver
  57. 6) engine detaches from driver
  58. 7) engine calls driver `finish' routine, if any
  59. note that stop/start may be called multiple times in the event of an
  60. error return from the `wait' function.
  61. */
  62. #ifdef _ANNOTATED_DRIVER_DECLARATION_
  63. #define JACK_DRIVER_DECL
  64. /* the driver should set this to be the interval it expects to elapse
  65. between returning from the `wait' function. if set to zero, it
  66. implies that the driver does not expect regular periodic wakeups.
  67. */
  68. jack_time_t period_usecs;
  69. /* the driver should set this within its "wait" function to indicate
  70. the UST of the most recent determination that the engine cycle
  71. should run. it should not be set if the "extra_fd" argument of
  72. the wait function is set to a non-zero value.
  73. */
  74. jack_time_t last_wait_ust;
  75. /* this is not used by the driver. it should not be written to or
  76. modified in any way
  77. */
  78. void *handle;
  79. /* this should perform any cleanup associated with the driver. it will
  80. be called when jack server process decides to get rid of the
  81. driver. in some systems, it may not be called at all, so the driver
  82. should never rely on a call to this. it can set it to NULL if
  83. it has nothing do do.
  84. */
  85. void (*finish)(struct _jack_driver *);\
  86. /* the JACK engine will call this when it wishes to attach itself to
  87. the driver. the engine will pass a pointer to itself, which the driver
  88. may use in anyway it wishes to. the driver may assume that this
  89. is the same engine object that will make `wait' calls until a
  90. `detach' call is made.
  91. */
  92. JackDriverAttachFunction attach; \
  93. /* the JACK engine will call this when it is finished using a driver.
  94. */
  95. JackDriverDetachFunction detach; \
  96. /* the JACK engine will call this when it wants to wait until the
  97. driver decides that its time to process some data. the driver returns
  98. a count of the number of audioframes that can be processed.
  99. it should set the variable pointed to by `status' as follows:
  100. zero: the wait completed normally, processing may begin
  101. negative: the wait failed, and recovery is not possible
  102. positive: the wait failed, and the driver stopped itself.
  103. a call to `start' will return the driver to
  104. a correct and known state.
  105. the driver should also fill out the `delayed_usecs' variable to
  106. indicate any delay in its expected periodic execution. for example,
  107. if it discovers that its return from poll(2) is later than it
  108. expects it to be, it would place an estimate of the delay
  109. in this variable. the engine will use this to decide if it
  110. plans to continue execution.
  111. */
  112. JackDriverWaitFunction wait;
  113. /* the JACK engine will call this to ask the driver to move
  114. data from its inputs to its output port buffers. it should
  115. return 0 to indicate successful completion, negative otherwise.
  116. this function will always be called after the wait function (above).
  117. */
  118. JackDriverReadFunction read;
  119. /* the JACK engine will call this to ask the driver to move
  120. data from its input port buffers to its outputs. it should
  121. return 0 to indicate successful completion, negative otherwise.
  122. this function will always be called after the read function (above).
  123. */
  124. JackDriverWriteFunction write;
  125. /* the JACK engine will call this after the wait function (above) has
  126. been called, but for some reason the engine is unable to execute
  127. a full "cycle". the driver should do whatever is necessary to
  128. keep itself running correctly, but cannot reference ports
  129. or other JACK data structures in any way.
  130. */
  131. JackDriverNullCycleFunction null_cycle;
  132. /* the engine will call this when it plans to stop calling the `wait'
  133. function for some period of time. the driver should take
  134. appropriate steps to handle this (possibly no steps at all)
  135. */
  136. JackDriverStopFunction stop; \
  137. /* the engine will call this to let the driver know that it plans
  138. to start calling the `wait' function on a regular basis. the driver
  139. should take any appropriate steps to handle this (possibly no steps
  140. at all)
  141. */
  142. JackDriverStartFunction start;
  143. #else
  144. #define JACK_DRIVER_DECL \
  145. jack_time_t period_usecs; \
  146. jack_time_t last_wait_ust; \
  147. void *handle; \
  148. void (*finish)(struct _jack_driver *);\
  149. JackDriverAttachFunction attach; \
  150. JackDriverDetachFunction detach; \
  151. JackDriverWaitFunction wait; \
  152. JackDriverReadFunction read; \
  153. JackDriverWriteFunction write; \
  154. JackDriverNullCycleFunction null_cycle; \
  155. JackDriverStopFunction stop; \
  156. JackDriverStartFunction start;
  157. #endif /* _ANNOTATED_DRIVER_DECLARATION_ */
  158. typedef struct _jack_driver {
  159. JACK_DRIVER_DECL
  160. } jack_driver_t;
  161. void jack_driver_init (jack_driver_t *);
  162. void jack_driver_release (jack_driver_t *);
  163. jack_driver_t *jack_driver_load (int argc, char **argv);
  164. void jack_driver_unload (jack_driver_t *);
  165. #endif /* __jack_driver_h__ */