root/branches/ppalmers-streaming/src/libstreaming/motu/MotuStreamProcessor.h

Revision 705, 5.4 kB (checked in by ppalmers, 15 years ago)

restructure the streaming directory

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
28 #include "../generic/StreamProcessor.h"
29
30 #include "libutil/DelayLockedLoop.h"
31 #include "debugmodule/debugmodule.h"
32
33 #include <assert.h>
34
35 namespace Streaming {
36
37 class MotuAudioPort;
38
39 /**
40  * This class implements the outgoing stream processing for
41  * motu devices
42  */
43 class MotuTransmitStreamProcessor
44     : public TransmitStreamProcessor
45 {
46 public:
47
48     MotuTransmitStreamProcessor(int port, int framerate,
49         unsigned int event_size);
50
51     virtual ~MotuTransmitStreamProcessor();
52
53     enum raw1394_iso_disposition
54         getPacket(unsigned char *data, unsigned int *length,
55                   unsigned char *tag, unsigned char *sy,
56                   int cycle, unsigned int dropped, unsigned int max_length);
57
58     bool init();
59     bool reset();
60     bool prepare();
61
62     bool prepareForStop();
63     bool prepareForStart();
64
65     bool prepareForEnable(uint64_t time_to_enable_at);
66
67     bool putFrames(unsigned int nbframes, int64_t ts); ///< transfer the buffer contents from the client
68
69     // These two are important to calculate the optimal ISO DMA buffers
70     // size.  An estimate will do.
71     unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
72     unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
73
74     int getMinimalSyncDelay();
75
76     void setVerboseLevel(int l);
77
78 protected:
79     /*
80      * An iso packet mostly consists of multiple events.  m_event_size
81      * is the size of a single 'event' in bytes.
82      */
83     unsigned int m_event_size;
84
85     // Keep track of transmission data block count
86     unsigned int m_tx_dbc;
87
88     // Used to zero output data during startup while sync is established
89     signed int m_startup_count;
90
91     // Used to keep track of the close-down zeroing of output data
92     signed int m_closedown_count;
93     signed int m_streaming_active;
94
95     bool prefill();
96
97     bool transferSilence(unsigned int size);
98
99     bool processWriteBlock(char *data, unsigned int nevents, unsigned int offset);
100
101     bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
102
103     int transmitSilenceBlock(char *data, unsigned int nevents,
104                       unsigned int offset);
105
106     int encodePortToMotuEvents(MotuAudioPort *p, quadlet_t *data,
107         unsigned int offset, unsigned int nevents);
108     int encodeSilencePortToMotuEvents(MotuAudioPort *p, quadlet_t *data,
109         unsigned int offset, unsigned int nevents);
110
111     DECLARE_DEBUG_MODULE;
112
113 };
114
115 /**
116  * This class implements the incoming stream processing for
117  * motu devices
118  */
119 class MotuReceiveStreamProcessor
120     : public ReceiveStreamProcessor
121 {
122
123 public:
124
125     MotuReceiveStreamProcessor(int port, int framerate, unsigned int event_size);
126     virtual ~MotuReceiveStreamProcessor();
127
128     enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
129                   unsigned char channel, unsigned char tag, unsigned char sy,
130                   unsigned int cycle, unsigned int dropped);
131
132     bool getFrames(unsigned int nbframes, int64_t ts); ///< transfer the buffer contents to the client
133
134     bool init();
135     bool reset();
136     bool prepare();
137
138     // these two are important to calculate the optimal
139     // ISO DMA buffers size
140     // an estimate will do
141     unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
142     unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
143
144     int getMinimalSyncDelay();
145
146     virtual void setVerboseLevel(int l);
147
148     signed int setEventSize(unsigned int size);
149     unsigned int getEventSize(void);
150
151     virtual bool prepareForStop();
152     virtual bool prepareForStart();
153
154 protected:
155
156     bool processReadBlock(char *data, unsigned int nevents, unsigned int offset);
157
158     bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
159     signed int decodeMotuEventsToPort(MotuAudioPort *p, quadlet_t *data, unsigned int offset, unsigned int nevents);
160
161     /*
162      * An iso packet mostly consists of multiple events.  m_event_size
163      * is the size of a single 'event' in bytes.
164      */
165     unsigned int m_event_size;
166
167     // Signifies a closedown is in progress, in which case incoming data
168         // is junked.
169         signed int m_closedown_active;
170
171     uint64_t m_last_timestamp; /// last timestamp (in ticks)
172     uint64_t m_last_timestamp2; /// last timestamp (in ticks)
173     uint64_t m_last_timestamp_at_period_ticks;
174
175     DECLARE_DEBUG_MODULE;
176
177 };
178
179 } // end of namespace Streaming
180
181 #endif /* __FFADO_MOTUSTREAMPROCESSOR__ */
182
183
Note: See TracBrowser for help on using the browser.