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

Latency monitor. More...

#include <latency_monitor.h>

Inheritance diagram for roc::audio::LatencyMonitor:
Collaboration diagram for roc::audio::LatencyMonitor:

Public Member Functions

 LatencyMonitor (IFrameReader &frame_reader, const packet::SortedQueue &incoming_queue, const Depacketizer &depacketizer, ResamplerReader *resampler, const LatencyMonitorConfig &config, core::nanoseconds_t target_latency, const SampleSpec &input_sample_spec, const SampleSpec &output_sample_spec)
 Constructor. More...
 
bool is_valid () const
 Check if the object was initialized successfully. More...
 
bool is_alive () const
 Check if the stream is still alive. More...
 
LatencyMonitorMetrics metrics () const
 Get metrics. More...
 
virtual bool read (Frame &frame)
 Read audio frame from a pipeline. More...
 
bool reclock (core::nanoseconds_t playback_timestamp)
 Report playback timestamp of last frame returned by read. More...
 
- Public Member Functions inherited from roc::core::ListNode
ListNodeDatalist_node_data () const
 Get list node data. More...
 

Detailed Description

Latency monitor.

Features

  • calculates NIQ latency (network incoming queue) - how many samples are buffered in receiver packet queue and receiver pipeline before depacketizer
  • calculates E2E latency (end-to-end) - how much time passed between frame was captured on sender and played on receiver (this is based on capture timestamps, which are populated with the help of RTCP)
  • monitors how close actual latency and target latency are (which one to check, NIQ or E2E, depends on config)
  • 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 that clock drift
  • passes calculated scaling factor to resampler
  • shuts down session if the actual latency goes out of bounds

Flow

  • pipeline periodically calls read() method; it uses references to incoming packet queue (start of the pipeline) and depacketizer (last pipeline element that works with packets), asks them about current packet / frame, and calculates distance between them, which is NIQ latency
  • after adding frame to playback buffer, pipeline invokes reclock() method; it calculates difference between capture and playback time of the frame, which is E2E latency
  • latency monitor has an instance of FreqEstimator (FE); it continously passes calculated latency to FE, and FE calculates scaling factor for resampler
  • latency monitor has a reference to resampler, and periodically passes updated scaling factor to it;
  • pipeline also can query latency monitor for latency statistics on behalf of request from user

Definition at line 140 of file latency_monitor.h.

Constructor & Destructor Documentation

◆ LatencyMonitor()

roc::audio::LatencyMonitor::LatencyMonitor ( IFrameReader frame_reader,
const packet::SortedQueue incoming_queue,
const Depacketizer depacketizer,
ResamplerReader resampler,
const LatencyMonitorConfig config,
core::nanoseconds_t  target_latency,
const SampleSpec input_sample_spec,
const SampleSpec output_sample_spec 
)

Constructor.

Parameters

  • frame_reader is inner frame reader for E2E latency calculation
  • incoming_queue and depacketizer are used to NIQ latency calculation
  • resampler is used to set the scaling factor to compensate clock drift according to calculated latency
  • config defines calculation parameters
  • target_latency defines target latency that we should maintain
  • input_sample_spec is the sample spec of the input packets
  • output_sample_spec is the sample spec of the output frames (after resampling)

Member Function Documentation

◆ is_alive()

bool roc::audio::LatencyMonitor::is_alive ( ) const

Check if the stream is still alive.

◆ is_valid()

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

Check if the object was initialized successfully.

◆ metrics()

LatencyMonitorMetrics roc::audio::LatencyMonitor::metrics ( ) const

Get metrics.

◆ read()

virtual bool roc::audio::LatencyMonitor::read ( Frame frame)
virtual

Read audio frame from a pipeline.

Remarks
Forwards frame from underlying reader as-is.

Implements roc::audio::IFrameReader.

◆ reclock()

bool roc::audio::LatencyMonitor::reclock ( core::nanoseconds_t  playback_timestamp)

Report playback timestamp of last frame returned by read.

Remarks
Pipeline invokes this method after adding last frame to playback buffer and knowing its playback time.
Returns
false if the session is ended

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