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

Side by Side Diff: webrtc/modules/audio_coding/neteq/neteq_impl.cc

Issue 1610073003: Switch CriticalSectionWrapper->rtc::CriticalSection in modules/audio_coding. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 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
(...skipping 26 matching lines...) Expand all
37 #include "webrtc/modules/audio_coding/neteq/nack.h" 37 #include "webrtc/modules/audio_coding/neteq/nack.h"
38 #include "webrtc/modules/audio_coding/neteq/normal.h" 38 #include "webrtc/modules/audio_coding/neteq/normal.h"
39 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" 39 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h"
40 #include "webrtc/modules/audio_coding/neteq/packet.h" 40 #include "webrtc/modules/audio_coding/neteq/packet.h"
41 #include "webrtc/modules/audio_coding/neteq/payload_splitter.h" 41 #include "webrtc/modules/audio_coding/neteq/payload_splitter.h"
42 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h" 42 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h"
43 #include "webrtc/modules/audio_coding/neteq/preemptive_expand.h" 43 #include "webrtc/modules/audio_coding/neteq/preemptive_expand.h"
44 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" 44 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h"
45 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h" 45 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h"
46 #include "webrtc/modules/include/module_common_types.h" 46 #include "webrtc/modules/include/module_common_types.h"
47 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
48 47
49 // Modify the code to obtain backwards bit-exactness. Once bit-exactness is no 48 // Modify the code to obtain backwards bit-exactness. Once bit-exactness is no
50 // longer required, this #define should be removed (and the code that it 49 // longer required, this #define should be removed (and the code that it
51 // enables). 50 // enables).
52 #define LEGACY_BITEXACT 51 #define LEGACY_BITEXACT
53 52
54 namespace webrtc { 53 namespace webrtc {
55 54
56 NetEqImpl::NetEqImpl(const NetEq::Config& config, 55 NetEqImpl::NetEqImpl(const NetEq::Config& config,
57 BufferLevelFilter* buffer_level_filter, 56 BufferLevelFilter* buffer_level_filter,
58 DecoderDatabase* decoder_database, 57 DecoderDatabase* decoder_database,
59 DelayManager* delay_manager, 58 DelayManager* delay_manager,
60 DelayPeakDetector* delay_peak_detector, 59 DelayPeakDetector* delay_peak_detector,
61 DtmfBuffer* dtmf_buffer, 60 DtmfBuffer* dtmf_buffer,
62 DtmfToneGenerator* dtmf_tone_generator, 61 DtmfToneGenerator* dtmf_tone_generator,
63 PacketBuffer* packet_buffer, 62 PacketBuffer* packet_buffer,
64 PayloadSplitter* payload_splitter, 63 PayloadSplitter* payload_splitter,
65 TimestampScaler* timestamp_scaler, 64 TimestampScaler* timestamp_scaler,
66 AccelerateFactory* accelerate_factory, 65 AccelerateFactory* accelerate_factory,
67 ExpandFactory* expand_factory, 66 ExpandFactory* expand_factory,
68 PreemptiveExpandFactory* preemptive_expand_factory, 67 PreemptiveExpandFactory* preemptive_expand_factory,
69 bool create_components) 68 bool create_components)
70 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), 69 : buffer_level_filter_(buffer_level_filter),
71 buffer_level_filter_(buffer_level_filter),
72 decoder_database_(decoder_database), 70 decoder_database_(decoder_database),
73 delay_manager_(delay_manager), 71 delay_manager_(delay_manager),
74 delay_peak_detector_(delay_peak_detector), 72 delay_peak_detector_(delay_peak_detector),
75 dtmf_buffer_(dtmf_buffer), 73 dtmf_buffer_(dtmf_buffer),
76 dtmf_tone_generator_(dtmf_tone_generator), 74 dtmf_tone_generator_(dtmf_tone_generator),
77 packet_buffer_(packet_buffer), 75 packet_buffer_(packet_buffer),
78 payload_splitter_(payload_splitter), 76 payload_splitter_(payload_splitter),
79 timestamp_scaler_(timestamp_scaler), 77 timestamp_scaler_(timestamp_scaler),
80 vad_(new PostDecodeVad()), 78 vad_(new PostDecodeVad()),
81 expand_factory_(expand_factory), 79 expand_factory_(expand_factory),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 vad_->Enable(); 117 vad_->Enable();
120 } 118 }
121 } 119 }
122 120
123 NetEqImpl::~NetEqImpl() = default; 121 NetEqImpl::~NetEqImpl() = default;
124 122
125 int NetEqImpl::InsertPacket(const WebRtcRTPHeader& rtp_header, 123 int NetEqImpl::InsertPacket(const WebRtcRTPHeader& rtp_header,
126 rtc::ArrayView<const uint8_t> payload, 124 rtc::ArrayView<const uint8_t> payload,
127 uint32_t receive_timestamp) { 125 uint32_t receive_timestamp) {
128 TRACE_EVENT0("webrtc", "NetEqImpl::InsertPacket"); 126 TRACE_EVENT0("webrtc", "NetEqImpl::InsertPacket");
129 CriticalSectionScoped lock(crit_sect_.get()); 127 rtc::CritScope lock(&crit_sect_);
130 int error = 128 int error =
131 InsertPacketInternal(rtp_header, payload, receive_timestamp, false); 129 InsertPacketInternal(rtp_header, payload, receive_timestamp, false);
132 if (error != 0) { 130 if (error != 0) {
133 error_code_ = error; 131 error_code_ = error;
134 return kFail; 132 return kFail;
135 } 133 }
136 return kOK; 134 return kOK;
137 } 135 }
138 136
139 int NetEqImpl::InsertSyncPacket(const WebRtcRTPHeader& rtp_header, 137 int NetEqImpl::InsertSyncPacket(const WebRtcRTPHeader& rtp_header,
140 uint32_t receive_timestamp) { 138 uint32_t receive_timestamp) {
141 CriticalSectionScoped lock(crit_sect_.get()); 139 rtc::CritScope lock(&crit_sect_);
142 const uint8_t kSyncPayload[] = { 's', 'y', 'n', 'c' }; 140 const uint8_t kSyncPayload[] = { 's', 'y', 'n', 'c' };
143 int error = 141 int error =
144 InsertPacketInternal(rtp_header, kSyncPayload, receive_timestamp, true); 142 InsertPacketInternal(rtp_header, kSyncPayload, receive_timestamp, true);
145 143
146 if (error != 0) { 144 if (error != 0) {
147 error_code_ = error; 145 error_code_ = error;
148 return kFail; 146 return kFail;
149 } 147 }
150 return kOK; 148 return kOK;
151 } 149 }
152 150
153 int NetEqImpl::GetAudio(size_t max_length, int16_t* output_audio, 151 int NetEqImpl::GetAudio(size_t max_length, int16_t* output_audio,
154 size_t* samples_per_channel, size_t* num_channels, 152 size_t* samples_per_channel, size_t* num_channels,
155 NetEqOutputType* type) { 153 NetEqOutputType* type) {
156 TRACE_EVENT0("webrtc", "NetEqImpl::GetAudio"); 154 TRACE_EVENT0("webrtc", "NetEqImpl::GetAudio");
157 CriticalSectionScoped lock(crit_sect_.get()); 155 rtc::CritScope lock(&crit_sect_);
158 int error = GetAudioInternal(max_length, output_audio, samples_per_channel, 156 int error = GetAudioInternal(max_length, output_audio, samples_per_channel,
159 num_channels); 157 num_channels);
160 if (error != 0) { 158 if (error != 0) {
161 error_code_ = error; 159 error_code_ = error;
162 return kFail; 160 return kFail;
163 } 161 }
164 if (type) { 162 if (type) {
165 *type = LastOutputType(); 163 *type = LastOutputType();
166 } 164 }
167 last_output_sample_rate_hz_ = 165 last_output_sample_rate_hz_ =
168 rtc::checked_cast<int>(*samples_per_channel * 100); 166 rtc::checked_cast<int>(*samples_per_channel * 100);
169 RTC_DCHECK(last_output_sample_rate_hz_ == 8000 || 167 RTC_DCHECK(last_output_sample_rate_hz_ == 8000 ||
170 last_output_sample_rate_hz_ == 16000 || 168 last_output_sample_rate_hz_ == 16000 ||
171 last_output_sample_rate_hz_ == 32000 || 169 last_output_sample_rate_hz_ == 32000 ||
172 last_output_sample_rate_hz_ == 48000) 170 last_output_sample_rate_hz_ == 48000)
173 << "Unexpected sample rate " << last_output_sample_rate_hz_; 171 << "Unexpected sample rate " << last_output_sample_rate_hz_;
174 return kOK; 172 return kOK;
175 } 173 }
176 174
177 int NetEqImpl::RegisterPayloadType(NetEqDecoder codec, 175 int NetEqImpl::RegisterPayloadType(NetEqDecoder codec,
178 const std::string& name, 176 const std::string& name,
179 uint8_t rtp_payload_type) { 177 uint8_t rtp_payload_type) {
180 CriticalSectionScoped lock(crit_sect_.get()); 178 rtc::CritScope lock(&crit_sect_);
181 LOG(LS_VERBOSE) << "RegisterPayloadType " 179 LOG(LS_VERBOSE) << "RegisterPayloadType "
182 << static_cast<int>(rtp_payload_type) << " " 180 << static_cast<int>(rtp_payload_type) << " "
183 << static_cast<int>(codec); 181 << static_cast<int>(codec);
184 int ret = decoder_database_->RegisterPayload(rtp_payload_type, codec, name); 182 int ret = decoder_database_->RegisterPayload(rtp_payload_type, codec, name);
185 if (ret != DecoderDatabase::kOK) { 183 if (ret != DecoderDatabase::kOK) {
186 switch (ret) { 184 switch (ret) {
187 case DecoderDatabase::kInvalidRtpPayloadType: 185 case DecoderDatabase::kInvalidRtpPayloadType:
188 error_code_ = kInvalidRtpPayloadType; 186 error_code_ = kInvalidRtpPayloadType;
189 break; 187 break;
190 case DecoderDatabase::kCodecNotSupported: 188 case DecoderDatabase::kCodecNotSupported:
191 error_code_ = kCodecNotSupported; 189 error_code_ = kCodecNotSupported;
192 break; 190 break;
193 case DecoderDatabase::kDecoderExists: 191 case DecoderDatabase::kDecoderExists:
194 error_code_ = kDecoderExists; 192 error_code_ = kDecoderExists;
195 break; 193 break;
196 default: 194 default:
197 error_code_ = kOtherError; 195 error_code_ = kOtherError;
198 } 196 }
199 return kFail; 197 return kFail;
200 } 198 }
201 return kOK; 199 return kOK;
202 } 200 }
203 201
204 int NetEqImpl::RegisterExternalDecoder(AudioDecoder* decoder, 202 int NetEqImpl::RegisterExternalDecoder(AudioDecoder* decoder,
205 NetEqDecoder codec, 203 NetEqDecoder codec,
206 const std::string& codec_name, 204 const std::string& codec_name,
207 uint8_t rtp_payload_type, 205 uint8_t rtp_payload_type,
208 int sample_rate_hz) { 206 int sample_rate_hz) {
209 CriticalSectionScoped lock(crit_sect_.get()); 207 rtc::CritScope lock(&crit_sect_);
210 LOG(LS_VERBOSE) << "RegisterExternalDecoder " 208 LOG(LS_VERBOSE) << "RegisterExternalDecoder "
211 << static_cast<int>(rtp_payload_type) << " " 209 << static_cast<int>(rtp_payload_type) << " "
212 << static_cast<int>(codec); 210 << static_cast<int>(codec);
213 if (!decoder) { 211 if (!decoder) {
214 LOG(LS_ERROR) << "Cannot register external decoder with NULL pointer"; 212 LOG(LS_ERROR) << "Cannot register external decoder with NULL pointer";
215 assert(false); 213 assert(false);
216 return kFail; 214 return kFail;
217 } 215 }
218 int ret = decoder_database_->InsertExternal( 216 int ret = decoder_database_->InsertExternal(
219 rtp_payload_type, codec, codec_name, sample_rate_hz, decoder); 217 rtp_payload_type, codec, codec_name, sample_rate_hz, decoder);
(...skipping 16 matching lines...) Expand all
236 break; 234 break;
237 default: 235 default:
238 error_code_ = kOtherError; 236 error_code_ = kOtherError;
239 } 237 }
240 return kFail; 238 return kFail;
241 } 239 }
242 return kOK; 240 return kOK;
243 } 241 }
244 242
245 int NetEqImpl::RemovePayloadType(uint8_t rtp_payload_type) { 243 int NetEqImpl::RemovePayloadType(uint8_t rtp_payload_type) {
246 CriticalSectionScoped lock(crit_sect_.get()); 244 rtc::CritScope lock(&crit_sect_);
247 int ret = decoder_database_->Remove(rtp_payload_type); 245 int ret = decoder_database_->Remove(rtp_payload_type);
248 if (ret == DecoderDatabase::kOK) { 246 if (ret == DecoderDatabase::kOK) {
249 return kOK; 247 return kOK;
250 } else if (ret == DecoderDatabase::kDecoderNotFound) { 248 } else if (ret == DecoderDatabase::kDecoderNotFound) {
251 error_code_ = kDecoderNotFound; 249 error_code_ = kDecoderNotFound;
252 } else { 250 } else {
253 error_code_ = kOtherError; 251 error_code_ = kOtherError;
254 } 252 }
255 return kFail; 253 return kFail;
256 } 254 }
257 255
258 bool NetEqImpl::SetMinimumDelay(int delay_ms) { 256 bool NetEqImpl::SetMinimumDelay(int delay_ms) {
259 CriticalSectionScoped lock(crit_sect_.get()); 257 rtc::CritScope lock(&crit_sect_);
260 if (delay_ms >= 0 && delay_ms < 10000) { 258 if (delay_ms >= 0 && delay_ms < 10000) {
261 assert(delay_manager_.get()); 259 assert(delay_manager_.get());
262 return delay_manager_->SetMinimumDelay(delay_ms); 260 return delay_manager_->SetMinimumDelay(delay_ms);
263 } 261 }
264 return false; 262 return false;
265 } 263 }
266 264
267 bool NetEqImpl::SetMaximumDelay(int delay_ms) { 265 bool NetEqImpl::SetMaximumDelay(int delay_ms) {
268 CriticalSectionScoped lock(crit_sect_.get()); 266 rtc::CritScope lock(&crit_sect_);
269 if (delay_ms >= 0 && delay_ms < 10000) { 267 if (delay_ms >= 0 && delay_ms < 10000) {
270 assert(delay_manager_.get()); 268 assert(delay_manager_.get());
271 return delay_manager_->SetMaximumDelay(delay_ms); 269 return delay_manager_->SetMaximumDelay(delay_ms);
272 } 270 }
273 return false; 271 return false;
274 } 272 }
275 273
276 int NetEqImpl::LeastRequiredDelayMs() const { 274 int NetEqImpl::LeastRequiredDelayMs() const {
277 CriticalSectionScoped lock(crit_sect_.get()); 275 rtc::CritScope lock(&crit_sect_);
278 assert(delay_manager_.get()); 276 assert(delay_manager_.get());
279 return delay_manager_->least_required_delay_ms(); 277 return delay_manager_->least_required_delay_ms();
280 } 278 }
281 279
282 int NetEqImpl::SetTargetDelay() { 280 int NetEqImpl::SetTargetDelay() {
283 return kNotImplemented; 281 return kNotImplemented;
284 } 282 }
285 283
286 int NetEqImpl::TargetDelay() { 284 int NetEqImpl::TargetDelay() {
287 return kNotImplemented; 285 return kNotImplemented;
288 } 286 }
289 287
290 int NetEqImpl::CurrentDelayMs() const { 288 int NetEqImpl::CurrentDelayMs() const {
291 CriticalSectionScoped lock(crit_sect_.get()); 289 rtc::CritScope lock(&crit_sect_);
292 if (fs_hz_ == 0) 290 if (fs_hz_ == 0)
293 return 0; 291 return 0;
294 // Sum up the samples in the packet buffer with the future length of the sync 292 // Sum up the samples in the packet buffer with the future length of the sync
295 // buffer, and divide the sum by the sample rate. 293 // buffer, and divide the sum by the sample rate.
296 const size_t delay_samples = 294 const size_t delay_samples =
297 packet_buffer_->NumSamplesInBuffer(decoder_database_.get(), 295 packet_buffer_->NumSamplesInBuffer(decoder_database_.get(),
298 decoder_frame_length_) + 296 decoder_frame_length_) +
299 sync_buffer_->FutureLength(); 297 sync_buffer_->FutureLength();
300 // The division below will truncate. 298 // The division below will truncate.
301 const int delay_ms = 299 const int delay_ms =
302 static_cast<int>(delay_samples) / rtc::CheckedDivExact(fs_hz_, 1000); 300 static_cast<int>(delay_samples) / rtc::CheckedDivExact(fs_hz_, 1000);
303 return delay_ms; 301 return delay_ms;
304 } 302 }
305 303
306 // Deprecated. 304 // Deprecated.
307 // TODO(henrik.lundin) Delete. 305 // TODO(henrik.lundin) Delete.
308 void NetEqImpl::SetPlayoutMode(NetEqPlayoutMode mode) { 306 void NetEqImpl::SetPlayoutMode(NetEqPlayoutMode mode) {
309 CriticalSectionScoped lock(crit_sect_.get()); 307 rtc::CritScope lock(&crit_sect_);
310 if (mode != playout_mode_) { 308 if (mode != playout_mode_) {
311 playout_mode_ = mode; 309 playout_mode_ = mode;
312 CreateDecisionLogic(); 310 CreateDecisionLogic();
313 } 311 }
314 } 312 }
315 313
316 // Deprecated. 314 // Deprecated.
317 // TODO(henrik.lundin) Delete. 315 // TODO(henrik.lundin) Delete.
318 NetEqPlayoutMode NetEqImpl::PlayoutMode() const { 316 NetEqPlayoutMode NetEqImpl::PlayoutMode() const {
319 CriticalSectionScoped lock(crit_sect_.get()); 317 rtc::CritScope lock(&crit_sect_);
320 return playout_mode_; 318 return playout_mode_;
321 } 319 }
322 320
323 int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) { 321 int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) {
324 CriticalSectionScoped lock(crit_sect_.get()); 322 rtc::CritScope lock(&crit_sect_);
325 assert(decoder_database_.get()); 323 assert(decoder_database_.get());
326 const size_t total_samples_in_buffers = 324 const size_t total_samples_in_buffers =
327 packet_buffer_->NumSamplesInBuffer(decoder_database_.get(), 325 packet_buffer_->NumSamplesInBuffer(decoder_database_.get(),
328 decoder_frame_length_) + 326 decoder_frame_length_) +
329 sync_buffer_->FutureLength(); 327 sync_buffer_->FutureLength();
330 assert(delay_manager_.get()); 328 assert(delay_manager_.get());
331 assert(decision_logic_.get()); 329 assert(decision_logic_.get());
332 stats_.GetNetworkStatistics(fs_hz_, total_samples_in_buffers, 330 stats_.GetNetworkStatistics(fs_hz_, total_samples_in_buffers,
333 decoder_frame_length_, *delay_manager_.get(), 331 decoder_frame_length_, *delay_manager_.get(),
334 *decision_logic_.get(), stats); 332 *decision_logic_.get(), stats);
335 return 0; 333 return 0;
336 } 334 }
337 335
338 void NetEqImpl::GetRtcpStatistics(RtcpStatistics* stats) { 336 void NetEqImpl::GetRtcpStatistics(RtcpStatistics* stats) {
339 CriticalSectionScoped lock(crit_sect_.get()); 337 rtc::CritScope lock(&crit_sect_);
340 if (stats) { 338 if (stats) {
341 rtcp_.GetStatistics(false, stats); 339 rtcp_.GetStatistics(false, stats);
342 } 340 }
343 } 341 }
344 342
345 void NetEqImpl::GetRtcpStatisticsNoReset(RtcpStatistics* stats) { 343 void NetEqImpl::GetRtcpStatisticsNoReset(RtcpStatistics* stats) {
346 CriticalSectionScoped lock(crit_sect_.get()); 344 rtc::CritScope lock(&crit_sect_);
347 if (stats) { 345 if (stats) {
348 rtcp_.GetStatistics(true, stats); 346 rtcp_.GetStatistics(true, stats);
349 } 347 }
350 } 348 }
351 349
352 void NetEqImpl::EnableVad() { 350 void NetEqImpl::EnableVad() {
353 CriticalSectionScoped lock(crit_sect_.get()); 351 rtc::CritScope lock(&crit_sect_);
354 assert(vad_.get()); 352 assert(vad_.get());
355 vad_->Enable(); 353 vad_->Enable();
356 } 354 }
357 355
358 void NetEqImpl::DisableVad() { 356 void NetEqImpl::DisableVad() {
359 CriticalSectionScoped lock(crit_sect_.get()); 357 rtc::CritScope lock(&crit_sect_);
360 assert(vad_.get()); 358 assert(vad_.get());
361 vad_->Disable(); 359 vad_->Disable();
362 } 360 }
363 361
364 bool NetEqImpl::GetPlayoutTimestamp(uint32_t* timestamp) { 362 bool NetEqImpl::GetPlayoutTimestamp(uint32_t* timestamp) {
365 CriticalSectionScoped lock(crit_sect_.get()); 363 rtc::CritScope lock(&crit_sect_);
366 if (first_packet_) { 364 if (first_packet_) {
367 // We don't have a valid RTP timestamp until we have decoded our first 365 // We don't have a valid RTP timestamp until we have decoded our first
368 // RTP packet. 366 // RTP packet.
369 return false; 367 return false;
370 } 368 }
371 *timestamp = timestamp_scaler_->ToExternal(playout_timestamp_); 369 *timestamp = timestamp_scaler_->ToExternal(playout_timestamp_);
372 return true; 370 return true;
373 } 371 }
374 372
375 int NetEqImpl::last_output_sample_rate_hz() const { 373 int NetEqImpl::last_output_sample_rate_hz() const {
376 CriticalSectionScoped lock(crit_sect_.get()); 374 rtc::CritScope lock(&crit_sect_);
377 return last_output_sample_rate_hz_; 375 return last_output_sample_rate_hz_;
378 } 376 }
379 377
380 int NetEqImpl::SetTargetNumberOfChannels() { 378 int NetEqImpl::SetTargetNumberOfChannels() {
381 return kNotImplemented; 379 return kNotImplemented;
382 } 380 }
383 381
384 int NetEqImpl::SetTargetSampleRate() { 382 int NetEqImpl::SetTargetSampleRate() {
385 return kNotImplemented; 383 return kNotImplemented;
386 } 384 }
387 385
388 int NetEqImpl::LastError() const { 386 int NetEqImpl::LastError() const {
389 CriticalSectionScoped lock(crit_sect_.get()); 387 rtc::CritScope lock(&crit_sect_);
390 return error_code_; 388 return error_code_;
391 } 389 }
392 390
393 int NetEqImpl::LastDecoderError() { 391 int NetEqImpl::LastDecoderError() {
394 CriticalSectionScoped lock(crit_sect_.get()); 392 rtc::CritScope lock(&crit_sect_);
395 return decoder_error_code_; 393 return decoder_error_code_;
396 } 394 }
397 395
398 void NetEqImpl::FlushBuffers() { 396 void NetEqImpl::FlushBuffers() {
399 CriticalSectionScoped lock(crit_sect_.get()); 397 rtc::CritScope lock(&crit_sect_);
400 LOG(LS_VERBOSE) << "FlushBuffers"; 398 LOG(LS_VERBOSE) << "FlushBuffers";
401 packet_buffer_->Flush(); 399 packet_buffer_->Flush();
402 assert(sync_buffer_.get()); 400 assert(sync_buffer_.get());
403 assert(expand_.get()); 401 assert(expand_.get());
404 sync_buffer_->Flush(); 402 sync_buffer_->Flush();
405 sync_buffer_->set_next_index(sync_buffer_->next_index() - 403 sync_buffer_->set_next_index(sync_buffer_->next_index() -
406 expand_->overlap_length()); 404 expand_->overlap_length());
407 // Set to wait for new codec. 405 // Set to wait for new codec.
408 first_packet_ = true; 406 first_packet_ = true;
409 } 407 }
410 408
411 void NetEqImpl::PacketBufferStatistics(int* current_num_packets, 409 void NetEqImpl::PacketBufferStatistics(int* current_num_packets,
412 int* max_num_packets) const { 410 int* max_num_packets) const {
413 CriticalSectionScoped lock(crit_sect_.get()); 411 rtc::CritScope lock(&crit_sect_);
414 packet_buffer_->BufferStat(current_num_packets, max_num_packets); 412 packet_buffer_->BufferStat(current_num_packets, max_num_packets);
415 } 413 }
416 414
417 void NetEqImpl::EnableNack(size_t max_nack_list_size) { 415 void NetEqImpl::EnableNack(size_t max_nack_list_size) {
418 CriticalSectionScoped lock(crit_sect_.get()); 416 rtc::CritScope lock(&crit_sect_);
419 if (!nack_enabled_) { 417 if (!nack_enabled_) {
420 const int kNackThresholdPackets = 2; 418 const int kNackThresholdPackets = 2;
421 nack_.reset(Nack::Create(kNackThresholdPackets)); 419 nack_.reset(Nack::Create(kNackThresholdPackets));
422 nack_enabled_ = true; 420 nack_enabled_ = true;
423 nack_->UpdateSampleRate(fs_hz_); 421 nack_->UpdateSampleRate(fs_hz_);
424 } 422 }
425 nack_->SetMaxNackListSize(max_nack_list_size); 423 nack_->SetMaxNackListSize(max_nack_list_size);
426 } 424 }
427 425
428 void NetEqImpl::DisableNack() { 426 void NetEqImpl::DisableNack() {
429 CriticalSectionScoped lock(crit_sect_.get()); 427 rtc::CritScope lock(&crit_sect_);
430 nack_.reset(); 428 nack_.reset();
431 nack_enabled_ = false; 429 nack_enabled_ = false;
432 } 430 }
433 431
434 std::vector<uint16_t> NetEqImpl::GetNackList(int64_t round_trip_time_ms) const { 432 std::vector<uint16_t> NetEqImpl::GetNackList(int64_t round_trip_time_ms) const {
435 CriticalSectionScoped lock(crit_sect_.get()); 433 rtc::CritScope lock(&crit_sect_);
436 if (!nack_enabled_) { 434 if (!nack_enabled_) {
437 return std::vector<uint16_t>(); 435 return std::vector<uint16_t>();
438 } 436 }
439 RTC_DCHECK(nack_.get()); 437 RTC_DCHECK(nack_.get());
440 return nack_->GetNackList(round_trip_time_ms); 438 return nack_->GetNackList(round_trip_time_ms);
441 } 439 }
442 440
443 const SyncBuffer* NetEqImpl::sync_buffer_for_test() const { 441 const SyncBuffer* NetEqImpl::sync_buffer_for_test() const {
444 CriticalSectionScoped lock(crit_sect_.get()); 442 rtc::CritScope lock(&crit_sect_);
445 return sync_buffer_.get(); 443 return sync_buffer_.get();
446 } 444 }
447 445
448 // Methods below this line are private. 446 // Methods below this line are private.
449 447
450 int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, 448 int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
451 rtc::ArrayView<const uint8_t> payload, 449 rtc::ArrayView<const uint8_t> payload,
452 uint32_t receive_timestamp, 450 uint32_t receive_timestamp,
453 bool is_sync_packet) { 451 bool is_sync_packet) {
454 if (payload.empty()) { 452 if (payload.empty()) {
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 2043
2046 void NetEqImpl::CreateDecisionLogic() { 2044 void NetEqImpl::CreateDecisionLogic() {
2047 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, 2045 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_,
2048 playout_mode_, 2046 playout_mode_,
2049 decoder_database_.get(), 2047 decoder_database_.get(),
2050 *packet_buffer_.get(), 2048 *packet_buffer_.get(),
2051 delay_manager_.get(), 2049 delay_manager_.get(),
2052 buffer_level_filter_.get())); 2050 buffer_level_filter_.get()));
2053 } 2051 }
2054 } // namespace webrtc 2052 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_impl.h ('k') | webrtc/modules/audio_coding/test/Channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698