root/branches/libfreebob-2.0/src/libstreaming/AmdtpStreamProcessor.h

Revision 266, 6.4 kB (checked in by pieterpalmers, 18 years ago)

- temporary commit

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 int m_last_timestamp;
144
145     unsigned int m_dbc;
146
147     DECLARE_DEBUG_MODULE;
148
149 };
150 /*!
151 \brief The Base Class for an AMDTP receive stream processor
152
153  This class implements a ReceiveStreamProcessor that demultiplexes
154  AMDTP streams into Ports.
155  
156 */
157 class AmdtpReceiveStreamProcessor
158         : public ReceiveStreamProcessor
159 {
160
161 public:
162     // FIXME: debug
163     friend class AmdtpTransmitStreamProcessor;
164
165         AmdtpReceiveStreamProcessor(int port, int framerate, int dimension);
166
167         virtual ~AmdtpReceiveStreamProcessor();
168
169         enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
170                       unsigned char channel, unsigned char tag, unsigned char sy,
171                           unsigned int cycle, unsigned int dropped);
172
173
174         bool init();
175         bool reset();
176         bool prepare();
177         bool transfer();
178
179         virtual void setVerboseLevel(int l);
180        
181         bool isOnePeriodReady();
182        
183     // We have 1 period of samples = m_period
184     // this period takes m_period/m_framerate seconds of time
185     // during this time, 8000 packets are sent
186 //      unsigned int getPacketsPerPeriod() {return (m_period*8000)/m_framerate;};
187    
188     // however, if we only count the number of used packets
189     // it is m_period / m_syt_interval
190         unsigned int getPacketsPerPeriod() {return (m_period)/m_syt_interval;};
191        
192         unsigned int getMaxPacketSize() {return 4 * (2 + m_syt_interval * m_dimension);};
193
194     float getTicksPerFrame() {return m_ticks_per_frame;};
195     unsigned int getPeriodTimeStamp() {return m_last_timestamp_at_period_ticks;};
196
197     void dumpInfo();
198    
199 protected:
200
201         int receiveBlock(char *data, unsigned int nevents, unsigned int offset);
202         bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
203        
204         int decodeMBLAEventsToPort(AmdtpAudioPort *, quadlet_t *data, unsigned int offset, unsigned int nevents);
205
206         freebob_ringbuffer_t * m_event_buffer;
207         char* m_cluster_buffer;
208         int m_dimension;
209         unsigned int m_syt_interval;
210    
211     unsigned int m_last_timestamp;
212     unsigned int m_last_timestamp2;
213     unsigned int m_last_timestamp_at_period_ticks;
214    
215     float m_ticks_per_frame;
216    
217     DECLARE_DEBUG_MODULE;
218
219 };
220
221
222 } // end of namespace FreebobStreaming
223
224 #endif /* __FREEBOB_AMDTPSTREAMPROCESSOR__ */
225
226
Note: See TracBrowser for help on using the browser.