OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 constexpr float kValidRatio = 1.2f; | 25 constexpr float kValidRatio = 1.2f; |
26 } | 26 } |
27 | 27 |
28 namespace webrtc { | 28 namespace webrtc { |
29 | 29 |
30 ProbingResult::ProbingResult() : bps(kNoEstimate), timestamp(0) {} | 30 ProbingResult::ProbingResult() : bps(kNoEstimate), timestamp(0) {} |
31 | 31 |
32 ProbingResult::ProbingResult(int bps, int64_t timestamp) | 32 ProbingResult::ProbingResult(int bps, int64_t timestamp) |
33 : bps(bps), timestamp(timestamp) {} | 33 : bps(bps), timestamp(timestamp) {} |
34 | 34 |
| 35 bool ProbingResult::valid() const { |
| 36 return bps != kNoEstimate; |
| 37 } |
| 38 |
35 ProbeBitrateEstimator::ProbeBitrateEstimator() : last_valid_cluster_id_(0) {} | 39 ProbeBitrateEstimator::ProbeBitrateEstimator() : last_valid_cluster_id_(0) {} |
36 | 40 |
37 ProbingResult ProbeBitrateEstimator::PacketFeedback( | 41 ProbingResult ProbeBitrateEstimator::PacketFeedback( |
38 const PacketInfo& packet_info) { | 42 const PacketInfo& packet_info) { |
39 // If this is not a probing packet or if this probing packet | 43 // If this is not a probing packet or if this probing packet |
40 // belongs to an old cluster, do nothing. | 44 // belongs to an old cluster, do nothing. |
41 if (packet_info.probe_cluster_id == PacketInfo::kNotAProbe || | 45 if (packet_info.probe_cluster_id == PacketInfo::kNotAProbe || |
42 packet_info.probe_cluster_id < last_valid_cluster_id_) { | 46 packet_info.probe_cluster_id < last_valid_cluster_id_) { |
43 return ProbingResult(); | 47 return ProbingResult(); |
44 } | 48 } |
45 | 49 |
46 AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id]; | 50 AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id]; |
47 cluster->first_send_ms = | 51 cluster->first_send_ms = |
48 std::min(cluster->first_send_ms, packet_info.send_time_ms); | 52 std::min(cluster->first_send_ms, packet_info.send_time_ms); |
49 cluster->last_send_ms = | 53 cluster->last_send_ms = |
50 std::max(cluster->last_send_ms, packet_info.send_time_ms); | 54 std::max(cluster->last_send_ms, packet_info.send_time_ms); |
51 cluster->first_receive_ms = | 55 cluster->first_receive_ms = |
52 std::min(cluster->first_receive_ms, packet_info.arrival_time_ms); | 56 std::min(cluster->first_receive_ms, packet_info.arrival_time_ms); |
53 cluster->last_receive_ms = | 57 cluster->last_receive_ms = |
54 std::max(cluster->last_receive_ms, packet_info.arrival_time_ms); | 58 std::max(cluster->last_receive_ms, packet_info.arrival_time_ms); |
55 cluster->size += packet_info.payload_size; | 59 cluster->size += packet_info.payload_size * 8; |
56 cluster->num_probes += 1; | 60 cluster->num_probes += 1; |
57 | 61 |
58 // Clean up old clusters. | 62 // Clean up old clusters. |
59 while (clusters_.size() > kMaxNumSavedClusters) | 63 while (clusters_.size() > kMaxNumSavedClusters) |
60 clusters_.erase(clusters_.begin()); | 64 clusters_.erase(clusters_.begin()); |
61 | 65 |
62 if (cluster->num_probes < kMinNumProbesValidCluster) | 66 if (cluster->num_probes < kMinNumProbesValidCluster) |
63 return ProbingResult(); | 67 return ProbingResult(); |
64 | 68 |
65 int send_interval_ms = cluster->last_send_ms - cluster->first_send_ms; | 69 float send_interval_ms = cluster->last_send_ms - cluster->first_send_ms; |
66 int receive_interval_ms = | 70 float receive_interval_ms = |
67 cluster->last_receive_ms - cluster->first_receive_ms; | 71 cluster->last_receive_ms - cluster->first_receive_ms; |
68 | 72 |
| 73 // Since the send/receive interval does not include the send/receive time of |
| 74 // the last/first packet we expand the interval by the average inverval |
| 75 // between the probing packets. |
| 76 float interval_correction = |
| 77 static_cast<float>(cluster->num_probes) / (cluster->num_probes - 1); |
| 78 send_interval_ms *= interval_correction; |
| 79 receive_interval_ms *= interval_correction; |
| 80 |
69 if (send_interval_ms == 0 || receive_interval_ms == 0) { | 81 if (send_interval_ms == 0 || receive_interval_ms == 0) { |
70 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval" | 82 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval" |
71 << " [cluster id: " << packet_info.probe_cluster_id | 83 << " [cluster id: " << packet_info.probe_cluster_id |
72 << "] [send interval: " << send_interval_ms << " ms]" | 84 << "] [send interval: " << send_interval_ms << " ms]" |
73 << " [receive interval: " << receive_interval_ms << " ms]"; | 85 << " [receive interval: " << receive_interval_ms << " ms]"; |
74 | 86 |
75 return ProbingResult(); | 87 return ProbingResult(); |
76 } | 88 } |
77 | |
78 float send_bps = static_cast<float>(cluster->size) / send_interval_ms * 1000; | 89 float send_bps = static_cast<float>(cluster->size) / send_interval_ms * 1000; |
79 float receive_bps = | 90 float receive_bps = |
80 static_cast<float>(cluster->size) / receive_interval_ms * 1000; | 91 static_cast<float>(cluster->size) / receive_interval_ms * 1000; |
81 float ratio = receive_bps / send_bps; | 92 float ratio = receive_bps / send_bps; |
82 if (ratio > kValidRatio) { | 93 if (ratio > kValidRatio) { |
83 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high" | 94 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high" |
84 << " [cluster id: " << packet_info.probe_cluster_id | 95 << " [cluster id: " << packet_info.probe_cluster_id |
85 << "] [send: " << cluster->size << " bytes / " | 96 << "] [send: " << cluster->size << " bytes / " |
86 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]" | 97 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]" |
87 << " [receive: " << cluster->size << " bytes / " | 98 << " [receive: " << cluster->size << " bytes / " |
(...skipping 12 matching lines...) Expand all Loading... |
100 << " [cluster id: " << packet_info.probe_cluster_id | 111 << " [cluster id: " << packet_info.probe_cluster_id |
101 << "] [send: " << cluster->size << " bytes / " | 112 << "] [send: " << cluster->size << " bytes / " |
102 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]" | 113 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]" |
103 << " [receive: " << cluster->size << " bytes / " | 114 << " [receive: " << cluster->size << " bytes / " |
104 << receive_interval_ms << " ms = " << receive_bps / 1000 | 115 << receive_interval_ms << " ms = " << receive_bps / 1000 |
105 << " kb/s]"; | 116 << " kb/s]"; |
106 | 117 |
107 return ProbingResult(result_bps, packet_info.arrival_time_ms); | 118 return ProbingResult(result_bps, packet_info.arrival_time_ms); |
108 } | 119 } |
109 } // namespace webrtc | 120 } // namespace webrtc |
OLD | NEW |