monitor_interval.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2018 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_PCC_MONITOR_INTERVAL_H_
  11. #define MODULES_CONGESTION_CONTROLLER_PCC_MONITOR_INTERVAL_H_
  12. #include <vector>
  13. #include "api/transport/network_types.h"
  14. #include "api/units/data_rate.h"
  15. #include "api/units/data_size.h"
  16. #include "api/units/time_delta.h"
  17. #include "api/units/timestamp.h"
  18. namespace webrtc {
  19. namespace pcc {
  20. // PCC divides time into consecutive monitor intervals which are used to test
  21. // consequences for performance of sending at a certain rate.
  22. class PccMonitorInterval {
  23. public:
  24. PccMonitorInterval(DataRate target_sending_rate,
  25. Timestamp start_time,
  26. TimeDelta duration);
  27. ~PccMonitorInterval();
  28. PccMonitorInterval(const PccMonitorInterval& other);
  29. void OnPacketsFeedback(const std::vector<PacketResult>& packets_results);
  30. // Returns true if got complete information about packets.
  31. // Notice, this only happens when received feedback about the first packet
  32. // which were sent after the end of the monitor interval. If such event
  33. // doesn't occur, we don't mind anyway and stay in the same state.
  34. bool IsFeedbackCollectionDone() const;
  35. Timestamp GetEndTime() const;
  36. double GetLossRate() const;
  37. // Estimates the gradient using linear regression on the 2-dimensional
  38. // dataset (sampled packets delay, time of sampling).
  39. double ComputeDelayGradient(double delay_gradient_threshold) const;
  40. DataRate GetTargetSendingRate() const;
  41. // How fast receiving side gets packets.
  42. DataRate GetTransmittedPacketsRate() const;
  43. private:
  44. struct ReceivedPacket {
  45. TimeDelta delay;
  46. Timestamp sent_time;
  47. };
  48. // Target bitrate used to generate and pace the outgoing packets.
  49. // Actually sent bitrate might not match the target exactly.
  50. DataRate target_sending_rate_;
  51. // Start time is not included into interval while end time is included.
  52. Timestamp start_time_;
  53. TimeDelta interval_duration_;
  54. // Vectors below updates while receiving feedback.
  55. std::vector<ReceivedPacket> received_packets_;
  56. std::vector<Timestamp> lost_packets_sent_time_;
  57. DataSize received_packets_size_;
  58. bool feedback_collection_done_;
  59. };
  60. } // namespace pcc
  61. } // namespace webrtc
  62. #endif // MODULES_CONGESTION_CONTROLLER_PCC_MONITOR_INTERVAL_H_