diff --git a/src/internal_modules/roc_rtcp/reporter.cpp b/src/internal_modules/roc_rtcp/reporter.cpp index 72aea1c88..644681079 100644 --- a/src/internal_modules/roc_rtcp/reporter.cpp +++ b/src/internal_modules/roc_rtcp/reporter.cpp @@ -1401,7 +1401,7 @@ Reporter::find_stream_(packet::stream_source_t source_id, CreateMode mode) { (unsigned long)source_id); stream = - new(stream_pool_) Stream(stream_pool_, source_id, report_time_, config_.rtt, dumper_); + new(stream_pool_) Stream(arena_, stream_pool_, source_id, report_time_, config_.rtt, dumper_); if (!stream) { report_error_ = status::StatusNoMem; return NULL; diff --git a/src/internal_modules/roc_rtcp/reporter.h b/src/internal_modules/roc_rtcp/reporter.h index 8022a50ec..8ea7b7cfe 100644 --- a/src/internal_modules/roc_rtcp/reporter.h +++ b/src/internal_modules/roc_rtcp/reporter.h @@ -262,14 +262,15 @@ class Reporter : public core::NonCopyable<> { struct Stream : core::RefCounted, core::HashmapNode<>, core::ListNode<> { - Stream(core::IPool &pool, packet::stream_source_t source_id, core::nanoseconds_t report_time, + Stream(core::IArena &arena, core::IPool &pool, packet::stream_source_t source_id, + core::nanoseconds_t report_time, const RttConfig &rtt_config, dbgio::CsvDumper *dumper) : core::RefCounted(pool) , source_id(source_id) , has_remote_recv_report(false) - , remote_recv_rtt(rtt_config, dumper) + , remote_recv_rtt(arena, rtt_config, dumper) , has_remote_send_report(false) - , remote_send_rtt(rtt_config, dumper) + , remote_send_rtt(arena, rtt_config, dumper) , local_recv_report(NULL) , last_update(report_time) , last_local_sr(0) diff --git a/src/internal_modules/roc_rtcp/rtt_estimator.cpp b/src/internal_modules/roc_rtcp/rtt_estimator.cpp index f93401407..32cf4fdae 100644 --- a/src/internal_modules/roc_rtcp/rtt_estimator.cpp +++ b/src/internal_modules/roc_rtcp/rtt_estimator.cpp @@ -12,13 +12,14 @@ namespace roc { namespace rtcp { -RttEstimator::RttEstimator(const RttConfig &config, dbgio::CsvDumper *dumper) +RttEstimator::RttEstimator(core::IArena &arena, const RttConfig &config, dbgio::CsvDumper *dumper) : config_(config) , metrics_() , has_metrics_(false) , first_report_ts_(0) , last_report_ts_(0) - , dumper_(dumper) { + , dumper_(dumper) + , rtt_stats_(arena, 100){ } bool RttEstimator::has_metrics() const { @@ -86,8 +87,14 @@ void RttEstimator::update(core::nanoseconds_t local_report_ts, } last_report_ts_ = local_report_ts; - metrics_.clock_offset = clock_offset; - metrics_.rtt = rtt; + RttOffsetPair p; + p.rtt = rtt; + p.offset = clock_offset; + rtt_stats_.add(p); + RttOffsetPair min = rtt_stats_.mov_min(); + + metrics_.clock_offset = min.offset; + metrics_.rtt = min.rtt; has_metrics_ = true; diff --git a/src/internal_modules/roc_rtcp/rtt_estimator.h b/src/internal_modules/roc_rtcp/rtt_estimator.h index bcb3aa756..3844e7aa1 100644 --- a/src/internal_modules/roc_rtcp/rtt_estimator.h +++ b/src/internal_modules/roc_rtcp/rtt_estimator.h @@ -15,6 +15,7 @@ #include "roc_core/time.h" #include "roc_packet/units.h" #include "roc_dbgio/csv_dumper.h" +#include "roc_stat/mov_aggregate.h" namespace roc { namespace rtcp { @@ -52,7 +53,7 @@ struct RttMetrics { class RttEstimator { public: //! Initialize. - RttEstimator(const RttConfig &config, dbgio::CsvDumper *dumper); + RttEstimator(core::IArena &arena, const RttConfig &config, dbgio::CsvDumper *dumper); //! Check whether metrics are already available. bool has_metrics() const; @@ -83,6 +84,26 @@ class RttEstimator { dbgio::CsvDumper *dumper_; + struct RttOffsetPair { + core::nanoseconds_t rtt; + core::nanoseconds_t offset; + + RttOffsetPair() { + rtt = 10e9; + } + + RttOffsetPair(const int64_t &r) { + rtt = r; + offset = 0; + } + + operator int64_t() const { + return rtt; + } + }; + + stat::MovAggregate rtt_stats_; + }; } // namespace rtcp