Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
feedback_monitor.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2024 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_audio/feedback_monitor.h
10
//! @brief Feedback monitor.
11
12
#ifndef ROC_AUDIO_FEEDBACK_MONITOR_H_
13
#define ROC_AUDIO_FEEDBACK_MONITOR_H_
14
15
#include "
roc_audio/iframe_writer.h
"
16
#include "
roc_audio/latency_tuner.h
"
17
#include "
roc_audio/packetizer.h
"
18
#include "
roc_audio/resampler_writer.h
"
19
#include "
roc_audio/sample_spec.h
"
20
#include "
roc_core/noncopyable.h
"
21
#include "
roc_core/rate_limiter.h
"
22
#include "
roc_core/time.h
"
23
#include "
roc_packet/ilink_meter.h
"
24
25
namespace
roc
{
26
namespace
audio
{
27
28
//! Feedback monitor configuration.
29
struct
FeedbackConfig {
30
//! Timeout for source feedback.
31
//! If there is no new feedback during timeout, feedback monitor resets state.
32
core::nanoseconds_t
source_timeout
;
33
34
//! Cooldown period between source changes.
35
//! After source is change, another source change is now allowed during
36
//! this period and is ignored.
37
core::nanoseconds_t
source_cooldown
;
38
39
FeedbackConfig()
40
:
source_timeout
(1500 *
core
::Millisecond)
41
,
source_cooldown
(50 *
core
::Millisecond) {
42
}
43
};
44
45
//! Feedback monitor.
46
//!
47
//! @b Features
48
//!
49
//! - handles latency metrics from receiver (obtained via RTCP)
50
//! - asks LatencyTuner to calculate scaling factor based on the actual and
51
//! target latencies
52
//! - passes calculated scaling factor to resampler
53
//!
54
//! @b Flow
55
//!
56
//! - when pipeline obtains RTCP report, it calls write_metrics() method
57
//! - pipeline periodically calls write() method; it passes latest metrics
58
//! to LatencyTuner, and obtains scaling factor for resampler
59
//! - feedback monitor has a reference to resampler, and periodically passes
60
//! updated scaling factor to it
61
//! - pipeline also can query feedback monitor for latency metrics on behalf of
62
//! request from user
63
class
FeedbackMonitor
:
public
IFrameWriter
,
public
core::NonCopyable
<> {
64
public
:
65
//! Constructor.
66
FeedbackMonitor
(
IFrameWriter
& writer,
67
Packetizer
& packetizer,
68
ResamplerWriter
* resampler,
69
const
FeedbackConfig
& feedback_config,
70
const
LatencyConfig
& latency_config,
71
const
SampleSpec
& sample_spec);
72
73
//! Check if the object was initialized successfully.
74
bool
is_valid
()
const
;
75
76
//! Check if feedback monitoring is started.
77
bool
is_started
()
const
;
78
79
//! Enable feedback monitoring.
80
void
start
();
81
82
//! Process feedback from receiver.
83
void
process_feedback
(
packet::stream_source_t
source_id,
84
const
LatencyMetrics
&
latency_metrics
,
85
const
packet::LinkMetrics
&
link_metrics
);
86
87
//! Write audio frame.
88
//! Passes frame to underlying writer.
89
//! If feedback monitoring is started, also performs latency tuning.
90
virtual
void
write
(
Frame
& frame);
91
92
//! Get number of remote participants from which there is feedback.
93
size_t
num_participants
()
const
;
94
95
//! Get latest latency metrics for session.
96
//! @p party_index should be in range [0; num_participants()-1].
97
const
LatencyMetrics
&
latency_metrics
(
size_t
party_index)
const
;
98
99
//! Get latest link metrics for session.
100
//! @p party_index should be in range [0; num_participants()-1].
101
const
packet::LinkMetrics
&
link_metrics
(
size_t
party_index)
const
;
102
103
private
:
104
bool
update_tuner_(
packet::stream_timestamp_t
duration);
105
106
bool
init_scaling_();
107
bool
update_scaling_();
108
109
LatencyTuner
tuner_;
110
111
LatencyMetrics
latency_metrics_;
112
packet::LinkMetrics
link_metrics_;
113
bool
use_packetizer_;
114
115
bool
has_feedback_;
116
core::nanoseconds_t
last_feedback_ts_;
117
const
core::nanoseconds_t
feedback_timeout_;
118
119
Packetizer
& packetizer_;
120
IFrameWriter
& writer_;
121
122
ResamplerWriter
* resampler_;
123
const
bool
enable_scaling_;
124
125
packet::stream_source_t
source_;
126
core::RateLimiter
source_change_limiter_;
127
128
const
SampleSpec
sample_spec_;
129
130
bool
started_;
131
bool
valid_;
132
};
133
134
}
// namespace audio
135
}
// namespace roc
136
137
#endif
// ROC_AUDIO_FEEDBACK_MONITOR_H_
roc::audio::FeedbackMonitor::process_feedback
void process_feedback(packet::stream_source_t source_id, const LatencyMetrics &latency_metrics, const packet::LinkMetrics &link_metrics)
Process feedback from receiver.
roc::audio::FeedbackMonitor::is_started
bool is_started() const
Check if feedback monitoring is started.
roc::audio::FeedbackMonitor::start
void start()
Enable feedback monitoring.
roc::audio::FeedbackMonitor::is_valid
bool is_valid() const
Check if the object was initialized successfully.
roc::audio::FeedbackMonitor::write
virtual void write(Frame &frame)
Write audio frame. Passes frame to underlying writer. If feedback monitoring is started,...
roc::audio::FeedbackMonitor::num_participants
size_t num_participants() const
Get number of remote participants from which there is feedback.
roc::audio::FeedbackMonitor::link_metrics
const packet::LinkMetrics & link_metrics(size_t party_index) const
Get latest link metrics for session. party_index should be in range [0; num_participants()-1].
roc::audio::FeedbackMonitor::FeedbackMonitor
FeedbackMonitor(IFrameWriter &writer, Packetizer &packetizer, ResamplerWriter *resampler, const FeedbackConfig &feedback_config, const LatencyConfig &latency_config, const SampleSpec &sample_spec)
Constructor.
roc::audio::FeedbackMonitor::latency_metrics
const LatencyMetrics & latency_metrics(size_t party_index) const
Get latest latency metrics for session. party_index should be in range [0; num_participants()-1].
roc::audio::Frame
Audio frame.
Definition
frame.h:25
roc::audio::IFrameWriter
Frame writer interface.
Definition
iframe_writer.h:22
roc::audio::LatencyTuner
Latency tuner.
Definition
latency_tuner.h:167
roc::audio::Packetizer
Packetizer.
Definition
packetizer.h:49
roc::audio::ResamplerWriter
Resampler element for writing pipeline.
Definition
resampler_writer.h:31
roc::audio::SampleSpec
Sample specification. Describes sample rate and channels.
Definition
sample_spec.h:30
roc::core::NonCopyable
Base class for non-copyable objects.
Definition
noncopyable.h:23
roc::core::RateLimiter
Rate limiter.
Definition
rate_limiter.h:22
iframe_writer.h
Frame writer interface.
ilink_meter.h
Link meter interface.
latency_tuner.h
Latency tuner.
roc::audio
Audio frames and audio processing.
roc::core
General-purpose building blocks and platform abstraction layer.
roc::core::nanoseconds_t
int64_t nanoseconds_t
Nanoseconds.
Definition
time.h:58
roc::packet::stream_source_t
uint32_t stream_source_t
Packet stream identifier.
Definition
units.h:27
roc::packet::stream_timestamp_t
uint32_t stream_timestamp_t
Packet stream timestamp.
Definition
units.h:36
roc
Root namespace.
noncopyable.h
Non-copyable object.
packetizer.h
Packetizer.
rate_limiter.h
Rate limiter.
resampler_writer.h
Resampler.
sample_spec.h
Sample specifications.
roc::audio::FeedbackConfig
Feedback monitor configuration.
Definition
feedback_monitor.h:29
roc::audio::FeedbackConfig::source_cooldown
core::nanoseconds_t source_cooldown
Cooldown period between source changes. After source is change, another source change is now allowed ...
Definition
feedback_monitor.h:37
roc::audio::FeedbackConfig::source_timeout
core::nanoseconds_t source_timeout
Timeout for source feedback. If there is no new feedback during timeout, feedback monitor resets stat...
Definition
feedback_monitor.h:32
roc::audio::LatencyConfig
Latency settings.
Definition
latency_tuner.h:64
roc::audio::LatencyMetrics
Latency-related metrics.
Definition
latency_tuner.h:133
roc::packet::LinkMetrics
Link metrics.
Definition
ilink_meter.h:23
time.h
Time definitions.
roc_audio
feedback_monitor.h
Generated by
1.17.0