Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) { |
|
kwiberg-webrtc
2015/07/12 17:39:26
Maybe n != 0 now that it can't be negative.
Peter Kasting
2015/07/13 02:46:26
Is one preferred over the other for some reason?
kwiberg-webrtc
2015/07/15 01:05:00
The compiler is surely smart enough to realize tha
Peter Kasting
2015/07/15 06:30:09
When I'm working with webrtc code (where I'm basic
Peter Kasting
2015/07/17 00:12:08
Done.
| |
| 94 int i = n - 1; | 96 size_t i = n - 1; |
|
kwiberg-webrtc
2015/07/12 17:39:26
Hmm. This code already jumps through all the hoops
Peter Kasting
2015/07/13 02:46:26
That's probably a sign that I updated the code to
| |
| 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 Loading... | |
| 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 Loading... | |
| 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 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1273 *channels = 1; | 1276 *channels = 1; |
| 1274 break; | 1277 break; |
| 1275 #endif | 1278 #endif |
| 1276 default: | 1279 default: |
| 1277 FATAL() << "Codec type " << codec_type << " not supported."; | 1280 FATAL() << "Codec type " << codec_type << " not supported."; |
| 1278 } | 1281 } |
| 1279 return true; | 1282 return true; |
| 1280 } | 1283 } |
| 1281 | 1284 |
| 1282 } // namespace webrtc | 1285 } // namespace webrtc |
| OLD | NEW |