Skip to content

Commit

Permalink
optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Aug 13, 2023
1 parent 646eb16 commit 8dea0d2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/FEC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <array>
#include <vector>
#include <iostream>

#include "HelperSources/Helper.hpp"
#include "external/fec/fec_base.h"
Expand Down
18 changes: 18 additions & 0 deletions src/FECEnabled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//

#include "FECEnabled.h"

#include <cmath>

#include "wifibroadcast-spdlog.h"

#include "FEC.hpp"
Expand Down Expand Up @@ -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<float>(n_primary_fragments) * static_cast<float>(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);
}
40 changes: 14 additions & 26 deletions src/FECEnabled.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,14 @@
#define WIFIBROADCAST_FECENABLED_H

#include <array>
#include <cerrno>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#include <memory>

#include "HelperSources/TimeHelper.hpp"
#include "FEC.hpp"
#include "HelperSources/TimeHelper.hpp"

/**
* Encoder and Decoder pair for FEC protected block / packet based data streaming.
Expand Down Expand Up @@ -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<float>(n_primary_fragments) * static_cast<float>(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:
Expand Down
2 changes: 2 additions & 0 deletions src/HelperSources/SeqNrHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#define WIFIBROADCAST_SRC_HELPERSOURCES_SEQNRHELPER_H_

#include <atomic>
#include <cmath>
#include <memory>

#include "../wifibroadcast-spdlog.h"

namespace seq_nr{
Expand Down

0 comments on commit 8dea0d2

Please sign in to comment.