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

Side by Side Diff: webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc

Issue 1174813003: Prepare to convert various types to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments + 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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 << " ms when using VAD/CNG."; 129 << " ms when using VAD/CNG.";
130 130
131 // Group several 10 ms blocks per VAD call. Call VAD once or twice using the 131 // Group several 10 ms blocks per VAD call. Call VAD once or twice using the
132 // following split sizes: 132 // following split sizes:
133 // 10 ms = 10 + 0 ms; 20 ms = 20 + 0 ms; 30 ms = 30 + 0 ms; 133 // 10 ms = 10 + 0 ms; 20 ms = 20 + 0 ms; 30 ms = 30 + 0 ms;
134 // 40 ms = 20 + 20 ms; 50 ms = 30 + 20 ms; 60 ms = 30 + 30 ms. 134 // 40 ms = 20 + 20 ms; 50 ms = 30 + 20 ms; 60 ms = 30 + 30 ms.
135 int blocks_in_first_vad_call = 135 int blocks_in_first_vad_call =
136 (frames_to_encode > 3 ? 3 : frames_to_encode); 136 (frames_to_encode > 3 ? 3 : frames_to_encode);
137 if (frames_to_encode == 4) 137 if (frames_to_encode == 4)
138 blocks_in_first_vad_call = 2; 138 blocks_in_first_vad_call = 2;
139 CHECK_GE(frames_to_encode, blocks_in_first_vad_call);
139 const int blocks_in_second_vad_call = 140 const int blocks_in_second_vad_call =
140 frames_to_encode - blocks_in_first_vad_call; 141 frames_to_encode - blocks_in_first_vad_call;
141 CHECK_GE(blocks_in_second_vad_call, 0);
142 142
143 // Check if all of the buffer is passive speech. Start with checking the first 143 // Check if all of the buffer is passive speech. Start with checking the first
144 // block. 144 // block.
145 Vad::Activity activity = vad_->VoiceActivity( 145 Vad::Activity activity = vad_->VoiceActivity(
146 &speech_buffer_[0], samples_per_10ms_frame * blocks_in_first_vad_call, 146 &speech_buffer_[0], samples_per_10ms_frame * blocks_in_first_vad_call,
147 SampleRateHz()); 147 SampleRateHz());
148 if (activity == Vad::kPassive && blocks_in_second_vad_call > 0) { 148 if (activity == Vad::kPassive && blocks_in_second_vad_call > 0) {
149 // Only check the second block if the first was passive. 149 // Only check the second block if the first was passive.
150 activity = vad_->VoiceActivity( 150 activity = vad_->VoiceActivity(
151 &speech_buffer_[samples_per_10ms_frame * blocks_in_first_vad_call], 151 &speech_buffer_[samples_per_10ms_frame * blocks_in_first_vad_call],
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 AudioEncoder::EncodedInfo AudioEncoderCng::EncodeActive( 210 AudioEncoder::EncodedInfo AudioEncoderCng::EncodeActive(
211 int frames_to_encode, 211 int frames_to_encode,
212 size_t max_encoded_bytes, 212 size_t max_encoded_bytes,
213 uint8_t* encoded) { 213 uint8_t* encoded) {
214 const size_t samples_per_10ms_frame = SamplesPer10msFrame(); 214 const size_t samples_per_10ms_frame = SamplesPer10msFrame();
215 AudioEncoder::EncodedInfo info; 215 AudioEncoder::EncodedInfo info;
216 for (int i = 0; i < frames_to_encode; ++i) { 216 for (int i = 0; i < frames_to_encode; ++i) {
217 info = speech_encoder_->Encode( 217 info = speech_encoder_->Encode(
218 rtp_timestamps_.front(), &speech_buffer_[i * samples_per_10ms_frame], 218 rtp_timestamps_.front(), &speech_buffer_[i * samples_per_10ms_frame],
219 samples_per_10ms_frame, max_encoded_bytes, encoded); 219 samples_per_10ms_frame, max_encoded_bytes, encoded);
220 if (i == frames_to_encode - 1) { 220 if (i + 1 == frames_to_encode) {
221 CHECK_GT(info.encoded_bytes, 0u) << "Encoder didn't deliver data."; 221 CHECK_GT(info.encoded_bytes, 0u) << "Encoder didn't deliver data.";
222 } else { 222 } else {
223 CHECK_EQ(info.encoded_bytes, 0u) << "Encoder delivered data too early."; 223 CHECK_EQ(info.encoded_bytes, 0u) << "Encoder delivered data too early.";
224 } 224 }
225 } 225 }
226 return info; 226 return info;
227 } 227 }
228 228
229 size_t AudioEncoderCng::SamplesPer10msFrame() const { 229 size_t AudioEncoderCng::SamplesPer10msFrame() const {
230 return rtc::CheckedDivExact(10 * SampleRateHz(), 1000); 230 return rtc::CheckedDivExact(10 * SampleRateHz(), 1000);
231 } 231 }
232 232
233 } // namespace webrtc 233 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/codecs/audio_decoder.cc ('k') | webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698