root/trunk/libffado/src/libstreaming/StreamProcessorManager.h

Revision 445, 4.2 kB (checked in by pieterpalmers, 17 years ago)

* name change from FreeBoB to FFADO
* replaced tabs by 4 spaces
* got rid of end-of-line spaces
* made all license and copyrights conform

library becomes LGPL, apps become GPL
explicitly state LGPL v2.1 and GPL v2 (don't like v3 draft)

copyrights are 2005-2007 Daniel & Pieter
except for the MotU stuff (C) Jonathan, Pieter

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     int getDelayedUsecs() {return m_delayed_usecs;};
91     bool xrunOccurred();
92     int getXrunCount() {return m_xruns;};
93
94 private:
95     int m_delayed_usecs;
96     // this stores the time at which the next transfer should occur
97     // usually this is in the past, but it is needed as a timestamp
98     // for the transmit SP's
99     uint64_t m_time_of_transfer;
100
101 public:
102     bool handleXrun(); ///< reset the streams & buffers after xrun
103
104     bool setThreadParameters(bool rt, int priority);
105
106     virtual void setVerboseLevel(int l);
107     void dumpInfo();
108
109 private: // slaving support
110     bool m_is_slave;
111
112     // the sync source stuff
113 private:
114     StreamProcessor *m_SyncSource;
115
116 public:
117     bool setSyncSource(StreamProcessor *s);
118     StreamProcessor * getSyncSource();
119
120 protected:
121
122     // thread sync primitives
123     bool m_xrun_happened;
124
125     bool m_thread_realtime;
126     int m_thread_priority;
127
128     // processor list
129     StreamProcessorVector m_ReceiveProcessors;
130     StreamProcessorVector m_TransmitProcessors;
131
132     unsigned int m_nb_buffers;
133     unsigned int m_period;
134     unsigned int m_xruns;
135
136     IsoHandlerManager *m_isoManager;
137
138     unsigned int m_nbperiods;
139
140     DECLARE_DEBUG_MODULE;
141
142 };
143
144 }
145
146 #endif /* __FFADO_STREAMPROCESSORMANAGER__ */
147
148
Note: See TracBrowser for help on using the browser.