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.

217 lines
7.3KB

  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 *,
  38. struct _jack_engine *);
  39. typedef int (*JackDriverDetachFunction)(struct _jack_driver *,
  40. struct _jack_engine *);
  41. typedef int (*JackDriverReadFunction)(struct _jack_driver *,
  42. jack_nframes_t nframes);
  43. typedef int (*JackDriverWriteFunction)(struct _jack_driver *,
  44. jack_nframes_t nframes);
  45. typedef int (*JackDriverNullCycleFunction)(struct _jack_driver *,
  46. jack_nframes_t nframes);
  47. typedef int (*JackDriverStopFunction)(struct _jack_driver *);
  48. typedef int (*JackDriverStartFunction)(struct _jack_driver *);
  49. typedef jack_nframes_t (*JackDriverWaitFunction)(struct _jack_driver *,
  50. int fd, int *status,
  51. float *delayed_usecs);
  52. /*
  53. Call sequence summary:
  54. 1) engine loads driver via runtime dynamic linking
  55. - calls jack_driver_load
  56. - we lookup "driver_initialize" and execute it
  57. 2) engine attaches to driver
  58. 3) engine starts driver
  59. 4) while (1) {
  60. engine->wait ();
  61. engine->audio_cycle ();
  62. }
  63. 5) engine stops driver
  64. 6) engine detaches from driver
  65. 7) engine calls driver `finish' routine
  66. Note that stop/start may be called multiple times in the event of an
  67. error return from the `wait' function.
  68. */
  69. typedef struct _jack_driver {
  70. /* The _jack_driver structure fields are included at the beginning of
  71. each driver-specific structure using the JACK_DRIVER_DECL macro,
  72. which is defined below. The comments that follow describe each
  73. common field.
  74. The driver should set this to be the interval it expects to elapse
  75. between returning from the `wait' function. if set to zero, it
  76. implies that the driver does not expect regular periodic wakeups.
  77. jack_time_t period_usecs;
  78. The driver should set this within its "wait" function to indicate
  79. the UST of the most recent determination that the engine cycle
  80. should run. it should not be set if the "extra_fd" argument of
  81. the wait function is set to a non-zero value.
  82. jack_time_t last_wait_ust;
  83. This is not used by the driver. it should not be written to or
  84. modified in any way
  85. void *handle;
  86. This should perform any cleanup associated with the driver. it will
  87. be called when jack server process decides to get rid of the
  88. driver. in some systems, it may not be called at all, so the driver
  89. should never rely on a call to this. it can set it to NULL if
  90. it has nothing do do.
  91. void (*finish)(struct _jack_driver *);
  92. The JACK engine will call this when it wishes to attach itself to
  93. the driver. the engine will pass a pointer to itself, which the driver
  94. may use in anyway it wishes to. the driver may assume that this
  95. is the same engine object that will make `wait' calls until a
  96. `detach' call is made.
  97. JackDriverAttachFunction attach;
  98. The JACK engine will call this when it is finished using a driver.
  99. JackDriverDetachFunction detach;
  100. The JACK engine will call this when it wants to wait until the
  101. driver decides that its time to process some data. the driver returns
  102. a count of the number of audioframes that can be processed.
  103. it should set the variable pointed to by `status' as follows:
  104. zero: the wait completed normally, processing may begin
  105. negative: the wait failed, and recovery is not possible
  106. positive: the wait failed, and the driver stopped itself.
  107. a call to `start' will return the driver to
  108. a correct and known state.
  109. the driver should also fill out the `delayed_usecs' variable to
  110. indicate any delay in its expected periodic execution. for example,
  111. if it discovers that its return from poll(2) is later than it
  112. expects it to be, it would place an estimate of the delay
  113. in this variable. the engine will use this to decide if it
  114. plans to continue execution.
  115. JackDriverWaitFunction wait;
  116. The JACK engine will call this to ask the driver to move
  117. data from its inputs to its output port buffers. it should
  118. return 0 to indicate successful completion, negative otherwise.
  119. This function will always be called after the wait function (above).
  120. JackDriverReadFunction read;
  121. The JACK engine will call this to ask the driver to move
  122. data from its input port buffers to its outputs. it should
  123. return 0 to indicate successful completion, negative otherwise.
  124. this function will always be called after the read function (above).
  125. JackDriverWriteFunction write;
  126. The JACK engine will call this after the wait function (above) has
  127. been called, but for some reason the engine is unable to execute
  128. a full "cycle". the driver should do whatever is necessary to
  129. keep itself running correctly, but cannot reference ports
  130. or other JACK data structures in any way.
  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. JackDriverStopFunction stop;
  136. The engine will call this to let the driver know that it plans
  137. to start calling the `wait' function on a regular basis. the driver
  138. should take any appropriate steps to handle this (possibly no steps
  139. at all)
  140. JackDriverStartFunction start;
  141. */
  142. /* define the fields here... */
  143. #define JACK_DRIVER_DECL \
  144. jack_time_t period_usecs; \
  145. jack_time_t last_wait_ust; \
  146. void *handle; \
  147. void (*finish)(struct _jack_driver *);\
  148. JackDriverAttachFunction attach; \
  149. JackDriverDetachFunction detach; \
  150. JackDriverWaitFunction wait; \
  151. JackDriverReadFunction read; \
  152. JackDriverWriteFunction write; \
  153. JackDriverNullCycleFunction null_cycle; \
  154. JackDriverStopFunction stop; \
  155. JackDriverStartFunction start;
  156. JACK_DRIVER_DECL /* expand the macro */
  157. } jack_driver_t;
  158. void jack_driver_init (jack_driver_t *);
  159. void jack_driver_release (jack_driver_t *);
  160. jack_driver_t *jack_driver_load (int argc, char **argv);
  161. void jack_driver_unload (jack_driver_t *);
  162. #endif /* __jack_driver_h__ */