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 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
"
16
#include "
roc_audio/sample_spec.h
"
17
#include "
roc_core/atomic.h
"
18
#include "
roc_core/attributes.h
"
19
#include "
roc_core/buffer_factory.h
"
20
#include "
roc_core/noncopyable.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
27
namespace
roc
{
28
namespace
sndio {
29
30
//! Audio pump.
31
//! @remarks
32
//! Reads frames from source and writes them to sink.
33
class
Pump
:
public
core::NonCopyable
<> {
34
public
:
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.
45
Pump
(
core::BufferFactory<audio::sample_t>
& buffer_factory,
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.
60
ROC_ATTR_NODISCARD
bool
run
();
61
62
//! Stop the pump.
63
//! @remarks
64
//! May be called from any thread.
65
void
stop
();
66
67
private
:
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
81
core::Atomic<int>
stop_;
82
};
83
84
}
// namespace sndio
85
}
// namespace roc
86
87
#endif
// ROC_SNDIO_PUMP_H_
atomic.h
Atomic.
attributes.h
Compiler attributes.
ROC_ATTR_NODISCARD
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition:
attributes.h:31
buffer_factory.h
Buffer factory.
roc::audio::SampleSpec
Sample specification. Describes sample rate and channels.
Definition:
sample_spec.h:26
roc::core::Atomic< int >
roc::core::BufferFactory< audio::sample_t >
roc::core::NonCopyable
Base class for non-copyable objects.
Definition:
noncopyable.h:23
roc::core::Slice< audio::sample_t >
roc::sndio::ISink
Sink interface.
Definition:
isink.h:22
roc::sndio::ISource
Source interface.
Definition:
isource.h:23
roc::sndio::Pump
Audio pump.
Definition:
pump.h:33
roc::sndio::Pump::stop
void stop()
Stop the pump.
roc::sndio::Pump::run
ROC_ATTR_NODISCARD bool run()
Run the pump.
roc::sndio::Pump::is_valid
bool is_valid() const
Check if the object was successfulyl constructed.
roc::sndio::Pump::Mode
Mode
Pump mode.
Definition:
pump.h:36
roc::sndio::Pump::Pump
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.
isink.h
Sink interface.
isource.h
Source interface.
roc::core::nanoseconds_t
int64_t nanoseconds_t
Nanoseconds.
Definition:
time.h:58
roc
Root namespace.
noncopyable.h
Non-copyable object.
sample.h
Audio sample.
sample_spec.h
Sample specifications.
slice.h
Slice.
stddefs.h
Commonly used types and functions.
units.h
Various units used in packets.
roc_sndio
pump.h
Generated by
1.9.1