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

Revision 714, 4.3 kB (checked in by ppalmers, 15 years ago)

- cleanup of streaming interfaces
- doesn't work yet

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 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 private:
99     void resetXrunCounters();
100
101     int m_delayed_usecs;
102     // this stores the time at which the next transfer should occur
103     // usually this is in the past, but it is needed as a timestamp
104     // for the transmit SP's
105     uint64_t m_time_of_transfer;
106
107 public:
108     bool handleXrun(); ///< reset the streams & buffers after xrun
109
110     bool setThreadParameters(bool rt, int priority);
111
112     virtual void setVerboseLevel(int l);
113     void dumpInfo();
114
115 private: // slaving support
116     bool m_is_slave;
117
118     // the sync source stuff
119 private:
120     StreamProcessor *m_SyncSource;
121
122 public:
123     bool setSyncSource(StreamProcessor *s);
124     StreamProcessor& getSyncSource()
125         {return *m_SyncSource;};
126
127 protected:
128
129     // thread sync primitives
130     bool m_xrun_happened;
131
132     bool m_thread_realtime;
133     int m_thread_priority;
134
135     // processor list
136     StreamProcessorVector m_ReceiveProcessors;
137     StreamProcessorVector m_TransmitProcessors;
138
139     unsigned int m_nb_buffers;
140     unsigned int m_period;
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.