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

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

Issue 1230503003: Update a ton of audio code to use size_t more correctly and in general reduce (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 4 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/audio_coding/neteq/delay_manager.h" 11 #include "webrtc/modules/audio_coding/neteq/delay_manager.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <math.h> 14 #include <math.h>
15 15
16 #include <algorithm> // max, min 16 #include <algorithm> // max, min
17 17
18 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 18 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
19 #include "webrtc/modules/audio_coding/neteq/delay_peak_detector.h" 19 #include "webrtc/modules/audio_coding/neteq/delay_peak_detector.h"
20 #include "webrtc/modules/interface/module_common_types.h" 20 #include "webrtc/modules/interface/module_common_types.h"
21 #include "webrtc/system_wrappers/interface/logging.h" 21 #include "webrtc/system_wrappers/interface/logging.h"
22 22
23 namespace webrtc { 23 namespace webrtc {
24 24
25 DelayManager::DelayManager(int max_packets_in_buffer, 25 DelayManager::DelayManager(size_t max_packets_in_buffer,
26 DelayPeakDetector* peak_detector) 26 DelayPeakDetector* peak_detector)
27 : first_packet_received_(false), 27 : first_packet_received_(false),
28 max_packets_in_buffer_(max_packets_in_buffer), 28 max_packets_in_buffer_(max_packets_in_buffer),
29 iat_vector_(kMaxIat + 1, 0), 29 iat_vector_(kMaxIat + 1, 0),
30 iat_factor_(0), 30 iat_factor_(0),
31 packet_iat_count_ms_(0), 31 packet_iat_count_ms_(0),
32 base_target_level_(4), // In Q0 domain. 32 base_target_level_(4), // In Q0 domain.
33 target_level_(base_target_level_ << 8), // In Q8 domain. 33 target_level_(base_target_level_ << 8), // In Q8 domain.
34 packet_len_ms_(0), 34 packet_len_ms_(0),
35 streaming_mode_(false), 35 streaming_mode_(false),
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 int minimum_delay_packet_q8 = (minimum_delay_ms_ << 8) / packet_len_ms_; 232 int minimum_delay_packet_q8 = (minimum_delay_ms_ << 8) / packet_len_ms_;
233 target_level_ = std::max(target_level_, minimum_delay_packet_q8); 233 target_level_ = std::max(target_level_, minimum_delay_packet_q8);
234 } 234 }
235 235
236 if (maximum_delay_ms_ > 0 && packet_len_ms_ > 0) { 236 if (maximum_delay_ms_ > 0 && packet_len_ms_ > 0) {
237 int maximum_delay_packet_q8 = (maximum_delay_ms_ << 8) / packet_len_ms_; 237 int maximum_delay_packet_q8 = (maximum_delay_ms_ << 8) / packet_len_ms_;
238 target_level_ = std::min(target_level_, maximum_delay_packet_q8); 238 target_level_ = std::min(target_level_, maximum_delay_packet_q8);
239 } 239 }
240 240
241 // Shift to Q8, then 75%.; 241 // Shift to Q8, then 75%.;
242 int max_buffer_packets_q8 = (3 * (max_packets_in_buffer_ << 8)) / 4; 242 int max_buffer_packets_q8 =
243 static_cast<int>((3 * (max_packets_in_buffer_ << 8)) / 4);
243 target_level_ = std::min(target_level_, max_buffer_packets_q8); 244 target_level_ = std::min(target_level_, max_buffer_packets_q8);
244 245
245 // Sanity check, at least 1 packet (in Q8). 246 // Sanity check, at least 1 packet (in Q8).
246 target_level_ = std::max(target_level_, 1 << 8); 247 target_level_ = std::max(target_level_, 1 << 8);
247 } 248 }
248 249
249 int DelayManager::CalculateTargetLevel(int iat_packets) { 250 int DelayManager::CalculateTargetLevel(int iat_packets) {
250 int limit_probability = kLimitProbability; 251 int limit_probability = kLimitProbability;
251 if (streaming_mode_) { 252 if (streaming_mode_) {
252 limit_probability = kLimitProbabilityStreaming; 253 limit_probability = kLimitProbabilityStreaming;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 last_pack_cng_or_dtmf_ = -1; 383 last_pack_cng_or_dtmf_ = -1;
383 } 384 }
384 } 385 }
385 386
386 bool DelayManager::SetMinimumDelay(int delay_ms) { 387 bool DelayManager::SetMinimumDelay(int delay_ms) {
387 // Minimum delay shouldn't be more than maximum delay, if any maximum is set. 388 // Minimum delay shouldn't be more than maximum delay, if any maximum is set.
388 // Also, if possible check |delay| to less than 75% of 389 // Also, if possible check |delay| to less than 75% of
389 // |max_packets_in_buffer_|. 390 // |max_packets_in_buffer_|.
390 if ((maximum_delay_ms_ > 0 && delay_ms > maximum_delay_ms_) || 391 if ((maximum_delay_ms_ > 0 && delay_ms > maximum_delay_ms_) ||
391 (packet_len_ms_ > 0 && 392 (packet_len_ms_ > 0 &&
392 delay_ms > 3 * max_packets_in_buffer_ * packet_len_ms_ / 4)) { 393 delay_ms >
394 static_cast<int>(3 * max_packets_in_buffer_ * packet_len_ms_ / 4))) {
393 return false; 395 return false;
394 } 396 }
395 minimum_delay_ms_ = delay_ms; 397 minimum_delay_ms_ = delay_ms;
396 return true; 398 return true;
397 } 399 }
398 400
399 bool DelayManager::SetMaximumDelay(int delay_ms) { 401 bool DelayManager::SetMaximumDelay(int delay_ms) {
400 if (delay_ms == 0) { 402 if (delay_ms == 0) {
401 // Zero input unsets the maximum delay. 403 // Zero input unsets the maximum delay.
402 maximum_delay_ms_ = 0; 404 maximum_delay_ms_ = 0;
(...skipping 13 matching lines...) Expand all
416 int DelayManager::base_target_level() const { return base_target_level_; } 418 int DelayManager::base_target_level() const { return base_target_level_; }
417 void DelayManager::set_streaming_mode(bool value) { streaming_mode_ = value; } 419 void DelayManager::set_streaming_mode(bool value) { streaming_mode_ = value; }
418 int DelayManager::last_pack_cng_or_dtmf() const { 420 int DelayManager::last_pack_cng_or_dtmf() const {
419 return last_pack_cng_or_dtmf_; 421 return last_pack_cng_or_dtmf_;
420 } 422 }
421 423
422 void DelayManager::set_last_pack_cng_or_dtmf(int value) { 424 void DelayManager::set_last_pack_cng_or_dtmf(int value) {
423 last_pack_cng_or_dtmf_ = value; 425 last_pack_cng_or_dtmf_ = value;
424 } 426 }
425 } // namespace webrtc 427 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/delay_manager.h ('k') | webrtc/modules/audio_coding/neteq/dsp_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698