root/tags/2.0-rc1/libffado/ffado.h

Revision 1371, 15.7 kB (checked in by ppalmers, 4 years ago)

* implement our own code to do FCP transactions. the code from libavc had too much side-effects.
* remove libavc1394 as a dependency
* set the SPLIT_TIMEOUT value for the host controller such that late responses by the DM1x00 based devices are not discarded. Should fix the issues with FA-101 discovery. (re:
#155, #162)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* ffado.h
2  *
3  * Copyright (C) 2005-2008 by Pieter Palmers
4  * Copyright (C) 2005-2008 by Daniel Wagner
5  *
6  * This file is part of FFADO
7  * FFADO = Free Firewire (pro-)audio drivers for linux
8  *
9  * FFADO is based upon FreeBoB
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) version 3 of the License.
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, see <http://www.gnu.org/licenses/>.
23  *
24  */
25
26 #ifndef FFADO_H
27 #define FFADO_H
28
29 #define FFADO_MAX_NAME_LEN 256
30
31 #include <stdlib.h>
32
33 #define FFADO_STREAMING_MAX_URL_LENGTH 2048
34
35 #define FFADO_IGNORE_CAPTURE         (1<<0)
36 #define FFADO_IGNORE_PLAYBACK     (1<<1)
37
38 enum ffado_direction {
39     FFADO_CAPTURE  = 0,
40     FFADO_PLAYBACK = 1,
41 };
42
43 typedef struct ffado_handle* ffado_handle_t;
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 /* ABI stuff */
50 const char*
51 ffado_get_version();
52
53 int
54 ffado_get_api_version();
55
56 /* various function */
57
58 /* The basic operation of the API is as follows:
59  *
60  * ffado_streaming_init()
61  * ffado_streaming_start()
62  * while(running) {
63  *   retval = ffado_streaming_wait();
64  *   if (retval == -1) {
65  *     ffado_streaming_reset();
66  *     continue;
67  *   }
68  *
69  *   ffado_streaming_transfer_buffers(dev);
70  *
71  *   for(all channels) {
72  *     switch (channel_type) {
73  *     case audio:
74  *       bytesread=ffado_streaming_read(audioinbuffer[channel]);
75  *       byteswritten=ffado_streaming_write(audiooutbuffer[channel]);
76  *     case midi:
77  *       bytesread=ffado_streaming_read(midiinbuffer[channel]);
78  *       byteswritten=ffado_streaming_write(midioutbuffer[channel]);
79  *     }
80  *   }
81  * }
82  * ffado_streaming_stop();
83  * ffado_streaming_finish();
84  *
85  */
86
87 typedef struct _ffado_device ffado_device_t;
88
89 /**
90  * The sample format used by the ffado streaming API
91  */
92
93 typedef unsigned int ffado_sample_t; // FIXME
94 typedef unsigned int ffado_nframes_t;
95
96 #define FFADO_MAX_SPECSTRING_LENGTH 256
97 #define FFADO_MAX_SPECSTRINGS       64
98 /**
99  * This struct serves to define the devices that should be used by the library
100  * device_spec_strings is an array of pointers that should contain nb_device_spec_strings
101  * valid pointers to strings.
102  *
103  * The spec strings should be null terminated and can be no longer
104  * than FFADO_MAX_SPECSTRINGS.
105  *
106  * nb_device_spec_strings < FFADO_MAX_SPECSTRING_LENGTH
107  * nb_device_spec_strings >= 0
108  *
109  * If nb_device_spec_strings == 0, all busses are scanned for attached devices, and
110  * all found devices that are supported are combined into one large pseudo-device. The
111  * device order is defined by the GUID of the device. Devices with lower GUID's will
112  * be the first ones.
113  *
114  * If multiple device specifications are present, the device order is defined as follows:
115  *  - device(s) that correspond to a spec string with a lower index will be added before
116  *    devices from higher indexes.
117  *  - if a spec string results in multiple devices, they are sorted by GUID unless the
118  *    spec format dictates otherwise.
119  *
120  * The actual meaning of the device specification should be one of the following:
121  * - Format 1: "hw:x[,y[,z]]"
122  *     x = the firewire bus to use ('port' in raw1394 terminology)
123  *         (mandatory)
124  *     y = the node id the device currently has (bus resets might change that, but FFADO
125  *         will track these changes and keep using the device specified on startup)
126  *         (optional)
127  *     z = the stream direction to use.
128  *           0 => capture (record) channels only
129  *           1 => playback channels only
130  *           other/unspecified => both playback and capture
131  *         (optional)
132  *
133  * - Format 2: the device alias as defined in the ffado config file (UNIMPLEMENTED)
134  */
135 typedef struct ffado_device_info {
136     unsigned int nb_device_spec_strings;
137     char **device_spec_strings;
138
139     /* add some extra space to allow for future API extention
140        w/o breaking binary compatibility */
141     int32_t reserved[32];
142 } ffado_device_info_t;
143
144 /**
145  * Structure to pass the options to the ffado streaming code.
146  */
147 typedef struct ffado_options {
148     /* driver related setup */
149     int32_t sample_rate;         /*
150                              * you can specify a value here or -1 to autodetect
151                               */
152
153     /* buffer setup */
154     int32_t period_size;     /* one period is the amount of frames that
155                  * has to be sent or received in order for
156                  * a period boundary to be signalled.
157                  * (unit: frames)
158                  */
159     int32_t nb_buffers;    /* the size of the frame buffer (in periods) */
160
161     /* packetizer thread options */
162     int32_t realtime;
163     int32_t packetizer_priority;
164
165     /* verbosity */
166     int32_t verbose;
167
168     /* slave mode */
169     int32_t slave_mode;
170     /* snoop mode */
171     int32_t snoop_mode;
172
173     /* add some extra space to allow for future API extention
174        w/o breaking binary compatibility */
175     int32_t reserved[24];
176
177 } ffado_options_t;
178
179 /**
180  * The types of streams supported by the API
181  *
182  * A ffado_audio type stream is a stream that consists of successive samples.
183  * The format is a 24bit UINT in host byte order, aligned as the 24LSB's of the
184  * 32bit UINT of the read/write buffer.
185  * The wait operation looks at this type of streams only.
186  *
187  * A ffado_midi type stream is a stream of midi bytes. The bytes are 8bit UINT,
188  * aligned as the first 8LSB's of the 32bit UINT of the read/write buffer.
189  *
190  * A ffado_control type stream is a stream that provides control information. The
191  * format of this control information is undefined, and the stream should be ignored.
192  *
193  */
194 typedef enum {
195       ffado_stream_type_invalid                      =   -1,
196       ffado_stream_type_unknown                      =   0,
197       ffado_stream_type_audio                        =   1,
198       ffado_stream_type_midi                         =   2,
199       ffado_stream_type_control                      =   3,
200 } ffado_streaming_stream_type;
201
202 /**
203  *
204  * Audio data types known to the API
205  *
206  */
207 typedef enum {
208     ffado_audio_datatype_error           = -1,
209     ffado_audio_datatype_int24           =  0,
210     ffado_audio_datatype_float           =  1,
211 } ffado_streaming_audio_datatype;
212
213 /**
214  *
215  * Wait responses
216  *
217  */
218 typedef enum {
219     ffado_wait_shutdown        = -3,
220     ffado_wait_error           = -2,
221     ffado_wait_xrun            = -1,
222     ffado_wait_ok              =  0,
223 } ffado_wait_response;
224
225 /**
226  * Initializes the streaming from/to a FFADO device. A FFADO device
227  * is a virtual device composed of several BeBoB or compatible devices,
228  * linked together in one sync domain.
229  *
230  * This prepares all IEEE1394 related stuff and sets up all buffering.
231  * It elects a sync master if nescessary.
232  *
233  * @param device_info provides a way to specify the virtual device
234  * @param options options regarding buffers, ieee1394 setup, ...
235  *
236  * @return Opaque device handle if successful.  If this is NULL, the
237  * init operation failed.
238  *
239  */
240 ffado_device_t *ffado_streaming_init(
241                      ffado_device_info_t device_info,
242                      ffado_options_t options);
243
244 /**
245  * preparation should be done after setting all per-stream parameters
246  * the way you want them. being buffer data type etc...
247  *
248  * @param dev the ffado device
249  * @return
250  */
251 int ffado_streaming_prepare(ffado_device_t *dev);
252
253
254 /**
255  * Finishes the FFADO streaming. Cleans up all internal data structures
256  * and terminates connections.
257  *
258  * @param dev the ffado device to be closed.
259  */
260 void ffado_streaming_finish(ffado_device_t *dev);
261
262 /**
263  * Returns the amount of capture channels available
264  *
265  * @param dev the ffado device
266  *
267  * @return the number of capture streams present & active on the device.
268  *         can be 0. returns -1 upon error.
269  */
270 int ffado_streaming_get_nb_capture_streams(ffado_device_t *dev);
271
272 /**
273  * Returns the amount of playack channels available
274  *
275  * @param dev the ffado device
276  *
277  * @return the number of playback streams present & active on the device.
278  *         can be 0. returns -1 upon error.
279  */
280 int ffado_streaming_get_nb_playback_streams(ffado_device_t *dev);
281
282 /**
283  * Copies the capture channel name into the specified buffer
284  *
285  * @param dev the ffado device
286  * @param number the stream number
287  * @param buffer the buffer to copy the name into. has to be allocated.
288  * @param buffersize the size of the buffer
289  *
290  * @return the number of characters copied into the buffer
291  */
292 int ffado_streaming_get_capture_stream_name(ffado_device_t *dev, int number, char* buffer, size_t buffersize);
293
294 /**
295  * Copies the playback channel name into the specified buffer
296  *
297  * @param dev the ffado device
298  * @param number the stream number
299  * @param buffer the buffer to copy the name into. has to be allocated.
300  * @param buffersize the size of the buffer
301  *
302  * @return the number of characters copied into the buffer
303  */
304 int ffado_streaming_get_playback_stream_name(ffado_device_t *dev, int number, char* buffer, size_t buffersize);
305
306 /**
307  * Returns the type of a capture channel
308  *
309  * @param dev the ffado device
310  * @param number the stream number
311  *
312  * @return the channel type
313  */
314 ffado_streaming_stream_type ffado_streaming_get_capture_stream_type(ffado_device_t *dev, int number);
315
316 /**
317  * Returns the type of a playback channel
318  *
319  * @param dev the ffado device
320  * @param number the stream number
321  *
322  * @return the channel type
323  */
324 ffado_streaming_stream_type ffado_streaming_get_playback_stream_type(ffado_device_t *dev, int number);
325 /*
326  *
327  * Note: buffer handling will change in order to allow setting the sample type for *_read and *_write
328  * and separately indicate if you want to use a user buffer or a managed buffer.
329  *
330  */
331
332 /**
333  * Sets the decode buffer for the stream. This allows for zero-copy decoding.
334  * The call to ffado_streaming_transfer_buffers will decode one period of the stream to
335  * this buffer. Make sure it is large enough.
336  *
337  * @param dev the ffado device
338  * @param number the stream number
339  * @param buff a pointer to the sample buffer, make sure it is large enough
340  *             i.e. sizeof(your_sample_type)*period_size
341  * @param t   the type of the buffer. this determines sample type and the decode function used.
342  *
343  * @return -1 on error, 0 on success
344  */
345
346 int ffado_streaming_set_capture_stream_buffer(ffado_device_t *dev, int number, char *buff);
347 int ffado_streaming_capture_stream_onoff(ffado_device_t *dev, int number, int on);
348
349 /**
350  * Sets the encode buffer for the stream. This allows for zero-copy encoding (directly to the events).
351  * The call to ffado_streaming_transfer_buffers will encode one period of the stream from
352  * this buffer to the event buffer.
353  *
354  * @param dev the ffado device
355  * @param number the stream number
356  * @param buff a pointer to the sample buffer
357  * @param t   the type of the buffer. this determines sample type and the decode function used.
358  *
359  * @return -1 on error, 0 on success
360  */
361 int ffado_streaming_set_playback_stream_buffer(ffado_device_t *dev, int number, char *buff);
362 int ffado_streaming_playback_stream_onoff(ffado_device_t *dev, int number, int on);
363
364 ffado_streaming_audio_datatype ffado_streaming_get_audio_datatype(ffado_device_t *dev);
365 int ffado_streaming_set_audio_datatype(ffado_device_t *dev, ffado_streaming_audio_datatype t);
366
367 /**
368  * preparation should be done after setting all per-stream parameters
369  * the way you want them. being buffer data type etc...
370  *
371  * @param dev
372  * @return
373  */
374  
375 int ffado_streaming_prepare(ffado_device_t *dev);
376
377 /**
378  * Starts the streaming operation. This initiates the connections to the FFADO devices and
379  * starts the packet handling thread(s). This has to be called before any I/O can occur.
380  *
381  * @param dev the ffado device
382  *
383  * @return 0 on success, -1 on failure.
384  */
385 int ffado_streaming_start(ffado_device_t *dev);
386
387 /**
388  * Stops the streaming operation. This closes the connections to the FFADO devices and
389  * stops the packet handling thread(s).
390  *
391  * @param dev the ffado device
392  *
393  * @return 0 on success, -1 on failure.
394  */
395 int ffado_streaming_stop(ffado_device_t *dev);
396
397 /**
398  * Resets the streaming as if it was stopped and restarted. The difference is that the connections
399  * are not nescessarily broken and restored.
400  *
401  * All buffers are reset in the initial state and all data in them is lost.
402  *
403  * @param dev the ffado device
404  *
405  * @return 0 on success, -1 on failure.
406  */
407 int ffado_streaming_reset(ffado_device_t *dev);
408
409 /**
410  * Waits until there is at least one period of data available on all capture connections and
411  * room for one period of data on all playback connections
412  *
413  * @param dev the ffado device
414  *
415  * @return The number of frames ready. -1 when a problem occurred.
416  */
417 ffado_wait_response ffado_streaming_wait(ffado_device_t *dev);
418
419 /**
420  * Transfer & decode the events from the packet buffer to the sample buffers
421  *
422  * This should be called after the wait call returns, before reading/writing the sample buffers
423  * with ffado_streaming_[read|write].
424  *
425  * The purpose is to allow more precise timing information. ffado_streaming_wait returns as soon as the
426  * period boundary is crossed, and can therefore be used to determine the time instant of this crossing (e.g. jack DLL).
427  *
428  * The actual decoding work is done in this function and can therefore be omitted in this timing calculation.
429  * Note that you HAVE to call this function in order for the buffers not to overflow, and only call it when
430  * ffado_streaming_wait doesn't indicate a buffer xrun (xrun handler resets buffer).
431  *
432  * If user supplied playback buffers are specified with ffado_streaming_set_playback_buffers
433  * their contents should be valid before calling this function.
434  * If user supplied capture buffers are specified with ffado_streaming_set_capture_buffers
435  * their contents are updated in this function.
436  *
437  * Use either ffado_streaming_transfer_buffers to transfer all buffers at once, or use
438  * ffado_streaming_transfer_playback_buffers and ffado_streaming_transfer_capture_buffers
439  * to have more control. Don't use both.
440  *
441  * @param dev the ffado device
442  * @return  -1 on error.
443  */
444  
445 int ffado_streaming_transfer_buffers(ffado_device_t *dev);
446
447 /**
448  * Transfer & encode the events from the sample buffers to the packet buffer
449  *
450  * This should be called after the wait call returns, after writing the sample buffers
451  * with ffado_streaming_write.
452  *
453  * If user supplied playback buffers are specified with ffado_streaming_set_playback_buffers
454  * their contents should be valid before calling this function.
455  *
456  * Use either ffado_streaming_transfer_buffers to transfer all buffers at once, or use
457  * ffado_streaming_transfer_playback_buffers and ffado_streaming_transfer_capture_buffers
458  * to have more control. Don't use both.
459  *
460  * @param dev the ffado device
461  * @return  -1 on error.
462  */
463  
464 int ffado_streaming_transfer_playback_buffers(ffado_device_t *dev);
465
466 /**
467  * Transfer & decode the events from the packet buffer to the sample buffers
468  *
469  * This should be called after the wait call returns, before reading the sample buffers
470  * with ffado_streaming_read.
471  *
472  * If user supplied capture buffers are specified with ffado_streaming_set_capture_buffers
473  * their contents are updated in this function.
474  *
475  * Use either ffado_streaming_transfer_buffers to transfer all buffers at once, or use
476  * ffado_streaming_transfer_playback_buffers and ffado_streaming_transfer_capture_buffers
477  * to have more control. Don't use both.
478  *
479  * @param dev the ffado device
480  * @return  -1 on error.
481  */
482
483 int ffado_streaming_transfer_capture_buffers(ffado_device_t *dev);
484
485 #ifdef __cplusplus
486 }
487 #endif
488
489 #endif /* FFADO_STREAMING */
Note: See TracBrowser for help on using the browser.