Jack2 1.9.8
|
00001 /* freebob_driver.h 00002 * 00003 * FreeBob Backend for Jack 00004 * FreeBob = Firewire (pro-)audio for linux 00005 * 00006 * adapted for jackmp 00007 * 00008 * http://freebob.sf.net 00009 * http://jackit.sf.net 00010 * 00011 * Copyright (C) 2005,2006,2007 Pieter Palmers <pieterpalmers@users.sourceforge.net> 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU General Public License as published by 00015 * the Free Software Foundation; either version 2 of the License, or 00016 * (at your option) any later version. 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with this program; if not, write to the Free Software 00025 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00026 */ 00027 00028 /* 00029 * Main Jack driver entry routines 00030 * 00031 */ 00032 00033 #ifndef __JACK_FREEBOB_DRIVER_H__ 00034 #define __JACK_FREEBOB_DRIVER_H__ 00035 00036 // #define FREEBOB_DRIVER_WITH_MIDI 00037 // #define DEBUG_ENABLED 00038 00039 #include <libfreebob/freebob.h> 00040 #include <libfreebob/freebob_streaming.h> 00041 00042 #include <string.h> 00043 #include <stdlib.h> 00044 #include <errno.h> 00045 #include <stdio.h> 00046 #include <poll.h> 00047 #include <sys/time.h> 00048 #include <netinet/in.h> 00049 #include <endian.h> 00050 00051 #include <pthread.h> 00052 #include <semaphore.h> 00053 00054 #include <driver.h> 00055 #include <types.h> 00056 00057 #ifdef FREEBOB_DRIVER_WITH_MIDI 00058 #include <JackPosixThread.h> 00059 #include <alsa/asoundlib.h> 00060 #endif 00061 00062 // debug print control flags 00063 #define DEBUG_LEVEL_BUFFERS (1<<0) 00064 #define DEBUG_LEVEL_HANDLERS (1<<1) 00065 #define DEBUG_LEVEL_XRUN_RECOVERY (1<<2) 00066 #define DEBUG_LEVEL_WAIT (1<<3) 00067 00068 #define DEBUG_LEVEL_RUN_CYCLE (1<<8) 00069 00070 #define DEBUG_LEVEL_PACKETCOUNTER (1<<16) 00071 #define DEBUG_LEVEL_STARTUP (1<<17) 00072 #define DEBUG_LEVEL_THREADS (1<<18) 00073 00074 #ifdef DEBUG_ENABLED 00075 00076 // default debug level 00077 #define DEBUG_LEVEL ( DEBUG_LEVEL_RUN_CYCLE | \ 00078 (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER) 00079 00080 #warning Building debug build! 00081 00082 #define printMessage(format, args...) jack_error( "FreeBoB MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) 00083 #define printError(format, args...) jack_error( "FreeBoB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) 00084 00085 /* #define printEnter() jack_error( "FBDRV ENTERS: %s (%s)", __FUNCTION__, __FILE__) 00086 #define printExit() jack_error( "FBDRV EXITS: %s (%s)", __FUNCTION__, __FILE__)*/ 00087 #define printEnter() 00088 #define printExit() 00089 00090 #define debugError(format, args...) jack_error( "FREEBOB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) 00091 #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ##args ); 00092 #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( format,##args ); 00093 #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: "format, debugGetCurrentUTime(),##args ); 00094 #define SEGFAULT int *test=NULL; *test=1; 00095 #else 00096 #define DEBUG_LEVEL 00097 00098 #define printMessage(format, args...) if(g_verbose) \ 00099 jack_error("FreeBoB MSG: " format, ##args ) 00100 #define printError(format, args...) jack_error("FreeBoB ERR: " format, ##args ) 00101 00102 #define printEnter() 00103 #define printExit() 00104 00105 #define debugError(format, args...) 00106 #define debugPrint(Level, format, args...) 00107 #define debugPrintShort(Level, format, args...) 00108 #define debugPrintWithTimeStamp(Level, format, args...) 00109 #endif 00110 00111 // thread priority setup 00112 #define FREEBOB_RT_PRIORITY_PACKETIZER_RELATIVE 5 00113 00114 #ifdef FREEBOB_DRIVER_WITH_MIDI 00115 00116 #define ALSA_SEQ_BUFF_SIZE 1024 00117 #define MIDI_TRANSMIT_BUFFER_SIZE 1024 00118 #define MIDI_THREAD_SLEEP_TIME_USECS 100 00119 // midi priority should be higher than the audio priority in order to 00120 // make sure events are not only delivered on period boundarys 00121 // but I think it should be smaller than the packetizer thread in order not 00122 // to lose any packets 00123 #define FREEBOB_RT_PRIORITY_MIDI_RELATIVE 4 00124 00125 #endif 00126 00127 typedef struct _freebob_driver freebob_driver_t; 00128 00129 /* 00130 * Jack Driver command line parameters 00131 */ 00132 00133 typedef struct _freebob_jack_settings freebob_jack_settings_t; 00134 struct _freebob_jack_settings 00135 { 00136 int period_size_set; 00137 jack_nframes_t period_size; 00138 00139 int sample_rate_set; 00140 int sample_rate; 00141 00142 int buffer_size_set; 00143 jack_nframes_t buffer_size; 00144 00145 int port_set; 00146 int port; 00147 00148 int node_id_set; 00149 int node_id; 00150 00151 int playback_ports; 00152 int capture_ports; 00153 00154 jack_nframes_t capture_frame_latency; 00155 jack_nframes_t playback_frame_latency; 00156 00157 freebob_handle_t fb_handle; 00158 }; 00159 00160 #ifdef FREEBOB_DRIVER_WITH_MIDI 00161 00162 typedef struct 00163 { 00164 int stream_nr; 00165 int seq_port_nr; 00166 snd_midi_event_t *parser; 00167 snd_seq_t *seq_handle; 00168 } 00169 freebob_midi_port_t; 00170 00171 typedef struct _freebob_driver_midi_handle 00172 { 00173 freebob_device_t *dev; 00174 freebob_driver_t *driver; 00175 00176 snd_seq_t *seq_handle; 00177 00178 pthread_t queue_thread; 00179 pthread_t dequeue_thread; 00180 int queue_thread_realtime; 00181 int queue_thread_priority; 00182 00183 int nb_input_ports; 00184 int nb_output_ports; 00185 00186 freebob_midi_port_t **input_ports; 00187 freebob_midi_port_t **output_ports; 00188 00189 freebob_midi_port_t **input_stream_port_map; 00190 int *output_port_stream_map; 00191 } 00192 freebob_driver_midi_handle_t; 00193 00194 #endif 00195 /* 00196 * JACK driver structure 00197 */ 00198 00199 struct _freebob_driver 00200 { 00201 JACK_DRIVER_NT_DECL 00202 00203 jack_nframes_t sample_rate; 00204 jack_nframes_t period_size; 00205 unsigned long wait_time; 00206 00207 jack_time_t wait_last; 00208 jack_time_t wait_next; 00209 int wait_late; 00210 00211 jack_client_t *client; 00212 00213 int xrun_detected; 00214 int xrun_count; 00215 00216 int process_count; 00217 00218 /* settings from the command line */ 00219 freebob_jack_settings_t settings; 00220 00221 /* the freebob virtual device */ 00222 freebob_device_t *dev; 00223 00224 JSList *capture_ports; 00225 JSList *playback_ports; 00226 JSList *monitor_ports; 00227 unsigned long playback_nchannels; 00228 unsigned long capture_nchannels; 00229 unsigned long playback_nchannels_audio; 00230 unsigned long capture_nchannels_audio; 00231 00232 jack_nframes_t playback_frame_latency; 00233 jack_nframes_t capture_frame_latency; 00234 00235 freebob_device_info_t device_info; 00236 freebob_options_t device_options; 00237 00238 #ifdef FREEBOB_DRIVER_WITH_MIDI 00239 freebob_driver_midi_handle_t *midi_handle; 00240 #endif 00241 }; 00242 00243 #endif /* __JACK_FREEBOB_DRIVER_H__ */ 00244 00245