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"
18#include "roc_core/attributes.h"
21#include "roc_core/slice.h"
22#include "roc_core/stddefs.h"
23#include "roc_packet/units.h"
24#include "roc_sndio/isink.h"
25#include "roc_sndio/isource.h"
26
27namespace roc {
28namespace sndio {
29
30//! Audio pump.
31//! @remarks
32//! Reads frames from source and writes them to sink.
33class Pump : public core::NonCopyable<> {
34public:
35 //! Pump mode.
36 enum Mode {
37 // Run until the source return EOF.
38 ModePermanent = 0,
39
40 // Run until the source return EOF or become inactive first time.
41 ModeOneshot = 1
42 };
43
44 //! Initialize.
46 ISource& source,
47 ISource* backup_source,
48 ISink& sink,
49 core::nanoseconds_t frame_length,
50 const audio::SampleSpec& sample_spec,
51 Mode mode);
52
53 //! Check if the object was successfulyl constructed.
54 bool is_valid() const;
55
56 //! Run the pump.
57 //! @remarks
58 //! Run until the stop() is called or, if oneshot mode is enabled,
59 //! the source becomes inactive.
61
62 //! Stop the pump.
63 //! @remarks
64 //! May be called from any thread.
65 void stop();
66
67private:
68 bool transfer_frame_(ISource& current_source);
69
70 ISource& main_source_;
71 ISource* backup_source_;
72 ISink& sink_;
73
74 audio::SampleSpec sample_spec_;
75
76 core::Slice<audio::sample_t> frame_buffer_;
77
78 size_t n_bufs_;
79 const bool oneshot_;
80
82};
83
84} // namespace sndio
85} // namespace roc
86
87#endif // ROC_SNDIO_PUMP_H_
Atomic.
Compiler attributes.
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition attributes.h:31
Buffer factory.
Sample specification. Describes sample rate and channels.
Definition sample_spec.h:26
Base class for non-copyable objects.
Definition noncopyable.h:23
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
Sink interface.
Definition isink.h:22
Source interface.
Definition isource.h:23
Audio pump.
Definition pump.h:33
void stop()
Stop the pump.
ROC_ATTR_NODISCARD bool run()
Run the pump.
bool is_valid() const
Check if the object was successfulyl constructed.
Mode
Pump mode.
Definition pump.h:36
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.
Root namespace.
Non-copyable object.
Audio sample.
Sample specifications.
Slice.
Commonly used types and functions.
Various units used in packets.