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 program is free software: you can redistribute it and/or modify |
---|
10 |
* it under the terms of the GNU General Public License as published by |
---|
11 |
* the Free Software Foundation, either version 3 of the License, or |
---|
12 |
* (at your option) any later version. |
---|
13 |
* |
---|
14 |
* This program is distributed in the hope that it will be useful, |
---|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 |
* GNU General Public License for more details. |
---|
18 |
* |
---|
19 |
* You should have received a copy of the GNU General Public License |
---|
20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 |
* |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
#ifndef __FFADO_STREAMPROCESSORMANAGER__ |
---|
25 |
#define __FFADO_STREAMPROCESSORMANAGER__ |
---|
26 |
|
---|
27 |
#include "generic/Port.h" |
---|
28 |
#include "generic/StreamProcessor.h" |
---|
29 |
|
---|
30 |
#include "debugmodule/debugmodule.h" |
---|
31 |
#include "libutil/Thread.h" |
---|
32 |
#include "libutil/OptionContainer.h" |
---|
33 |
|
---|
34 |
#include <vector> |
---|
35 |
#include <semaphore.h> |
---|
36 |
|
---|
37 |
namespace Streaming { |
---|
38 |
|
---|
39 |
class StreamProcessor; |
---|
40 |
|
---|
41 |
typedef std::vector<StreamProcessor *> StreamProcessorVector; |
---|
42 |
typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator; |
---|
43 |
|
---|
44 |
/*! |
---|
45 |
\brief Manages a collection of StreamProcessors and provides a synchronisation interface |
---|
46 |
|
---|
47 |
*/ |
---|
48 |
class StreamProcessorManager : public Util::OptionContainer { |
---|
49 |
friend class StreamProcessor; |
---|
50 |
|
---|
51 |
public: |
---|
52 |
|
---|
53 |
StreamProcessorManager(); |
---|
54 |
StreamProcessorManager(unsigned int period, unsigned int rate, unsigned int nb_buffers); |
---|
55 |
virtual ~StreamProcessorManager(); |
---|
56 |
|
---|
57 |
bool prepare(); ///< to be called after the processors are registered |
---|
58 |
|
---|
59 |
bool start(); |
---|
60 |
bool stop(); |
---|
61 |
|
---|
62 |
bool startDryRunning(); |
---|
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 |
void setPeriodSize(unsigned int period) |
---|
70 |
{m_period = period;}; |
---|
71 |
unsigned int getPeriodSize() |
---|
72 |
{return m_period;}; |
---|
73 |
|
---|
74 |
void setNbBuffers(unsigned int nb_buffers) |
---|
75 |
{m_nb_buffers = nb_buffers;}; |
---|
76 |
int getNbBuffers() |
---|
77 |
{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 |
bool waitForPeriod(); |
---|
85 |
bool transfer(); |
---|
86 |
bool transfer(enum StreamProcessor::eProcessorType); |
---|
87 |
private: |
---|
88 |
bool transferSilence(); |
---|
89 |
bool transferSilence(enum StreamProcessor::eProcessorType); |
---|
90 |
|
---|
91 |
bool alignReceivedStreams(); |
---|
92 |
public: |
---|
93 |
int getDelayedUsecs() {return m_delayed_usecs;}; |
---|
94 |
bool xrunOccurred(); |
---|
95 |
int getXrunCount() {return m_xruns;}; |
---|
96 |
|
---|
97 |
void setNominalRate(unsigned int r) {m_nominal_framerate = r;}; |
---|
98 |
unsigned int getNominalRate() {return m_nominal_framerate;}; |
---|
99 |
uint64_t getTimeOfLastTransfer() { return m_time_of_transfer;}; |
---|
100 |
|
---|
101 |
private: |
---|
102 |
int m_delayed_usecs; |
---|
103 |
// this stores the time at which the next transfer should occur |
---|
104 |
// usually this is in the past, but it is needed as a timestamp |
---|
105 |
// for the transmit SP's |
---|
106 |
uint64_t m_time_of_transfer; |
---|
107 |
|
---|
108 |
public: |
---|
109 |
bool handleXrun(); ///< reset the streams & buffers after xrun |
---|
110 |
|
---|
111 |
bool setThreadParameters(bool rt, int priority); |
---|
112 |
|
---|
113 |
virtual void setVerboseLevel(int l); |
---|
114 |
void dumpInfo(); |
---|
115 |
|
---|
116 |
private: // slaving support |
---|
117 |
bool m_is_slave; |
---|
118 |
|
---|
119 |
// the sync source stuff |
---|
120 |
private: |
---|
121 |
StreamProcessor *m_SyncSource; |
---|
122 |
|
---|
123 |
public: |
---|
124 |
bool setSyncSource(StreamProcessor *s); |
---|
125 |
StreamProcessor& getSyncSource() |
---|
126 |
{return *m_SyncSource;}; |
---|
127 |
|
---|
128 |
protected: |
---|
129 |
|
---|
130 |
// thread sync primitives |
---|
131 |
bool m_xrun_happened; |
---|
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_nominal_framerate; |
---|
142 |
unsigned int m_xruns; |
---|
143 |
|
---|
144 |
unsigned int m_nbperiods; |
---|
145 |
|
---|
146 |
DECLARE_DEBUG_MODULE; |
---|
147 |
|
---|
148 |
}; |
---|
149 |
|
---|
150 |
} |
---|
151 |
|
---|
152 |
#endif /* __FFADO_STREAMPROCESSORMANAGER__ */ |
---|
153 |
|
---|
154 |
|
---|