Skip to content

Commit 9695873

Browse files
danodano
authored andcommitted
[WIP] add min/max latency option for estimators
1 parent faf66d0 commit 9695873

File tree

10 files changed

+126
-2
lines changed

10 files changed

+126
-2
lines changed

src/base/core/Config.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ struct Config {
142142

143143
// number of pre-allocated frames in frame pool
144144
size_t frame_pool_size { 128 };
145+
146+
// minimum latency time of a time window measurement in nanoseconds
147+
unsigned int min_latency {0u};
148+
149+
// maximum latency time of a time window measurement in nanoseconds
150+
unsigned int max_latency {static_cast<unsigned>(-1)};
145151

146152
// get warmup duration in samples
147153
size_t warmup_samples() const {

src/base/core/Frame.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,11 @@ nanoseconds_t Frame::hw_delay() const {
126126
return hw_delay_;
127127
}
128128

129+
bool Frame::has_impulse() const{
130+
return has_impulse_;
131+
}
132+
133+
void Frame::set_has_impulse(bool has_impulse){
134+
has_impulse_ = has_impulse;
135+
}
129136
} // namespace signal_estimator

src/base/core/Frame.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ class Frame {
7777
// at the time when frame was captured or played
7878
nanoseconds_t hw_delay() const;
7979

80+
// get whether frame contains impulse
81+
bool has_impulse() const;
82+
83+
// record whether frame contains impulse
84+
void set_has_impulse(bool has_impulse);
85+
8086
// index access
8187
const sample_t& operator[](const size_t index) const {
8288
assert(index < data_.size());
@@ -110,6 +116,7 @@ class Frame {
110116
nanoseconds_t sw_delay_ {};
111117
nanoseconds_t hw_delay_ {};
112118

119+
bool has_impulse_ {};
113120
std::atomic<int> refcount_ {};
114121
};
115122

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Signal Estimator authors
2+
// Licensed under MIT
3+
4+
#pragma once
5+
6+
#include "core/Frame.hpp"
7+
#include "processing/IEstimator.hpp"
8+
#include <memory>
9+
10+
namespace signal_estimator {
11+
12+
// estimate and report some signal characteristic
13+
class IEstimatorWrapper :public IEstimator {
14+
protected:
15+
std::unique_ptr<IEstimator> m_Estimator;
16+
public:
17+
IEstimatorWrapper(std::unique_ptr<IEstimator> estimator) : m_Estimator(std::move(estimator)){}
18+
// called from output thread
19+
void add_output(FramePtr frame) override {
20+
m_Estimator->add_output(frame);
21+
}
22+
23+
// called from input thread
24+
void add_input(FramePtr frame) override {
25+
m_Estimator->add_input(frame);
26+
}
27+
};
28+
29+
} // namespace signal_estimator

src/base/processing/ImpulseGenerator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void ImpulseGenerator::generate(Frame& frame) {
1414

1515
size_t i_frame = 0;
1616

17+
// TODO set flag for frame-> set_has_impulse
1718
do {
1819
for (; i_frame < frame.size() && counter_ < impulse_size_
1920
&& counter_ < impulse_interval_;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
#include "processing/MinMaxEstimator.hpp"
3+
4+
namespace signal_estimator {
5+
6+
// called from output thread
7+
void MinMaxEstimator::add_output(FramePtr frame){
8+
if(frame->has_impulse()){
9+
impulse_started_.store(true);
10+
impulse_time_.store(frame->sw_frame_time());
11+
}else{
12+
impulse_started_.store(false);
13+
}
14+
m_Estimator->add_output(frame);
15+
};
16+
17+
// called from input thread
18+
void MinMaxEstimator::add_input(FramePtr frame){
19+
if(impulse_started_.load() &&
20+
(frame->sw_frame_time() >= impulse_time_.load() + config_.min_latency) &&
21+
(frame->sw_frame_time() < impulse_time_.load() + config_.max_latency)){
22+
m_Estimator->add_input(frame);
23+
}
24+
else{
25+
for (size_t i = 0; i < frame->size(); i++){
26+
(frame->data())[i] = 0;
27+
}
28+
m_Estimator->add_input(frame);
29+
}
30+
};
31+
32+
33+
} // namespace signal_estimator
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Signal Estimator authors
2+
// Licensed under MIT
3+
4+
#pragma once
5+
#include "processing/IEstimatorWrapper.hpp"
6+
#include "core/Config.hpp"
7+
8+
9+
namespace signal_estimator {
10+
11+
// estimate and report some signal characteristic
12+
class MinMaxEstimator :public IEstimatorWrapper {
13+
public:
14+
MinMaxEstimator(const Config& config, std::unique_ptr<IEstimator> estimator)
15+
: IEstimatorWrapper(std::move(estimator)),
16+
config_(config){}
17+
// called from output thread
18+
void add_output(FramePtr frame) override;
19+
20+
// called from input thread
21+
void add_input(FramePtr frame) override;
22+
private:
23+
std::atomic<bool> impulse_started_{};
24+
std::atomic<nanoseconds_t> impulse_time_{};
25+
const Config config_;
26+
};
27+
28+
} // namespace signal_estimator

src/base/processing/StepsGenerator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ StepsGenerator::StepsGenerator(const Config& config)
1515
, warmup_countdown_(config.output_info.period_count) {
1616
}
1717

18+
// TODO set flag for frame-> set_has_impulse
1819
void StepsGenerator::generate(Frame& frame) {
1920
std::fill_n(frame.data(), frame.size(), 0);
2021

src/base/run/Runner.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "processing/LossEstimator.hpp"
1818
#include "processing/StepsGenerator.hpp"
1919
#include "processing/StepsLatencyEstimator.hpp"
20+
#include "processing/MinMaxEstimator.hpp"
2021
#include "reports/JsonReporter.hpp"
2122
#include "reports/TextReporter.hpp"
2223

@@ -141,12 +142,14 @@ bool Runner::start() {
141142

142143
case Mode::LatencyStep:
143144
estimators_.emplace_back(
144-
std::make_unique<StepsLatencyEstimator>(config_, *reporters_[n]));
145+
std::make_unique<MinMaxEstimator>(config_,
146+
std::make_unique<StepsLatencyEstimator>(config_, *reporters_[n])));
145147
break;
146148

147149
case Mode::Losses:
148150
estimators_.emplace_back(
149-
std::make_unique<LossEstimator>(config_, *reporters_[n]));
151+
std::make_unique<MinMaxEstimator>(config_,
152+
std::make_unique<LossEstimator>(config_, *reporters_[n])));
150153
break;
151154

152155
case Mode::IOJitter:

src/cli/Main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ int main(int argc, char** argv) {
5555
->add_option("-w,--warmup", config.warmup_duration,
5656
"Warmup duration, seconds (zero for no warmup)")
5757
->default_val(config.warmup_duration);
58+
control_opts
59+
->add_option("--min-latency", config.min_latency,
60+
"Minimum latency time window, microseconds (zero for no latency)")
61+
->default_val(config.min_latency);
62+
63+
control_opts
64+
->add_option("--max-latency", config.max_latency,
65+
"Maximum latency time window, microseconds (zero for no maximum)")
66+
->default_val(config.max_latency);
5867

5968
auto io_opts = app.add_option_group("I/O options");
6069

0 commit comments

Comments
 (0)