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/remote_bitrate_estimator/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/remote_bitrate_estimator/include/remote_bitrate_estimat
or.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/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
20 #include "webrtc/modules/utility/include/process_thread.h" | 21 #include "webrtc/modules/utility/include/process_thread.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 | 24 |
24 const int64_t kNoTimestamp = -1; | 25 const int64_t kNoTimestamp = -1; |
25 const int64_t kSendTimeHistoryWindowMs = 10000; | 26 const int64_t kSendTimeHistoryWindowMs = 10000; |
26 const int64_t kBaseTimestampScaleFactor = | 27 const int64_t kBaseTimestampScaleFactor = |
27 rtcp::TransportFeedback::kDeltaScaleFactor * (1 << 8); | 28 rtcp::TransportFeedback::kDeltaScaleFactor * (1 << 8); |
28 const int64_t kBaseTimestampRangeSizeUs = kBaseTimestampScaleFactor * (1 << 24); | 29 const int64_t kBaseTimestampRangeSizeUs = kBaseTimestampScaleFactor * (1 << 24); |
29 | 30 |
30 class PacketInfoComparator { | 31 class PacketInfoComparator { |
31 public: | 32 public: |
32 inline bool operator()(const PacketInfo& lhs, const PacketInfo& rhs) { | 33 inline bool operator()(const PacketInfo& lhs, const PacketInfo& rhs) { |
33 if (lhs.arrival_time_ms != rhs.arrival_time_ms) | 34 if (lhs.arrival_time_ms != rhs.arrival_time_ms) |
34 return lhs.arrival_time_ms < rhs.arrival_time_ms; | 35 return lhs.arrival_time_ms < rhs.arrival_time_ms; |
35 if (lhs.send_time_ms != rhs.send_time_ms) | 36 if (lhs.send_time_ms != rhs.send_time_ms) |
36 return lhs.send_time_ms < rhs.send_time_ms; | 37 return lhs.send_time_ms < rhs.send_time_ms; |
37 return lhs.sequence_number < rhs.sequence_number; | 38 return lhs.sequence_number < rhs.sequence_number; |
38 } | 39 } |
39 }; | 40 }; |
40 | 41 |
41 TransportFeedbackAdapter::TransportFeedbackAdapter( | 42 TransportFeedbackAdapter::TransportFeedbackAdapter( |
42 Clock* clock) | 43 Clock* clock, |
| 44 BitrateController* bitrate_controller) |
43 : send_time_history_(clock, kSendTimeHistoryWindowMs), | 45 : send_time_history_(clock, kSendTimeHistoryWindowMs), |
44 clock_(clock), | 46 clock_(clock), |
45 current_offset_ms_(kNoTimestamp), | 47 current_offset_ms_(kNoTimestamp), |
46 last_timestamp_us_(kNoTimestamp) {} | 48 last_timestamp_us_(kNoTimestamp), |
| 49 bitrate_controller_(bitrate_controller) {} |
47 | 50 |
48 TransportFeedbackAdapter::~TransportFeedbackAdapter() { | 51 TransportFeedbackAdapter::~TransportFeedbackAdapter() {} |
49 } | |
50 | 52 |
51 void TransportFeedbackAdapter::SetBitrateEstimator( | 53 void TransportFeedbackAdapter::InitBwe() { |
52 RemoteBitrateEstimator* rbe) { | 54 rtc::CritScope cs(&bwe_lock_); |
53 if (bitrate_estimator_.get() != rbe) { | 55 delay_based_bwe_.reset(new DelayBasedBwe(clock_)); |
54 bitrate_estimator_.reset(rbe); | |
55 } | |
56 } | 56 } |
57 | 57 |
58 void TransportFeedbackAdapter::AddPacket(uint16_t sequence_number, | 58 void TransportFeedbackAdapter::AddPacket(uint16_t sequence_number, |
59 size_t length, | 59 size_t length, |
60 int probe_cluster_id) { | 60 int probe_cluster_id) { |
61 rtc::CritScope cs(&lock_); | 61 rtc::CritScope cs(&lock_); |
62 send_time_history_.AddAndRemoveOld(sequence_number, length, probe_cluster_id); | 62 send_time_history_.AddAndRemoveOld(sequence_number, length, probe_cluster_id); |
63 } | 63 } |
64 | 64 |
65 void TransportFeedbackAdapter::OnSentPacket(uint16_t sequence_number, | 65 void TransportFeedbackAdapter::OnSentPacket(uint16_t sequence_number, |
66 int64_t send_time_ms) { | 66 int64_t send_time_ms) { |
67 rtc::CritScope cs(&lock_); | 67 rtc::CritScope cs(&lock_); |
68 send_time_history_.OnSentPacket(sequence_number, send_time_ms); | 68 send_time_history_.OnSentPacket(sequence_number, send_time_ms); |
69 } | 69 } |
70 | 70 |
| 71 void TransportFeedbackAdapter::SetMinBitrate(int min_bitrate_bps) { |
| 72 rtc::CritScope cs(&bwe_lock_); |
| 73 delay_based_bwe_->SetMinBitrate(min_bitrate_bps); |
| 74 } |
| 75 |
71 std::vector<PacketInfo> TransportFeedbackAdapter::GetPacketFeedbackVector( | 76 std::vector<PacketInfo> TransportFeedbackAdapter::GetPacketFeedbackVector( |
72 const rtcp::TransportFeedback& feedback) { | 77 const rtcp::TransportFeedback& feedback) { |
73 int64_t timestamp_us = feedback.GetBaseTimeUs(); | 78 int64_t timestamp_us = feedback.GetBaseTimeUs(); |
74 // Add timestamp deltas to a local time base selected on first packet arrival. | 79 // Add timestamp deltas to a local time base selected on first packet arrival. |
75 // This won't be the true time base, but makes it easier to manually inspect | 80 // This won't be the true time base, but makes it easier to manually inspect |
76 // time stamps. | 81 // time stamps. |
77 if (last_timestamp_us_ == kNoTimestamp) { | 82 if (last_timestamp_us_ == kNoTimestamp) { |
78 current_offset_ms_ = clock_->TimeInMilliseconds(); | 83 current_offset_ms_ = clock_->TimeInMilliseconds(); |
79 } else { | 84 } else { |
80 int64_t delta = timestamp_us - last_timestamp_us_; | 85 int64_t delta = timestamp_us - last_timestamp_us_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 << " packet" << (failed_lookups > 1 ? "s" : "") | 127 << " packet" << (failed_lookups > 1 ? "s" : "") |
123 << ". Send time history too small?"; | 128 << ". Send time history too small?"; |
124 } | 129 } |
125 } | 130 } |
126 return packet_feedback_vector; | 131 return packet_feedback_vector; |
127 } | 132 } |
128 | 133 |
129 void TransportFeedbackAdapter::OnTransportFeedback( | 134 void TransportFeedbackAdapter::OnTransportFeedback( |
130 const rtcp::TransportFeedback& feedback) { | 135 const rtcp::TransportFeedback& feedback) { |
131 last_packet_feedback_vector_ = GetPacketFeedbackVector(feedback); | 136 last_packet_feedback_vector_ = GetPacketFeedbackVector(feedback); |
132 if (bitrate_estimator_.get()) | 137 DelayBasedBwe::Result result; |
133 bitrate_estimator_->IncomingPacketFeedbackVector( | 138 { |
| 139 rtc::CritScope cs(&bwe_lock_); |
| 140 result = delay_based_bwe_->IncomingPacketFeedbackVector( |
134 last_packet_feedback_vector_); | 141 last_packet_feedback_vector_); |
| 142 } |
| 143 if (result.updated) |
| 144 bitrate_controller_->OnDelayBasedBweResult(result); |
135 } | 145 } |
136 | 146 |
137 std::vector<PacketInfo> TransportFeedbackAdapter::GetTransportFeedbackVector() | 147 std::vector<PacketInfo> TransportFeedbackAdapter::GetTransportFeedbackVector() |
138 const { | 148 const { |
139 return last_packet_feedback_vector_; | 149 return last_packet_feedback_vector_; |
140 } | 150 } |
141 | 151 |
142 void TransportFeedbackAdapter::OnRttUpdate(int64_t avg_rtt_ms, | 152 void TransportFeedbackAdapter::OnRttUpdate(int64_t avg_rtt_ms, |
143 int64_t max_rtt_ms) { | 153 int64_t max_rtt_ms) { |
144 RTC_DCHECK(bitrate_estimator_.get() != nullptr); | 154 rtc::CritScope cs(&bwe_lock_); |
145 bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 155 delay_based_bwe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
146 } | 156 } |
147 | 157 |
148 } // namespace webrtc | 158 } // namespace webrtc |
OLD | NEW |