Index: webrtc/modules/pacing/packet_router.cc |
diff --git a/webrtc/modules/pacing/packet_router.cc b/webrtc/modules/pacing/packet_router.cc |
index ab86bfa4bd82551f8014cd5652540e743577ce8d..18ec23f67b93163ebaab2365b13511ba09d6d220 100644 |
--- a/webrtc/modules/pacing/packet_router.cc |
+++ b/webrtc/modules/pacing/packet_router.cc |
@@ -12,6 +12,7 @@ |
#include "webrtc/base/atomicops.h" |
#include "webrtc/base/checks.h" |
+#include "webrtc/base/timeutils.h" |
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
@@ -121,7 +122,50 @@ uint16_t PacketRouter::AllocateSequenceNumber() { |
return new_seq; |
} |
-bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { |
+void PacketRouter::OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
+ uint32_t bitrate) { |
+ const int kRembSendIntervalMs = 200; |
+ |
+ // % threshold for if we should send a new REMB asap. |
+ const uint32_t kSendThresholdPercent = 97; |
+ |
+ int64_t now = rtc::TimeMillis(); |
+ { |
+ rtc::CritScope lock(&remb_crit_); |
+ |
+ // If we already have an estimate, check if the new total estimate is below |
+ // kSendThresholdPercent of the previous estimate. |
+ if (last_send_bitrate_ > 0) { |
+ uint32_t new_remb_bitrate = last_send_bitrate_ - bitrate_ + bitrate; |
+ |
+ if (new_remb_bitrate < kSendThresholdPercent * last_send_bitrate_ / 100) { |
+ // The new bitrate estimate is less than kSendThresholdPercent % of the |
+ // last report. Send a REMB asap. |
+ last_remb_time_ = now - kRembSendIntervalMs; |
+ } |
+ } |
+ bitrate_ = bitrate; |
+ |
+ if (now - last_remb_time_ < kRembSendIntervalMs) { |
+ return; |
+ } |
+ // NOTE: Updated if we intend to send the data; we might not have |
+ // a module to actually send it. |
+ last_remb_time_ = now; |
+ last_send_bitrate_ = bitrate; |
+ } |
+ { |
+ rtc::CritScope lock(&modules_crit_); |
+ // TODO(nisse): Check REMB status of the modules? Or add a loop, |
nisse-webrtc
2017/04/03 14:45:02
Can you have another look at this logic? Can we ge
|
+ // similar to SendTransportFeedback below? |
+ if (!rtp_send_modules_.empty()) |
+ rtp_send_modules_.front()->SetREMBData(bitrate, ssrcs); |
+ else if (!rtp_receive_modules_.empty()) |
+ rtp_receive_modules_.front()->SetREMBData(bitrate, ssrcs); |
+ } |
+} |
+ |
+bool PacketRouter::SendTransportFeedback(rtcp::TransportFeedback* packet) { |
RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
rtc::CritScope cs(&modules_crit_); |
// Prefer send modules. |