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

Revision 287, 5.4 kB (checked in by jwoithe, 18 years ago)

Some cleanups to the MotuStreamProcessor? source.
First pass at a stop preparation method (StreamProcessor::preparedToStop()).
Motu uses preparedToStop to write zero data to device before iso closedown.

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_MOTUSTREAMPROCESSOR__
29 #define __FREEBOB_MOTUSTREAMPROCESSOR__
30 #include <assert.h>
31
32 #include "../debugmodule/debugmodule.h"
33 #include "StreamProcessor.h"
34
35 #include "../libutil/DelayLockedLoop.h"
36
37 namespace FreebobStreaming {
38
39 class MotuAudioPort;
40
41 /**
42  * This class implements the outgoing stream processing for
43  * motu devices
44  */
45 class MotuTransmitStreamProcessor
46     : public TransmitStreamProcessor
47 {
48 public:
49        
50         MotuTransmitStreamProcessor(int port, int framerate,
51                 unsigned int event_size);
52
53         virtual ~MotuTransmitStreamProcessor();
54
55         enum raw1394_iso_disposition
56                 getPacket(unsigned char *data, unsigned int *length,
57                       unsigned char *tag, unsigned char *sy,
58                       int cycle, unsigned int dropped, unsigned int max_length);
59
60         bool init();
61         bool reset();
62         bool prepare();
63         bool transfer();
64        
65         bool isOnePeriodReady();
66
67         // These two are important to calculate the optimal ISO DMA buffers
68         // size.  An estimate will do.
69         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
70         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
71
72         virtual void setVerboseLevel(int l);
73
74         void set_sph_ofs_dll(FreebobUtil::DelayLockedLoop *dll) {m_sph_ofs_dll=dll;};
75
76         virtual bool preparedForStop();
77
78 protected:
79
80         freebob_ringbuffer_t * m_event_buffer;
81         char* m_tmp_event_buffer;
82        
83         /*
84          * An iso packet mostly consists of multiple events.  m_event_size
85          * is the size of a single 'event' in bytes.
86          */
87         unsigned int m_event_size;
88
89         // Keep track of transmission data block count
90         unsigned int m_tx_dbc;
91
92         // Transmission cycle count and cycle offset
93         signed int m_cycle_count;
94         float m_cycle_ofs;
95
96         // Hook to the DLL in the receive stream which allows calculation
97         // of cycle offsets to put into frame SPHs.  This object is
98         // owned by the receive stream, so the transmit stream should
99         // not dispose of it.
100         FreebobUtil::DelayLockedLoop *m_sph_ofs_dll;
101
102         // Used to keep track of the close-down zeroing of output data
103         signed int m_closedown_count;
104
105     bool prefill();
106    
107         bool transferSilence(unsigned int size);
108
109         int transmitBlock(char *data, unsigned int nevents,
110                           unsigned int offset);
111                          
112         bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
113        
114         int transmitSilenceBlock(char *data, unsigned int nevents,
115                           unsigned int offset);
116                          
117         int MotuTransmitStreamProcessor::encodePortToMBLAEvents(
118                 MotuAudioPort *p, quadlet_t *data, unsigned int offset,
119                 unsigned int nevents);
120         int MotuTransmitStreamProcessor::encodeSilencePortToMBLAEvents(
121                 MotuAudioPort *p, quadlet_t *data, unsigned int offset,
122                 unsigned int nevents);
123
124
125     DECLARE_DEBUG_MODULE;
126
127 };
128
129 /**
130  * This class implements the incoming stream processing for
131  * motu devices
132  */
133 class MotuReceiveStreamProcessor
134     : public ReceiveStreamProcessor
135 {
136
137 public:
138
139         MotuReceiveStreamProcessor(int port, int framerate, unsigned int event_size);
140         virtual ~MotuReceiveStreamProcessor();
141        
142         enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
143                       unsigned char channel, unsigned char tag, unsigned char sy,
144                           unsigned int cycle, unsigned int dropped);
145        
146         bool init();
147         bool reset();
148         bool prepare();
149         bool transfer();
150        
151         bool isOnePeriodReady();
152
153     // these two are important to calculate the optimal
154     // ISO DMA buffers size
155     // an estimate will do
156         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
157         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
158
159         virtual void setVerboseLevel(int l);
160        
161         FreebobUtil::DelayLockedLoop *get_sph_ofs_dll(void) {return m_sph_ofs_dll;};
162         signed int setEventSize(unsigned int size);
163         unsigned int getEventSize(void);
164
165 protected:
166
167         int receiveBlock(char *data, unsigned int nevents, unsigned int offset);
168         bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
169         signed int decodeMBLAEventsToPort(MotuAudioPort *p, quadlet_t *data, unsigned int offset, unsigned int nevents);
170
171         freebob_ringbuffer_t * m_event_buffer;
172         char* m_tmp_event_buffer;
173        
174         /*
175          * An iso packet mostly consists of multiple events.  m_event_size
176          * is the size of a single 'event' in bytes.
177          */
178         unsigned int m_event_size;
179
180         FreebobUtil::DelayLockedLoop *m_sph_ofs_dll;
181         signed int m_last_cycle_ofs;
182
183     DECLARE_DEBUG_MODULE;
184
185 };
186
187 } // end of namespace FreebobStreaming
188
189 #endif /* __FREEBOB_MOTUSTREAMPROCESSOR__ */
190
191
Note: See TracBrowser for help on using the browser.