root/trunk/libfreebob/src/libfreebobstreaming/freebob_streaming_private.h

Revision 185, 6.5 kB (checked in by wagi, 18 years ago)

CVS-SVN migration developer public sync patch

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  *   FreeBob Streaming API
3  *   FreeBob = Firewire (pro-)audio for linux
4  *
5  *   http://freebob.sf.net
6  *
7  *   Copyright (C) 2005 Pieter Palmers <pieterpalmers@users.sourceforge.net>
8  *
9  *   This program is free software; you can redistribute it and/or modify
10  *   it under the terms of the GNU General Public License as published by
11  *   the Free Software Foundation; either version 2 of the License, or
12  *   (at your option) any later version.
13  *
14  *   This program is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with this program; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  *
24  *
25  */
26
27 /* freebob_streaming_private.h
28  *
29  * Private stuff related to the freebob streaming API
30  *
31  */
32  
33 #ifndef __FREEBOB_STREAMING_PRIVATE_H__
34 #define __FREEBOB_STREAMING_PRIVATE_H__
35
36 #ifndef DEBUG
37 //#define DEBUG
38 #endif
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 #define AMDTP_MAX_PACKET_SIZE 2048
44
45 #define IEC61883_STREAM_TYPE_MIDI   0x0D
46 #define IEC61883_STREAM_TYPE_SPDIF  0x00
47 #define IEC61883_STREAM_TYPE_MBLA   0x06
48
49 #define IEC61883_AM824_LABEL_MASK                       0xFF000000
50 #define IEC61883_AM824_GET_LABEL(x)             (((x) & 0xFF000000) >> 24)
51 #define IEC61883_AM824_SET_LABEL(x,y)           ((x) | ((y)<<24))
52
53 #define IEC61883_AM824_LABEL_MIDI_NO_DATA       0x80
54 #define IEC61883_AM824_LABEL_MIDI_1X            0x81
55 #define IEC61883_AM824_LABEL_MIDI_2X            0x82
56 #define IEC61883_AM824_LABEL_MIDI_3X            0x83
57
58 #define SAMPLE_MAX_24BIT  8388608.0f
59
60 #include <libfreebob/freebob.h>
61 #include <libraw1394/raw1394.h>
62 #include <libiec61883/iec61883.h>
63 #include <pthread.h>
64 #include <linux/types.h>
65 #include <string.h>
66 #include <stdlib.h>
67 #include <errno.h>
68 #include <stdio.h>
69 #include <poll.h>
70 #include <sys/time.h>
71 #include <netinet/in.h>
72 #include <endian.h>
73
74 #include <pthread.h>
75 #include <semaphore.h>
76
77 #include <assert.h>
78
79 #include "ringbuffer.h"
80 #include "freebob_connections.h"
81
82 #define FALSE 0
83 #define TRUE 1
84
85 /*
86 #define DBC_MASK 0xFF
87 #define DBC_SHIFT 16
88
89 #define FREEBOB_STREAMING_EXTRACT_DBC(xx) ((xx & (DBC_MASK << DBC_SHIFT))>>DBC_SHIFT)
90 #define FREEBOB_STREAMING_REMOVE_DBC(xx) (xx & ~(DBC_MASK << DBC_SHIFT))
91 #define FREEBOB_STREAMING_INSERT_DBC(xx,yy) (yy | (((yy%8) & DBC_MASK) << DBC_SHIFT))
92 */
93
94 /**
95  * Structure to keep track of the packetizer thread status
96  */
97  
98 typedef struct _freebob_packetizer_status freebob_packetizer_status_t;
99 struct _freebob_packetizer_status {
100         sem_t transfer_boundary;
101         sem_t transfer_ack;
102         int retval;
103         int status;
104         int run;
105        
106         int realtime;
107         int priority;
108        
109         pthread_t transfer_thread;
110
111 };
112
113 /**
114  * Device structure
115  */
116
117 struct _freebob_device
118 {       
119
120         freebob_device_info_t device_info;
121         freebob_handle_t fb_handle;
122        
123         freebob_options_t options;
124
125         int xrun_detected;
126         int xrun_count;
127        
128         /* packet transfer thread */
129         freebob_packetizer_status_t packetizer;
130
131         /* watchdog thread */
132         int watchdog_check;
133         pthread_t watchdog_thread;
134        
135         /* ISO connections */
136         freebob_connection_t *sync_master_connection;
137        
138         int nb_connections;
139         int nb_connections_playback;
140         int nb_connections_capture;
141         freebob_connection_t *connections;
142        
143         int nb_capture_streams;
144         freebob_stream_t **capture_streams;
145         int nb_playback_streams;
146         freebob_stream_t **playback_streams;
147        
148         /*
149          * Sync'ed streams are streams that count when determining the period boundary
150          *
151          */
152         int nb_synced_capture_streams;
153         freebob_stream_t **synced_capture_streams;
154         int nb_synced_playback_streams;
155         freebob_stream_t **synced_playback_streams;
156
157         /*
158          * the fd map for polling
159          */
160         int                  nfds;
161         struct pollfd        *pfds;
162         freebob_connection_t **fdmap;
163        
164 };
165
166
167 int freebob_streaming_prefill_playback_streams(freebob_device_t *dev);
168
169 int freebob_streaming_stop_iso(freebob_device_t *dev);
170 int freebob_streaming_start_iso(freebob_device_t *dev);
171
172 int freebob_streaming_set_stream_buffer(freebob_device_t *dev,  freebob_stream_t *dst, char *b, freebob_streaming_buffer_type t);
173 void freebob_streaming_free_stream_buffer(freebob_device_t* dev, freebob_stream_t *dst);
174
175 /**
176  * Registers the stream in the stream list
177  */
178 void freebob_streaming_register_capture_stream(freebob_device_t *dev, freebob_stream_t *stream);
179 void freebob_streaming_register_playback_stream(freebob_device_t *dev, freebob_stream_t *stream);
180
181 /**
182  * Thread related
183  */
184                            
185 int freebob_streaming_start_thread(freebob_device_t *dev);
186 int freebob_streaming_stop_thread(freebob_device_t *dev);
187                            
188 void * freebob_iso_packet_iterator(void *arg);
189
190 void *freebob_streaming_watchdog_thread (void *arg);
191 int freebob_streaming_start_watchdog (freebob_device_t *dev);
192 void freebob_streaming_stop_watchdog (freebob_device_t *dev);
193
194 void freebob_streaming_print_bufferfill(freebob_device_t *dev);
195
196
197 /**
198  * freebob_encode_stream_to_events
199  *
200  * Encodes events from a buffer to AM824 events, according to a specific stream specification.
201  *     
202  * This will read nsamples samples from the stream ringbuffer, and encode them into events conform
203  * the stream specification.
204  *
205  * NOTE: the buffer has to be big enough
206  *
207  *  connection    : The connection the stream belongs to
208  *      stream        : Contains the stream structure
209  *  events        : Pointer to a buffer that will hold the encoded events
210  *  nsamples      : The number of samples to encode
211  *  dbc           : Data Block Counter, needed for mux of midi streams
212  */
213 /* are static inline now
214 int
215 freebob_encode_stream_to_events(freebob_connection_t *connection,
216                                                                 freebob_stream_t *stream,
217                                                                 quadlet_t* events,
218                                                                 unsigned int nsamples,
219                                                                 unsigned int dbc
220                                                                 );
221 */
222 /**
223  * freebob_decode_events_to_stream
224  *
225  * Decodes events from a buffer of AM824 events, to samples of the correct type in a stream structure.
226  * Skips events marked as empty.
227  *     
228  * This will decode nframes at maximum.
229  *
230  *  connection    : The connection the stream belongs to
231  *      stream        : Contains the stream structure
232  *  events        : Pointer to a buffer that holds the encoded events
233  *  nsamples      : The number of samples available
234  *  dbc           : Data Block Counter, needed for demux of midi streams
235  */
236 /* are static inline now
237
238 int
239 freebob_decode_events_to_stream(freebob_connection_t *connection,
240                                                                 freebob_stream_t *stream,
241                                                                 quadlet_t* events,
242                                                                 unsigned int nsamples,
243                                                                 unsigned int dbc
244                                                                 );
245 */
246
247 #ifdef __cplusplus
248 }
249 #endif
250
251 #endif
Note: See TracBrowser for help on using the browser.