forked from roc-streaming/roc-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
roc-streaminggh-675 Rework pipeline configs
- Replace LatencyMonitorConfig w/ LatencyConfig, which may be also used for FeedbackMonitor - Move target_latency to LatencyConfig - Use single deduce_defaults() method instead of multiple deduce_xxx() calls for each parameter - Extract ResamplerConfig and move deducing default backend to it - Invoke deduce_defaults() when constructing pipelines
- Loading branch information
Showing
48 changed files
with
714 additions
and
538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2024 Roc Streaming authors | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "roc_audio/latency_config.h" | ||
|
||
namespace roc { | ||
namespace audio { | ||
|
||
void LatencyConfig::deduce_defaults(bool is_receiver) { | ||
if (fe_input == audio::FreqEstimatorInput_Default) { | ||
// On receiver, by default adjust clock based on NIQ latency. | ||
// On sender, by default do not adjust clock. | ||
fe_input = is_receiver ? audio::FreqEstimatorInput_NiqLatency | ||
: audio::FreqEstimatorInput_Disable; | ||
} | ||
|
||
if (fe_profile == audio::FreqEstimatorProfile_Default) { | ||
fe_profile = target_latency < 30 * core::Millisecond | ||
// Prefer responsive profile on low latencies, because gradual profile | ||
// won't do it at all. | ||
? audio::FreqEstimatorProfile_Responsive | ||
// Prefer gradual profile for higher latencies, because it can handle | ||
// higher network jitter. | ||
: audio::FreqEstimatorProfile_Gradual; | ||
} | ||
|
||
if (latency_tolerance < 0) { | ||
// This formula returns target_latency * N, where N starts with larger | ||
// number and approaches 0.5 as target_latency grows. | ||
// Examples: | ||
// target=1ms -> tolerance=8ms (x8) | ||
// target=10ms -> tolerance=20ms (x2) | ||
// target=200ms -> tolerance=200ms (x1) | ||
// target=2000ms -> tolerance=1444ms (x0.722) | ||
const core::nanoseconds_t capped_latency = | ||
std::max(target_latency, core::Millisecond); | ||
|
||
latency_tolerance = core::nanoseconds_t( | ||
capped_latency | ||
* (std::log((200 * core::Millisecond) * 2) / std::log(capped_latency * 2))); | ||
} | ||
} | ||
|
||
} // namespace audio | ||
} // namespace roc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2015 Roc Streaming authors | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
//! @file roc_audio/latency_config.h | ||
//! @brief Latency config. | ||
|
||
#ifndef ROC_AUDIO_LATENCY_CONFIG_H_ | ||
#define ROC_AUDIO_LATENCY_CONFIG_H_ | ||
|
||
#include "roc_audio/freq_estimator.h" | ||
#include "roc_core/time.h" | ||
|
||
namespace roc { | ||
namespace audio { | ||
|
||
//! Parameters for latency and feedback monitors. | ||
struct LatencyConfig { | ||
//! FreqEstimator input. | ||
FreqEstimatorInput fe_input; | ||
|
||
//! FreqEstimator profile. | ||
FreqEstimatorProfile fe_profile; | ||
|
||
//! FreqEstimator update interval, nanoseconds. | ||
//! How often to run FreqEstimator and update Resampler scaling. | ||
core::nanoseconds_t fe_update_interval; | ||
|
||
//! Target latency, nanoseconds. | ||
core::nanoseconds_t target_latency; | ||
|
||
//! Maximum allowed deviation from target latency, nanoseconds. | ||
//! If the latency goes out of bounds, the session is terminated. | ||
core::nanoseconds_t latency_tolerance; | ||
|
||
//! Maximum allowed deviation of freq_coeff from 1.0. | ||
//! If the scaling goes out of bounds, it is trimmed. | ||
//! For example, 0.01 allows freq_coeff values in range [0.99; 1.01]. | ||
float scaling_tolerance; | ||
|
||
//! Initialize. | ||
LatencyConfig(const core::nanoseconds_t default_target_latency) | ||
: fe_input(FreqEstimatorInput_Default) | ||
, fe_profile(FreqEstimatorProfile_Default) | ||
, fe_update_interval(5 * core::Millisecond) | ||
, target_latency(default_target_latency) | ||
, latency_tolerance(-1) | ||
, scaling_tolerance(0.005f) { | ||
} | ||
|
||
//! Automatically fill missing settings. | ||
void deduce_defaults(bool is_receiver); | ||
}; | ||
|
||
} // namespace audio | ||
} // namespace roc | ||
|
||
#endif // ROC_AUDIO_LATENCY_CONFIG_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.