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

Revision 864, 4.5 kB (checked in by ppalmers, 15 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

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