Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" | 11 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" |
| 12 | 12 |
| 13 #include <limits> | 13 #include <limits> |
| 14 | 14 |
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/common_types.h" | 16 #include "webrtc/common_types.h" |
| 17 #include "webrtc/modules/audio_coding/codecs/g711/g711_interface.h" | 17 #include "webrtc/modules/audio_coding/codecs/g711/g711_interface.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 int16_t NumSamplesPerFrame(int num_channels, | 23 int16_t NumSamplesPerFrame(size_t num_channels, |
| 24 int frame_size_ms, | 24 int frame_size_ms, |
| 25 int sample_rate_hz) { | 25 int sample_rate_hz) { |
| 26 int samples_per_frame = num_channels * frame_size_ms * sample_rate_hz / 1000; | 26 size_t samples_per_frame = |
|
minyue-webrtc
2015/12/29 10:42:47
but why not casting |num_channels| to int and keep
Peter Kasting
2015/12/30 00:55:45
What? How can that be negative? You'd have to ha
minyue-webrtc
2016/01/04 09:06:02
sorry for ambiguity. I meant that there is no chec
Peter Kasting
2016/01/04 19:49:42
Looking at its use, it should be, yes. I can make
minyue-webrtc
2016/01/04 22:03:18
I guess that check is to make sure that casting on
Peter Kasting
2016/01/08 02:45:06
I simplified everything to just do this calculatio
| |
| 27 RTC_CHECK_LE(samples_per_frame, std::numeric_limits<int16_t>::max()) | 27 num_channels * frame_size_ms * sample_rate_hz / 1000; |
| 28 RTC_CHECK_LE(samples_per_frame, | |
| 29 static_cast<size_t>(std::numeric_limits<int16_t>::max())) | |
| 28 << "Frame size too large."; | 30 << "Frame size too large."; |
| 29 return static_cast<int16_t>(samples_per_frame); | 31 return static_cast<int16_t>(samples_per_frame); |
| 30 } | 32 } |
| 31 | 33 |
| 32 template <typename T> | 34 template <typename T> |
| 33 typename T::Config CreateConfig(const CodecInst& codec_inst) { | 35 typename T::Config CreateConfig(const CodecInst& codec_inst) { |
| 34 typename T::Config config; | 36 typename T::Config config; |
| 35 config.frame_size_ms = codec_inst.pacsize / 8; | 37 config.frame_size_ms = codec_inst.pacsize / 8; |
| 36 config.num_channels = codec_inst.channels; | 38 config.num_channels = codec_inst.channels; |
| 37 config.payload_type = codec_inst.pltype; | 39 config.payload_type = codec_inst.pltype; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 63 AudioEncoderPcm::~AudioEncoderPcm() = default; | 65 AudioEncoderPcm::~AudioEncoderPcm() = default; |
| 64 | 66 |
| 65 size_t AudioEncoderPcm::MaxEncodedBytes() const { | 67 size_t AudioEncoderPcm::MaxEncodedBytes() const { |
| 66 return full_frame_samples_ * BytesPerSample(); | 68 return full_frame_samples_ * BytesPerSample(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 int AudioEncoderPcm::SampleRateHz() const { | 71 int AudioEncoderPcm::SampleRateHz() const { |
| 70 return sample_rate_hz_; | 72 return sample_rate_hz_; |
| 71 } | 73 } |
| 72 | 74 |
| 73 int AudioEncoderPcm::NumChannels() const { | 75 size_t AudioEncoderPcm::NumChannels() const { |
| 74 return num_channels_; | 76 return num_channels_; |
| 75 } | 77 } |
| 76 | 78 |
| 77 size_t AudioEncoderPcm::Num10MsFramesInNextPacket() const { | 79 size_t AudioEncoderPcm::Num10MsFramesInNextPacket() const { |
| 78 return num_10ms_frames_per_packet_; | 80 return num_10ms_frames_per_packet_; |
| 79 } | 81 } |
| 80 | 82 |
| 81 size_t AudioEncoderPcm::Max10MsFramesInAPacket() const { | 83 size_t AudioEncoderPcm::Max10MsFramesInAPacket() const { |
| 82 return num_10ms_frames_per_packet_; | 84 return num_10ms_frames_per_packet_; |
| 83 } | 85 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 size_t input_len, | 136 size_t input_len, |
| 135 uint8_t* encoded) { | 137 uint8_t* encoded) { |
| 136 return WebRtcG711_EncodeU(audio, input_len, encoded); | 138 return WebRtcG711_EncodeU(audio, input_len, encoded); |
| 137 } | 139 } |
| 138 | 140 |
| 139 size_t AudioEncoderPcmU::BytesPerSample() const { | 141 size_t AudioEncoderPcmU::BytesPerSample() const { |
| 140 return 1; | 142 return 1; |
| 141 } | 143 } |
| 142 | 144 |
| 143 } // namespace webrtc | 145 } // namespace webrtc |
| OLD | NEW |