1 |
/* $Id$ */ |
---|
2 |
|
---|
3 |
/* |
---|
4 |
* FreeBob Streaming API |
---|
5 |
* FreeBob = Firewire (pro-)audio for linux |
---|
6 |
* |
---|
7 |
* http://freebob.sf.net |
---|
8 |
* |
---|
9 |
* Copyright (C) 2005,2006 Pieter Palmers <pieterpalmers@users.sourceforge.net> |
---|
10 |
* |
---|
11 |
* This program is free software {} you can redistribute it and/or modify |
---|
12 |
* it under the terms of the GNU General Public License as published by |
---|
13 |
* the Free Software Foundation {} either version 2 of the License, or |
---|
14 |
* (at your option) any later version. |
---|
15 |
* |
---|
16 |
* This program is distributed in the hope that it will be useful, |
---|
17 |
* but WITHOUT ANY WARRANTY {} without even the implied warranty of |
---|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 |
* GNU General Public License for more details. |
---|
20 |
* |
---|
21 |
* You should have received a copy of the GNU General Public License |
---|
22 |
* along with this program {} if not, write to the Free Software |
---|
23 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
24 |
* |
---|
25 |
* |
---|
26 |
* |
---|
27 |
*/ |
---|
28 |
#ifndef __FREEBOB_STREAMPROCESSORMANAGER__ |
---|
29 |
#define __FREEBOB_STREAMPROCESSORMANAGER__ |
---|
30 |
|
---|
31 |
#include "debugmodule/debugmodule.h" |
---|
32 |
#include "libutil/Thread.h" |
---|
33 |
#include "libutil/OptionContainer.h" |
---|
34 |
#include <semaphore.h> |
---|
35 |
#include "Port.h" |
---|
36 |
#include "StreamProcessor.h" |
---|
37 |
#include "IsoHandlerManager.h" |
---|
38 |
|
---|
39 |
#include <vector> |
---|
40 |
|
---|
41 |
namespace Streaming { |
---|
42 |
|
---|
43 |
class StreamProcessor; |
---|
44 |
class IsoHandlerManager; |
---|
45 |
|
---|
46 |
typedef std::vector<StreamProcessor *> StreamProcessorVector; |
---|
47 |
typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator; |
---|
48 |
|
---|
49 |
/*! |
---|
50 |
\brief Manages a collection of StreamProcessors and provides a synchronisation interface |
---|
51 |
|
---|
52 |
*/ |
---|
53 |
class StreamProcessorManager : public Util::OptionContainer { |
---|
54 |
friend class StreamProcessor; |
---|
55 |
|
---|
56 |
public: |
---|
57 |
|
---|
58 |
StreamProcessorManager(unsigned int period, unsigned int nb_buffers); |
---|
59 |
virtual ~StreamProcessorManager(); |
---|
60 |
|
---|
61 |
bool init(); ///< to be called immediately after the construction |
---|
62 |
bool prepare(); ///< to be called after the processors are registered |
---|
63 |
|
---|
64 |
bool start(); |
---|
65 |
bool stop(); |
---|
66 |
|
---|
67 |
bool syncStartAll(); |
---|
68 |
|
---|
69 |
// this is the setup API |
---|
70 |
bool registerProcessor(StreamProcessor *processor); ///< start managing a streamprocessor |
---|
71 |
bool unregisterProcessor(StreamProcessor *processor); ///< stop managing a streamprocessor |
---|
72 |
|
---|
73 |
bool enableStreamProcessors(uint64_t time_to_enable_at); /// enable registered StreamProcessors |
---|
74 |
bool disableStreamProcessors(); /// disable registered StreamProcessors |
---|
75 |
|
---|
76 |
void setPeriodSize(unsigned int period); |
---|
77 |
void setPeriodSize(unsigned int period, unsigned int nb_buffers); |
---|
78 |
int getPeriodSize() {return m_period;}; |
---|
79 |
|
---|
80 |
void setNbBuffers(unsigned int nb_buffers); |
---|
81 |
int getNbBuffers() {return m_nb_buffers;}; |
---|
82 |
|
---|
83 |
int getPortCount(enum Port::E_PortType, enum Port::E_Direction); |
---|
84 |
int getPortCount(enum Port::E_Direction); |
---|
85 |
Port* getPortByIndex(int idx, enum Port::E_Direction); |
---|
86 |
|
---|
87 |
// the client-side functions |
---|
88 |
|
---|
89 |
bool waitForPeriod(); ///< wait for the next period |
---|
90 |
|
---|
91 |
bool transfer(); ///< transfer the buffer contents from/to client |
---|
92 |
bool transfer(enum StreamProcessor::EProcessorType); ///< transfer the buffer contents from/to client (single processor type) |
---|
93 |
|
---|
94 |
int getDelayedUsecs() {return m_delayed_usecs;}; |
---|
95 |
bool xrunOccurred(); |
---|
96 |
int getXrunCount() {return m_xruns;}; |
---|
97 |
|
---|
98 |
private: |
---|
99 |
int m_delayed_usecs; |
---|
100 |
// this stores the time at which the next transfer should occur |
---|
101 |
// usually this is in the past, but it is needed as a timestamp |
---|
102 |
// for the transmit SP's |
---|
103 |
uint64_t m_time_of_transfer; |
---|
104 |
|
---|
105 |
public: |
---|
106 |
bool handleXrun(); ///< reset the streams & buffers after xrun |
---|
107 |
|
---|
108 |
bool setThreadParameters(bool rt, int priority); |
---|
109 |
|
---|
110 |
virtual void setVerboseLevel(int l); |
---|
111 |
void dumpInfo(); |
---|
112 |
|
---|
113 |
private: // slaving support |
---|
114 |
bool m_is_slave; |
---|
115 |
|
---|
116 |
// the sync source stuff |
---|
117 |
private: |
---|
118 |
StreamProcessor *m_SyncSource; |
---|
119 |
|
---|
120 |
public: |
---|
121 |
bool setSyncSource(StreamProcessor *s); |
---|
122 |
StreamProcessor * getSyncSource(); |
---|
123 |
|
---|
124 |
protected: |
---|
125 |
|
---|
126 |
// thread sync primitives |
---|
127 |
bool m_xrun_happened; |
---|
128 |
|
---|
129 |
bool m_thread_realtime; |
---|
130 |
int m_thread_priority; |
---|
131 |
|
---|
132 |
// processor list |
---|
133 |
StreamProcessorVector m_ReceiveProcessors; |
---|
134 |
StreamProcessorVector m_TransmitProcessors; |
---|
135 |
|
---|
136 |
unsigned int m_nb_buffers; |
---|
137 |
unsigned int m_period; |
---|
138 |
unsigned int m_xruns; |
---|
139 |
|
---|
140 |
IsoHandlerManager *m_isoManager; |
---|
141 |
|
---|
142 |
unsigned int m_nbperiods; |
---|
143 |
|
---|
144 |
DECLARE_DEBUG_MODULE; |
---|
145 |
|
---|
146 |
}; |
---|
147 |
|
---|
148 |
} |
---|
149 |
|
---|
150 |
#endif /* __FREEBOB_STREAMPROCESSORMANAGER__ */ |
---|
151 |
|
---|
152 |
|
---|