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.

241 lines
6.2KB

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