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_bps) { | |
| 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_ms = 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_bps_ > 0) { | |
| 139 uint32_t new_remb_bitrate_bps = | |
| 140 last_send_bitrate_bps_ - bitrate_bps_ + bitrate_bps; | |
| 141 | |
| 142 if (new_remb_bitrate_bps < | |
| 143 kSendThresholdPercent * last_send_bitrate_bps_ / 100) { | |
| 144 // The new bitrate estimate is less than kSendThresholdPercent % of the | |
| 145 // last report. Send a REMB asap. | |
| 146 last_remb_time_ms_ = now_ms - kRembSendIntervalMs; | |
| 147 } | |
| 148 } | |
| 149 bitrate_bps_ = bitrate_bps; | |
| 150 | |
| 151 if (now_ms - last_remb_time_ms_ < kRembSendIntervalMs) { | |
| 152 return; | |
| 153 } | |
| 154 // NOTE: Updated if we intend to send the data; we might not have | |
| 155 // a module to actually send it. | |
| 156 last_remb_time_ms_ = now_ms; | |
| 157 last_send_bitrate_bps_ = bitrate_bps; | |
| 158 } | |
| 159 { | |
|
danilchap
2017/04/03 16:31:34
Do you mind splitting this block into own public f
nisse-webrtc
2017/04/04 09:46:44
Not at all. (If possible, I'd actually prefer to n
danilchap
2017/04/04 10:18:27
not strictly needed, but this is one of the way to
| |
| 160 rtc::CritScope lock(&modules_crit_); | |
| 161 // TODO(nisse): Check REMB status of the modules? Or add a loop, | |
| 162 // similar to SendTransportFeedback below? | |
| 163 if (!rtp_send_modules_.empty()) | |
| 164 rtp_send_modules_.front()->SetREMBData(bitrate_bps, ssrcs); | |
| 165 else if (!rtp_receive_modules_.empty()) | |
| 166 rtp_receive_modules_.front()->SetREMBData(bitrate_bps, ssrcs); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 bool PacketRouter::SendTransportFeedback(rtcp::TransportFeedback* packet) { | |
| 125 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); | 171 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
| 126 rtc::CritScope cs(&modules_crit_); | 172 rtc::CritScope cs(&modules_crit_); |
| 127 // Prefer send modules. | 173 // Prefer send modules. |
| 128 for (auto* rtp_module : rtp_send_modules_) { | 174 for (auto* rtp_module : rtp_send_modules_) { |
| 129 packet->SetSenderSsrc(rtp_module->SSRC()); | 175 packet->SetSenderSsrc(rtp_module->SSRC()); |
| 130 if (rtp_module->SendFeedbackPacket(*packet)) | 176 if (rtp_module->SendFeedbackPacket(*packet)) |
| 131 return true; | 177 return true; |
| 132 } | 178 } |
| 133 for (auto* rtp_module : rtp_receive_modules_) { | 179 for (auto* rtp_module : rtp_receive_modules_) { |
| 134 packet->SetSenderSsrc(rtp_module->SSRC()); | 180 packet->SetSenderSsrc(rtp_module->SSRC()); |
| 135 if (rtp_module->SendFeedbackPacket(*packet)) | 181 if (rtp_module->SendFeedbackPacket(*packet)) |
| 136 return true; | 182 return true; |
| 137 } | 183 } |
| 138 return false; | 184 return false; |
| 139 } | 185 } |
| 140 | 186 |
| 141 } // namespace webrtc | 187 } // namespace webrtc |
| OLD | NEW |