Jack2: freebob_driver.h Source File

Jack2 1.9.12

freebob_driver.h
1 /* freebob_driver.h
2 *
3 * FreeBob Backend for Jack
4 * FreeBob = Firewire (pro-)audio for linux
5 *
6 * adapted for jackmp
7 *
8 * http://freebob.sf.net
9 * http://jackit.sf.net
10 *
11 * Copyright (C) 2005,2006,2007 Pieter Palmers <pieterpalmers@users.sourceforge.net>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28 /*
29 * Main Jack driver entry routines
30 *
31 */
32
33 #ifndef __JACK_FREEBOB_DRIVER_H__
34 #define __JACK_FREEBOB_DRIVER_H__
35
36 // #define FREEBOB_DRIVER_WITH_MIDI
37 // #define DEBUG_ENABLED
38
39 #include <libfreebob/freebob.h>
40 #include <libfreebob/freebob_streaming.h>
41
42 #include <string.h>
43 #include <stdlib.h>
44 #include <errno.h>
45 #include <stdio.h>
46 #include <poll.h>
47 #include <sys/time.h>
48 #include <netinet/in.h>
49 #include <endian.h>
50
51 #include <pthread.h>
52 #include <semaphore.h>
53
54 #include <driver.h>
55 #include <types.h>
56
57 #ifdef FREEBOB_DRIVER_WITH_MIDI
58 #include <JackPosixThread.h>
59 #include <alsa/asoundlib.h>
60 #endif
61
62 // debug print control flags
63 #define DEBUG_LEVEL_BUFFERS (1<<0)
64 #define DEBUG_LEVEL_HANDLERS (1<<1)
65 #define DEBUG_LEVEL_XRUN_RECOVERY (1<<2)
66 #define DEBUG_LEVEL_WAIT (1<<3)
67
68 #define DEBUG_LEVEL_RUN_CYCLE (1<<8)
69
70 #define DEBUG_LEVEL_PACKETCOUNTER (1<<16)
71 #define DEBUG_LEVEL_STARTUP (1<<17)
72 #define DEBUG_LEVEL_THREADS (1<<18)
73
74 #ifdef DEBUG_ENABLED
75
76 // default debug level
77 #define DEBUG_LEVEL ( DEBUG_LEVEL_RUN_CYCLE | \
78 (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER)
79
80 #warning Building debug build!
81
82 #define printMessage(format, args...) jack_error( "FreeBoB MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
83 #define printError(format, args...) jack_error( "FreeBoB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
84
85 /* #define printEnter() jack_error( "FBDRV ENTERS: %s (%s)", __FUNCTION__, __FILE__)
86 #define printExit() jack_error( "FBDRV EXITS: %s (%s)", __FUNCTION__, __FILE__)*/
87 #define printEnter()
88 #define printExit()
89
90 #define debugError(format, args...) jack_error( "FREEBOB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
91 #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ##args );
92 #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( format,##args );
93 #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: "format, debugGetCurrentUTime(),##args );
94 #define SEGFAULT int *test=NULL; *test=1;
95 #else
96 #define DEBUG_LEVEL
97
98 #define printMessage(format, args...) if(g_verbose) \
99 jack_error("FreeBoB MSG: " format, ##args )
100 #define printError(format, args...) jack_error("FreeBoB ERR: " format, ##args )
101
102 #define printEnter()
103 #define printExit()
104
105 #define debugError(format, args...)
106 #define debugPrint(Level, format, args...)
107 #define debugPrintShort(Level, format, args...)
108 #define debugPrintWithTimeStamp(Level, format, args...)
109 #endif
110
111 // thread priority setup
112 #define FREEBOB_RT_PRIORITY_PACKETIZER_RELATIVE 5
113
114 #ifdef FREEBOB_DRIVER_WITH_MIDI
115
116 #define ALSA_SEQ_BUFF_SIZE 1024
117 #define MIDI_TRANSMIT_BUFFER_SIZE 1024
118 #define MIDI_THREAD_SLEEP_TIME_USECS 100
119 // midi priority should be higher than the audio priority in order to
120 // make sure events are not only delivered on period boundarys
121 // but I think it should be smaller than the packetizer thread in order not
122 // to lose any packets
123 #define FREEBOB_RT_PRIORITY_MIDI_RELATIVE 4
124
125 #endif
126
127 typedef struct _freebob_driver freebob_driver_t;
128
129 /*
130 * Jack Driver command line parameters
131 */
132
133 typedef struct _freebob_jack_settings freebob_jack_settings_t;
134 struct _freebob_jack_settings
135 {
136 int period_size_set;
137 jack_nframes_t period_size;
138
139 int sample_rate_set;
140 int sample_rate;
141
142 int buffer_size_set;
143 jack_nframes_t buffer_size;
144
145 int port_set;
146 int port;
147
148 int node_id_set;
149 int node_id;
150
151 int playback_ports;
152 int capture_ports;
153
154 jack_nframes_t capture_frame_latency;
155 jack_nframes_t playback_frame_latency;
156
157 freebob_handle_t fb_handle;
158 };
159
160 #ifdef FREEBOB_DRIVER_WITH_MIDI
161
162 typedef struct
163 {
164 int stream_nr;
165 int seq_port_nr;
166 snd_midi_event_t *parser;
167 snd_seq_t *seq_handle;
168 }
169 freebob_midi_port_t;
170
171 typedef struct _freebob_driver_midi_handle
172 {
173 freebob_device_t *dev;
174 freebob_driver_t *driver;
175
176 snd_seq_t *seq_handle;
177
178 pthread_t queue_thread;
179 pthread_t dequeue_thread;
180 int queue_thread_realtime;
181 int queue_thread_priority;
182
183 int nb_input_ports;
184 int nb_output_ports;
185
186 freebob_midi_port_t **input_ports;
187 freebob_midi_port_t **output_ports;
188
189 freebob_midi_port_t **input_stream_port_map;
190 int *output_port_stream_map;
191 }
192 freebob_driver_midi_handle_t;
193
194 #endif
195 /*
196 * JACK driver structure
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 unsigned long playback_nchannels;
228 unsigned long capture_nchannels;
229 unsigned long playback_nchannels_audio;
230 unsigned long capture_nchannels_audio;
231
232 jack_nframes_t playback_frame_latency;
233 jack_nframes_t capture_frame_latency;
234
235 freebob_device_info_t device_info;
236 freebob_options_t device_options;
237
238 #ifdef FREEBOB_DRIVER_WITH_MIDI
239 freebob_driver_midi_handle_t *midi_handle;
240 #endif
241 };
242
243 #endif /* __JACK_FREEBOB_DRIVER_H__ */
244
245
_freebob_jack_settings
Definition: freebob_driver.h:134
_freebob_driver
Definition: freebob_driver.h:199
_JSList
Definition: linux/alsa/jslist.h:35