| 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/remote_estimator_proxy.h" | 11 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" |
| 12 | 12 |
| 13 #include <limits> | 13 #include <limits> |
| 14 #include <algorithm> |
| 14 | 15 |
| 15 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/system_wrappers/include/clock.h" | 18 #include "webrtc/system_wrappers/include/clock.h" |
| 18 #include "webrtc/modules/pacing/packet_router.h" | 19 #include "webrtc/modules/pacing/packet_router.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/rtp_rtcp/include/rtp_rtcp.h" | 21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 // TODO(sprang): Tune these! | 25 // TODO(sprang): Tune these! |
| 25 const int RemoteEstimatorProxy::kDefaultProcessIntervalMs = 50; | |
| 26 const int RemoteEstimatorProxy::kBackWindowMs = 500; | 26 const int RemoteEstimatorProxy::kBackWindowMs = 500; |
| 27 const int RemoteEstimatorProxy::kMinSendIntervalMs = 50; |
| 28 const int RemoteEstimatorProxy::kMaxSendIntervalMs = 250; |
| 29 const int RemoteEstimatorProxy::kDefaultSendIntervalMs = 100; |
| 27 | 30 |
| 28 // The maximum allowed value for a timestamp in milliseconds. This is lower | 31 // The maximum allowed value for a timestamp in milliseconds. This is lower |
| 29 // than the numerical limit since we often convert to microseconds. | 32 // than the numerical limit since we often convert to microseconds. |
| 30 static constexpr int64_t kMaxTimeMs = | 33 static constexpr int64_t kMaxTimeMs = |
| 31 std::numeric_limits<int64_t>::max() / 1000; | 34 std::numeric_limits<int64_t>::max() / 1000; |
| 32 | 35 |
| 33 RemoteEstimatorProxy::RemoteEstimatorProxy(Clock* clock, | 36 RemoteEstimatorProxy::RemoteEstimatorProxy(Clock* clock, |
| 34 PacketRouter* packet_router) | 37 PacketRouter* packet_router) |
| 35 : clock_(clock), | 38 : clock_(clock), |
| 36 packet_router_(packet_router), | 39 packet_router_(packet_router), |
| 37 last_process_time_ms_(-1), | 40 last_process_time_ms_(-1), |
| 38 media_ssrc_(0), | 41 media_ssrc_(0), |
| 39 feedback_sequence_(0), | 42 feedback_sequence_(0), |
| 40 window_start_seq_(-1) {} | 43 window_start_seq_(-1), |
| 44 send_interval_ms_(kDefaultSendIntervalMs) {} |
| 41 | 45 |
| 42 RemoteEstimatorProxy::~RemoteEstimatorProxy() {} | 46 RemoteEstimatorProxy::~RemoteEstimatorProxy() {} |
| 43 | 47 |
| 44 void RemoteEstimatorProxy::IncomingPacketFeedbackVector( | 48 void RemoteEstimatorProxy::IncomingPacketFeedbackVector( |
| 45 const std::vector<PacketInfo>& packet_feedback_vector) { | 49 const std::vector<PacketInfo>& packet_feedback_vector) { |
| 46 rtc::CritScope cs(&lock_); | 50 rtc::CritScope cs(&lock_); |
| 47 for (PacketInfo info : packet_feedback_vector) | 51 for (PacketInfo info : packet_feedback_vector) |
| 48 OnPacketArrival(info.sequence_number, info.arrival_time_ms); | 52 OnPacketArrival(info.sequence_number, info.arrival_time_ms); |
| 49 } | 53 } |
| 50 | 54 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 61 | 65 |
| 62 OnPacketArrival(header.extension.transportSequenceNumber, arrival_time_ms); | 66 OnPacketArrival(header.extension.transportSequenceNumber, arrival_time_ms); |
| 63 } | 67 } |
| 64 | 68 |
| 65 bool RemoteEstimatorProxy::LatestEstimate(std::vector<unsigned int>* ssrcs, | 69 bool RemoteEstimatorProxy::LatestEstimate(std::vector<unsigned int>* ssrcs, |
| 66 unsigned int* bitrate_bps) const { | 70 unsigned int* bitrate_bps) const { |
| 67 return false; | 71 return false; |
| 68 } | 72 } |
| 69 | 73 |
| 70 int64_t RemoteEstimatorProxy::TimeUntilNextProcess() { | 74 int64_t RemoteEstimatorProxy::TimeUntilNextProcess() { |
| 71 int64_t now = clock_->TimeInMilliseconds(); | |
| 72 int64_t time_until_next = 0; | 75 int64_t time_until_next = 0; |
| 73 if (last_process_time_ms_ != -1 && | 76 if (last_process_time_ms_ != -1) { |
| 74 now - last_process_time_ms_ < kDefaultProcessIntervalMs) { | 77 rtc::CritScope cs(&lock_); |
| 75 time_until_next = (last_process_time_ms_ + kDefaultProcessIntervalMs - now); | 78 int64_t now = clock_->TimeInMilliseconds(); |
| 79 if (now - last_process_time_ms_ < send_interval_ms_) |
| 80 time_until_next = (last_process_time_ms_ + send_interval_ms_ - now); |
| 76 } | 81 } |
| 77 return time_until_next; | 82 return time_until_next; |
| 78 } | 83 } |
| 79 | 84 |
| 80 void RemoteEstimatorProxy::Process() { | 85 void RemoteEstimatorProxy::Process() { |
| 81 last_process_time_ms_ = clock_->TimeInMilliseconds(); | 86 last_process_time_ms_ = clock_->TimeInMilliseconds(); |
| 82 | 87 |
| 83 bool more_to_build = true; | 88 bool more_to_build = true; |
| 84 while (more_to_build) { | 89 while (more_to_build) { |
| 85 rtcp::TransportFeedback feedback_packet; | 90 rtcp::TransportFeedback feedback_packet; |
| 86 if (BuildFeedbackPacket(&feedback_packet)) { | 91 if (BuildFeedbackPacket(&feedback_packet)) { |
| 87 RTC_DCHECK(packet_router_ != nullptr); | 92 RTC_DCHECK(packet_router_ != nullptr); |
| 88 packet_router_->SendFeedback(&feedback_packet); | 93 packet_router_->SendFeedback(&feedback_packet); |
| 89 } else { | 94 } else { |
| 90 more_to_build = false; | 95 more_to_build = false; |
| 91 } | 96 } |
| 92 } | 97 } |
| 93 } | 98 } |
| 94 | 99 |
| 100 void RemoteEstimatorProxy::OnBitrateChanged(int bitrate_bps) { |
| 101 // TwccReportSize = Ipv4(20B) + UDP(8B) + SRTP(10B) + |
| 102 // AverageTwccReport(30B) |
| 103 // TwccReport size at 50ms interval is 24 byte. |
| 104 // TwccReport size at 250ms interval is 36 byte. |
| 105 // AverageTwccReport = (TwccReport(50ms) + TwccReport(250ms)) / 2 |
| 106 constexpr int kTwccReportSize = 20 + 8 + 10 + 30; |
| 107 constexpr double kMinTwccRate = |
| 108 kTwccReportSize * 8.0 * 1000.0 / kMaxSendIntervalMs; |
| 109 constexpr double kMaxTwccRate = |
| 110 kTwccReportSize * 8.0 * 1000.0 / kMinSendIntervalMs; |
| 111 |
| 112 // Let TWCC reports occupy 5% of total bandwidth. |
| 113 rtc::CritScope cs(&lock_); |
| 114 send_interval_ms_ = static_cast<int>(0.5 + kTwccReportSize * 8.0 * 1000.0 / |
| 115 (std::max(std::min(0.05 * bitrate_bps, kMaxTwccRate), kMinTwccRate))); |
| 116 } |
| 117 |
| 95 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, | 118 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, |
| 96 int64_t arrival_time) { | 119 int64_t arrival_time) { |
| 97 if (arrival_time < 0 || arrival_time > kMaxTimeMs) { | 120 if (arrival_time < 0 || arrival_time > kMaxTimeMs) { |
| 98 LOG(LS_WARNING) << "Arrival time out of bounds: " << arrival_time; | 121 LOG(LS_WARNING) << "Arrival time out of bounds: " << arrival_time; |
| 99 return; | 122 return; |
| 100 } | 123 } |
| 101 | 124 |
| 102 // TODO(holmer): We should handle a backwards wrap here if the first | 125 // TODO(holmer): We should handle a backwards wrap here if the first |
| 103 // sequence number was small and the new sequence number is large. The | 126 // sequence number was small and the new sequence number is large. The |
| 104 // SequenceNumberUnwrapper doesn't do this, so we should replace this with | 127 // SequenceNumberUnwrapper doesn't do this, so we should replace this with |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // Note: Don't erase items from packet_arrival_times_ after sending, in case | 197 // Note: Don't erase items from packet_arrival_times_ after sending, in case |
| 175 // they need to be re-sent after a reordering. Removal will be handled | 198 // they need to be re-sent after a reordering. Removal will be handled |
| 176 // by OnPacketArrival once packets are too old. | 199 // by OnPacketArrival once packets are too old. |
| 177 window_start_seq_ = it->first + 1; | 200 window_start_seq_ = it->first + 1; |
| 178 } | 201 } |
| 179 | 202 |
| 180 return true; | 203 return true; |
| 181 } | 204 } |
| 182 | 205 |
| 183 } // namespace webrtc | 206 } // namespace webrtc |
| OLD | NEW |