MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / wt_perform_rate_adjustment

Method wt_perform_rate_adjustment

OpenHD/ohd_interface/src/wb_link.cpp:1114–1200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1112}
1113
1114void WBLink::wt_perform_rate_adjustment() {
1115 using namespace openhd::wb;
1116 if (!m_profile.is_air) return; // Only done on air unit
1117 // Rate adjustment is done on air and only if enabled
1118 if (!(m_profile.is_air &&
1119 m_settings->get_settings().enable_wb_video_variable_bitrate)) {
1120 return;
1121 }
1122 const auto& settings = m_settings->get_settings();
1123 const auto& card = m_broadcast_cards.at(0);
1124 // First we calculate the theoretical rate for the current "wifi config" aka
1125 // taking mcs index, channel width, ... into account
1126 const int max_rate_for_current_wifi_config =
1127 calculate_bitrate_for_wifi_config_kbits(
1128 card, settings.wb_frequency, settings.wb_air_tx_channel_width,
1129 settings.wb_air_mcs_index,
1130 settings.wb_video_rate_for_mcs_adjustment_percent, false);
1131 m_max_total_rate_for_current_wifi_config_kbits =
1132 max_rate_for_current_wifi_config;
1133 // Subtract the FEC overhead from (video) bitrate
1134 const int max_video_rate_for_current_wifi_fec_config =
1135 openhd::wb::deduce_fec_overhead(max_rate_for_current_wifi_config,
1136 settings.wb_video_fec_percentage);
1137 // const auto stats=m_wb_txrx->get_rx_stats();
1138 // m_foreign_p_helper.update(stats.count_p_any,stats.count_p_valid);
1139 // m_console->debug("N foreign packets per second
1140 // :{}",m_foreign_p_helper.get_foreign_packets_per_second());
1141 if (m_max_video_rate_for_current_wifi_fec_config !=
1142 max_video_rate_for_current_wifi_fec_config ||
1143 m_rate_adjustment_frequency_changed) {
1144 m_rate_adjustment_frequency_changed = false;
1145 // Apply the default for this configuration, then return - we will start the
1146 // auto-adjustment depending on tx error(s) next time the rate adjustment is
1147 // called
1148 m_console->debug(
1149 "MCS:{} ch_width:{} Calculated max_rate:{}, max_video_rate:{}",
1150 settings.wb_air_mcs_index, settings.wb_air_tx_channel_width,
1151 openhd::kbits_per_second_to_string(max_rate_for_current_wifi_config),
1152 openhd::kbits_per_second_to_string(
1153 max_video_rate_for_current_wifi_fec_config));
1154 m_max_video_rate_for_current_wifi_fec_config =
1155 max_video_rate_for_current_wifi_fec_config;
1156 m_recommended_video_bitrate_kbits =
1157 m_max_video_rate_for_current_wifi_fec_config;
1158 m_curr_n_rate_adjustments = 0;
1159 recommend_bitrate_to_encoder(m_recommended_video_bitrate_kbits);
1160 // We 'give' the camera up to X seconds to adjust to the newly set rate. If
1161 // we drop frames during this period, we do not count it as errors that need
1162 // bitrate reduction.
1163 m_frame_drop_helper.delay_for(std::chrono::seconds(5));
1164 m_primary_total_dropped_frames = 0;
1165 m_secondary_total_dropped_frames = 0;
1166 return;
1167 }
1168 // const bool
1169 // dropping_many_frames=m_frame_drop_helper.needs_bitrate_reduction();
1170 const bool dropping_many_frames = false;
1171 // m_console->debug("Dropped since last check:{}",dropped_since_last_check);

Callers

nothing calls this directly

Calls 5

deduce_fec_overheadFunction · 0.85
debugMethod · 0.80
delay_forMethod · 0.80
is_x20Method · 0.80

Tested by

no test coverage detected