~ubuntu-branches/ubuntu/trusty/jack-audio-connection-kit/trusty

« back to all changes in this revision

Viewing changes to drivers/firewire/ffado_driver.h

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-12-06 11:05:15 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20081206110515-xa9v9pajr9jqvfvg
Tags: 0.115.6-1ubuntu1
* Merge from Debian unstable, remaining Ubuntu changes:
  - Redirect stderr in bash completion (Debian #504488).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   FireWire Backend for Jack
 
3
 *   using FFADO
 
4
 *   FFADO = Firewire (pro-)audio for linux
 
5
 *
 
6
 *   http://www.ffado.org
 
7
 *   http://www.jackaudio.org
 
8
 *
 
9
 *   Copyright (C) 2005-2007 Pieter Palmers
 
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_FFADO_DRIVER_H__
 
32
#define __JACK_FFADO_DRIVER_H__
 
33
 
 
34
#include <assert.h>
 
35
 
 
36
#include <libffado/ffado.h>
 
37
 
 
38
#include <string.h>
 
39
#include <stdlib.h>
 
40
#include <errno.h>
 
41
#include <stdio.h>
 
42
#include <poll.h>
 
43
#include <sys/time.h>
 
44
#include <netinet/in.h>
 
45
#include <endian.h>
 
46
 
 
47
#include <pthread.h>
 
48
#include <semaphore.h>
 
49
 
 
50
#include <jack/driver.h>
 
51
#include <jack/engine.h>
 
52
#include <jack/types.h>
 
53
#include <jack/internal.h>
 
54
#include <jack/types.h>
 
55
#include <jack/ringbuffer.h>
 
56
#include <jack/thread.h>
 
57
 
 
58
#include <../alsa-midi/midi_pack.h>
 
59
#include <../alsa-midi/midi_unpack.h>
 
60
 
 
61
// debug print control flags
 
62
#define DEBUG_LEVEL_BUFFERS             (1<<0)
 
63
#define DEBUG_LEVEL_HANDLERS                    (1<<1)
 
64
#define DEBUG_LEVEL_XRUN_RECOVERY       (1<<2)
 
65
#define DEBUG_LEVEL_WAIT                        (1<<3)
 
66
 
 
67
#define DEBUG_LEVEL_RUN_CYCLE           (1<<8)
 
68
 
 
69
#define DEBUG_LEVEL_PACKETCOUNTER               (1<<16)
 
70
#define DEBUG_LEVEL_STARTUP                             (1<<17)
 
71
#define DEBUG_LEVEL_THREADS                             (1<<18)
 
72
 
 
73
//#define DEBUG_ENABLED
 
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( "firewire MSG: %s:%d (%s): " format,  __FILE__, __LINE__, __FUNCTION__, ##args )
 
83
        #define printError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format,  __FILE__, __LINE__, __FUNCTION__, ##args )
 
84
        
 
85
        #define printEnter() jack_error( "FWDRV ENTERS: %s (%s)\n", __FUNCTION__,  __FILE__)
 
86
        #define printExit() jack_error( "FWDRV EXITS: %s (%s)\n", __FUNCTION__,  __FILE__)
 
87
        #define printEnter() 
 
88
        #define printExit() 
 
89
        
 
90
        #define debugError(format, args...) jack_error( "firewire 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("firewire MSG: " format, ##args )
 
100
        #define printError(format, args...)   jack_error("firewire 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
typedef struct _ffado_driver ffado_driver_t;
 
112
 
 
113
/*
 
114
 * Jack Driver command line parameters
 
115
 */
 
116
 
 
117
typedef struct _ffado_jack_settings ffado_jack_settings_t;
 
118
struct _ffado_jack_settings {
 
119
    int verbose_level;
 
120
 
 
121
    int period_size_set;
 
122
    jack_nframes_t period_size;
 
123
    
 
124
    int sample_rate_set;
 
125
    int sample_rate;
 
126
    
 
127
    int buffer_size_set;
 
128
    jack_nframes_t buffer_size;
 
129
 
 
130
    int playback_ports;
 
131
    int capture_ports;
 
132
    
 
133
    jack_nframes_t capture_frame_latency;
 
134
    jack_nframes_t playback_frame_latency;
 
135
    
 
136
    int slave_mode;
 
137
    int snoop_mode;
 
138
    
 
139
    char *device_info;
 
140
};
 
141
 
 
142
typedef struct _ffado_capture_channel
 
143
{
 
144
        ffado_streaming_stream_type stream_type;
 
145
        midi_unpack_t midi_unpack;
 
146
        uint32_t *midi_buffer;
 
147
} ffado_capture_channel_t;
 
148
 
 
149
#define MIDI_OVERFLOW_BUFFER_SIZE 4
 
150
typedef struct _ffado_playback_channel
 
151
{
 
152
        ffado_streaming_stream_type stream_type;
 
153
        midi_pack_t midi_pack;
 
154
        uint32_t *midi_buffer;
 
155
        // to hold the midi bytes that couldn't be transferred
 
156
        // during the previous period
 
157
        char overflow_buffer[MIDI_OVERFLOW_BUFFER_SIZE];
 
158
        unsigned int nb_overflow_bytes;
 
159
} ffado_playback_channel_t;
 
160
 
 
161
/*
 
162
 * JACK driver structure
 
163
 */
 
164
struct _ffado_driver
 
165
{
 
166
        JACK_DRIVER_NT_DECL;
 
167
        
 
168
        jack_nframes_t  sample_rate;
 
169
        jack_nframes_t  period_size;
 
170
        unsigned long   wait_time;
 
171
 
 
172
    jack_time_t                   wait_last;
 
173
    jack_time_t                   wait_next;
 
174
        int wait_late;
 
175
        
 
176
        jack_client_t  *client;
 
177
        
 
178
        int             xrun_detected;
 
179
        int             xrun_count;
 
180
        
 
181
        int process_count;
 
182
        
 
183
        /* settings from the command line */
 
184
        ffado_jack_settings_t settings;
 
185
        
 
186
        /* the firewire virtual device */
 
187
        ffado_device_t *dev;
 
188
 
 
189
        ffado_sample_t *nullbuffer;
 
190
        ffado_sample_t *scratchbuffer;
 
191
 
 
192
    JSList                       *capture_ports;
 
193
    JSList                       *playback_ports;
 
194
    JSList                       *monitor_ports;
 
195
    channel_t                     playback_nchannels;
 
196
    channel_t                     capture_nchannels;
 
197
 
 
198
        ffado_playback_channel_t *playback_channels;
 
199
        ffado_capture_channel_t  *capture_channels;
 
200
 
 
201
        jack_nframes_t  playback_frame_latency;
 
202
        jack_nframes_t  capture_frame_latency;
 
203
        
 
204
        ffado_device_info_t device_info;
 
205
        ffado_options_t device_options;
 
206
 
 
207
}; 
 
208
 
 
209
 
 
210
 
 
211
#endif /* __JACK_FFADO_DRIVER_H__ */
 
212
 
 
213