| 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 |
| 11 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" | 11 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" |
| 12 | 12 |
| 13 #include <algorithm> |
| 14 |
| 13 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" | 15 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" |
| 14 #include "webrtc/modules/audio_coding/acm2/acm_receiver.h" | 16 #include "webrtc/modules/audio_coding/acm2/acm_receiver.h" |
| 15 #include "webrtc/modules/audio_coding/acm2/acm_resampler.h" | 17 #include "webrtc/modules/audio_coding/acm2/acm_resampler.h" |
| 16 #include "webrtc/modules/audio_coding/acm2/codec_manager.h" | 18 #include "webrtc/modules/audio_coding/acm2/codec_manager.h" |
| 17 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" | 19 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" |
| 18 #include "webrtc/rtc_base/checks.h" | 20 #include "webrtc/rtc_base/checks.h" |
| 19 #include "webrtc/rtc_base/logging.h" | 21 #include "webrtc/rtc_base/logging.h" |
| 20 #include "webrtc/rtc_base/safe_conversions.h" | 22 #include "webrtc/rtc_base/safe_conversions.h" |
| 21 #include "webrtc/system_wrappers/include/metrics.h" | 23 #include "webrtc/system_wrappers/include/metrics.h" |
| 22 | 24 |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 RTC_DCHECK_GE(length_out_buff, frame.samples_per_channel_); | 330 RTC_DCHECK_GE(length_out_buff, frame.samples_per_channel_); |
| 329 | 331 |
| 330 if (!frame.muted()) { | 332 if (!frame.muted()) { |
| 331 const int16_t* frame_data = frame.data(); | 333 const int16_t* frame_data = frame.data(); |
| 332 for (size_t n = 0; n < frame.samples_per_channel_; ++n) { | 334 for (size_t n = 0; n < frame.samples_per_channel_; ++n) { |
| 333 out_buff[n] = static_cast<int16_t>( | 335 out_buff[n] = static_cast<int16_t>( |
| 334 (static_cast<int32_t>(frame_data[2 * n]) + | 336 (static_cast<int32_t>(frame_data[2 * n]) + |
| 335 static_cast<int32_t>(frame_data[2 * n + 1])) >> 1); | 337 static_cast<int32_t>(frame_data[2 * n + 1])) >> 1); |
| 336 } | 338 } |
| 337 } else { | 339 } else { |
| 338 memset(out_buff, 0, frame.samples_per_channel_); | 340 std::fill(out_buff, out_buff + frame.samples_per_channel_, 0); |
| 339 } | 341 } |
| 340 return 0; | 342 return 0; |
| 341 } | 343 } |
| 342 | 344 |
| 343 // Mono-to-stereo can be used as in-place. | 345 // Mono-to-stereo can be used as in-place. |
| 344 int UpMix(const AudioFrame& frame, size_t length_out_buff, int16_t* out_buff) { | 346 int UpMix(const AudioFrame& frame, size_t length_out_buff, int16_t* out_buff) { |
| 345 RTC_DCHECK_EQ(frame.num_channels_, 1); | 347 RTC_DCHECK_EQ(frame.num_channels_, 1); |
| 346 RTC_DCHECK_GE(length_out_buff, 2 * frame.samples_per_channel_); | 348 RTC_DCHECK_GE(length_out_buff, 2 * frame.samples_per_channel_); |
| 347 | 349 |
| 348 if (!frame.muted()) { | 350 if (!frame.muted()) { |
| 349 const int16_t* frame_data = frame.data(); | 351 const int16_t* frame_data = frame.data(); |
| 350 for (size_t n = frame.samples_per_channel_; n != 0; --n) { | 352 for (size_t n = frame.samples_per_channel_; n != 0; --n) { |
| 351 size_t i = n - 1; | 353 size_t i = n - 1; |
| 352 int16_t sample = frame_data[i]; | 354 int16_t sample = frame_data[i]; |
| 353 out_buff[2 * i + 1] = sample; | 355 out_buff[2 * i + 1] = sample; |
| 354 out_buff[2 * i] = sample; | 356 out_buff[2 * i] = sample; |
| 355 } | 357 } |
| 356 } else { | 358 } else { |
| 357 memset(out_buff, 0, 2 * frame.samples_per_channel_); | 359 std::fill(out_buff, out_buff + frame.samples_per_channel_ * 2, 0); |
| 358 } | 360 } |
| 359 return 0; | 361 return 0; |
| 360 } | 362 } |
| 361 | 363 |
| 362 void ConvertEncodedInfoToFragmentationHeader( | 364 void ConvertEncodedInfoToFragmentationHeader( |
| 363 const AudioEncoder::EncodedInfo& info, | 365 const AudioEncoder::EncodedInfo& info, |
| 364 RTPFragmentationHeader* frag) { | 366 RTPFragmentationHeader* frag) { |
| 365 if (info.redundant.empty()) { | 367 if (info.redundant.empty()) { |
| 366 frag->fragmentationVectorSize = 0; | 368 frag->fragmentationVectorSize = 0; |
| 367 return; | 369 return; |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 | 1360 |
| 1359 // Checks the validity of the parameters of the given codec | 1361 // Checks the validity of the parameters of the given codec |
| 1360 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { | 1362 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { |
| 1361 bool valid = acm2::RentACodec::IsCodecValid(codec); | 1363 bool valid = acm2::RentACodec::IsCodecValid(codec); |
| 1362 if (!valid) | 1364 if (!valid) |
| 1363 LOG(LS_ERROR) << "Invalid codec setting"; | 1365 LOG(LS_ERROR) << "Invalid codec setting"; |
| 1364 return valid; | 1366 return valid; |
| 1365 } | 1367 } |
| 1366 | 1368 |
| 1367 } // namespace webrtc | 1369 } // namespace webrtc |
| OLD | NEW |