philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_CONGESTION_CONTROLLER_PROBE_BITRATE_ESTIMATOR_H_ |
| 12 | #define MODULES_CONGESTION_CONTROLLER_PROBE_BITRATE_ESTIMATOR_H_ |
philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 13 | |
| 14 | #include <map> |
| 15 | #include <limits> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
philipel | f4238f9 | 2017-03-28 04:18:02 -0700 | [diff] [blame] | 20 | class RtcEventLog; |
philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 21 | |
philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 22 | class ProbeBitrateEstimator { |
| 23 | public: |
philipel | f4238f9 | 2017-03-28 04:18:02 -0700 | [diff] [blame] | 24 | explicit ProbeBitrateEstimator(RtcEventLog* event_log); |
nisse | 76e62b0 | 2017-05-31 02:24:52 -0700 | [diff] [blame] | 25 | ~ProbeBitrateEstimator(); |
philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 26 | |
Irfan Sheriff | f99a9de | 2016-08-23 14:23:03 -0700 | [diff] [blame] | 27 | // Should be called for every probe packet we receive feedback about. |
| 28 | // Returns the estimated bitrate if the probe completes a valid cluster. |
elad.alon | f949000 | 2017-03-06 05:32:21 -0800 | [diff] [blame] | 29 | int HandleProbeAndEstimateBitrate(const PacketFeedback& packet_feedback); |
philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 30 | |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 31 | rtc::Optional<int> FetchAndResetLastEstimatedBitrateBps(); |
| 32 | |
philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 33 | private: |
| 34 | struct AggregatedCluster { |
| 35 | int num_probes = 0; |
| 36 | int64_t first_send_ms = std::numeric_limits<int64_t>::max(); |
| 37 | int64_t last_send_ms = 0; |
| 38 | int64_t first_receive_ms = std::numeric_limits<int64_t>::max(); |
| 39 | int64_t last_receive_ms = 0; |
philipel | 0561bdf | 2016-08-24 03:43:53 -0700 | [diff] [blame] | 40 | int size_last_send = 0; |
| 41 | int size_first_receive = 0; |
| 42 | int size_total = 0; |
philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Irfan Sheriff | f99a9de | 2016-08-23 14:23:03 -0700 | [diff] [blame] | 45 | // Erases old cluster data that was seen before |timestamp_ms|. |
| 46 | void EraseOldClusters(int64_t timestamp_ms); |
| 47 | |
philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 48 | std::map<int, AggregatedCluster> clusters_; |
philipel | f4238f9 | 2017-03-28 04:18:02 -0700 | [diff] [blame] | 49 | RtcEventLog* const event_log_; |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 50 | rtc::Optional<int> estimated_bitrate_bps_; |
philipel | 233c4ba | 2016-08-01 08:49:04 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | } // namespace webrtc |
| 54 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 55 | #endif // MODULES_CONGESTION_CONTROLLER_PROBE_BITRATE_ESTIMATOR_H_ |