Jack2  1.9.10
ffado_driver.h
00001 /*
00002  *   FireWire Backend for Jack
00003  *   using FFADO
00004  *   FFADO = Firewire (pro-)audio for linux
00005  *
00006  *   http://www.ffado.org
00007  *   http://www.jackaudio.org
00008  *
00009  *   Copyright (C) 2005-2007 Pieter Palmers
00010  *   Copyright (C) 2009 Devin Anderson
00011  *
00012  *   adapted for JackMP by Pieter Palmers
00013  *
00014  *   This program is free software; you can redistribute it and/or modify
00015  *   it under the terms of the GNU General Public License as published by
00016  *   the Free Software Foundation; either version 2 of the License, or
00017  *   (at your option) any later version.
00018  *
00019  *   This program is distributed in the hope that it will be useful,
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *   GNU General Public License for more details.
00023  *
00024  *   You should have received a copy of the GNU General Public License
00025  *   along with this program; if not, write to the Free Software
00026  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027  */
00028 
00029 /*
00030  * Main Jack driver entry routines
00031  *
00032  */
00033 
00034 #ifndef __JACK_FFADO_DRIVER_H__
00035 #define __JACK_FFADO_DRIVER_H__
00036 
00037 #include <libffado/ffado.h>
00038 
00039 #include <string.h>
00040 #include <stdlib.h>
00041 #include <errno.h>
00042 #include <stdio.h>
00043 #include <poll.h>
00044 #include <sys/time.h>
00045 #include <netinet/in.h>
00046 #include <endian.h>
00047 
00048 #include <pthread.h>
00049 #include <semaphore.h>
00050 
00051 #include <driver.h>
00052 #include <types.h>
00053 
00054 #include <assert.h>
00055 //#include <jack/midiport.h>
00056 
00057 // debug print control flags
00058 #define DEBUG_LEVEL_BUFFERS             (1<<0)
00059 #define DEBUG_LEVEL_HANDLERS                    (1<<1)
00060 #define DEBUG_LEVEL_XRUN_RECOVERY       (1<<2)
00061 #define DEBUG_LEVEL_WAIT                        (1<<3)
00062 
00063 #define DEBUG_LEVEL_RUN_CYCLE           (1<<8)
00064 
00065 #define DEBUG_LEVEL_PACKETCOUNTER               (1<<16)
00066 #define DEBUG_LEVEL_STARTUP                             (1<<17)
00067 #define DEBUG_LEVEL_THREADS                             (1<<18)
00068 
00069 //#define DEBUG_ENABLED
00070 #ifdef DEBUG_ENABLED
00071 
00072 // default debug level
00073 #define DEBUG_LEVEL (  DEBUG_LEVEL_RUN_CYCLE | \
00074         (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER)
00075 
00076 #warning Building debug build!
00077 
00078 #define printMessage(format, args...) jack_error( "firewire MSG: %s:%d (%s): " format,  __FILE__, __LINE__, __FUNCTION__, ##args )
00079 #define printError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format,  __FILE__, __LINE__, __FUNCTION__, ##args )
00080 
00081 #define printEnter() jack_error( "FWDRV ENTERS: %s (%s)\n", __FUNCTION__,  __FILE__)
00082 #define printExit() jack_error( "FWDRV EXITS: %s (%s)\n", __FUNCTION__,  __FILE__)
00083 #define printEnter()
00084 #define printExit()
00085 
00086 #define debugError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format,  __FILE__, __LINE__, __FUNCTION__, ##args )
00087 #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level))  jack_error("DEBUG %s:%d (%s) :"  format, __FILE__, __LINE__, __FUNCTION__, ##args );
00088 #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level))  jack_error( format,##args );
00089 #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: "format, debugGetCurrentUTime(),##args );
00090 #define SEGFAULT int *test=NULL;        *test=1;
00091 #else
00092 #define DEBUG_LEVEL
00093 
00094 #define printMessage(format, args...) if(g_verbose) \
00095                                                  jack_error("firewire MSG: " format, ##args )
00096 #define printError(format, args...)   jack_error("firewire ERR: " format, ##args )
00097 
00098 #define printEnter()
00099 #define printExit()
00100 
00101 #define debugError(format, args...)
00102 #define debugPrint(Level, format, args...)
00103 #define debugPrintShort(Level, format, args...)
00104 #define debugPrintWithTimeStamp(Level, format, args...)
00105 #endif
00106 
00107 // thread priority setup
00108 #define FFADO_RT_PRIORITY_PACKETIZER_RELATIVE   5
00109 
00110 typedef struct _ffado_driver ffado_driver_t;
00111 
00112 /*
00113  * Jack Driver command line parameters
00114  */
00115 
00116 typedef struct _ffado_jack_settings ffado_jack_settings_t;
00117 struct _ffado_jack_settings
00118 {
00119     int verbose_level;
00120 
00121     int period_size_set;
00122     jack_nframes_t period_size;
00123 
00124     int sample_rate_set;
00125     int sample_rate;
00126 
00127     int buffer_size_set;
00128     jack_nframes_t buffer_size;
00129 
00130     int playback_ports;
00131     int capture_ports;
00132 
00133     jack_nframes_t capture_frame_latency;
00134     jack_nframes_t playback_frame_latency;
00135 
00136     int slave_mode;
00137     int snoop_mode;
00138 
00139     char *device_info;
00140 };
00141 
00142 typedef struct _ffado_capture_channel
00143 {
00144     ffado_streaming_stream_type stream_type;
00145     uint32_t *midi_buffer;
00146     void *midi_input;
00147 }
00148 ffado_capture_channel_t;
00149 
00150 typedef struct _ffado_playback_channel
00151 {
00152     ffado_streaming_stream_type stream_type;
00153     uint32_t *midi_buffer;
00154     void *midi_output;
00155 }
00156 ffado_playback_channel_t;
00157 
00158 /*
00159  * JACK driver structure
00160  */
00161 struct _ffado_driver
00162 {
00163     JACK_DRIVER_NT_DECL;
00164 
00165     jack_nframes_t  sample_rate;
00166     jack_nframes_t  period_size;
00167     unsigned long   wait_time;
00168 
00169     jack_time_t                   wait_last;
00170     jack_time_t                   wait_next;
00171     int wait_late;
00172 
00173     jack_client_t  *client;
00174 
00175     int         xrun_detected;
00176     int         xrun_count;
00177 
00178     int process_count;
00179 
00180     /* settings from the command line */
00181     ffado_jack_settings_t settings;
00182 
00183     /* the firewire virtual device */
00184     ffado_device_t *dev;
00185 
00186     channel_t                     playback_nchannels;
00187     channel_t                     capture_nchannels;
00188 
00189     ffado_playback_channel_t *playback_channels;
00190     ffado_capture_channel_t  *capture_channels;
00191     ffado_sample_t *nullbuffer;
00192     ffado_sample_t *scratchbuffer;
00193 
00194     jack_nframes_t  playback_frame_latency;
00195     jack_nframes_t  capture_frame_latency;
00196 
00197     ffado_device_info_t device_info;
00198     ffado_options_t device_options;
00199 
00200 };
00201 
00202 #endif /* __JACK_FFADO_DRIVER_H__ */
00203 
00204