root/trunk/libffado/src/libstreaming/StreamProcessorManager.h

Revision 1763, 5.8 kB (checked in by ppalmers, 12 years ago)

Merged revisions 1536,1541,1544-1546,1549,1554-1562,1571,1579-1581,1618,1632,1634-1635,1661,1677-1679,1703-1704,1715,1720-1723,1743-1745,1755 via svnmerge from
svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0

Also fix remaining format string warnings.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program 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
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef __FFADO_STREAMPROCESSORMANAGER__
25 #define __FFADO_STREAMPROCESSORMANAGER__
26
27 #include "generic/PortManager.h"
28 #include "generic/Port.h"
29 #include "generic/StreamProcessor.h"
30
31 #include "debugmodule/debugmodule.h"
32 #include "libutil/Thread.h"
33 #include "libutil/Mutex.h"
34 #include "libutil/OptionContainer.h"
35
36 #include <vector>
37 #include <semaphore.h>
38
39 class DeviceManager;
40
41 namespace Streaming {
42
43 class StreamProcessor;
44
45 typedef std::vector<StreamProcessor *> StreamProcessorVector;
46 typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator;
47
48 /*!
49 \brief Manages a collection of StreamProcessors and provides a synchronisation interface
50
51 */
52 class StreamProcessorManager : public Util::OptionContainer {
53     friend class StreamProcessor;
54
55 public:
56     enum eADT_AudioDataType {
57         eADT_Int24,
58         eADT_Float,
59     };
60
61     StreamProcessorManager(DeviceManager &parent);
62     StreamProcessorManager(DeviceManager &parent, unsigned int period,
63                            unsigned int rate, unsigned int nb_buffers);
64     virtual ~StreamProcessorManager();
65
66     bool prepare(); ///< to be called after the processors are registered
67
68     bool start();
69     bool stop();
70
71     bool startDryRunning();
72     bool syncStartAll();
73     // activity signaling
74     enum eActivityResult {
75         eAR_Activity,
76         eAR_Timeout,
77         eAR_Interrupted,
78         eAR_Error
79     };
80     void signalActivity();
81     enum eActivityResult waitForActivity();
82
83     // this is the setup API
84     bool registerProcessor(StreamProcessor *processor); ///< start managing a streamprocessor
85     bool unregisterProcessor(StreamProcessor *processor); ///< stop managing a streamprocessor
86
87     void setPeriodSize(unsigned int period)
88             {m_period = period;};
89     unsigned int getPeriodSize()
90             {return m_period;};
91
92     bool setAudioDataType(enum eADT_AudioDataType t)
93         {m_audio_datatype = t; return true;};
94     enum eADT_AudioDataType getAudioDataType()
95         {return m_audio_datatype;}
96
97     void setNbBuffers(unsigned int nb_buffers)
98             {m_nb_buffers = nb_buffers;};
99     unsigned int getNbBuffers()
100             {return m_nb_buffers;};
101
102     // this is the amount of usecs we wait before an activity
103     // timeout occurs.
104     void setActivityWaitTimeoutUsec(int usec)
105             {m_activity_wait_timeout_nsec = usec*1000LL;};
106     int getActivityWaitTimeoutUsec()
107             {return m_activity_wait_timeout_nsec/1000;};
108
109     int getPortCount(enum Port::E_PortType, enum Port::E_Direction);
110     int getPortCount(enum Port::E_Direction);
111     Port* getPortByIndex(int idx, enum Port::E_Direction);
112
113     // the client-side functions
114     bool waitForPeriod();
115     bool transfer();
116     bool transfer(enum StreamProcessor::eProcessorType);
117
118     // for bus reset handling
119     void lockWaitLoop() {m_WaitLock->Lock();};
120     void unlockWaitLoop() {m_WaitLock->Unlock();};
121
122 private:
123     bool transferSilence();
124     bool transferSilence(enum StreamProcessor::eProcessorType);
125
126     bool alignReceivedStreams();
127 public:
128     int getDelayedUsecs() {return m_delayed_usecs;};
129     bool xrunOccurred();
130     bool shutdownNeeded() {return m_shutdown_needed;};
131     int getXrunCount() {return m_xruns;};
132
133     void setNominalRate(unsigned int r) {m_nominal_framerate = r;};
134     unsigned int getNominalRate() {return m_nominal_framerate;};
135     uint64_t getTimeOfLastTransfer() { return m_time_of_transfer;};
136
137 private:
138     int m_delayed_usecs;
139     // this stores the time at which the next transfer should occur
140     // usually this is in the past, but it is needed as a timestamp
141     // for the transmit SP's
142     uint64_t m_time_of_transfer;
143     #ifdef DEBUG
144     uint64_t m_time_of_transfer2;
145     #endif
146
147 public:
148     bool handleXrun(); ///< reset the streams & buffers after xrun
149
150     bool setThreadParameters(bool rt, int priority);
151
152     virtual void setVerboseLevel(int l);
153     void dumpInfo();
154
155 private: // slaving support
156     bool m_is_slave;
157
158     // the sync source stuff
159 private:
160     StreamProcessor *m_SyncSource;
161
162 public:
163     bool setSyncSource(StreamProcessor *s);
164     StreamProcessor& getSyncSource()
165         {return *m_SyncSource;};
166
167 protected: // FIXME: private?
168
169     // parent device manager
170     DeviceManager &m_parent;
171
172     // thread related vars
173     bool m_xrun_happened;
174     int64_t m_activity_wait_timeout_nsec;
175     bool m_thread_realtime;
176     int m_thread_priority;
177
178     // activity signaling
179     sem_t m_activity_semaphore;
180
181     // processor list
182     StreamProcessorVector m_ReceiveProcessors;
183     StreamProcessorVector m_TransmitProcessors;
184
185     // port shadow lists
186     PortVector m_CapturePorts_shadow;
187     PortVector m_PlaybackPorts_shadow;
188     void updateShadowLists();
189
190     unsigned int m_nb_buffers;
191     unsigned int m_period;
192     unsigned int m_sync_delay;
193     enum eADT_AudioDataType m_audio_datatype;
194     unsigned int m_nominal_framerate;
195     unsigned int m_xruns;
196     bool m_shutdown_needed;
197
198     unsigned int m_nbperiods;
199
200     Util::Mutex *m_WaitLock;
201
202     DECLARE_DEBUG_MODULE;
203
204 };
205
206 }
207
208 #endif /* __FFADO_STREAMPROCESSORMANAGER__ */
209
210
Note: See TracBrowser for help on using the browser.