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

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc

Issue 1230503003: Update a ton of audio code to use size_t more correctly and in general reduce (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 3 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) 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
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 bool IsCodecCN(const CodecInst* codec) { 70 bool IsCodecCN(const CodecInst* codec) {
71 return (STR_CASE_CMP(codec->plname, "CN") == 0); 71 return (STR_CASE_CMP(codec->plname, "CN") == 0);
72 } 72 }
73 73
74 bool IsCodecCN(int index) { 74 bool IsCodecCN(int index) {
75 return (IsCodecCN(&ACMCodecDB::database_[index])); 75 return (IsCodecCN(&ACMCodecDB::database_[index]));
76 } 76 }
77 77
78 // Stereo-to-mono can be used as in-place. 78 // Stereo-to-mono can be used as in-place.
79 int DownMix(const AudioFrame& frame, int length_out_buff, int16_t* out_buff) { 79 int DownMix(const AudioFrame& frame,
80 size_t length_out_buff,
81 int16_t* out_buff) {
80 if (length_out_buff < frame.samples_per_channel_) { 82 if (length_out_buff < frame.samples_per_channel_) {
81 return -1; 83 return -1;
82 } 84 }
83 for (int n = 0; n < frame.samples_per_channel_; ++n) 85 for (size_t n = 0; n < frame.samples_per_channel_; ++n)
84 out_buff[n] = (frame.data_[2 * n] + frame.data_[2 * n + 1]) >> 1; 86 out_buff[n] = (frame.data_[2 * n] + frame.data_[2 * n + 1]) >> 1;
85 return 0; 87 return 0;
86 } 88 }
87 89
88 // Mono-to-stereo can be used as in-place. 90 // Mono-to-stereo can be used as in-place.
89 int UpMix(const AudioFrame& frame, int length_out_buff, int16_t* out_buff) { 91 int UpMix(const AudioFrame& frame, size_t length_out_buff, int16_t* out_buff) {
90 if (length_out_buff < frame.samples_per_channel_) { 92 if (length_out_buff < frame.samples_per_channel_) {
91 return -1; 93 return -1;
92 } 94 }
93 for (int n = frame.samples_per_channel_; n > 0; --n) { 95 for (size_t n = frame.samples_per_channel_; n != 0; --n) {
94 int i = n - 1; 96 size_t i = n - 1;
95 int16_t sample = frame.data_[i]; 97 int16_t sample = frame.data_[i];
96 out_buff[2 * i + 1] = sample; 98 out_buff[2 * i + 1] = sample;
97 out_buff[2 * i] = sample; 99 out_buff[2 * i] = sample;
98 } 100 }
99 return 0; 101 return 0;
100 } 102 }
101 103
102 void ConvertEncodedInfoToFragmentationHeader( 104 void ConvertEncodedInfoToFragmentationHeader(
103 const AudioEncoder::EncodedInfo& info, 105 const AudioEncoder::EncodedInfo& info,
104 RTPFragmentationHeader* frag) { 106 RTPFragmentationHeader* frag) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 // Add 10MS of raw (PCM) audio data to the encoder. 333 // Add 10MS of raw (PCM) audio data to the encoder.
332 int AudioCodingModuleImpl::Add10MsData(const AudioFrame& audio_frame) { 334 int AudioCodingModuleImpl::Add10MsData(const AudioFrame& audio_frame) {
333 InputData input_data; 335 InputData input_data;
334 CriticalSectionScoped lock(acm_crit_sect_); 336 CriticalSectionScoped lock(acm_crit_sect_);
335 int r = Add10MsDataInternal(audio_frame, &input_data); 337 int r = Add10MsDataInternal(audio_frame, &input_data);
336 return r < 0 ? r : Encode(input_data); 338 return r < 0 ? r : Encode(input_data);
337 } 339 }
338 340
339 int AudioCodingModuleImpl::Add10MsDataInternal(const AudioFrame& audio_frame, 341 int AudioCodingModuleImpl::Add10MsDataInternal(const AudioFrame& audio_frame,
340 InputData* input_data) { 342 InputData* input_data) {
341 if (audio_frame.samples_per_channel_ <= 0) { 343 if (audio_frame.samples_per_channel_ == 0) {
342 assert(false); 344 assert(false);
343 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, 345 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
344 "Cannot Add 10 ms audio, payload length is negative or " 346 "Cannot Add 10 ms audio, payload length is zero");
345 "zero");
346 return -1; 347 return -1;
347 } 348 }
348 349
349 if (audio_frame.sample_rate_hz_ > 48000) { 350 if (audio_frame.sample_rate_hz_ > 48000) {
350 assert(false); 351 assert(false);
351 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, 352 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
352 "Cannot Add 10 ms audio, input frequency not valid"); 353 "Cannot Add 10 ms audio, input frequency not valid");
353 return -1; 354 return -1;
354 } 355 }
355 356
356 // If the length and frequency matches. We currently just support raw PCM. 357 // If the length and frequency matches. We currently just support raw PCM.
357 if ((audio_frame.sample_rate_hz_ / 100) != 358 if (static_cast<size_t>(audio_frame.sample_rate_hz_ / 100) !=
358 audio_frame.samples_per_channel_) { 359 audio_frame.samples_per_channel_) {
359 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, 360 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
360 "Cannot Add 10 ms audio, input frequency and length doesn't" 361 "Cannot Add 10 ms audio, input frequency and length doesn't"
361 " match"); 362 " match");
362 return -1; 363 return -1;
363 } 364 }
364 365
365 if (audio_frame.num_channels_ != 1 && audio_frame.num_channels_ != 2) { 366 if (audio_frame.num_channels_ != 1 && audio_frame.num_channels_ != 2) {
366 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, 367 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
367 "Cannot Add 10 ms audio, invalid number of channels."); 368 "Cannot Add 10 ms audio, invalid number of channels.");
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 471 }
471 472
472 preprocess_frame_.timestamp_ = expected_codec_ts_; 473 preprocess_frame_.timestamp_ = expected_codec_ts_;
473 preprocess_frame_.samples_per_channel_ = in_frame.samples_per_channel_; 474 preprocess_frame_.samples_per_channel_ = in_frame.samples_per_channel_;
474 preprocess_frame_.sample_rate_hz_ = in_frame.sample_rate_hz_; 475 preprocess_frame_.sample_rate_hz_ = in_frame.sample_rate_hz_;
475 // If it is required, we have to do a resampling. 476 // If it is required, we have to do a resampling.
476 if (resample) { 477 if (resample) {
477 // The result of the resampler is written to output frame. 478 // The result of the resampler is written to output frame.
478 dest_ptr_audio = preprocess_frame_.data_; 479 dest_ptr_audio = preprocess_frame_.data_;
479 480
480 preprocess_frame_.samples_per_channel_ = resampler_.Resample10Msec( 481 int samples_per_channel = resampler_.Resample10Msec(
481 src_ptr_audio, in_frame.sample_rate_hz_, 482 src_ptr_audio, in_frame.sample_rate_hz_,
482 codec_manager_.CurrentEncoder()->SampleRateHz(), 483 codec_manager_.CurrentEncoder()->SampleRateHz(),
483 preprocess_frame_.num_channels_, AudioFrame::kMaxDataSizeSamples, 484 preprocess_frame_.num_channels_, AudioFrame::kMaxDataSizeSamples,
484 dest_ptr_audio); 485 dest_ptr_audio);
485 486
486 if (preprocess_frame_.samples_per_channel_ < 0) { 487 if (samples_per_channel < 0) {
487 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, 488 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
488 "Cannot add 10 ms audio, resampling failed"); 489 "Cannot add 10 ms audio, resampling failed");
489 return -1; 490 return -1;
490 } 491 }
492 preprocess_frame_.samples_per_channel_ =
493 static_cast<size_t>(samples_per_channel);
491 preprocess_frame_.sample_rate_hz_ = 494 preprocess_frame_.sample_rate_hz_ =
492 codec_manager_.CurrentEncoder()->SampleRateHz(); 495 codec_manager_.CurrentEncoder()->SampleRateHz();
493 } 496 }
494 497
495 expected_codec_ts_ += 498 expected_codec_ts_ +=
496 static_cast<uint32_t>(preprocess_frame_.samples_per_channel_); 499 static_cast<uint32_t>(preprocess_frame_.samples_per_channel_);
497 expected_in_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_); 500 expected_in_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_);
498 501
499 return 0; 502 return 0;
500 } 503 }
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 *channels = 1; 1299 *channels = 1;
1297 break; 1300 break;
1298 #endif 1301 #endif
1299 default: 1302 default:
1300 FATAL() << "Codec type " << codec_type << " not supported."; 1303 FATAL() << "Codec type " << codec_type << " not supported.";
1301 } 1304 }
1302 return true; 1305 return true;
1303 } 1306 }
1304 1307
1305 } // namespace webrtc 1308 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698