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 11 #ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_BITRATE_ESTIMATOR_H_ 12 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_BITRATE_ESTIMATOR_H_ 13 14 #include <limits> 15 #include <map> 16 17 #include "absl/types/optional.h" 18 #include "api/transport/network_types.h" 19 #include "api/units/data_rate.h" 20 21 namespace webrtc { 22 class RtcEventLog; 23 24 class ProbeBitrateEstimator { 25 public: 26 explicit ProbeBitrateEstimator(RtcEventLog* event_log); 27 ~ProbeBitrateEstimator(); 28 29 // Should be called for every probe packet we receive feedback about. 30 // Returns the estimated bitrate if the probe completes a valid cluster. 31 absl::optional<DataRate> HandleProbeAndEstimateBitrate( 32 const PacketResult& packet_feedback); 33 34 absl::optional<DataRate> FetchAndResetLastEstimatedBitrate(); 35 36 private: 37 struct AggregatedCluster { 38 int num_probes = 0; 39 Timestamp first_send = Timestamp::PlusInfinity(); 40 Timestamp last_send = Timestamp::MinusInfinity(); 41 Timestamp first_receive = Timestamp::PlusInfinity(); 42 Timestamp last_receive = Timestamp::MinusInfinity(); 43 DataSize size_last_send = DataSize::Zero(); 44 DataSize size_first_receive = DataSize::Zero(); 45 DataSize size_total = DataSize::Zero(); 46 }; 47 48 // Erases old cluster data that was seen before |timestamp|. 49 void EraseOldClusters(Timestamp timestamp); 50 51 std::map<int, AggregatedCluster> clusters_; 52 RtcEventLog* const event_log_; 53 absl::optional<DataRate> estimated_data_rate_; 54 }; 55 56 } // namespace webrtc 57 58 #endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_PROBE_BITRATE_ESTIMATOR_H_ 59