OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 |
11 #include "webrtc/modules/congestion_controller/transport_feedback_adapter.h" | 11 #include "webrtc/modules/congestion_controller/transport_feedback_adapter.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <limits> | 14 #include <limits> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 18 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
19 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" | 19 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" |
20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
21 #include "webrtc/modules/utility/include/process_thread.h" | 21 #include "webrtc/modules/utility/include/process_thread.h" |
22 #include "webrtc/system_wrappers/include/field_trial.h" | 22 #include "webrtc/system_wrappers/include/field_trial.h" |
23 | 23 |
24 namespace webrtc { | 24 namespace webrtc { |
25 | 25 |
26 const int64_t kNoTimestamp = -1; | 26 const int64_t kNoTimestamp = -1; |
27 const int64_t kSendTimeHistoryWindowMs = 10000; | 27 const int64_t kSendTimeHistoryWindowMs = 60000; |
28 const int64_t kBaseTimestampScaleFactor = | 28 const int64_t kBaseTimestampScaleFactor = |
29 rtcp::TransportFeedback::kDeltaScaleFactor * (1 << 8); | 29 rtcp::TransportFeedback::kDeltaScaleFactor * (1 << 8); |
30 const int64_t kBaseTimestampRangeSizeUs = kBaseTimestampScaleFactor * (1 << 24); | 30 const int64_t kBaseTimestampRangeSizeUs = kBaseTimestampScaleFactor * (1 << 24); |
31 | 31 |
32 class PacketInfoComparator { | 32 class PacketInfoComparator { |
33 public: | 33 public: |
34 inline bool operator()(const PacketInfo& lhs, const PacketInfo& rhs) { | 34 inline bool operator()(const PacketInfo& lhs, const PacketInfo& rhs) { |
35 if (lhs.arrival_time_ms != rhs.arrival_time_ms) | 35 if (lhs.arrival_time_ms != rhs.arrival_time_ms) |
36 return lhs.arrival_time_ms < rhs.arrival_time_ms; | 36 return lhs.arrival_time_ms < rhs.arrival_time_ms; |
37 if (lhs.send_time_ms != rhs.send_time_ms) | 37 if (lhs.send_time_ms != rhs.send_time_ms) |
38 return lhs.send_time_ms < rhs.send_time_ms; | 38 return lhs.send_time_ms < rhs.send_time_ms; |
39 return lhs.sequence_number < rhs.sequence_number; | 39 return lhs.sequence_number < rhs.sequence_number; |
40 } | 40 } |
41 }; | 41 }; |
42 | 42 |
43 TransportFeedbackAdapter::TransportFeedbackAdapter( | 43 TransportFeedbackAdapter::TransportFeedbackAdapter( |
44 Clock* clock, | 44 Clock* clock, |
45 BitrateController* bitrate_controller) | 45 BitrateController* bitrate_controller) |
46 : send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName( | 46 : send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName( |
47 "WebRTC-SendSideBwe-WithOverhead") == "Enabled"), | 47 "WebRTC-SendSideBwe-WithOverhead") == |
48 "Enabled"), | |
48 transport_overhead_bytes_per_packet_(0), | 49 transport_overhead_bytes_per_packet_(0), |
49 send_time_history_(clock, kSendTimeHistoryWindowMs), | 50 send_time_history_(clock, kSendTimeHistoryWindowMs), |
50 clock_(clock), | 51 clock_(clock), |
51 current_offset_ms_(kNoTimestamp), | 52 current_offset_ms_(kNoTimestamp), |
52 last_timestamp_us_(kNoTimestamp), | 53 last_timestamp_us_(kNoTimestamp), |
53 bitrate_controller_(bitrate_controller) {} | 54 bitrate_controller_(bitrate_controller) {} |
54 | 55 |
55 TransportFeedbackAdapter::~TransportFeedbackAdapter() {} | 56 TransportFeedbackAdapter::~TransportFeedbackAdapter() {} |
56 | 57 |
57 void TransportFeedbackAdapter::InitBwe() { | 58 void TransportFeedbackAdapter::InitBwe() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 if (std::abs(delta - kBaseTimestampRangeSizeUs) < std::abs(delta)) { | 112 if (std::abs(delta - kBaseTimestampRangeSizeUs) < std::abs(delta)) { |
112 delta -= kBaseTimestampRangeSizeUs; // Wrap backwards. | 113 delta -= kBaseTimestampRangeSizeUs; // Wrap backwards. |
113 } else if (std::abs(delta + kBaseTimestampRangeSizeUs) < std::abs(delta)) { | 114 } else if (std::abs(delta + kBaseTimestampRangeSizeUs) < std::abs(delta)) { |
114 delta += kBaseTimestampRangeSizeUs; // Wrap forwards. | 115 delta += kBaseTimestampRangeSizeUs; // Wrap forwards. |
115 } | 116 } |
116 | 117 |
117 current_offset_ms_ += delta / 1000; | 118 current_offset_ms_ += delta / 1000; |
118 } | 119 } |
119 last_timestamp_us_ = timestamp_us; | 120 last_timestamp_us_ = timestamp_us; |
120 | 121 |
122 auto received_packets = feedback.GetReceivedPackets(); | |
121 std::vector<PacketInfo> packet_feedback_vector; | 123 std::vector<PacketInfo> packet_feedback_vector; |
122 packet_feedback_vector.reserve(feedback.GetReceivedPackets().size()); | 124 packet_feedback_vector.reserve(received_packets.size()); |
125 if (received_packets.empty()) { | |
126 LOG(LS_INFO) << "Empty transport feedback packet received."; | |
127 return packet_feedback_vector; | |
128 } | |
123 { | 129 { |
124 rtc::CritScope cs(&lock_); | 130 rtc::CritScope cs(&lock_); |
125 size_t failed_lookups = 0; | 131 size_t failed_lookups = 0; |
126 int64_t offset_us = 0; | 132 int64_t offset_us = 0; |
133 int64_t timestamp_ms = 0; | |
127 for (const auto& packet : feedback.GetReceivedPackets()) { | 134 for (const auto& packet : feedback.GetReceivedPackets()) { |
128 offset_us += packet.delta_us(); | 135 offset_us += packet.delta_us(); |
129 int64_t timestamp_ms = current_offset_ms_ + (offset_us / 1000); | 136 timestamp_ms = current_offset_ms_ + (offset_us / 1000); |
130 PacketInfo info(timestamp_ms, packet.sequence_number()); | 137 PacketInfo info(timestamp_ms, packet.sequence_number()); |
131 if (send_time_history_.GetInfo(&info, true) && info.send_time_ms >= 0) { | 138 if (!send_time_history_.GetInfo(&info, true)) |
stefan-webrtc
2017/02/10 14:15:11
With this change we will add also acks which have
| |
132 packet_feedback_vector.push_back(info); | |
133 } else { | |
134 ++failed_lookups; | 139 ++failed_lookups; |
135 } | 140 packet_feedback_vector.push_back(info); |
136 } | 141 } |
137 std::sort(packet_feedback_vector.begin(), packet_feedback_vector.end(), | 142 std::sort(packet_feedback_vector.begin(), packet_feedback_vector.end(), |
138 PacketInfoComparator()); | 143 PacketInfoComparator()); |
139 if (failed_lookups > 0) { | 144 if (failed_lookups > 0) { |
140 LOG(LS_WARNING) << "Failed to lookup send time for " << failed_lookups | 145 LOG(LS_WARNING) << "Failed to lookup send time for " << failed_lookups |
141 << " packet" << (failed_lookups > 1 ? "s" : "") | 146 << " packet" << (failed_lookups > 1 ? "s" : "") |
142 << ". Send time history too small?"; | 147 << ". Send time history too small?"; |
143 } | 148 } |
144 } | 149 } |
145 return packet_feedback_vector; | 150 return packet_feedback_vector; |
146 } | 151 } |
147 | 152 |
148 void TransportFeedbackAdapter::OnTransportFeedback( | 153 void TransportFeedbackAdapter::OnTransportFeedback( |
149 const rtcp::TransportFeedback& feedback) { | 154 const rtcp::TransportFeedback& feedback) { |
150 last_packet_feedback_vector_ = GetPacketFeedbackVector(feedback); | 155 last_packet_feedback_vector_ = GetPacketFeedbackVector(feedback); |
151 DelayBasedBwe::Result result; | 156 DelayBasedBwe::Result result; |
152 { | 157 { |
153 rtc::CritScope cs(&bwe_lock_); | 158 rtc::CritScope cs(&bwe_lock_); |
154 result = delay_based_bwe_->IncomingPacketFeedbackVector( | 159 result = delay_based_bwe_->IncomingPacketFeedbackVector( |
155 last_packet_feedback_vector_); | 160 last_packet_feedback_vector_); |
156 } | 161 } |
157 if (result.updated) | 162 if (result.updated) { |
158 bitrate_controller_->OnDelayBasedBweResult(result); | 163 bitrate_controller_->OnDelayBasedBweResult(result); |
164 } | |
159 } | 165 } |
160 | 166 |
161 std::vector<PacketInfo> TransportFeedbackAdapter::GetTransportFeedbackVector() | 167 std::vector<PacketInfo> TransportFeedbackAdapter::GetTransportFeedbackVector() |
162 const { | 168 const { |
163 return last_packet_feedback_vector_; | 169 return last_packet_feedback_vector_; |
164 } | 170 } |
165 | 171 |
166 void TransportFeedbackAdapter::OnRttUpdate(int64_t avg_rtt_ms, | 172 void TransportFeedbackAdapter::OnRttUpdate(int64_t avg_rtt_ms, |
167 int64_t max_rtt_ms) { | 173 int64_t max_rtt_ms) { |
168 rtc::CritScope cs(&bwe_lock_); | 174 rtc::CritScope cs(&bwe_lock_); |
169 delay_based_bwe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 175 delay_based_bwe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
170 } | 176 } |
171 | 177 |
172 } // namespace webrtc | 178 } // namespace webrtc |
OLD | NEW |