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.

214 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. * 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_FFADO_DRIVER_H__
  30. #define __JACK_FFADO_DRIVER_H__
  31. #include <assert.h>
  32. #include <libffado/ffado.h>
  33. #include <string.h>
  34. #include <stdlib.h>
  35. #include <errno.h>
  36. #include <stdio.h>
  37. #include <poll.h>
  38. #include <sys/time.h>
  39. #include <netinet/in.h>
  40. #include <endian.h>
  41. #include <pthread.h>
  42. #include <semaphore.h>
  43. #include <jack/driver.h>
  44. #include <jack/engine.h>
  45. #include <jack/types.h>
  46. #include <jack/internal.h>
  47. #include <jack/types.h>
  48. #include <jack/ringbuffer.h>
  49. #include <jack/thread.h>
  50. #include <../alsa-midi/midi_pack.h>
  51. #include <../alsa-midi/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. typedef struct _ffado_driver ffado_driver_t;
  91. /*
  92. * Jack Driver command line parameters
  93. */
  94. typedef struct _ffado_jack_settings ffado_jack_settings_t;
  95. struct _ffado_jack_settings {
  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. midi_unpack_t midi_unpack;
  115. uint32_t *midi_buffer;
  116. } ffado_capture_channel_t;
  117. #define MIDI_OVERFLOW_BUFFER_SIZE 4
  118. typedef struct _ffado_playback_channel
  119. {
  120. ffado_streaming_stream_type stream_type;
  121. midi_pack_t midi_pack;
  122. uint32_t *midi_buffer;
  123. // to hold the midi bytes that couldn't be transferred
  124. // during the previous period
  125. char overflow_buffer[MIDI_OVERFLOW_BUFFER_SIZE];
  126. unsigned int nb_overflow_bytes;
  127. } ffado_playback_channel_t;
  128. /*
  129. * JACK driver structure
  130. */
  131. struct _ffado_driver
  132. {
  133. JACK_DRIVER_NT_DECL;
  134. jack_nframes_t sample_rate;
  135. jack_nframes_t period_size;
  136. unsigned long wait_time;
  137. jack_time_t wait_last;
  138. jack_time_t wait_next;
  139. int wait_late;
  140. jack_client_t *client;
  141. int xrun_detected;
  142. int xrun_count;
  143. int process_count;
  144. /* settings from the command line */
  145. ffado_jack_settings_t settings;
  146. /* the firewire virtual device */
  147. ffado_device_t *dev;
  148. ffado_sample_t *nullbuffer;
  149. ffado_sample_t *scratchbuffer;
  150. JSList *capture_ports;
  151. JSList *playback_ports;
  152. JSList *monitor_ports;
  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. jack_nframes_t playback_frame_latency;
  158. jack_nframes_t capture_frame_latency;
  159. ffado_device_info_t device_info;
  160. ffado_options_t device_options;
  161. };
  162. #endif /* __JACK_FFADO_DRIVER_H__ */