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/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. {
  112. ffado_streaming_stream_type stream_type;
  113. midi_unpack_t midi_unpack;
  114. uint32_t *midi_buffer;
  115. } ffado_capture_channel_t;
  116. #define MIDI_OVERFLOW_BUFFER_SIZE 4
  117. typedef struct _ffado_playback_channel
  118. {
  119. ffado_streaming_stream_type stream_type;
  120. midi_pack_t midi_pack;
  121. uint32_t *midi_buffer;
  122. // to hold the midi bytes that couldn't be transferred
  123. // during the previous period
  124. char overflow_buffer[MIDI_OVERFLOW_BUFFER_SIZE];
  125. unsigned int nb_overflow_bytes;
  126. } ffado_playback_channel_t;
  127. /*
  128. * JACK driver structure
  129. */
  130. struct _ffado_driver
  131. {
  132. JACK_DRIVER_NT_DECL;
  133. jack_nframes_t sample_rate;
  134. jack_nframes_t period_size;
  135. unsigned long wait_time;
  136. jack_time_t wait_last;
  137. jack_time_t wait_next;
  138. int wait_late;
  139. jack_client_t *client;
  140. int xrun_detected;
  141. int xrun_count;
  142. int process_count;
  143. /* settings from the command line */
  144. ffado_jack_settings_t settings;
  145. /* the firewire virtual device */
  146. ffado_device_t *dev;
  147. ffado_sample_t *nullbuffer;
  148. ffado_sample_t *scratchbuffer;
  149. JSList *capture_ports;
  150. JSList *playback_ports;
  151. JSList *monitor_ports;
  152. channel_t playback_nchannels;
  153. channel_t capture_nchannels;
  154. ffado_playback_channel_t *playback_channels;
  155. ffado_capture_channel_t *capture_channels;
  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__ */