Skip to content

Commit

Permalink
roc-streaminggh-675 Pass jitter and niq_latency to FeedbackMonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Jan 26, 2024
1 parent a426853 commit 25820a0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
20 changes: 18 additions & 2 deletions src/internal_modules/roc_audio/feedback_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ FeedbackMonitor::FeedbackMonitor(IFrameWriter& writer,
, e2e_latency_(0)
, has_niq_latency_(false)
, has_e2e_latency_(false)
, jitter_(0)
, has_jitter_(false)
, target_latency_(fe_input_ != audio::FreqEstimatorInput_Disable
? sample_spec.ns_2_stream_timestamp_delta(config.target_latency)
: 0)
Expand Down Expand Up @@ -105,6 +107,8 @@ FeedbackMonitorMetrics FeedbackMonitor::metrics() const {
roc_panic_if(!is_valid());

FeedbackMonitorMetrics metrics;
metrics.jitter = sample_spec_.stream_timestamp_delta_2_ns(jitter_);
metrics.niq_latency = sample_spec_.stream_timestamp_delta_2_ns(niq_latency_);
metrics.e2e_latency = sample_spec_.stream_timestamp_delta_2_ns(e2e_latency_);

return metrics;
Expand All @@ -128,6 +132,16 @@ void FeedbackMonitor::store(const FeedbackMonitorMetrics& metrics) {
return;
}

if (metrics.jitter != 0) {
jitter_ = sample_spec_.ns_2_stream_timestamp_delta(metrics.jitter);
has_jitter_ = true;
}

if (metrics.niq_latency != 0) {
niq_latency_ = sample_spec_.ns_2_stream_timestamp_delta(metrics.niq_latency);
has_niq_latency_ = true;
}

if (metrics.e2e_latency != 0) {
e2e_latency_ = sample_spec_.ns_2_stream_timestamp_delta(metrics.e2e_latency);
has_e2e_latency_ = true;
Expand Down Expand Up @@ -229,7 +243,7 @@ void FeedbackMonitor::report_() {
return;
}

if (!has_e2e_latency_ && !has_niq_latency_) {
if (!has_e2e_latency_ && !has_niq_latency_ && !has_jitter_) {
return;
}

Expand All @@ -249,10 +263,12 @@ void FeedbackMonitor::report_() {
roc_log(LogDebug,
"feedback monitor:"
" e2e_latency=%ld(%.3fms) niq_latency=%ld(%.3fms) target_latency=%ld(%.3fms)"
" jitter=%ld(%.3fms)"
" fe=%.6f trim_fe=%.6f",
(long)e2e_latency_, timestamp_to_ms(sample_spec_, e2e_latency_),
(long)niq_latency_, timestamp_to_ms(sample_spec_, niq_latency_),
(long)target_latency_, timestamp_to_ms(sample_spec_, target_latency_),
(long)jitter_, timestamp_to_ms(sample_spec_, jitter_), (long)target_latency_,
timestamp_to_ms(sample_spec_, target_latency_),
(double)(fe_ ? fe_->freq_coeff() : 0), (double)freq_coeff_);
}

Expand Down
20 changes: 17 additions & 3 deletions src/internal_modules/roc_audio/feedback_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,24 @@ namespace audio {

//! Metrics for feedback monitor.
struct FeedbackMonitorMetrics {
//! Estimated interarrival jitter.
//! An estimate of the statistical variance of the RTP data packet
//! interarrival time.
core::nanoseconds_t jitter;

//! Estimated network incoming queue latency.
//! An estimate of how much media is buffered in receiver packet queue.
core::nanoseconds_t niq_latency;

//! Estimated end-to-end latency.
//! An estimate of the time from recording a frame on sender to
//! playing it on receiver.
//! An estimate of the time from recording a frame on sender to playing it
//! on receiver.
core::nanoseconds_t e2e_latency;

FeedbackMonitorMetrics()
: e2e_latency(0) {
: jitter(0)
, niq_latency(0)
, e2e_latency(0) {
}
};

Expand Down Expand Up @@ -94,6 +105,9 @@ class FeedbackMonitor : public IFrameWriter, public core::NonCopyable<> {
bool has_niq_latency_;
bool has_e2e_latency_;

packet::stream_timestamp_diff_t jitter_;
bool has_jitter_;

const packet::stream_timestamp_diff_t target_latency_;

const SampleSpec sample_spec_;
Expand Down
2 changes: 2 additions & 0 deletions src/internal_modules/roc_pipeline/sender_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ SenderSession::notify_send_stream(packet::stream_source_t recv_source_id,

if (feedback_monitor_ && feedback_monitor_->is_started()) {
audio::FeedbackMonitorMetrics metrics;
metrics.jitter = recv_report.jitter;
metrics.niq_latency = recv_report.niq_latency;
metrics.e2e_latency = recv_report.e2e_latency;

feedback_monitor_->store(metrics);
Expand Down

0 comments on commit 25820a0

Please sign in to comment.