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

Revision 705, 4.3 kB (checked in by ppalmers, 16 years ago)

restructure the streaming directory

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
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_xruns;
141
142     IsoHandlerManager *m_isoManager;
143
144     unsigned int m_nbperiods;
145
146     DECLARE_DEBUG_MODULE;
147
148 };
149
150 }
151
152 #endif /* __FFADO_STREAMPROCESSORMANAGER__ */
153
154
Note: See TracBrowser for help on using the browser.