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.

245 lines
6.3KB

  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 <string.h>
  35. #include <stdlib.h>
  36. #include <errno.h>
  37. #include <stdio.h>
  38. #include <poll.h>
  39. #include <sys/time.h>
  40. #include <netinet/in.h>
  41. #include <endian.h>
  42. #include <pthread.h>
  43. #include <semaphore.h>
  44. #include <jack/driver.h>
  45. #include <jack/engine.h>
  46. #include <jack/types.h>
  47. #ifdef FREEBOB_DRIVER_WITH_MIDI
  48. #include <jack/thread.h>
  49. #include <alsa/asoundlib.h>
  50. #endif
  51. // debug print control flags
  52. #define DEBUG_LEVEL_BUFFERS (1<<0)
  53. #define DEBUG_LEVEL_HANDLERS (1<<1)
  54. #define DEBUG_LEVEL_XRUN_RECOVERY (1<<2)
  55. #define DEBUG_LEVEL_WAIT (1<<3)
  56. #define DEBUG_LEVEL_RUN_CYCLE (1<<8)
  57. #define DEBUG_LEVEL_PACKETCOUNTER (1<<16)
  58. #define DEBUG_LEVEL_STARTUP (1<<17)
  59. #define DEBUG_LEVEL_THREADS (1<<18)
  60. #ifdef DEBUG_ENABLED
  61. // default debug level
  62. #define DEBUG_LEVEL ( DEBUG_LEVEL_RUN_CYCLE | \
  63. (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER)
  64. #warning Building debug build!
  65. #define printMessage(format, args...) jack_error( "FreeBoB MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  66. #define printError(format, args...) jack_error( "FreeBoB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  67. //#define printEnter() jack_error( "FBDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__)
  68. //#define printExit() jack_error( "FBDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__)
  69. #define printEnter()
  70. #define printExit()
  71. #define debugError(format, args...) jack_error( "FREEBOB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  72. #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ##args );
  73. #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( format,##args );
  74. #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: "format, debugGetCurrentUTime(),##args );
  75. #define SEGFAULT int *test=NULL; *test=1;
  76. #else
  77. #define DEBUG_LEVEL
  78. #define printMessage(format, args...) if(g_verbose) \
  79. jack_error("FreeBoB MSG: " format, ##args )
  80. #define printError(format, args...) jack_error("FreeBoB ERR: " format, ##args )
  81. #define printEnter()
  82. #define printExit()
  83. #define debugError(format, args...)
  84. #define debugPrint(Level, format, args...)
  85. #define debugPrintShort(Level, format, args...)
  86. #define debugPrintWithTimeStamp(Level, format, args...)
  87. #endif
  88. // thread priority setup
  89. #define FREEBOB_RT_PRIORITY_PACKETIZER_RELATIVE 5
  90. #ifdef FREEBOB_DRIVER_WITH_MIDI
  91. #define ALSA_SEQ_BUFF_SIZE 1024
  92. #define MIDI_TRANSMIT_BUFFER_SIZE 1024
  93. #define MIDI_THREAD_SLEEP_TIME_USECS 100
  94. // midi priority should be higher than the audio priority in order to
  95. // make sure events are not only delivered on period boundarys
  96. // but I think it should be smaller than the packetizer thread in order not
  97. // to lose any packets
  98. #define FREEBOB_RT_PRIORITY_MIDI_RELATIVE 4
  99. #endif
  100. typedef struct _freebob_driver freebob_driver_t;
  101. /*
  102. * Jack Driver command line parameters
  103. */
  104. typedef struct _freebob_jack_settings freebob_jack_settings_t;
  105. struct _freebob_jack_settings {
  106. int period_size_set;
  107. jack_nframes_t period_size;
  108. int sample_rate_set;
  109. int sample_rate;
  110. int buffer_size_set;
  111. jack_nframes_t buffer_size;
  112. int port_set;
  113. int port;
  114. int node_id_set;
  115. int node_id;
  116. int playback_ports;
  117. int capture_ports;
  118. jack_nframes_t capture_frame_latency;
  119. jack_nframes_t playback_frame_latency;
  120. freebob_handle_t fb_handle;
  121. };
  122. #ifdef FREEBOB_DRIVER_WITH_MIDI
  123. typedef struct {
  124. int stream_nr;
  125. int seq_port_nr;
  126. snd_midi_event_t *parser;
  127. snd_seq_t *seq_handle;
  128. } freebob_midi_port_t;
  129. typedef struct _freebob_driver_midi_handle {
  130. freebob_device_t *dev;
  131. freebob_driver_t *driver;
  132. snd_seq_t *seq_handle;
  133. pthread_t queue_thread;
  134. pthread_t dequeue_thread;
  135. int queue_thread_realtime;
  136. int queue_thread_priority;
  137. int nb_input_ports;
  138. int nb_output_ports;
  139. freebob_midi_port_t **input_ports;
  140. freebob_midi_port_t **output_ports;
  141. freebob_midi_port_t **input_stream_port_map;
  142. int *output_port_stream_map;
  143. } freebob_driver_midi_handle_t;
  144. #endif
  145. /*
  146. * JACK driver structure
  147. */
  148. struct _freebob_driver
  149. {
  150. JACK_DRIVER_NT_DECL
  151. jack_nframes_t sample_rate;
  152. jack_nframes_t period_size;
  153. unsigned long wait_time;
  154. jack_time_t wait_last;
  155. jack_time_t wait_next;
  156. int wait_late;
  157. jack_client_t *client;
  158. int xrun_detected;
  159. int xrun_count;
  160. int process_count;
  161. /* settings from the command line */
  162. freebob_jack_settings_t settings;
  163. /* the freebob virtual device */
  164. freebob_device_t *dev;
  165. JSList *capture_ports;
  166. JSList *playback_ports;
  167. JSList *monitor_ports;
  168. channel_t playback_nchannels;
  169. channel_t capture_nchannels;
  170. jack_nframes_t playback_frame_latency;
  171. jack_nframes_t capture_frame_latency;
  172. freebob_device_info_t device_info;
  173. freebob_options_t device_options;
  174. #ifdef FREEBOB_DRIVER_WITH_MIDI
  175. freebob_driver_midi_handle_t *midi_handle;
  176. #endif
  177. };
  178. #endif /* __JACK_FREEBOB_DRIVER_H__ */