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

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

first working version of the reworked streaming code

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 startDryRunning();
65     bool syncStartAll();
66
67     // this is the setup API
68     bool registerProcessor(StreamProcessor *processor); ///< start managing a streamprocessor
69     bool unregisterProcessor(StreamProcessor *processor); ///< stop managing a streamprocessor
70
71     void setPeriodSize(unsigned int period);
72     void setPeriodSize(unsigned int period, unsigned int nb_buffers);
73     int getPeriodSize() {return m_period;};
74
75     void setNbBuffers(unsigned int nb_buffers);
76     int getNbBuffers() {return m_nb_buffers;};
77
78     int getPortCount(enum Port::E_PortType, enum Port::E_Direction);
79     int getPortCount(enum Port::E_Direction);
80     Port* getPortByIndex(int idx, enum Port::E_Direction);
81
82     // the client-side functions
83
84     bool waitForPeriod(); ///< wait for the next period
85     bool transfer(); ///< transfer the buffer contents from/to client
86     bool transfer(enum StreamProcessor::eProcessorType); ///< transfer the buffer contents from/to client (single processor type)
87
88     int getDelayedUsecs() {return m_delayed_usecs;};
89     bool xrunOccurred();
90     int getXrunCount() {return m_xruns;};
91
92     unsigned int getNominalRate() {return m_nominal_framerate;};
93     uint64_t getTimeOfLastTransfer() { return m_time_of_transfer;};
94
95 private:
96     int m_delayed_usecs;
97     // this stores the time at which the next transfer should occur
98     // usually this is in the past, but it is needed as a timestamp
99     // for the transmit SP's
100     uint64_t m_time_of_transfer;
101
102 public:
103     bool handleXrun(); ///< reset the streams & buffers after xrun
104
105     bool setThreadParameters(bool rt, int priority);
106
107     virtual void setVerboseLevel(int l);
108     void dumpInfo();
109
110 private: // slaving support
111     bool m_is_slave;
112
113     // the sync source stuff
114 private:
115     StreamProcessor *m_SyncSource;
116
117 public:
118     bool setSyncSource(StreamProcessor *s);
119     StreamProcessor& getSyncSource()
120         {return *m_SyncSource;};
121
122 protected:
123
124     // thread sync primitives
125     bool m_xrun_happened;
126
127     bool m_thread_realtime;
128     int m_thread_priority;
129
130     // processor list
131     StreamProcessorVector m_ReceiveProcessors;
132     StreamProcessorVector m_TransmitProcessors;
133
134     unsigned int m_nb_buffers;
135     unsigned int m_period;
136     unsigned int m_nominal_framerate;
137     unsigned int m_xruns;
138
139     IsoHandlerManager *m_isoManager;
140
141     unsigned int m_nbperiods;
142
143     DECLARE_DEBUG_MODULE;
144
145 };
146
147 }
148
149 #endif /* __FFADO_STREAMPROCESSORMANAGER__ */
150
151
Note: See TracBrowser for help on using the browser.