Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_packet_history.cc

Issue 1877253002: Replaced CriticalSectionWrapper with rtc::CriticalSection in rtp_rtcp module (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: git cl format dtmf_queue.cc Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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/rtp_rtcp/source/rtp_packet_history.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <string.h> // memset 15 #include <string.h> // memset
16 16
17 #include <algorithm> 17 #include <algorithm>
18 #include <limits> 18 #include <limits>
19 #include <set> 19 #include <set>
20 20
21 #include "webrtc/base/checks.h" 21 #include "webrtc/base/checks.h"
22 #include "webrtc/base/logging.h" 22 #include "webrtc/base/logging.h"
23 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 23 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
24 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
25 24
26 namespace webrtc { 25 namespace webrtc {
27 26
28 static const int kMinPacketRequestBytes = 50; 27 static const int kMinPacketRequestBytes = 50;
29 28
30 RTPPacketHistory::RTPPacketHistory(Clock* clock) 29 RTPPacketHistory::RTPPacketHistory(Clock* clock)
31 : clock_(clock), 30 : clock_(clock),
32 critsect_(CriticalSectionWrapper::CreateCriticalSection()),
33 store_(false), 31 store_(false),
34 prev_index_(0) {} 32 prev_index_(0) {}
35 33
36 RTPPacketHistory::~RTPPacketHistory() { 34 RTPPacketHistory::~RTPPacketHistory() {
37 } 35 }
38 36
39 void RTPPacketHistory::SetStorePacketsStatus(bool enable, 37 void RTPPacketHistory::SetStorePacketsStatus(bool enable,
40 uint16_t number_to_store) { 38 uint16_t number_to_store) {
41 CriticalSectionScoped cs(critsect_.get()); 39 rtc::CritScope cs(&critsect_);
42 if (enable) { 40 if (enable) {
43 if (store_) { 41 if (store_) {
44 LOG(LS_WARNING) << "Purging packet history in order to re-set status."; 42 LOG(LS_WARNING) << "Purging packet history in order to re-set status.";
45 Free(); 43 Free();
46 } 44 }
47 assert(!store_); 45 assert(!store_);
48 Allocate(number_to_store); 46 Allocate(number_to_store);
49 } else { 47 } else {
50 Free(); 48 Free();
51 } 49 }
(...skipping 11 matching lines...) Expand all
63 return; 61 return;
64 } 62 }
65 63
66 stored_packets_.clear(); 64 stored_packets_.clear();
67 65
68 store_ = false; 66 store_ = false;
69 prev_index_ = 0; 67 prev_index_ = 0;
70 } 68 }
71 69
72 bool RTPPacketHistory::StorePackets() const { 70 bool RTPPacketHistory::StorePackets() const {
73 CriticalSectionScoped cs(critsect_.get()); 71 rtc::CritScope cs(&critsect_);
74 return store_; 72 return store_;
75 } 73 }
76 74
77 int32_t RTPPacketHistory::PutRTPPacket(const uint8_t* packet, 75 int32_t RTPPacketHistory::PutRTPPacket(const uint8_t* packet,
78 size_t packet_length, 76 size_t packet_length,
79 int64_t capture_time_ms, 77 int64_t capture_time_ms,
80 StorageType type) { 78 StorageType type) {
81 CriticalSectionScoped cs(critsect_.get()); 79 rtc::CritScope cs(&critsect_);
82 if (!store_) { 80 if (!store_) {
83 return 0; 81 return 0;
84 } 82 }
85 83
86 assert(packet); 84 assert(packet);
87 assert(packet_length > 3); 85 assert(packet_length > 3);
88 86
89 if (packet_length > IP_PACKET_SIZE) { 87 if (packet_length > IP_PACKET_SIZE) {
90 LOG(LS_WARNING) << "Failed to store RTP packet with length: " 88 LOG(LS_WARNING) << "Failed to store RTP packet with length: "
91 << packet_length; 89 << packet_length;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 stored_packets_[prev_index_].has_been_retransmitted = false; 122 stored_packets_[prev_index_].has_been_retransmitted = false;
125 123
126 ++prev_index_; 124 ++prev_index_;
127 if (prev_index_ >= stored_packets_.size()) { 125 if (prev_index_ >= stored_packets_.size()) {
128 prev_index_ = 0; 126 prev_index_ = 0;
129 } 127 }
130 return 0; 128 return 0;
131 } 129 }
132 130
133 bool RTPPacketHistory::HasRTPPacket(uint16_t sequence_number) const { 131 bool RTPPacketHistory::HasRTPPacket(uint16_t sequence_number) const {
134 CriticalSectionScoped cs(critsect_.get()); 132 rtc::CritScope cs(&critsect_);
135 if (!store_) { 133 if (!store_) {
136 return false; 134 return false;
137 } 135 }
138 136
139 int32_t index = 0; 137 int32_t index = 0;
140 bool found = FindSeqNum(sequence_number, &index); 138 bool found = FindSeqNum(sequence_number, &index);
141 if (!found) { 139 if (!found) {
142 return false; 140 return false;
143 } 141 }
144 142
145 if (stored_packets_[index].length == 0) { 143 if (stored_packets_[index].length == 0) {
146 // Invalid length. 144 // Invalid length.
147 return false; 145 return false;
148 } 146 }
149 return true; 147 return true;
150 } 148 }
151 149
152 bool RTPPacketHistory::SetSent(uint16_t sequence_number) { 150 bool RTPPacketHistory::SetSent(uint16_t sequence_number) {
153 CriticalSectionScoped cs(critsect_.get()); 151 rtc::CritScope cs(&critsect_);
154 if (!store_) { 152 if (!store_) {
155 return false; 153 return false;
156 } 154 }
157 155
158 int32_t index = 0; 156 int32_t index = 0;
159 bool found = FindSeqNum(sequence_number, &index); 157 bool found = FindSeqNum(sequence_number, &index);
160 if (!found) { 158 if (!found) {
161 return false; 159 return false;
162 } 160 }
163 161
164 // Send time already set. 162 // Send time already set.
165 if (stored_packets_[index].send_time != 0) { 163 if (stored_packets_[index].send_time != 0) {
166 return false; 164 return false;
167 } 165 }
168 166
169 stored_packets_[index].send_time = clock_->TimeInMilliseconds(); 167 stored_packets_[index].send_time = clock_->TimeInMilliseconds();
170 return true; 168 return true;
171 } 169 }
172 170
173 bool RTPPacketHistory::GetPacketAndSetSendTime(uint16_t sequence_number, 171 bool RTPPacketHistory::GetPacketAndSetSendTime(uint16_t sequence_number,
174 int64_t min_elapsed_time_ms, 172 int64_t min_elapsed_time_ms,
175 bool retransmit, 173 bool retransmit,
176 uint8_t* packet, 174 uint8_t* packet,
177 size_t* packet_length, 175 size_t* packet_length,
178 int64_t* stored_time_ms) { 176 int64_t* stored_time_ms) {
179 CriticalSectionScoped cs(critsect_.get()); 177 rtc::CritScope cs(&critsect_);
180 RTC_CHECK_GE(*packet_length, static_cast<size_t>(IP_PACKET_SIZE)); 178 RTC_CHECK_GE(*packet_length, static_cast<size_t>(IP_PACKET_SIZE));
181 if (!store_) 179 if (!store_)
182 return false; 180 return false;
183 181
184 int32_t index = 0; 182 int32_t index = 0;
185 bool found = FindSeqNum(sequence_number, &index); 183 bool found = FindSeqNum(sequence_number, &index);
186 if (!found) { 184 if (!found) {
187 LOG(LS_WARNING) << "No match for getting seqNum " << sequence_number; 185 LOG(LS_WARNING) << "No match for getting seqNum " << sequence_number;
188 return false; 186 return false;
189 } 187 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // Get packet. 223 // Get packet.
226 size_t length = stored_packets_[index].length; 224 size_t length = stored_packets_[index].length;
227 memcpy(packet, stored_packets_[index].data, length); 225 memcpy(packet, stored_packets_[index].data, length);
228 *packet_length = length; 226 *packet_length = length;
229 *stored_time_ms = stored_packets_[index].time_ms; 227 *stored_time_ms = stored_packets_[index].time_ms;
230 } 228 }
231 229
232 bool RTPPacketHistory::GetBestFittingPacket(uint8_t* packet, 230 bool RTPPacketHistory::GetBestFittingPacket(uint8_t* packet,
233 size_t* packet_length, 231 size_t* packet_length,
234 int64_t* stored_time_ms) { 232 int64_t* stored_time_ms) {
235 CriticalSectionScoped cs(critsect_.get()); 233 rtc::CritScope cs(&critsect_);
236 if (!store_) 234 if (!store_)
237 return false; 235 return false;
238 int index = FindBestFittingPacket(*packet_length); 236 int index = FindBestFittingPacket(*packet_length);
239 if (index < 0) 237 if (index < 0)
240 return false; 238 return false;
241 GetPacket(index, packet, packet_length, stored_time_ms); 239 GetPacket(index, packet, packet_length, stored_time_ms);
242 return true; 240 return true;
243 } 241 }
244 242
245 // private, lock should already be taken 243 // private, lock should already be taken
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 min_diff = diff; 290 min_diff = diff;
293 best_index = static_cast<int>(i); 291 best_index = static_cast<int>(i);
294 } 292 }
295 } 293 }
296 return best_index; 294 return best_index;
297 } 295 }
298 296
299 RTPPacketHistory::StoredPacket::StoredPacket() {} 297 RTPPacketHistory::StoredPacket::StoredPacket() {}
300 298
301 } // namespace webrtc 299 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_packet_history.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698