Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
watchdog.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2018 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/watchdog.h
10
//! @brief Watchdog.
11
12
#ifndef ROC_AUDIO_WATCHDOG_H_
13
#define ROC_AUDIO_WATCHDOG_H_
14
15
#include "
roc_audio/iframe_reader.h
"
16
#include "
roc_audio/sample_spec.h
"
17
#include "
roc_core/array.h
"
18
#include "
roc_core/attributes.h
"
19
#include "
roc_core/iarena.h
"
20
#include "
roc_core/noncopyable.h
"
21
#include "
roc_core/time.h
"
22
#include "
roc_packet/units.h
"
23
24
namespace
roc
{
25
namespace
audio
{
26
27
//! Watchdog parameters.
28
struct
WatchdogConfig
{
29
//! Timeout for the lack of packets, nanoseconds.
30
//! @remarks
31
//! Maximum allowed period during which every frame is blank. After this period,
32
//! the session is terminated. This mechanism allows to detect dead, hanging, or
33
//! broken clients.
34
//! @note
35
//! If zero, default value is used.
36
//! If negative, the check is disabled.
37
core::nanoseconds_t
no_playback_timeout
;
38
39
//! Timeout for frequent stuttering, nanoseconds.
40
//! @remarks
41
//! Maximum allowed period during which every drop detection window overlaps with
42
//! at least one frame which caused packet drops and with at least one frame which
43
//! is incomplete (it may be the same frame). After this period, the session is
44
//! terminated. This mechanism allows to detect the vicious circle when all client
45
//! packets are a bit late and we are constantly dropping them producing unpleasant
46
//! noise.
47
//! @note
48
//! If zero, default value is used.
49
//! If negative, the check is disabled.
50
core::nanoseconds_t
choppy_playback_timeout
;
51
52
//! Window size of detecting stuttering, nanoseconds.
53
//! @see choppy_playback_timeout
54
//! @note
55
//! If zero, default value is used.
56
core::nanoseconds_t
choppy_playback_window
;
57
58
//! Duration of the warmup phase in the beginning, nanoseconds
59
//! @remarks
60
//! During the warmup phase blank_timeout is not triggered. After this period last
61
//! position before blank frames is set to the current position. Warmup can also
62
//! be terminated in case a non-blank frame occurs during it. This mechanism allows
63
//! watchdog to work with latency longer than no_playback_timeout. Usually is equal
64
//! to target_latency.
65
//! @note
66
//! If zero, default value is used.
67
//! If negative, warmup phase is disabled.
68
core::nanoseconds_t
warmup_duration
;
69
70
//! Frame status window size for logging, number of frames.
71
//! @remarks
72
//! Used for debug logging. Set to zero to disable.
73
//! @note
74
//! If zero, default value is used.
75
size_t
frame_status_window
;
76
77
//! Initialize config with default values.
78
WatchdogConfig
()
79
:
no_playback_timeout
(0)
80
,
choppy_playback_timeout
(0)
81
,
choppy_playback_window
(0)
82
,
warmup_duration
(0)
83
,
frame_status_window
(0) {
84
}
85
86
//! Automatically fill missing settings.
87
void
deduce_defaults
(
const
core::nanoseconds_t
target_latency);
88
};
89
90
//! Watchdog.
91
//! @remarks
92
//! Terminates session if it is considered dead or corrupted.
93
class
Watchdog
:
public
IFrameReader
,
public
core::NonCopyable
<> {
94
public
:
95
//! Initialize.
96
Watchdog
(
IFrameReader
& reader,
97
const
SampleSpec
& sample_spec,
98
const
WatchdogConfig
& config,
99
core::IArena
& arena);
100
101
//! Check if object is successfully constructed.
102
bool
is_valid
()
const
;
103
104
//! Check if stream is still alive.
105
//! @returns
106
//! false if during the session timeout each frame has an empty flag or the maximum
107
//! allowed number of consecutive windows that can contain frames that aren't fully
108
//! filled and contain dropped packets was exceeded.
109
bool
is_alive
()
const
;
110
111
//! Read audio frame.
112
//! @remarks
113
//! Updates stream state and reads frame from the input reader.
114
virtual
bool
read
(
Frame
& frame);
115
116
private
:
117
void
update_blank_timeout_(
const
Frame
& frame,
118
packet::stream_timestamp_t
next_read_pos);
119
bool
check_blank_timeout_()
const
;
120
121
void
update_drops_timeout_(
const
Frame
& frame,
122
packet::stream_timestamp_t
next_read_pos);
123
bool
check_drops_timeout_();
124
125
void
update_warmup_();
126
127
void
update_status_(
const
Frame
& frame);
128
void
flush_status_();
129
130
IFrameReader
& reader_;
131
132
const
SampleSpec
sample_spec_;
133
134
packet::stream_timestamp_t
max_blank_duration_;
135
packet::stream_timestamp_t
max_drops_duration_;
136
packet::stream_timestamp_t
drops_detection_window_;
137
138
packet::stream_timestamp_t
curr_read_pos_;
139
packet::stream_timestamp_t
last_pos_before_blank_;
140
packet::stream_timestamp_t
last_pos_before_drops_;
141
142
packet::stream_timestamp_t
warmup_duration_;
143
bool
in_warmup_;
144
145
unsigned
curr_window_flags_;
146
147
core::Array<char>
status_;
148
size_t
status_pos_;
149
bool
show_status_;
150
151
bool
alive_;
152
bool
valid_;
153
};
154
155
}
// namespace audio
156
}
// namespace roc
157
158
#endif
// ROC_AUDIO_WATCHDOG_H_
array.h
Dynamic array.
attributes.h
Compiler attributes.
roc::audio::Frame
Audio frame.
Definition
frame.h:25
roc::audio::IFrameReader
Frame reader interface.
Definition
iframe_reader.h:22
roc::audio::SampleSpec
Sample specification. Describes sample rate and channels.
Definition
sample_spec.h:30
roc::audio::Watchdog::read
virtual bool read(Frame &frame)
Read audio frame.
roc::audio::Watchdog::is_valid
bool is_valid() const
Check if object is successfully constructed.
roc::audio::Watchdog::is_alive
bool is_alive() const
Check if stream is still alive.
roc::audio::Watchdog::Watchdog
Watchdog(IFrameReader &reader, const SampleSpec &sample_spec, const WatchdogConfig &config, core::IArena &arena)
Initialize.
roc::core::Array
Dynamic array.
Definition
array.h:40
roc::core::IArena
Memory arena interface.
Definition
iarena.h:23
roc::core::NonCopyable
Base class for non-copyable objects.
Definition
noncopyable.h:23
iarena.h
Memory arena interface.
iframe_reader.h
Frame reader interface.
roc::audio
Audio frames and audio processing.
roc::core::nanoseconds_t
int64_t nanoseconds_t
Nanoseconds.
Definition
time.h:58
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.
sample_spec.h
Sample specifications.
roc::audio::WatchdogConfig
Watchdog parameters.
Definition
watchdog.h:28
roc::audio::WatchdogConfig::choppy_playback_window
core::nanoseconds_t choppy_playback_window
Window size of detecting stuttering, nanoseconds.
Definition
watchdog.h:56
roc::audio::WatchdogConfig::WatchdogConfig
WatchdogConfig()
Initialize config with default values.
Definition
watchdog.h:78
roc::audio::WatchdogConfig::deduce_defaults
void deduce_defaults(const core::nanoseconds_t target_latency)
Automatically fill missing settings.
roc::audio::WatchdogConfig::choppy_playback_timeout
core::nanoseconds_t choppy_playback_timeout
Timeout for frequent stuttering, nanoseconds.
Definition
watchdog.h:50
roc::audio::WatchdogConfig::frame_status_window
size_t frame_status_window
Frame status window size for logging, number of frames.
Definition
watchdog.h:75
roc::audio::WatchdogConfig::no_playback_timeout
core::nanoseconds_t no_playback_timeout
Timeout for the lack of packets, nanoseconds.
Definition
watchdog.h:37
roc::audio::WatchdogConfig::warmup_duration
core::nanoseconds_t warmup_duration
Duration of the warmup phase in the beginning, nanoseconds.
Definition
watchdog.h:68
time.h
Time definitions.
units.h
Various units used in packets.
roc_audio
watchdog.h
Generated by
1.17.0