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() {} |
22 } | |
23 | 22 |
24 PacketRouter::~PacketRouter() { | 23 PacketRouter::~PacketRouter() { |
25 RTC_DCHECK(rtp_modules_.empty()); | 24 RTC_DCHECK(rtp_modules_.empty()); |
26 } | 25 } |
27 | 26 |
28 void PacketRouter::AddRtpModule(RtpRtcp* rtp_module) { | 27 void PacketRouter::AddRtpModule(RtpRtcp* rtp_module) { |
29 rtc::CritScope cs(&modules_lock_); | 28 rtc::CritScope cs(&modules_lock_); |
30 RTC_DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) == | 29 RTC_DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) == |
31 rtp_modules_.end()); | 30 rtp_modules_.end()); |
32 rtp_modules_.push_back(rtp_module); | 31 rtp_modules_.push_back(rtp_module); |
(...skipping 29 matching lines...) Expand all Loading... |
62 module->TimeToSendPadding(bytes_to_send - total_bytes_sent); | 61 module->TimeToSendPadding(bytes_to_send - total_bytes_sent); |
63 total_bytes_sent += bytes_sent; | 62 total_bytes_sent += bytes_sent; |
64 if (total_bytes_sent >= bytes_to_send) | 63 if (total_bytes_sent >= bytes_to_send) |
65 break; | 64 break; |
66 } | 65 } |
67 } | 66 } |
68 return total_bytes_sent; | 67 return total_bytes_sent; |
69 } | 68 } |
70 | 69 |
71 void PacketRouter::SetTransportWideSequenceNumber(uint16_t sequence_number) { | 70 void PacketRouter::SetTransportWideSequenceNumber(uint16_t sequence_number) { |
72 rtc::AtomicOps::ReleaseStore(&transport_seq_, sequence_number); | 71 rtc::AtomicInt::ReleaseStore(&transport_seq_, sequence_number); |
73 } | 72 } |
74 | 73 |
75 uint16_t PacketRouter::AllocateSequenceNumber() { | 74 uint16_t PacketRouter::AllocateSequenceNumber() { |
76 int prev_seq = rtc::AtomicOps::AcquireLoad(&transport_seq_); | 75 int prev_seq = rtc::AtomicInt::AcquireLoad(&transport_seq_); |
77 int desired_prev_seq; | 76 int desired_prev_seq; |
78 int new_seq; | 77 int new_seq; |
79 do { | 78 do { |
80 desired_prev_seq = prev_seq; | 79 desired_prev_seq = prev_seq; |
81 new_seq = (desired_prev_seq + 1) & 0xFFFF; | 80 new_seq = (desired_prev_seq + 1) & 0xFFFF; |
82 // Note: CompareAndSwap returns the actual value of transport_seq at the | 81 // Note: CompareAndSwap returns the actual value of transport_seq at the |
83 // time the CAS operation was executed. Thus, if prev_seq is returned, the | 82 // time the CAS operation was executed. Thus, if prev_seq is returned, the |
84 // operation was successful - otherwise we need to retry. Saving the | 83 // operation was successful - otherwise we need to retry. Saving the |
85 // return value saves us a load on retry. | 84 // return value saves us a load on retry. |
86 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, | 85 prev_seq = rtc::AtomicInt::CompareAndSwap(&transport_seq_, desired_prev_seq, |
87 new_seq); | 86 new_seq); |
88 } while (prev_seq != desired_prev_seq); | 87 } while (prev_seq != desired_prev_seq); |
89 | 88 |
90 return new_seq; | 89 return new_seq; |
91 } | 90 } |
92 | 91 |
93 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { | 92 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { |
94 rtc::CritScope cs(&modules_lock_); | 93 rtc::CritScope cs(&modules_lock_); |
95 for (auto* rtp_module : rtp_modules_) { | 94 for (auto* rtp_module : rtp_modules_) { |
96 packet->WithPacketSenderSsrc(rtp_module->SSRC()); | 95 packet->WithPacketSenderSsrc(rtp_module->SSRC()); |
97 if (rtp_module->SendFeedbackPacket(*packet)) | 96 if (rtp_module->SendFeedbackPacket(*packet)) |
98 return true; | 97 return true; |
99 } | 98 } |
100 return false; | 99 return false; |
101 } | 100 } |
102 | 101 |
103 } // namespace webrtc | 102 } // namespace webrtc |
OLD | NEW |