From e55105840df52b221bc857af0e6cde3eb10cfe21 Mon Sep 17 00:00:00 2001 From: consti10 Date: Wed, 23 Aug 2023 13:39:14 +0200 Subject: [PATCH 1/4] only consider cars that are currently receiving data for tx switching --- src/WBTxRx.cpp | 15 +++++++++++---- src/WBTxRx.h | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/WBTxRx.cpp b/src/WBTxRx.cpp index 90fff82b..0d8bd187 100644 --- a/src/WBTxRx.cpp +++ b/src/WBTxRx.cpp @@ -25,6 +25,7 @@ WBTxRx::WBTxRx(std::vector wifi_cards1,Options options1) assert(false); } m_receive_pollfds.resize(m_wifi_cards.size()); + m_active_tx_card_data.resize(m_wifi_cards.size()); for(int i=0;ihighest_dbm){ - idx_card_highest_rssi=i; - highest_dbm=(int)dbm_average; + // Check if this card is behaving "okay", aka receiving packets at the time + const auto delta_valid_packets=this_card_stats.count_p_valid-m_active_tx_card_data[i].last_received_n_valid_packets; + m_active_tx_card_data[i].last_received_n_valid_packets=this_card_stats.count_p_valid; + if(delta_valid_packets!=0){ + // Some valid packets on this card, or reset + const auto dbm_average=this_card_stats.card_dbm; + if(dbm_average>highest_dbm){ + idx_card_highest_rssi=i; + highest_dbm=static_cast(dbm_average); // NOLINT(cert-str34-c) + } } //m_console->debug("Card {} dbm_average:{}",i,dbm_average); } diff --git a/src/WBTxRx.h b/src/WBTxRx.h index 6674a32b..ec11cc02 100644 --- a/src/WBTxRx.h +++ b/src/WBTxRx.h @@ -285,6 +285,10 @@ class WBTxRx { uint64_t m_nonce=0; // For multiple RX cards the card with the highest rx rssi is used to inject packets on std::atomic m_curr_tx_card=0; + struct ActiveCardCalculationData{ + int64_t last_received_n_valid_packets=0; + }; + std::vector m_active_tx_card_data; SessionKeyPacket m_tx_sess_key_packet; std::unique_ptr m_encryptor; std::unique_ptr m_decryptor; From 76a32538862ec0038b565e5f4e991e724fb351f5 Mon Sep 17 00:00:00 2001 From: consti10 Date: Wed, 23 Aug 2023 13:40:56 +0200 Subject: [PATCH 2/4] only consider cars that are currently receiving data for tx switching --- src/WBTxRx.cpp | 1 - src/WBTxRx.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/WBTxRx.cpp b/src/WBTxRx.cpp index 0d8bd187..edbaf2f5 100644 --- a/src/WBTxRx.cpp +++ b/src/WBTxRx.cpp @@ -561,7 +561,6 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx,const uint8_t *pkt,const int p } void WBTxRx::switch_tx_card_if_needed() { - // Adjustment of which card is used for injecting packets in case there are multiple RX card(s) if(m_wifi_cards.size()>1 && m_options.enable_auto_switch_tx_card){ const auto elapsed=std::chrono::steady_clock::now()-m_last_highest_rssi_adjustment_tp; if(elapsed>=HIGHEST_RSSI_ADJUSTMENT_INTERVAL){ diff --git a/src/WBTxRx.h b/src/WBTxRx.h index ec11cc02..213371fc 100644 --- a/src/WBTxRx.h +++ b/src/WBTxRx.h @@ -362,6 +362,8 @@ class WBTxRx { // called avery time we have successfully decrypted a packet void on_valid_packet(uint64_t nonce,int wlan_index,uint8_t stream_index,const uint8_t *data,int data_len); static std::string options_to_string(const std::vector& wifi_cards,const Options& options); + // Adjustment of which card is used for injecting packets in case there are multiple RX card(s) + // (Of all cards currently receiving data, find the one with the highest reported dBm) void switch_tx_card_if_needed(); private: // These are 'extra' for calculating some channel pollution value From adf63378f81dd65305860b92fef6bedf5d8a0be6 Mon Sep 17 00:00:00 2001 From: consti10 Date: Thu, 24 Aug 2023 20:38:51 +0200 Subject: [PATCH 3/4] add tx dropped frames stat --- src/WBStreamTx.cpp | 3 ++- src/WBStreamTx.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/WBStreamTx.cpp b/src/WBStreamTx.cpp index 10ddff3a..c118e8ec 100644 --- a/src/WBStreamTx.cpp +++ b/src/WBStreamTx.cpp @@ -81,6 +81,7 @@ bool WBStreamTx::try_enqueue_block(std::vectortry_enqueue(item); if(!res){ m_n_dropped_packets+=fragments.size(); + m_n_dropped_frames++; //m_curr_seq_nr+=fragments.size(); } return res; @@ -107,12 +108,12 @@ WBStreamTx::Statistics WBStreamTx::get_latest_stats() { m_bitrate_calculator_data_provided.get_last_or_recalculate( m_count_bytes_data_provided,std::chrono::seconds(2)); ret.n_dropped_packets=m_n_dropped_packets; + ret.n_dropped_frames=m_n_dropped_frames; ret.current_injected_packets_per_second=m_packets_per_second_calculator.get_last_or_recalculate( m_n_injected_packets,std::chrono::seconds(2)); return ret; } - void WBStreamTx::loop_process_data() { if(options.dequeue_thread_max_realtime){ SchedulingHelper::setThreadParamsMaxRealtime(); diff --git a/src/WBStreamTx.h b/src/WBStreamTx.h index 71bf7b09..2dc64f2e 100644 --- a/src/WBStreamTx.h +++ b/src/WBStreamTx.h @@ -83,7 +83,9 @@ class WBStreamTx { // Sending a lot of small packets for example should be avoided uint64_t current_injected_packets_per_second; // N of dropped packets, increases when both the internal driver queue and the extra 124 packets queue of the tx fill up + // In FEC mode (video), every time a frame is dropped this is increased by the n of fragments in this frame uint64_t n_dropped_packets; + int32_t n_dropped_frames; }; Statistics get_latest_stats(); // only valid when actually doing FEC @@ -130,6 +132,7 @@ class WBStreamTx { std::unique_ptr m_process_data_thread; bool m_process_data_thread_run=true; uint64_t m_n_dropped_packets=0; + int32_t m_n_dropped_frames=0; // Time fragments / blocks spend in the non-blocking atomic queue. AvgCalculator m_queue_time_calculator; AvgCalculator m_block_until_tx_time; From ab8a3a79efb2e9186b9cc243bee68f14eb2a5e64 Mon Sep 17 00:00:00 2001 From: consti10 Date: Thu, 24 Aug 2023 20:42:12 +0200 Subject: [PATCH 4/4] add tx dropped frames stat --- src/WBTxRx.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/WBTxRx.h b/src/WBTxRx.h index 213371fc..c4191be1 100644 --- a/src/WBTxRx.h +++ b/src/WBTxRx.h @@ -173,7 +173,10 @@ class WBTxRx { int curr_bits_per_second_including_overhead=-1; // tx error hint, first sign the tx can't keep up with the provided bitrate int32_t count_tx_injections_error_hint=0; - // actual tx errors + // actual tx errors - e.g. packets dropped during injection. + // Usually, this shouldn't increase, since "injecting a frame" should be a blocking operation + // (until there is space available in the tx queue, aka either linux network or driver packet queue) + // and openhd does automatic bitrate adjust at the tx. int32_t count_tx_errors=0; }; struct RxStats{