| 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/include/audio_encoder_pcm.h" | 11 #include "webrtc/modules/audio_coding/codecs/g711/include/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/include/g711_interface.h" | 17 #include "webrtc/modules/audio_coding/codecs/g711/include/g711_interface.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 int16_t NumSamplesPerFrame(int num_channels, | 22 int16_t NumSamplesPerFrame(size_t num_channels, |
| 23 int frame_size_ms, | 23 int frame_size_ms, |
| 24 int sample_rate_hz) { | 24 int sample_rate_hz) { |
| 25 int samples_per_frame = num_channels * frame_size_ms * sample_rate_hz / 1000; | 25 size_t samples_per_frame = |
| 26 CHECK_LE(samples_per_frame, std::numeric_limits<int16_t>::max()) | 26 num_channels * frame_size_ms * sample_rate_hz / 1000; |
| 27 CHECK_LE(samples_per_frame, |
| 28 static_cast<size_t>(std::numeric_limits<int16_t>::max())) |
| 27 << "Frame size too large."; | 29 << "Frame size too large."; |
| 28 return static_cast<int16_t>(samples_per_frame); | 30 return static_cast<int16_t>(samples_per_frame); |
| 29 } | 31 } |
| 30 } // namespace | 32 } // namespace |
| 31 | 33 |
| 32 bool AudioEncoderPcm::Config::IsOk() const { | 34 bool AudioEncoderPcm::Config::IsOk() const { |
| 33 return (frame_size_ms % 10 == 0) && (num_channels >= 1); | 35 return (frame_size_ms % 10 == 0) && (num_channels >= 1); |
| 34 } | 36 } |
| 35 | 37 |
| 36 AudioEncoderPcm::AudioEncoderPcm(const Config& config, int sample_rate_hz) | 38 AudioEncoderPcm::AudioEncoderPcm(const Config& config, int sample_rate_hz) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 speech_buffer_.reserve(full_frame_samples_); | 51 speech_buffer_.reserve(full_frame_samples_); |
| 50 } | 52 } |
| 51 | 53 |
| 52 AudioEncoderPcm::~AudioEncoderPcm() { | 54 AudioEncoderPcm::~AudioEncoderPcm() { |
| 53 } | 55 } |
| 54 | 56 |
| 55 int AudioEncoderPcm::SampleRateHz() const { | 57 int AudioEncoderPcm::SampleRateHz() const { |
| 56 return sample_rate_hz_; | 58 return sample_rate_hz_; |
| 57 } | 59 } |
| 58 | 60 |
| 59 int AudioEncoderPcm::NumChannels() const { | 61 size_t AudioEncoderPcm::NumChannels() const { |
| 60 return num_channels_; | 62 return num_channels_; |
| 61 } | 63 } |
| 62 | 64 |
| 63 size_t AudioEncoderPcm::MaxEncodedBytes() const { | 65 size_t AudioEncoderPcm::MaxEncodedBytes() const { |
| 64 return full_frame_samples_ * BytesPerSample(); | 66 return full_frame_samples_ * BytesPerSample(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 size_t AudioEncoderPcm::Num10MsFramesInNextPacket() const { | 69 size_t AudioEncoderPcm::Num10MsFramesInNextPacket() const { |
| 68 return num_10ms_frames_per_packet_; | 70 return num_10ms_frames_per_packet_; |
| 69 } | 71 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 : AudioEncoderMutableImpl<AudioEncoderPcmU>( | 139 : AudioEncoderMutableImpl<AudioEncoderPcmU>( |
| 138 CreateConfig<AudioEncoderPcmU>(codec_inst)) { | 140 CreateConfig<AudioEncoderPcmU>(codec_inst)) { |
| 139 } | 141 } |
| 140 | 142 |
| 141 AudioEncoderMutablePcmA::AudioEncoderMutablePcmA(const CodecInst& codec_inst) | 143 AudioEncoderMutablePcmA::AudioEncoderMutablePcmA(const CodecInst& codec_inst) |
| 142 : AudioEncoderMutableImpl<AudioEncoderPcmA>( | 144 : AudioEncoderMutableImpl<AudioEncoderPcmA>( |
| 143 CreateConfig<AudioEncoderPcmA>(codec_inst)) { | 145 CreateConfig<AudioEncoderPcmA>(codec_inst)) { |
| 144 } | 146 } |
| 145 | 147 |
| 146 } // namespace webrtc | 148 } // namespace webrtc |
| OLD | NEW |