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

Revision 398, 4.2 kB (checked in by pieterpalmers, 16 years ago)

remove cycle timer prediction & DLL code from the IsoHandler?, as it is replaced by a raw1394 API call

Line 
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 <semaphore.h>
34 #include "Port.h"
35 #include "StreamProcessor.h"
36 #include "IsoHandlerManager.h"
37
38 #include <vector>
39
40 namespace FreebobStreaming {
41
42 class StreamProcessor;
43 class IsoHandlerManager;
44
45 typedef std::vector<StreamProcessor *> StreamProcessorVector;
46 typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator;
47
48 /*!
49 \brief Manages a collection of StreamProcessors and provides a synchronisation interface
50  
51 */
52 class StreamProcessorManager {
53
54 public:
55
56     StreamProcessorManager(unsigned int period, unsigned int nb_buffers);
57     virtual ~StreamProcessorManager();
58
59     bool init(); ///< to be called immediately after the construction
60     bool prepare(); ///< to be called after the processors are registered
61
62     bool start();
63     bool stop();
64    
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     bool enableStreamProcessors(uint64_t time_to_enable_at); /// enable registered StreamProcessors
72     bool disableStreamProcessors(); /// disable registered StreamProcessors
73
74     void setPeriodSize(unsigned int period);
75     void setPeriodSize(unsigned int period, unsigned int nb_buffers);
76     int getPeriodSize() {return m_period;};
77
78     void setNbBuffers(unsigned int nb_buffers);
79     int getNbBuffers() {return m_nb_buffers;};
80
81     int getPortCount(enum Port::E_PortType, enum Port::E_Direction);
82     int getPortCount(enum Port::E_Direction);
83     Port* getPortByIndex(int idx, enum Port::E_Direction);
84
85     // the client-side functions
86
87     bool waitForPeriod(); ///< wait for the next period
88
89     bool transfer(); ///< transfer the buffer contents from/to client
90     bool transfer(enum StreamProcessor::EProcessorType); ///< transfer the buffer contents from/to client (single processor type)
91    
92     int getDelayedUsecs() {return m_delayed_usecs;};
93     bool xrunOccurred();
94     int getXrunCount() {return m_xruns;};
95    
96 private:
97     int m_delayed_usecs;
98     // this stores the time at which the next transfer should occur
99     // usually this is in the past, but it is needed as a timestamp
100     // for the transmit SP's
101     uint64_t m_time_of_transfer;
102    
103 public:
104     bool handleXrun(); ///< reset the streams & buffers after xrun
105
106     bool setThreadParameters(bool rt, int priority);
107
108     virtual void setVerboseLevel(int l);
109     void dumpInfo();
110    
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    
121 protected:
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 /* __FREEBOB_STREAMPROCESSORMANAGER__ */
147
148
Note: See TracBrowser for help on using the browser.