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 bool RemoveModule(RtpRtcp* rtp_module, std::list<RtpRtcp*>* rtp_modules) { | |
29 auto it = std::find(rtp_modules->begin(), rtp_modules->end(), rtp_module); | |
30 if (it == rtp_modules->end()) | |
31 return false; | |
32 rtp_modules->erase(it); | |
tommi
2016/01/23 17:23:26
if we didn't have to search the receiver list when
stefan-webrtc
2016/01/23 17:46:03
Right, that would be an option, and I can definite
tommi
2016/01/24 10:30:08
We can use std::find() inside an RTC_DCHECK to che
stefan-webrtc
2016/01/25 11:54:46
I think I'll just add a bool sender to RemoveRtpMo
| |
33 return true; | |
34 } | |
35 | |
36 bool SendFeedback(rtcp::TransportFeedback* packet, | |
37 std::list<RtpRtcp*>* rtp_modules) { | |
38 for (auto* rtp_module : *rtp_modules) { | |
39 packet->WithPacketSenderSsrc(rtp_module->SSRC()); | |
40 if (rtp_module->SendFeedbackPacket(*packet)) | |
41 return true; | |
42 } | |
43 return false; | |
44 } | |
45 } | |
46 | |
21 PacketRouter::PacketRouter() : transport_seq_(0) { | 47 PacketRouter::PacketRouter() : transport_seq_(0) { |
22 } | 48 } |
23 | 49 |
24 PacketRouter::~PacketRouter() { | 50 PacketRouter::~PacketRouter() { |
25 RTC_DCHECK(rtp_modules_.empty()); | 51 RTC_DCHECK(send_rtp_modules_.empty()); |
52 RTC_DCHECK(recv_rtp_modules_.empty()); | |
26 } | 53 } |
27 | 54 |
28 void PacketRouter::AddRtpModule(RtpRtcp* rtp_module) { | 55 void PacketRouter::AddRtpModule(RtpRtcp* rtp_module, bool sender) { |
29 rtc::CritScope cs(&modules_lock_); | 56 rtc::CritScope cs(&modules_lock_); |
30 RTC_DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) == | 57 |
31 rtp_modules_.end()); | 58 if (sender) { |
tommi
2016/01/23 17:23:26
is it good to lock both sender and receiver maps w
stefan-webrtc
2016/01/23 17:46:03
We could have different locks, but I don't think i
tommi
2016/01/24 10:30:08
I think that this particular class is very light b
stefan-webrtc
2016/01/25 11:54:46
Agree it's not very clear how expensive it is to s
| |
32 rtp_modules_.push_back(rtp_module); | 59 AddModule(rtp_module, &send_rtp_modules_); |
60 } else { | |
61 AddModule(rtp_module, &recv_rtp_modules_); | |
62 } | |
33 } | 63 } |
34 | 64 |
35 void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module) { | 65 void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module) { |
36 rtc::CritScope cs(&modules_lock_); | 66 rtc::CritScope cs(&modules_lock_); |
37 auto it = std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module); | 67 bool removed = RemoveModule(rtp_module, &send_rtp_modules_); |
38 RTC_DCHECK(it != rtp_modules_.end()); | 68 if (!removed) |
39 rtp_modules_.erase(it); | 69 removed = RemoveModule(rtp_module, &recv_rtp_modules_); |
70 RTC_DCHECK(removed); | |
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(&modules_lock_); |
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()) { |
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(&modules_lock_); |
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 15 matching lines...) Expand all Loading... | |
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 rtc::CritScope cs(&modules_lock_); |
95 for (auto* rtp_module : rtp_modules_) { | 126 if (!::webrtc::SendFeedback(packet, &recv_rtp_modules_)) |
96 packet->WithPacketSenderSsrc(rtp_module->SSRC()); | 127 return ::webrtc::SendFeedback(packet, &send_rtp_modules_); |
97 if (rtp_module->SendFeedbackPacket(*packet)) | 128 return true; |
tommi
2016/01/23 17:23:25
nit:
return webrtc::SendFeedback(packet, &recv_rt
stefan-webrtc
2016/01/23 17:46:04
Agree, I think it would be better to find the modu
tommi
2016/01/24 10:30:08
No chance that it could be removed while the call
stefan-webrtc
2016/01/25 11:54:46
I thought I could guarantee that, but unfortunatel
| |
98 return true; | |
99 } | |
100 return false; | |
101 } | 129 } |
102 | 130 |
103 } // namespace webrtc | 131 } // namespace webrtc |
OLD | NEW |