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 PacketRouter::PacketRouter() : transport_seq_(0) { | 21 PacketRouter::PacketRouter() : transport_seq_(0) { |
22 pacer_thread_checker_.DetachFromThread(); | 22 pacer_thread_checker_.DetachFromThread(); |
23 } | 23 } |
24 | 24 |
25 PacketRouter::~PacketRouter() { | 25 PacketRouter::~PacketRouter() { |
26 RTC_DCHECK(rtp_modules_.empty()); | 26 RTC_DCHECK(rtp_send_modules_.empty()); |
27 RTC_DCHECK(rtp_receive_modules_.empty()); | |
27 } | 28 } |
28 | 29 |
29 void PacketRouter::AddRtpModule(RtpRtcp* rtp_module) { | 30 void PacketRouter::AddSendRtpModule(RtpRtcp* rtp_module) { |
30 rtc::CritScope cs(&modules_crit_); | 31 rtc::CritScope cs(&modules_crit_); |
31 RTC_DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) == | 32 RTC_DCHECK(std::find(rtp_send_modules_.begin(), rtp_send_modules_.end(), |
32 rtp_modules_.end()); | 33 rtp_module) == rtp_send_modules_.end()); |
33 // Put modules which can use regular payload packets (over rtx) instead of | 34 // Put modules which can use regular payload packets (over rtx) instead of |
34 // padding first as it's less of a waste | 35 // padding first as it's less of a waste |
35 if ((rtp_module->RtxSendStatus() & kRtxRedundantPayloads) > 0) { | 36 if ((rtp_module->RtxSendStatus() & kRtxRedundantPayloads) > 0) { |
36 rtp_modules_.push_front(rtp_module); | 37 rtp_send_modules_.push_front(rtp_module); |
37 } else { | 38 } else { |
38 rtp_modules_.push_back(rtp_module); | 39 rtp_send_modules_.push_back(rtp_module); |
39 } | 40 } |
40 } | 41 } |
41 | 42 |
42 void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module) { | 43 void PacketRouter::RemoveSendRtpModule(RtpRtcp* rtp_module) { |
43 rtc::CritScope cs(&modules_crit_); | 44 rtc::CritScope cs(&modules_crit_); |
44 RTC_DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) != | 45 RTC_DCHECK(std::find(rtp_send_modules_.begin(), rtp_send_modules_.end(), |
45 rtp_modules_.end()); | 46 rtp_module) != rtp_send_modules_.end()); |
46 rtp_modules_.remove(rtp_module); | 47 rtp_send_modules_.remove(rtp_module); |
48 } | |
49 | |
50 void PacketRouter::AddReceiveRtpModule(RtpRtcp* rtp_module) { | |
51 rtc::CritScope cs(&modules_crit_); | |
52 RTC_DCHECK(std::find(rtp_receive_modules_.begin(), rtp_receive_modules_.end(), | |
53 rtp_module) == rtp_receive_modules_.end()); | |
54 rtp_receive_modules_.push_back(rtp_module); | |
55 } | |
56 | |
57 void PacketRouter::RemoveReceiveRtpModule(RtpRtcp* rtp_module) { | |
58 rtc::CritScope cs(&modules_crit_); | |
59 RTC_DCHECK(std::find(rtp_receive_modules_.begin(), rtp_receive_modules_.end(), | |
60 rtp_module) != rtp_receive_modules_.end()); | |
61 rtp_receive_modules_.remove(rtp_module); | |
47 } | 62 } |
48 | 63 |
49 bool PacketRouter::TimeToSendPacket(uint32_t ssrc, | 64 bool PacketRouter::TimeToSendPacket(uint32_t ssrc, |
50 uint16_t sequence_number, | 65 uint16_t sequence_number, |
51 int64_t capture_timestamp, | 66 int64_t capture_timestamp, |
52 bool retransmission, | 67 bool retransmission, |
53 const PacedPacketInfo& pacing_info) { | 68 const PacedPacketInfo& pacing_info) { |
54 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); | 69 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
55 rtc::CritScope cs(&modules_crit_); | 70 rtc::CritScope cs(&modules_crit_); |
56 for (auto* rtp_module : rtp_modules_) { | 71 for (auto* rtp_module : rtp_send_modules_) { |
57 if (!rtp_module->SendingMedia()) | 72 if (!rtp_module->SendingMedia()) |
58 continue; | 73 continue; |
59 if (ssrc == rtp_module->SSRC() || ssrc == rtp_module->FlexfecSsrc()) { | 74 if (ssrc == rtp_module->SSRC() || ssrc == rtp_module->FlexfecSsrc()) { |
60 return rtp_module->TimeToSendPacket(ssrc, sequence_number, | 75 return rtp_module->TimeToSendPacket(ssrc, sequence_number, |
61 capture_timestamp, retransmission, | 76 capture_timestamp, retransmission, |
62 pacing_info); | 77 pacing_info); |
63 } | 78 } |
64 } | 79 } |
65 return true; | 80 return true; |
66 } | 81 } |
67 | 82 |
68 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send, | 83 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send, |
69 const PacedPacketInfo& pacing_info) { | 84 const PacedPacketInfo& pacing_info) { |
70 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); | 85 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
71 size_t total_bytes_sent = 0; | 86 size_t total_bytes_sent = 0; |
72 rtc::CritScope cs(&modules_crit_); | 87 rtc::CritScope cs(&modules_crit_); |
73 // Rtp modules are ordered by which stream can most benefit from padding. | 88 // Rtp modules are ordered by which stream can most benefit from padding. |
74 for (RtpRtcp* module : rtp_modules_) { | 89 for (RtpRtcp* module : rtp_send_modules_) { |
75 if (module->SendingMedia() && module->HasBweExtensions()) { | 90 if (module->SendingMedia() && module->HasBweExtensions()) { |
76 size_t bytes_sent = module->TimeToSendPadding( | 91 size_t bytes_sent = module->TimeToSendPadding( |
77 bytes_to_send - total_bytes_sent, pacing_info); | 92 bytes_to_send - total_bytes_sent, pacing_info); |
78 total_bytes_sent += bytes_sent; | 93 total_bytes_sent += bytes_sent; |
79 if (total_bytes_sent >= bytes_to_send) | 94 if (total_bytes_sent >= bytes_to_send) |
80 break; | 95 break; |
81 } | 96 } |
82 } | 97 } |
83 return total_bytes_sent; | 98 return total_bytes_sent; |
84 } | 99 } |
(...skipping 14 matching lines...) Expand all Loading... | |
99 // operation was successful - otherwise we need to retry. Saving the | 114 // operation was successful - otherwise we need to retry. Saving the |
100 // return value saves us a load on retry. | 115 // return value saves us a load on retry. |
101 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, | 116 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, |
102 new_seq); | 117 new_seq); |
103 } while (prev_seq != desired_prev_seq); | 118 } while (prev_seq != desired_prev_seq); |
104 | 119 |
105 return new_seq; | 120 return new_seq; |
106 } | 121 } |
107 | 122 |
108 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { | 123 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { |
109 rtc::CritScope cs(&modules_crit_); | 124 rtc::CritScope cs(&modules_crit_); |
the sun
2017/03/28 12:21:52
From which thread is this driven, vs TimeToSendPac
nisse-webrtc
2017/03/29 13:58:36
Not entirely sure, but I think TimeToSendPacket is
the sun
2017/03/31 07:17:13
Could you add the missing thread checkers to docum
nisse-webrtc
2017/03/31 08:30:54
After a second look, I think SendFeedback is actua
the sun
2017/03/31 10:38:48
Nice!
nisse-webrtc
2017/03/31 10:51:53
Unfortunately, the lock is still needed, for synch
| |
110 for (auto* rtp_module : rtp_modules_) { | 125 for (auto* rtp_module : rtp_receive_modules_) { |
111 packet->SetSenderSsrc(rtp_module->SSRC()); | 126 packet->SetSenderSsrc(rtp_module->SSRC()); |
112 if (rtp_module->SendFeedbackPacket(*packet)) | 127 if (rtp_module->SendFeedbackPacket(*packet)) |
113 return true; | 128 return true; |
114 } | 129 } |
115 return false; | 130 return false; |
116 } | 131 } |
117 | 132 |
118 } // namespace webrtc | 133 } // namespace webrtc |
OLD | NEW |