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

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

Issue 1168753002: Match existing type usage better. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 6 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return NoPacket(play_dtmf); 60 return NoPacket(play_dtmf);
61 } 61 }
62 62
63 // If the expand period was very long, reset NetEQ since it is likely that the 63 // If the expand period was very long, reset NetEQ since it is likely that the
64 // sender was restarted. 64 // sender was restarted.
65 if (num_consecutive_expands_ > kReinitAfterExpands) { 65 if (num_consecutive_expands_ > kReinitAfterExpands) {
66 *reset_decoder = true; 66 *reset_decoder = true;
67 return kNormal; 67 return kNormal;
68 } 68 }
69 69
70 const uint32_t five_seconds_samples = 5 * 8000 * fs_mult_; 70 const uint32_t five_seconds_samples =
71 static_cast<uint32_t>(5 * 8000 * fs_mult_);
71 // Check if the required packet is available. 72 // Check if the required packet is available.
72 if (target_timestamp == available_timestamp) { 73 if (target_timestamp == available_timestamp) {
73 return ExpectedPacketAvailable(prev_mode, play_dtmf); 74 return ExpectedPacketAvailable(prev_mode, play_dtmf);
74 } else if (!PacketBuffer::IsObsoleteTimestamp( 75 } else if (!PacketBuffer::IsObsoleteTimestamp(
75 available_timestamp, target_timestamp, five_seconds_samples)) { 76 available_timestamp, target_timestamp, five_seconds_samples)) {
76 return FuturePacketAvailable(sync_buffer, expand, decoder_frame_length, 77 return FuturePacketAvailable(sync_buffer, expand, decoder_frame_length,
77 prev_mode, target_timestamp, 78 prev_mode, target_timestamp,
78 available_timestamp, play_dtmf); 79 available_timestamp, play_dtmf);
79 } else { 80 } else {
80 // This implies that available_timestamp < target_timestamp, which can 81 // This implies that available_timestamp < target_timestamp, which can
81 // happen when a new stream or codec is received. Signal for a reset. 82 // happen when a new stream or codec is received. Signal for a reset.
82 return kUndefined; 83 return kUndefined;
83 } 84 }
84 } 85 }
85 86
86 Operations DecisionLogicNormal::CngOperation(Modes prev_mode, 87 Operations DecisionLogicNormal::CngOperation(Modes prev_mode,
87 uint32_t target_timestamp, 88 uint32_t target_timestamp,
88 uint32_t available_timestamp) { 89 uint32_t available_timestamp) {
89 // Signed difference between target and available timestamp. 90 // Signed difference between target and available timestamp.
90 int32_t timestamp_diff = (generated_noise_samples_ + target_timestamp) - 91 int32_t timestamp_diff = static_cast<int32_t>(
91 available_timestamp; 92 static_cast<uint32_t>(generated_noise_samples_ + target_timestamp) -
92 int32_t optimal_level_samp = 93 available_timestamp);
93 (delay_manager_->TargetLevel() * packet_length_samples_) >> 8; 94 int32_t optimal_level_samp = static_cast<int32_t>(
95 (delay_manager_->TargetLevel() * packet_length_samples_) >> 8);
94 int32_t excess_waiting_time_samp = -timestamp_diff - optimal_level_samp; 96 int32_t excess_waiting_time_samp = -timestamp_diff - optimal_level_samp;
95 97
96 if (excess_waiting_time_samp > optimal_level_samp / 2) { 98 if (excess_waiting_time_samp > optimal_level_samp / 2) {
97 // The waiting time for this packet will be longer than 1.5 99 // The waiting time for this packet will be longer than 1.5
98 // times the wanted buffer delay. Advance the clock to cut 100 // times the wanted buffer delay. Advance the clock to cut
99 // waiting time down to the optimal. 101 // waiting time down to the optimal.
100 generated_noise_samples_ += excess_waiting_time_samp; 102 generated_noise_samples_ += excess_waiting_time_samp;
101 timestamp_diff += excess_waiting_time_samp; 103 timestamp_diff += excess_waiting_time_samp;
102 } 104 }
103 105
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 const int cur_size_samples = samples_left + 177 const int cur_size_samples = samples_left +
176 packet_buffer_.NumPacketsInBuffer() * decoder_frame_length; 178 packet_buffer_.NumPacketsInBuffer() * decoder_frame_length;
177 179
178 // If previous was comfort noise, then no merge is needed. 180 // If previous was comfort noise, then no merge is needed.
179 if (prev_mode == kModeRfc3389Cng || 181 if (prev_mode == kModeRfc3389Cng ||
180 prev_mode == kModeCodecInternalCng) { 182 prev_mode == kModeCodecInternalCng) {
181 // Keep the same delay as before the CNG (or maximum 70 ms in buffer as 183 // Keep the same delay as before the CNG (or maximum 70 ms in buffer as
182 // safety precaution), but make sure that the number of samples in buffer 184 // safety precaution), but make sure that the number of samples in buffer
183 // is no higher than 4 times the optimal level. (Note that TargetLevel() 185 // is no higher than 4 times the optimal level. (Note that TargetLevel()
184 // is in Q8.) 186 // is in Q8.)
185 int32_t timestamp_diff = (generated_noise_samples_ + target_timestamp) - 187 if (static_cast<uint32_t>(generated_noise_samples_ + target_timestamp) >=
186 available_timestamp; 188 available_timestamp ||
187 if (timestamp_diff >= 0 ||
188 cur_size_samples > 189 cur_size_samples >
189 4 * ((delay_manager_->TargetLevel() * packet_length_samples_) >> 8)) { 190 ((delay_manager_->TargetLevel() * packet_length_samples_) >> 8) *
191 4) {
190 // Time to play this new packet. 192 // Time to play this new packet.
191 return kNormal; 193 return kNormal;
192 } else { 194 } else {
193 // Too early to play this new packet; keep on playing comfort noise. 195 // Too early to play this new packet; keep on playing comfort noise.
194 if (prev_mode == kModeRfc3389Cng) { 196 if (prev_mode == kModeRfc3389Cng) {
195 return kRfc3389CngNoPacket; 197 return kRfc3389CngNoPacket;
196 } else { // prevPlayMode == kModeCodecInternalCng. 198 } else { // prevPlayMode == kModeCodecInternalCng.
197 return kCodecInternalCng; 199 return kCodecInternalCng;
198 } 200 }
199 } 201 }
(...skipping 26 matching lines...) Expand all
226 bool DecisionLogicNormal::PacketTooEarly(uint32_t timestamp_leap) const { 228 bool DecisionLogicNormal::PacketTooEarly(uint32_t timestamp_leap) const {
227 return timestamp_leap > 229 return timestamp_leap >
228 static_cast<uint32_t>(output_size_samples_ * num_consecutive_expands_); 230 static_cast<uint32_t>(output_size_samples_ * num_consecutive_expands_);
229 } 231 }
230 232
231 bool DecisionLogicNormal::MaxWaitForPacket() const { 233 bool DecisionLogicNormal::MaxWaitForPacket() const {
232 return num_consecutive_expands_ >= kMaxWaitForPacket; 234 return num_consecutive_expands_ >= kMaxWaitForPacket;
233 } 235 }
234 236
235 } // namespace webrtc 237 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/background_noise.cc ('k') | webrtc/modules/audio_coding/neteq/expand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698