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, const packet::ILinkMeter &link_meter, ResamplerReader *resampler, const LatencyConfig &config, const SampleSpec &packet_sample_spec, const SampleSpec &frame_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...
 
const LatencyMetricsmetrics () 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< Tag >
ListDatalist_data () const
 Get pointer to internal data. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from roc::core::ListNode< Tag >
static ListNodelist_node (ListData *data)
 Get pointer to parent node from pointer to internal 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)
  • asks LatencyTuner to calculate scaling factor based on the actual and target latencies
  • passes calculated scaling factor to resampler

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 LatencyTuner; it continuously passes calculated latencies to it, and obtains 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 metrics on behalf of request from user or to report them to sender via RTCP

Definition at line 60 of file latency_monitor.h.

Constructor & Destructor Documentation

◆ LatencyMonitor()

roc::audio::LatencyMonitor::LatencyMonitor ( IFrameReader frame_reader,
const packet::SortedQueue incoming_queue,
const Depacketizer depacketizer,
const packet::ILinkMeter link_meter,
ResamplerReader resampler,
const LatencyConfig config,
const SampleSpec packet_sample_spec,
const SampleSpec frame_sample_spec 
)

Constructor.

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()

const LatencyMetrics& 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: