| 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 config.num_channels * config.frame_size_ms * sample_rate_hz / 1000), | 45 config.num_channels * config.frame_size_ms * sample_rate_hz / 1000), |
| 46 first_timestamp_in_buffer_(0) { | 46 first_timestamp_in_buffer_(0) { |
| 47 RTC_CHECK_GT(sample_rate_hz, 0) << "Sample rate must be larger than 0 Hz"; | 47 RTC_CHECK_GT(sample_rate_hz, 0) << "Sample rate must be larger than 0 Hz"; |
| 48 RTC_CHECK_EQ(config.frame_size_ms % 10, 0) | 48 RTC_CHECK_EQ(config.frame_size_ms % 10, 0) |
| 49 << "Frame size must be an integer multiple of 10 ms."; | 49 << "Frame size must be an integer multiple of 10 ms."; |
| 50 speech_buffer_.reserve(full_frame_samples_); | 50 speech_buffer_.reserve(full_frame_samples_); |
| 51 } | 51 } |
| 52 | 52 |
| 53 AudioEncoderPcm::~AudioEncoderPcm() = default; | 53 AudioEncoderPcm::~AudioEncoderPcm() = default; |
| 54 | 54 |
| 55 size_t AudioEncoderPcm::MaxEncodedBytes() const { | |
| 56 return full_frame_samples_ * BytesPerSample(); | |
| 57 } | |
| 58 | |
| 59 int AudioEncoderPcm::SampleRateHz() const { | 55 int AudioEncoderPcm::SampleRateHz() const { |
| 60 return sample_rate_hz_; | 56 return sample_rate_hz_; |
| 61 } | 57 } |
| 62 | 58 |
| 63 size_t AudioEncoderPcm::NumChannels() const { | 59 size_t AudioEncoderPcm::NumChannels() const { |
| 64 return num_channels_; | 60 return num_channels_; |
| 65 } | 61 } |
| 66 | 62 |
| 67 size_t AudioEncoderPcm::Num10MsFramesInNextPacket() const { | 63 size_t AudioEncoderPcm::Num10MsFramesInNextPacket() const { |
| 68 return num_10ms_frames_per_packet_; | 64 return num_10ms_frames_per_packet_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 86 } | 82 } |
| 87 speech_buffer_.insert(speech_buffer_.end(), audio.begin(), audio.end()); | 83 speech_buffer_.insert(speech_buffer_.end(), audio.begin(), audio.end()); |
| 88 if (speech_buffer_.size() < full_frame_samples_) { | 84 if (speech_buffer_.size() < full_frame_samples_) { |
| 89 return EncodedInfo(); | 85 return EncodedInfo(); |
| 90 } | 86 } |
| 91 RTC_CHECK_EQ(speech_buffer_.size(), full_frame_samples_); | 87 RTC_CHECK_EQ(speech_buffer_.size(), full_frame_samples_); |
| 92 EncodedInfo info; | 88 EncodedInfo info; |
| 93 info.encoded_timestamp = first_timestamp_in_buffer_; | 89 info.encoded_timestamp = first_timestamp_in_buffer_; |
| 94 info.payload_type = payload_type_; | 90 info.payload_type = payload_type_; |
| 95 info.encoded_bytes = | 91 info.encoded_bytes = |
| 96 encoded->AppendData(MaxEncodedBytes(), | 92 encoded->AppendData(full_frame_samples_ * BytesPerSample(), |
| 97 [&] (rtc::ArrayView<uint8_t> encoded) { | 93 [&] (rtc::ArrayView<uint8_t> encoded) { |
| 98 return EncodeCall(&speech_buffer_[0], | 94 return EncodeCall(&speech_buffer_[0], |
| 99 full_frame_samples_, | 95 full_frame_samples_, |
| 100 encoded.data()); | 96 encoded.data()); |
| 101 }); | 97 }); |
| 102 speech_buffer_.clear(); | 98 speech_buffer_.clear(); |
| 103 return info; | 99 return info; |
| 104 } | 100 } |
| 105 | 101 |
| 106 void AudioEncoderPcm::Reset() { | 102 void AudioEncoderPcm::Reset() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 127 size_t input_len, | 123 size_t input_len, |
| 128 uint8_t* encoded) { | 124 uint8_t* encoded) { |
| 129 return WebRtcG711_EncodeU(audio, input_len, encoded); | 125 return WebRtcG711_EncodeU(audio, input_len, encoded); |
| 130 } | 126 } |
| 131 | 127 |
| 132 size_t AudioEncoderPcmU::BytesPerSample() const { | 128 size_t AudioEncoderPcmU::BytesPerSample() const { |
| 133 return 1; | 129 return 1; |
| 134 } | 130 } |
| 135 | 131 |
| 136 } // namespace webrtc | 132 } // namespace webrtc |
| OLD | NEW |