| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 int AudioEncoderIsacT<T>::GetTargetBitrate() const { | 110 int AudioEncoderIsacT<T>::GetTargetBitrate() const { |
| 111 if (config_.adaptive_mode) | 111 if (config_.adaptive_mode) |
| 112 return -1; | 112 return -1; |
| 113 return config_.bit_rate == 0 ? kDefaultBitRate : config_.bit_rate; | 113 return config_.bit_rate == 0 ? kDefaultBitRate : config_.bit_rate; |
| 114 } | 114 } |
| 115 | 115 |
| 116 template <typename T> | 116 template <typename T> |
| 117 AudioEncoder::EncodedInfo AudioEncoderIsacT<T>::EncodeInternal( | 117 AudioEncoder::EncodedInfo AudioEncoderIsacT<T>::EncodeInternal( |
| 118 uint32_t rtp_timestamp, | 118 uint32_t rtp_timestamp, |
| 119 rtc::ArrayView<const int16_t> audio, | 119 rtc::ArrayView<const int16_t> audio, |
| 120 size_t max_encoded_bytes, | 120 rtc::Buffer* encoded) { |
| 121 uint8_t* encoded) { | |
| 122 if (!packet_in_progress_) { | 121 if (!packet_in_progress_) { |
| 123 // Starting a new packet; remember the timestamp for later. | 122 // Starting a new packet; remember the timestamp for later. |
| 124 packet_in_progress_ = true; | 123 packet_in_progress_ = true; |
| 125 packet_timestamp_ = rtp_timestamp; | 124 packet_timestamp_ = rtp_timestamp; |
| 126 } | 125 } |
| 127 if (bwinfo_) { | 126 if (bwinfo_) { |
| 128 IsacBandwidthInfo bwinfo = bwinfo_->Get(); | 127 IsacBandwidthInfo bwinfo = bwinfo_->Get(); |
| 129 T::SetBandwidthInfo(isac_state_, &bwinfo); | 128 T::SetBandwidthInfo(isac_state_, &bwinfo); |
| 130 } | 129 } |
| 131 int r = T::Encode(isac_state_, audio.data(), encoded); | |
| 132 RTC_CHECK_GE(r, 0) << "Encode failed (error code " | |
| 133 << T::GetErrorCode(isac_state_) << ")"; | |
| 134 | 130 |
| 135 // T::Encode doesn't allow us to tell it the size of the output | 131 size_t encoded_bytes = encoded->AppendData( |
| 136 // buffer. All we can do is check for an overrun after the fact. | 132 kSufficientEncodeBufferSizeBytes, |
| 137 RTC_CHECK_LE(static_cast<size_t>(r), max_encoded_bytes); | 133 [&] (rtc::ArrayView<uint8_t> encoded) { |
| 134 int r = T::Encode(isac_state_, audio.data(), encoded.data()); |
| 138 | 135 |
| 139 if (r == 0) | 136 RTC_CHECK_GE(r, 0) << "Encode failed (error code " |
| 137 << T::GetErrorCode(isac_state_) << ")"; |
| 138 |
| 139 return static_cast<size_t>(r); |
| 140 }); |
| 141 |
| 142 if (encoded_bytes == 0) |
| 140 return EncodedInfo(); | 143 return EncodedInfo(); |
| 141 | 144 |
| 142 // Got enough input to produce a packet. Return the saved timestamp from | 145 // Got enough input to produce a packet. Return the saved timestamp from |
| 143 // the first chunk of input that went into the packet. | 146 // the first chunk of input that went into the packet. |
| 144 packet_in_progress_ = false; | 147 packet_in_progress_ = false; |
| 145 EncodedInfo info; | 148 EncodedInfo info; |
| 146 info.encoded_bytes = r; | 149 info.encoded_bytes = encoded_bytes; |
| 147 info.encoded_timestamp = packet_timestamp_; | 150 info.encoded_timestamp = packet_timestamp_; |
| 148 info.payload_type = config_.payload_type; | 151 info.payload_type = config_.payload_type; |
| 149 return info; | 152 return info; |
| 150 } | 153 } |
| 151 | 154 |
| 152 template <typename T> | 155 template <typename T> |
| 153 void AudioEncoderIsacT<T>::Reset() { | 156 void AudioEncoderIsacT<T>::Reset() { |
| 154 RecreateEncoderInstance(config_); | 157 RecreateEncoderInstance(config_); |
| 155 } | 158 } |
| 156 | 159 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 182 // we get an encoding that isn't bit-for-bit identical with what a combined | 185 // we get an encoding that isn't bit-for-bit identical with what a combined |
| 183 // encoder+decoder object produces. | 186 // encoder+decoder object produces. |
| 184 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); | 187 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); |
| 185 | 188 |
| 186 config_ = config; | 189 config_ = config; |
| 187 } | 190 } |
| 188 | 191 |
| 189 } // namespace webrtc | 192 } // namespace webrtc |
| 190 | 193 |
| 191 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 194 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ |
| OLD | NEW |