Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 ProbingResult ProbeBitrateEstimator::PacketFeedback( | 41 ProbingResult ProbeBitrateEstimator::PacketFeedback( |
| 42 const PacketInfo& packet_info) { | 42 const PacketInfo& packet_info) { |
| 43 // 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 |
| 44 // belongs to an old cluster, do nothing. | 44 // belongs to an old cluster, do nothing. |
| 45 if (packet_info.probe_cluster_id == PacketInfo::kNotAProbe || | 45 if (packet_info.probe_cluster_id == PacketInfo::kNotAProbe || |
| 46 packet_info.probe_cluster_id < last_valid_cluster_id_) { | 46 packet_info.probe_cluster_id < last_valid_cluster_id_) { |
| 47 return ProbingResult(); | 47 return ProbingResult(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 int payload_size = packet_info.payload_size * 8; | |
|
danilchap
2016/08/22 13:53:35
may be call it payload_size_bits
philipel
2016/08/22 14:06:40
Done.
| |
| 50 AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id]; | 51 AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id]; |
| 51 cluster->first_send_ms = | 52 if (packet_info.send_time_ms < cluster->first_send_ms) { |
| 52 std::min(cluster->first_send_ms, packet_info.send_time_ms); | 53 cluster->first_send_ms = packet_info.send_time_ms; |
| 53 cluster->last_send_ms = | 54 } |
| 54 std::max(cluster->last_send_ms, packet_info.send_time_ms); | 55 if (packet_info.send_time_ms > cluster->last_send_ms) { |
| 55 cluster->first_receive_ms = | 56 cluster->last_send_ms = packet_info.send_time_ms; |
| 56 std::min(cluster->first_receive_ms, packet_info.arrival_time_ms); | 57 cluster->size_last_send = payload_size; |
| 57 cluster->last_receive_ms = | 58 } |
| 58 std::max(cluster->last_receive_ms, packet_info.arrival_time_ms); | 59 if (packet_info.arrival_time_ms < cluster->first_receive_ms) { |
| 59 cluster->size += packet_info.payload_size * 8; | 60 cluster->first_receive_ms = packet_info.arrival_time_ms; |
| 61 cluster->size_first_receive = payload_size; | |
| 62 } | |
| 63 if (packet_info.arrival_time_ms > cluster->last_receive_ms) { | |
| 64 cluster->last_receive_ms = packet_info.arrival_time_ms; | |
| 65 } | |
| 66 cluster->size_total += payload_size; | |
| 60 cluster->num_probes += 1; | 67 cluster->num_probes += 1; |
| 61 | 68 |
| 62 // Clean up old clusters. | 69 // Clean up old clusters. |
| 63 while (clusters_.size() > kMaxNumSavedClusters) | 70 while (clusters_.size() > kMaxNumSavedClusters) |
| 64 clusters_.erase(clusters_.begin()); | 71 clusters_.erase(clusters_.begin()); |
| 65 | 72 |
| 66 if (cluster->num_probes < kMinNumProbesValidCluster) | 73 if (cluster->num_probes < kMinNumProbesValidCluster) |
| 67 return ProbingResult(); | 74 return ProbingResult(); |
| 68 | 75 |
| 69 float send_interval_ms = cluster->last_send_ms - cluster->first_send_ms; | 76 float send_interval_ms = cluster->last_send_ms - cluster->first_send_ms; |
| 70 float receive_interval_ms = | 77 float receive_interval_ms = |
| 71 cluster->last_receive_ms - cluster->first_receive_ms; | 78 cluster->last_receive_ms - cluster->first_receive_ms; |
| 72 | 79 |
| 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 | |
| 81 if (send_interval_ms == 0 || receive_interval_ms == 0) { | 80 if (send_interval_ms == 0 || receive_interval_ms == 0) { |
| 82 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval" | 81 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval" |
| 83 << " [cluster id: " << packet_info.probe_cluster_id | 82 << " [cluster id: " << packet_info.probe_cluster_id |
| 84 << "] [send interval: " << send_interval_ms << " ms]" | 83 << "] [send interval: " << send_interval_ms << " ms]" |
| 85 << " [receive interval: " << receive_interval_ms << " ms]"; | 84 << " [receive interval: " << receive_interval_ms << " ms]"; |
| 86 | 85 |
| 87 return ProbingResult(); | 86 return ProbingResult(); |
| 88 } | 87 } |
| 89 float send_bps = static_cast<float>(cluster->size) / send_interval_ms * 1000; | 88 // Since the |send_interval_ms| does not include the time it takes to actually |
| 90 float receive_bps = | 89 // send the last packet the size of the last sent packet should not be |
| 91 static_cast<float>(cluster->size) / receive_interval_ms * 1000; | 90 // included when calculating the send bitrate. |
| 91 float send_size = cluster->size_total - cluster->size_last_send; | |
|
danilchap
2016/08/22 13:53:35
probably RTC_DCHECK_GT(cluster->size_total - clust
philipel
2016/08/22 14:06:40
Done.
| |
| 92 float send_bps = send_size / send_interval_ms * 1000; | |
| 93 | |
| 94 // Since the |receive_interval_ms| does not include the time it takes to | |
| 95 // actually receive the first packet the size of the first received packet | |
| 96 // should not be included when calculating the receive bitrate. | |
| 97 float receive_size = cluster->size_total - cluster->size_first_receive; | |
| 98 float receive_bps = receive_size / receive_interval_ms * 1000; | |
| 99 | |
| 92 float ratio = receive_bps / send_bps; | 100 float ratio = receive_bps / send_bps; |
| 93 if (ratio > kValidRatio) { | 101 if (ratio > kValidRatio) { |
| 94 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high" | 102 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high" |
| 95 << " [cluster id: " << packet_info.probe_cluster_id | 103 << " [cluster id: " << packet_info.probe_cluster_id |
| 96 << "] [send: " << cluster->size << " bytes / " | 104 << "] [send: " << send_size << " bytes / " << send_interval_ms |
| 97 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]" | 105 << " ms = " << send_bps / 1000 << " kb/s]" |
| 98 << " [receive: " << cluster->size << " bytes / " | 106 << " [receive: " << receive_size << " bytes / " |
| 99 << receive_interval_ms << " ms = " << receive_bps / 1000 | 107 << receive_interval_ms << " ms = " << receive_bps / 1000 |
| 100 << " kb/s]" | 108 << " kb/s]" |
| 101 << " [ratio: " << receive_bps / 1000 << " / " | 109 << " [ratio: " << receive_bps / 1000 << " / " |
| 102 << send_bps / 1000 << " = " << ratio << " > kValidRatio (" | 110 << send_bps / 1000 << " = " << ratio << " > kValidRatio (" |
| 103 << kValidRatio << ")]"; | 111 << kValidRatio << ")]"; |
| 104 | 112 |
| 105 return ProbingResult(); | 113 return ProbingResult(); |
| 106 } | 114 } |
| 107 // We have a valid estimate. | 115 // We have a valid estimate. |
| 108 int result_bps = std::min(send_bps, receive_bps); | 116 int result_bps = std::min(send_bps, receive_bps); |
| 109 last_valid_cluster_id_ = packet_info.probe_cluster_id; | 117 last_valid_cluster_id_ = packet_info.probe_cluster_id; |
| 110 LOG(LS_INFO) << "Probing successful" | 118 LOG(LS_INFO) << "Probing successful" |
| 111 << " [cluster id: " << packet_info.probe_cluster_id | 119 << " [cluster id: " << packet_info.probe_cluster_id |
| 112 << "] [send: " << cluster->size << " bytes / " | 120 << "] [send: " << send_size << " bytes / " << send_interval_ms |
| 113 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]" | 121 << " ms = " << send_bps / 1000 << " kb/s]" |
| 114 << " [receive: " << cluster->size << " bytes / " | 122 << " [receive: " << receive_size << " bytes / " |
| 115 << receive_interval_ms << " ms = " << receive_bps / 1000 | 123 << receive_interval_ms << " ms = " << receive_bps / 1000 |
| 116 << " kb/s]"; | 124 << " kb/s]"; |
| 117 | 125 |
| 118 return ProbingResult(result_bps, packet_info.arrival_time_ms); | 126 return ProbingResult(result_bps, packet_info.arrival_time_ms); |
| 119 } | 127 } |
| 120 } // namespace webrtc | 128 } // namespace webrtc |
| OLD | NEW |