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.

210 lines
5.8KB

  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. int verbose_level;
  99. int period_size_set;
  100. jack_nframes_t period_size;
  101. int sample_rate_set;
  102. int sample_rate;
  103. int buffer_size_set;
  104. jack_nframes_t buffer_size;
  105. int playback_ports;
  106. int capture_ports;
  107. jack_nframes_t capture_frame_latency;
  108. jack_nframes_t playback_frame_latency;
  109. int slave_mode;
  110. int snoop_mode;
  111. char *device_info;
  112. };
  113. typedef struct _ffado_capture_channel
  114. {
  115. ffado_streaming_stream_type stream_type;
  116. midi_unpack_t midi_unpack;
  117. uint32_t *midi_buffer;
  118. } ffado_capture_channel_t;
  119. #define MIDI_OVERFLOW_BUFFER_SIZE 4
  120. typedef struct _ffado_playback_channel
  121. {
  122. ffado_streaming_stream_type stream_type;
  123. midi_pack_t midi_pack;
  124. uint32_t *midi_buffer;
  125. // to hold the midi bytes that couldn't be transferred
  126. // during the previous period
  127. char overflow_buffer[MIDI_OVERFLOW_BUFFER_SIZE];
  128. unsigned int nb_overflow_bytes;
  129. } ffado_playback_channel_t;
  130. /*
  131. * JACK driver structure
  132. */
  133. struct _ffado_driver
  134. {
  135. JACK_DRIVER_NT_DECL;
  136. jack_nframes_t sample_rate;
  137. jack_nframes_t period_size;
  138. unsigned long wait_time;
  139. jack_time_t wait_last;
  140. jack_time_t wait_next;
  141. int wait_late;
  142. jack_client_t *client;
  143. int xrun_detected;
  144. int xrun_count;
  145. int process_count;
  146. /* settings from the command line */
  147. ffado_jack_settings_t settings;
  148. /* the firewire virtual device */
  149. ffado_device_t *dev;
  150. channel_t playback_nchannels;
  151. channel_t capture_nchannels;
  152. ffado_playback_channel_t *playback_channels;
  153. ffado_capture_channel_t *capture_channels;
  154. ffado_sample_t *nullbuffer;
  155. ffado_sample_t *scratchbuffer;
  156. jack_nframes_t playback_frame_latency;
  157. jack_nframes_t capture_frame_latency;
  158. ffado_device_info_t device_info;
  159. ffado_options_t device_options;
  160. };
  161. #endif /* __JACK_FFADO_DRIVER_H__ */