Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
pump.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Roc authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_sndio/pump.h
10 //! @brief Pump.
11 
12 #ifndef ROC_SNDIO_PUMP_H_
13 #define ROC_SNDIO_PUMP_H_
14 
15 #include "roc_core/atomic.h"
16 #include "roc_core/buffer_pool.h"
17 #include "roc_core/noncopyable.h"
18 #include "roc_core/slice.h"
19 #include "roc_core/stddefs.h"
20 #include "roc_sndio/isink.h"
21 #include "roc_sndio/isource.h"
22 
23 namespace roc {
24 namespace sndio {
25 
26 //! Audio pump.
27 //! @remarks
28 //! Reads frames from source and writes them to sink.
29 class Pump : public core::NonCopyable<> {
30 public:
31  //! Pump mode.
32  enum Mode {
33  // Run until the source return EOF.
34  ModePermanent = 0,
35 
36  // Run until the source return EOF or become inactive first time.
37  ModeOneshot = 1
38  };
39 
40  //! Initialize.
42  ISource& source,
43  ISink& sink,
44  size_t frame_size,
45  Mode mode);
46 
47  //! Check if the object was successfulyl constructed.
48  bool valid() const;
49 
50  //! Run the pump.
51  //! @remarks
52  //! Run until the stop() is called or, if oneshot mode is enabled,
53  //! the source becomes inactive.
54  bool run();
55 
56  //! Stop the pump.
57  //! @remarks
58  //! May be called from any thread.
59  void stop();
60 
61 private:
62  ISource& source_;
63  ISink& sink_;
64 
65  core::Slice<audio::sample_t> frame_buffer_;
66 
67  size_t n_bufs_;
68  const bool oneshot_;
69 
70  core::Atomic stop_;
71 };
72 
73 } // namespace sndio
74 } // namespace roc
75 
76 #endif // ROC_SNDIO_PUMP_H_
bool run()
Run the pump.
Sink interface.
Definition: isink.h:21
Sink interface.
Mode
Pump mode.
Definition: pump.h:32
bool valid() const
Check if the object was successfulyl constructed.
Root namespace.
Audio pump.
Definition: pump.h:29
Pump(core::BufferPool< audio::sample_t > &buffer_pool, ISource &source, ISink &sink, size_t frame_size, Mode mode)
Initialize.
Atomic integer.
Definition: atomic.h:21
Commonly used types and functions.
Source interface.
Base class for non-copyable objects.
Definition: noncopyable.h:23
Atomic integer.
Slice.
Buffer pool.
Non-copyable object.
void stop()
Stop the pump.
Source interface.
Definition: isource.h:21