Async  0.18.0
AsyncAudioSource.h
Go to the documentation of this file.
1 
28 #ifndef ASYNC_AUDIO_SOURCE_INCLUDED
29 #define ASYNC_AUDIO_SOURCE_INCLUDED
30 
31 
32 /****************************************************************************
33  *
34  * System Includes
35  *
36  ****************************************************************************/
37 
38 #include <cassert>
39 
40 
41 /****************************************************************************
42  *
43  * Project Includes
44  *
45  ****************************************************************************/
46 
47 
48 
49 /****************************************************************************
50  *
51  * Local Includes
52  *
53  ****************************************************************************/
54 
55 
56 
57 /****************************************************************************
58  *
59  * Forward declarations
60  *
61  ****************************************************************************/
62 
63 
64 
65 /****************************************************************************
66  *
67  * Namespace
68  *
69  ****************************************************************************/
70 
71 namespace Async
72 {
73 
74 
75 /****************************************************************************
76  *
77  * Forward declarations of classes inside of the declared namespace
78  *
79  ****************************************************************************/
80 
81 class AudioSink;
82 
83 
84 /****************************************************************************
85  *
86  * Defines & typedefs
87  *
88  ****************************************************************************/
89 
90 
91 
92 /****************************************************************************
93  *
94  * Exported Global Variables
95  *
96  ****************************************************************************/
97 
98 
99 
100 /****************************************************************************
101  *
102  * Class definitions
103  *
104  ****************************************************************************/
105 
115 {
116  public:
121  : m_sink(0), m_sink_managed(false), m_handler(0), is_flushing(false)
122  {
123  }
124 
128  virtual ~AudioSource(void);
129 
137  bool registerSink(AudioSink *sink, bool managed=false);
138 
142  void unregisterSink(void);
143 
148  bool isRegistered(void) const { return m_sink != 0; }
149 
155  AudioSink *sink(void) const { return m_sink; }
156 
165  bool sinkManaged(void) const { return m_sink_managed; }
166 
175  {
176  is_flushing = false;
178  }
179 
188  virtual void resumeOutput(void)
189  {
190  assert(m_handler != 0);
191  m_handler->resumeOutput();
192  }
193 
194 
195  protected:
205  virtual void allSamplesFlushed(void)
206  {
207  assert(m_handler != 0);
208  m_handler->handleAllSamplesFlushed();
209  }
210 
211  /*
212  * @brief Write samples to the connected sink
213  * @param samples The buffer containing the samples to write
214  * @param len The number of samples in the buffer
215  * @return Return the number of samples that was taken care of
216  *
217  * This function is used by the inheriting class to write samples to
218  * the connected sink, if any. If there is no connected sink, the samples
219  * will be thrown away. This function will return the number of samples
220  * that was taken care of. Samples that was not taken care of should
221  * normally be written again to the sink.
222  */
223  int sinkWriteSamples(const float *samples, int len);
224 
225  /*
226  * @brief Tell the sink to flush any buffered samples
227  *
228  * This function is used by the inheriting class to tell the connected
229  * sink to flush its buffered samples. When the sink have flushed all its
230  * samples it will call the allSamplesFlushed function in this class.
231  * If there is no registered sink the allSamplesFlushed function will be
232  * called right away.
233  */
234  void sinkFlushSamples(void);
235 
246 
247  /*
248  * @brief Return the handler
249  * @return Returns the handler previously set with setHandler or 0
250  * if none have been set
251  */
252  AudioSource *handler(void) const { return m_handler; }
253 
257  void clearHandler(void);
258 
259 
260  private:
261  AudioSink *m_sink;
262  bool m_sink_managed;
263  AudioSource *m_handler;
264  bool m_auto_unreg_source;
265  bool is_flushing;
266 
267  bool registerSinkInternal(AudioSink *sink, bool managed, bool reg);
268  void unregisterSinkInternal(bool is_being_destroyed);
269 
270 }; /* class AudioSource */
271 
272 
273 } /* namespace */
274 
275 #endif /* ASYNC_AUDIO_SOURCE_INCLUDED */
276 
277 
278 
279 /*
280  * This file has not been truncated
281  */
282