root/branches/ppalmers-streaming/MotuStreamProcessor.h

Revision 512, 5.4 kB (checked in by jwoithe, 17 years ago)

MOTU: more tweaks to improve reliability. Things are looking pretty good now.
MOTU: Commenced cleanup of MOTU code, removing temporary debug output etc.

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