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

Revision 383, 6.5 kB (checked in by pieterpalmers, 16 years ago)

mostly whitespace fixes

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 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 #include "cip.h"
38 #include <libiec61883/iec61883.h>
39 #include "ringbuffer.h"
40
41 #define AMDTP_MAX_PACKET_SIZE 2048
42
43 #define IEC61883_STREAM_TYPE_MIDI   0x0D
44 #define IEC61883_STREAM_TYPE_SPDIF  0x00
45 #define IEC61883_STREAM_TYPE_MBLA   0x06
46
47 #define IEC61883_AM824_LABEL_MASK                       0xFF000000
48 #define IEC61883_AM824_GET_LABEL(x)             (((x) & 0xFF000000) >> 24)
49 #define IEC61883_AM824_SET_LABEL(x,y)           ((x) | ((y)<<24))
50
51 #define IEC61883_AM824_LABEL_MIDI_NO_DATA       0x80
52 #define IEC61883_AM824_LABEL_MIDI_1X            0x81
53 #define IEC61883_AM824_LABEL_MIDI_2X            0x82
54 #define IEC61883_AM824_LABEL_MIDI_3X            0x83
55
56 namespace FreebobStreaming {
57
58 class Port;
59 class AmdtpAudioPort;
60 class AmdtpMidiPort;
61 class AmdtpReceiveStreamProcessor;
62
63 /*!
64 \brief The Base Class for an AMDTP transmit stream processor
65
66  This class implements a TransmitStreamProcessor that multiplexes Ports
67  into AMDTP streams.
68  
69 */
70 class AmdtpTransmitStreamProcessor
71         : public TransmitStreamProcessor
72 {
73
74 public:
75     // FIXME: debug
76     friend class AmdtpReceiveStreamProcessor;
77    
78     AmdtpTransmitStreamProcessor(int port, int framerate, int dimension);
79
80     virtual ~AmdtpTransmitStreamProcessor();
81
82     enum raw1394_iso_disposition
83             getPacket(unsigned char *data, unsigned int *length,
84                     unsigned char *tag, unsigned char *sy,
85                     int cycle, unsigned int dropped, unsigned int max_length);
86
87     bool init();
88     bool reset();
89     bool prepare();
90     bool transfer();
91     virtual void setVerboseLevel(int l);
92    
93     bool isOnePeriodReady();
94
95     // We have 1 period of samples = m_period
96     // this period takes m_period/m_framerate seconds of time
97     // during this time, 8000 packets are sent
98 //      unsigned int getPacketsPerPeriod() {return (m_period*8000)/m_framerate;};
99    
100     // however, if we only count the number of used packets
101     // it is m_period / m_syt_interval
102     unsigned int getPacketsPerPeriod() {return (m_period)/m_syt_interval;};
103    
104     unsigned int getMaxPacketSize() {return 4 * (2 + m_syt_interval * m_dimension);};
105
106     // FIXME: do this the proper way!
107     AmdtpReceiveStreamProcessor *syncmaster;
108
109     // this updates the timestamp, and the
110     // 'bufferfill'
111     // should be called from the same thread
112     // that does the iteration
113     void decrementFrameCounter();
114         void incrementFrameCounter(int nbframes);
115    
116 protected:
117
118     struct iec61883_cip m_cip_status;
119
120     freebob_ringbuffer_t * m_event_buffer;
121     char* m_cluster_buffer;
122     int m_dimension;
123     unsigned int m_syt_interval;
124
125     int m_fdf;
126    
127     bool prefill();
128    
129     bool transferSilence(unsigned int size);
130
131     int transmitBlock(char *data, unsigned int nevents,
132                         unsigned int offset);
133                        
134     bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
135     int encodePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data,
136                                 unsigned int offset, unsigned int nevents);
137    
138     int transmitSilenceBlock(char *data, unsigned int nevents,
139                         unsigned int offset);
140     int encodeSilencePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data,
141                                 unsigned int offset, unsigned int nevents);
142
143     unsigned long m_last_timestamp;
144
145     unsigned int m_dbc;
146    
147     unsigned int m_ringbuffer_size_frames;
148
149     DECLARE_DEBUG_MODULE;
150
151 };
152 /*!
153 \brief The Base Class for an AMDTP receive stream processor
154
155  This class implements a ReceiveStreamProcessor that demultiplexes
156  AMDTP streams into Ports.
157  
158 */
159 class AmdtpReceiveStreamProcessor
160         : public ReceiveStreamProcessor
161 {
162
163 public:
164     // FIXME: debug
165     friend class AmdtpTransmitStreamProcessor;
166
167         AmdtpReceiveStreamProcessor(int port, int framerate, int dimension);
168
169         virtual ~AmdtpReceiveStreamProcessor();
170
171         enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
172                       unsigned char channel, unsigned char tag, unsigned char sy,
173                           unsigned int cycle, unsigned int dropped);
174
175
176         bool init();
177         bool reset();
178         bool prepare();
179         bool transfer();
180
181         virtual void setVerboseLevel(int l);
182        
183         bool isOnePeriodReady();
184        
185     // We have 1 period of samples = m_period
186     // this period takes m_period/m_framerate seconds of time
187     // during this time, 8000 packets are sent
188 //      unsigned int getPacketsPerPeriod() {return (m_period*8000)/m_framerate;};
189    
190     // however, if we only count the number of used packets
191     // it is m_period / m_syt_interval
192         unsigned int getPacketsPerPeriod() {return (m_period)/m_syt_interval;};
193        
194         unsigned int getMaxPacketSize() {return 4 * (2 + m_syt_interval * m_dimension);};
195
196     float getTicksPerFrame() {return m_ticks_per_frame;};
197     unsigned int getPeriodTimeStamp();
198    
199     void dumpInfo();
200    
201 protected:
202
203     int receiveBlock(char *data, unsigned int nevents, unsigned int offset);
204     bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
205    
206     int decodeMBLAEventsToPort(AmdtpAudioPort *, quadlet_t *data, unsigned int offset, unsigned int nevents);
207
208     freebob_ringbuffer_t * m_event_buffer;
209     char* m_cluster_buffer;
210     int m_dimension;
211     unsigned int m_syt_interval;
212    
213     unsigned int m_last_timestamp;
214     unsigned int m_last_timestamp2;
215     unsigned int m_last_timestamp_at_period_ticks;
216    
217     float m_ticks_per_frame;
218    
219     bool m_one_period_passed;
220    
221     DECLARE_DEBUG_MODULE;
222
223 };
224
225
226 } // end of namespace FreebobStreaming
227
228 #endif /* __FREEBOB_AMDTPSTREAMPROCESSOR__ */
229
230
Note: See TracBrowser for help on using the browser.