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_.erase(std::remove(rtp_receive_modules_.begin(), | |
the sun
2017/03/31 10:38:48
This doesn't look right. Did you mean std::find? s
nisse-webrtc
2017/03/31 10:51:53
My understanding is that std::remove moves element
the sun
2017/03/31 10:59:57
Ah, now I remember! Thanks. (I don't think I'll ev
nisse-webrtc
2017/03/31 11:14:08
Since we already have the find call above (in the
| |
62 rtp_receive_modules_.end(), | |
63 rtp_module), | |
64 rtp_receive_modules_.end()); | |
47 } | 65 } |
48 | 66 |
49 bool PacketRouter::TimeToSendPacket(uint32_t ssrc, | 67 bool PacketRouter::TimeToSendPacket(uint32_t ssrc, |
50 uint16_t sequence_number, | 68 uint16_t sequence_number, |
51 int64_t capture_timestamp, | 69 int64_t capture_timestamp, |
52 bool retransmission, | 70 bool retransmission, |
53 const PacedPacketInfo& pacing_info) { | 71 const PacedPacketInfo& pacing_info) { |
54 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); | 72 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
55 rtc::CritScope cs(&modules_crit_); | 73 rtc::CritScope cs(&modules_crit_); |
56 for (auto* rtp_module : rtp_modules_) { | 74 for (auto* rtp_module : rtp_send_modules_) { |
57 if (!rtp_module->SendingMedia()) | 75 if (!rtp_module->SendingMedia()) |
58 continue; | 76 continue; |
59 if (ssrc == rtp_module->SSRC() || ssrc == rtp_module->FlexfecSsrc()) { | 77 if (ssrc == rtp_module->SSRC() || ssrc == rtp_module->FlexfecSsrc()) { |
60 return rtp_module->TimeToSendPacket(ssrc, sequence_number, | 78 return rtp_module->TimeToSendPacket(ssrc, sequence_number, |
61 capture_timestamp, retransmission, | 79 capture_timestamp, retransmission, |
62 pacing_info); | 80 pacing_info); |
63 } | 81 } |
64 } | 82 } |
65 return true; | 83 return true; |
66 } | 84 } |
67 | 85 |
68 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send, | 86 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send, |
69 const PacedPacketInfo& pacing_info) { | 87 const PacedPacketInfo& pacing_info) { |
70 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); | 88 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
71 size_t total_bytes_sent = 0; | 89 size_t total_bytes_sent = 0; |
72 rtc::CritScope cs(&modules_crit_); | 90 rtc::CritScope cs(&modules_crit_); |
73 // Rtp modules are ordered by which stream can most benefit from padding. | 91 // Rtp modules are ordered by which stream can most benefit from padding. |
74 for (RtpRtcp* module : rtp_modules_) { | 92 for (RtpRtcp* module : rtp_send_modules_) { |
75 if (module->SendingMedia() && module->HasBweExtensions()) { | 93 if (module->SendingMedia() && module->HasBweExtensions()) { |
76 size_t bytes_sent = module->TimeToSendPadding( | 94 size_t bytes_sent = module->TimeToSendPadding( |
77 bytes_to_send - total_bytes_sent, pacing_info); | 95 bytes_to_send - total_bytes_sent, pacing_info); |
78 total_bytes_sent += bytes_sent; | 96 total_bytes_sent += bytes_sent; |
79 if (total_bytes_sent >= bytes_to_send) | 97 if (total_bytes_sent >= bytes_to_send) |
80 break; | 98 break; |
81 } | 99 } |
82 } | 100 } |
83 return total_bytes_sent; | 101 return total_bytes_sent; |
84 } | 102 } |
(...skipping 14 matching lines...) Expand all Loading... | |
99 // operation was successful - otherwise we need to retry. Saving the | 117 // operation was successful - otherwise we need to retry. Saving the |
100 // return value saves us a load on retry. | 118 // return value saves us a load on retry. |
101 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, | 119 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, |
102 new_seq); | 120 new_seq); |
103 } while (prev_seq != desired_prev_seq); | 121 } while (prev_seq != desired_prev_seq); |
104 | 122 |
105 return new_seq; | 123 return new_seq; |
106 } | 124 } |
107 | 125 |
108 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { | 126 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { |
127 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); | |
109 rtc::CritScope cs(&modules_crit_); | 128 rtc::CritScope cs(&modules_crit_); |
110 for (auto* rtp_module : rtp_modules_) { | 129 // Prefer send modules. |
130 for (auto* rtp_module : rtp_send_modules_) { | |
111 packet->SetSenderSsrc(rtp_module->SSRC()); | 131 packet->SetSenderSsrc(rtp_module->SSRC()); |
112 if (rtp_module->SendFeedbackPacket(*packet)) | 132 if (rtp_module->SendFeedbackPacket(*packet)) |
113 return true; | 133 return true; |
134 } | |
135 for (auto* rtp_module : rtp_receive_modules_) { | |
136 packet->SetSenderSsrc(rtp_module->SSRC()); | |
137 if (rtp_module->SendFeedbackPacket(*packet)) | |
138 return true; | |
114 } | 139 } |
115 return false; | 140 return false; |
116 } | 141 } |
117 | 142 |
118 } // namespace webrtc | 143 } // namespace webrtc |
OLD | NEW |