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

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

- rework of streaming startup
- started moving files around to enhance structure

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 "debugmodule/debugmodule.h"
28 #include "libutil/Thread.h"
29 #include "libutil/OptionContainer.h"
30 #include <semaphore.h>
31 #include "Port.h"
32 #include "StreamProcessor.h"
33 #include "IsoHandlerManager.h"
34
35 #include <vector>
36
37 namespace Streaming {
38
39 class StreamProcessor;
40 class IsoHandlerManager;
41
42 typedef std::vector<StreamProcessor *> StreamProcessorVector;
43 typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator;
44
45 /*!
46 \brief Manages a collection of StreamProcessors and provides a synchronisation interface
47
48 */
49 class StreamProcessorManager : public Util::OptionContainer {
50     friend class StreamProcessor;
51
52 public:
53
54     StreamProcessorManager(unsigned int period, unsigned int nb_buffers);
55     virtual ~StreamProcessorManager();
56
57     bool init(); ///< to be called immediately after the construction
58     bool prepare(); ///< to be called after the processors are registered
59
60     bool start();
61     bool stop();
62
63     bool syncStartAll();
64
65     // this is the setup API
66     bool registerProcessor(StreamProcessor *processor); ///< start managing a streamprocessor
67     bool unregisterProcessor(StreamProcessor *processor); ///< stop managing a streamprocessor
68
69     bool enableStreamProcessors(uint64_t time_to_enable_at); /// enable registered StreamProcessors
70     bool disableStreamProcessors(); /// disable registered StreamProcessors
71
72     void setPeriodSize(unsigned int period);
73     void setPeriodSize(unsigned int period, unsigned int nb_buffers);
74     int getPeriodSize() {return m_period;};
75
76     void setNbBuffers(unsigned int nb_buffers);
77     int getNbBuffers() {return m_nb_buffers;};
78
79     int getPortCount(enum Port::E_PortType, enum Port::E_Direction);
80     int getPortCount(enum Port::E_Direction);
81     Port* getPortByIndex(int idx, enum Port::E_Direction);
82
83     // the client-side functions
84
85     bool waitForPeriod(); ///< wait for the next period
86
87     bool transfer(); ///< transfer the buffer contents from/to client
88     bool transfer(enum StreamProcessor::EProcessorType); ///< transfer the buffer contents from/to client (single processor type)
89    
90     bool dryRun();
91     bool dryRun(enum StreamProcessor::EProcessorType);
92
93     int getDelayedUsecs() {return m_delayed_usecs;};
94     bool xrunOccurred();
95     int getXrunCount() {return m_xruns;};
96
97 private:
98     void resetXrunCounters();
99
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
125 protected:
126
127     // thread sync primitives
128     bool m_xrun_happened;
129
130     bool m_thread_realtime;
131     int m_thread_priority;
132
133     // processor list
134     StreamProcessorVector m_ReceiveProcessors;
135     StreamProcessorVector m_TransmitProcessors;
136
137     unsigned int m_nb_buffers;
138     unsigned int m_period;
139     unsigned int m_xruns;
140
141     IsoHandlerManager *m_isoManager;
142
143     unsigned int m_nbperiods;
144
145     DECLARE_DEBUG_MODULE;
146
147 };
148
149 }
150
151 #endif /* __FFADO_STREAMPROCESSORMANAGER__ */
152
153
Note: See TracBrowser for help on using the browser.