Skip to content

Commit

Permalink
Added start latency param roc-streaming#688
Browse files Browse the repository at this point in the history
  • Loading branch information
baranovmv committed May 10, 2024
1 parent 87b913a commit c539a5d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/internal_modules/roc_audio/latency_tuner.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ struct LatencyConfig {
//! Negative value is an error.
core::nanoseconds_t target_latency;

//! Start latency.
//! @remarks
//! In case of dynamic latency the tuner will start from this value.
//! @note
//! This value makes sense only when target_latency is set to 0.
core::nanoseconds_t start_latency;

//! Minimum allowed latency.
//! @remarks
//! If the latency goes out of bounds, the session is terminated.
Expand Down
6 changes: 5 additions & 1 deletion src/internal_modules/roc_pipeline/receiver_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ ReceiverSession::ReceiverSession(
pkt_reader = filter_.get();

delayed_reader_.reset(new (delayed_reader_) packet::DelayedReader(
*pkt_reader, session_config.latency.target_latency, pkt_encoding->sample_spec));
*pkt_reader,
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
7 changes: 7 additions & 0 deletions src/public_api/include/roc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,13 @@ typedef struct roc_receiver_config {
*/
unsigned long long target_latency;

/** Start latency, in nanoseconds.
*
* If target latency is set to zero, and latency tuning is enabled, this value
* sets initial value of latency.
*/
unsigned long long start_latency;

/** Minimum allowed latency, in nanoseconds.
*
* How latency is calculated depends on \c latency_tuner_backend field.
Expand Down
12 changes: 12 additions & 0 deletions src/public_api/src/adapters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ bool receiver_config_from_user(node::Context&,
(core::nanoseconds_t)in.target_latency;
}

if (in.start_latency != 0) {
if (in.target_latency != 0) {
roc_log (LogError,
"bad configuration:"
" start latency must be 0 if latency tuning is disabled"
" (target_latency != 0)");
return false;
}
out.session_defaults.latency.start_latency =
(core::nanoseconds_t)in.start_latency;
}

if (in.min_latency != 0) {
out.session_defaults.latency.min_latency = (core::nanoseconds_t)in.min_latency;
}
Expand Down
3 changes: 3 additions & 0 deletions src/tools/roc_recv/cmdline.ggo
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ section "Options"
option "target-latency" - "Target latency, TIME units"
string optional

option "start-latency" - "Start latency, target-latency must be 0 or unset, TIME units"
string optional

option "io-latency" - "Playback target latency, TIME units"
string optional

Expand Down
15 changes: 14 additions & 1 deletion src/tools/roc_recv/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,25 @@ int main(int argc, char** argv) {
roc_log(LogError, "invalid --target-latency: bad format");
return 1;
}
if (receiver_config.session_defaults.latency.target_latency <= 0) {
if (receiver_config.session_defaults.latency.target_latency < 0) {
roc_log(LogError, "invalid --target-latency: should be > 0");
return 1;
}
}

if (args.start_latency_given) {
if (!core::parse_duration(
args.start_latency_arg,
receiver_config.session_defaults.latency.start_latency)) {
roc_log(LogError, "invalid --start-latency: bad format");
return 1;
}
if (receiver_config.session_defaults.latency.start_latency < 0) {
roc_log(LogError, "invalid --start-latency: should be >= 0");
return 1;
}
}

if (args.min_latency_given || args.max_latency_given) {
if (!args.min_latency_given || !args.max_latency_given) {
roc_log(LogError,
Expand Down

0 comments on commit c539a5d

Please sign in to comment.