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

246 lines
6.4KB

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