probe_controller.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_
  11. #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_
  12. #include <stdint.h>
  13. #include <initializer_list>
  14. #include <vector>
  15. #include "absl/types/optional.h"
  16. #include "api/rtc_event_log/rtc_event_log.h"
  17. #include "api/transport/network_control.h"
  18. #include "api/transport/webrtc_key_value_config.h"
  19. #include "api/units/data_rate.h"
  20. #include "rtc_base/constructor_magic.h"
  21. #include "rtc_base/experiments/field_trial_parser.h"
  22. #include "rtc_base/system/unused.h"
  23. namespace webrtc {
  24. struct ProbeControllerConfig {
  25. explicit ProbeControllerConfig(const WebRtcKeyValueConfig* key_value_config);
  26. ProbeControllerConfig(const ProbeControllerConfig&);
  27. ProbeControllerConfig& operator=(const ProbeControllerConfig&) = default;
  28. ~ProbeControllerConfig();
  29. // These parameters configure the initial probes. First we send one or two
  30. // probes of sizes p1 * start_bitrate_bps_ and p2 * start_bitrate_bps_.
  31. // Then whenever we get a bitrate estimate of at least further_probe_threshold
  32. // times the size of the last sent probe we'll send another one of size
  33. // step_size times the new estimate.
  34. FieldTrialParameter<double> first_exponential_probe_scale;
  35. FieldTrialOptional<double> second_exponential_probe_scale;
  36. FieldTrialParameter<double> further_exponential_probe_scale;
  37. FieldTrialParameter<double> further_probe_threshold;
  38. // Configures how often we send ALR probes and how big they are.
  39. FieldTrialParameter<TimeDelta> alr_probing_interval;
  40. FieldTrialParameter<double> alr_probe_scale;
  41. // Configures the probes emitted by changed to the allocated bitrate.
  42. FieldTrialOptional<double> first_allocation_probe_scale;
  43. FieldTrialOptional<double> second_allocation_probe_scale;
  44. FieldTrialFlag allocation_allow_further_probing;
  45. FieldTrialParameter<DataRate> allocation_probe_max;
  46. };
  47. // This class controls initiation of probing to estimate initial channel
  48. // capacity. There is also support for probing during a session when max
  49. // bitrate is adjusted by an application.
  50. class ProbeController {
  51. public:
  52. explicit ProbeController(const WebRtcKeyValueConfig* key_value_config,
  53. RtcEventLog* event_log);
  54. ~ProbeController();
  55. RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> SetBitrates(
  56. int64_t min_bitrate_bps,
  57. int64_t start_bitrate_bps,
  58. int64_t max_bitrate_bps,
  59. int64_t at_time_ms);
  60. // The total bitrate, as opposed to the max bitrate, is the sum of the
  61. // configured bitrates for all active streams.
  62. RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig>
  63. OnMaxTotalAllocatedBitrate(int64_t max_total_allocated_bitrate,
  64. int64_t at_time_ms);
  65. RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> OnNetworkAvailability(
  66. NetworkAvailability msg);
  67. RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> SetEstimatedBitrate(
  68. int64_t bitrate_bps,
  69. int64_t at_time_ms);
  70. void EnablePeriodicAlrProbing(bool enable);
  71. void SetAlrStartTimeMs(absl::optional<int64_t> alr_start_time);
  72. void SetAlrEndedTimeMs(int64_t alr_end_time);
  73. RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> RequestProbe(
  74. int64_t at_time_ms);
  75. // Sets a new maximum probing bitrate, without generating a new probe cluster.
  76. void SetMaxBitrate(int64_t max_bitrate_bps);
  77. // Resets the ProbeController to a state equivalent to as if it was just
  78. // created EXCEPT for |enable_periodic_alr_probing_|.
  79. void Reset(int64_t at_time_ms);
  80. RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> Process(
  81. int64_t at_time_ms);
  82. private:
  83. enum class State {
  84. // Initial state where no probing has been triggered yet.
  85. kInit,
  86. // Waiting for probing results to continue further probing.
  87. kWaitingForProbingResult,
  88. // Probing is complete.
  89. kProbingComplete,
  90. };
  91. RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig>
  92. InitiateExponentialProbing(int64_t at_time_ms);
  93. RTC_WARN_UNUSED_RESULT std::vector<ProbeClusterConfig> InitiateProbing(
  94. int64_t now_ms,
  95. std::vector<int64_t> bitrates_to_probe,
  96. bool probe_further);
  97. bool network_available_;
  98. State state_;
  99. int64_t min_bitrate_to_probe_further_bps_;
  100. int64_t time_last_probing_initiated_ms_;
  101. int64_t estimated_bitrate_bps_;
  102. int64_t start_bitrate_bps_;
  103. int64_t max_bitrate_bps_;
  104. int64_t last_bwe_drop_probing_time_ms_;
  105. absl::optional<int64_t> alr_start_time_ms_;
  106. absl::optional<int64_t> alr_end_time_ms_;
  107. bool enable_periodic_alr_probing_;
  108. int64_t time_of_last_large_drop_ms_;
  109. int64_t bitrate_before_last_large_drop_bps_;
  110. int64_t max_total_allocated_bitrate_;
  111. const bool in_rapid_recovery_experiment_;
  112. const bool limit_probes_with_allocateable_rate_;
  113. // For WebRTC.BWE.MidCallProbing.* metric.
  114. bool mid_call_probing_waiting_for_result_;
  115. int64_t mid_call_probing_bitrate_bps_;
  116. int64_t mid_call_probing_succcess_threshold_;
  117. RtcEventLog* event_log_;
  118. int32_t next_probe_cluster_id_ = 1;
  119. ProbeControllerConfig config_;
  120. RTC_DISALLOW_COPY_AND_ASSIGN(ProbeController);
  121. };
  122. } // namespace webrtc
  123. #endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_CONTROLLER_H_