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

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

Issue 1685103002: Fix two UBSan warnings in NetEq (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Change to checked_cast Created 4 years, 10 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
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/neteq/timestamp_scaler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base/safe_conversions.h"
18 #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"
19 #include "webrtc/modules/audio_coding/neteq/delay_peak_detector.h" 20 #include "webrtc/modules/audio_coding/neteq/delay_peak_detector.h"
20 #include "webrtc/modules/include/module_common_types.h" 21 #include "webrtc/modules/include/module_common_types.h"
21 #include "webrtc/system_wrappers/include/logging.h" 22 #include "webrtc/system_wrappers/include/logging.h"
22 23
23 namespace webrtc { 24 namespace webrtc {
24 25
25 DelayManager::DelayManager(size_t max_packets_in_buffer, 26 DelayManager::DelayManager(size_t max_packets_in_buffer,
26 DelayPeakDetector* peak_detector) 27 DelayPeakDetector* peak_detector)
27 : first_packet_received_(false), 28 : first_packet_received_(false),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 87 }
87 88
88 // Try calculating packet length from current and previous timestamps. 89 // Try calculating packet length from current and previous timestamps.
89 int packet_len_ms; 90 int packet_len_ms;
90 if (!IsNewerTimestamp(timestamp, last_timestamp_) || 91 if (!IsNewerTimestamp(timestamp, last_timestamp_) ||
91 !IsNewerSequenceNumber(sequence_number, last_seq_no_)) { 92 !IsNewerSequenceNumber(sequence_number, last_seq_no_)) {
92 // Wrong timestamp or sequence order; use stored value. 93 // Wrong timestamp or sequence order; use stored value.
93 packet_len_ms = packet_len_ms_; 94 packet_len_ms = packet_len_ms_;
94 } else { 95 } else {
95 // Calculate timestamps per packet and derive packet length in ms. 96 // Calculate timestamps per packet and derive packet length in ms.
96 int packet_len_samp = 97 int64_t packet_len_samp =
97 static_cast<uint32_t>(timestamp - last_timestamp_) / 98 static_cast<uint32_t>(timestamp - last_timestamp_) /
98 static_cast<uint16_t>(sequence_number - last_seq_no_); 99 static_cast<uint16_t>(sequence_number - last_seq_no_);
99 packet_len_ms = (1000 * packet_len_samp) / sample_rate_hz; 100 packet_len_ms =
101 rtc::checked_cast<int>(1000 * packet_len_samp / sample_rate_hz);
100 } 102 }
101 103
102 if (packet_len_ms > 0) { 104 if (packet_len_ms > 0) {
103 // Cannot update statistics unless |packet_len_ms| is valid. 105 // Cannot update statistics unless |packet_len_ms| is valid.
104 // Calculate inter-arrival time (IAT) in integer "packet times" 106 // Calculate inter-arrival time (IAT) in integer "packet times"
105 // (rounding down). This is the value used as index to the histogram 107 // (rounding down). This is the value used as index to the histogram
106 // vector |iat_vector_|. 108 // vector |iat_vector_|.
107 int iat_packets = packet_iat_count_ms_ / packet_len_ms; 109 int iat_packets = packet_iat_count_ms_ / packet_len_ms;
108 110
109 if (streaming_mode_) { 111 if (streaming_mode_) {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 int DelayManager::base_target_level() const { return base_target_level_; } 420 int DelayManager::base_target_level() const { return base_target_level_; }
419 void DelayManager::set_streaming_mode(bool value) { streaming_mode_ = value; } 421 void DelayManager::set_streaming_mode(bool value) { streaming_mode_ = value; }
420 int DelayManager::last_pack_cng_or_dtmf() const { 422 int DelayManager::last_pack_cng_or_dtmf() const {
421 return last_pack_cng_or_dtmf_; 423 return last_pack_cng_or_dtmf_;
422 } 424 }
423 425
424 void DelayManager::set_last_pack_cng_or_dtmf(int value) { 426 void DelayManager::set_last_pack_cng_or_dtmf(int value) {
425 last_pack_cng_or_dtmf_ = value; 427 last_pack_cng_or_dtmf_ = value;
426 } 428 }
427 } // namespace webrtc 429 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/neteq/timestamp_scaler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698