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 15 matching lines...) Expand all Loading... |
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_); |
110 for (auto* rtp_module : rtp_modules_) { | 125 // Prefer send modules. |
| 126 for (auto* rtp_module : rtp_send_modules_) { |
111 packet->SetSenderSsrc(rtp_module->SSRC()); | 127 packet->SetSenderSsrc(rtp_module->SSRC()); |
112 if (rtp_module->SendFeedbackPacket(*packet)) | 128 if (rtp_module->SendFeedbackPacket(*packet)) |
113 return true; | 129 return true; |
| 130 } |
| 131 for (auto* rtp_module : rtp_receive_modules_) { |
| 132 packet->SetSenderSsrc(rtp_module->SSRC()); |
| 133 if (rtp_module->SendFeedbackPacket(*packet)) |
| 134 return true; |
114 } | 135 } |
115 return false; | 136 return false; |
116 } | 137 } |
117 | 138 |
118 } // namespace webrtc | 139 } // namespace webrtc |
OLD | NEW |