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

Revision 244, 5.5 kB (checked in by pieterpalmers, 18 years ago)

- first try to implement the SYT synchronisation.

Not working yet.

- committing to spend some time to get the Motu people going.

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
62 /*!
63 \brief The Base Class for an AMDTP transmit stream processor
64
65  This class implements a TransmitStreamProcessor that multiplexes Ports
66  into AMDTP streams.
67  
68 */
69 class AmdtpTransmitStreamProcessor
70         : public TransmitStreamProcessor
71 {
72
73 public:
74
75         AmdtpTransmitStreamProcessor(int port, int framerate, int dimension);
76
77         virtual ~AmdtpTransmitStreamProcessor();
78
79         enum raw1394_iso_disposition
80                 getPacket(unsigned char *data, unsigned int *length,
81                       unsigned char *tag, unsigned char *sy,
82                       int cycle, unsigned int dropped, unsigned int max_length);
83
84         bool init();
85         bool reset();
86         bool prepare();
87         bool transfer();
88         virtual void setVerboseLevel(int l);
89        
90         bool isOnePeriodReady();
91
92     // We have 1 period of samples = m_period
93     // this period takes m_period/m_framerate seconds of time
94     // during this time, 8000 packets are sent
95 //      unsigned int getPacketsPerPeriod() {return (m_period*8000)/m_framerate;};
96    
97     // however, if we only count the number of used packets
98     // it is m_period / m_syt_interval
99         unsigned int getPacketsPerPeriod() {return (m_period)/m_syt_interval;};
100        
101         unsigned int getMaxPacketSize() {return 4 * (2 + m_syt_interval * m_dimension);};
102
103 protected:
104
105         struct iec61883_cip m_cip_status;
106
107         freebob_ringbuffer_t * m_event_buffer;
108         char* m_cluster_buffer;
109         int m_dimension;
110         unsigned int m_syt_interval;
111
112         int m_fdf;
113        
114     bool prefill();
115    
116         bool transferSilence(unsigned int size);
117
118         int transmitBlock(char *data, unsigned int nevents,
119                           unsigned int offset);
120                          
121         bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
122         int encodePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data,
123                                    unsigned int offset, unsigned int nevents);
124        
125         int transmitSilenceBlock(char *data, unsigned int nevents,
126                           unsigned int offset);
127         int encodeSilencePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data,
128                                    unsigned int offset, unsigned int nevents);
129
130     DECLARE_DEBUG_MODULE;
131
132 };
133 /*!
134 \brief The Base Class for an AMDTP receive stream processor
135
136  This class implements a ReceiveStreamProcessor that demultiplexes
137  AMDTP streams into Ports.
138  
139 */
140 class AmdtpReceiveStreamProcessor
141         : public ReceiveStreamProcessor
142 {
143
144 public:
145
146         AmdtpReceiveStreamProcessor(int port, int framerate, int dimension);
147
148         virtual ~AmdtpReceiveStreamProcessor();
149
150         enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
151                       unsigned char channel, unsigned char tag, unsigned char sy,
152                           unsigned int cycle, unsigned int dropped);
153
154
155         bool init();
156         bool reset();
157         bool prepare();
158         bool transfer();
159
160         virtual void setVerboseLevel(int l);
161        
162         bool isOnePeriodReady();
163        
164     // We have 1 period of samples = m_period
165     // this period takes m_period/m_framerate seconds of time
166     // during this time, 8000 packets are sent
167 //      unsigned int getPacketsPerPeriod() {return (m_period*8000)/m_framerate;};
168    
169     // however, if we only count the number of used packets
170     // it is m_period / m_syt_interval
171         unsigned int getPacketsPerPeriod() {return (m_period)/m_syt_interval;};
172        
173         unsigned int getMaxPacketSize() {return 4 * (2 + m_syt_interval * m_dimension);};
174
175 protected:
176
177         int receiveBlock(char *data, unsigned int nevents, unsigned int offset);
178         bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
179        
180         int decodeMBLAEventsToPort(AmdtpAudioPort *, quadlet_t *data, unsigned int offset, unsigned int nevents);
181
182         freebob_ringbuffer_t * m_event_buffer;
183         char* m_cluster_buffer;
184         int m_dimension;
185         unsigned int m_syt_interval;
186    
187     unsigned int m_last_timestamp;
188    
189     DECLARE_DEBUG_MODULE;
190
191 };
192
193
194 } // end of namespace FreebobStreaming
195
196 #endif /* __FREEBOB_AMDTPSTREAMPROCESSOR__ */
197
198
Note: See TracBrowser for help on using the browser.