OLD | NEW |
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/base/safe_conversions.h" | 18 #include "webrtc/base/safe_conversions.h" |
19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
20 #include "webrtc/modules/audio_coding/neteq/delay_peak_detector.h" | 20 #include "webrtc/modules/audio_coding/neteq/delay_peak_detector.h" |
21 #include "webrtc/modules/include/module_common_types.h" | 21 #include "webrtc/modules/include/module_common_types.h" |
22 #include "webrtc/system_wrappers/include/logging.h" | |
23 | 22 |
24 namespace webrtc { | 23 namespace webrtc { |
25 | 24 |
26 DelayManager::DelayManager(size_t max_packets_in_buffer, | 25 DelayManager::DelayManager(size_t max_packets_in_buffer, |
27 DelayPeakDetector* peak_detector, | 26 DelayPeakDetector* peak_detector, |
28 const TickTimer* tick_timer) | 27 const TickTimer* tick_timer) |
29 : first_packet_received_(false), | 28 : first_packet_received_(false), |
30 max_packets_in_buffer_(max_packets_in_buffer), | 29 max_packets_in_buffer_(max_packets_in_buffer), |
31 iat_vector_(kMaxIat + 1, 0), | 30 iat_vector_(kMaxIat + 1, 0), |
32 iat_factor_(0), | 31 iat_factor_(0), |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 287 |
289 // Sanity check. |target_level| must be strictly positive. | 288 // Sanity check. |target_level| must be strictly positive. |
290 target_level = std::max(target_level, 1); | 289 target_level = std::max(target_level, 1); |
291 // Scale to Q8 and assign to member variable. | 290 // Scale to Q8 and assign to member variable. |
292 target_level_ = target_level << 8; | 291 target_level_ = target_level << 8; |
293 return target_level_; | 292 return target_level_; |
294 } | 293 } |
295 | 294 |
296 int DelayManager::SetPacketAudioLength(int length_ms) { | 295 int DelayManager::SetPacketAudioLength(int length_ms) { |
297 if (length_ms <= 0) { | 296 if (length_ms <= 0) { |
298 LOG_F(LS_ERROR) << "length_ms = " << length_ms; | |
299 return -1; | 297 return -1; |
300 } | 298 } |
301 packet_len_ms_ = length_ms; | 299 packet_len_ms_ = length_ms; |
302 peak_detector_.SetPacketAudioLength(packet_len_ms_); | 300 peak_detector_.SetPacketAudioLength(packet_len_ms_); |
303 packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch(); | 301 packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch(); |
304 last_pack_cng_or_dtmf_ = 1; // TODO(hlundin): Legacy. Remove? | 302 last_pack_cng_or_dtmf_ = 1; // TODO(hlundin): Legacy. Remove? |
305 return 0; | 303 return 0; |
306 } | 304 } |
307 | 305 |
308 | 306 |
(...skipping 29 matching lines...) Expand all Loading... |
338 | 336 |
339 void DelayManager::ResetPacketIatCount() { | 337 void DelayManager::ResetPacketIatCount() { |
340 packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch(); | 338 packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch(); |
341 } | 339 } |
342 | 340 |
343 // Note that |low_limit| and |higher_limit| are not assigned to | 341 // Note that |low_limit| and |higher_limit| are not assigned to |
344 // |minimum_delay_ms_| and |maximum_delay_ms_| defined by the client of this | 342 // |minimum_delay_ms_| and |maximum_delay_ms_| defined by the client of this |
345 // class. They are computed from |target_level_| and used for decision making. | 343 // class. They are computed from |target_level_| and used for decision making. |
346 void DelayManager::BufferLimits(int* lower_limit, int* higher_limit) const { | 344 void DelayManager::BufferLimits(int* lower_limit, int* higher_limit) const { |
347 if (!lower_limit || !higher_limit) { | 345 if (!lower_limit || !higher_limit) { |
348 LOG_F(LS_ERROR) << "NULL pointers supplied as input"; | |
349 assert(false); | 346 assert(false); |
350 return; | 347 return; |
351 } | 348 } |
352 | 349 |
353 int window_20ms = 0x7FFF; // Default large value for legacy bit-exactness. | 350 int window_20ms = 0x7FFF; // Default large value for legacy bit-exactness. |
354 if (packet_len_ms_ > 0) { | 351 if (packet_len_ms_ > 0) { |
355 window_20ms = (20 << 8) / packet_len_ms_; | 352 window_20ms = (20 << 8) / packet_len_ms_; |
356 } | 353 } |
357 | 354 |
358 // |target_level_| is in Q8 already. | 355 // |target_level_| is in Q8 already. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 int DelayManager::base_target_level() const { return base_target_level_; } | 405 int DelayManager::base_target_level() const { return base_target_level_; } |
409 void DelayManager::set_streaming_mode(bool value) { streaming_mode_ = value; } | 406 void DelayManager::set_streaming_mode(bool value) { streaming_mode_ = value; } |
410 int DelayManager::last_pack_cng_or_dtmf() const { | 407 int DelayManager::last_pack_cng_or_dtmf() const { |
411 return last_pack_cng_or_dtmf_; | 408 return last_pack_cng_or_dtmf_; |
412 } | 409 } |
413 | 410 |
414 void DelayManager::set_last_pack_cng_or_dtmf(int value) { | 411 void DelayManager::set_last_pack_cng_or_dtmf(int value) { |
415 last_pack_cng_or_dtmf_ = value; | 412 last_pack_cng_or_dtmf_ = value; |
416 } | 413 } |
417 } // namespace webrtc | 414 } // namespace webrtc |
OLD | NEW |