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.

211 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. * 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/types.h>
  44. #include <jack/ringbuffer.h>
  45. #include <jack/thread.h>
  46. #include "driver.h"
  47. #include "engine.h"
  48. #include "internal.h"
  49. #include "../alsa_midi/midi_pack.h"
  50. #include "../alsa_midi/midi_unpack.h"
  51. // debug print control flags
  52. #define DEBUG_LEVEL_BUFFERS (1 << 0)
  53. #define DEBUG_LEVEL_HANDLERS (1 << 1)
  54. #define DEBUG_LEVEL_XRUN_RECOVERY (1 << 2)
  55. #define DEBUG_LEVEL_WAIT (1 << 3)
  56. #define DEBUG_LEVEL_RUN_CYCLE (1 << 8)
  57. #define DEBUG_LEVEL_PACKETCOUNTER (1 << 16)
  58. #define DEBUG_LEVEL_STARTUP (1 << 17)
  59. #define DEBUG_LEVEL_THREADS (1 << 18)
  60. //#define DEBUG_ENABLED
  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 ( "firewire MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ## args )
  67. #define printError(format, args ...) jack_error ( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ## args )
  68. #define printEnter() jack_error ( "FWDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__)
  69. #define printExit() jack_error ( "FWDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__)
  70. #define printEnter()
  71. #define printExit()
  72. #define debugError(format, args ...) jack_error ( "firewire 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 ("firewire MSG: " format, ## args )
  81. #define printError(format, args ...) jack_error ("firewire 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. 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. int verbose_level;
  96. int period_size_set;
  97. jack_nframes_t period_size;
  98. int sample_rate_set;
  99. int sample_rate;
  100. int buffer_size_set;
  101. jack_nframes_t buffer_size;
  102. int playback_ports;
  103. int capture_ports;
  104. jack_nframes_t capture_frame_latency;
  105. jack_nframes_t playback_frame_latency;
  106. int slave_mode;
  107. int snoop_mode;
  108. char *device_info;
  109. };
  110. typedef struct _ffado_capture_channel {
  111. ffado_streaming_stream_type stream_type;
  112. midi_unpack_t midi_unpack;
  113. uint32_t *midi_buffer;
  114. } ffado_capture_channel_t;
  115. #define MIDI_OVERFLOW_BUFFER_SIZE 4
  116. typedef struct _ffado_playback_channel {
  117. ffado_streaming_stream_type stream_type;
  118. midi_pack_t midi_pack;
  119. uint32_t *midi_buffer;
  120. // to hold the midi bytes that couldn't be transferred
  121. // during the previous period
  122. char overflow_buffer[MIDI_OVERFLOW_BUFFER_SIZE];
  123. unsigned int nb_overflow_bytes;
  124. } ffado_playback_channel_t;
  125. /*
  126. * JACK driver structure
  127. */
  128. struct _ffado_driver {
  129. JACK_DRIVER_NT_DECL;
  130. jack_nframes_t sample_rate;
  131. jack_nframes_t period_size;
  132. unsigned long wait_time;
  133. jack_time_t wait_last;
  134. jack_time_t wait_next;
  135. int wait_late;
  136. jack_client_t *client;
  137. int xrun_detected;
  138. int xrun_count;
  139. int process_count;
  140. /* settings from the command line */
  141. ffado_jack_settings_t settings;
  142. /* the firewire virtual device */
  143. ffado_device_t *dev;
  144. ffado_sample_t *nullbuffer;
  145. ffado_sample_t *scratchbuffer;
  146. JSList *capture_ports;
  147. JSList *playback_ports;
  148. JSList *monitor_ports;
  149. channel_t playback_nchannels;
  150. channel_t capture_nchannels;
  151. ffado_playback_channel_t *playback_channels;
  152. ffado_capture_channel_t *capture_channels;
  153. jack_nframes_t playback_frame_latency;
  154. jack_nframes_t capture_frame_latency;
  155. ffado_device_info_t device_info;
  156. ffado_options_t device_options;
  157. };
  158. #endif /* __JACK_FFADO_DRIVER_H__ */