root/branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.h

Revision 404, 6.6 kB (checked in by pieterpalmers, 16 years ago)

- introduce support framework for DICE and Metric Halo
- change probe/discovery code to make adding devices easier
- made conditional compilation effectively work.

./configure now has the following switches:

--enable-bebob build BeBoB support (default=yes)
--enable-motu build Motu support (default=no)
--enable-dice build DICE support (default=no)
--enable-metric-halo build Metric Halo support (note: completely useless)

(default=no)

--enable-rme build RME support (note: completely useless)

(default=no)

--enable-bounce build Bounce device support (default=no)
--enable-all-devices build support for all supported devices (default=no)

these now turn on/off compilation effectively.

Line 
1 /* $Id$ */
2
3 /*
4  *   FreeBob Streaming API
5  *   FreeBob = Firewire (pro-)audio for linux
6  *
7  *   http://freebob.sf.net
8  *
9  *   Copyright (C) 2005,2006,2007 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  */
28 #ifdef ENABLE_BEBOB
29     #ifndef ENABLE_AMDTP_SP
30         #define ENABLE_AMDTP_SP
31     #endif
32 #endif
33
34 #ifdef ENABLE_DICE
35     #ifndef ENABLE_AMDTP_SP
36         #define ENABLE_AMDTP_SP
37     #endif
38 #endif
39
40 #ifdef ENABLE_BOUNCE
41     #ifndef ENABLE_AMDTP_SP
42         #define ENABLE_AMDTP_SP
43     #endif
44 #endif
45
46 #ifdef ENABLE_AMDTP_SP
47
48 #ifndef __FREEBOB_AMDTPSTREAMPROCESSOR__
49 #define __FREEBOB_AMDTPSTREAMPROCESSOR__
50
51 /**
52  * This class implements IEC61883-6 / AM824 / AMDTP based streaming
53  */
54
55 #include "../debugmodule/debugmodule.h"
56 #include "StreamProcessor.h"
57
58 #include "cip.h"
59 #include <libiec61883/iec61883.h>
60 #include <pthread.h>
61
62 #define AMDTP_MAX_PACKET_SIZE 2048
63
64 #define IEC61883_STREAM_TYPE_MIDI   0x0D
65 #define IEC61883_STREAM_TYPE_SPDIF  0x00
66 #define IEC61883_STREAM_TYPE_MBLA   0x06
67
68 #define IEC61883_AM824_LABEL_MASK                       0xFF000000
69 #define IEC61883_AM824_GET_LABEL(x)             (((x) & 0xFF000000) >> 24)
70 #define IEC61883_AM824_SET_LABEL(x,y)           ((x) | ((y)<<24))
71
72 #define IEC61883_AM824_LABEL_MIDI_NO_DATA       0x80
73 #define IEC61883_AM824_LABEL_MIDI_1X            0x81
74 #define IEC61883_AM824_LABEL_MIDI_2X            0x82
75 #define IEC61883_AM824_LABEL_MIDI_3X            0x83
76
77 namespace FreebobStreaming {
78
79 class Port;
80 class AmdtpAudioPort;
81 class AmdtpMidiPort;
82 class AmdtpReceiveStreamProcessor;
83
84 /*!
85 \brief The Base Class for an AMDTP transmit stream processor
86
87  This class implements a TransmitStreamProcessor that multiplexes Ports
88  into AMDTP streams.
89  
90 */
91 class AmdtpTransmitStreamProcessor
92         : public TransmitStreamProcessor
93 {
94
95 public:
96     AmdtpTransmitStreamProcessor(int port, int framerate, int dimension);
97
98     virtual ~AmdtpTransmitStreamProcessor();
99
100     enum raw1394_iso_disposition
101             getPacket(unsigned char *data, unsigned int *length,
102                     unsigned char *tag, unsigned char *sy,
103                     int cycle, unsigned int dropped, unsigned int max_length);
104
105     bool init();
106     bool reset();
107     bool prepare();
108    
109     bool prepareForStop();
110     bool prepareForStart();
111    
112     bool prepareForEnable(uint64_t time_to_enable_at);
113    
114     bool putFrames(unsigned int nbframes, int64_t ts); ///< transfer the buffer contents from the client
115
116     // We have 1 period of samples = m_period
117     // this period takes m_period/m_framerate seconds of time
118     // during this time, 8000 packets are sent
119 //      unsigned int getPacketsPerPeriod() {return (m_period*8000)/m_framerate;};
120    
121     // however, if we only count the number of used packets
122     // it is m_period / m_syt_interval
123     unsigned int getPacketsPerPeriod() {return (m_period)/m_syt_interval;};
124    
125     unsigned int getMaxPacketSize() {return 4 * (2 + m_syt_interval * m_dimension);};
126    
127     int getMinimalSyncDelay();
128    
129     void setVerboseLevel(int l);
130    
131 protected:
132     bool processWriteBlock(char *data, unsigned int nevents, unsigned int offset);
133
134     struct iec61883_cip m_cip_status;
135    
136     int m_dimension;
137     unsigned int m_syt_interval;
138
139     int m_fdf;
140    
141     bool prefill();
142    
143     bool transferSilence(unsigned int size);
144
145     int transmitBlock(char *data, unsigned int nevents,
146                         unsigned int offset);
147                        
148     bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
149     int encodePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data,
150                                 unsigned int offset, unsigned int nevents);
151    
152     int transmitSilenceBlock(char *data, unsigned int nevents,
153                         unsigned int offset);
154     int encodeSilencePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data,
155                                 unsigned int offset, unsigned int nevents);
156
157     unsigned long m_last_timestamp;
158
159     unsigned int m_dbc;
160    
161     unsigned int m_ringbuffer_size_frames;
162
163     DECLARE_DEBUG_MODULE;
164
165 };
166 /*!
167 \brief The Base Class for an AMDTP receive stream processor
168
169  This class implements a ReceiveStreamProcessor that demultiplexes
170  AMDTP streams into Ports.
171  
172 */
173 class AmdtpReceiveStreamProcessor
174         : public ReceiveStreamProcessor
175 {
176
177 public:
178         AmdtpReceiveStreamProcessor(int port, int framerate, int dimension);
179
180         virtual ~AmdtpReceiveStreamProcessor();
181
182         enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
183                       unsigned char channel, unsigned char tag, unsigned char sy,
184                           unsigned int cycle, unsigned int dropped);
185
186
187         bool init();
188         bool reset();
189         bool prepare();
190        
191     bool prepareForStop();
192     bool prepareForStart();
193        
194     bool getFrames(unsigned int nbframes); ///< transfer the buffer contents to the client
195
196     // We have 1 period of samples = m_period
197     // this period takes m_period/m_framerate seconds of time
198     // during this time, 8000 packets are sent
199 //      unsigned int getPacketsPerPeriod() {return (m_period*8000)/m_framerate;};
200    
201     // however, if we only count the number of used packets
202     // it is m_period / m_syt_interval
203         unsigned int getPacketsPerPeriod() {return (m_period)/m_syt_interval;};
204        
205         unsigned int getMaxPacketSize() {return 4 * (2 + m_syt_interval * m_dimension);};
206
207     void dumpInfo();
208    
209     int getMinimalSyncDelay();
210        
211     void setVerboseLevel(int l);
212            
213 protected:
214
215     bool processReadBlock(char *data, unsigned int nevents, unsigned int offset);
216
217     bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
218    
219     int decodeMBLAEventsToPort(AmdtpAudioPort *, quadlet_t *data, unsigned int offset, unsigned int nevents);
220
221     int m_dimension;
222     unsigned int m_syt_interval;
223    
224     uint64_t m_last_timestamp; /// last timestamp (in ticks)
225     uint64_t m_last_timestamp2; /// last timestamp (in ticks)
226     uint64_t m_last_timestamp_at_period_ticks;
227    
228     DECLARE_DEBUG_MODULE;
229
230 };
231
232
233 } // end of namespace FreebobStreaming
234
235 #endif /* __FREEBOB_AMDTPSTREAMPROCESSOR__ */
236
237 #endif // #ifdef ENABLE_AMDTP_SP
238
Note: See TracBrowser for help on using the browser.