| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 return config_.bitrate_bps; | 130 return config_.bitrate_bps; |
| 131 } | 131 } |
| 132 | 132 |
| 133 AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( | 133 AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( |
| 134 uint32_t rtp_timestamp, | 134 uint32_t rtp_timestamp, |
| 135 rtc::ArrayView<const int16_t> audio, | 135 rtc::ArrayView<const int16_t> audio, |
| 136 size_t max_encoded_bytes, | 136 size_t max_encoded_bytes, |
| 137 uint8_t* encoded) { | 137 uint8_t* encoded) { |
| 138 if (input_buffer_.empty()) | 138 if (input_buffer_.empty()) |
| 139 first_timestamp_in_buffer_ = rtp_timestamp; | 139 first_timestamp_in_buffer_ = rtp_timestamp; |
| 140 RTC_DCHECK_EQ(static_cast<size_t>(SamplesPer10msFrame()), audio.size()); | 140 RTC_DCHECK_EQ(SamplesPer10msFrame(), audio.size()); |
| 141 input_buffer_.insert(input_buffer_.end(), audio.cbegin(), audio.cend()); | 141 input_buffer_.insert(input_buffer_.end(), audio.cbegin(), audio.cend()); |
| 142 if (input_buffer_.size() < | 142 if (input_buffer_.size() < |
| 143 (static_cast<size_t>(Num10msFramesPerPacket()) * SamplesPer10msFrame())) { | 143 (Num10msFramesPerPacket() * SamplesPer10msFrame())) { |
| 144 return EncodedInfo(); | 144 return EncodedInfo(); |
| 145 } | 145 } |
| 146 RTC_CHECK_EQ( | 146 RTC_CHECK_EQ(input_buffer_.size(), |
| 147 input_buffer_.size(), | 147 Num10msFramesPerPacket() * SamplesPer10msFrame()); |
| 148 static_cast<size_t>(Num10msFramesPerPacket()) * SamplesPer10msFrame()); | |
| 149 int status = WebRtcOpus_Encode( | 148 int status = WebRtcOpus_Encode( |
| 150 inst_, &input_buffer_[0], | 149 inst_, &input_buffer_[0], |
| 151 rtc::CheckedDivExact(input_buffer_.size(), | 150 rtc::CheckedDivExact(input_buffer_.size(), |
| 152 static_cast<size_t>(config_.num_channels)), | 151 static_cast<size_t>(config_.num_channels)), |
| 153 rtc::saturated_cast<int16_t>(max_encoded_bytes), encoded); | 152 rtc::saturated_cast<int16_t>(max_encoded_bytes), encoded); |
| 154 RTC_CHECK_GE(status, 0); // Fails only if fed invalid data. | 153 RTC_CHECK_GE(status, 0); // Fails only if fed invalid data. |
| 155 input_buffer_.clear(); | 154 input_buffer_.clear(); |
| 156 EncodedInfo info; | 155 EncodedInfo info; |
| 157 info.encoded_bytes = static_cast<size_t>(status); | 156 info.encoded_bytes = static_cast<size_t>(status); |
| 158 info.encoded_timestamp = first_timestamp_in_buffer_; | 157 info.encoded_timestamp = first_timestamp_in_buffer_; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 206 } |
| 208 } | 207 } |
| 209 | 208 |
| 210 void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) { | 209 void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) { |
| 211 config_.bitrate_bps = | 210 config_.bitrate_bps = |
| 212 std::max(std::min(bits_per_second, kMaxBitrateBps), kMinBitrateBps); | 211 std::max(std::min(bits_per_second, kMaxBitrateBps), kMinBitrateBps); |
| 213 RTC_DCHECK(config_.IsOk()); | 212 RTC_DCHECK(config_.IsOk()); |
| 214 RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.bitrate_bps)); | 213 RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.bitrate_bps)); |
| 215 } | 214 } |
| 216 | 215 |
| 217 int AudioEncoderOpus::Num10msFramesPerPacket() const { | 216 size_t AudioEncoderOpus::Num10msFramesPerPacket() const { |
| 218 return rtc::CheckedDivExact(config_.frame_size_ms, 10); | 217 return static_cast<size_t>(rtc::CheckedDivExact(config_.frame_size_ms, 10)); |
| 219 } | 218 } |
| 220 | 219 |
| 221 int AudioEncoderOpus::SamplesPer10msFrame() const { | 220 size_t AudioEncoderOpus::SamplesPer10msFrame() const { |
| 222 return rtc::CheckedDivExact(kSampleRateHz, 100) * config_.num_channels; | 221 return rtc::CheckedDivExact(kSampleRateHz, 100) * config_.num_channels; |
| 223 } | 222 } |
| 224 | 223 |
| 225 // If the given config is OK, recreate the Opus encoder instance with those | 224 // If the given config is OK, recreate the Opus encoder instance with those |
| 226 // settings, save the config, and return true. Otherwise, do nothing and return | 225 // settings, save the config, and return true. Otherwise, do nothing and return |
| 227 // false. | 226 // false. |
| 228 bool AudioEncoderOpus::RecreateEncoderInstance(const Config& config) { | 227 bool AudioEncoderOpus::RecreateEncoderInstance(const Config& config) { |
| 229 if (!config.IsOk()) | 228 if (!config.IsOk()) |
| 230 return false; | 229 return false; |
| 231 if (inst_) | 230 if (inst_) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 249 RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_)); | 248 RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_)); |
| 250 } | 249 } |
| 251 RTC_CHECK_EQ(0, | 250 RTC_CHECK_EQ(0, |
| 252 WebRtcOpus_SetPacketLossRate( | 251 WebRtcOpus_SetPacketLossRate( |
| 253 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5))); | 252 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5))); |
| 254 config_ = config; | 253 config_ = config; |
| 255 return true; | 254 return true; |
| 256 } | 255 } |
| 257 | 256 |
| 258 } // namespace webrtc | 257 } // namespace webrtc |
| OLD | NEW |