root/branches/libfreebob-2.0/support/jack/freebob_driver.h

Revision 247, 6.3 kB (checked in by pieterpalmers, 16 years ago)

- added a modified jackd backend for version 2.0

Line 
1 /* freebob_driver.h
2  *
3  *   FreeBob Backend for Jack
4  *   FreeBob = Firewire (pro-)audio for linux
5  *
6  *   http://freebob.sf.net
7  *   http://jackit.sf.net
8  *
9  *   Copyright (C) 2005 Pieter Palmers <pieterpalmers@users.sourceforge.net>
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 /*
27  * Main Jack driver entry routines
28  *
29  */
30  
31 #ifndef __JACK_FREEBOB_DRIVER_H__
32 #define __JACK_FREEBOB_DRIVER_H__
33
34 #define FREEBOB_DRIVER_WITH_MIDI
35
36 #include <libfreebob/freebob.h>
37 #include <libfreebob/freebob_streaming.h>
38
39 #include <jack/driver.h>
40 #include <jack/engine.h>
41 #include <jack/types.h>
42
43 #include <string.h>
44 #include <stdlib.h>
45 #include <errno.h>
46 #include <stdio.h>
47 #include <poll.h>
48 #include <sys/time.h>
49 #include <netinet/in.h>
50 #include <endian.h>
51
52 #include <pthread.h>
53 #include <semaphore.h>
54
55 #include <jack/internal.h>
56 #include <jack/types.h>
57 #include <jack/ringbuffer.h>
58 #include <jack/driver.h>
59 #include <jack/engine.h>
60 #include <jack/types.h>
61 #include <jack/thread.h>
62
63 #include <alsa/asoundlib.h>
64
65 // debug print control flags
66 #define DEBUG_LEVEL_BUFFERS             (1<<0)
67 #define DEBUG_LEVEL_HANDLERS                    (1<<1)
68 #define DEBUG_LEVEL_XRUN_RECOVERY       (1<<2)
69 #define DEBUG_LEVEL_WAIT                        (1<<3)
70
71 #define DEBUG_LEVEL_RUN_CYCLE           (1<<8)
72
73 #define DEBUG_LEVEL_PACKETCOUNTER               (1<<16)
74 #define DEBUG_LEVEL_STARTUP                             (1<<17)
75 #define DEBUG_LEVEL_THREADS                             (1<<18)
76
77
78 #ifdef DEBUG_ENABLED
79
80         // default debug level
81         #define DEBUG_LEVEL (  DEBUG_LEVEL_RUN_CYCLE | \
82         (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER)
83
84         #warning Building debug build!
85
86         #define printMessage(format, args...) jack_error( "FreeBoB MSG: %s:%d (%s): " format,  __FILE__, __LINE__, __FUNCTION__, ##args )
87         #define printError(format, args...) jack_error( "FreeBoB ERR: %s:%d (%s): " format,  __FILE__, __LINE__, __FUNCTION__, ##args )
88        
89         //#define printEnter() jack_error( "FBDRV ENTERS: %s (%s)\n", __FUNCTION__,  __FILE__)
90         //#define printExit() jack_error( "FBDRV EXITS: %s (%s)\n", __FUNCTION__,  __FILE__)
91         #define printEnter()
92         #define printExit()
93        
94         #define debugError(format, args...) jack_error( "FREEBOB ERR: %s:%d (%s): " format,  __FILE__, __LINE__, __FUNCTION__, ##args )
95         #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level))  jack_error("DEBUG %s:%d (%s) :"  format, __FILE__, __LINE__, __FUNCTION__, ##args );
96         #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level))  jack_error( format,##args );
97         #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: "format, debugGetCurrentUTime(),##args );
98         #define SEGFAULT int *test=NULL;        *test=1;
99 #else
100         #define DEBUG_LEVEL
101        
102         #define printMessage(format, args...) if(g_verbose) \
103                                                  jack_error("FreeBoB MSG: " format, ##args )
104         #define printError(format, args...)   jack_error("FreeBoB ERR: " format, ##args )
105        
106         #define printEnter()
107         #define printExit()
108        
109         #define debugError(format, args...)
110         #define debugPrint(Level, format, args...)
111         #define debugPrintShort(Level, format, args...)
112         #define debugPrintWithTimeStamp(Level, format, args...)
113 #endif
114
115 // thread priority setup
116 #define FREEBOB_RT_PRIORITY_PACKETIZER_RELATIVE 5
117
118 #ifdef FREEBOB_DRIVER_WITH_MIDI
119
120         #define ALSA_SEQ_BUFF_SIZE 1024
121         #define MIDI_TRANSMIT_BUFFER_SIZE 1024
122         #define MIDI_THREAD_SLEEP_TIME_USECS 100
123         // midi priority should be higher than the audio priority in order to
124         // make sure events are not only delivered on period boundarys
125         // but I think it should be smaller than the packetizer thread in order not
126         // to lose any packets
127         #define FREEBOB_RT_PRIORITY_MIDI_RELATIVE       4
128
129 #endif
130
131 typedef struct _freebob_driver freebob_driver_t;
132
133 /*
134  * Jack Driver command line parameters
135  */
136
137 typedef struct _freebob_jack_settings freebob_jack_settings_t;
138 struct _freebob_jack_settings {
139         int period_size_set;
140         jack_nframes_t period_size;
141        
142         int sample_rate_set;
143         int sample_rate;
144        
145         int buffer_size_set;
146         jack_nframes_t buffer_size;
147
148         int port_set;
149         int port;
150        
151         int node_id_set;
152         int node_id;
153
154         int playback_ports;
155         int capture_ports;
156
157         freebob_handle_t fb_handle;
158 };
159
160 #ifdef FREEBOB_DRIVER_WITH_MIDI
161
162
163 typedef struct {
164         int stream_nr;
165         int seq_port_nr;
166         snd_midi_event_t *parser;
167         snd_seq_t *seq_handle;
168 } freebob_midi_port_t;
169
170 typedef struct _freebob_driver_midi_handle {
171         freebob_device_t *dev;
172         freebob_driver_t *driver;
173
174         snd_seq_t *seq_handle;
175        
176         pthread_t queue_thread;
177         pthread_t dequeue_thread;
178         int queue_thread_realtime;
179         int queue_thread_priority;
180
181         int nb_input_ports;
182         int nb_output_ports;
183
184         freebob_midi_port_t **input_ports;
185         freebob_midi_port_t **output_ports;
186
187         freebob_midi_port_t **input_stream_port_map;
188         int *output_port_stream_map;
189
190
191 } freebob_driver_midi_handle_t;
192
193 #endif
194 /*
195  * JACK driver structure
196  */
197  
198
199 struct _freebob_driver
200 {
201         JACK_DRIVER_NT_DECL
202        
203         jack_nframes_t  sample_rate;
204         jack_nframes_t  period_size;
205         unsigned long   wait_time;
206
207     jack_time_t                   wait_last;
208     jack_time_t                   wait_next;
209         int wait_late;
210        
211         jack_client_t  *client;
212        
213         int             xrun_detected;
214         int             xrun_count;
215        
216         int process_count;
217        
218         /* settings from the command line */
219         freebob_jack_settings_t settings;
220        
221         /* the freebob virtual device */
222         freebob_device_t *dev;
223        
224     JSList                       *capture_ports;
225     JSList                       *playback_ports;
226     JSList                       *monitor_ports;
227     channel_t                     playback_nchannels;
228     channel_t                     capture_nchannels;
229        
230         freebob_device_info_t device_info;
231         freebob_options_t device_options;
232
233 #ifdef FREEBOB_DRIVER_WITH_MIDI
234         freebob_driver_midi_handle_t *midi_handle;
235 #endif
236
237 };
238
239
240
241 #endif /* __JACK_FREEBOB_DRIVER_H__ */
242
243
Note: See TracBrowser for help on using the browser.