root/branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.h

Revision 223, 3.7 kB (checked in by pieterpalmers, 18 years ago)

- this is the first audio capable commit of the 2.0 code
- xrun handling etc.. is not ready yet

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 "FreebobThread.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 typedef std::vector<StreamProcessor *> StreamProcessorVector;
44 typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator;
45
46
47 class StreamProcessorManager :
48                         public FreebobRunnableInterface {
49
50         friend class StreamRunner;
51
52 public:
53
54         StreamProcessorManager(unsigned int period, unsigned int nb_buffers);
55         virtual ~StreamProcessorManager();
56
57         int initialize(); // to be called immediately after the construction
58         bool prepare(); // to be called after the processors are registered
59
60         virtual void setVerboseLevel(int l);
61         void dumpInfo();
62
63         // this is the setup API
64         int unregisterProcessor(StreamProcessor *processor);
65         int registerProcessor(StreamProcessor *processor);
66
67         void setPeriodSize(unsigned int period);
68         void setPeriodSize(unsigned int period, unsigned int nb_buffers);
69         int getPeriodSize() {return m_period;};
70
71         void setNbBuffers(unsigned int nb_buffers);
72         int getNbBuffers() {return m_nb_buffers;};
73
74         int getPortCount(enum Port::E_PortType, enum Port::E_Direction);
75         int getPortCount(enum Port::E_Direction);
76         Port* getPortByIndex(int idx, enum Port::E_Direction);
77
78         // the client-side functions
79         bool xrunOccurred();
80         int getXrunCount() {return m_xruns;};
81
82         int waitForPeriod(); // wait for the next period
83
84         int transfer(); // transfer the buffer contents from/to client
85         int transfer(enum StreamProcessor::EProcessorType); // transfer the buffer contents from/to client
86
87         void reset(); // reset the streams & buffers (e.g. after xrun)
88
89         int registerStreamProcessors(IsoHandlerManager *m);
90
91
92         // the ISO-side functions
93 protected:
94         int signalWaiters(); // call this to signal a period boundary
95         // FreebobRunnableInterface interface
96         bool Execute(); // note that this is called in we while(running) loop
97         bool Init();
98
99         // thread sync primitives
100         sem_t m_period_semaphore;
101         // this may only be written by the packet thread, and read by
102         // the waiting thread. The packet thread terminates if this is
103         // true, therefore it will never by updated again.
104         // it can only be set to true before the period semaphore is
105         // signalled, which the waiting thread is waiting for. Therefore
106         // this variable is protected by the semaphore.
107         bool m_xrun_has_occured;
108
109         // processor list
110         StreamProcessorVector m_ReceiveProcessors;
111         StreamProcessorVector m_TransmitProcessors;
112
113         unsigned int m_nb_buffers;
114         unsigned int m_period;
115         unsigned int m_xruns;
116
117
118     DECLARE_DEBUG_MODULE;
119
120 };
121
122 }
123
124 #endif /* __FREEBOB_STREAMPROCESSORMANAGER__ */
125
126
Note: See TracBrowser for help on using the browser.