Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(986)

Unified Diff: webrtc/modules/pacing/packet_router.cc

Issue 1628683002: Use separate rtp module lists for send and receive in PacketRouter. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add more dchecks. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8d43a8d9a3ee9d8f0adade9dd3e3e88750adb5b5 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) {
}
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) {
+ if (sender) {
+ rtc::CritScope cs(&send_modules_crit_);
+ AddModule(rtp_module, &send_rtp_modules_);
+ } else {
+ rtc::CritScope cs(&recv_modules_crit_);
+ 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) {
+ if (sender) {
+ rtc::CritScope cs(&send_modules_crit_);
+ RemoveModule(rtp_module, &send_rtp_modules_);
+ } else {
+ rtc::CritScope cs(&recv_modules_crit_);
+ 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::CritScope cs(&send_modules_crit_);
+ for (auto* rtp_module : send_rtp_modules_) {
if (rtp_module->SendingMedia() && ssrc == rtp_module->SSRC()) {
the sun 2016/01/28 15:33:45 Can we rely on the RtpSender::sending_media_ flag
stefan-webrtc 2016/01/28 15:52:00 I'm not sure that is possible, as modules are adde
the sun 2016/01/29 10:07:07 I thought it would actually make the CL simpler -
stefan-webrtc 2016/01/29 10:59:55 I think we still should use two lists to reduce co
the sun 2016/01/29 12:29:43 Did you ever figure out how many threads are invol
stefan-webrtc 2016/01/29 13:36:33 Possibly, but both TimeToSendPacket() and SendFeed
the sun 2016/01/29 15:38:14 Sorry, I may have missed something, are you saying
stefan-webrtc 2016/01/29 16:09:07 Yes there are two, one for sending packets and (ca
the sun 2016/01/29 17:15:11 Ah, now I understand!
return rtp_module->TimeToSendPacket(ssrc, sequence_number,
capture_timestamp, retransmission);
@@ -55,8 +86,8 @@ bool PacketRouter::TimeToSendPacket(uint32_t ssrc,
size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send) {
size_t total_bytes_sent = 0;
- rtc::CritScope cs(&modules_lock_);
- for (RtpRtcp* module : rtp_modules_) {
+ rtc::CritScope cs(&send_modules_crit_);
+ for (RtpRtcp* module : send_rtp_modules_) {
if (module->SendingMedia()) {
size_t bytes_sent =
module->TimeToSendPadding(bytes_to_send - total_bytes_sent);
@@ -91,10 +122,14 @@ 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))
+ {
+ rtc::CritScope cs(&recv_modules_crit_);
+ if (::webrtc::SendFeedback(packet, &recv_rtp_modules_))
+ return true;
+ }
+ {
+ rtc::CritScope cs(&send_modules_crit_);
+ if (::webrtc::SendFeedback(packet, &send_rtp_modules_))
return true;
}
return false;

Powered by Google App Engine
This is Rietveld 408576698