From 8dea0d202ed8fb475b2a6464a6443857317a9fe6 Mon Sep 17 00:00:00 2001 From: consti10 Date: Sun, 13 Aug 2023 22:43:58 +0200 Subject: [PATCH] optimize imports --- src/FEC.hpp | 1 + src/FECEnabled.cpp | 18 ++++++++++++++ src/FECEnabled.h | 40 +++++++++++-------------------- src/HelperSources/SeqNrHelper.hpp | 2 ++ 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/FEC.hpp b/src/FEC.hpp index 7917d581..408028ef 100644 --- a/src/FEC.hpp +++ b/src/FEC.hpp @@ -7,6 +7,7 @@ #include #include +#include #include "HelperSources/Helper.hpp" #include "external/fec/fec_base.h" diff --git a/src/FECEnabled.cpp b/src/FECEnabled.cpp index e4a31f02..e98472e8 100644 --- a/src/FECEnabled.cpp +++ b/src/FECEnabled.cpp @@ -3,6 +3,9 @@ // #include "FECEnabled.h" + +#include + #include "wifibroadcast-spdlog.h" #include "FEC.hpp" @@ -439,3 +442,18 @@ void FECDecoder::reset_rx_queue() { rx_queue.resize(0); last_known_block=((uint64_t) -1); } + +uint32_t calculate_n_secondary_fragments(uint32_t n_primary_fragments, + uint32_t fec_overhead_perc) { + if(fec_overhead_perc<=0)return 0; + const float n_secondary=static_cast(n_primary_fragments) * static_cast(fec_overhead_perc) / 100.0f; + if(n_secondary<=1.0){ + // Always calculate at least one FEC packet + return 1; + } + return std::lroundf(n_secondary); +} + +unsigned int calculateN(const unsigned int k, const unsigned int percentage) { + return k + calculate_n_secondary_fragments(k,percentage); +} diff --git a/src/FECEnabled.h b/src/FECEnabled.h index 059fb31c..4a659c6c 100644 --- a/src/FECEnabled.h +++ b/src/FECEnabled.h @@ -6,22 +6,14 @@ #define WIFIBROADCAST_FECENABLED_H #include -#include -#include -#include -#include -#include -#include #include +#include #include -#include #include -#include #include -#include -#include "HelperSources/TimeHelper.hpp" #include "FEC.hpp" +#include "HelperSources/TimeHelper.hpp" /** * Encoder and Decoder pair for FEC protected block / packet based data streaming. @@ -62,22 +54,18 @@ static constexpr const uint16_t MAX_N_S_FRAGMENTS_PER_BLOCK = 128; static constexpr const uint16_t MAX_TOTAL_FRAGMENTS_PER_BLOCK = MAX_N_P_FRAGMENTS_PER_BLOCK + MAX_N_S_FRAGMENTS_PER_BLOCK; -// For dynamic block sizes, we switched to a FEC overhead "percentage" value. -// e.g. the final data throughput ~= original data throughput * fec overhead percentage -static uint32_t calculate_n_secondary_fragments(uint32_t n_primary_fragments,uint32_t fec_overhead_perc){ - if(fec_overhead_perc<=0)return 0; - const float n_secondary=static_cast(n_primary_fragments) * static_cast(fec_overhead_perc) / 100.0f; - if(n_secondary<=1.0){ - // Always calculate at least one FEC packet - return 1; - } - return std::lroundf(n_secondary); -} -// calculate n from k and percentage as used in FEC terms -// (k: number of primary fragments, n: primary + secondary fragments) -static unsigned int calculateN(const unsigned int k, const unsigned int percentage) { - return k + calculate_n_secondary_fragments(k,percentage); -} +/** + * For dynamic block sizes, we switched to a FEC overhead "percentage" value. + * e.g. the final data throughput ~= original data throughput * fec overhead percentage + * Rounds up / down (.5), but always at least 1 + */ +uint32_t calculate_n_secondary_fragments(uint32_t n_primary_fragments,uint32_t fec_overhead_perc); + +/** + * calculate n from k and percentage as used in FEC terms + * (k: number of primary fragments, n: primary + secondary fragments) + */ +unsigned int calculateN(unsigned int k, unsigned int percentage); class FECEncoder { public: diff --git a/src/HelperSources/SeqNrHelper.hpp b/src/HelperSources/SeqNrHelper.hpp index c2ccb817..74fa66f1 100644 --- a/src/HelperSources/SeqNrHelper.hpp +++ b/src/HelperSources/SeqNrHelper.hpp @@ -6,7 +6,9 @@ #define WIFIBROADCAST_SRC_HELPERSOURCES_SEQNRHELPER_H_ #include +#include #include + #include "../wifibroadcast-spdlog.h" namespace seq_nr{