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

Revision 309, 5.7 kB (checked in by jwoithe, 16 years ago)

MOTU: Fixed false "missed rx cycle" report following xrun recovery.
Ensure iso rx/tx contexts are deallocated during shutdown/xrun recovery by explicitly deleting IsoHandlers? in IsoHandlerManager::pruneHandlers(). If they aren't deleted here they never get deleted because the reference is lost.
IsoHandler? destructor should only call stop() if the handle is valid.
IsoXmitHandler?'s destructor sets the handle NULL to prevent double-free by the inherited IsoHandler? destructor.
Don't call raw1394_iso_shutdown() from our code. libraw1394 1.2.1 has a bug whereby raw1394_new_handle() fails to initialise the iso_packet_infos field. The bug hits us particularly in IsoRecvHandler::prepare(). It's also not really necessary to call raw1394_iso_shutdown() since raw1394_destroy_handle() will do any cleanups we happen to need.
MOTU: the receive stream no longer falsely complains of buffer problems during device shutdown.
MOTU: fixed a false "missed cycle" detection immediately after the stream was enabled.

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 namespace FreebobStreaming {
39
40 class MotuAudioPort;
41
42 /**
43  * This class implements the outgoing stream processing for
44  * motu devices
45  */
46 class MotuTransmitStreamProcessor
47     : public TransmitStreamProcessor
48 {
49 public:
50        
51         MotuTransmitStreamProcessor(int port, int framerate,
52                 unsigned int event_size);
53
54         virtual ~MotuTransmitStreamProcessor();
55
56         enum raw1394_iso_disposition
57                 getPacket(unsigned char *data, unsigned int *length,
58                       unsigned char *tag, unsigned char *sy,
59                       int cycle, unsigned int dropped, unsigned int max_length);
60
61         bool init();
62         bool reset();
63         bool prepare();
64         bool transfer();
65        
66         bool isOnePeriodReady();
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         virtual void setVerboseLevel(int l);
74
75         void setTicksPerFrameDLL(float *dll) {m_ticks_per_frame=dll;};
76
77         virtual bool preparedForStop();
78
79 protected:
80
81         freebob_ringbuffer_t * m_event_buffer;
82         char* m_tmp_event_buffer;
83        
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         // Transmission cycle count and cycle offset
94         signed int m_cycle_count;
95         float m_cycle_ofs;
96
97         // Used to detect missed cycles
98         signed int m_next_cycle;
99
100         // Hook to the DLL in the receive stream which provides a
101         // continuously updated estimate of the number of ieee1394 ticks
102         // per audio frame.
103         float *m_ticks_per_frame;
104
105         // Used to keep track of the close-down zeroing of output data
106         signed int m_closedown_count;
107         signed int m_streaming_active;
108
109     bool prefill();
110    
111         bool transferSilence(unsigned int size);
112
113         int transmitBlock(char *data, unsigned int nevents,
114                           unsigned int offset);
115                          
116         bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
117        
118         int transmitSilenceBlock(char *data, unsigned int nevents,
119                           unsigned int offset);
120                          
121         int encodePortToMBLAEvents(MotuAudioPort *p, quadlet_t *data,
122                 unsigned int offset, unsigned int nevents);
123         int encodeSilencePortToMBLAEvents(MotuAudioPort *p, quadlet_t *data,
124                 unsigned int offset, unsigned int nevents);
125
126     DECLARE_DEBUG_MODULE;
127
128 };
129
130 /**
131  * This class implements the incoming stream processing for
132  * motu devices
133  */
134 class MotuReceiveStreamProcessor
135     : public ReceiveStreamProcessor
136 {
137
138 public:
139
140         MotuReceiveStreamProcessor(int port, int framerate, unsigned int event_size);
141         virtual ~MotuReceiveStreamProcessor();
142        
143         enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
144                       unsigned char channel, unsigned char tag, unsigned char sy,
145                           unsigned int cycle, unsigned int dropped);
146        
147         bool init();
148         bool reset();
149         bool prepare();
150         bool transfer();
151        
152         bool isOnePeriodReady();
153
154     // these two are important to calculate the optimal
155     // ISO DMA buffers size
156     // an estimate will do
157         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
158         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
159
160         virtual void setVerboseLevel(int l);
161        
162         float *getTicksPerFrameDLL(void) {return &m_ticks_per_frame;};
163         signed int setEventSize(unsigned int size);
164         unsigned int getEventSize(void);
165
166         virtual bool preparedForStop();
167
168 protected:
169
170         int receiveBlock(char *data, unsigned int nevents, unsigned int offset);
171         bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
172         signed int decodeMBLAEventsToPort(MotuAudioPort *p, quadlet_t *data, unsigned int offset, unsigned int nevents);
173
174         freebob_ringbuffer_t * m_event_buffer;
175         char* m_tmp_event_buffer;
176        
177         /*
178          * An iso packet mostly consists of multiple events.  m_event_size
179          * is the size of a single 'event' in bytes.
180          */
181         unsigned int m_event_size;
182
183         // The integrator of a Delay-Locked Loop (DLL) used to provide a
184         // continuously updated estimate of the number of ieee1394 frames
185         // per audio frame at the current sample rate.
186         float m_ticks_per_frame;
187
188         signed int m_last_cycle_ofs;
189         signed int m_next_cycle;
190
191         // Signifies a closedown is in progress, in which case incoming data
192         // is junked.
193         signed int m_closedown_active;
194
195     DECLARE_DEBUG_MODULE;
196
197 };
198
199 } // end of namespace FreebobStreaming
200
201 #endif /* __FREEBOB_MOTUSTREAMPROCESSOR__ */
202
203
Note: See TracBrowser for help on using the browser.