Skip to content

Commit

Permalink
latency_tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
baranovmv committed Jun 18, 2024
1 parent 3c81338 commit 20265f1
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 136 deletions.
273 changes: 156 additions & 117 deletions src/internal_modules/roc_audio/latency_tuner.cpp

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/internal_modules/roc_audio/latency_tuner.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ struct LatencyConfig {
//! Negative value is an error.
core::nanoseconds_t target_latency;

//! Latency tolerance.
//! Maximum allowed deviation from target latency.
//! @remarks
//! If the latency goes out of bounds, the session is terminated.
//! @note
//! If zero, default value is used if possible.
//! Negative value is an error.
core::nanoseconds_t latency_tolerance;

//! Start latency.
Expand Down Expand Up @@ -140,6 +145,7 @@ struct LatencyConfig {
: tuner_backend(LatencyTunerBackend_Default)
, tuner_profile(LatencyTunerProfile_Default)
, target_latency(0)
, latency_tolerance(0)
, start_latency(0)
, min_latency(0)
, max_latency(0)
Expand Down Expand Up @@ -269,6 +275,7 @@ class LatencyTuner : public core::NonCopyable<> {
LatencyMetrics latency_metrics_;
packet::LinkMetrics link_metrics_;

bool auto_tune_;
packet::stream_timestamp_diff_t target_latency_;
packet::stream_timestamp_diff_t min_latency_;
packet::stream_timestamp_diff_t max_latency_;
Expand Down
7 changes: 3 additions & 4 deletions src/internal_modules/roc_pipeline/receiver_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ReceiverSession::ReceiverSession(const ReceiverSessionConfig& session_config,
const rtp::EncodingMap& encoding_map,
packet::PacketFactory& packet_factory,
audio::FrameFactory& frame_factory,
core::CsvDumper* dumper,
core::CsvDumper* dumper,
core::IArena& arena)
: core::RefCounted<ReceiverSession, core::ArenaAllocation>(arena)
, frame_reader_(NULL)
Expand Down Expand Up @@ -81,9 +81,8 @@ ReceiverSession::ReceiverSession(const ReceiverSessionConfig& session_config,

delayed_reader_.reset(new (delayed_reader_) packet::DelayedReader(
*pkt_reader,
session_config.latency.target_latency != 0
? session_config.latency.target_latency
: session_config.latency.start_latency,
session_config.latency.target_latency != 0 ? session_config.latency.target_latency
: session_config.latency.start_latency,
pkt_encoding->sample_spec));
if (!delayed_reader_ || !delayed_reader_->is_valid()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ReceiverSessionGroup::ReceiverSessionGroup(const ReceiverSourceConfig& source_co
const rtp::EncodingMap& encoding_map,
packet::PacketFactory& packet_factory,
audio::FrameFactory& frame_factory,
core::CsvDumper* dumper,
core::CsvDumper* dumper,
core::IArena& arena)
: source_config_(source_config)
, slot_config_(slot_config)
Expand Down
8 changes: 3 additions & 5 deletions src/internal_modules/roc_pipeline/receiver_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ ReceiverSource::ReceiverSource(const ReceiverSourceConfig& source_config,
return;
}


if (source_config.dump_file) {
dumper_.reset(new (dumper_) core::CsvDumper(source_config.dump_file,
dumper_config_, arena));
Expand All @@ -89,10 +88,9 @@ ReceiverSlot* ReceiverSource::create_slot(const ReceiverSlotConfig& slot_config)

roc_log(LogInfo, "receiver source: adding slot");

core::SharedPtr<ReceiverSlot> slot =
new (arena_) ReceiverSlot(source_config_, slot_config, state_tracker_, *mixer_,
encoding_map_, packet_factory_, frame_factory_,
dumper_.get(), arena_);
core::SharedPtr<ReceiverSlot> slot = new (arena_)
ReceiverSlot(source_config_, slot_config, state_tracker_, *mixer_, encoding_map_,
packet_factory_, frame_factory_, dumper_.get(), arena_);

if (!slot || !slot->is_valid()) {
roc_log(LogError, "receiver source: can't create slot");
Expand Down
4 changes: 2 additions & 2 deletions src/internal_modules/roc_rtp/link_meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ void LinkMeter::update_jitter_(const packet::Packet& packet) {
last_seqnum_hi_ = 0;
last_seqnum_lo_ = pkt_seqnum;

// If packet seqnum is after last seqnum, update last seqnum, and
// also counts possible wraps.
// If packet seqnum is after last seqnum, update last seqnum, and
// also counts possible wraps.
} else if (packet::seqnum_diff(pkt_seqnum, last_seqnum_lo_) > 0) {
if (pkt_seqnum < last_seqnum_lo_) {
last_seqnum_hi_ += 1 << 16;
Expand Down
2 changes: 1 addition & 1 deletion src/public_api/include/roc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ typedef struct roc_receiver_config {
* If target latency is set to zero, and latency tuning is enabled, this value
* sets initial value of latency.
*/
unsigned long long start_latency;
unsigned long long start_latency;

/** Minimum allowed latency, in nanoseconds.
*
Expand Down
2 changes: 1 addition & 1 deletion src/public_api/src/adapters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ bool receiver_config_from_user(node::Context&,

if (in.start_latency != 0) {
if (in.target_latency != 0) {
roc_log (LogError,
roc_log(LogError,
"bad configuration:"
" start latency must be 0 if latency tuning is disabled"
" (target_latency != 0)");
Expand Down
8 changes: 4 additions & 4 deletions src/tests/roc_pipeline/test_receiver_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ TEST(receiver_endpoint, valid) {
ReceiverSourceConfig source_config;
ReceiverSlotConfig slot_config;
ReceiverSessionGroup session_group(source_config, slot_config, state_tracker, mixer,
encoding_map, packet_factory, frame_factory,
NULL, arena);
encoding_map, packet_factory, frame_factory, NULL,
arena);

ReceiverEndpoint endpoint(address::Proto_RTP, state_tracker, session_group,
encoding_map, address::SocketAddr(), NULL, arena);
Expand All @@ -58,8 +58,8 @@ TEST(receiver_endpoint, invalid_proto) {
ReceiverSourceConfig source_config;
ReceiverSlotConfig slot_config;
ReceiverSessionGroup session_group(source_config, slot_config, state_tracker, mixer,
encoding_map, packet_factory, frame_factory,
NULL, arena);
encoding_map, packet_factory, frame_factory, NULL,
arena);

ReceiverEndpoint endpoint(address::Proto_None, state_tracker, session_group,
encoding_map, address::SocketAddr(), NULL, arena);
Expand Down

0 comments on commit 20265f1

Please sign in to comment.