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

Revision 742, 4.2 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

Line 
1 /*
2  * Copyright (C) 2005-2007 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 3 of the License, or
12  * (at your option) any later version.
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/Port.h"
28 #include "generic/StreamProcessor.h"
29 #include "util/IsoHandlerManager.h"
30
31 #include "debugmodule/debugmodule.h"
32 #include "libutil/Thread.h"
33 #include "libutil/OptionContainer.h"
34
35 #include <vector>
36 #include <semaphore.h>
37
38 namespace Streaming {
39
40 class StreamProcessor;
41 class IsoHandlerManager;
42
43 typedef std::vector<StreamProcessor *> StreamProcessorVector;
44 typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator;
45
46 /*!
47 \brief Manages a collection of StreamProcessors and provides a synchronisation interface
48
49 */
50 class StreamProcessorManager : public Util::OptionContainer {
51     friend class StreamProcessor;
52
53 public:
54
55     StreamProcessorManager(unsigned int period, unsigned int rate, unsigned int nb_buffers);
56     virtual ~StreamProcessorManager();
57
58     bool init(); ///< to be called immediately after the construction
59     bool prepare(); ///< to be called after the processors are registered
60
61     bool start();
62     bool stop();
63
64     bool startDryRunning();
65     bool syncStartAll();
66
67     // this is the setup API
68     bool registerProcessor(StreamProcessor *processor); ///< start managing a streamprocessor
69     bool unregisterProcessor(StreamProcessor *processor); ///< stop managing a streamprocessor
70
71     void setPeriodSize(unsigned int period);
72     void setPeriodSize(unsigned int period, unsigned int nb_buffers);
73     unsigned int getPeriodSize() {return m_period;};
74
75     void setNbBuffers(unsigned int nb_buffers);
76     int getNbBuffers() {return m_nb_buffers;};
77
78     int getPortCount(enum Port::E_PortType, enum Port::E_Direction);
79     int getPortCount(enum Port::E_Direction);
80     Port* getPortByIndex(int idx, enum Port::E_Direction);
81
82     // the client-side functions
83     bool waitForPeriod();
84     bool transfer();
85     bool transfer(enum StreamProcessor::eProcessorType);
86 private:
87     bool transferSilence();
88     bool transferSilence(enum StreamProcessor::eProcessorType);
89
90     bool alignReceivedStreams();
91 public:
92     int getDelayedUsecs() {return m_delayed_usecs;};
93     bool xrunOccurred();
94     int getXrunCount() {return m_xruns;};
95
96     unsigned int getNominalRate() {return m_nominal_framerate;};
97     uint64_t getTimeOfLastTransfer() { return m_time_of_transfer;};
98
99 private:
100     int m_delayed_usecs;
101     // this stores the time at which the next transfer should occur
102     // usually this is in the past, but it is needed as a timestamp
103     // for the transmit SP's
104     uint64_t m_time_of_transfer;
105
106 public:
107     bool handleXrun(); ///< reset the streams & buffers after xrun
108
109     bool setThreadParameters(bool rt, int priority);
110
111     virtual void setVerboseLevel(int l);
112     void dumpInfo();
113
114 private: // slaving support
115     bool m_is_slave;
116
117     // the sync source stuff
118 private:
119     StreamProcessor *m_SyncSource;
120
121 public:
122     bool setSyncSource(StreamProcessor *s);
123     StreamProcessor& getSyncSource()
124         {return *m_SyncSource;};
125
126 protected:
127
128     // thread sync primitives
129     bool m_xrun_happened;
130
131     bool m_thread_realtime;
132     int m_thread_priority;
133
134     // processor list
135     StreamProcessorVector m_ReceiveProcessors;
136     StreamProcessorVector m_TransmitProcessors;
137
138     unsigned int m_nb_buffers;
139     unsigned int m_period;
140     unsigned int m_nominal_framerate;
141     unsigned int m_xruns;
142
143     IsoHandlerManager *m_isoManager;
144
145     unsigned int m_nbperiods;
146
147     DECLARE_DEBUG_MODULE;
148
149 };
150
151 }
152
153 #endif /* __FFADO_STREAMPROCESSORMANAGER__ */
154
155
Note: See TracBrowser for help on using the browser.