| 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/base/timeutils.h" |
| 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 19 | 19 |
| 20 namespace webrtc { | 20 namespace webrtc { |
| 21 | 21 |
| 22 PacketRouter::PacketRouter() | 22 PacketRouter::PacketRouter() |
| 23 : last_remb_time_ms_(rtc::TimeMillis()), | 23 : last_remb_time_ms_(rtc::TimeMillis()), |
| 24 last_send_bitrate_bps_(0), | 24 last_send_bitrate_bps_(0), |
| 25 transport_seq_(0) { | 25 transport_seq_(0) {} |
| 26 pacer_thread_checker_.DetachFromThread(); | |
| 27 } | |
| 28 | 26 |
| 29 PacketRouter::~PacketRouter() { | 27 PacketRouter::~PacketRouter() { |
| 30 RTC_DCHECK(rtp_send_modules_.empty()); | 28 RTC_DCHECK(rtp_send_modules_.empty()); |
| 31 RTC_DCHECK(rtp_receive_modules_.empty()); | 29 RTC_DCHECK(rtp_receive_modules_.empty()); |
| 32 } | 30 } |
| 33 | 31 |
| 34 void PacketRouter::AddSendRtpModule(RtpRtcp* rtp_module) { | 32 void PacketRouter::AddSendRtpModule(RtpRtcp* rtp_module) { |
| 35 rtc::CritScope cs(&modules_crit_); | 33 rtc::CritScope cs(&modules_crit_); |
| 36 RTC_DCHECK(std::find(rtp_send_modules_.begin(), rtp_send_modules_.end(), | 34 RTC_DCHECK(std::find(rtp_send_modules_.begin(), rtp_send_modules_.end(), |
| 37 rtp_module) == rtp_send_modules_.end()); | 35 rtp_module) == rtp_send_modules_.end()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 rtp_receive_modules_.front()->SetREMBStatus(true); | 89 rtp_receive_modules_.front()->SetREMBStatus(true); |
| 92 } | 90 } |
| 93 } | 91 } |
| 94 } | 92 } |
| 95 | 93 |
| 96 bool PacketRouter::TimeToSendPacket(uint32_t ssrc, | 94 bool PacketRouter::TimeToSendPacket(uint32_t ssrc, |
| 97 uint16_t sequence_number, | 95 uint16_t sequence_number, |
| 98 int64_t capture_timestamp, | 96 int64_t capture_timestamp, |
| 99 bool retransmission, | 97 bool retransmission, |
| 100 const PacedPacketInfo& pacing_info) { | 98 const PacedPacketInfo& pacing_info) { |
| 101 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); | 99 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
| 102 rtc::CritScope cs(&modules_crit_); | 100 rtc::CritScope cs(&modules_crit_); |
| 103 for (auto* rtp_module : rtp_send_modules_) { | 101 for (auto* rtp_module : rtp_send_modules_) { |
| 104 if (!rtp_module->SendingMedia()) | 102 if (!rtp_module->SendingMedia()) |
| 105 continue; | 103 continue; |
| 106 if (ssrc == rtp_module->SSRC() || ssrc == rtp_module->FlexfecSsrc()) { | 104 if (ssrc == rtp_module->SSRC() || ssrc == rtp_module->FlexfecSsrc()) { |
| 107 return rtp_module->TimeToSendPacket(ssrc, sequence_number, | 105 return rtp_module->TimeToSendPacket(ssrc, sequence_number, |
| 108 capture_timestamp, retransmission, | 106 capture_timestamp, retransmission, |
| 109 pacing_info); | 107 pacing_info); |
| 110 } | 108 } |
| 111 } | 109 } |
| 112 return true; | 110 return true; |
| 113 } | 111 } |
| 114 | 112 |
| 115 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send, | 113 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send, |
| 116 const PacedPacketInfo& pacing_info) { | 114 const PacedPacketInfo& pacing_info) { |
| 117 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); | 115 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
| 118 size_t total_bytes_sent = 0; | 116 size_t total_bytes_sent = 0; |
| 119 rtc::CritScope cs(&modules_crit_); | 117 rtc::CritScope cs(&modules_crit_); |
| 120 // Rtp modules are ordered by which stream can most benefit from padding. | 118 // Rtp modules are ordered by which stream can most benefit from padding. |
| 121 for (RtpRtcp* module : rtp_send_modules_) { | 119 for (RtpRtcp* module : rtp_send_modules_) { |
| 122 if (module->SendingMedia() && module->HasBweExtensions()) { | 120 if (module->SendingMedia() && module->HasBweExtensions()) { |
| 123 size_t bytes_sent = module->TimeToSendPadding( | 121 size_t bytes_sent = module->TimeToSendPadding( |
| 124 bytes_to_send - total_bytes_sent, pacing_info); | 122 bytes_to_send - total_bytes_sent, pacing_info); |
| 125 total_bytes_sent += bytes_sent; | 123 total_bytes_sent += bytes_sent; |
| 126 if (total_bytes_sent >= bytes_to_send) | 124 if (total_bytes_sent >= bytes_to_send) |
| 127 break; | 125 break; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return false; | 199 return false; |
| 202 // The Add* and Remove* methods above ensure that this (and only this) module | 200 // The Add* and Remove* methods above ensure that this (and only this) module |
| 203 // has REMB enabled. REMB should be disabled on all other modules, because | 201 // has REMB enabled. REMB should be disabled on all other modules, because |
| 204 // otherwise, they will send REMB with stale info. | 202 // otherwise, they will send REMB with stale info. |
| 205 RTC_DCHECK(remb_module->REMB()); | 203 RTC_DCHECK(remb_module->REMB()); |
| 206 remb_module->SetREMBData(bitrate_bps, ssrcs); | 204 remb_module->SetREMBData(bitrate_bps, ssrcs); |
| 207 return true; | 205 return true; |
| 208 } | 206 } |
| 209 | 207 |
| 210 bool PacketRouter::SendTransportFeedback(rtcp::TransportFeedback* packet) { | 208 bool PacketRouter::SendTransportFeedback(rtcp::TransportFeedback* packet) { |
| 211 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); | 209 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
| 212 rtc::CritScope cs(&modules_crit_); | 210 rtc::CritScope cs(&modules_crit_); |
| 213 // Prefer send modules. | 211 // Prefer send modules. |
| 214 for (auto* rtp_module : rtp_send_modules_) { | 212 for (auto* rtp_module : rtp_send_modules_) { |
| 215 packet->SetSenderSsrc(rtp_module->SSRC()); | 213 packet->SetSenderSsrc(rtp_module->SSRC()); |
| 216 if (rtp_module->SendFeedbackPacket(*packet)) | 214 if (rtp_module->SendFeedbackPacket(*packet)) |
| 217 return true; | 215 return true; |
| 218 } | 216 } |
| 219 for (auto* rtp_module : rtp_receive_modules_) { | 217 for (auto* rtp_module : rtp_receive_modules_) { |
| 220 packet->SetSenderSsrc(rtp_module->SSRC()); | 218 packet->SetSenderSsrc(rtp_module->SSRC()); |
| 221 if (rtp_module->SendFeedbackPacket(*packet)) | 219 if (rtp_module->SendFeedbackPacket(*packet)) |
| 222 return true; | 220 return true; |
| 223 } | 221 } |
| 224 return false; | 222 return false; |
| 225 } | 223 } |
| 226 | 224 |
| 227 } // namespace webrtc | 225 } // namespace webrtc |
| OLD | NEW |