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

Revision 407, 5.3 kB (checked in by pieterpalmers, 16 years ago)

- Changed the way the device class configure options are handled. Now they are handled in the makefiles instead of the source files. The only source file that still contains the #ifdef's is devicemanager.cpp, to conditionally include the device class include files and to conditionally probe the classes that might be supported.
- added a configure option to disable the compilation of the test programs in tests/
- cleaned up the ADMTP transmit streamprocessor. Now it sends silenced packets when in the disabled state, instead of no-data packets
- added a getNodeID() to ieee1394service
- made comments in ieee1394service.h doxygen compliant

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
65         bool prepareForStop();
66         bool prepareForStart();
67        
68     bool prepareForEnable(uint64_t time_to_enable_at);
69    
70     bool putFrames(unsigned int nbframes, int64_t ts); ///< transfer the buffer contents from the client
71        
72         // These two are important to calculate the optimal ISO DMA buffers
73         // size.  An estimate will do.
74         unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;};
75         unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};
76
77     int getMinimalSyncDelay();
78
79         void setVerboseLevel(int l);
80
81 protected:
82         /*
83          * An iso packet mostly consists of multiple events.  m_event_size
84          * is the size of a single 'event' in bytes.
85          */
86         unsigned int m_event_size;
87
88         // Keep track of transmission data block count
89         unsigned int m_tx_dbc;
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); ///< 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 FreebobStreaming
180
181 #endif /* __FREEBOB_MOTUSTREAMPROCESSOR__ */
182
183
Note: See TracBrowser for help on using the browser.