root/branches/ppalmers-streaming/src/libstreaming/StreamProcessorManager.h

Revision 715, 4.4 kB (checked in by ppalmers, 15 years ago)

some more cleaning

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 library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
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 syncStartAll();
65
66     // this is the setup API
67     bool registerProcessor(StreamProcessor *processor); ///< start managing a streamprocessor
68     bool unregisterProcessor(StreamProcessor *processor); ///< stop managing a streamprocessor
69
70     bool enableStreamProcessors(uint64_t time_to_enable_at); /// enable registered StreamProcessors
71     bool disableStreamProcessors(); /// disable registered StreamProcessors
72
73     void setPeriodSize(unsigned int period);
74     void setPeriodSize(unsigned int period, unsigned int nb_buffers);
75     int getPeriodSize() {return m_period;};
76
77     void setNbBuffers(unsigned int nb_buffers);
78     int getNbBuffers() {return m_nb_buffers;};
79
80     int getPortCount(enum Port::E_PortType, enum Port::E_Direction);
81     int getPortCount(enum Port::E_Direction);
82     Port* getPortByIndex(int idx, enum Port::E_Direction);
83
84     // the client-side functions
85
86     bool waitForPeriod(); ///< wait for the next period
87
88     bool transfer(); ///< transfer the buffer contents from/to client
89     bool transfer(enum StreamProcessor::eProcessorType); ///< transfer the buffer contents from/to client (single processor type)
90    
91     bool dryRun();
92     bool dryRun(enum StreamProcessor::eProcessorType);
93
94     int getDelayedUsecs() {return m_delayed_usecs;};
95     bool xrunOccurred();
96     int getXrunCount() {return m_xruns;};
97
98     unsigned int getNominalRate() {return m_nominal_framerate;};
99
100 private:
101     void resetXrunCounters();
102
103     int m_delayed_usecs;
104     // this stores the time at which the next transfer should occur
105     // usually this is in the past, but it is needed as a timestamp
106     // for the transmit SP's
107     uint64_t m_time_of_transfer;
108
109 public:
110     bool handleXrun(); ///< reset the streams & buffers after xrun
111
112     bool setThreadParameters(bool rt, int priority);
113
114     virtual void setVerboseLevel(int l);
115     void dumpInfo();
116
117 private: // slaving support
118     bool m_is_slave;
119
120     // the sync source stuff
121 private:
122     StreamProcessor *m_SyncSource;
123
124 public:
125     bool setSyncSource(StreamProcessor *s);
126     StreamProcessor& getSyncSource()
127         {return *m_SyncSource;};
128
129 protected:
130
131     // thread sync primitives
132     bool m_xrun_happened;
133
134     bool m_thread_realtime;
135     int m_thread_priority;
136
137     // processor list
138     StreamProcessorVector m_ReceiveProcessors;
139     StreamProcessorVector m_TransmitProcessors;
140
141     unsigned int m_nb_buffers;
142     unsigned int m_period;
143     unsigned int m_nominal_framerate;
144     unsigned int m_xruns;
145
146     IsoHandlerManager *m_isoManager;
147
148     unsigned int m_nbperiods;
149
150     DECLARE_DEBUG_MODULE;
151
152 };
153
154 }
155
156 #endif /* __FFADO_STREAMPROCESSORMANAGER__ */
157
158
Note: See TracBrowser for help on using the browser.