network_control.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 API_TRANSPORT_NETWORK_CONTROL_H_
  11. #define API_TRANSPORT_NETWORK_CONTROL_H_
  12. #include <stdint.h>
  13. #include <memory>
  14. #include "absl/base/attributes.h"
  15. #include "api/rtc_event_log/rtc_event_log.h"
  16. #include "api/transport/network_types.h"
  17. #include "api/transport/webrtc_key_value_config.h"
  18. namespace webrtc {
  19. class TargetTransferRateObserver {
  20. public:
  21. virtual ~TargetTransferRateObserver() = default;
  22. // Called to indicate target transfer rate as well as giving information about
  23. // the current estimate of network parameters.
  24. virtual void OnTargetTransferRate(TargetTransferRate) = 0;
  25. // Called to provide updates to the expected target rate in case it changes
  26. // before the first call to OnTargetTransferRate.
  27. virtual void OnStartRateUpdate(DataRate) {}
  28. };
  29. // Configuration sent to factory create function. The parameters here are
  30. // optional to use for a network controller implementation.
  31. struct NetworkControllerConfig {
  32. // The initial constraints to start with, these can be changed at any later
  33. // time by calls to OnTargetRateConstraints. Note that the starting rate
  34. // has to be set initially to provide a starting state for the network
  35. // controller, even though the field is marked as optional.
  36. TargetRateConstraints constraints;
  37. // Initial stream specific configuration, these are changed at any later time
  38. // by calls to OnStreamsConfig.
  39. StreamsConfig stream_based_config;
  40. // Optional override of configuration of WebRTC internals. Using nullptr here
  41. // indicates that the field trial API will be used.
  42. const WebRtcKeyValueConfig* key_value_config = nullptr;
  43. // Optional override of event log.
  44. RtcEventLog* event_log = nullptr;
  45. };
  46. // NetworkControllerInterface is implemented by network controllers. A network
  47. // controller is a class that uses information about network state and traffic
  48. // to estimate network parameters such as round trip time and bandwidth. Network
  49. // controllers does not guarantee thread safety, the interface must be used in a
  50. // non-concurrent fashion.
  51. class NetworkControllerInterface {
  52. public:
  53. virtual ~NetworkControllerInterface() = default;
  54. // Called when network availabilty changes.
  55. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnNetworkAvailability(
  56. NetworkAvailability) = 0;
  57. // Called when the receiving or sending endpoint changes address.
  58. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnNetworkRouteChange(
  59. NetworkRouteChange) = 0;
  60. // Called periodically with a periodicy as specified by
  61. // NetworkControllerFactoryInterface::GetProcessInterval.
  62. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnProcessInterval(
  63. ProcessInterval) = 0;
  64. // Called when remotely calculated bitrate is received.
  65. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnRemoteBitrateReport(
  66. RemoteBitrateReport) = 0;
  67. // Called round trip time has been calculated by protocol specific mechanisms.
  68. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnRoundTripTimeUpdate(
  69. RoundTripTimeUpdate) = 0;
  70. // Called when a packet is sent on the network.
  71. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnSentPacket(
  72. SentPacket) = 0;
  73. // Called when a packet is received from the remote client.
  74. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnReceivedPacket(
  75. ReceivedPacket) = 0;
  76. // Called when the stream specific configuration has been updated.
  77. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnStreamsConfig(
  78. StreamsConfig) = 0;
  79. // Called when target transfer rate constraints has been changed.
  80. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnTargetRateConstraints(
  81. TargetRateConstraints) = 0;
  82. // Called when a protocol specific calculation of packet loss has been made.
  83. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnTransportLossReport(
  84. TransportLossReport) = 0;
  85. // Called with per packet feedback regarding receive time.
  86. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnTransportPacketsFeedback(
  87. TransportPacketsFeedback) = 0;
  88. // Called with network state estimate updates.
  89. ABSL_MUST_USE_RESULT virtual NetworkControlUpdate OnNetworkStateEstimate(
  90. NetworkStateEstimate) = 0;
  91. };
  92. // NetworkControllerFactoryInterface is an interface for creating a network
  93. // controller.
  94. class NetworkControllerFactoryInterface {
  95. public:
  96. virtual ~NetworkControllerFactoryInterface() = default;
  97. // Used to create a new network controller, requires an observer to be
  98. // provided to handle callbacks.
  99. virtual std::unique_ptr<NetworkControllerInterface> Create(
  100. NetworkControllerConfig config) = 0;
  101. // Returns the interval by which the network controller expects
  102. // OnProcessInterval calls.
  103. virtual TimeDelta GetProcessInterval() const = 0;
  104. };
  105. // Under development, subject to change without notice.
  106. class NetworkStateEstimator {
  107. public:
  108. // Gets the current best estimate according to the estimator.
  109. virtual absl::optional<NetworkStateEstimate> GetCurrentEstimate() = 0;
  110. // Called with per packet feedback regarding receive time.
  111. // Used when the NetworkStateEstimator runs in the sending endpoint.
  112. virtual void OnTransportPacketsFeedback(const TransportPacketsFeedback&) = 0;
  113. // Called with per packet feedback regarding receive time.
  114. // Used when the NetworkStateEstimator runs in the receiving endpoint.
  115. virtual void OnReceivedPacket(const PacketResult&) {}
  116. // Called when the receiving or sending endpoint changes address.
  117. virtual void OnRouteChange(const NetworkRouteChange&) = 0;
  118. virtual ~NetworkStateEstimator() = default;
  119. };
  120. class NetworkStateEstimatorFactory {
  121. public:
  122. virtual std::unique_ptr<NetworkStateEstimator> Create(
  123. const WebRtcKeyValueConfig* key_value_config) = 0;
  124. virtual ~NetworkStateEstimatorFactory() = default;
  125. };
  126. } // namespace webrtc
  127. #endif // API_TRANSPORT_NETWORK_CONTROL_H_