Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
pump.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Roc Streaming 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_audio/sample.h"
17#include "roc_core/atomic.h"
20#include "roc_core/slice.h"
21#include "roc_core/stddefs.h"
22#include "roc_packet/units.h"
23#include "roc_sndio/isink.h"
24#include "roc_sndio/isource.h"
25
26namespace roc {
27namespace sndio {
28
29//! Audio pump.
30//! @remarks
31//! Reads frames from source and writes them to sink.
32class Pump : public core::NonCopyable<> {
33public:
34 //! Pump mode.
35 enum Mode {
36 // Run until the source return EOF.
37 ModePermanent = 0,
38
39 // Run until the source return EOF or become inactive first time.
40 ModeOneshot = 1
41 };
42
43 //! Initialize.
45 ISource& source,
46 ISource* backup_source,
47 ISink& sink,
48 core::nanoseconds_t frame_length,
49 const audio::SampleSpec& sample_spec,
50 Mode mode);
51
52 //! Check if the object was successfulyl constructed.
53 bool valid() const;
54
55 //! Run the pump.
56 //! @remarks
57 //! Run until the stop() is called or, if oneshot mode is enabled,
58 //! the source becomes inactive.
59 bool run();
60
61 //! Stop the pump.
62 //! @remarks
63 //! May be called from any thread.
64 void stop();
65
66private:
67 ISource& main_source_;
68 ISource* backup_source_;
69 ISink& sink_;
70
71 audio::SampleSpec sample_spec_;
72
73 core::Slice<audio::sample_t> frame_buffer_;
74
75 size_t n_bufs_;
76 const bool oneshot_;
77
79};
80
81} // namespace sndio
82} // namespace roc
83
84#endif // ROC_SNDIO_PUMP_H_
Atomic.
Buffer factory.
Sample stream specification. Defines sample rate and channel layout.
Definition sample_spec.h:24
Atomic integer. Provides sequential consistency. For a fine-grained memory order control,...
Definition atomic.h:26
Base class for non-copyable objects.
Definition noncopyable.h:23
Sink interface.
Definition isink.h:22
Source interface.
Definition isource.h:23
Audio pump.
Definition pump.h:32
void stop()
Stop the pump.
bool run()
Run the pump.
Mode
Pump mode.
Definition pump.h:35
bool valid() const
Check if the object was successfulyl constructed.
Pump(core::BufferFactory< audio::sample_t > &buffer_factory, ISource &source, ISource *backup_source, ISink &sink, core::nanoseconds_t frame_length, const audio::SampleSpec &sample_spec, Mode mode)
Initialize.
Sink interface.
Source interface.
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
Root namespace.
Non-copyable object.
Audio sample.
Sample specifications.
Slice.
Commonly used types and functions.
Various units used in packets.