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.

205 lines
5.4KB

  1. /*
  2. * FireWire Backend for Jack
  3. * using FFADO
  4. * FFADO = Firewire (pro-)audio for linux
  5. *
  6. * http://www.ffado.org
  7. * http://www.jackaudio.org
  8. *
  9. * Copyright (C) 2005-2007 Pieter Palmers
  10. * Copyright (C) 2009 Devin Anderson
  11. *
  12. * adapted for JackMP by Pieter Palmers
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. */
  28. /*
  29. * Main Jack driver entry routines
  30. *
  31. */
  32. #ifndef __JACK_FFADO_DRIVER_H__
  33. #define __JACK_FFADO_DRIVER_H__
  34. #include <libffado/ffado.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37. #include <errno.h>
  38. #include <stdio.h>
  39. #include <poll.h>
  40. #include <sys/time.h>
  41. #include <netinet/in.h>
  42. #include <endian.h>
  43. #include <pthread.h>
  44. #include <semaphore.h>
  45. #include <driver.h>
  46. #include <types.h>
  47. #include <assert.h>
  48. //#include <jack/midiport.h>
  49. // debug print control flags
  50. #define DEBUG_LEVEL_BUFFERS (1<<0)
  51. #define DEBUG_LEVEL_HANDLERS (1<<1)
  52. #define DEBUG_LEVEL_XRUN_RECOVERY (1<<2)
  53. #define DEBUG_LEVEL_WAIT (1<<3)
  54. #define DEBUG_LEVEL_RUN_CYCLE (1<<8)
  55. #define DEBUG_LEVEL_PACKETCOUNTER (1<<16)
  56. #define DEBUG_LEVEL_STARTUP (1<<17)
  57. #define DEBUG_LEVEL_THREADS (1<<18)
  58. //#define DEBUG_ENABLED
  59. #ifdef DEBUG_ENABLED
  60. // default debug level
  61. #define DEBUG_LEVEL ( DEBUG_LEVEL_RUN_CYCLE | \
  62. (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER)
  63. #warning Building debug build!
  64. #define printMessage(format, args...) jack_error( "firewire MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  65. #define printError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  66. #define printEnter() jack_error( "FWDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__)
  67. #define printExit() jack_error( "FWDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__)
  68. #define printEnter()
  69. #define printExit()
  70. #define debugError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  71. #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ##args );
  72. #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( format,##args );
  73. #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: " format, debugGetCurrentUTime(), ##args );
  74. #define SEGFAULT int *test=NULL; *test=1;
  75. #else
  76. #define DEBUG_LEVEL
  77. #define printMessage(format, args...) if(g_verbose) \
  78. jack_error("firewire MSG: " format, ##args )
  79. #define printError(format, args...) jack_error("firewire ERR: " format, ##args )
  80. #define printEnter()
  81. #define printExit()
  82. #define debugError(format, args...)
  83. #define debugPrint(Level, format, args...)
  84. #define debugPrintShort(Level, format, args...)
  85. #define debugPrintWithTimeStamp(Level, format, args...)
  86. #endif
  87. // thread priority setup
  88. #define FFADO_RT_PRIORITY_PACKETIZER_RELATIVE 5
  89. typedef struct _ffado_driver ffado_driver_t;
  90. /*
  91. * Jack Driver command line parameters
  92. */
  93. typedef struct _ffado_jack_settings ffado_jack_settings_t;
  94. struct _ffado_jack_settings
  95. {
  96. int verbose_level;
  97. int period_size_set;
  98. jack_nframes_t period_size;
  99. int sample_rate_set;
  100. int sample_rate;
  101. int buffer_size_set;
  102. jack_nframes_t buffer_size;
  103. int playback_ports;
  104. int capture_ports;
  105. jack_nframes_t capture_frame_latency;
  106. jack_nframes_t playback_frame_latency;
  107. int slave_mode;
  108. int snoop_mode;
  109. char *device_info;
  110. };
  111. typedef struct _ffado_capture_channel
  112. {
  113. ffado_streaming_stream_type stream_type;
  114. uint32_t *midi_buffer;
  115. void *midi_input;
  116. }
  117. ffado_capture_channel_t;
  118. typedef struct _ffado_playback_channel
  119. {
  120. ffado_streaming_stream_type stream_type;
  121. uint32_t *midi_buffer;
  122. void *midi_output;
  123. }
  124. ffado_playback_channel_t;
  125. /*
  126. * JACK driver structure
  127. */
  128. struct _ffado_driver
  129. {
  130. JACK_DRIVER_NT_DECL;
  131. jack_nframes_t sample_rate;
  132. jack_nframes_t period_size;
  133. unsigned long wait_time;
  134. jack_time_t wait_last;
  135. jack_time_t wait_next;
  136. int wait_late;
  137. jack_client_t *client;
  138. int xrun_detected;
  139. int xrun_count;
  140. int process_count;
  141. /* settings from the command line */
  142. ffado_jack_settings_t settings;
  143. /* the firewire virtual device */
  144. ffado_device_t *dev;
  145. channel_t playback_nchannels;
  146. channel_t capture_nchannels;
  147. ffado_playback_channel_t *playback_channels;
  148. ffado_capture_channel_t *capture_channels;
  149. ffado_sample_t *nullbuffer;
  150. ffado_sample_t *scratchbuffer;
  151. jack_nframes_t playback_frame_latency;
  152. jack_nframes_t capture_frame_latency;
  153. ffado_device_info_t device_info;
  154. ffado_options_t device_options;
  155. };
  156. #endif /* __JACK_FFADO_DRIVER_H__ */