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

Revision 383, 3.9 kB (checked in by pieterpalmers, 17 years ago)

mostly whitespace fixes

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 "../libutil/PosixThread.h"
34 #include <semaphore.h>
35 #include "Port.h"
36 #include "StreamProcessor.h"
37 #include "IsoHandlerManager.h"
38
39 #include <vector>
40
41 namespace FreebobStreaming {
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 :
54                         public FreebobUtil::RunnableInterface {
55
56         friend class StreamRunner;
57
58 public:
59
60     StreamProcessorManager(unsigned int period, unsigned int nb_buffers);
61     virtual ~StreamProcessorManager();
62
63     bool init(); ///< to be called immediately after the construction
64     bool prepare(); ///< to be called after the processors are registered
65
66     virtual void setVerboseLevel(int l);
67     void dumpInfo();
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     void setPeriodSize(unsigned int period);
74     void setPeriodSize(unsigned int period, unsigned int nb_buffers);
75     int getPeriodSize() {return m_period;};
76
77     void setNbBuffers(unsigned int nb_buffers);
78     int getNbBuffers() {return m_nb_buffers;};
79
80     int getPortCount(enum Port::E_PortType, enum Port::E_Direction);
81     int getPortCount(enum Port::E_Direction);
82     Port* getPortByIndex(int idx, enum Port::E_Direction);
83
84     // the client-side functions
85     bool xrunOccurred();
86     int getXrunCount() {return m_xruns;};
87
88     bool waitForPeriod(); ///< wait for the next period
89
90     bool transfer(); ///< transfer the buffer contents from/to client
91     bool transfer(enum StreamProcessor::EProcessorType); ///< transfer the buffer contents from/to client (single processor type)
92
93     bool handleXrun(); ///< reset the streams & buffers after xrun
94
95     bool start();
96     bool stop();
97
98     bool setThreadParameters(bool rt, int priority);
99
100         // the ISO-side functions
101 protected:
102     int signalWaiters(); // call this to signal a period boundary
103     // RunnableInterface interface
104     bool Execute(); // note that this is called in we while(running) loop
105     bool Init();
106
107     // thread sync primitives
108     sem_t m_period_semaphore;
109
110     bool m_xrun_happened;
111
112     bool m_thread_realtime;
113     int m_thread_priority;
114
115     // processor list
116     StreamProcessorVector m_ReceiveProcessors;
117     StreamProcessorVector m_TransmitProcessors;
118
119     unsigned int m_nb_buffers;
120     unsigned int m_period;
121     unsigned int m_xruns;
122    
123     IsoHandlerManager *m_isoManager;
124
125     FreebobUtil::PosixThread *m_streamingThread;
126     FreebobUtil::PosixThread *m_isoManagerThread;
127
128     unsigned int m_nbperiods;
129
130     DECLARE_DEBUG_MODULE;
131
132 };
133
134 }
135
136 #endif /* __FREEBOB_STREAMPROCESSORMANAGER__ */
137
138
Note: See TracBrowser for help on using the browser.