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

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