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.

213 lines
5.7KB

  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. *
  11. * adapted for JackMP by Pieter Palmers
  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. #include <libffado/ffado.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 <driver.h>
  45. #include <types.h>
  46. #include <assert.h>
  47. #include <jack/midiport.h>
  48. // #include "JackPort.h"
  49. // #include "JackMidiPort.h"
  50. #include <../alsa/midi_pack.h>
  51. #include <../alsa/midi_unpack.h>
  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. //#define DEBUG_ENABLED
  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( "firewire MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  68. #define printError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
  69. #define printEnter() jack_error( "FWDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__)
  70. #define printExit() jack_error( "FWDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__)
  71. #define printEnter()
  72. #define printExit()
  73. #define debugError(format, args...) jack_error( "firewire 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("firewire MSG: " format, ##args )
  82. #define printError(format, args...) jack_error("firewire 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 FFADO_RT_PRIORITY_PACKETIZER_RELATIVE 5
  92. typedef struct _ffado_driver ffado_driver_t;
  93. /*
  94. * Jack Driver command line parameters
  95. */
  96. typedef struct _ffado_jack_settings ffado_jack_settings_t;
  97. struct _ffado_jack_settings
  98. {
  99. int verbose_level;
  100. int period_size_set;
  101. jack_nframes_t period_size;
  102. int sample_rate_set;
  103. int sample_rate;
  104. int buffer_size_set;
  105. jack_nframes_t buffer_size;
  106. int playback_ports;
  107. int capture_ports;
  108. jack_nframes_t capture_frame_latency;
  109. jack_nframes_t playback_frame_latency;
  110. int slave_mode;
  111. int snoop_mode;
  112. char *device_info;
  113. };
  114. typedef struct _ffado_capture_channel
  115. {
  116. ffado_streaming_stream_type stream_type;
  117. midi_unpack_t midi_unpack;
  118. uint32_t *midi_buffer;
  119. }
  120. ffado_capture_channel_t;
  121. #define MIDI_OVERFLOW_BUFFER_SIZE 4
  122. typedef struct _ffado_playback_channel
  123. {
  124. ffado_streaming_stream_type stream_type;
  125. midi_pack_t midi_pack;
  126. uint32_t *midi_buffer;
  127. // to hold the midi bytes that couldn't be transferred
  128. // during the previous period
  129. char overflow_buffer[MIDI_OVERFLOW_BUFFER_SIZE];
  130. unsigned int nb_overflow_bytes;
  131. }
  132. ffado_playback_channel_t;
  133. /*
  134. * JACK driver structure
  135. */
  136. struct _ffado_driver
  137. {
  138. JACK_DRIVER_NT_DECL;
  139. jack_nframes_t sample_rate;
  140. jack_nframes_t period_size;
  141. unsigned long wait_time;
  142. jack_time_t wait_last;
  143. jack_time_t wait_next;
  144. int wait_late;
  145. jack_client_t *client;
  146. int xrun_detected;
  147. int xrun_count;
  148. int process_count;
  149. /* settings from the command line */
  150. ffado_jack_settings_t settings;
  151. /* the firewire virtual device */
  152. ffado_device_t *dev;
  153. channel_t playback_nchannels;
  154. channel_t capture_nchannels;
  155. ffado_playback_channel_t *playback_channels;
  156. ffado_capture_channel_t *capture_channels;
  157. ffado_sample_t *nullbuffer;
  158. ffado_sample_t *scratchbuffer;
  159. jack_nframes_t playback_frame_latency;
  160. jack_nframes_t capture_frame_latency;
  161. ffado_device_info_t device_info;
  162. ffado_options_t device_options;
  163. };
  164. #endif /* __JACK_FFADO_DRIVER_H__ */