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
6.4KB

  1. /* freebob_driver.h
  2. *
  3. * FreeBob Backend for Jack
  4. * FreeBob = Firewire (pro-)audio for linux
  5. *
  6. * http://freebob.sf.net
  7. * http://jackit.sf.net
  8. *
  9. * Copyright (C) 2005 Pieter Palmers <pieterpalmers@users.sourceforge.net>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*
  26. * Main Jack driver entry routines
  27. *
  28. */
  29. #ifndef __JACK_FREEBOB_DRIVER_H__
  30. #define __JACK_FREEBOB_DRIVER_H__
  31. #define FREEBOB_DRIVER_WITH_MIDI
  32. #include <libfreebob/freebob.h>
  33. #include <libfreebob/freebob_streaming.h>
  34. #include <jack/driver.h>
  35. #include <jack/engine.h>
  36. #include <jack/types.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39. #include <errno.h>
  40. #include <stdio.h>
  41. #include <poll.h>
  42. #include <sys/time.h>
  43. #include <netinet/in.h>
  44. #include <endian.h>
  45. #include <pthread.h>
  46. #include <semaphore.h>
  47. #include <jack/internal.h>
  48. #include <jack/types.h>
  49. #include <jack/ringbuffer.h>
  50. #include <jack/driver.h>
  51. #include <jack/engine.h>
  52. #include <jack/types.h>
  53. #include <jack/thread.h>
  54. #include <alsa/asoundlib.h>
  55. // debug print control flags
  56. #define DEBUG_LEVEL_BUFFERS (1<<0)
  57. #define DEBUG_LEVEL_HANDLERS (1<<1)
  58. #define DEBUG_LEVEL_XRUN_RECOVERY (1<<2)
  59. #define DEBUG_LEVEL_WAIT (1<<3)
  60. #define DEBUG_LEVEL_RUN_CYCLE (1<<8)
  61. #define DEBUG_LEVEL_PACKETCOUNTER (1<<16)
  62. #define DEBUG_LEVEL_STARTUP (1<<17)
  63. #define DEBUG_LEVEL_THREADS (1<<18)
  64. #ifdef DEBUG_ENABLED
  65. // default debug level
  66. #define DEBUG_LEVEL ( DEBUG_LEVEL_RUN_CYCLE | \
  67. (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER)
  68. #warning Building debug build!
  69. #define printMessage(format, args...) jack_error( "FreeBoB MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  70. #define printError(format, args...) jack_error( "FreeBoB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  71. //#define printEnter() jack_error( "FBDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__)
  72. //#define printExit() jack_error( "FBDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__)
  73. #define printEnter()
  74. #define printExit()
  75. #define debugError(format, args...) jack_error( "FREEBOB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  76. #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ##args );
  77. #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( format,##args );
  78. #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: "format, debugGetCurrentUTime(),##args );
  79. #define SEGFAULT int *test=NULL; *test=1;
  80. #else
  81. #define DEBUG_LEVEL
  82. #define printMessage(format, args...) if(g_verbose) \
  83. jack_error("FreeBoB MSG: " format, ##args )
  84. #define printError(format, args...) jack_error("FreeBoB ERR: " format, ##args )
  85. #define printEnter()
  86. #define printExit()
  87. #define debugError(format, args...)
  88. #define debugPrint(Level, format, args...)
  89. #define debugPrintShort(Level, format, args...)
  90. #define debugPrintWithTimeStamp(Level, format, args...)
  91. #endif
  92. // thread priority setup
  93. #define FREEBOB_RT_PRIORITY_PACKETIZER_RELATIVE 5
  94. #ifdef FREEBOB_DRIVER_WITH_MIDI
  95. #define ALSA_SEQ_BUFF_SIZE 1024
  96. #define MIDI_TRANSMIT_BUFFER_SIZE 1024
  97. #define MIDI_THREAD_SLEEP_TIME_USECS 100
  98. // midi priority should be higher than the audio priority in order to
  99. // make sure events are not only delivered on period boundarys
  100. // but I think it should be smaller than the packetizer thread in order not
  101. // to lose any packets
  102. #define FREEBOB_RT_PRIORITY_MIDI_RELATIVE 4
  103. #endif
  104. typedef struct _freebob_driver freebob_driver_t;
  105. /*
  106. * Jack Driver command line parameters
  107. */
  108. typedef struct _freebob_jack_settings freebob_jack_settings_t;
  109. struct _freebob_jack_settings {
  110. int period_size_set;
  111. jack_nframes_t period_size;
  112. int sample_rate_set;
  113. int sample_rate;
  114. int buffer_size_set;
  115. jack_nframes_t buffer_size;
  116. int port_set;
  117. int port;
  118. int node_id_set;
  119. int node_id;
  120. int playback_ports;
  121. int capture_ports;
  122. jack_nframes_t capture_frame_latency;
  123. jack_nframes_t playback_frame_latency;
  124. freebob_handle_t fb_handle;
  125. };
  126. #ifdef FREEBOB_DRIVER_WITH_MIDI
  127. typedef struct {
  128. int stream_nr;
  129. int seq_port_nr;
  130. snd_midi_event_t *parser;
  131. snd_seq_t *seq_handle;
  132. } freebob_midi_port_t;
  133. typedef struct _freebob_driver_midi_handle {
  134. freebob_device_t *dev;
  135. freebob_driver_t *driver;
  136. snd_seq_t *seq_handle;
  137. pthread_t queue_thread;
  138. pthread_t dequeue_thread;
  139. int queue_thread_realtime;
  140. int queue_thread_priority;
  141. int nb_input_ports;
  142. int nb_output_ports;
  143. freebob_midi_port_t **input_ports;
  144. freebob_midi_port_t **output_ports;
  145. freebob_midi_port_t **input_stream_port_map;
  146. int *output_port_stream_map;
  147. } freebob_driver_midi_handle_t;
  148. #endif
  149. /*
  150. * JACK driver structure
  151. */
  152. struct _freebob_driver
  153. {
  154. JACK_DRIVER_NT_DECL
  155. jack_nframes_t sample_rate;
  156. jack_nframes_t period_size;
  157. unsigned long wait_time;
  158. jack_time_t wait_last;
  159. jack_time_t wait_next;
  160. int wait_late;
  161. jack_client_t *client;
  162. int xrun_detected;
  163. int xrun_count;
  164. int process_count;
  165. /* settings from the command line */
  166. freebob_jack_settings_t settings;
  167. /* the freebob virtual device */
  168. freebob_device_t *dev;
  169. JSList *capture_ports;
  170. JSList *playback_ports;
  171. JSList *monitor_ports;
  172. channel_t playback_nchannels;
  173. channel_t capture_nchannels;
  174. jack_nframes_t playback_frame_latency;
  175. jack_nframes_t capture_frame_latency;
  176. freebob_device_info_t device_info;
  177. freebob_options_t device_options;
  178. #ifdef FREEBOB_DRIVER_WITH_MIDI
  179. freebob_driver_midi_handle_t *midi_handle;
  180. #endif
  181. };
  182. #endif /* __JACK_FREEBOB_DRIVER_H__ */