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.

207 lines
6.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 <glib.h>
  19. #include <pthread.h>
  20. #include <jack/types.h>
  21. #include <jack/port.h>
  22. typedef float gain_t;
  23. typedef long channel_t;
  24. typedef enum {
  25. Lock = 0x1,
  26. NoLock = 0x2,
  27. Sync = 0x4,
  28. NoSync = 0x8
  29. } ClockSyncStatus;
  30. typedef void (*ClockSyncListenerFunction)(channel_t,ClockSyncStatus,void*);
  31. typedef struct {
  32. unsigned long id;
  33. ClockSyncListenerFunction function;
  34. void *arg;
  35. } ClockSyncListener;
  36. struct _jack_engine;
  37. struct _jack_driver;
  38. typedef int (*JackDriverAttachFunction)(struct _jack_driver *, struct _jack_engine *);
  39. typedef int (*JackDriverDetachFunction)(struct _jack_driver *, struct _jack_engine *);
  40. typedef jack_nframes_t (*JackDriverWaitFunction)(struct _jack_driver *, int fd, int *status, float *delayed_usecs);
  41. typedef int (*JackDriverProcessFunction)(struct _jack_driver *, jack_nframes_t);
  42. typedef int (*JackDriverStopFunction)(struct _jack_driver *);
  43. typedef int (*JackDriverStartFunction)(struct _jack_driver *);
  44. /*
  45. Call sequence summary:
  46. 1) engine loads driver via runtime dynamic linking
  47. - calls jack_driver_load
  48. - we lookup "driver_initialize" and execute it
  49. 2) engine attaches to driver
  50. 3) engine starts driver
  51. 4) while (1) {
  52. engine->wait ();
  53. }
  54. 5) engine stops driver
  55. 6) engine detaches from driver
  56. 7) engine calls driver `finish' routine, if any
  57. note that stop/start may be called multiple times in the event of an
  58. error return from the `wait' function.
  59. */
  60. #ifdef _ANNOTATED_DRIVER_DECLARATION_
  61. #define JACK_DRIVER_DECL
  62. /* the driver should set this to be the interval it expects to elapse
  63. between returning from the `wait' function.
  64. */
  65. nframes_t period_usecs;
  66. /* this is not used by the driver. it should not be written to or
  67. modified in any way
  68. */
  69. void *handle;
  70. /* this should perform any cleanup associated with the driver. it will
  71. be called when jack server process decides to get rid of the
  72. driver. in some systems, it may not be called at all, so the driver
  73. should never rely on a call to this. it can set it to NULL if
  74. it has nothing do do.
  75. */
  76. void (*finish)(struct _jack_driver *);\
  77. /* the JACK engine will call this when it wishes to attach itself to
  78. the driver. the engine will pass a pointer to itself, which the driver
  79. may use in anyway it wishes to. the driver may assume that this
  80. is the same engine object that will make `wait' calls until a
  81. `detach' call is made.
  82. */
  83. JackDriverAttachFunction attach; \
  84. /* the JACK engine will call this when it is finished using a driver.
  85. */
  86. JackDriverDetachFunction detach; \
  87. /* the JACK engine will call this when it wants to wait until the
  88. driver decides that its time to process some data. the driver returns
  89. a count of the number of audioframes that can be processed.
  90. it should set the variable pointed to by `status' as follows:
  91. zero: the wait completed normally, processing may begin
  92. negative: the wait failed, and recovery is not possible
  93. positive: the wait failed, and the driver stopped itself.
  94. a call to `start' will return the driver to
  95. a correct and known state.
  96. the driver should also fill out the `delayed_usecs' variable to
  97. indicate any delay in its expected periodic execution. for example,
  98. if it discovers that its return from poll(2) is later than it
  99. expects it to be, it would place an estimate of the delay
  100. in this variable. the engine will use this to decide if it
  101. plans to continue execution.
  102. */
  103. JackDriverWaitFunction wait; \
  104. /* this is somewhat like a JACK client process callback. see jack.h for
  105. details. the engine will call this after the driver has returned
  106. from `wait', and it will pass the number of audio frames that
  107. the driver returned from `wait' as the second argument.
  108. the driver should make the following calls (with error checking)
  109. from within this function:
  110. engine->process_lock (engine);
  111. ...
  112. engine->process (engine);
  113. ...
  114. engine->process_unlock (engine);
  115. ...
  116. engine->post_process (engine);
  117. the reason for the structure is complex. it can be explained
  118. in more detail you are curious.
  119. */
  120. JackDriverProcessFunction process; \
  121. /* the engine will call this when it plans to stop calling the `wait'
  122. function for some period of time. the driver should take
  123. appropriate steps to handle this (possibly no steps at all)
  124. */
  125. JackDriverStartFunction stop; \
  126. /* the engine will call this to let the driver know that it plans
  127. to start calling the `wait' function on a regular basis. the driver
  128. should take any appropriate steps to handle this (possibly no steps
  129. at all)
  130. */
  131. JackDriverStopFunction start;
  132. #endif _ANNOTATED_DRIVER_DECLARATION_
  133. #define JACK_DRIVER_DECL \
  134. jack_nframes_t period_usecs; \
  135. void *handle; \
  136. void (*finish)(struct _jack_driver *);\
  137. JackDriverAttachFunction attach; \
  138. JackDriverDetachFunction detach; \
  139. JackDriverWaitFunction wait; \
  140. JackDriverProcessFunction process; \
  141. JackDriverStartFunction stop; \
  142. JackDriverStopFunction start;
  143. typedef struct _jack_driver {
  144. JACK_DRIVER_DECL
  145. } jack_driver_t;
  146. void jack_driver_init (jack_driver_t *);
  147. void jack_driver_release (jack_driver_t *);
  148. jack_driver_t *jack_driver_load (int argc, char **argv);
  149. void jack_driver_unload (jack_driver_t *);
  150. #endif /* __jack_driver_h__ */