root/branches/streaming-rework/support/jack/freebob_driver.h

Revision 424, 6.4 kB (checked in by pieterpalmers, 15 years ago)

- The library can now be started in 'slave mode', creating a BounceSlaveDevice?.

On a discovering node, this slave device is discovered as a BounceDevice?.
Streaming does not work yet, something wrong with the timestamps.

- Implemented the 'snoop mode', that allows a client to 'snoop' the streams

between another host and a device. It is only implemented for BeBoB devices.
The channel numbers and stream configuration are automatically detected.
Note that it currently relies on a rather hackish support for reading the
{i,o}PCR plugs by using private functions of libiec61883

- changed jack backend to support these two new features

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     int slave_mode;
158     int snoop_mode;
159    
160     freebob_handle_t fb_handle;
161 };
162
163 #ifdef FREEBOB_DRIVER_WITH_MIDI
164
165
166 typedef struct {
167         int stream_nr;
168         int seq_port_nr;
169         snd_midi_event_t *parser;
170         snd_seq_t *seq_handle;
171 } freebob_midi_port_t;
172
173 typedef struct _freebob_driver_midi_handle {
174         freebob_device_t *dev;
175         freebob_driver_t *driver;
176
177         snd_seq_t *seq_handle;
178        
179         pthread_t queue_thread;
180         pthread_t dequeue_thread;
181         int queue_thread_realtime;
182         int queue_thread_priority;
183
184         int nb_input_ports;
185         int nb_output_ports;
186
187         freebob_midi_port_t **input_ports;
188         freebob_midi_port_t **output_ports;
189
190         freebob_midi_port_t **input_stream_port_map;
191         int *output_port_stream_map;
192
193
194 } freebob_driver_midi_handle_t;
195
196 #endif
197 /*
198  * JACK driver structure
199  */
200  
201
202 struct _freebob_driver
203 {
204         JACK_DRIVER_NT_DECL
205        
206         jack_nframes_t  sample_rate;
207         jack_nframes_t  period_size;
208         unsigned long   wait_time;
209
210     jack_time_t                   wait_last;
211     jack_time_t                   wait_next;
212         int wait_late;
213        
214         jack_client_t  *client;
215        
216         int             xrun_detected;
217         int             xrun_count;
218        
219         int process_count;
220        
221         /* settings from the command line */
222         freebob_jack_settings_t settings;
223        
224         /* the freebob virtual device */
225         freebob_device_t *dev;
226        
227     JSList                       *capture_ports;
228     JSList                       *playback_ports;
229     JSList                       *monitor_ports;
230     channel_t                     playback_nchannels;
231     channel_t                     capture_nchannels;
232        
233         freebob_device_info_t device_info;
234         freebob_options_t device_options;
235
236 #ifdef FREEBOB_DRIVER_WITH_MIDI
237         freebob_driver_midi_handle_t *midi_handle;
238 #endif
239
240 };
241
242
243
244 #endif /* __JACK_FREEBOB_DRIVER_H__ */
245
246
Note: See TracBrowser for help on using the browser.