{"id":377,"date":"2022-02-13T19:05:12","date_gmt":"2022-02-13T11:05:12","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=377"},"modified":"2022-02-22T21:36:08","modified_gmt":"2022-02-22T13:36:08","slug":"webrtc-congestion-control-classes","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=377","title":{"rendered":"WebRTC Congestion Control classes"},"content":{"rendered":"<h1>Module remote_bitrate_estimator<\/h1>\n<h2>class RemoteEstimatorProxy<\/h2>\n<p>It is used when send-side BWE is enabled: This proxy is instantiated on the receive side. <\/p>\n<p>It buffers a number of receive timestamps and then sends transport feedback messages back too the send side.<\/p>\n<h2>class AimdRateControl<\/h2>\n<p>A rate control implementation based on additive increases of bitrate when no over-use is detected and multiplicative decreases when over-uses are detected. <\/p>\n<p>When we think the available bandwidth has changes or is unknown, we will switch to a &quot;slow-start mode&quot; where we increase multiplicatively.<\/p>\n<h2>class InterArrival<\/h2>\n<p>It is Helper class to compute the inter-arrival time delta and the size delta between two timestamp groups. A timestamp is a 32 bit unsigned number with a client defined rate.<\/p>\n<h2>class OveruseDetector<\/h2>\n<ul>\n<li>main method<\/li>\n<\/ul>\n<pre><code>\/\/ Update the detection state based on the estimated inter-arrival time delta\n\/\/ offset. `timestamp_delta` is the delta between the last timestamp which the\n\/\/ estimated offset is based on and the last timestamp on which the last\n\/\/ offset was based on, representing the time between detector updates.\n\/\/ `num_of_deltas` is the number of deltas the offset estimate is based on.\n\/\/ Returns the state after the detection update.\nBandwidthUsage Detect(double offset,\n                        double timestamp_delta,\n                        int num_of_deltas,\n                        int64_t now_ms);<\/code><\/pre>\n<h1>Module congestion_controller<\/h1>\n<h2>rtp module<\/h2>\n<h3>CongestionControlHandler<\/h3>\n<p>This is used to observe the network controller state and route calls to the proper handler. <\/p>\n<p>It also keeps cached values for safe asynchronous use.<\/p>\n<p>This makes sure that things running on the worker queue can't access state in RtpTransportControllerSend, which would risk causing data race on destruction unless members are properly ordered.<\/p>\n<pre><code class=\"language-cpp\">\nstruct NetworkEstimate {\n  Timestamp at_time = Timestamp::PlusInfinity();\n  \/\/ Deprecated, use TargetTransferRate::target_rate instead.\n  DataRate bandwidth = DataRate::Infinity();\n  TimeDelta round_trip_time = TimeDelta::PlusInfinity();\n  TimeDelta bwe_period = TimeDelta::PlusInfinity();\n\n  float loss_rate_ratio = 0;\n};\n\nstruct TargetTransferRate {\n  Timestamp at_time = Timestamp::PlusInfinity();\n  \/\/ The estimate on which the target rate is based on.\n  NetworkEstimate network_estimate;\n  DataRate target_rate = DataRate::Zero();\n  DataRate stable_target_rate = DataRate::Zero();\n  double cwnd_reduce_ratio = 0;\n};\n\nclass CongestionControlHandler {\n public:\n  CongestionControlHandler();\n  ~CongestionControlHandler();\n\n  CongestionControlHandler(const CongestionControlHandler&amp;) = delete;\n  CongestionControlHandler&amp; operator=(const CongestionControlHandler&amp;) = delete;\n\n  void SetTargetRate(TargetTransferRate new_target_rate);\n  void SetNetworkAvailability(bool network_available);\n  void SetPacerQueue(TimeDelta expected_queue_time);\n  absl::optional&lt;TargetTransferRate&gt; GetUpdate();\n  \/\/...\n}<\/code><\/pre>\n<h2>TransportFeedbackAdapter<\/h2>\n<p>It is from RTCP message to struct TransportPacketsFeedback<\/p>\n<ul>\n<li>RTCP message class<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">class TransportFeedback : public Rtpfb {\n\/\/...\n};<\/code><\/pre>\n<ul>\n<li>\n<p>TransportPacketsFeedback<\/p>\n<pre><code class=\"language-cpp\">struct TransportPacketsFeedback {\nTransportPacketsFeedback();\nTransportPacketsFeedback(const TransportPacketsFeedback&amp; other);\n~TransportPacketsFeedback();\n\nTimestamp feedback_time = Timestamp::PlusInfinity();\nTimestamp first_unacked_send_time = Timestamp::PlusInfinity();\nDataSize data_in_flight = DataSize::Zero();\nDataSize prior_in_flight = DataSize::Zero();\nstd::vector&lt;PacketResult&gt; packet_feedbacks;\n\n\/\/ Arrival times for messages without send time information.\nstd::vector&lt;Timestamp&gt; sendless_arrival_times;\n\nstd::vector&lt;PacketResult&gt; ReceivedWithSendInfo() const;\nstd::vector&lt;PacketResult&gt; LostWithSendInfo() const;\nstd::vector&lt;PacketResult&gt; PacketsWithFeedback() const;\nstd::vector&lt;PacketResult&gt; SortedByReceiveTime() const;\n};<\/code><\/pre>\n<\/li>\n<li>\n<p>main methods<\/p>\n<\/li>\n<\/ul>\n<pre><code>  void AddPacket(const RtpPacketSendInfo&amp; packet_info,\n                 size_t overhead_bytes,\n                 Timestamp creation_time);\n\n  absl::optional&lt;SentPacket&gt; ProcessSentPacket(const rtc::SentPacket&amp; sent_packet);\n\n  absl::optional&lt;TransportPacketsFeedback&gt; ProcessTransportFeedback(\n      const rtcp::TransportFeedback&amp; feedback,\n      Timestamp feedback_receive_time);\n\n  void SetNetworkRoute(const rtc::NetworkRoute&amp; network_route);\n\n  DataSize GetOutstandingData() const;<\/code><\/pre>\n<h2>TransportFeedbackDemuxer<\/h2>\n<p>Implementation of StreamFeedbackProvider that provides a way for implementations of StreamFeedbackObserver to register for feedback callbacks for a given set of SSRCs.<br \/>\nRegistration methods need to be called from the same execution context (thread or task queue) and callbacks to StreamFeedbackObserver::OnPacketFeedbackVector will be made in that same context.<\/p>\n<p>StreamFeedbackProvider \u7684\u5b9e\u73b0\uff0c\u5b83\u4e3a StreamFeedbackObserver \u7684\u5b9e\u73b0\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u6cd5\uff0c\u7528\u4e8e\u6ce8\u518c\u4e00\u7ec4\u7ed9\u5b9a SSRC \u7684\u53cd\u9988\u56de\u8c03\u3002<br \/>\n\u6ce8\u518c\u65b9\u6cd5\u9700\u8981\u4ece\u76f8\u540c\u7684\u6267\u884c\u4e0a\u4e0b\u6587\uff08\u7ebf\u7a0b\u6216\u4efb\u52a1\u961f\u5217\uff09\u8c03\u7528\uff0c\u5e76\u4e14\u5c06\u5728\u540c\u4e00\u4e0a\u4e0b\u6587\u4e2d\u5bf9StreamFeedbackObserver\uff1a\uff1aOnPacketFeedbackVector\u8fdb\u884c\u56de\u8c03\u3002<\/p>\n<pre><code class=\"language-cpp\">\nclass StreamFeedbackObserver {\n public:\n  struct StreamPacketInfo {\n    bool received;\n\n    \/\/ `rtp_sequence_number` and `is_retransmission` are only valid if `ssrc`\n    \/\/ is populated.\n    absl::optional&lt;uint32_t&gt; ssrc;\n    uint16_t rtp_sequence_number;\n    bool is_retransmission;\n  };\n  virtual ~StreamFeedbackObserver() = default;\n\n  virtual void OnPacketFeedbackVector(\n      std::vector&lt;StreamPacketInfo&gt; packet_feedback_vector) = 0;\n};\n\nclass StreamFeedbackProvider {\n public:\n  virtual void RegisterStreamFeedbackObserver(\n      std::vector&lt;uint32_t&gt; ssrcs,\n      StreamFeedbackObserver* observer) = 0;\n  virtual void DeRegisterStreamFeedbackObserver(\n      StreamFeedbackObserver* observer) = 0;\n  virtual ~StreamFeedbackProvider() = default;\n};\n<\/code><\/pre>\n<h1>gcc module<\/h1>\n<h2>class InterArrivalDelta<\/h2>\n<p>It is Helper class to compute the inter-arrival time delta and the size delta<br \/>\nbetween two send bursts.<br \/>\nThis code is branched from modules\/remote_bitrate_estimator\/inter_arrival.<\/p>\n<h2>SendSideBandwidthEstimation<\/h2>\n<h2>AlrDetector<\/h2>\n<p>Application limited region detector is a class that utilizes signals of elapsed time and bytes sent to estimate whether network traffic is currently limited by the application's ability to generate traffic.<\/p>\n<p>AlrDetector provides a signal that can be utilized to adjust estimate bandwidth.<\/p>\n<p>Note: This class is not thread-safe.<\/p>\n<ul>\n<li>config:<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">struct AlrDetectorConfig {\n  \/\/ Sent traffic ratio as a function of network capacity used to determine\n  \/\/ application-limited region. ALR region start when bandwidth usage drops\n  \/\/ below kAlrStartUsageRatio and ends when it raises above\n  \/\/ kAlrEndUsageRatio. NOTE: This is intentionally conservative at the moment\n  \/\/ until BW adjustments of application limited region is fine tuned.\n  double bandwidth_usage_ratio = 0.65;\n  double start_budget_level_ratio = 0.80;\n  double stop_budget_level_ratio = 0.50;\n  std::unique_ptr&lt;StructParametersParser&gt; Parser();\n};<\/code><\/pre>\n<h2>class ProbeController<\/h2>\n<p>This class controls initiation of probing to estimate initial channel capacity. There is also support for probing during a session when max bitrate is adjusted by an application.<\/p>\n<h2>ProbeBitrateEstimator<\/h2>\n<ul>\n<li>main method HandleProbeAndEstimateBitrate<\/li>\n<\/ul>\n<pre><code>  \/\/ Should be called for every probe packet we receive feedback about.\n  \/\/ Returns the estimated bitrate if the probe completes a valid cluster.\n  absl::optional&lt;DataRate&gt; HandleProbeAndEstimateBitrate(\n      const PacketResult&amp; packet_feedback);<\/code><\/pre>\n<h2>DelayBasedBwe<\/h2>\n<p>\u8fd9\u4e2a\u7c7b\u7684\u4e3b\u8981\u65b9\u6cd5\u5c31\u662f <\/p>\n<pre><code class=\"language-cpp\">\n  Result IncomingPacketFeedbackVector(\n      const TransportPacketsFeedback&amp; msg,\n      absl::optional&lt;DataRate&gt; acked_bitrate,\n      absl::optional&lt;DataRate&gt; probe_bitrate,\n      absl::optional&lt;NetworkStateEstimate&gt; network_estimate,\n      bool in_alr);<\/code><\/pre>\n<p>\u5176\u7ed3\u679c\u7c7b\u578b\u4e3a<\/p>\n<pre><code class=\"language-cpp\">  struct Result {\n    Result();\n    ~Result() = default;\n    bool updated;\n    bool probe;\n    DataRate target_bitrate = DataRate::Zero();\n    bool recovered_from_overuse;\n    bool backoff_in_alr;\n  };<\/code><\/pre>\n<h2>AcknowledgedBitrateEstimator<\/h2>\n<p>According to the below setting , use class BitrateEstimator to estimate throughput<\/p>\n<ul>\n<li>setting<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">\nstruct RobustThroughputEstimatorSettings {\n  static constexpr char kKey[] = &quot;WebRTC-Bwe-RobustThroughputEstimatorSettings&quot;;\n  static constexpr size_t kMaxPackets = 500;\n\n  RobustThroughputEstimatorSettings() = delete;\n  explicit RobustThroughputEstimatorSettings(\n      const WebRtcKeyValueConfig* key_value_config);\n\n  bool enabled = false;  \/\/ Set to true to use RobustThroughputEstimator.\n\n  \/\/ The estimator handles delay spikes by removing the largest receive time\n  \/\/ gap, but this introduces some bias that may lead to overestimation when\n  \/\/ there isn&#039;t any delay spike. If `reduce_bias` is true, we instead replace\n  \/\/ the largest receive time gap by the second largest. This reduces the bias\n  \/\/ at the cost of not completely removing the genuine delay spikes.\n  bool reduce_bias = true;\n\n  \/\/ If `assume_shared_link` is false, we ignore the size of the first packet\n  \/\/ when computing the receive rate. Otherwise, we remove half of the first\n  \/\/ and last packet&#039;s sizes.\n  bool assume_shared_link = false;\n\n  \/\/ The estimator window keeps at least `min_packets` packets and up to\n  \/\/ kMaxPackets received during the last `window_duration`.\n  unsigned min_packets = 20;\n  TimeDelta window_duration = TimeDelta::Millis(500);\n\n  \/\/ The estimator window requires at least `initial_packets` packets received\n  \/\/ over at least `initial_duration`.\n  unsigned initial_packets = 20;\n\n  \/\/ If audio packets are included in allocation, but not in bandwidth\n  \/\/ estimation and the sent audio packets get double counted,\n  \/\/ then it might be useful to reduce the weight to 0.5.\n  double unacked_weight = 1.0;\n\n  std::unique_ptr&lt;StructParametersParser&gt; Parser();\n};<\/code><\/pre>\n<h2>class BitrateEstimator <\/h2>\n<p>Computes a bayesian estimate of the throughput given acks containing the arrival time and payload size. <\/p>\n<p>Samples which are far from the current estimate or are based on few packets are given a smaller weight, as they are considered to be more likely to have been caused by, e.g., delay spikes unrelated to congestion.<\/p>\n<p>\u8ba1\u7b97\u7ed9\u5b9a\u7684\u786e\u8ba4\u7684\u541e\u5410\u91cf\u7684\u8d1d\u53f6\u65af\u4f30\u8ba1\u503c\uff0c\u5176\u4e2d\u5305\u542b\u5230\u8fbe\u65f6\u95f4\u548c\u6709\u6548\u8d1f\u8f7d\u5927\u5c0f\u3002<\/p>\n<p>\u4e0e\u5f53\u524d\u4f30\u8ba1\u503c\u76f8\u5dee\u751a\u8fdc\u6216\u57fa\u4e8e\u5c11\u91cf\u6570\u636e\u5305\u7684\u6837\u672c\u6743\u91cd\u8f83\u5c0f\uff0c\u56e0\u4e3a\u5b83\u4eec\u88ab\u8ba4\u4e3a\u66f4\u6709\u53ef\u80fd\u662f\u7531\u4e0e\u62e5\u585e\u65e0\u5173\u7684\u5ef6\u8fdf\u5cf0\u503c\u5f15\u8d77\u7684\u3002<\/p>\n<p>\u5c06\u6837\u672c\u4e0d\u786e\u5b9a\u6027\u5b9a\u4e49\u4e3a\u5b83\u4e0e\u5f53\u524d\u4f30\u8ba1\u503c\u4e4b\u95f4\u7684\u8ddd\u79bb\u7684\u51fd\u6570\u3002\u5bf9\u4e8e\u8f83\u4f4e\u7684uncertainty_symmetry<em>cap<\/em>\uff0c\u6211\u4eec\u589e\u52a0\u7684\u4e0d\u786e\u5b9a\u6027\u5927\u4e8e\u51cf\u5c11\u7684\u4e0d\u786e\u5b9a\u6027\u3002\u5bf9\u4e8e\u66f4\u9ad8\u7684\u503c\uff0c\u6211\u4eec\u63a5\u8fd1\u5bf9\u79f0\u6027\u3002<\/p>\n<pre><code class=\"language-cpp\">void BitrateEstimator::Update(int64_t now_ms, int bytes) {\n  int rate_window_ms = noninitial_window_ms_.Get();\n  \/\/ We use a larger window at the beginning to get a more stable sample that\n  \/\/ we can use to initialize the estimate.\n  if (bitrate_estimate_kbps_ &lt; 0.f)\n    rate_window_ms = initial_window_ms_.Get();\n  float bitrate_sample_kbps = UpdateWindow(now_ms, bytes, rate_window_ms);\n  if (bitrate_sample_kbps &lt; 0.0f)\n    return;\n  if (bitrate_estimate_kbps_ &lt; 0.0f) {\n    \/\/ This is the very first sample we get. Use it to initialize the estimate.\n    bitrate_estimate_kbps_ = bitrate_sample_kbps;\n    return;\n  }\n  \/\/ Define the sample uncertainty as a function of how far away it is from the\n  \/\/ current estimate. With low values of uncertainty_symmetry_cap_ we add more\n  \/\/ uncertainty to increases than to decreases. For higher values we approach\n  \/\/ symmetry.\n  float sample_uncertainty =\n      uncertainty_scale_ *\n      std::abs(bitrate_estimate_kbps_ - bitrate_sample_kbps) \/\n      (bitrate_estimate_kbps_ +\n       std::min(bitrate_sample_kbps,\n                uncertainty_symmetry_cap_.Get().kbps&lt;float&gt;()));\n\n  float sample_var = sample_uncertainty * sample_uncertainty;\n  \/\/ Update a bayesian estimate of the rate, weighting it lower if the sample\n  \/\/ uncertainty is large.\n  \/\/ The bitrate estimate uncertainty is increased with each update to model\n  \/\/ that the bitrate changes over time.\n  float pred_bitrate_estimate_var = bitrate_estimate_var_ + 5.f;\n  bitrate_estimate_kbps_ = (sample_var * bitrate_estimate_kbps_ +\n                            pred_bitrate_estimate_var * bitrate_sample_kbps) \/\n                           (sample_var + pred_bitrate_estimate_var);\n  bitrate_estimate_kbps_ =\n      std::max(bitrate_estimate_kbps_, estimate_floor_.Get().kbps&lt;float&gt;());\n  bitrate_estimate_var_ = sample_var * pred_bitrate_estimate_var \/\n                          (sample_var + pred_bitrate_estimate_var);\n  BWE_TEST_LOGGING_PLOT(1, &quot;acknowledged_bitrate&quot;, now_ms,\n                        bitrate_estimate_kbps_ * 1000);\n}<\/code><\/pre>\n<h2>CongestionWindowPushbackController<\/h2>\n<p>This class enables pushback from congestion window directly to video encoder.<br \/>\nWhen the congestion window is filling up, the video encoder target bitrate will be reduced accordingly to accommodate the network changes. To avoid pausing video too frequently, a minimum encoder target bitrate threshold is used to prevent video pause due to a full congestion window.<\/p>\n<p>\u6b64\u7c7b\u652f\u6301\u4ece\u62e5\u585e\u7a97\u53e3\u76f4\u63a5\u63a8\u9001\u5230\u89c6\u9891\u7f16\u7801\u5668\u3002 \u5f53\u62e5\u585e\u7a97\u53e3\u88ab\u586b\u6ee1\u65f6\uff0c\u89c6\u9891\u7f16\u7801\u5668\u76ee\u6807\u6bd4\u7279\u7387\u5c06\u76f8\u5e94\u964d\u4f4e\u4ee5\u9002\u5e94\u7f51\u7edc\u53d8\u5316\u3002 \u4e3a\u4e86\u907f\u514d\u8fc7\u4e8e\u9891\u7e41\u5730\u6682\u505c\u89c6\u9891\uff0c\u4f7f\u7528\u6700\u5c0f\u7f16\u7801\u5668\u76ee\u6807\u6bd4\u7279\u7387\u9608\u503c\u6765\u9632\u6b62\u89c6\u9891\u7531\u4e8e\u5b8c\u5168\u62e5\u585e\u7a97\u53e3\u800c\u6682\u505c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Module remote_bitrate_estimator class RemoteEstimatorProxy It is used when send-side BWE is enabled: This proxy is instantiated on the receive side. It buffers a number of receive timestamps and then sends transport feedback messages back too the send side. class AimdRateControl A rate control implementation based on additive increases of bitrate when no over-use is detected [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=377\" title=\"Permanent Link to: WebRTC Congestion Control classes\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-377","post","type-post","status-publish","format-standard","hentry","category-webrtc"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/377"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=377"}],"version-history":[{"count":21,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/377\/revisions"}],"predecessor-version":[{"id":460,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/377\/revisions\/460"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}