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

Revision 402, 5.3 kB (checked in by pieterpalmers, 17 years ago)

adapted the Motu SP to the new stream sync framework

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  *   Copyright (C) 2006 Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
11  *
12  *   This program is free software {} you can redistribute it and/or modify
13  *   it under the terms of the GNU General Public License as published by
14  *   the Free Software Foundation {} either version 2 of the License, or
15  *   (at your option) any later version.
16  *
17  *   This program is distributed in the hope that it will be useful,
18  *   but WITHOUT ANY WARRANTY {} without even the implied warranty of
19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *   GNU General Public License for more details.
21  *
22  *   You should have received a copy of the GNU General Public License
23  *   along with this program {} if not, write to the Free Software
24  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  *
26  *
27  *
28  */
29 #ifndef __FREEBOB_MOTUSTREAMPROCESSOR__
30 #define __FREEBOB_MOTUSTREAMPROCESSOR__
31 #include <assert.h>
32
33 #include "../debugmodule/debugmodule.h"
34 #include "StreamProcessor.h"
35
36 #include "../libutil/DelayLockedLoop.h"
37
38 #ifdef ENABLE_MOTU
39
40 namespace FreebobStreaming {
41
42 class MotuAudioPort;
43
44 /**
45  * This class implements the outgoing stream processing for
46  * motu devices
47  */
48 class MotuTransmitStreamProcessor
49     : public TransmitStreamProcessor
50 {
51 public:
52        
53         MotuTransmitStreamProcessor(int port, int framerate,
54                 unsigned int event_size);
55
56         virtual ~MotuTransmitStreamProcessor();
57
58         enum raw1394_iso_disposition
59                 getPacket(unsigned char *data, unsigned int *length,
60                       unsigned char *tag, unsigned char *sy,
61                       int cycle, unsigned int dropped, unsigned int max_length);
62
63         bool init();
64         bool reset();
65         bool prepare();
66
67         bool prepareForStop();
68         bool prepareForStart();
69        
70     bool prepareForEnable(uint64_t time_to_enable_at);
71    
72     bool putFrames(unsigned int nbframes, int64_t ts); ///< transfer the buffer contents from the client
73        
74         // These two are important to calculate the optimal ISO DMA buffers
75         // size.  An estimate will do.
76         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
77         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
78
79     int getMinimalSyncDelay();
80
81         void setVerboseLevel(int l);
82
83 protected:
84         /*
85          * An iso packet mostly consists of multiple events.  m_event_size
86          * is the size of a single 'event' in bytes.
87          */
88         unsigned int m_event_size;
89
90         // Keep track of transmission data block count
91         unsigned int m_tx_dbc;
92
93         // Used to keep track of the close-down zeroing of output data
94         signed int m_closedown_count;
95         signed int m_streaming_active;
96
97     bool prefill();
98    
99         bool transferSilence(unsigned int size);
100
101     bool processWriteBlock(char *data, unsigned int nevents, unsigned int offset);
102
103         bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
104        
105         int transmitSilenceBlock(char *data, unsigned int nevents,
106                           unsigned int offset);
107                          
108         int encodePortToMotuEvents(MotuAudioPort *p, quadlet_t *data,
109                 unsigned int offset, unsigned int nevents);
110         int encodeSilencePortToMotuEvents(MotuAudioPort *p, quadlet_t *data,
111                 unsigned int offset, unsigned int nevents);
112
113     DECLARE_DEBUG_MODULE;
114
115 };
116
117 /**
118  * This class implements the incoming stream processing for
119  * motu devices
120  */
121 class MotuReceiveStreamProcessor
122     : public ReceiveStreamProcessor
123 {
124
125 public:
126
127         MotuReceiveStreamProcessor(int port, int framerate, unsigned int event_size);
128         virtual ~MotuReceiveStreamProcessor();
129        
130         enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
131                       unsigned char channel, unsigned char tag, unsigned char sy,
132                           unsigned int cycle, unsigned int dropped);
133                          
134     bool getFrames(unsigned int nbframes); ///< transfer the buffer contents to the client
135        
136         bool init();
137         bool reset();
138         bool prepare();
139
140     // these two are important to calculate the optimal
141     // ISO DMA buffers size
142     // an estimate will do
143         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
144         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
145    
146     int getMinimalSyncDelay();
147
148         virtual void setVerboseLevel(int l);
149        
150         signed int setEventSize(unsigned int size);
151         unsigned int getEventSize(void);
152
153         virtual bool prepareForStop();
154         virtual bool prepareForStart();
155
156 protected:
157
158         bool processReadBlock(char *data, unsigned int nevents, unsigned int offset);
159        
160         bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
161         signed int decodeMotuEventsToPort(MotuAudioPort *p, quadlet_t *data, unsigned int offset, unsigned int nevents);
162
163         /*
164          * An iso packet mostly consists of multiple events.  m_event_size
165          * is the size of a single 'event' in bytes.
166          */
167         unsigned int m_event_size;
168
169         // Signifies a closedown is in progress, in which case incoming data
170         // is junked.
171         signed int m_closedown_active;
172        
173     uint64_t m_last_timestamp; /// last timestamp (in ticks)
174     uint64_t m_last_timestamp2; /// last timestamp (in ticks)
175     uint64_t m_last_timestamp_at_period_ticks;
176    
177     DECLARE_DEBUG_MODULE;
178
179 };
180
181 } // end of namespace FreebobStreaming
182
183 #endif /* ENABLE_MOTU */
184
185 #endif /* __FREEBOB_MOTUSTREAMPROCESSOR__ */
186
187
Note: See TracBrowser for help on using the browser.