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/frame_factory.h
"
16
#include "
roc_audio/sample.h
"
17
#include "
roc_audio/sample_spec.h
"
18
#include "
roc_core/atomic.h
"
19
#include "
roc_core/attributes.h
"
20
#include "
roc_core/ipool.h
"
21
#include "
roc_core/noncopyable.h
"
22
#include "
roc_core/slice.h
"
23
#include "
roc_core/stddefs.h
"
24
#include "
roc_packet/units.h
"
25
#include "
roc_sndio/isink.h
"
26
#include "
roc_sndio/isource.h
"
27
28
namespace
roc
{
29
namespace
sndio {
30
31
//! Audio pump.
32
//! @remarks
33
//! Reads frames from source and writes them to sink.
34
class
Pump
:
public
core::NonCopyable
<> {
35
public
:
36
//! Pump mode.
37
enum
Mode
{
38
// Run until the source return EOF.
39
ModePermanent = 0,
40
41
// Run until the source return EOF or become inactive first time.
42
ModeOneshot = 1
43
};
44
45
//! Initialize.
46
Pump
(
core::IPool
& buffer_pool,
47
ISource
& source,
48
ISource
* backup_source,
49
ISink
& sink,
50
core::nanoseconds_t
frame_length,
51
const
audio::SampleSpec
& sample_spec,
52
Mode
mode);
53
54
//! Check if the object was successfulyl constructed.
55
bool
is_valid
()
const
;
56
57
//! Run the pump.
58
//! @remarks
59
//! Run until the stop() is called or, if oneshot mode is enabled,
60
//! the source becomes inactive.
61
ROC_ATTR_NODISCARD
bool
run
();
62
63
//! Stop the pump.
64
//! @remarks
65
//! May be called from any thread.
66
void
stop
();
67
68
private
:
69
bool
transfer_frame_(
ISource
& current_source);
70
71
audio::FrameFactory
frame_factory_;
72
73
ISource
& main_source_;
74
ISource
* backup_source_;
75
ISink
& sink_;
76
77
audio::SampleSpec
sample_spec_;
78
79
core::Slice<audio::sample_t>
frame_buffer_;
80
81
size_t
n_bufs_;
82
const
bool
oneshot_;
83
84
core::Atomic<int>
stop_;
85
};
86
87
}
// namespace sndio
88
}
// namespace roc
89
90
#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
roc::audio::FrameFactory
Frame factory.
Definition:
frame_factory.h:38
roc::audio::SampleSpec
Sample specification. Describes sample rate and channels.
Definition:
sample_spec.h:30
roc::core::Atomic< int >
roc::core::IPool
Memory pool interface.
Definition:
ipool.h:23
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:34
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:37
roc::sndio::Pump::Pump
Pump(core::IPool &buffer_pool, ISource &source, ISource *backup_source, ISink &sink, core::nanoseconds_t frame_length, const audio::SampleSpec &sample_spec, Mode mode)
Initialize.
frame_factory.h
Frame factory.
ipool.h
Memory pool interface.
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