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 * Copyright (C) 2009 Devin Anderson 11 * 12 * adapted for JackMP by Pieter Palmers 13 * 14 * This program is free software; you can redistribute it and/or modify 15 * it under the terms of the GNU General Public License as published by 16 * the Free Software Foundation; either version 2 of the License, or 17 * (at your option) any later version. 18 * 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License 25 * along with this program; if not, write to the Free Software 26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27 */ 28 29 /* 30 * Main Jack driver entry routines 31 * 32 */ 33 34 #ifndef __JACK_FFADO_DRIVER_H__ 35 #define __JACK_FFADO_DRIVER_H__ 36 37 #include <libffado/ffado.h> 38 39 #include <string.h> 40 #include <stdlib.h> 41 #include <errno.h> 42 #include <stdio.h> 43 #include <poll.h> 44 #include <sys/time.h> 45 #include <netinet/in.h> 46 #include <endian.h> 47 48 #include <pthread.h> 49 #include <semaphore.h> 50 51 #include <driver.h> 52 #include <types.h> 53 54 #include <assert.h> 55 //#include <jack/midiport.h> 56 57 // debug print control flags 58 #define DEBUG_LEVEL_BUFFERS (1<<0) 59 #define DEBUG_LEVEL_HANDLERS (1<<1) 60 #define DEBUG_LEVEL_XRUN_RECOVERY (1<<2) 61 #define DEBUG_LEVEL_WAIT (1<<3) 62 63 #define DEBUG_LEVEL_RUN_CYCLE (1<<8) 64 65 #define DEBUG_LEVEL_PACKETCOUNTER (1<<16) 66 #define DEBUG_LEVEL_STARTUP (1<<17) 67 #define DEBUG_LEVEL_THREADS (1<<18) 68 69 //#define DEBUG_ENABLED 70 #ifdef DEBUG_ENABLED 71 72 // default debug level 73 #define DEBUG_LEVEL ( DEBUG_LEVEL_RUN_CYCLE | \ 74 (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER) 75 76 #warning Building debug build! 77 78 #define printMessage(format, args...) jack_error( "firewire MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) 79 #define printError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) 80 81 #define printEnter() jack_error( "FWDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__) 82 #define printExit() jack_error( "FWDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__) 83 #define printEnter() 84 #define printExit() 85 86 #define debugError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) 87 #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ##args ); 88 #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( format,##args ); 89 #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: " format, debugGetCurrentUTime(), ##args ); 90 #define SEGFAULT int *test=NULL; *test=1; 91 #else 92 #define DEBUG_LEVEL 93 94 #define printMessage(format, args...) if(g_verbose) \ 95 jack_error("firewire MSG: " format, ##args ) 96 #define printError(format, args...) jack_error("firewire ERR: " format, ##args ) 97 98 #define printEnter() 99 #define printExit() 100 101 #define debugError(format, args...) 102 #define debugPrint(Level, format, args...) 103 #define debugPrintShort(Level, format, args...) 104 #define debugPrintWithTimeStamp(Level, format, args...) 105 #endif 106 107 // thread priority setup 108 #define FFADO_RT_PRIORITY_PACKETIZER_RELATIVE 5 109 110 typedef struct _ffado_driver ffado_driver_t; 111 112 /* 113 * Jack Driver command line parameters 114 */ 115 116 typedef struct _ffado_jack_settings ffado_jack_settings_t; 117 struct _ffado_jack_settings 118 { 119 int verbose_level; 120 121 int period_size_set; 122 jack_nframes_t period_size; 123 124 int sample_rate_set; 125 int sample_rate; 126 127 int buffer_size_set; 128 jack_nframes_t buffer_size; 129 130 int playback_ports; 131 int capture_ports; 132 133 jack_nframes_t capture_frame_latency; 134 jack_nframes_t playback_frame_latency; 135 136 int slave_mode; 137 int snoop_mode; 138 139 char *device_info; 140 }; 141 142 typedef struct _ffado_capture_channel 143 { 144 ffado_streaming_stream_type stream_type; 145 uint32_t *midi_buffer; 146 void *midi_input; 147 } 148 ffado_capture_channel_t; 149 150 typedef struct _ffado_playback_channel 151 { 152 ffado_streaming_stream_type stream_type; 153 uint32_t *midi_buffer; 154 void *midi_output; 155 } 156 ffado_playback_channel_t; 157 158 /* 159 * JACK driver structure 160 */ 161 struct _ffado_driver 162 { 163 JACK_DRIVER_NT_DECL; 164 165 jack_nframes_t sample_rate; 166 jack_nframes_t period_size; 167 unsigned long wait_time; 168 169 jack_time_t wait_last; 170 jack_time_t wait_next; 171 int wait_late; 172 173 jack_client_t *client; 174 175 int xrun_detected; 176 int xrun_count; 177 178 int process_count; 179 180 /* settings from the command line */ 181 ffado_jack_settings_t settings; 182 183 /* the firewire virtual device */ 184 ffado_device_t *dev; 185 186 channel_t playback_nchannels; 187 channel_t capture_nchannels; 188 189 ffado_playback_channel_t *playback_channels; 190 ffado_capture_channel_t *capture_channels; 191 ffado_sample_t *nullbuffer; 192 ffado_sample_t *scratchbuffer; 193 194 jack_nframes_t playback_frame_latency; 195 jack_nframes_t capture_frame_latency; 196 197 ffado_device_info_t device_info; 198 ffado_options_t device_options; 199 200 }; 201 202 #endif /* __JACK_FFADO_DRIVER_H__ */ 203 204 205