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

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

Issue 1228843002: Update audio code to use size_t more correctly, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments 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) 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
11 #include "webrtc/modules/audio_coding/neteq/decision_logic_normal.h" 11 #include "webrtc/modules/audio_coding/neteq/decision_logic_normal.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 14
15 #include <algorithm> 15 #include <algorithm>
16 16
17 #include "webrtc/modules/audio_coding/neteq/buffer_level_filter.h" 17 #include "webrtc/modules/audio_coding/neteq/buffer_level_filter.h"
18 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" 18 #include "webrtc/modules/audio_coding/neteq/decoder_database.h"
19 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" 19 #include "webrtc/modules/audio_coding/neteq/delay_manager.h"
20 #include "webrtc/modules/audio_coding/neteq/expand.h" 20 #include "webrtc/modules/audio_coding/neteq/expand.h"
21 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" 21 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h"
22 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" 22 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h"
23 #include "webrtc/modules/interface/module_common_types.h" 23 #include "webrtc/modules/interface/module_common_types.h"
24 24
25 namespace webrtc { 25 namespace webrtc {
26 26
27 Operations DecisionLogicNormal::GetDecisionSpecialized( 27 Operations DecisionLogicNormal::GetDecisionSpecialized(
28 const SyncBuffer& sync_buffer, 28 const SyncBuffer& sync_buffer,
29 const Expand& expand, 29 const Expand& expand,
30 int decoder_frame_length, 30 size_t decoder_frame_length,
31 const RTPHeader* packet_header, 31 const RTPHeader* packet_header,
32 Modes prev_mode, 32 Modes prev_mode,
33 bool play_dtmf, 33 bool play_dtmf,
34 bool* reset_decoder) { 34 bool* reset_decoder) {
35 assert(playout_mode_ == kPlayoutOn || playout_mode_ == kPlayoutStreaming); 35 assert(playout_mode_ == kPlayoutOn || playout_mode_ == kPlayoutStreaming);
36 // Guard for errors, to avoid getting stuck in error mode. 36 // Guard for errors, to avoid getting stuck in error mode.
37 if (prev_mode == kModeError) { 37 if (prev_mode == kModeError) {
38 if (!packet_header) { 38 if (!packet_header) {
39 return kExpand; 39 return kExpand;
40 } else { 40 } else {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (buffer_level_filter_->filtered_current_level() < low_limit) 142 if (buffer_level_filter_->filtered_current_level() < low_limit)
143 return kPreemptiveExpand; 143 return kPreemptiveExpand;
144 } 144 }
145 } 145 }
146 return kNormal; 146 return kNormal;
147 } 147 }
148 148
149 Operations DecisionLogicNormal::FuturePacketAvailable( 149 Operations DecisionLogicNormal::FuturePacketAvailable(
150 const SyncBuffer& sync_buffer, 150 const SyncBuffer& sync_buffer,
151 const Expand& expand, 151 const Expand& expand,
152 int decoder_frame_length, 152 size_t decoder_frame_length,
153 Modes prev_mode, 153 Modes prev_mode,
154 uint32_t target_timestamp, 154 uint32_t target_timestamp,
155 uint32_t available_timestamp, 155 uint32_t available_timestamp,
156 bool play_dtmf) { 156 bool play_dtmf) {
157 // Required packet is not available, but a future packet is. 157 // Required packet is not available, but a future packet is.
158 // Check if we should continue with an ongoing expand because the new packet 158 // Check if we should continue with an ongoing expand because the new packet
159 // is too far into the future. 159 // is too far into the future.
160 uint32_t timestamp_leap = available_timestamp - target_timestamp; 160 uint32_t timestamp_leap = available_timestamp - target_timestamp;
161 if ((prev_mode == kModeExpand) && 161 if ((prev_mode == kModeExpand) &&
162 !ReinitAfterExpands(timestamp_leap) && 162 !ReinitAfterExpands(timestamp_leap) &&
163 !MaxWaitForPacket() && 163 !MaxWaitForPacket() &&
164 PacketTooEarly(timestamp_leap) && 164 PacketTooEarly(timestamp_leap) &&
165 UnderTargetLevel()) { 165 UnderTargetLevel()) {
166 if (play_dtmf) { 166 if (play_dtmf) {
167 // Still have DTMF to play, so do not do expand. 167 // Still have DTMF to play, so do not do expand.
168 return kDtmf; 168 return kDtmf;
169 } else { 169 } else {
170 // Nothing to play. 170 // Nothing to play.
171 return kExpand; 171 return kExpand;
172 } 172 }
173 } 173 }
174 174
175 const int samples_left = static_cast<int>(sync_buffer.FutureLength() - 175 const size_t samples_left =
176 expand.overlap_length()); 176 sync_buffer.FutureLength() - expand.overlap_length();
177 const int cur_size_samples = samples_left + 177 const size_t cur_size_samples = samples_left +
178 packet_buffer_.NumPacketsInBuffer() * decoder_frame_length; 178 packet_buffer_.NumPacketsInBuffer() * decoder_frame_length;
179 179
180 // If previous was comfort noise, then no merge is needed. 180 // If previous was comfort noise, then no merge is needed.
181 if (prev_mode == kModeRfc3389Cng || 181 if (prev_mode == kModeRfc3389Cng ||
182 prev_mode == kModeCodecInternalCng) { 182 prev_mode == kModeCodecInternalCng) {
183 // 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
184 // 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
185 // 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()
186 // is in Q8.) 186 // is in Q8.)
187 if (static_cast<uint32_t>(generated_noise_samples_ + target_timestamp) >= 187 if (static_cast<uint32_t>(generated_noise_samples_ + target_timestamp) >=
(...skipping 10 matching lines...) Expand all
198 } else { // prevPlayMode == kModeCodecInternalCng. 198 } else { // prevPlayMode == kModeCodecInternalCng.
199 return kCodecInternalCng; 199 return kCodecInternalCng;
200 } 200 }
201 } 201 }
202 } 202 }
203 // Do not merge unless we have done an expand before. 203 // Do not merge unless we have done an expand before.
204 // (Convert kAllowMergeWithoutExpand from ms to samples by multiplying with 204 // (Convert kAllowMergeWithoutExpand from ms to samples by multiplying with
205 // fs_mult_ * 8 = fs / 1000.) 205 // fs_mult_ * 8 = fs / 1000.)
206 if (prev_mode == kModeExpand || 206 if (prev_mode == kModeExpand ||
207 (decoder_frame_length < output_size_samples_ && 207 (decoder_frame_length < output_size_samples_ &&
208 cur_size_samples > kAllowMergeWithoutExpandMs * fs_mult_ * 8)) { 208 cur_size_samples >
209 static_cast<size_t>(kAllowMergeWithoutExpandMs * fs_mult_ * 8))) {
209 return kMerge; 210 return kMerge;
210 } else if (play_dtmf) { 211 } else if (play_dtmf) {
211 // Play DTMF instead of expand. 212 // Play DTMF instead of expand.
212 return kDtmf; 213 return kDtmf;
213 } else { 214 } else {
214 return kExpand; 215 return kExpand;
215 } 216 }
216 } 217 }
217 218
218 bool DecisionLogicNormal::UnderTargetLevel() const { 219 bool DecisionLogicNormal::UnderTargetLevel() const {
219 return buffer_level_filter_->filtered_current_level() <= 220 return buffer_level_filter_->filtered_current_level() <=
220 delay_manager_->TargetLevel(); 221 delay_manager_->TargetLevel();
221 } 222 }
222 223
223 bool DecisionLogicNormal::ReinitAfterExpands(uint32_t timestamp_leap) const { 224 bool DecisionLogicNormal::ReinitAfterExpands(uint32_t timestamp_leap) const {
224 return timestamp_leap >= 225 return timestamp_leap >=
225 static_cast<uint32_t>(output_size_samples_ * kReinitAfterExpands); 226 static_cast<uint32_t>(output_size_samples_ * kReinitAfterExpands);
226 } 227 }
227 228
228 bool DecisionLogicNormal::PacketTooEarly(uint32_t timestamp_leap) const { 229 bool DecisionLogicNormal::PacketTooEarly(uint32_t timestamp_leap) const {
229 return timestamp_leap > 230 return timestamp_leap >
230 static_cast<uint32_t>(output_size_samples_ * num_consecutive_expands_); 231 static_cast<uint32_t>(output_size_samples_ * num_consecutive_expands_);
231 } 232 }
232 233
233 bool DecisionLogicNormal::MaxWaitForPacket() const { 234 bool DecisionLogicNormal::MaxWaitForPacket() const {
234 return num_consecutive_expands_ >= kMaxWaitForPacket; 235 return num_consecutive_expands_ >= kMaxWaitForPacket;
235 } 236 }
236 237
237 } // namespace webrtc 238 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/decision_logic_normal.h ('k') | webrtc/modules/audio_coding/neteq/delay_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698