You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2014 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_PACING_BITRATE_PROBER_H_
  11. #define MODULES_PACING_BITRATE_PROBER_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <queue>
  15. #include "api/transport/field_trial_based_config.h"
  16. #include "api/transport/network_types.h"
  17. #include "rtc_base/experiments/field_trial_parser.h"
  18. namespace webrtc {
  19. class RtcEventLog;
  20. struct BitrateProberConfig {
  21. explicit BitrateProberConfig(const WebRtcKeyValueConfig* key_value_config);
  22. BitrateProberConfig(const BitrateProberConfig&) = default;
  23. BitrateProberConfig& operator=(const BitrateProberConfig&) = default;
  24. ~BitrateProberConfig() = default;
  25. // The minimum number probing packets used.
  26. FieldTrialParameter<int> min_probe_packets_sent;
  27. // A minimum interval between probes to allow scheduling to be feasible.
  28. FieldTrialParameter<TimeDelta> min_probe_delta;
  29. // The minimum probing duration.
  30. FieldTrialParameter<TimeDelta> min_probe_duration;
  31. // Maximum amount of time each probe can be delayed. Probe cluster is reset
  32. // and retried from the start when this limit is reached.
  33. FieldTrialParameter<TimeDelta> max_probe_delay;
  34. };
  35. // Note that this class isn't thread-safe by itself and therefore relies
  36. // on being protected by the caller.
  37. class BitrateProber {
  38. public:
  39. explicit BitrateProber(const WebRtcKeyValueConfig& field_trials);
  40. ~BitrateProber();
  41. void SetEnabled(bool enable);
  42. // Returns true if the prober is in a probing session, i.e., it currently
  43. // wants packets to be sent out according to the time returned by
  44. // TimeUntilNextProbe().
  45. bool IsProbing() const;
  46. // Initializes a new probing session if the prober is allowed to probe. Does
  47. // not initialize the prober unless the packet size is large enough to probe
  48. // with.
  49. void OnIncomingPacket(size_t packet_size);
  50. // Create a cluster used to probe for |bitrate_bps| with |num_probes| number
  51. // of probes.
  52. void CreateProbeCluster(int bitrate_bps, int64_t now_ms, int cluster_id);
  53. // Returns the number of milliseconds until the next probe should be sent to
  54. // get accurate probing.
  55. int TimeUntilNextProbe(int64_t now_ms);
  56. // Information about the current probing cluster.
  57. PacedPacketInfo CurrentCluster() const;
  58. // Returns the minimum number of bytes that the prober recommends for
  59. // the next probe.
  60. size_t RecommendedMinProbeSize() const;
  61. // Called to report to the prober that a probe has been sent. In case of
  62. // multiple packets per probe, this call would be made at the end of sending
  63. // the last packet in probe. |probe_size| is the total size of all packets
  64. // in probe.
  65. void ProbeSent(int64_t now_ms, size_t probe_size);
  66. private:
  67. enum class ProbingState {
  68. // Probing will not be triggered in this state at all times.
  69. kDisabled,
  70. // Probing is enabled and ready to trigger on the first packet arrival.
  71. kInactive,
  72. // Probe cluster is filled with the set of data rates to be probed and
  73. // probes are being sent.
  74. kActive,
  75. // Probing is enabled, but currently suspended until an explicit trigger
  76. // to start probing again.
  77. kSuspended,
  78. };
  79. // A probe cluster consists of a set of probes. Each probe in turn can be
  80. // divided into a number of packets to accommodate the MTU on the network.
  81. struct ProbeCluster {
  82. PacedPacketInfo pace_info;
  83. int sent_probes = 0;
  84. int sent_bytes = 0;
  85. int64_t time_created_ms = -1;
  86. int64_t time_started_ms = -1;
  87. int retries = 0;
  88. };
  89. int64_t GetNextProbeTime(const ProbeCluster& cluster);
  90. ProbingState probing_state_;
  91. // Probe bitrate per packet. These are used to compute the delta relative to
  92. // the previous probe packet based on the size and time when that packet was
  93. // sent.
  94. std::queue<ProbeCluster> clusters_;
  95. // Time the next probe should be sent when in kActive state.
  96. int64_t next_probe_time_ms_;
  97. int total_probe_count_;
  98. int total_failed_probe_count_;
  99. BitrateProberConfig config_;
  100. };
  101. } // namespace webrtc
  102. #endif // MODULES_PACING_BITRATE_PROBER_H_