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

Revision 390, 4.5 kB (checked in by pieterpalmers, 16 years ago)

* working version of SYT based AMDTP receive and transmit.

Still has to be tuned to work with low buffer sizes.

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                         public FreebobUtil::RunnableInterface {
54
55 public:
56
57     StreamProcessorManager(unsigned int period, unsigned int nb_buffers);
58     virtual ~StreamProcessorManager();
59
60     bool init(); ///< to be called immediately after the construction
61     bool prepare(); ///< to be called after the processors are registered
62
63     bool start();
64     bool stop();
65    
66     bool syncStartAll();
67
68     // this is the setup API
69     bool registerProcessor(StreamProcessor *processor); ///< start managing a streamprocessor
70     bool unregisterProcessor(StreamProcessor *processor); ///< stop managing a streamprocessor
71
72     bool enableStreamProcessors(unsigned int time_to_enable_at); /// enable registered StreamProcessors
73     bool disableStreamProcessors(); /// disable registered StreamProcessors
74
75     void setPeriodSize(unsigned int period);
76     void setPeriodSize(unsigned int period, unsigned int nb_buffers);
77     int getPeriodSize() {return m_period;};
78
79     void setNbBuffers(unsigned int nb_buffers);
80     int getNbBuffers() {return m_nb_buffers;};
81
82     int getPortCount(enum Port::E_PortType, enum Port::E_Direction);
83     int getPortCount(enum Port::E_Direction);
84     Port* getPortByIndex(int idx, enum Port::E_Direction);
85
86     // the client-side functions
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     int getDelayedUsecs() {return m_delayed_usecs;};
94     bool xrunOccurred();
95     int getXrunCount() {return m_xruns;};
96    
97 private:
98     int m_delayed_usecs;
99     // this stores the time at which the next transfer should occur
100     // usually this is in the past, but it is needed as a timestamp
101     // for the transmit SP's
102     uint64_t m_time_of_transfer;
103    
104 public:
105     bool handleXrun(); ///< reset the streams & buffers after xrun
106
107     bool setThreadParameters(bool rt, int priority);
108
109     virtual void setVerboseLevel(int l);
110     void dumpInfo();
111    
112    
113     // the sync source stuff
114 private:
115     StreamProcessor *m_SyncSource;
116    
117 public:
118     bool setSyncSource(StreamProcessor *s);
119     StreamProcessor * getSyncSource();
120
121    
122 protected:
123     int signalWaiters(); // call this to signal a period boundary
124     // RunnableInterface interface
125     bool Execute(); // note that this is called in we while(running) loop
126     bool Init();
127
128     // thread sync primitives
129     sem_t m_period_semaphore;
130
131     bool m_xrun_happened;
132
133     bool m_thread_realtime;
134     int m_thread_priority;
135
136     // processor list
137     StreamProcessorVector m_ReceiveProcessors;
138     StreamProcessorVector m_TransmitProcessors;
139
140     unsigned int m_nb_buffers;
141     unsigned int m_period;
142     unsigned int m_xruns;
143    
144     IsoHandlerManager *m_isoManager;
145
146     FreebobUtil::PosixThread *m_streamingThread;
147
148     unsigned int m_nbperiods;
149
150     DECLARE_DEBUG_MODULE;
151
152 };
153
154 }
155
156 #endif /* __FREEBOB_STREAMPROCESSORMANAGER__ */
157
158
Note: See TracBrowser for help on using the browser.