Index: webrtc/modules/pacing/packet_router.cc |
diff --git a/webrtc/modules/pacing/packet_router.cc b/webrtc/modules/pacing/packet_router.cc |
index 5fd350834a5e1ec6231966d0e7e207f79b5e5b99..e98ab0c2b02539963758ce0259c412e5657f385f 100644 |
--- a/webrtc/modules/pacing/packet_router.cc |
+++ b/webrtc/modules/pacing/packet_router.cc |
@@ -18,33 +18,64 @@ |
namespace webrtc { |
+namespace { |
+void AddModule(RtpRtcp* rtp_module, std::list<RtpRtcp*>* rtp_modules) { |
+ RTC_DCHECK(std::find(rtp_modules->begin(), rtp_modules->end(), rtp_module) == |
+ rtp_modules->end()); |
+ rtp_modules->push_back(rtp_module); |
+} |
+ |
+void RemoveModule(RtpRtcp* rtp_module, std::list<RtpRtcp*>* rtp_modules) { |
+ RTC_DCHECK(std::find(rtp_modules->begin(), rtp_modules->end(), rtp_module) != |
+ rtp_modules->end()); |
+ rtp_modules->remove(rtp_module); |
+} |
+ |
+bool SendFeedback(rtcp::TransportFeedback* packet, |
+ std::list<RtpRtcp*>* rtp_modules) { |
+ for (auto* rtp_module : *rtp_modules) { |
+ packet->WithPacketSenderSsrc(rtp_module->SSRC()); |
+ if (rtp_module->SendFeedbackPacket(*packet)) |
+ return true; |
+ } |
+ return false; |
+} |
+} |
+ |
PacketRouter::PacketRouter() : transport_seq_(0) { |
+ pacer_thread_checker_.DetachFromThread(); |
} |
PacketRouter::~PacketRouter() { |
- RTC_DCHECK(rtp_modules_.empty()); |
+ RTC_DCHECK(send_rtp_modules_.empty()); |
+ RTC_DCHECK(recv_rtp_modules_.empty()); |
} |
-void PacketRouter::AddRtpModule(RtpRtcp* rtp_module) { |
- rtc::CritScope cs(&modules_lock_); |
- RTC_DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) == |
- rtp_modules_.end()); |
- rtp_modules_.push_back(rtp_module); |
+void PacketRouter::AddRtpModule(RtpRtcp* rtp_module, bool sender) { |
+ rtc::CritScope cs(&modules_crit_); |
+ if (sender) { |
+ AddModule(rtp_module, &send_rtp_modules_); |
+ } else { |
+ AddModule(rtp_module, &recv_rtp_modules_); |
+ } |
} |
-void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module) { |
- rtc::CritScope cs(&modules_lock_); |
- auto it = std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module); |
- RTC_DCHECK(it != rtp_modules_.end()); |
- rtp_modules_.erase(it); |
+void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module, bool sender) { |
+ rtc::CritScope cs(&modules_crit_); |
+ if (sender) { |
+ RemoveModule(rtp_module, &send_rtp_modules_); |
+ } else { |
+ RemoveModule(rtp_module, &recv_rtp_modules_); |
+ } |
} |
bool PacketRouter::TimeToSendPacket(uint32_t ssrc, |
uint16_t sequence_number, |
int64_t capture_timestamp, |
bool retransmission) { |
- rtc::CritScope cs(&modules_lock_); |
- for (auto* rtp_module : rtp_modules_) { |
+ RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
+ rtc::CritScope cs(&modules_crit_); |
+ for (auto* rtp_module : send_rtp_modules_) { |
if (rtp_module->SendingMedia() && ssrc == rtp_module->SSRC()) { |
return rtp_module->TimeToSendPacket(ssrc, sequence_number, |
capture_timestamp, retransmission); |
@@ -54,9 +85,10 @@ bool PacketRouter::TimeToSendPacket(uint32_t ssrc, |
} |
size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send) { |
+ RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
size_t total_bytes_sent = 0; |
- rtc::CritScope cs(&modules_lock_); |
- for (RtpRtcp* module : rtp_modules_) { |
+ rtc::CritScope cs(&modules_crit_); |
+ for (RtpRtcp* module : send_rtp_modules_) { |
if (module->SendingMedia()) { |
size_t bytes_sent = |
module->TimeToSendPadding(bytes_to_send - total_bytes_sent); |
@@ -91,12 +123,12 @@ uint16_t PacketRouter::AllocateSequenceNumber() { |
} |
bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { |
- rtc::CritScope cs(&modules_lock_); |
- for (auto* rtp_module : rtp_modules_) { |
- packet->WithPacketSenderSsrc(rtp_module->SSRC()); |
- if (rtp_module->SendFeedbackPacket(*packet)) |
- return true; |
- } |
+ RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
+ rtc::CritScope cs(&modules_crit_); |
+ if (::webrtc::SendFeedback(packet, &recv_rtp_modules_)) |
+ return true; |
+ if (::webrtc::SendFeedback(packet, &send_rtp_modules_)) |
+ return true; |
return false; |
} |