Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ add_library(base_objects OBJECT
src/base/processing/LossEstimator.cpp
src/base/processing/StepsGenerator.cpp
src/base/processing/StepsLatencyEstimator.cpp
src/base/processing/MinMaxEstimator.cpp
src/base/reports/Console.cpp
src/base/reports/JsonPrinter.cpp
src/base/reports/JsonReporter.cpp
Expand Down
6 changes: 6 additions & 0 deletions src/base/core/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ struct Config {

// number of pre-allocated frames in frame pool
size_t frame_pool_size { 128 };

// minimum latency time of a time window measurement in nanoseconds
unsigned int min_latency {0u};

// maximum latency time of a time window measurement in nanoseconds
unsigned int max_latency {static_cast<unsigned>(-1)};

// get warmup duration in samples
size_t warmup_samples() const {
Expand Down
7 changes: 7 additions & 0 deletions src/base/core/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,11 @@ nanoseconds_t Frame::hw_delay() const {
return hw_delay_;
}

bool Frame::has_impulse() const{
return has_impulse_;
}

void Frame::set_has_impulse(bool has_impulse){
has_impulse_ = has_impulse;
}
} // namespace signal_estimator
7 changes: 7 additions & 0 deletions src/base/core/Frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class Frame {
// at the time when frame was captured or played
nanoseconds_t hw_delay() const;

// get whether frame contains impulse
bool has_impulse() const;

// record whether frame contains impulse
void set_has_impulse(bool has_impulse);

// index access
const sample_t& operator[](const size_t index) const {
assert(index < data_.size());
Expand Down Expand Up @@ -110,6 +116,7 @@ class Frame {
nanoseconds_t sw_delay_ {};
nanoseconds_t hw_delay_ {};

bool has_impulse_ {};
std::atomic<int> refcount_ {};
};

Expand Down
29 changes: 29 additions & 0 deletions src/base/processing/IEstimatorWrapper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Signal Estimator authors
// Licensed under MIT

#pragma once

#include "core/Frame.hpp"
#include "processing/IEstimator.hpp"
#include <memory>

namespace signal_estimator {

// estimate and report some signal characteristic
class IEstimatorWrapper :public IEstimator {
protected:
std::unique_ptr<IEstimator> m_Estimator;
public:
IEstimatorWrapper(std::unique_ptr<IEstimator> estimator) : m_Estimator(std::move(estimator)){}
// called from output thread
void add_output(FramePtr frame) override {
m_Estimator->add_output(frame);
}

// called from input thread
void add_input(FramePtr frame) override {
m_Estimator->add_input(frame);
}
};

} // namespace signal_estimator
1 change: 1 addition & 0 deletions src/base/processing/ImpulseGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void ImpulseGenerator::generate(Frame& frame) {

size_t i_frame = 0;

// TODO set flag for frame-> set_has_impulse
do {
for (; i_frame < frame.size() && counter_ < impulse_size_
&& counter_ < impulse_interval_;
Expand Down
33 changes: 33 additions & 0 deletions src/base/processing/MinMaxEstimator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

#include "processing/MinMaxEstimator.hpp"

namespace signal_estimator {

// called from output thread
void MinMaxEstimator::add_output(FramePtr frame){
if(frame->has_impulse()){
impulse_started_.store(true);
impulse_time_.store(frame->sw_frame_time());
}else{
impulse_started_.store(false);
}
m_Estimator->add_output(frame);
};

// called from input thread
void MinMaxEstimator::add_input(FramePtr frame){
if(impulse_started_.load() &&
(frame->sw_frame_time() >= impulse_time_.load() + config_.min_latency) &&
(frame->sw_frame_time() < impulse_time_.load() + config_.max_latency)){
m_Estimator->add_input(frame);
}
else{
for (size_t i = 0; i < frame->size(); i++){
(frame->data())[i] = 0;
}
m_Estimator->add_input(frame);
}
};


} // namespace signal_estimator
28 changes: 28 additions & 0 deletions src/base/processing/MinMaxEstimator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Signal Estimator authors
// Licensed under MIT

#pragma once
#include "processing/IEstimatorWrapper.hpp"
#include "core/Config.hpp"


namespace signal_estimator {

// estimate and report some signal characteristic
class MinMaxEstimator :public IEstimatorWrapper {
public:
MinMaxEstimator(const Config& config, std::unique_ptr<IEstimator> estimator)
: IEstimatorWrapper(std::move(estimator)),
config_(config){}
// called from output thread
void add_output(FramePtr frame) override;

// called from input thread
void add_input(FramePtr frame) override;
private:
std::atomic<bool> impulse_started_{};
std::atomic<nanoseconds_t> impulse_time_{};
const Config config_;
};

} // namespace signal_estimator
1 change: 1 addition & 0 deletions src/base/processing/StepsGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ StepsGenerator::StepsGenerator(const Config& config)
, warmup_countdown_(config.output_info.period_count) {
}

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

Expand Down
7 changes: 5 additions & 2 deletions src/base/run/Runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "processing/LossEstimator.hpp"
#include "processing/StepsGenerator.hpp"
#include "processing/StepsLatencyEstimator.hpp"
#include "processing/MinMaxEstimator.hpp"
#include "reports/JsonReporter.hpp"
#include "reports/TextReporter.hpp"

Expand Down Expand Up @@ -141,12 +142,14 @@ bool Runner::start() {

case Mode::LatencyStep:
estimators_.emplace_back(
std::make_unique<StepsLatencyEstimator>(config_, *reporters_[n]));
std::make_unique<MinMaxEstimator>(config_,
std::make_unique<StepsLatencyEstimator>(config_, *reporters_[n])));
break;

case Mode::Losses:
estimators_.emplace_back(
std::make_unique<LossEstimator>(config_, *reporters_[n]));
std::make_unique<MinMaxEstimator>(config_,
std::make_unique<LossEstimator>(config_, *reporters_[n])));
break;

case Mode::IOJitter:
Expand Down
9 changes: 9 additions & 0 deletions src/cli/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ int main(int argc, char** argv) {
->add_option("-w,--warmup", config.warmup_duration,
"Warmup duration, seconds (zero for no warmup)")
->default_val(config.warmup_duration);
control_opts
->add_option("--min-latency", config.min_latency,
"Minimum latency time window, microseconds (zero for no latency)")
->default_val(config.min_latency);

control_opts
->add_option("--max-latency", config.max_latency,
"Maximum latency time window, microseconds (zero for no maximum)")
->default_val(config.max_latency);

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

Expand Down