Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
rtt_estimator.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_rtcp/rtt_estimator.h
10 //! @brief Round-trip time estimator.
11 
12 #ifndef ROC_RTCP_RTT_ESTIMATOR_H_
13 #define ROC_RTCP_RTT_ESTIMATOR_H_
14 
15 #include "roc_core/time.h"
16 #include "roc_packet/units.h"
17 
18 namespace roc {
19 namespace rtcp {
20 
21 //! Round-trip time metrics.
22 struct RttConfig {
23  //! Measurement interval duration.
24  //! All metrics below are computed for a sliding window of this length.
26 
27  RttConfig()
28  : interval_duration(core::Second * 5) {
29  }
30 };
31 
32 //! Round-trip time metrics.
33 struct RttMetrics {
34  //! Estimated offset of remote clock relative to local clock.
35  //! Estimated based on RTT and local/remote timestamp.
37 
38  //! Estimated round-trip time.
40 
41  RttMetrics()
42  : clock_offset(0)
43  , rtt(0) {
44  }
45 };
46 
47 //! Round-trip time estimator.
48 //! Created inside rtcp::Reporter for each RTP stream.
49 //! Continously computes RTT and clock offset based on LSR/DLSR
50 //! or LRR/DLRR timestamps.
51 class RttEstimator {
52 public:
53  //! Initialize.
54  RttEstimator(const RttConfig& config);
55 
56  //! Check whether metrics are already available.
57  bool has_metrics() const;
58 
59  //! Get estimated metrics.
60  const RttMetrics& metrics() const;
61 
62  //! Update metrics with new data.
63  //! Parameters:
64  //! - @p local_report_ts - local unix time when we've sent report
65  //! - @p remote_report_ts - remote unix time when they've received our report
66  //! - @p remote_reply_ts - remote unix time when they've send reply report
67  //! - @p local_reply_ts - local unix time when we've received their reply
68  void update(core::nanoseconds_t local_report_ts,
69  core::nanoseconds_t remote_report_ts,
70  core::nanoseconds_t remote_reply_ts,
71  core::nanoseconds_t local_reply_ts);
72 
73 private:
74  const RttConfig config_;
75  RttMetrics metrics_;
76  bool has_metrics_;
77 
78  core::nanoseconds_t first_report_ts_;
79  core::nanoseconds_t last_report_ts_;
80 };
81 
82 } // namespace rtcp
83 } // namespace roc
84 
85 #endif // ROC_RTCP_RTT_ESTIMATOR_H_
Round-trip time estimator. Created inside rtcp::Reporter for each RTP stream. Continously computes RT...
Definition: rtt_estimator.h:51
RttEstimator(const RttConfig &config)
Initialize.
void update(core::nanoseconds_t local_report_ts, core::nanoseconds_t remote_report_ts, core::nanoseconds_t remote_reply_ts, core::nanoseconds_t local_reply_ts)
Update metrics with new data. Parameters:
bool has_metrics() const
Check whether metrics are already available.
const RttMetrics & metrics() const
Get estimated metrics.
const nanoseconds_t Second
One second represented in nanoseconds.
Definition: time.h:70
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
Root namespace.
Round-trip time metrics.
Definition: rtt_estimator.h:22
core::nanoseconds_t interval_duration
Measurement interval duration. All metrics below are computed for a sliding window of this length.
Definition: rtt_estimator.h:25
Round-trip time metrics.
Definition: rtt_estimator.h:33
core::nanoseconds_t clock_offset
Estimated offset of remote clock relative to local clock. Estimated based on RTT and local/remote tim...
Definition: rtt_estimator.h:36
core::nanoseconds_t rtt
Estimated round-trip time.
Definition: rtt_estimator.h:39
Time definitions.
Various units used in packets.