Chromium Code Reviews| 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/pacing/packet_router.h" | 11 #include "webrtc/modules/pacing/packet_router.h" |
| 12 | 12 |
| 13 #include "webrtc/base/atomicops.h" | 13 #include "webrtc/base/atomicops.h" |
| 14 #include "webrtc/base/checks.h" | 14 #include "webrtc/base/checks.h" |
| 15 #include "webrtc/base/timeutils.h" | |
| 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 18 | 19 |
| 19 namespace webrtc { | 20 namespace webrtc { |
| 20 | 21 |
| 21 PacketRouter::PacketRouter() : transport_seq_(0) { | 22 PacketRouter::PacketRouter() : transport_seq_(0) { |
| 22 pacer_thread_checker_.DetachFromThread(); | 23 pacer_thread_checker_.DetachFromThread(); |
| 23 } | 24 } |
| 24 | 25 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 // time the CAS operation was executed. Thus, if prev_seq is returned, the | 115 // time the CAS operation was executed. Thus, if prev_seq is returned, the |
| 115 // operation was successful - otherwise we need to retry. Saving the | 116 // operation was successful - otherwise we need to retry. Saving the |
| 116 // return value saves us a load on retry. | 117 // return value saves us a load on retry. |
| 117 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, | 118 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, |
| 118 new_seq); | 119 new_seq); |
| 119 } while (prev_seq != desired_prev_seq); | 120 } while (prev_seq != desired_prev_seq); |
| 120 | 121 |
| 121 return new_seq; | 122 return new_seq; |
| 122 } | 123 } |
| 123 | 124 |
| 124 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { | 125 void PacketRouter::OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
| 126 uint32_t bitrate) { | |
| 127 const int kRembSendIntervalMs = 200; | |
| 128 | |
| 129 // % threshold for if we should send a new REMB asap. | |
| 130 const uint32_t kSendThresholdPercent = 97; | |
| 131 | |
| 132 int64_t now = rtc::TimeMillis(); | |
| 133 { | |
| 134 rtc::CritScope lock(&remb_crit_); | |
| 135 | |
| 136 // If we already have an estimate, check if the new total estimate is below | |
| 137 // kSendThresholdPercent of the previous estimate. | |
| 138 if (last_send_bitrate_ > 0) { | |
| 139 uint32_t new_remb_bitrate = last_send_bitrate_ - bitrate_ + bitrate; | |
| 140 | |
| 141 if (new_remb_bitrate < kSendThresholdPercent * last_send_bitrate_ / 100) { | |
| 142 // The new bitrate estimate is less than kSendThresholdPercent % of the | |
| 143 // last report. Send a REMB asap. | |
| 144 last_remb_time_ = now - kRembSendIntervalMs; | |
| 145 } | |
| 146 } | |
| 147 bitrate_ = bitrate; | |
| 148 | |
| 149 if (now - last_remb_time_ < kRembSendIntervalMs) { | |
| 150 return; | |
| 151 } | |
| 152 // NOTE: Updated if we intend to send the data; we might not have | |
| 153 // a module to actually send it. | |
| 154 last_remb_time_ = now; | |
| 155 last_send_bitrate_ = bitrate; | |
| 156 } | |
| 157 { | |
| 158 rtc::CritScope lock(&modules_crit_); | |
| 159 // 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
| |
| 160 // similar to SendTransportFeedback below? | |
| 161 if (!rtp_send_modules_.empty()) | |
| 162 rtp_send_modules_.front()->SetREMBData(bitrate, ssrcs); | |
| 163 else if (!rtp_receive_modules_.empty()) | |
| 164 rtp_receive_modules_.front()->SetREMBData(bitrate, ssrcs); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 bool PacketRouter::SendTransportFeedback(rtcp::TransportFeedback* packet) { | |
| 125 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); | 169 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
| 126 rtc::CritScope cs(&modules_crit_); | 170 rtc::CritScope cs(&modules_crit_); |
| 127 // Prefer send modules. | 171 // Prefer send modules. |
| 128 for (auto* rtp_module : rtp_send_modules_) { | 172 for (auto* rtp_module : rtp_send_modules_) { |
| 129 packet->SetSenderSsrc(rtp_module->SSRC()); | 173 packet->SetSenderSsrc(rtp_module->SSRC()); |
| 130 if (rtp_module->SendFeedbackPacket(*packet)) | 174 if (rtp_module->SendFeedbackPacket(*packet)) |
| 131 return true; | 175 return true; |
| 132 } | 176 } |
| 133 for (auto* rtp_module : rtp_receive_modules_) { | 177 for (auto* rtp_module : rtp_receive_modules_) { |
| 134 packet->SetSenderSsrc(rtp_module->SSRC()); | 178 packet->SetSenderSsrc(rtp_module->SSRC()); |
| 135 if (rtp_module->SendFeedbackPacket(*packet)) | 179 if (rtp_module->SendFeedbackPacket(*packet)) |
| 136 return true; | 180 return true; |
| 137 } | 181 } |
| 138 return false; | 182 return false; |
| 139 } | 183 } |
| 140 | 184 |
| 141 } // namespace webrtc | 185 } // namespace webrtc |
| OLD | NEW |