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/modules/rtp_rtcp/include/rtp_rtcp.h" | 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 | 20 |
| 21 namespace { | |
| 22 void AddModule(RtpRtcp* rtp_module, std::list<RtpRtcp*>* rtp_modules) { | |
| 23 RTC_DCHECK(std::find(rtp_modules->begin(), rtp_modules->end(), rtp_module) == | |
| 24 rtp_modules->end()); | |
| 25 rtp_modules->push_back(rtp_module); | |
| 26 } | |
| 27 | |
| 28 void RemoveModule(RtpRtcp* rtp_module, std::list<RtpRtcp*>* rtp_modules) { | |
| 29 RTC_DCHECK(std::find(rtp_modules->begin(), rtp_modules->end(), rtp_module) != | |
| 30 rtp_modules->end()); | |
| 31 rtp_modules->remove(rtp_module); | |
| 32 } | |
| 33 | |
| 34 bool SendFeedback(rtcp::TransportFeedback* packet, | |
| 35 std::list<RtpRtcp*>* rtp_modules) { | |
| 36 for (auto* rtp_module : *rtp_modules) { | |
| 37 packet->WithPacketSenderSsrc(rtp_module->SSRC()); | |
| 38 if (rtp_module->SendFeedbackPacket(*packet)) | |
| 39 return true; | |
| 40 } | |
| 41 return false; | |
| 42 } | |
| 43 } | |
| 44 | |
| 21 PacketRouter::PacketRouter() : transport_seq_(0) { | 45 PacketRouter::PacketRouter() : transport_seq_(0) { |
| 22 } | 46 } |
| 23 | 47 |
| 24 PacketRouter::~PacketRouter() { | 48 PacketRouter::~PacketRouter() { |
| 25 RTC_DCHECK(rtp_modules_.empty()); | 49 RTC_DCHECK(send_rtp_modules_.empty()); |
| 50 RTC_DCHECK(recv_rtp_modules_.empty()); | |
| 26 } | 51 } |
| 27 | 52 |
| 28 void PacketRouter::AddRtpModule(RtpRtcp* rtp_module) { | 53 void PacketRouter::AddRtpModule(RtpRtcp* rtp_module, bool sender) { |
| 29 rtc::CritScope cs(&modules_lock_); | 54 if (sender) { |
| 30 RTC_DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) == | 55 rtc::CritScope cs(&send_modules_crit_); |
| 31 rtp_modules_.end()); | 56 AddModule(rtp_module, &send_rtp_modules_); |
| 32 rtp_modules_.push_back(rtp_module); | 57 } else { |
| 58 rtc::CritScope cs(&recv_modules_crit_); | |
| 59 AddModule(rtp_module, &recv_rtp_modules_); | |
| 60 } | |
| 33 } | 61 } |
| 34 | 62 |
| 35 void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module) { | 63 void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module, bool sender) { |
| 36 rtc::CritScope cs(&modules_lock_); | 64 if (sender) { |
| 37 auto it = std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module); | 65 rtc::CritScope cs(&send_modules_crit_); |
| 38 RTC_DCHECK(it != rtp_modules_.end()); | 66 RemoveModule(rtp_module, &send_rtp_modules_); |
| 39 rtp_modules_.erase(it); | 67 } else { |
| 68 rtc::CritScope cs(&recv_modules_crit_); | |
| 69 RemoveModule(rtp_module, &recv_rtp_modules_); | |
| 70 } | |
| 40 } | 71 } |
| 41 | 72 |
| 42 bool PacketRouter::TimeToSendPacket(uint32_t ssrc, | 73 bool PacketRouter::TimeToSendPacket(uint32_t ssrc, |
| 43 uint16_t sequence_number, | 74 uint16_t sequence_number, |
| 44 int64_t capture_timestamp, | 75 int64_t capture_timestamp, |
| 45 bool retransmission) { | 76 bool retransmission) { |
| 46 rtc::CritScope cs(&modules_lock_); | 77 rtc::CritScope cs(&send_modules_crit_); |
| 47 for (auto* rtp_module : rtp_modules_) { | 78 for (auto* rtp_module : send_rtp_modules_) { |
| 48 if (rtp_module->SendingMedia() && ssrc == rtp_module->SSRC()) { | 79 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!
| |
| 49 return rtp_module->TimeToSendPacket(ssrc, sequence_number, | 80 return rtp_module->TimeToSendPacket(ssrc, sequence_number, |
| 50 capture_timestamp, retransmission); | 81 capture_timestamp, retransmission); |
| 51 } | 82 } |
| 52 } | 83 } |
| 53 return true; | 84 return true; |
| 54 } | 85 } |
| 55 | 86 |
| 56 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send) { | 87 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send) { |
| 57 size_t total_bytes_sent = 0; | 88 size_t total_bytes_sent = 0; |
| 58 rtc::CritScope cs(&modules_lock_); | 89 rtc::CritScope cs(&send_modules_crit_); |
| 59 for (RtpRtcp* module : rtp_modules_) { | 90 for (RtpRtcp* module : send_rtp_modules_) { |
| 60 if (module->SendingMedia()) { | 91 if (module->SendingMedia()) { |
| 61 size_t bytes_sent = | 92 size_t bytes_sent = |
| 62 module->TimeToSendPadding(bytes_to_send - total_bytes_sent); | 93 module->TimeToSendPadding(bytes_to_send - total_bytes_sent); |
| 63 total_bytes_sent += bytes_sent; | 94 total_bytes_sent += bytes_sent; |
| 64 if (total_bytes_sent >= bytes_to_send) | 95 if (total_bytes_sent >= bytes_to_send) |
| 65 break; | 96 break; |
| 66 } | 97 } |
| 67 } | 98 } |
| 68 return total_bytes_sent; | 99 return total_bytes_sent; |
| 69 } | 100 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 84 // operation was successful - otherwise we need to retry. Saving the | 115 // operation was successful - otherwise we need to retry. Saving the |
| 85 // return value saves us a load on retry. | 116 // return value saves us a load on retry. |
| 86 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, | 117 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, |
| 87 new_seq); | 118 new_seq); |
| 88 } while (prev_seq != desired_prev_seq); | 119 } while (prev_seq != desired_prev_seq); |
| 89 | 120 |
| 90 return new_seq; | 121 return new_seq; |
| 91 } | 122 } |
| 92 | 123 |
| 93 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { | 124 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { |
| 94 rtc::CritScope cs(&modules_lock_); | 125 { |
| 95 for (auto* rtp_module : rtp_modules_) { | 126 rtc::CritScope cs(&recv_modules_crit_); |
| 96 packet->WithPacketSenderSsrc(rtp_module->SSRC()); | 127 if (::webrtc::SendFeedback(packet, &recv_rtp_modules_)) |
| 97 if (rtp_module->SendFeedbackPacket(*packet)) | 128 return true; |
| 129 } | |
| 130 { | |
| 131 rtc::CritScope cs(&send_modules_crit_); | |
| 132 if (::webrtc::SendFeedback(packet, &send_rtp_modules_)) | |
| 98 return true; | 133 return true; |
| 99 } | 134 } |
| 100 return false; | 135 return false; |
| 101 } | 136 } |
| 102 | 137 |
| 103 } // namespace webrtc | 138 } // namespace webrtc |
| OLD | NEW |