Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::audio::LatencyTuner Class Reference

Latency tuner. More...

#include <latency_tuner.h>

Inheritance diagram for roc::audio::LatencyTuner:
Collaboration diagram for roc::audio::LatencyTuner:

Public Member Functions

 LatencyTuner (const LatencyConfig &config, const SampleSpec &sample_spec)
 Initialize. More...
 
bool is_valid () const
 Check if the object was initialized successfully. More...
 
void write_metrics (const LatencyMetrics &latency_metrics, const packet::LinkMetrics &link_metrics)
 Pass updated metrics to tuner. Tuner will use new values next time when update_stream() is called. More...
 
bool update_stream ()
 Update stream latency and scaling. This method performs all actual work: More...
 
void advance_stream (packet::stream_timestamp_t duration)
 Advance stream by given number of samples. Should be called after updating stream. More...
 
float fetch_scaling ()
 If scaling has changed, returns updated value. Otherwise, returns zero. More...
 

Detailed Description

Latency tuner.

On receiver, LatencyMonitor computes local metrics and passes them to LatencyTuner. On sender, FeedbackMonitor obtains remote metrics and passes them to LatencyTuner. In both cases, LatencyTuner processes metrics and computes scaling factor that should be passed to resampler.

Features:

  • monitors how close actual latency and target latency are
  • monitors whether latency goes out of bounds
  • assuming that the difference between actual latency and target latency is caused by the clock drift between sender and receiver, calculates scaling factor for resampler to compensate it

Definition at line 167 of file latency_tuner.h.

Constructor & Destructor Documentation

◆ LatencyTuner()

roc::audio::LatencyTuner::LatencyTuner ( const LatencyConfig config,
const SampleSpec sample_spec 
)

Initialize.

Member Function Documentation

◆ advance_stream()

void roc::audio::LatencyTuner::advance_stream ( packet::stream_timestamp_t  duration)

Advance stream by given number of samples. Should be called after updating stream.

◆ fetch_scaling()

float roc::audio::LatencyTuner::fetch_scaling ( )

If scaling has changed, returns updated value. Otherwise, returns zero.

Remarks
Latency tuner expects that this scaling will applied to the stream resampler, so that the latency will slowly achieve target value. Returned value is close to 1.0.

◆ is_valid()

bool roc::audio::LatencyTuner::is_valid ( ) const

Check if the object was initialized successfully.

◆ update_stream()

bool roc::audio::LatencyTuner::update_stream ( )

Update stream latency and scaling. This method performs all actual work:

  • depending on configured backend, selects which latency from metrics to use
  • check if latency goes out of bounds and session should be terminated; if so, returns false
  • computes updated scaling based on latency history and configured profile

◆ write_metrics()

void roc::audio::LatencyTuner::write_metrics ( const LatencyMetrics latency_metrics,
const packet::LinkMetrics link_metrics 
)

Pass updated metrics to tuner. Tuner will use new values next time when update_stream() is called.


The documentation for this class was generated from the following file: