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> | |
14 #include <limits> | |
15 | |
16 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/mod_ops.h" | 15 #include "webrtc/base/mod_ops.h" |
19 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | |
20 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | |
21 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" | 16 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" |
22 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
23 #include "webrtc/modules/utility/include/process_thread.h" | |
24 #include "webrtc/system_wrappers/include/field_trial.h" | 18 #include "webrtc/system_wrappers/include/field_trial.h" |
25 | 19 |
26 namespace webrtc { | 20 namespace webrtc { |
27 | 21 |
28 const int64_t kNoTimestamp = -1; | 22 const int64_t kNoTimestamp = -1; |
29 const int64_t kSendTimeHistoryWindowMs = 60000; | 23 const int64_t kSendTimeHistoryWindowMs = 60000; |
30 const int64_t kBaseTimestampScaleFactor = | 24 const int64_t kBaseTimestampScaleFactor = |
31 rtcp::TransportFeedback::kDeltaScaleFactor * (1 << 8); | 25 rtcp::TransportFeedback::kDeltaScaleFactor * (1 << 8); |
32 const int64_t kBaseTimestampRangeSizeUs = kBaseTimestampScaleFactor * (1 << 24); | 26 const int64_t kBaseTimestampRangeSizeUs = kBaseTimestampScaleFactor * (1 << 24); |
33 | 27 |
34 TransportFeedbackAdapter::TransportFeedbackAdapter( | 28 TransportFeedbackAdapter::TransportFeedbackAdapter(Clock* clock) |
35 RtcEventLog* event_log, | |
36 Clock* clock, | |
37 BitrateController* bitrate_controller) | |
38 : send_side_bwe_with_overhead_( | 29 : send_side_bwe_with_overhead_( |
39 webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")), | 30 webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")), |
40 transport_overhead_bytes_per_packet_(0), | 31 transport_overhead_bytes_per_packet_(0), |
41 send_time_history_(clock, kSendTimeHistoryWindowMs), | 32 send_time_history_(clock, kSendTimeHistoryWindowMs), |
42 event_log_(event_log), | |
43 clock_(clock), | 33 clock_(clock), |
44 current_offset_ms_(kNoTimestamp), | 34 current_offset_ms_(kNoTimestamp), |
45 last_timestamp_us_(kNoTimestamp), | 35 last_timestamp_us_(kNoTimestamp) {} |
46 bitrate_controller_(bitrate_controller) {} | |
47 | 36 |
48 TransportFeedbackAdapter::~TransportFeedbackAdapter() {} | 37 TransportFeedbackAdapter::~TransportFeedbackAdapter() {} |
49 | 38 |
50 void TransportFeedbackAdapter::InitBwe() { | |
51 rtc::CritScope cs(&bwe_lock_); | |
52 delay_based_bwe_.reset(new DelayBasedBwe(event_log_, clock_)); | |
53 } | |
54 | |
55 void TransportFeedbackAdapter::AddPacket(uint16_t sequence_number, | 39 void TransportFeedbackAdapter::AddPacket(uint16_t sequence_number, |
56 size_t length, | 40 size_t length, |
57 const PacedPacketInfo& pacing_info) { | 41 const PacedPacketInfo& pacing_info) { |
58 rtc::CritScope cs(&lock_); | 42 rtc::CritScope cs(&lock_); |
59 if (send_side_bwe_with_overhead_) { | 43 if (send_side_bwe_with_overhead_) { |
60 length += transport_overhead_bytes_per_packet_; | 44 length += transport_overhead_bytes_per_packet_; |
61 } | 45 } |
62 send_time_history_.AddAndRemoveOld(sequence_number, length, pacing_info); | 46 send_time_history_.AddAndRemoveOld(sequence_number, length, pacing_info); |
63 } | 47 } |
64 | 48 |
65 void TransportFeedbackAdapter::OnSentPacket(uint16_t sequence_number, | 49 void TransportFeedbackAdapter::OnSentPacket(uint16_t sequence_number, |
66 int64_t send_time_ms) { | 50 int64_t send_time_ms) { |
67 rtc::CritScope cs(&lock_); | 51 rtc::CritScope cs(&lock_); |
68 send_time_history_.OnSentPacket(sequence_number, send_time_ms); | 52 send_time_history_.OnSentPacket(sequence_number, send_time_ms); |
69 } | 53 } |
70 | 54 |
71 void TransportFeedbackAdapter::SetStartBitrate(int start_bitrate_bps) { | |
72 rtc::CritScope cs(&bwe_lock_); | |
73 delay_based_bwe_->SetStartBitrate(start_bitrate_bps); | |
74 } | |
75 | |
76 void TransportFeedbackAdapter::SetMinBitrate(int min_bitrate_bps) { | |
77 rtc::CritScope cs(&bwe_lock_); | |
78 delay_based_bwe_->SetMinBitrate(min_bitrate_bps); | |
79 } | |
80 | |
81 void TransportFeedbackAdapter::SetTransportOverhead( | 55 void TransportFeedbackAdapter::SetTransportOverhead( |
82 int transport_overhead_bytes_per_packet) { | 56 int transport_overhead_bytes_per_packet) { |
83 rtc::CritScope cs(&lock_); | 57 rtc::CritScope cs(&lock_); |
84 transport_overhead_bytes_per_packet_ = transport_overhead_bytes_per_packet; | 58 transport_overhead_bytes_per_packet_ = transport_overhead_bytes_per_packet; |
85 } | 59 } |
86 | 60 |
87 int64_t TransportFeedbackAdapter::GetProbingIntervalMs() const { | |
88 rtc::CritScope cs(&bwe_lock_); | |
89 return delay_based_bwe_->GetProbingIntervalMs(); | |
90 } | |
91 | |
92 void TransportFeedbackAdapter::ClearSendTimeHistory() { | 61 void TransportFeedbackAdapter::ClearSendTimeHistory() { |
93 rtc::CritScope cs(&lock_); | 62 rtc::CritScope cs(&lock_); |
94 send_time_history_.Clear(); | 63 send_time_history_.Clear(); |
95 } | 64 } |
96 | 65 |
97 std::vector<PacketFeedback> TransportFeedbackAdapter::GetPacketFeedbackVector( | 66 std::vector<PacketFeedback> TransportFeedbackAdapter::GetPacketFeedbackVector( |
98 const rtcp::TransportFeedback& feedback) { | 67 const rtcp::TransportFeedback& feedback) { |
99 int64_t timestamp_us = feedback.GetBaseTimeUs(); | 68 int64_t timestamp_us = feedback.GetBaseTimeUs(); |
100 // Add timestamp deltas to a local time base selected on first packet arrival. | 69 // Add timestamp deltas to a local time base selected on first packet arrival. |
101 // This won't be the true time base, but makes it easier to manually inspect | 70 // This won't be the true time base, but makes it easier to manually inspect |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 << " packet" << (failed_lookups > 1 ? "s" : "") | 134 << " packet" << (failed_lookups > 1 ? "s" : "") |
166 << ". Send time history too small?"; | 135 << ". Send time history too small?"; |
167 } | 136 } |
168 } | 137 } |
169 return packet_feedback_vector; | 138 return packet_feedback_vector; |
170 } | 139 } |
171 | 140 |
172 void TransportFeedbackAdapter::OnTransportFeedback( | 141 void TransportFeedbackAdapter::OnTransportFeedback( |
173 const rtcp::TransportFeedback& feedback) { | 142 const rtcp::TransportFeedback& feedback) { |
174 last_packet_feedback_vector_ = GetPacketFeedbackVector(feedback); | 143 last_packet_feedback_vector_ = GetPacketFeedbackVector(feedback); |
175 DelayBasedBwe::Result result; | |
176 { | |
177 rtc::CritScope cs(&bwe_lock_); | |
178 result = delay_based_bwe_->IncomingPacketFeedbackVector( | |
179 last_packet_feedback_vector_); | |
180 } | |
181 if (result.updated) | |
182 bitrate_controller_->OnDelayBasedBweResult(result); | |
183 } | 144 } |
184 | 145 |
185 std::vector<PacketFeedback> | 146 std::vector<PacketFeedback> |
186 TransportFeedbackAdapter::GetTransportFeedbackVector() const { | 147 TransportFeedbackAdapter::GetTransportFeedbackVector() const { |
187 return last_packet_feedback_vector_; | 148 return last_packet_feedback_vector_; |
188 } | 149 } |
189 | |
190 void TransportFeedbackAdapter::OnRttUpdate(int64_t avg_rtt_ms, | |
191 int64_t max_rtt_ms) { | |
192 rtc::CritScope cs(&bwe_lock_); | |
193 delay_based_bwe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | |
194 } | |
195 | |
196 } // namespace webrtc | 150 } // namespace webrtc |
OLD | NEW |