• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef API_TRANSPORT_NETWORK_TYPES_H_
12 #define API_TRANSPORT_NETWORK_TYPES_H_
13 #include <stdint.h>
14 
15 #include <vector>
16 
17 #include "absl/types/optional.h"
18 #include "api/units/data_rate.h"
19 #include "api/units/data_size.h"
20 #include "api/units/time_delta.h"
21 #include "api/units/timestamp.h"
22 
23 namespace webrtc {
24 
25 // Configuration
26 
27 // Represents constraints and rates related to the currently enabled streams.
28 // This is used as input to the congestion controller via the StreamsConfig
29 // struct.
30 struct BitrateAllocationLimits {
31   // The total minimum send bitrate required by all sending streams.
32   DataRate min_allocatable_rate = DataRate::Zero();
33   // The total maximum allocatable bitrate for all currently available streams.
34   DataRate max_allocatable_rate = DataRate::Zero();
35   // The max bitrate to use for padding. The sum of the per-stream max padding
36   // rate.
37   DataRate max_padding_rate = DataRate::Zero();
38 };
39 
40 // Use StreamsConfig for information about streams that is required for specific
41 // adjustments to the algorithms in network controllers. Especially useful
42 // for experiments.
43 struct StreamsConfig {
44   StreamsConfig();
45   StreamsConfig(const StreamsConfig&);
46   ~StreamsConfig();
47   Timestamp at_time = Timestamp::PlusInfinity();
48   absl::optional<bool> requests_alr_probing;
49   absl::optional<double> pacing_factor;
50 
51   // TODO(srte): Use BitrateAllocationLimits here.
52   absl::optional<DataRate> min_total_allocated_bitrate;
53   absl::optional<DataRate> max_padding_rate;
54   absl::optional<DataRate> max_total_allocated_bitrate;
55 };
56 
57 struct TargetRateConstraints {
58   TargetRateConstraints();
59   TargetRateConstraints(const TargetRateConstraints&);
60   ~TargetRateConstraints();
61   Timestamp at_time = Timestamp::PlusInfinity();
62   absl::optional<DataRate> min_data_rate;
63   absl::optional<DataRate> max_data_rate;
64   // The initial bandwidth estimate to base target rate on. This should be used
65   // as the basis for initial OnTargetTransferRate and OnPacerConfig callbacks.
66   absl::optional<DataRate> starting_rate;
67 };
68 
69 // Send side information
70 
71 struct NetworkAvailability {
72   Timestamp at_time = Timestamp::PlusInfinity();
73   bool network_available = false;
74 };
75 
76 struct NetworkRouteChange {
77   NetworkRouteChange();
78   NetworkRouteChange(const NetworkRouteChange&);
79   ~NetworkRouteChange();
80   Timestamp at_time = Timestamp::PlusInfinity();
81   // The TargetRateConstraints are set here so they can be changed synchronously
82   // when network route changes.
83   TargetRateConstraints constraints;
84 };
85 
86 struct PacedPacketInfo {
87   PacedPacketInfo();
88   PacedPacketInfo(int probe_cluster_id,
89                   int probe_cluster_min_probes,
90                   int probe_cluster_min_bytes);
91 
92   bool operator==(const PacedPacketInfo& rhs) const;
93 
94   // TODO(srte): Move probing info to a separate, optional struct.
95   static constexpr int kNotAProbe = -1;
96   int send_bitrate_bps = -1;
97   int probe_cluster_id = kNotAProbe;
98   int probe_cluster_min_probes = -1;
99   int probe_cluster_min_bytes = -1;
100   int probe_cluster_bytes_sent = 0;
101 };
102 
103 struct SentPacket {
104   Timestamp send_time = Timestamp::PlusInfinity();
105   // Size of packet with overhead up to IP layer.
106   DataSize size = DataSize::Zero();
107   // Size of preceeding packets that are not part of feedback.
108   DataSize prior_unacked_data = DataSize::Zero();
109   // Probe cluster id and parameters including bitrate, number of packets and
110   // number of bytes.
111   PacedPacketInfo pacing_info;
112   // True if the packet is an audio packet, false for video, padding, RTX etc.
113   bool audio = false;
114   // Transport independent sequence number, any tracked packet should have a
115   // sequence number that is unique over the whole call and increasing by 1 for
116   // each packet.
117   int64_t sequence_number;
118   // Tracked data in flight when the packet was sent, excluding unacked data.
119   DataSize data_in_flight = DataSize::Zero();
120 };
121 
122 struct ReceivedPacket {
123   Timestamp send_time = Timestamp::MinusInfinity();
124   Timestamp receive_time = Timestamp::PlusInfinity();
125   DataSize size = DataSize::Zero();
126 };
127 
128 // Transport level feedback
129 
130 struct RemoteBitrateReport {
131   Timestamp receive_time = Timestamp::PlusInfinity();
132   DataRate bandwidth = DataRate::Infinity();
133 };
134 
135 struct RoundTripTimeUpdate {
136   Timestamp receive_time = Timestamp::PlusInfinity();
137   TimeDelta round_trip_time = TimeDelta::PlusInfinity();
138   bool smoothed = false;
139 };
140 
141 struct TransportLossReport {
142   Timestamp receive_time = Timestamp::PlusInfinity();
143   Timestamp start_time = Timestamp::PlusInfinity();
144   Timestamp end_time = Timestamp::PlusInfinity();
145   uint64_t packets_lost_delta = 0;
146   uint64_t packets_received_delta = 0;
147 };
148 
149 // Packet level feedback
150 
151 struct PacketResult {
152   class ReceiveTimeOrder {
153    public:
154     bool operator()(const PacketResult& lhs, const PacketResult& rhs);
155   };
156 
157   PacketResult();
158   PacketResult(const PacketResult&);
159   ~PacketResult();
160 
IsReceivedPacketResult161   inline bool IsReceived() const { return !receive_time.IsPlusInfinity(); }
162 
163   SentPacket sent_packet;
164   Timestamp receive_time = Timestamp::PlusInfinity();
165 };
166 
167 struct TransportPacketsFeedback {
168   TransportPacketsFeedback();
169   TransportPacketsFeedback(const TransportPacketsFeedback& other);
170   ~TransportPacketsFeedback();
171 
172   Timestamp feedback_time = Timestamp::PlusInfinity();
173   Timestamp first_unacked_send_time = Timestamp::PlusInfinity();
174   DataSize data_in_flight = DataSize::Zero();
175   DataSize prior_in_flight = DataSize::Zero();
176   std::vector<PacketResult> packet_feedbacks;
177 
178   // Arrival times for messages without send time information.
179   std::vector<Timestamp> sendless_arrival_times;
180 
181   std::vector<PacketResult> ReceivedWithSendInfo() const;
182   std::vector<PacketResult> LostWithSendInfo() const;
183   std::vector<PacketResult> PacketsWithFeedback() const;
184   std::vector<PacketResult> SortedByReceiveTime() const;
185 };
186 
187 // Network estimation
188 
189 struct NetworkEstimate {
190   Timestamp at_time = Timestamp::PlusInfinity();
191   // Deprecated, use TargetTransferRate::target_rate instead.
192   DataRate bandwidth = DataRate::Infinity();
193   TimeDelta round_trip_time = TimeDelta::PlusInfinity();
194   TimeDelta bwe_period = TimeDelta::PlusInfinity();
195 
196   float loss_rate_ratio = 0;
197 };
198 
199 // Network control
200 
201 struct PacerConfig {
202   Timestamp at_time = Timestamp::PlusInfinity();
203   // Pacer should send at most data_window data over time_window duration.
204   DataSize data_window = DataSize::Infinity();
205   TimeDelta time_window = TimeDelta::PlusInfinity();
206   // Pacer should send at least pad_window data over time_window duration.
207   DataSize pad_window = DataSize::Zero();
data_ratePacerConfig208   DataRate data_rate() const { return data_window / time_window; }
pad_ratePacerConfig209   DataRate pad_rate() const { return pad_window / time_window; }
210 };
211 
212 struct ProbeClusterConfig {
213   Timestamp at_time = Timestamp::PlusInfinity();
214   DataRate target_data_rate = DataRate::Zero();
215   TimeDelta target_duration = TimeDelta::Zero();
216   int32_t target_probe_count = 0;
217   int32_t id = 0;
218 };
219 
220 struct TargetTransferRate {
221   Timestamp at_time = Timestamp::PlusInfinity();
222   // The estimate on which the target rate is based on.
223   NetworkEstimate network_estimate;
224   DataRate target_rate = DataRate::Zero();
225   DataRate stable_target_rate = DataRate::Zero();
226   double cwnd_reduce_ratio = 0;
227 };
228 
229 // Contains updates of network controller comand state. Using optionals to
230 // indicate whether a member has been updated. The array of probe clusters
231 // should be used to send out probes if not empty.
232 struct NetworkControlUpdate {
233   NetworkControlUpdate();
234   NetworkControlUpdate(const NetworkControlUpdate&);
235   ~NetworkControlUpdate();
236   absl::optional<DataSize> congestion_window;
237   absl::optional<PacerConfig> pacer_config;
238   std::vector<ProbeClusterConfig> probe_cluster_configs;
239   absl::optional<TargetTransferRate> target_rate;
240 };
241 
242 // Process control
243 struct ProcessInterval {
244   Timestamp at_time = Timestamp::PlusInfinity();
245   absl::optional<DataSize> pacer_queue;
246 };
247 
248 // Under development, subject to change without notice.
249 struct NetworkStateEstimate {
250   double confidence = NAN;
251   // The time the estimate was received/calculated.
252   Timestamp update_time = Timestamp::MinusInfinity();
253   Timestamp last_receive_time = Timestamp::MinusInfinity();
254   Timestamp last_send_time = Timestamp::MinusInfinity();
255 
256   // Total estimated link capacity.
257   DataRate link_capacity = DataRate::MinusInfinity();
258   // Used as a safe measure of available capacity.
259   DataRate link_capacity_lower = DataRate::MinusInfinity();
260   // Used as limit for increasing bitrate.
261   DataRate link_capacity_upper = DataRate::MinusInfinity();
262 
263   TimeDelta pre_link_buffer_delay = TimeDelta::MinusInfinity();
264   TimeDelta post_link_buffer_delay = TimeDelta::MinusInfinity();
265   TimeDelta propagation_delay = TimeDelta::MinusInfinity();
266 
267   // Only for debugging
268   TimeDelta time_delta = TimeDelta::MinusInfinity();
269   Timestamp last_feed_time = Timestamp::MinusInfinity();
270   double cross_delay_rate = NAN;
271   double spike_delay_rate = NAN;
272   DataRate link_capacity_std_dev = DataRate::MinusInfinity();
273   DataRate link_capacity_min = DataRate::MinusInfinity();
274   double cross_traffic_ratio = NAN;
275 };
276 }  // namespace webrtc
277 
278 #endif  // API_TRANSPORT_NETWORK_TYPES_H_
279