blob: bb8a7ed534ea6836b41819b68b1fbb594b8482b5 [file] [log] [blame]
philipel233c4ba2016-08-01 08:49:04 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_CONGESTION_CONTROLLER_PROBE_BITRATE_ESTIMATOR_H_
12#define MODULES_CONGESTION_CONTROLLER_PROBE_BITRATE_ESTIMATOR_H_
philipel233c4ba2016-08-01 08:49:04 -070013
14#include <map>
15#include <limits>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
philipel233c4ba2016-08-01 08:49:04 -070018
19namespace webrtc {
philipelf4238f92017-03-28 04:18:02 -070020class RtcEventLog;
philipel233c4ba2016-08-01 08:49:04 -070021
philipel233c4ba2016-08-01 08:49:04 -070022class ProbeBitrateEstimator {
23 public:
philipelf4238f92017-03-28 04:18:02 -070024 explicit ProbeBitrateEstimator(RtcEventLog* event_log);
nisse76e62b02017-05-31 02:24:52 -070025 ~ProbeBitrateEstimator();
philipel233c4ba2016-08-01 08:49:04 -070026
Irfan Sherifff99a9de2016-08-23 14:23:03 -070027 // Should be called for every probe packet we receive feedback about.
28 // Returns the estimated bitrate if the probe completes a valid cluster.
elad.alonf9490002017-03-06 05:32:21 -080029 int HandleProbeAndEstimateBitrate(const PacketFeedback& packet_feedback);
philipel233c4ba2016-08-01 08:49:04 -070030
michaelt8490f8a2017-04-20 10:10:10 -070031 rtc::Optional<int> FetchAndResetLastEstimatedBitrateBps();
32
philipel233c4ba2016-08-01 08:49:04 -070033 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;
philipel0561bdf2016-08-24 03:43:53 -070040 int size_last_send = 0;
41 int size_first_receive = 0;
42 int size_total = 0;
philipel233c4ba2016-08-01 08:49:04 -070043 };
44
Irfan Sherifff99a9de2016-08-23 14:23:03 -070045 // Erases old cluster data that was seen before |timestamp_ms|.
46 void EraseOldClusters(int64_t timestamp_ms);
47
philipel233c4ba2016-08-01 08:49:04 -070048 std::map<int, AggregatedCluster> clusters_;
philipelf4238f92017-03-28 04:18:02 -070049 RtcEventLog* const event_log_;
michaelt8490f8a2017-04-20 10:10:10 -070050 rtc::Optional<int> estimated_bitrate_bps_;
philipel233c4ba2016-08-01 08:49:04 -070051};
52
53} // namespace webrtc
54
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020055#endif // MODULES_CONGESTION_CONTROLLER_PROBE_BITRATE_ESTIMATOR_H_